kaddressbook Library API Documentation

importdialog.cpp

00001 /*                                                                      
00002     This file is part of KAddressBook.                                  
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>                   
00004                                                                         
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or   
00008     (at your option) any later version.                                 
00009                                                                         
00010     This program is distributed in the hope that it will be useful,     
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00013     GNU General Public License for more details.                        
00014                                                                         
00015     You should have received a copy of the GNU General Public License   
00016     along with this program; if not, write to the Free Software         
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include "importdialog.h"
00025 
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 
00029 #include <kabc/addressbook.h>
00030 #include <kabc/addressee.h>
00031 #include <kabc/phonenumber.h>
00032 #include <kabc/address.h>
00033 
00034 ContactImportDialog::ContactImportDialog( KABC::AddressBook *doc, QWidget *parent )
00035   : KImportDialog( parent ), mDocument( doc )
00036 {
00037   mCustomList.setAutoDelete( true );
00038 
00039   mFormattedName = new KImportColumn( this, KABC::Addressee::formattedNameLabel() );
00040   mLastName = new KImportColumn( this, KABC::Addressee::familyNameLabel(), 1 );
00041   mFirstName = new KImportColumn( this, KABC::Addressee::givenNameLabel(), 1 );
00042   mAdditionalName = new KImportColumn( this, KABC::Addressee::additionalNameLabel() );
00043   mNamePrefix = new KImportColumn( this, KABC::Addressee::prefixLabel() );
00044   mNameSuffix = new KImportColumn( this, KABC::Addressee::suffixLabel() );
00045   mNickName = new KImportColumn( this, KABC::Addressee::nickNameLabel() );
00046   mBirthday = new KImportColumn( this, KABC::Addressee::birthdayLabel() );
00047 
00048   mAddressHomeStreet = new KImportColumn( this, KABC::Addressee::homeAddressStreetLabel() );
00049   mAddressHomeCity = new KImportColumn( this, KABC::Addressee::homeAddressLocalityLabel() );
00050   mAddressHomeState = new KImportColumn( this, KABC::Addressee::homeAddressRegionLabel() );
00051   mAddressHomeZip = new KImportColumn( this, KABC::Addressee::homeAddressPostalCodeLabel() );
00052   mAddressHomeCountry = new KImportColumn( this, KABC::Addressee::homeAddressCountryLabel() );
00053   mAddressHomeLabel = new KImportColumn( this, KABC::Addressee::homeAddressLabelLabel() );
00054 
00055   mAddressBusinessStreet = new KImportColumn( this, KABC::Addressee::businessAddressStreetLabel() );
00056   mAddressBusinessCity = new KImportColumn( this, KABC::Addressee::businessAddressLocalityLabel() );
00057   mAddressBusinessState = new KImportColumn( this, KABC::Addressee::businessAddressRegionLabel() );
00058   mAddressBusinessZip = new KImportColumn( this, KABC::Addressee::businessAddressPostalCodeLabel() );
00059   mAddressBusinessCountry = new KImportColumn( this, KABC::Addressee::businessAddressCountryLabel() );
00060   mAddressBusinessLabel = new KImportColumn( this, KABC::Addressee::businessAddressLabelLabel() );
00061 
00062   mPhoneHome = new KImportColumn( this, KABC::Addressee::homePhoneLabel() );
00063   mPhoneBusiness = new KImportColumn( this, KABC::Addressee::businessPhoneLabel() );
00064   mPhoneMobile = new KImportColumn( this, KABC::Addressee::mobilePhoneLabel() );
00065   mFaxHome = new KImportColumn( this, KABC::Addressee::homeFaxLabel() );
00066   mFaxBusiness = new KImportColumn( this, KABC::Addressee::businessFaxLabel() );
00067   mCarPhone = new KImportColumn( this, KABC::Addressee::carPhoneLabel() );
00068   mIsdn = new KImportColumn( this, KABC::Addressee::isdnLabel() );
00069   mPager = new KImportColumn( this, KABC::Addressee::pagerLabel() );
00070   mEmail = new KImportColumn( this, KABC::Addressee::emailLabel() );
00071   mMailClient = new KImportColumn( this, KABC::Addressee::mailerLabel() );
00072   mJobTitle = new KImportColumn( this, KABC::Addressee::titleLabel() );
00073   mRole = new KImportColumn( this, KABC::Addressee::roleLabel() );
00074   mCompany = new KImportColumn( this, KABC::Addressee::organizationLabel() );
00075   mNote = new KImportColumn( this, KABC::Addressee::noteLabel() );
00076   mUrl = new KImportColumn( this, KABC::Addressee::urlLabel() );
00077 
00078   KABC::Field::List fields = mDocument->fields( KABC::Field::CustomCategory );
00079   KABC::Field::List::Iterator it;
00080 
00081   for ( it = fields.begin(); it != fields.end(); ++it ) {
00082     KImportColumn *column = new KImportColumn( this, (*it)->label() );
00083     mCustomList.append( column );
00084   }
00085 
00086   registerColumns();
00087 }
00088 
00089 void ContactImportDialog::convertRow()
00090 {
00091   KABC::Addressee a;
00092   a.setFormattedName( mFormattedName->convert() );
00093   a.setGivenName( mFirstName->convert() );
00094   a.setFamilyName( mLastName->convert() );
00095   a.setAdditionalName( mAdditionalName->convert() );
00096   a.setPrefix( mNamePrefix->convert() );
00097   a.setSuffix( mNameSuffix->convert() );
00098   a.setNickName( mNickName->convert() );
00099   a.setBirthday( QDateTime::fromString( mBirthday->convert(), Qt::ISODate ) );
00100   if ( !mEmail->convert().isEmpty() )
00101     a.insertEmail( mEmail->convert(), true );
00102   a.setRole( mRole->convert() );
00103   a.setTitle( mJobTitle->convert() );
00104   a.setMailer( mMailClient->convert() );
00105   a.setUrl( mUrl->convert() );
00106   a.setOrganization( mCompany->convert() );
00107   a.setNote( mNote->convert() );
00108 
00109   QMap<KImportColumn*, int> columnMap;
00110   columnMap.insert( mPhoneHome, KABC::PhoneNumber::Home );
00111   columnMap.insert( mPhoneBusiness, KABC::PhoneNumber::Work );
00112   columnMap.insert( mPhoneMobile, KABC::PhoneNumber::Cell );
00113   columnMap.insert( mFaxHome, KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
00114   columnMap.insert( mFaxBusiness, KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
00115   columnMap.insert( mCarPhone, KABC::PhoneNumber::Car );
00116   columnMap.insert( mIsdn, KABC::PhoneNumber::Isdn );
00117   columnMap.insert( mPager, KABC::PhoneNumber::Pager );
00118 
00119   QMap<KImportColumn*, int>::Iterator phoneIt;
00120   for ( phoneIt = columnMap.begin(); phoneIt != columnMap.end(); ++phoneIt ) {
00121     QString number = phoneIt.key()->convert();
00122     if ( !number.isEmpty() ) {
00123       KABC::PhoneNumber p( number, phoneIt.data() );
00124       a.insertPhoneNumber( p );
00125     }
00126   }
00127 
00128   KABC::Address addrHome( KABC::Address::Home );
00129   addrHome.setStreet( mAddressHomeStreet->convert() );
00130   addrHome.setLocality( mAddressHomeCity->convert() );
00131   addrHome.setRegion( mAddressHomeState->convert() );
00132   addrHome.setPostalCode( mAddressHomeZip->convert() );
00133   addrHome.setCountry( mAddressHomeCountry->convert() );
00134   addrHome.setLabel( mAddressHomeLabel->convert() );
00135   if ( !addrHome.isEmpty() )
00136     a.insertAddress( addrHome );
00137   
00138   KABC::Address addrWork( KABC::Address::Work );
00139   addrWork.setStreet( mAddressBusinessStreet->convert() );
00140   addrWork.setLocality( mAddressBusinessCity->convert() );
00141   addrWork.setRegion( mAddressBusinessState->convert() );
00142   addrWork.setPostalCode( mAddressBusinessZip->convert() );
00143   addrWork.setCountry( mAddressBusinessCountry->convert() );
00144   addrWork.setLabel( mAddressBusinessLabel->convert() );
00145   if ( !addrWork.isEmpty() )
00146     a.insertAddress( addrWork );
00147 
00148   KABC::Field::List fields = mDocument->fields( KABC::Field::CustomCategory );
00149   KABC::Field::List::Iterator it;
00150 
00151   uint counter = 0;
00152   for ( it = fields.begin(); it != fields.end(); ++it ) {
00153     (*it)->setValue( a, mCustomList.at( counter )->convert() );
00154     ++counter;
00155   }
00156   
00157   mDocument->insertAddressee( a );
00158 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:37 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001