• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

opera_xxport.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KAddressbook.
00003     Copyright (c) 2003 - 2003 Daniel Molkentin <molkentin@kde.org>
00004                               Tobias Koenig <tokoe@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <QtCore/QFile>
00026 #include <QtCore/QRegExp>
00027 #include <QtCore/QTextStream>
00028 
00029 #include <kfiledialog.h>
00030 #include <kio/netaccess.h>
00031 #include <klocale.h>
00032 #include <kmessagebox.h>
00033 #include <ktemporaryfile.h>
00034 #include <kurl.h>
00035 
00036 #include <kdebug.h>
00037 
00038 #include "opera_xxport.h"
00039 
00040 K_EXPORT_KADDRESSBOOK_XXFILTER( kaddrbk_opera_xxport, OperaXXPort )
00041 
00042 OperaXXPort::OperaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
00043   : KAB::XXPort( ab, parent, name )
00044 {
00045   createImportAction( i18n( "Import Opera Addressbook..." ) );
00046 }
00047 
00048 KABC::Addressee::List OperaXXPort::importContacts( const QString& ) const
00049 {
00050   KABC::Addressee::List addrList;
00051 
00052   QString fileName = KFileDialog::getOpenFileName( QDir::homePath() + QString::fromLatin1( "/.opera/contacts.adr" ) );
00053   if ( fileName.isEmpty() )
00054     return addrList;
00055 
00056   QFile file( fileName );
00057   if ( !file.open( QIODevice::ReadOnly ) ) {
00058     QString msg = i18n( "<qt>Unable to open <b>%1</b> for reading.</qt>", fileName );
00059     KMessageBox::error( parentWidget(), msg );
00060     return addrList;
00061   }
00062 
00063   QTextStream stream( &file );
00064   stream.setCodec( "UTF-8" );
00065   QString line, key, value;
00066   bool parseContact = false;
00067   KABC::Addressee addr;
00068 
00069   QRegExp separator( "\x02\x02" );
00070 
00071   while ( !stream.atEnd() ) {
00072     line = stream.readLine();
00073     line = line.trimmed();
00074     if ( line == QString::fromLatin1( "#CONTACT" ) ) {
00075       parseContact = true;
00076       addr = KABC::Addressee();
00077       continue;
00078     } else if ( line.isEmpty() ) {
00079       parseContact = false;
00080       if ( !addr.isEmpty() ) {
00081         addrList.append( addr );
00082         addr = KABC::Addressee();
00083       }
00084       continue;
00085     }
00086 
00087     if ( parseContact == true ) {
00088       int sep = line.indexOf( '=' );
00089       key = line.left( sep ).toLower();
00090       value = line.mid( sep + 1 );
00091       if ( key == QString::fromLatin1( "name" ) )
00092         addr.setNameFromString( value );
00093       else if ( key == QString::fromLatin1( "mail" ) ) {
00094         QStringList emails = value.split( separator, QString::SkipEmptyParts );
00095 
00096         QStringList::Iterator it = emails.begin();
00097         bool preferred = true;
00098         for ( ; it != emails.end(); ++it ) {
00099           addr.insertEmail( *it, preferred );
00100           preferred = false;
00101         }
00102       } else if ( key == QString::fromLatin1( "phone" ) )
00103         addr.insertPhoneNumber( KABC::PhoneNumber( value ) );
00104       else if ( key == QString::fromLatin1( "fax" ) )
00105         addr.insertPhoneNumber( KABC::PhoneNumber( value,
00106                               KABC::PhoneNumber::Fax | KABC::PhoneNumber::Home ) );
00107       else if ( key == QString::fromLatin1( "postaladdress" ) ) {
00108         KABC::Address address( KABC::Address::Home );
00109         address.setLabel( value.replace( separator, "\n" ) );
00110         addr.insertAddress( address );
00111       } else if ( key == QString::fromLatin1( "description" ) )
00112         addr.setNote( value.replace( separator, "\n" ) );
00113       else if ( key == QString::fromLatin1( "url" ) )
00114         addr.setUrl( KUrl( value ) );
00115       else if ( key == QString::fromLatin1( "pictureurl" ) ) {
00116         KABC::Picture pic( value );
00117         addr.setPhoto( pic );
00118       }
00119     }
00120   }
00121 
00122   file.close();
00123 
00124   return addrList;
00125 }
00126 
00127 #include "opera_xxport.moc"

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal