author | zautrix <zautrix> | 2004-07-12 10:03:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-12 10:03:12 (UTC) |
commit | a55fa40fa32b115c7f7803fb6af0da5184cd7dff (patch) (side-by-side diff) | |
tree | d55eec53c51f3bef866b67dedd5e8508c4d8579e | |
parent | 2aeb681a7e8a0696608485f36d9c0561ba505c5c (diff) | |
download | kdepimpi-a55fa40fa32b115c7f7803fb6af0da5184cd7dff.zip kdepimpi-a55fa40fa32b115c7f7803fb6af0da5184cd7dff.tar.gz kdepimpi-a55fa40fa32b115c7f7803fb6af0da5184cd7dff.tar.bz2 |
Added importing from OL to KA/Pi
-rw-r--r-- | kaddressbook/kabcore.cpp | 26 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 3 | ||||
-rw-r--r-- | kaddressbook/kaddressbook.pro | 11 | ||||
-rw-r--r-- | kaddressbook/kaimportoldialog.cpp | 635 | ||||
-rw-r--r-- | kaddressbook/kaimportoldialog.h | 85 |
5 files changed, 757 insertions, 3 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 7e3fc7c..f4263c4 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -1,356 +1,363 @@ /* This file is part of KAddressbook. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "kabcore.h" #include <stdaddressbook.h> #include <klocale.h> #ifndef KAB_EMBEDDED #include <qclipboard.h> #include <qdir.h> #include <qfile.h> #include <qapplicaton.h> #include <qlayout.h> #include <qregexp.h> #include <qvbox.h> #include <kabc/addresseelist.h> #include <kabc/errorhandler.h> #include <kabc/resource.h> #include <kabc/vcardconverter.h> #include <kapplication.h> #include <kactionclasses.h> #include <kcmultidialog.h> #include <kdebug.h> #include <kdeversion.h> #include <kkeydialog.h> #include <kmessagebox.h> #include <kprinter.h> #include <kprotocolinfo.h> #include <kresources/selectdialog.h> #include <kstandarddirs.h> #include <ktempfile.h> #include <kxmlguiclient.h> #include <kaboutdata.h> #include <libkdepim/categoryselectdialog.h> #include "addresseeutil.h" #include "addresseeeditordialog.h" #include "extensionmanager.h" #include "kstdaction.h" #include "kaddressbookservice.h" #include "ldapsearchdialog.h" #include "printing/printingwizard.h" #else // KAB_EMBEDDED #include <kapplication.h> #include "KDGanttMinimizeSplitter.h" #include "kaddressbookmain.h" #include "kactioncollection.h" #include <qapp.h> #include <qmenubar.h> //#include <qtoolbar.h> #include <qmessagebox.h> #include <kdebug.h> #include <kiconloader.h> // needed for SmallIcon #include <kresources/kcmkresources.h> #include <ktoolbar.h> #include <kcmkabconfig.h> //US#include <qpe/resource.h> // needed for Resource::loadPixmap //#include <qlabel.h> #endif // KAB_EMBEDDED #include <kcmkabconfig.h> #include <kresources/selectdialog.h> #include <kmessagebox.h> #include <picture.h> #include <resource.h> //US#include <qsplitter.h> #include <qvbox.h> #include <qlayout.h> #include <qclipboard.h> #include <libkdepim/categoryselectdialog.h> #include "addresseeutil.h" #include "undocmds.h" #include "addresseeeditordialog.h" #include "viewmanager.h" #include "details/detailsviewcontainer.h" #include "kabprefs.h" #include "xxportmanager.h" #include "incsearchwidget.h" #include "jumpbuttonbar.h" #include "extensionmanager.h" #include "addresseeconfig.h" #include <kcmultidialog.h> +#ifdef _WIN32_ + +#include "kaimportoldialog.h" +#endif + #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ mReadWrite( readWrite ), mModified( false ), mMainWindow(client) #else //KAB_EMBEDDED KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), mReadWrite( readWrite ), mModified( false ) #endif //KAB_EMBEDDED { #ifdef KAB_EMBEDDED //US we define here our own global actioncollection. //mActionCollection = new KActionCollection(this); #endif //KAB_EMBEDDED mExtensionBarSplitter = 0; mIsPart = !parent->inherits( "KAddressBookMain" ); mAddressBook = KABC::StdAddressBook::self(); KABC::StdAddressBook::setAutomaticSave( false ); #ifndef KAB_EMBEDDED mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); #endif //KAB_EMBEDDED connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), SLOT( addressBookChanged() ) ); mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie addressbook mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); + mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, + "X-FreeBusyUrl", "KADDRESSBOOK" ); initGUI(); mIncSearchWidget->setFocus(); connect( mViewManager, SIGNAL( selected( const QString& ) ), SLOT( setContactSelected( const QString& ) ) ); connect( mViewManager, SIGNAL( executed( const QString& ) ), SLOT( editContact( const QString& ) ) ); connect( mViewManager, SIGNAL( deleteRequest( ) ), SLOT( deleteContacts( ) ) ); connect( mViewManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); connect( mXXPortManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); connect( mIncSearchWidget, SIGNAL( fieldChanged() ), mJumpButtonBar, SLOT( recreateButtons() ) ); #ifndef KAB_EMBEDDED connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), mXXPortManager, SLOT( importVCard( const KURL& ) ) ); connect( mDetails, SIGNAL( sendEmail( const QString& ) ), SLOT( sendMail( const QString& ) ) ); connect( mDetails, SIGNAL( browse( const QString& ) ), SLOT( browse( const QString& ) ) ); mAddressBookService = new KAddressBookService( this ); #endif //KAB_EMBEDDED mEditorDialog = 0; createAddresseeEditorDialog( this ); setModified( false ); } KABCore::~KABCore() { // save(); //saveSettings(); //KABPrefs::instance()->writeConfig(); delete AddresseeConfig::instance(); mAddressBook = 0; KABC::StdAddressBook::close(); #ifdef KAB_EMBEDDED //US we define here our own global actioncollection. // delete mActionCollection; #endif //KAB_EMBEDDED } void KABCore::restoreSettings() { bool state = KABPrefs::instance()->mJumpButtonBarVisible; mActionJumpBar->setChecked( state ); setJumpButtonBarVisible( state ); state = KABPrefs::instance()->mDetailsPageVisible; mActionDetails->setChecked( state ); setDetailsVisible( state ); QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( width() / 2 ); splitterSize.append( width() / 2 ); } mMiniSplitter->setSizes( splitterSize ); if ( mExtensionBarSplitter ) { splitterSize = KABPrefs::instance()->mExtensionsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( width() / 2 ); splitterSize.append( width() / 2 ); } mExtensionBarSplitter->setSizes( splitterSize ); } #ifndef KAB_EMBEDDED QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( width() / 2 ); splitterSize.append( width() / 2 ); } mExtensionBarSplitter->setSizes( splitterSize ); splitterSize = KABPrefs::instance()->mDetailsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( height() / 2 ); splitterSize.append( height() / 2 ); } mDetailsSplitter->setSizes( splitterSize ); mExtensionManager->restoreSettings(); #endif //KAB_EMBEDDED mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); mViewManager->restoreSettings(); mExtensionManager->restoreSettings(); } void KABCore::saveSettings() { KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); if ( mExtensionBarSplitter ) KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); #ifndef KAB_EMBEDDED KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); #endif //KAB_EMBEDDED mExtensionManager->saveSettings(); mViewManager->saveSettings(); KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); } KABC::AddressBook *KABCore::addressBook() const { return mAddressBook; } KConfig *KABCore::config() { #ifndef KAB_EMBEDDED return KABPrefs::instance()->config(); #else //KAB_EMBEDDED return KABPrefs::instance()->getConfig(); #endif //KAB_EMBEDDED } KActionCollection *KABCore::actionCollection() const { return mGUIClient->actionCollection(); } KABC::Field *KABCore::currentSearchField() const { if (mIncSearchWidget) return mIncSearchWidget->currentField(); else return 0; } QStringList KABCore::selectedUIDs() const { return mViewManager->selectedUids(); } KABC::Resource *KABCore::requestResource( QWidget *parent ) { QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); QPtrList<KRES::Resource> kresResources; QPtrListIterator<KABC::Resource> resIt( kabcResources ); KABC::Resource *resource; while ( ( resource = resIt.current() ) != 0 ) { ++resIt; if ( !resource->readOnly() ) { KRES::Resource *res = static_cast<KRES::Resource*>( resource ); if ( res ) kresResources.append( res ); } } KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); return static_cast<KABC::Resource*>( res ); } #ifndef KAB_EMBEDDED KAboutData *KABCore::createAboutData() #else //KAB_EMBEDDED void KABCore::createAboutData() #endif //KAB_EMBEDDED { #ifndef KAB_EMBEDDED KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), "3.1", I18N_NOOP( "The KDE Address Book" ), KAboutData::License_GPL_V2, I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); @@ -652,384 +659,395 @@ void KABCore::setCategories() if ( uids.count() > 0 ) setModified( true ); } void KABCore::setSearchFields( const KABC::Field::List &fields ) { mIncSearchWidget->setFields( fields ); } void KABCore::incrementalSearch( const QString& text ) { mViewManager->setSelected( QString::null, false ); if ( !text.isEmpty() ) { KABC::Field *field = mIncSearchWidget->currentField(); QString pattern = text.lower(); #if 1 //KDE_VERSION >= 319 KABC::AddresseeList list( mAddressBook->allAddressees() ); if ( field ) { list.sortByField( field ); KABC::AddresseeList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( field->value( *it ).lower().startsWith( pattern ) ) { mViewManager->setSelected( (*it).uid(), true ); return; } } } else { KABC::AddresseeList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { KABC::Field::List fieldList = mIncSearchWidget->fields(); KABC::Field::List::ConstIterator fieldIt; for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { mViewManager->setSelected( (*it).uid(), true ); return; } } } } #else KABC::AddressBook::Iterator it; for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { if ( field ) { if ( field->value( *it ).lower().startsWith( pattern ) ) { mViewManager->setSelected( (*it).uid(), true ); return; } } else { KABC::Field::List fieldList = mIncSearchWidget->fields(); KABC::Field::List::ConstIterator fieldIt; for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { mViewManager->setSelected( (*it).uid(), true ); return; } } } } #endif } } void KABCore::setModified() { setModified( true ); } void KABCore::setModifiedWOrefresh() { // qDebug("KABCore::setModifiedWOrefresh() "); mModified = true; mActionSave->setEnabled( mModified ); #ifdef DESKTOP_VERSION mDetails->refreshView(); #endif } void KABCore::setModified( bool modified ) { mModified = modified; mActionSave->setEnabled( mModified ); if ( modified ) mJumpButtonBar->recreateButtons(); mViewManager->refreshView(); mDetails->refreshView(); } bool KABCore::modified() const { return mModified; } void KABCore::contactModified( const KABC::Addressee &addr ) { Command *command = 0; QString uid; // check if it exists already KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); if ( origAddr.isEmpty() ) command = new PwNewCommand( mAddressBook, addr ); else { command = new PwEditCommand( mAddressBook, origAddr, addr ); uid = addr.uid(); } UndoStack::instance()->push( command ); RedoStack::instance()->clear(); setModified( true ); } void KABCore::newContact() { QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); QPtrList<KRES::Resource> kresResources; QPtrListIterator<KABC::Resource> it( kabcResources ); KABC::Resource *resource; while ( ( resource = it.current() ) != 0 ) { ++it; if ( !resource->readOnly() ) { KRES::Resource *res = static_cast<KRES::Resource*>( resource ); if ( res ) kresResources.append( res ); } } KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); resource = static_cast<KABC::Resource*>( res ); if ( resource ) { KABC::Addressee addr; addr.setResource( resource ); mEditorDialog->setAddressee( addr ); KApplication::execDialog ( mEditorDialog ); } else return; // mEditorDict.insert( dialog->addressee().uid(), dialog ); } void KABCore::addEmail( QString aStr ) { #ifndef KAB_EMBEDDED QString fullName, email; KABC::Addressee::parseEmailAddress( aStr, fullName, email ); // Try to lookup the addressee matching the email address bool found = false; QStringList emailList; KABC::AddressBook::Iterator it; for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { emailList = (*it).emails(); if ( emailList.contains( email ) > 0 ) { found = true; (*it).setNameFromString( fullName ); editContact( (*it).uid() ); } } if ( !found ) { KABC::Addressee addr; addr.setNameFromString( fullName ); addr.insertEmail( email, true ); mAddressBook->insertAddressee( addr ); mViewManager->refreshView( addr.uid() ); editContact( addr.uid() ); } #else //KAB_EMBEDDED qDebug("KABCore::addEmail finsih method"); #endif //KAB_EMBEDDED } void KABCore::importVCard( const KURL &url, bool showPreview ) { mXXPortManager->importVCard( url, showPreview ); } +void KABCore::importFromOL() +{ +#ifdef _WIN32_ + KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); + idgl->exec(); + KABC::Addressee::List list = idgl->getAddressList(); + if ( list.count() > 0 ) + pasteContacts( list ); + delete idgl; +#endif +} void KABCore::importVCard( const QString &vCard, bool showPreview ) { mXXPortManager->importVCard( vCard, showPreview ); } //US added a second method without defaultparameter void KABCore::editContact2() { editContact( QString::null ); } void KABCore::editContact( const QString &uid ) { if ( mExtensionManager->isQuickEditVisible() ) return; // First, locate the contact entry QString localUID = uid; if ( localUID.isNull() ) { QStringList uidList = mViewManager->selectedUids(); if ( uidList.count() > 0 ) localUID = *( uidList.at( 0 ) ); } KABC::Addressee addr = mAddressBook->findByUid( localUID ); if ( !addr.isEmpty() ) { mEditorDialog->setAddressee( addr ); KApplication::execDialog ( mEditorDialog ); } } void KABCore::save() { if ( !mModified ) return; QString text = i18n( "There was an error while attempting to save\n the " "address book. Please check that some \nother application is " "not using it. " ); statusMessage(i18n("Saving addressbook ... ")); #ifndef KAB_EMBEDDED KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); if ( !b || !b->save() ) { KMessageBox::error( this, text, i18n( "Unable to Save" ) ); } #else //KAB_EMBEDDED KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); if ( !b || !b->save() ) { QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); } #endif //KAB_EMBEDDED statusMessage(i18n("Addressbook saved!")); setModified( false ); } void KABCore::statusMessage(QString mess , int time ) { //topLevelWidget()->setCaption( mess ); // pending setting timer to revome message } void KABCore::undo() { UndoStack::instance()->undo(); // Refresh the view mViewManager->refreshView(); } void KABCore::redo() { RedoStack::instance()->redo(); // Refresh the view mViewManager->refreshView(); } void KABCore::setJumpButtonBarVisible( bool visible ) { if ( visible ) mJumpButtonBar->show(); else mJumpButtonBar->hide(); } void KABCore::setDetailsToState() { setDetailsVisible( mActionDetails->isChecked() ); } void KABCore::setDetailsVisible( bool visible ) { if ( visible ) mDetails->show(); else mDetails->hide(); } void KABCore::extensionModified( const KABC::Addressee::List &list ) { if ( list.count() != 0 ) { KABC::Addressee::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) mAddressBook->insertAddressee( *it ); if ( list.count() > 1 ) setModified(); else setModifiedWOrefresh(); } if ( list.count() == 0 ) mViewManager->refreshView(); else mViewManager->refreshView( list[ 0 ].uid() ); } QString KABCore::getNameByPhone( const QString &phone ) { #ifndef KAB_EMBEDDED QRegExp r( "[/*/-/ ]" ); QString localPhone( phone ); bool found = false; QString ownerName = ""; KABC::AddressBook::Iterator iter; KABC::PhoneNumber::List::Iterator phoneIter; KABC::PhoneNumber::List phoneList; for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { phoneList = (*iter).phoneNumbers(); for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); ++phoneIter) { // Get rid of separator chars so just the numbers are compared. if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { ownerName = (*iter).formattedName(); found = true; } } } return ownerName; #else //KAB_EMBEDDED qDebug("KABCore::getNameByPhone finsih method"); return ""; #endif //KAB_EMBEDDED } void KABCore::openConfigDialog() { KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); ConfigureDialog->addModule(kabcfg ); connect( ConfigureDialog, SIGNAL( applyClicked() ), this, SLOT( configurationChanged() ) ); connect( ConfigureDialog, SIGNAL( okClicked() ), this, SLOT( configurationChanged() ) ); saveSettings(); ConfigureDialog->showMaximized(); if ( ConfigureDialog->exec() ) KMessageBox::information( this, i18n("If you configured \nExtensions,\nplease restart!\n") ); delete ConfigureDialog; } void KABCore::openLDAPDialog() { #ifndef KAB_EMBEDDED if ( !mLdapSearchDialog ) { mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, SLOT( refreshView() ) ); connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, SLOT( setModified() ) ); } else mLdapSearchDialog->restoreSettings(); if ( mLdapSearchDialog->isOK() ) mLdapSearchDialog->exec(); #else //KAB_EMBEDDED qDebug("KABCore::openLDAPDialog() finsih method"); #endif //KAB_EMBEDDED } void KABCore::print() { #ifndef KAB_EMBEDDED KPrinter printer; if ( !printer.setup( this ) ) return; KABPrinting::PrintingWizard wizard( &printer, mAddressBook, @@ -1208,425 +1226,429 @@ void KABCore::initGUI() mDetails = new ViewContainer( mDetailsSplitter ); topLayout->addWidget( mDetailsSplitter ); topLayout->setStretchFactor( mDetailsSplitter, 100 ); #else //KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); // mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( this ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( this ); topLayout->addWidget( viewSpace ); // topLayout->setStretchFactor( mDetailsSplitter, 100 ); topLayout->addWidget( mDetails ); #endif //KAB_NOSPLITTER */ #endif //KAB_EMBEDDED initActions(); #ifdef KAB_EMBEDDED addActionsManually(); //US make sure the export and import menues are initialized before creating the xxPortManager. mXXPortManager = new XXPortManager( this, this ); // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); // mActionQuit->plug ( mMainWindow->toolBar()); //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); // mIncSearchWidget->hide(); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); topLayout->addWidget( mJumpButtonBar ); //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); // mMainWindow->getIconToolBar()->raise(); #endif //KAB_EMBEDDED } void KABCore::initActions() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifndef KAB_EMBEDDED connect( QApplication::clipboard(), SIGNAL( dataChanged() ), SLOT( clipboardDataChanged() ) ); #endif //KAB_EMBEDDED // file menu if ( mIsPart ) { mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, SLOT( sendMail() ), actionCollection(), "kaddressbook_mail" ); mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, SLOT( print() ), actionCollection(), "kaddressbook_print" ); } else { mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); } mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, this, SLOT( mailVCard() ), actionCollection(), "file_mail_vcard"); mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, this, SLOT( editContact2() ), actionCollection(), "file_properties" ); #ifdef KAB_EMBEDDED // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, mMainWindow, SLOT( exit() ), actionCollection(), "quit" ); #endif //KAB_EMBEDDED // edit menu if ( mIsPart ) { mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, SLOT( copyContacts() ), actionCollection(), "kaddressbook_copy" ); mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, SLOT( cutContacts() ), actionCollection(), "kaddressbook_cut" ); mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, SLOT( pasteContacts() ), actionCollection(), "kaddressbook_paste" ); mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, SLOT( selectAllContacts() ), actionCollection(), "kaddressbook_select_all" ); mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, SLOT( undo() ), actionCollection(), "kaddressbook_undo" ); mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, this, SLOT( redo() ), actionCollection(), "kaddressbook_redo" ); } else { mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); } mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", Key_Delete, this, SLOT( deleteContacts() ), actionCollection(), "edit_delete" ); mActionUndo->setEnabled( false ); mActionRedo->setEnabled( false ); // settings menu #ifdef KAB_EMBEDDED //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, SLOT( configureResources() ), actionCollection(), "kaddressbook_configure_resources" ); #endif //KAB_EMBEDDED if ( mIsPart ) { mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, SLOT( openConfigDialog() ), actionCollection(), "kaddressbook_configure" ); mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, this, SLOT( configureKeyBindings() ), actionCollection(), "kaddressbook_configure_shortcuts" ); #ifdef KAB_EMBEDDED mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); mActionConfigureToolbars->setEnabled( false ); #endif //KAB_EMBEDDED } else { mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); } mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, actionCollection(), "options_show_jump_bar" ); connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0, actionCollection(), "options_show_details" ); connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); // misc // only enable LDAP lookup if we can handle the protocol #ifndef KAB_EMBEDDED if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, this, SLOT( openLDAPDialog() ), actionCollection(), "ldap_lookup" ); } #else //KAB_EMBEDDED //qDebug("KABCore::initActions() LDAP has to be implemented"); #endif //KAB_EMBEDDED mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, SLOT( setWhoAmI() ), actionCollection(), "set_personal" ); mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, SLOT( setCategories() ), actionCollection(), "edit_set_categories" ); mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, SLOT( removeVoice() ), actionCollection(), "remove_voice" ); + mActionImportOL = new KAction( i18n( "Import from OL..." ), 0, this, + SLOT( importFromOL() ), actionCollection(), + "import_OL" ); #ifdef KAB_EMBEDDED mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, this, SLOT( createAboutData() ), actionCollection(), "kaddressbook_about_data" ); #endif //KAB_EMBEDDED clipboardDataChanged(); connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); } //US we need this function, to plug all actions into the correct menues. // KDE uses a XML format to plug the actions, but we work her without this overhead. void KABCore::addActionsManually() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifdef KAB_EMBEDDED QPopupMenu *fileMenu = new QPopupMenu( this ); QPopupMenu *editMenu = new QPopupMenu( this ); QPopupMenu *helpMenu = new QPopupMenu( this ); KToolBar* tb = mMainWindow->toolBar(); #ifdef DESKTOP_VERSION QMenuBar* mb = mMainWindow->menuBar(); //US setup menubar. //Disable the following block if you do not want to have a menubar. mb->insertItem( "&File", fileMenu ); mb->insertItem( "&Edit", editMenu ); mb->insertItem( "&View", viewMenu ); mb->insertItem( "&Settings", settingsMenu ); mb->insertItem( "&Change selected", changeMenu ); mb->insertItem( "&Help", helpMenu ); mIncSearchWidget = new IncSearchWidget( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget); #else //US setup toolbar QMenuBar *menuBarTB = new QMenuBar( tb ); QPopupMenu *popupBarTB = new QPopupMenu( this ); menuBarTB->insertItem( "ME", popupBarTB); tb->insertWidget(-1, 0, menuBarTB); mIncSearchWidget = new IncSearchWidget( tb ); tb->enableMoving(false); popupBarTB->insertItem( "&File", fileMenu ); popupBarTB->insertItem( "&Edit", editMenu ); popupBarTB->insertItem( "&View", viewMenu ); popupBarTB->insertItem( "&Settings", settingsMenu ); mViewManager->getFilterAction()->plug ( popupBarTB); popupBarTB->insertItem( "&Change selected", changeMenu ); popupBarTB->insertItem( "&Help", helpMenu ); if (QApplication::desktop()->width() > 320 ) { // mViewManager->getFilterAction()->plug ( tb); } #endif // mActionQuit->plug ( mMainWindow->toolBar()); //US Now connect the actions with the menue entries. mActionPrint->plug( fileMenu ); mActionMail->plug( fileMenu ); fileMenu->insertSeparator(); mActionNewContact->plug( fileMenu ); mActionNewContact->plug( tb ); mActionEditAddressee->plug( fileMenu ); fileMenu->insertSeparator(); mActionSave->plug( fileMenu ); fileMenu->insertItem( "&Import", ImportMenu ); fileMenu->insertItem( "&Emport", ExportMenu ); fileMenu->insertSeparator(); mActionMailVCard->plug( fileMenu ); fileMenu->insertSeparator(); mActionQuit->plug( fileMenu ); - - +#ifdef _WIN32_ + mActionImportOL->plug( ImportMenu ); +#endif // edit menu mActionUndo->plug( editMenu ); mActionRedo->plug( editMenu ); editMenu->insertSeparator(); mActionCut->plug( editMenu ); mActionCopy->plug( editMenu ); mActionPaste->plug( editMenu ); mActionDelete->plug( editMenu ); editMenu->insertSeparator(); mActionSelectAll->plug( editMenu ); mActionRemoveVoice->plug( changeMenu ); // settings menu //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionConfigKAddressbook->plug( settingsMenu ); if ( mIsPart ) { mActionConfigShortcuts->plug( settingsMenu ); mActionConfigureToolbars->plug( settingsMenu ); } else { mActionKeyBindings->plug( settingsMenu ); } settingsMenu->insertSeparator(); mActionJumpBar->plug( settingsMenu ); mActionDetails->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionWhoAmI->plug( settingsMenu ); mActionCategories->plug( settingsMenu ); mActionAboutKAddressbook->plug( helpMenu ); if (QApplication::desktop()->width() > 320 ) { mActionEditAddressee->plug( tb ); mActionSave->plug( tb ); mViewManager->getFilterAction()->plug ( tb); if (QApplication::desktop()->width() > 480 ) { mActionUndo->plug( tb ); mActionDelete->plug( tb ); mActionRedo->plug( tb ); } } //mActionQuit->plug ( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget, 6); //US link the searchwidget first to this. // The real linkage to the toolbar happens later. //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); //US tb->insertItem( mIncSearchWidget ); /*US mIncSearchWidget = new IncSearchWidget( tb ); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); //US topLayout->addWidget( mJumpButtonBar ); this->layout()->add( mJumpButtonBar ); */ #endif //KAB_EMBEDDED } void KABCore::removeVoice() { if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) return; KABC::Addressee::List list = mViewManager->selectedAddressees(); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found if ((*phoneIt).type() - PhoneNumber::Voice ) { (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); (*it).insertPhoneNumber( (*phoneIt) ); found = true; } } } if ( found ) contactModified((*it) ); } } void KABCore::clipboardDataChanged() { if ( mReadWrite ) mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); } void KABCore::updateActionMenu() { UndoStack *undo = UndoStack::instance(); RedoStack *redo = RedoStack::instance(); if ( undo->isEmpty() ) mActionUndo->setText( i18n( "Undo" ) ); else mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); mActionUndo->setEnabled( !undo->isEmpty() ); if ( !redo->top() ) mActionRedo->setText( i18n( "Redo" ) ); else mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); mActionRedo->setEnabled( !redo->isEmpty() ); } void KABCore::configureKeyBindings() { #ifndef KAB_EMBEDDED KKeyDialog::configure( actionCollection(), true ); #else //KAB_EMBEDDED qDebug("KABCore::configureKeyBindings() not implemented"); #endif //KAB_EMBEDDED } #ifdef KAB_EMBEDDED void KABCore::configureResources() { KRES::KCMKResources dlg( this, "" , 0 ); if ( !dlg.exec() ) return; KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); } #endif //KAB_EMBEDDED #ifndef KAB_EMBEDDED #include "kabcore.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 8d6041e..69a98a5 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -129,297 +129,298 @@ class KABCore : public QWidget #ifndef KAB_EMBEDDED static KAboutData *createAboutData(); #endif //KAB_EMBEDDED #ifdef KAB_EMBEDDED inline QPopupMenu* getImportMenu() { return ImportMenu;} inline QPopupMenu* getExportMenu() { return ExportMenu;} #endif //KAB_EMBEDDED public slots: #ifdef KAB_EMBEDDED void createAboutData(); #endif //KAB_EMBEDDED void statusMessage(QString, int time = 0 ); /** Is called whenever a contact is selected in the view. */ void setContactSelected( const QString &uid ); /** Opens the preferred mail composer with all selected contacts as arguments. */ void sendMail(); /** Opens the preferred mail composer with the given contacts as arguments. */ void sendMail( const QString& email ); void mailVCard(); void mailVCard(const QStringList& uids); /** Starts the preferred web browser with the given URL as argument. */ void browse( const QString& url ); /** Select all contacts in the view. */ void selectAllContacts(); /** Deletes all selected contacts from the address book. */ void deleteContacts(); /** Deletes given contacts from the address book. @param uids The uids of the contacts, which shall be deleted. */ void deleteContacts( const QStringList &uids ); /** Copys the selected contacts into clipboard for later pasting. */ void copyContacts(); /** Cuts the selected contacts and stores them for later pasting. */ void cutContacts(); /** Paste contacts from clipboard into the address book. */ void pasteContacts(); /** Paste given contacts into the address book. @param list The list of addressee, which shall be pasted. */ void pasteContacts( KABC::Addressee::List &list ); /** Sets the whoAmI contact, that is used by many other programs to get personal information about the current user. */ void setWhoAmI(); /** Displays the category dialog and applies the result to all selected contacts. */ void setCategories(); /** Sets the field list of the Incremental Search Widget. */ void setSearchFields( const KABC::Field::List &fields ); /** Search with the current search field for a contact, that matches the given text, and selects it in the view. */ void incrementalSearch( const QString& text ); /** Marks the address book as modified. */ void setModified(); /** Marks the address book as modified without refreshing the view. */ void setModifiedWOrefresh(); /** Marks the address book as modified concerning the argument. */ void setModified( bool modified ); /** Returns whether the address book is modified. */ bool modified() const; /** Called whenever an contact is modified in the contact editor dialog or the quick edit. */ void contactModified( const KABC::Addressee &addr ); /** DCOP METHODS. */ void addEmail( QString addr ); void importVCard( const KURL& url, bool showPreview ); void importVCard( const QString& vCard, bool showPreview ); void newContact(); QString getNameByPhone( const QString& phone ); /** END DCOP METHODS */ /** Saves the contents of the AddressBook back to disk. */ void save(); /** Undos the last command using the undo stack. */ void undo(); /** Redos the last command that was undone, using the redo stack. */ void redo(); /** Shows the edit dialog for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void editContact( const QString &uid /*US = QString::null*/ ); //US added a second method without defaultparameter void editContact2(); /** Launches the configuration dialog. */ void openConfigDialog(); /** Launches the ldap search dialog. */ void openLDAPDialog(); /** Creates a KAddressBookPrinter, which will display the print dialog and do the printing. */ void print(); /** Registers a new GUI client, so plugins can register its actions. */ void addGUIClient( KXMLGUIClient *client ); signals: void contactSelected( const QString &name ); void contactSelected( const QPixmap &pixmap ); public slots: void setDetailsVisible( bool visible ); void setDetailsToState(); private slots: void setJumpButtonBarVisible( bool visible ); - + void importFromOL(); void extensionModified( const KABC::Addressee::List &list ); void clipboardDataChanged(); void updateActionMenu(); void configureKeyBindings(); void removeVoice(); #ifdef KAB_EMBEDDED void configureResources(); #endif //KAB_EMBEDDED void slotEditorDestroyed( const QString &uid ); void configurationChanged(); void addressBookChanged(); private: void initGUI(); void initActions(); AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, const char *name = 0 ); KXMLGUIClient *mGUIClient; KABC::AddressBook *mAddressBook; ViewManager *mViewManager; // QSplitter *mDetailsSplitter; KDGanttMinimizeSplitter *mExtensionBarSplitter; ViewContainer *mDetails; KDGanttMinimizeSplitter* mMiniSplitter; XXPortManager *mXXPortManager; JumpButtonBar *mJumpButtonBar; IncSearchWidget *mIncSearchWidget; ExtensionManager *mExtensionManager; KCMultiDialog *mConfigureDialog; #ifndef KAB_EMBEDDED KCMultiDialog *mConfigureDialog; LDAPSearchDialog *mLdapSearchDialog; #endif //KAB_EMBEDDED // QDict<AddresseeEditorDialog> mEditorDict; AddresseeEditorDialog *mEditorDialog; bool mReadWrite; bool mModified; bool mIsPart; //US file menu KAction *mActionMail; KAction* mActionPrint; KAction* mActionNewContact; KAction *mActionSave; KAction *mActionEditAddressee; KAction *mActionMailVCard; KAction *mActionQuit; //US edit menu KAction *mActionCopy; KAction *mActionCut; KAction *mActionPaste; KAction *mActionSelectAll; KAction *mActionUndo; KAction *mActionRedo; KAction *mActionDelete; //US settings menu KAction *mActionConfigResources; KAction *mActionConfigKAddressbook; KAction *mActionConfigShortcuts; KAction *mActionConfigureToolbars; KAction *mActionKeyBindings; KToggleAction *mActionJumpBar; KToggleAction *mActionDetails; KAction *mActionWhoAmI; KAction *mActionCategories; KAction *mActionAboutKAddressbook; KAction *mActionDeleteView; QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; //US QAction *mActionSave; QPopupMenu *ImportMenu; QPopupMenu *ExportMenu; //LR additional methods KAction *mActionRemoveVoice; + KAction * mActionImportOL; #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; #endif //KAB_EMBEDDED class KABCorePrivate; KABCorePrivate *d; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED }; #endif diff --git a/kaddressbook/kaddressbook.pro b/kaddressbook/kaddressbook.pro index 761c3e7..bc14e68 100644 --- a/kaddressbook/kaddressbook.pro +++ b/kaddressbook/kaddressbook.pro @@ -1,166 +1,177 @@ TEMPLATE = app CONFIG = qt warn_on TARGET = kapi DESTDIR= ../bin include( ../variables.pri ) INCLUDEPATH += . ./details ./features ./kcmconfigs ./xxport ../microkde ../microkde/kdecore ../microkde/kutils ../microkde/kio/kfile ../microkde/kdeui ../kabc ../ interfaces DEFINES += KAB_EMBEDDED KAB_NOSPLITTER DESKTOP_VERSION unix : { LIBS += ../bin/libmicrokdepim.so LIBS += ../bin/libmicrokde.so LIBS += ../bin/libmicrokabc.so LIBS += ../bin/libmicrokcal.so LIBS += -lldap OBJECTS_DIR = obj/unix MOC_DIR = moc/unix } win32: { DEFINES += _WIN32_ LIBS += ../bin/microkdepim.lib LIBS += ../bin/microkcal.lib LIBS += ../bin/microkde.lib LIBS += ../bin/microkabc.lib QMAKE_LINK += /NODEFAULTLIB:LIBC OBJECTS_DIR = obj/win MOC_DIR = moc/win +LIBS += mfc71u.lib } INTERFACES = \ # filteredit_base.ui \ # kofilterview_base.ui \ HEADERS = \ features/mergewidget.h \ features/distributionlistwidget.h \ kcmconfigs/addresseewidget.h \ kcmconfigs/extensionconfigdialog.h \ kcmconfigs/kcmkabconfig.h \ kcmconfigs/kabconfigwidget.h \ addresseeeditordialog.h \ addresseeeditorwidget.h \ addresseditwidget.h \ addresseeconfig.h \ addresseeutil.h \ emaileditwidget.h \ filtereditdialog.h \ kaddressbookmain.h \ kabprefs.h \ kabcore.h \ viewmanager.h \ extensionmanager.h \ extensionwidget.h \ kaddressbookview.h \ geowidget.h \ imagewidget.h \ incsearchwidget.h \ jumpbuttonbar.h \ phoneeditwidget.h \ secrecywidget.h \ keywidget.h \ nameeditdialog.h \ filter.h \ addviewdialog.h \ configurewidget.h \ viewconfigurewidget.h \ viewconfigurefieldspage.h \ viewconfigurefilterpage.h \ typecombo.h \ undo.h \ undocmds.h \ xxportmanager.h \ xxportobject.h \ xxportselectdialog.h \ details/detailsviewcontainer.h \ details/look_basic.h \ details/look_html.h \ views/kaddressbookiconview.h \ views/kaddressbooktableview.h \ views/kaddressbookcardview.h \ views/configuretableviewdialog.h \ views/configurecardviewdialog.h \ views/cardview.h \ views/colorlistbox.h \ views/contactlistview.h \ xxport/vcard_xxport.h \ xxport/kde2_xxport.h \ xxport/csv_xxport.h \ xxport/csvimportdialog.h \ #details/look_details.h \ #mainwindoiw.h \ # alarmclient.h \ # calendarview.h \ # customlistviewitem.h \ # datenavigator.h SOURCES = \ addresseeeditordialog.cpp \ addresseeeditorwidget.cpp \ addresseditwidget.cpp \ addresseeconfig.cpp \ addresseeutil.cpp \ extensionmanager.cpp \ features/mergewidget.cpp \ features/distributionlistwidget.cpp \ kcmconfigs/addresseewidget.cpp \ kcmconfigs/extensionconfigdialog.cpp \ kcmconfigs/kcmkabconfig.cpp \ kcmconfigs/kabconfigwidget.cpp \ emaileditwidget.cpp \ filtereditdialog.cpp \ mainembedded.cpp \ kaddressbookmain.cpp \ kabcore.cpp \ kabprefs.cpp \ viewmanager.cpp \ kaddressbookview.cpp \ extensionwidget.cpp \ geowidget.cpp \ imagewidget.cpp \ incsearchwidget.cpp \ jumpbuttonbar.cpp \ phoneeditwidget.cpp \ secrecywidget.cpp \ keywidget.cpp \ nameeditdialog.cpp \ filter.cpp \ addviewdialog.cpp \ configurewidget.cpp \ viewconfigurewidget.cpp \ viewconfigurefieldspage.cpp \ viewconfigurefilterpage.cpp \ undo.cpp \ undocmds.cpp \ xxportmanager.cpp \ xxportobject.cpp \ xxportselectdialog.cpp \ details/detailsviewcontainer.cpp \ details/look_basic.cpp \ details/look_html.cpp \ views/kaddressbookiconview.cpp \ views/kaddressbooktableview.cpp \ views/kaddressbookcardview.cpp \ views/configuretableviewdialog.cpp \ views/configurecardviewdialog.cpp \ views/cardview.cpp \ views/contactlistview.cpp \ views/colorlistbox.cpp \ xxport/vcard_xxport.cpp \ xxport/kde2_xxport.cpp \ xxport/csv_xxport.cpp \ xxport/csvimportdialog.cpp \ #details/look_details.cpp \ #mainwindow.cpp \ # calendarview.cpp \ # timespanview.cpp + + +win32: { +HEADERS += ../outport/msoutl9.h \ + kaimportoldialog.h + +SOURCES += ../outport/msoutl9.cpp \ + kaimportoldialog.cpp +} + diff --git a/kaddressbook/kaimportoldialog.cpp b/kaddressbook/kaimportoldialog.cpp new file mode 100644 index 0000000..5e7d7c4 --- a/dev/null +++ b/kaddressbook/kaimportoldialog.cpp @@ -0,0 +1,635 @@ +/* + This file is part of KAddressbook/Pi. + Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <qtooltip.h> +#include <qframe.h> +#include <qpixmap.h> +#include <qlayout.h> +#include <qprogressbar.h> +#include <qwidgetstack.h> +#include <qdatetime.h> +#include <qdir.h> +#include <qapplication.h> +#include <qhbox.h> +#include <qheader.h> +#include <qdatetime.h> +#include <qlistview.h> + +#include <kdebug.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kmessagebox.h> +#include <kfiledialog.h> + +#include <libkdepim/categoryselectdialog.h> +#include <libkdepim/kinputdialog.h> + +#include <libkcal/calendarlocal.h> +#include <libkcal/icalformat.h> + +#include <kabc/addresseelist.h> +#include <kabc/phonenumber.h> + +#include "kaimportoldialog.h" + +#include "../outport/msoutl9.h" +#include <ole2.h> +#include <comutil.h> +_Application gOlAppAB; + +QDateTime mDdate2Qdtr( DATE dt) +{ + COleDateTime odt; + SYSTEMTIME st; + odt = dt; + if ( odt.GetStatus() != 0 ) + return QDateTime(); + odt.GetAsSystemTime(st); + if ( st.wYear > 4000 ) // this program as a year 4000 bug! + return QDateTime(); + // it seems so, that 1.1.4501 indicates: DATE invalid + QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); + return qdt; +} + +class OLEListViewItem : public QCheckListItem +{ + public: + OLEListViewItem( QListView *parent, QString text ) : + QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; }; + OLEListViewItem( QListViewItem *after, QString text ) : + QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; }; + ~OLEListViewItem() {}; + void setData( DWORD data ) {mData= data; }; + DWORD data() { return mData ;}; + private: + DWORD mData; +}; + +KAImportOLdialog::KAImportOLdialog( const QString &caption, + KABC::AddressBook * aBook, QWidget *parent ) : + KDialogBase( Plain, caption, User1 | Close, Ok, + parent, caption, true, false, i18n("Import!") ) +{ + QHBox * mw = new QHBox( this ); + setMainWidget( mw ); + mListView = new QListView( mw ); + mListView->addColumn(i18n("Select Folder to import")); + mListView->addColumn(i18n("Content Type")); + mABook = aBook; + connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); + setupFolderView(); + resize( sizeHint().width()+50, sizeHint().height()+50 ); +} + +KAImportOLdialog::~KAImportOLdialog() +{ + +} + +KABC::Addressee::List KAImportOLdialog::getAddressList() +{ + return mAList; +} +void KAImportOLdialog::setupFolderView() +{ + SCODE sc = ::OleInitialize(NULL); + if ( FAILED ( sc ) ) { + KMessageBox::information(this,"OLE initialisation failed"); + return; + } + + if(!gOlAppAB.CreateDispatch(_T("Outlook.Application"),NULL)){ + KMessageBox::information(this,"Sorry, cannot access Outlook"); + return ; + } + MAPIFolder mfInbox; + MAPIFolder mfRoot; + CString szName; + _NameSpace olNS; + olNS = gOlAppAB.GetNamespace(_T("MAPI")); + mfInbox = olNS.GetDefaultFolder(6); + mfRoot = mfInbox.GetParent(); + szName = mfRoot.GetName(); + long iType = mfRoot.GetDefaultItemType(); + QString mes; + mes = QString::fromUcs2( szName.GetBuffer() ); + OLEListViewItem * root = new OLEListViewItem( mListView, mes ); + mfRoot.m_lpDispatch->AddRef(); + addFolder( root, mfRoot.m_lpDispatch ); + root->setOpen( true ); + mListView->setSortColumn( 0 ); + mListView->sort( ); +} + + +void KAImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) +{ + MAPIFolder mfParent(dispParent), mfChild; + _Folders folders; + _variant_t fndx((long)0); + CString szName; + long iType; + OLEListViewItem* hChild; + + folders = mfParent.GetFolders(); + for(int i=1; i <= folders.GetCount(); ++i) + { + fndx = (long)i; + mfChild = folders.Item(fndx.Detach()); + mfChild.m_lpDispatch->AddRef(); + szName = mfChild.GetName(); + iType = mfChild.GetDefaultItemType(); + hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) ); + if ( iType != 2) + hChild->setEnabled( false ); + QString ts; + switch( iType ) { + case 0: + ts = i18n("Mail"); + break; + case 1: + ts = i18n("Calendar"); + break; + case 2: + ts = i18n("Contacts"); + break; + case 3: + ts = i18n("Todos"); + break; + case 4: + ts = i18n("Journals"); + break; + case 5: + ts = i18n("Notes"); + break; + default: + ts = i18n("Unknown"); + } + hChild->setText( 1,ts); + hChild->setData( (DWORD) mfChild.m_lpDispatch ); + mfChild.m_lpDispatch->AddRef(); + addFolder(hChild, mfChild.m_lpDispatch); + } +} + +void KAImportOLdialog::slotApply() +{ + importedItems = 0; + OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); + while ( child ) { + if ( child->isOn() ) + readContactData( child->data() ); + child = (OLEListViewItem*) child->itemBelow(); + } + QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); + KMessageBox::information(this,mes); +} +void KAImportOLdialog::readContactData( DWORD folder ) +{ + + LPDISPATCH dispItem = (LPDISPATCH)folder; + dispItem->AddRef(); + MAPIFolder mf(dispItem); + mf.m_lpDispatch->AddRef(); + _Items folderItems; + _variant_t indx((long)0); + LPDISPATCH itm; + int i; + folderItems = mf.GetItems(); + QProgressBar bar( folderItems.GetCount(),0 ); + bar.setCaption (i18n("Importing - close to abort!") ); + int h = bar.sizeHint().height() ; + int w = 300; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + for(i=1; i <= folderItems.GetCount(); ++i) + { + qApp->processEvents(); + if ( ! bar.isVisible() ) + return ; + bar.setProgress( i ); + indx = (long)i; + itm = folderItems.Item(indx.Detach()); + _ContactItem * pItem = (_ContactItem *)&itm; + ol2kapiContact( pItem ); + itm->Release(); + } +} +void KAImportOLdialog::slotOk() +{ + QDialog::accept(); +} + +void KAImportOLdialog::ol2kapiContact( _ContactItem * aItem ) +{ + KABC::Addressee addressee; + + addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer())); + + //addressee.setName( const QString &name ); + //addressee.setFormattedName( const QString &formattedName ); + addressee.setFamilyName( QString::fromUcs2(aItem->GetLastName().GetBuffer()) ); + addressee.setGivenName( QString::fromUcs2(aItem->GetFirstName().GetBuffer()) ); + addressee.setAdditionalName( QString::fromUcs2(aItem->GetMiddleName().GetBuffer()) ); + addressee.setPrefix(QString::fromUcs2(aItem->GetTitle().GetBuffer()) ); + addressee.setSuffix( QString::fromUcs2(aItem->GetSuffix().GetBuffer()) ); + addressee.setNickName( QString::fromUcs2(aItem->GetNickName().GetBuffer()) ); + QDateTime dtb = mDdate2Qdtr(aItem->GetBirthday()); + if ( dtb.isValid() ) + addressee.setBirthday( mDdate2Qdtr(aItem->GetBirthday())); + + //QString::fromUcs2(aItem->.GetBuffer()) + //addressee.setMailer( const QString &mailer ); + //addressee.setTimeZone( const TimeZone &timeZone ); + //addressee.setGeo( const Geo &geo ); + //addressee.setTitle( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) );// titel is the prefix + addressee.setRole( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) ); + addressee.setOrganization( QString::fromUcs2(aItem->GetCompanyName().GetBuffer()) ); + addressee.setNote( QString::fromUcs2(aItem->GetBody().GetBuffer()) ); + + addressee.setProductId( QString::fromUcs2(aItem->GetCustomerID().GetBuffer()) ); + //addressee.setRevision( const QDateTime &revision ); + // addressee.setSortString( const QString &sortString ); + addressee.setUrl( QString::fromUcs2(aItem->GetWebPage().GetBuffer()) ); + + QString tempS; + tempS = QString::fromUcs2(aItem->GetNetMeetingAlias().GetBuffer())+" AT SERVER: " +QString::fromUcs2(aItem->GetNetMeetingServer().GetBuffer()); + if ( tempS.length() > 12 ) + addressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", tempS ); + tempS = QString::fromUcs2(aItem->GetSpouse().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tempS ); + tempS = QString::fromUcs2(aItem->GetManagerName().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tempS ); + tempS = QString::fromUcs2(aItem->GetAssistantName().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tempS ); + tempS = QString::fromUcs2(aItem->GetDepartment().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-Department", tempS ); + tempS = QString::fromUcs2(aItem->GetOfficeLocation().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-Office",tempS ); + tempS = QString::fromUcs2(aItem->GetProfession().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-Profession", tempS ); + dtb = mDdate2Qdtr(aItem->GetAnniversary()); + if (dtb.isValid() ) { + QString dt = KGlobal::locale()->formatDate( dtb.date() , true, KLocale::ISODate); + addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); + } + int sec = aItem->GetSensitivity() ; + if ( sec > 1 )// mapping pers -> private + --sec; + addressee.setSecrecy( sec ); + //addressee.setLogo( const Picture &logo ); + //addressee.setPhoto( const Picture &photo ); + //addressee.setSound( const Sound &sound ); + //addressee.setAgent( const Agent &agent ); + QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()); + addressee.setCategories( QStringList::split( ";", cat )); + + QString phoneS; + + phoneS = QString::fromUcs2( aItem->GetAssistantTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Voice ) ); + phoneS = QString::fromUcs2( aItem->GetBusinessTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work ) ); + phoneS = QString::fromUcs2( aItem->GetBusiness2TelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work ) ); + phoneS = QString::fromUcs2( aItem->GetBusinessFaxNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Fax ) ); + phoneS = QString::fromUcs2( aItem->GetCarTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Car ) ); + phoneS = QString::fromUcs2( aItem->GetHomeTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home ) ); + phoneS = QString::fromUcs2( aItem->GetHome2TelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home ) ); + phoneS = QString::fromUcs2( aItem->GetHomeFaxNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home + KABC::PhoneNumber::Fax ) ); + phoneS = QString::fromUcs2( aItem->GetISDNNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Isdn ) ); + phoneS = QString::fromUcs2( aItem->GetMobileTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Cell ) ); + phoneS = QString::fromUcs2( aItem->GetOtherFaxNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Fax ) ); + phoneS = QString::fromUcs2( aItem->GetOtherTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Voice ) ); + phoneS = QString::fromUcs2( aItem->GetPagerNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Pager ) ); + phoneS = QString::fromUcs2( aItem->GetPrimaryTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Pref ) ); + phoneS = QString::fromUcs2( aItem->GetTTYTDDTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Modem ) ); + phoneS = QString::fromUcs2( aItem->GetTelexNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Fax + KABC::PhoneNumber::Bbs ) ); + phoneS = QString::fromUcs2( aItem->GetCompanyMainTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Pref ) ); + phoneS = QString::fromUcs2( aItem->GetRadioTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Video ) ); + phoneS = QString::fromUcs2( aItem->GetCallbackTelephoneNumber().GetBuffer()); + if ( ! phoneS.isEmpty()) + addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Voice + KABC::PhoneNumber::Pref ) ); + + bool preferred = true; + phoneS = QString::fromUcs2( aItem->GetEmail1Address().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressee.insertEmail(phoneS , preferred ); + preferred = false; + } + phoneS = QString::fromUcs2( aItem->GetEmail2Address().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressee.insertEmail(phoneS , preferred ); + preferred = false; + } + phoneS = QString::fromUcs2( aItem->GetEmail3Address().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressee.insertEmail(phoneS , preferred ); + preferred = false; + } + // is this the number of the preferred email? + // long GetSelectedMailingAddress();??? + + KABC::Address addressHome; + KABC::Address* addressAdd = &addressHome; + bool insert = false; + phoneS = QString::fromUcs2( aItem->GetHomeAddressCountry().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setCountry(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddressState().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setRegion(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddressCity().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setLocality(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddressPostalCode().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostalCode(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddressPostOfficeBox().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostOfficeBox(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddressStreet().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setStreet(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetHomeAddress().GetBuffer()); + if ( ! phoneS.isEmpty()) { + // redundant !addressAdd->setExtended(phoneS ); + // insert = true; + } + addressAdd->setType( KABC::Address::Home ); + if ( insert ) + addressee.insertAddress( *addressAdd ); + // ++++++++++++++++++++++ end of address + + KABC::Address addressWork; + addressAdd = &addressWork; + insert = false; + phoneS = QString::fromUcs2( aItem->GetBusinessAddressCountry().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setCountry(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddressState().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setRegion(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddressCity().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setLocality(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostalCode().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostalCode(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostOfficeBox().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostOfficeBox(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddressStreet().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setStreet(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetBusinessAddress().GetBuffer()); + if ( ! phoneS.isEmpty()) { + // redundant !addressAdd->setExtended(phoneS ); + // insert = true; + } + addressAdd->setType( KABC::Address::Work ); + if ( insert ) + addressee.insertAddress( *addressAdd ); + // ++++++++++++++++++++++ end of address + + KABC::Address addressOther; + addressAdd = &addressOther; + insert = false; + phoneS = QString::fromUcs2( aItem->GetOtherAddressCountry().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setCountry(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddressState().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setRegion(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddressCity().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setLocality(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddressPostalCode().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostalCode(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddressPostOfficeBox().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostOfficeBox(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddressStreet().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setStreet(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetOtherAddress().GetBuffer()); + if ( ! phoneS.isEmpty()) { + // redundant !addressAdd->setExtended(phoneS ); + //insert = true; + } + //addressAdd->setId( ); + if ( insert ) + addressee.insertAddress( *addressAdd ); + // ++++++++++++++++++++++ end of address + KABC::Address addressMail; + addressAdd = &addressMail; + insert = false; + phoneS = QString::fromUcs2( aItem->GetMailingAddressCountry().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setCountry(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddressState().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setRegion(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddressCity().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setLocality(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddressPostalCode().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostalCode(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddressPostOfficeBox().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setPostOfficeBox(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddressStreet().GetBuffer()); + if ( ! phoneS.isEmpty()) { + addressAdd->setStreet(phoneS ); + insert = true; + } + phoneS = QString::fromUcs2( aItem->GetMailingAddress().GetBuffer()); + if ( ! phoneS.isEmpty()) { + // redundant ! addressAdd->setExtended(phoneS ); + // insert = true; + } + addressAdd->setType( KABC::Address::Postal ); + if ( insert ) { + addressee.insertAddress( *addressAdd ); + } + // the following code is disabled + // it does not seem to be useful +#if 0 + if ( insert ) { + addressAdd->setType( KABC::Address::Home ); + if ( addressMail == addressHome ) { + addressHome.setType( KABC::Address::Postal+ KABC::Address::Home ); + addressee.insertAddress( addressHome ); + } else { + addressAdd->setType( KABC::Address::Work ); + if ( addressMail == addressWork ){ + addressWork.setType( KABC::Address::Postal+ KABC::Address::Work ); + addressee.insertAddress( addressWork ); + + } else { + addressAdd->setType( 0 ); + if ( addressOther == addressMail ){ + addressOther.setType( KABC::Address::Postal ); + addressee.insertAddress( addressOther ); + } else { + addressee.insertAddress( *addressAdd ); + } + } + } + } +#endif + // ++++++++++++++++++++++ end of ALL addresses + //GetUserProperties(); + tempS = QString::fromUcs2(aItem->GetInternetFreeBusyAddress().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-FreeBusyUrl", tempS ); + tempS = QString::fromUcs2(aItem->GetChildren().GetBuffer()); + if ( !tempS.isEmpty() ) + addressee.insertCustom( "KADDRESSBOOK", "X-Children", tempS ); + int gen = aItem->GetGender(); + if ( gen != 0 ) { // 0 undef - 1 female - 2 male + if ( gen == 1 ) + addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); + else + addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); + } + +#if 0 + // pending + - IM address: no clue where to get info about the helper ID + -custom fields: difficult to implement - not implemented + -keys: makes no sense +#endif + + if ( addAddressee( addressee )) + ++importedItems; +} +void KAImportOLdialog::slotCancel() +{ + reject(); +} + +bool KAImportOLdialog::addAddressee( KABC::Addressee a ) +{ + bool add = true; + KABC::Addressee::List::Iterator it; + for ( it = mAList.begin(); it != mAList.end(); ++it ) { + if ( (*it).uid() == a.uid() ) { + add = false; + break; + } + } + if ( add ) + mAList.append ( a ); + return add; +} diff --git a/kaddressbook/kaimportoldialog.h b/kaddressbook/kaimportoldialog.h new file mode 100644 index 0000000..41ea5f8 --- a/dev/null +++ b/kaddressbook/kaimportoldialog.h @@ -0,0 +1,85 @@ +/* + This file is part of KOrganizer. + Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ +#ifndef KOINCIDENCEEDITOR_H +#define KOINCIDENCEEDITOR_H + +#include <kdialogbase.h> + +#include <afxdisp.h> + +#include <kabc/addressee.h> +#include <kabc/addressbook.h> + +class QDateTime; +class QListView; +class OLEListViewItem; +class _ContactItem; + + +//using namespace KABC; +//class KABC::AddressBook; + +/** + This is the base class for the calendar component editors. +*/ +class KAImportOLdialog : public KDialogBase +{ + Q_OBJECT + public: + /** + Construct new IncidenceEditor. + */ + KAImportOLdialog( const QString &caption, KABC::AddressBook * aBook, + QWidget *parent ); + ~KAImportOLdialog(); + + /** Initialize editor. This function creates the tab widgets. */ + void init(); + KABC::Addressee::List getAddressList(); + public slots: + + + signals: + + protected slots: + void slotApply(); + void slotOk(); + void slotCancel(); + + protected: + void setupFolderView(); + void addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent); + void readContactData( DWORD folder ); + void ol2kapiContact( _ContactItem * ); + + KABC::AddressBook * mABook; + QListView * mListView; + KABC::Addressee::List mAList; + bool addAddressee( KABC::Addressee a ); + private: + int importedItems; +}; + +#endif + + |