00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qclipboard.h>
00025 #include <qdir.h>
00026 #include <qfile.h>
00027 #include <qlayout.h>
00028 #include <qregexp.h>
00029 #include <qvbox.h>
00030
00031 #include <kabc/addresseelist.h>
00032 #include <kabc/errorhandler.h>
00033 #include <kabc/resource.h>
00034 #include <kabc/stdaddressbook.h>
00035 #include <kabc/vcardconverter.h>
00036 #include <kabc/resourcefile.h>
00037 #include <kaboutdata.h>
00038 #include <kaccelmanager.h>
00039 #include <kapplication.h>
00040 #include <dcopclient.h>
00041 #include <kactionclasses.h>
00042 #include <kcmdlineargs.h>
00043 #include <kcmultidialog.h>
00044 #include <kdebug.h>
00045 #include <kdeversion.h>
00046 #include <kimproxy.h>
00047 #include <klocale.h>
00048 #include <kmessagebox.h>
00049 #include <kprinter.h>
00050 #include <kprotocolinfo.h>
00051 #include <kresources/selectdialog.h>
00052 #include <kstandarddirs.h>
00053 #include <kstatusbar.h>
00054 #include <kstdguiitem.h>
00055 #include <ktempfile.h>
00056 #include <kxmlguiclient.h>
00057 #include <ktoolbar.h>
00058 #include <libkdepim/addresseeview.h>
00059 #include <libkdepim/categoryeditdialog.h>
00060 #include <libkdepim/categoryselectdialog.h>
00061
00062 #include "addresseeutil.h"
00063 #include "addresseeeditordialog.h"
00064 #include "extensionmanager.h"
00065 #include "filterselectionwidget.h"
00066 #include "incsearchwidget.h"
00067 #include "jumpbuttonbar.h"
00068 #include "kablock.h"
00069 #include "kabprefs.h"
00070 #include "kaddressbookservice.h"
00071 #include "kaddressbookiface.h"
00072 #include "ldapsearchdialog.h"
00073 #include "locationmap.h"
00074 #include "printing/printingwizard.h"
00075 #include "searchmanager.h"
00076 #include "undocmds.h"
00077 #include "viewmanager.h"
00078 #include "xxportmanager.h"
00079
00080 #include "kabcore.h"
00081
00082 KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent,
00083 const QString &file, const char *name )
00084 : KAB::Core( client, parent, name ), mStatusBar( 0 ), mViewManager( 0 ),
00085 mExtensionManager( 0 ), mCategorySelectDialog( 0 ), mCategoryEditDialog( 0 ),
00086 mLdapSearchDialog( 0 ), mReadWrite( readWrite ), mModified( false )
00087 {
00088 mWidget = new QWidget( parent, name );
00089
00090 mIsPart = !parent->isA( "KAddressBookMain" );
00091
00092 if ( file.isEmpty() ) {
00093 mAddressBook = KABC::StdAddressBook::self( true );
00094 } else {
00095 kdDebug(5720) << "KABCore(): document '" << file << "'" << endl;
00096 mAddressBook = new KABC::AddressBook;
00097 mAddressBook->addResource( new KABC::ResourceFile( file ) );
00098 if ( !mAddressBook->load() ) {
00099 KMessageBox::error( parent, i18n("Unable to load '%1'.").arg( file ) );
00100 }
00101 }
00102 mAddressBook->setErrorHandler( new KABC::GuiErrorHandler( mWidget ) );
00103
00104 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
00105 "X-Department", "KADDRESSBOOK" );
00106 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
00107 "X-Profession", "KADDRESSBOOK" );
00108 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
00109 "X-AssistantsName", "KADDRESSBOOK" );
00110 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
00111 "X-ManagersName", "KADDRESSBOOK" );
00112 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
00113 "X-SpousesName", "KADDRESSBOOK" );
00114 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
00115 "X-Office", "KADDRESSBOOK" );
00116 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
00117 "X-IMAddress", "KADDRESSBOOK" );
00118 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
00119 "X-Anniversary", "KADDRESSBOOK" );
00120
00121 mSearchManager = new KAB::SearchManager( mAddressBook, parent );
00122
00123 connect( mSearchManager, SIGNAL( contactsUpdated() ),
00124 this, SIGNAL( contactsUpdated() ) );
00125
00126 initGUI();
00127
00128 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
00129 SLOT( addressBookChanged() ) );
00130
00131 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
00132 SLOT( addressBookChanged() ) );
00133
00134 mIncSearchWidget->setFocus();
00135
00136 connect( mViewManager, SIGNAL( selected( const QString& ) ),
00137 SLOT( setContactSelected( const QString& ) ) );
00138 connect( mViewManager, SIGNAL( executed( const QString& ) ),
00139 SLOT( editContact( const QString& ) ) );
00140 connect( mViewManager, SIGNAL( modified() ),
00141 SLOT( setModified() ) );
00142 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
00143 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
00144 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ),
00145 this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
00146 connect( mExtensionManager, SIGNAL( deleted( const QStringList& ) ),
00147 this, SLOT( extensionDeleted( const QStringList& ) ) );
00148
00149 connect( mXXPortManager, SIGNAL( modified() ),
00150 SLOT( setModified() ) );
00151
00152 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QStringList& ) ),
00153 SLOT( incrementalJumpButtonSearch( const QStringList& ) ) );
00154 connect( mViewManager, SIGNAL( sortFieldChanged() ),
00155 mJumpButtonBar, SLOT( updateButtons() ) );
00156 connect( mIncSearchWidget, SIGNAL( doReset() ),
00157 mJumpButtonBar, SLOT( reset() ) );
00158
00159 connect( mDetails, SIGNAL( highlightedMessage( const QString& ) ),
00160 SLOT( detailsHighlighted( const QString& ) ) );
00161
00162 mAddressBookService = new KAddressBookService( this );
00163
00164 mSearchManager->reload();
00165
00166 setModified( false );
00167
00168 KAcceleratorManager::manage( mWidget );
00169
00170 mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() );
00171 }
00172
00173 KABCore::~KABCore()
00174 {
00175 saveSettings();
00176 KABPrefs::instance()->writeConfig();
00177
00178 mAddressBook->disconnect();
00179
00180 mAddressBook = 0;
00181 KABC::StdAddressBook::close();
00182 mKIMProxy = 0;
00183 }
00184
00185 void KABCore::restoreSettings()
00186 {
00187 bool state = KABPrefs::instance()->mJumpButtonBarVisible;
00188 mActionJumpBar->setChecked( state );
00189 setJumpButtonBarVisible( state );
00190
00191 state = KABPrefs::instance()->mDetailsPageVisible;
00192 mActionDetails->setChecked( state );
00193 setDetailsVisible( state );
00194
00195 mViewManager->restoreSettings();
00196 mExtensionManager->restoreSettings();
00197
00198 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
00199
00200 QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
00201 if ( splitterSize.count() == 0 ) {
00202 splitterSize.append( mDetailsSplitter->height() / 2 );
00203 splitterSize.append( mDetailsSplitter->height() / 2 );
00204 }
00205 mExtensionBarSplitter->setSizes( splitterSize );
00206
00207 splitterSize = KABPrefs::instance()->mDetailsSplitter;
00208 if ( splitterSize.count() == 0 ) {
00209 splitterSize.append( 360 );
00210 splitterSize.append( 260 );
00211 }
00212 mDetailsSplitter->setSizes( splitterSize );
00213
00214 }
00215
00216 void KABCore::saveSettings()
00217 {
00218 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
00219 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
00220
00221 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
00222 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
00223
00224 mExtensionManager->saveSettings();
00225 mViewManager->saveSettings();
00226
00227 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
00228 }
00229
00230 KABC::AddressBook *KABCore::addressBook() const
00231 {
00232 return mAddressBook;
00233 }
00234
00235 KConfig *KABCore::config() const
00236 {
00237 return KABPrefs::instance()->config();
00238 }
00239
00240 KActionCollection *KABCore::actionCollection() const
00241 {
00242 return guiClient()->actionCollection();
00243 }
00244
00245 KABC::Field *KABCore::currentSortField() const
00246 {
00247 return mViewManager->currentSortField();
00248 }
00249
00250 QStringList KABCore::selectedUIDs() const
00251 {
00252 return mViewManager->selectedUids();
00253 }
00254
00255 KABC::Resource *KABCore::requestResource( QWidget *parent )
00256 {
00257 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
00258
00259 QPtrList<KRES::Resource> kresResources;
00260 QPtrListIterator<KABC::Resource> resIt( kabcResources );
00261 KABC::Resource *resource;
00262 while ( ( resource = resIt.current() ) != 0 ) {
00263 ++resIt;
00264 if ( !resource->readOnly() ) {
00265 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
00266 if ( res )
00267 kresResources.append( res );
00268 }
00269 }
00270
00271 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
00272 return static_cast<KABC::Resource*>( res );
00273 }
00274
00275 QWidget *KABCore::widget() const
00276 {
00277 return mWidget;
00278 }
00279
00280 KAboutData *KABCore::createAboutData()
00281 {
00282 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
00283 "3.3.1", I18N_NOOP( "The KDE Address Book" ),
00284 KAboutData::License_GPL_V2,
00285 I18N_NOOP( "(c) 1997-2004, The KDE PIM Team" ) );
00286 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer" ), "tokoe@kde.org" );
00287 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author" ) );
00288 about->addAuthor( "Cornelius Schumacher",
00289 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export" ),
00290 "schumacher@kde.org" );
00291 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign" ),
00292 "mpilone@slac.com" );
00293 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
00294 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
00295 about->addAuthor( "Mischel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup" ),
00296 "michel@klaralvdalens-datakonsult.se" );
00297 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup" ),
00298 "hansen@kde.org" );
00299
00300 return about;
00301 }
00302
00303 void KABCore::setStatusBar( KStatusBar *statusBar )
00304 {
00305 mStatusBar = statusBar;
00306 }
00307
00308 KStatusBar *KABCore::statusBar() const
00309 {
00310 return mStatusBar;
00311 }
00312
00313 void KABCore::setContactSelected( const QString &uid )
00314 {
00315 KABC::Addressee addr = mAddressBook->findByUid( uid );
00316 if ( !mDetails->isHidden() )
00317 mDetails->setAddressee( addr );
00318
00319 mExtensionManager->setSelectionChanged();
00320
00321
00322 bool selected = !uid.isEmpty();
00323
00324 if ( mReadWrite ) {
00325 mActionCut->setEnabled( selected );
00326 mActionPaste->setEnabled( selected );
00327 }
00328
00329 mActionCopy->setEnabled( selected );
00330 mActionDelete->setEnabled( selected );
00331 mActionEditAddressee->setEnabled( selected );
00332 mActionStoreAddresseeIn->setEnabled( selected );
00333 mActionMail->setEnabled( selected );
00334 mActionMailVCard->setEnabled( selected );
00335 mActionChat->setEnabled( selected && mKIMProxy && mKIMProxy->initialize() );
00336 mActionWhoAmI->setEnabled( selected );
00337 mActionCategories->setEnabled( selected );
00338 mActionMerge->setEnabled( selected );
00339 }
00340
00341 void KABCore::sendMail()
00342 {
00343 sendMail( mViewManager->selectedEmails().join( ", " ) );
00344 }
00345
00346 void KABCore::sendMail( const QString& email )
00347 {
00348 kapp->invokeMailer( email, "" );
00349 }
00350
00351 void KABCore::mailVCard()
00352 {
00353 QStringList uids = mViewManager->selectedUids();
00354 if ( !uids.isEmpty() )
00355 mailVCard( uids );
00356 }
00357
00358 void KABCore::mailVCard( const QStringList& uids )
00359 {
00360
00361 KURL::List urls;
00362
00363
00364 KTempFile tempDir;
00365 if ( tempDir.status() != 0 ) {
00366 kdWarning() << strerror( tempDir.status() ) << endl;
00367 return;
00368 }
00369
00370 QString dirName = tempDir.name();
00371 tempDir.unlink();
00372 QDir().mkdir( dirName, true );
00373
00374 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
00375 KABC::Addressee a = mAddressBook->findByUid( *it );
00376
00377 if ( a.isEmpty() )
00378 continue;
00379
00380 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
00381
00382 QString fileName = dirName + "/" + name;
00383
00384 QFile outFile(fileName);
00385 if ( outFile.open( IO_WriteOnly ) ) {
00386 KABC::VCardConverter converter;
00387 KABC::Addressee::List list;
00388 list.append( a );
00389 QString vcard = converter.createVCards( list, KABC::VCardConverter::v3_0 );
00390
00391 QTextStream t( &outFile );
00392 t.setEncoding( QTextStream::UnicodeUTF8 );
00393 t << vcard;
00394
00395 outFile.close();
00396
00397 KURL url( fileName );
00398 url.setFileEncoding( "UTF-8" );
00399 urls.append( url );
00400 }
00401 }
00402 kapp->invokeMailer( QString::null, QString::null, QString::null,
00403 QString::null,
00404 QString::null,
00405 QString::null,
00406 urls.toStringList() );
00407 }
00408
00409 void KABCore::startChat()
00410 {
00411 QStringList uids = mViewManager->selectedUids();
00412 if ( !uids.isEmpty() )
00413 mKIMProxy->chatWithContact( uids.first() );
00414 }
00415
00416 void KABCore::browse( const QString& url )
00417 {
00418 kapp->invokeBrowser( url );
00419 }
00420
00421 void KABCore::selectAllContacts()
00422 {
00423 mViewManager->setSelected( QString::null, true );
00424 }
00425
00426 void KABCore::deleteContacts()
00427 {
00428 QStringList uidList = mViewManager->selectedUids();
00429
00430 deleteContacts( uidList );
00431 }
00432
00433 void KABCore::deleteContacts( const QStringList &uids )
00434 {
00435 if ( uids.count() > 0 ) {
00436 QStringList names;
00437 QStringList::ConstIterator it = uids.begin();
00438 while ( it != uids.end() ) {
00439 KABC::Addressee addr = mAddressBook->findByUid( *it );
00440 names.append( addr.realName().isEmpty() ? addr.preferredEmail() : addr.realName() );
00441 ++it;
00442 }
00443
00444 if ( KMessageBox::warningContinueCancelList( mWidget, i18n( "Do you really want to delete these contacts?" ),
00445 names, "", KGuiItem( i18n("&Delete"), "editdelete") ) == KMessageBox::Cancel )
00446 return;
00447
00448 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
00449 UndoStack::instance()->push( command );
00450 RedoStack::instance()->clear();
00451
00452
00453 setContactSelected( QString::null );
00454 setModified( true );
00455 }
00456 }
00457
00458 void KABCore::copyContacts()
00459 {
00460 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
00461
00462 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
00463
00464 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
00465
00466 QClipboard *cb = QApplication::clipboard();
00467 cb->setText( clipText );
00468 }
00469
00470 void KABCore::cutContacts()
00471 {
00472 QStringList uidList = mViewManager->selectedUids();
00473
00474 if ( uidList.size() > 0 ) {
00475 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
00476 UndoStack::instance()->push( command );
00477 RedoStack::instance()->clear();
00478
00479 setModified( true );
00480 }
00481 }
00482
00483 void KABCore::pasteContacts()
00484 {
00485 QClipboard *cb = QApplication::clipboard();
00486
00487 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
00488
00489 pasteContacts( list );
00490 }
00491
00492 void KABCore::pasteContacts( KABC::Addressee::List &list )
00493 {
00494 KABC::Resource *resource = requestResource( mWidget );
00495 KABC::Addressee::List::Iterator it;
00496 for ( it = list.begin(); it != list.end(); ++it )
00497 (*it).setResource( resource );
00498
00499 PwPasteCommand *command = new PwPasteCommand( this, list );
00500 UndoStack::instance()->push( command );
00501 RedoStack::instance()->clear();
00502
00503 setModified( true );
00504 }
00505
00506 void KABCore::mergeContacts()
00507 {
00508 KABC::Addressee::List list = mViewManager->selectedAddressees();
00509 if ( list.count() < 2 )
00510 return;
00511
00512 KABC::Addressee addr = mergeContacts( list );
00513
00514 KABC::Addressee::List::Iterator it = list.begin();
00515 ++it;
00516 while ( it != list.end() ) {
00517 mAddressBook->removeAddressee( *it );
00518 ++it;
00519 }
00520
00521 mAddressBook->insertAddressee( addr );
00522
00523 mSearchManager->reload();
00524 }
00525
00526 void KABCore::setWhoAmI()
00527 {
00528 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
00529
00530 if ( addrList.count() > 1 ) {
00531 KMessageBox::sorry( mWidget, i18n( "Please select only one contact." ) );
00532 return;
00533 }
00534
00535 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
00536 if ( KMessageBox::questionYesNo( mWidget, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
00537 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self( true ) )->setWhoAmI( addrList[ 0 ] );
00538 }
00539
00540 void KABCore::incrementalTextSearch( const QString& text )
00541 {
00542 setContactSelected( QString::null );
00543 mSearchManager->search( text, mIncSearchWidget->currentField() );
00544 }
00545
00546 void KABCore::incrementalJumpButtonSearch( const QStringList& characters )
00547 {
00548 setContactSelected( QString::null );
00549 mSearchManager->setJumpButtonFilter( characters, mViewManager->currentSortField() );
00550 }
00551
00552 void KABCore::setModified()
00553 {
00554 setModified( true );
00555 }
00556
00557 void KABCore::setModified( bool modified )
00558 {
00559 mModified = modified;
00560 mActionSave->setEnabled( mModified );
00561
00562 mSearchManager->reload();
00563 }
00564
00565 bool KABCore::modified() const
00566 {
00567 return mModified;
00568 }
00569
00570 void KABCore::contactModified( const KABC::Addressee &addr )
00571 {
00572 Command *command = 0;
00573
00574
00575 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
00576 if ( origAddr.isEmpty() ) {
00577 command = new PwNewCommand( mAddressBook, addr );
00578 } else {
00579 command = new PwEditCommand( mAddressBook, origAddr, addr );
00580 }
00581
00582 UndoStack::instance()->push( command );
00583 RedoStack::instance()->clear();
00584
00585 setContactSelected( addr.uid() );
00586 setModified( true );
00587 }
00588
00589 void KABCore::newContact()
00590 {
00591 AddresseeEditorDialog *dialog = 0;
00592
00593 KABC::Resource* resource = requestResource( mWidget );
00594
00595 if ( resource ) {
00596 KABC::Addressee addr;
00597 addr.setResource( resource );
00598
00599 if ( !KABLock::self( mAddressBook )->lock( addr.resource() ) )
00600 return;
00601
00602 dialog = createAddresseeEditorDialog( mWidget );
00603 dialog->setAddressee( addr );
00604 } else
00605 return;
00606
00607 mEditorDict.insert( dialog->addressee().uid(), dialog );
00608
00609 dialog->show();
00610 }
00611
00612 void KABCore::addEmail( const QString &aStr )
00613 {
00614 QString fullName, email;
00615
00616 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
00617
00618
00619 bool found = false;
00620 QStringList emailList;
00621 KABC::AddressBook::Iterator it;
00622 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
00623 emailList = (*it).emails();
00624 if ( emailList.contains( email ) > 0 ) {
00625 found = true;
00626 (*it).setNameFromString( fullName );
00627 editContact( (*it).uid() );
00628 }
00629 }
00630
00631 if ( !found ) {
00632 KABC::Addressee addr;
00633 addr.setNameFromString( fullName );
00634 addr.insertEmail( email, true );
00635
00636 mAddressBook->insertAddressee( addr );
00637 mViewManager->refreshView( addr.uid() );
00638 editContact( addr.uid() );
00639 }
00640 }
00641
00642 void KABCore::importVCard( const KURL &url )
00643 {
00644 mXXPortManager->importVCard( url );
00645 }
00646
00647 void KABCore::importVCard( const QString &vCardURL )
00648 {
00649 mXXPortManager->importVCard( vCardURL );
00650 }
00651
00652 void KABCore::editContact( const QString &uid )
00653 {
00654 if ( mExtensionManager->isQuickEditVisible() )
00655 return;
00656
00657
00658 QString localUID = uid;
00659 if ( localUID.isNull() ) {
00660 QStringList uidList = mViewManager->selectedUids();
00661 if ( uidList.count() > 0 )
00662 localUID = *( uidList.at( 0 ) );
00663 }
00664
00665 KABC::Addressee addr = mAddressBook->findByUid( localUID );
00666 if ( !addr.isEmpty() ) {
00667 AddresseeEditorDialog *dialog = mEditorDict.find( addr.uid() );
00668 if ( !dialog ) {
00669
00670 if ( !addr.resource()->readOnly() )
00671 if ( !KABLock::self( mAddressBook )->lock( addr.resource() ) )
00672 return;
00673
00674 dialog = createAddresseeEditorDialog( mWidget );
00675
00676 mEditorDict.insert( addr.uid(), dialog );
00677
00678 dialog->setAddressee( addr );
00679 }
00680
00681 dialog->raise();
00682 dialog->show();
00683 }
00684 }
00685
00686 void KABCore::storeContactIn( const QString &uid )
00687 {
00688
00689 QStringList uidList;
00690 if ( uid.isNull() ) {
00691 uidList = mViewManager->selectedUids();
00692 } else {
00693 uidList << uid;
00694 }
00695 KABC::Resource *resource = requestResource( mWidget );
00696 if ( !resource ) return;
00697 KABLock::self( mAddressBook )->lock( resource );
00698 QStringList::Iterator it( uidList.begin() );
00699 while ( it != uidList.end() ) {
00700 KABC::Addressee addr = mAddressBook->findByUid( *it++ );
00701 if ( !addr.isEmpty() ) {
00702 KABC::Addressee newAddr( addr );
00703
00704
00705 newAddr.setUid( KApplication::randomString( 10 ) );
00706 newAddr.setResource( resource );
00707 addressBook()->insertAddressee( newAddr );
00708 KABLock::self( mAddressBook )->lock( addr.resource() );
00709 addressBook()->removeAddressee( addr );
00710 KABLock::self( mAddressBook )->unlock( addr.resource() );
00711 }
00712 }
00713 KABLock::self( mAddressBook )->unlock( resource );
00714 }
00715
00716 void KABCore::save()
00717 {
00718 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
00719 if ( b ) {
00720 if ( !b->save() ) {
00721 QString text = i18n( "There was an error while attempting to save the "
00722 "address book. Please check that no other application "
00723 "is using it." );
00724
00725 KMessageBox::error( mWidget, text, i18n( "Unable to Save" ) );
00726 } else {
00727 setModified( false );
00728 }
00729 } else {
00730
00731
00732
00733 KABC::Ticket *ticket = mAddressBook->requestSaveTicket();
00734 if ( ticket ) {
00735 if ( !mAddressBook->save( ticket ) ) {
00736 KMessageBox::error( mWidget, i18n("Error saving address book.") );
00737 mAddressBook->releaseSaveTicket( ticket );
00738 } else {
00739 setModified( false );
00740 }
00741 } else {
00742 KMessageBox::error( mWidget,
00743 i18n("Unable to get access for saving the address "
00744 "book.") );
00745 }
00746 }
00747 }
00748
00749 void KABCore::undo()
00750 {
00751 UndoStack::instance()->undo();
00752
00753
00754 mViewManager->refreshView();
00755 }
00756
00757 void KABCore::redo()
00758 {
00759 RedoStack::instance()->redo();
00760
00761
00762 mViewManager->refreshView();
00763 }
00764
00765 void KABCore::setJumpButtonBarVisible( bool visible )
00766 {
00767 if ( visible )
00768 mJumpButtonBar->show();
00769 else
00770 mJumpButtonBar->hide();
00771 }
00772
00773 void KABCore::setDetailsVisible( bool visible )
00774 {
00775 if ( visible )
00776 mDetailsPage->show();
00777 else
00778 mDetailsPage->hide();
00779 }
00780
00781 void KABCore::extensionModified( const KABC::Addressee::List &list )
00782 {
00783 if ( list.count() != 0 ) {
00784 KABC::Addressee::List::ConstIterator it;
00785 for ( it = list.begin(); it != list.end(); ++it ) {
00786 Command *command = 0;
00787
00788
00789 KABC::Addressee origAddr = mAddressBook->findByUid( (*it).uid() );
00790 if ( origAddr.isEmpty() )
00791 command = new PwNewCommand( mAddressBook, *it );
00792 else
00793 command = new PwEditCommand( mAddressBook, origAddr, *it );
00794
00795 UndoStack::instance()->push( command );
00796 RedoStack::instance()->clear();
00797 }
00798
00799 setModified( true );
00800 }
00801
00802 if ( list.count() == 0 )
00803 mViewManager->refreshView();
00804 else
00805 mViewManager->refreshView( list[ 0 ].uid() );
00806 }
00807
00808 void KABCore::extensionDeleted( const QStringList &uidList )
00809 {
00810 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uidList );
00811 UndoStack::instance()->push( command );
00812 RedoStack::instance()->clear();
00813
00814
00815 setContactSelected( QString::null );
00816 setModified( true );
00817 mViewManager->refreshView();
00818 }
00819
00820 QString KABCore::getNameByPhone( const QString &phone )
00821 {
00822 QRegExp r( "[/*/-/ ]" );
00823 QString localPhone( phone );
00824
00825 bool found = false;
00826 QString ownerName = "";
00827 KABC::AddressBook::Iterator iter;
00828 KABC::PhoneNumber::List::Iterator phoneIter;
00829 KABC::PhoneNumber::List phoneList;
00830 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
00831 phoneList = (*iter).phoneNumbers();
00832 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
00833 ++phoneIter) {
00834
00835 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
00836 ownerName = (*iter).realName();
00837 found = true;
00838 }
00839 }
00840 }
00841
00842 return ownerName;
00843 }
00844
00845 void KABCore::openLDAPDialog()
00846 {
00847 if ( !KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
00848 KMessageBox::error( mWidget, i18n( "Your KDE installation is missing LDAP "
00849 "support, please ask your administrator or distributor for more information." ),
00850 i18n( "No LDAP IO slave available" ) );
00851 return;
00852 }
00853
00854 if ( !mLdapSearchDialog ) {
00855 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this, mWidget );
00856 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
00857 SLOT( addressBookChanged() ) );
00858 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ),
00859 SLOT( setModified() ) );
00860 } else
00861 mLdapSearchDialog->restoreSettings();
00862
00863 if ( mLdapSearchDialog->isOK() )
00864 mLdapSearchDialog->exec();
00865 }
00866
00867 void KABCore::configure()
00868 {
00869
00870 saveSettings();
00871
00872 KCMultiDialog dlg( mWidget, "", true );
00873 connect( &dlg, SIGNAL( configCommitted() ),
00874 this, SLOT( configurationChanged() ) );
00875
00876 dlg.addModule( "kabconfig.desktop" );
00877 dlg.addModule( "kabldapconfig.desktop" );
00878 dlg.addModule( "kabcustomfields.desktop" );
00879
00880 dlg.exec();
00881 }
00882
00883 void KABCore::print()
00884 {
00885 KPrinter printer;
00886 if ( !printer.setup( mWidget, i18n("Print Addresses") ) )
00887 return;
00888
00889 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
00890 mViewManager->selectedUids(), mWidget );
00891
00892 wizard.exec();
00893 }
00894
00895 void KABCore::detailsHighlighted( const QString &msg )
00896 {
00897 if ( mStatusBar )
00898 mStatusBar->changeItem( msg, 1 );
00899 }
00900
00901 void KABCore::showContactsAddress( const QString &addrUid )
00902 {
00903 QStringList uidList = mViewManager->selectedUids();
00904 if ( uidList.isEmpty() )
00905 return;
00906
00907 KABC::Addressee addr = mAddressBook->findByUid( uidList.first() );
00908 if ( addr.isEmpty() )
00909 return;
00910
00911 KABC::Address::List list = addr.addresses();
00912 KABC::Address::List::Iterator it;
00913 for ( it = list.begin(); it != list.end(); ++it )
00914 if ( (*it).id() == addrUid ) {
00915 LocationMap::instance()->showAddress( *it );
00916 break;
00917 }
00918 }
00919
00920 void KABCore::configurationChanged()
00921 {
00922 mExtensionManager->reconfigure();
00923 mSearchManager->reconfigure();
00924 mViewManager->refreshView();
00925 }
00926
00927 void KABCore::addressBookChanged()
00928 {
00929 mJumpButtonBar->updateButtons();
00930 mSearchManager->reload();
00931 }
00932
00933 AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
00934 const char *name )
00935 {
00936 AddresseeEditorDialog *dialog = new AddresseeEditorDialog( this, parent,
00937 name ? name : "editorDialog" );
00938 connect( dialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
00939 SLOT( contactModified( const KABC::Addressee& ) ) );
00940 connect( dialog, SIGNAL( editorDestroyed( const QString& ) ),
00941 SLOT( slotEditorDestroyed( const QString& ) ) );
00942
00943 return dialog;
00944 }
00945
00946 void KABCore::slotEditorDestroyed( const QString &uid )
00947 {
00948 mEditorDict.remove( uid );
00949
00950 KABC::Addressee addr = mAddressBook->findByUid( uid );
00951
00952 QApplication::setOverrideCursor( Qt::waitCursor );
00953
00954 KABLock::self( mAddressBook )->unlock( addr.resource() );
00955
00956 QApplication::restoreOverrideCursor();
00957 }
00958
00959 void KABCore::initGUI()
00960 {
00961 QVBoxLayout *topLayout = new QVBoxLayout( mWidget, 0, 0 );
00962 KToolBar* searchTB = new KToolBar( mWidget, "search toolbar");
00963 searchTB->boxLayout()->setSpacing( KDialog::spacingHint() );
00964 mIncSearchWidget = new IncSearchWidget( searchTB, "kde toolbar widget");
00965 searchTB->setStretchableWidget( mIncSearchWidget );
00966 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
00967 SLOT( incrementalTextSearch( const QString& ) ) );
00968
00969 mFilterSelectionWidget = new FilterSelectionWidget( searchTB , "kde toolbar widget" );
00970
00971 QHBoxLayout *hbox = new QHBoxLayout( mWidget, 0, 0 );
00972
00973 mDetailsSplitter = new QSplitter( mWidget );
00974 hbox->addWidget( mDetailsSplitter );
00975
00976 topLayout->addWidget( searchTB );
00977 topLayout->addWidget( mDetailsSplitter );
00978
00979 mExtensionBarSplitter = new QSplitter( mDetailsSplitter );
00980 mExtensionBarSplitter->setOrientation( Qt::Vertical );
00981
00982 QWidget *detailsWidget = new QWidget( mDetailsSplitter );
00983 QHBoxLayout *detailsLayout = new QHBoxLayout( detailsWidget );
00984
00985 mDetailsPage = new QWidget( detailsWidget );
00986 detailsLayout->addWidget( mDetailsPage );
00987
00988 QHBoxLayout *detailsPageLayout = new QHBoxLayout( mDetailsPage, 0, 0 );
00989 mDetails = new KPIM::AddresseeView( mDetailsPage );
00990 detailsPageLayout->addWidget( mDetails );
00991
00992 connect( mDetails, SIGNAL( addressClicked( const QString&) ),
00993 this, SLOT( showContactsAddress( const QString& ) ) );
00994
00995 mViewManager = new ViewManager( this, mExtensionBarSplitter );
00996 mViewManager->setFilterSelectionWidget( mFilterSelectionWidget );
00997
00998 connect( mFilterSelectionWidget, SIGNAL( filterActivated( int ) ),
00999 mViewManager, SLOT( setActiveFilter( int ) ) );
01000
01001 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
01002
01003 mJumpButtonBar = new JumpButtonBar( this, detailsWidget );
01004 detailsLayout->addWidget( mJumpButtonBar );
01005 detailsLayout->setStretchFactor( mJumpButtonBar, 1 );
01006
01007 topLayout->setStretchFactor( hbox, 1 );
01008
01009 mXXPortManager = new XXPortManager( this, mWidget );
01010
01011 initActions();
01012 }
01013
01014 void KABCore::initActions()
01015 {
01016 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
01017 SLOT( clipboardDataChanged() ) );
01018
01019 KAction *action;
01020
01021
01022 mActionMail = new KAction( i18n( "&Send Email to Contact..." ), "mail_send", 0,
01023 this, SLOT( sendMail() ), actionCollection(), "file_mail" );
01024 action = KStdAction::print( this, SLOT( print() ), actionCollection() );
01025 mActionMail->setWhatsThis( i18n( "Send a mail to all selected contacts." ) );
01026 action->setWhatsThis( i18n( "Print a special number of contacts." ) );
01027
01028 mActionSave = KStdAction::save( this,
01029 SLOT( save() ), actionCollection(), "file_sync" );
01030 mActionSave->setWhatsThis( i18n( "Save all changes of the address book to the storage backend." ) );
01031
01032 action = new KAction( i18n( "&New Contact..." ), "identity", CTRL+Key_N, this,
01033 SLOT( newContact() ), actionCollection(), "file_new_contact" );
01034 action->setWhatsThis( i18n( "Create a new contact<p>You will be presented with a dialog where you can add all data about a person, including addresses and phone numbers." ) );
01035
01036 mActionMailVCard = new KAction( i18n("Send &Contact..."), "mail_post_to", 0,
01037 this, SLOT( mailVCard() ),
01038 actionCollection(), "file_mail_vcard" );
01039 mActionMailVCard->setWhatsThis( i18n( "Send a mail with the selected contact as attachment." ) );
01040
01041 mActionChat = new KAction( i18n("Chat &With..."), 0,
01042 this, SLOT( startChat() ),
01043 actionCollection(), "file_chat" );
01044 mActionChat->setWhatsThis( i18n( "Start a chat with the selected contact." ) );
01045
01046 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
01047 this, SLOT( editContact() ),
01048 actionCollection(), "file_properties" );
01049 mActionEditAddressee->setWhatsThis( i18n( "Edit a contact<p>You will be presented with a dialog where you can change all data about a person, including addresses and phone numbers." ) );
01050
01051 mActionMerge = new KAction( i18n( "&Merge Contacts" ), "", 0,
01052 this, SLOT( mergeContacts() ),
01053 actionCollection(), "edit_merge" );
01054
01055
01056 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
01057 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
01058 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
01059 action = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
01060 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
01061 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
01062 mActionCopy->setWhatsThis( i18n( "Copy the currently selected contact(s) to system clipboard in vCard format." ) );
01063 mActionCut->setWhatsThis( i18n( "Cuts the currently selected contact(s) to system clipboard in vCard format." ) );
01064 mActionPaste->setWhatsThis( i18n( "Paste the previously cut or copied contacts from clipboard." ) );
01065 action->setWhatsThis( i18n( "Selects all visible contacts from current view." ) );
01066 mActionUndo->setWhatsThis( i18n( "Undoes the last <b>Cut</b>, <b>Copy</b> or <b>Paste</b>." ) );
01067 mActionRedo->setWhatsThis( i18n( "Redoes the last <b>Cut</b>, <b>Copy</b> or <b>Paste</b>." ) );
01068
01069 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
01070 Key_Delete, this, SLOT( deleteContacts() ),
01071 actionCollection(), "edit_delete" );
01072 mActionDelete->setWhatsThis( i18n( "Delete all selected contacts." ) );
01073
01074
01075 mActionStoreAddresseeIn = new KAction( i18n( "St&ore Contact in..." ), "", 0,
01076 this, SLOT( storeContactIn() ),
01077 actionCollection(), "edit_store_in" );
01078 mActionStoreAddresseeIn->setWhatsThis( i18n( "Store a contact in a different Addressbook<p>You will be presented with a dialog where you can select a new storage place for this contact." ) );
01079
01080
01081 mActionUndo->setEnabled( false );
01082 mActionRedo->setEnabled( false );
01083
01084
01085 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), "next", 0,
01086 actionCollection(), "options_show_jump_bar" );
01087 mActionJumpBar->setWhatsThis( i18n( "Toggle whether the jump button bar shall be visible." ) );
01088 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
01089
01090 mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0,
01091 actionCollection(), "options_show_details" );
01092 mActionDetails->setWhatsThis( i18n( "Toggle whether the details page shall be visible." ) );
01093 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
01094
01095 if ( mIsPart )
01096 action = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0,
01097 this, SLOT( configure() ), actionCollection(),
01098 "kaddressbook_configure" );
01099 else
01100 action = KStdAction::preferences( this, SLOT( configure() ), actionCollection() );
01101
01102 action->setWhatsThis( i18n( "You will be presented with a dialog, that offers you all possibilities to configure KAddressBook." ) );
01103
01104
01105 action = new KAction( i18n( "&Lookup Addresses in LDAP Directory..." ), "find", 0,
01106 this, SLOT( openLDAPDialog() ), actionCollection(), "ldap_lookup" );
01107 action->setWhatsThis( i18n( "Search for contacts on a LDAP server<p>You will be presented with a dialog, where you can search for contacts and select the ones you want to add to your local address book." ) );
01108
01109 mActionWhoAmI = new KAction( i18n( "Set as Personal Contact Data" ), "personal", 0, this,
01110 SLOT( setWhoAmI() ), actionCollection(),
01111 "edit_set_personal" );
01112 mActionWhoAmI->setWhatsThis( i18n( "Set the personal contact<p>The data of this contact will be used in many other KDE applications, so you do not have to input your personal data several times." ) );
01113
01114 mActionCategories = new KAction( i18n( "Select Categories..." ), 0, this,
01115 SLOT( setCategories() ), actionCollection(),
01116 "edit_set_categories" );
01117 mActionCategories->setWhatsThis( i18n( "Set the categories for all selected contacts." ) );
01118
01119 clipboardDataChanged();
01120
01121 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
01122 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
01123 }
01124
01125 void KABCore::clipboardDataChanged()
01126 {
01127 if ( mReadWrite )
01128 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
01129 }
01130
01131 void KABCore::updateActionMenu()
01132 {
01133 UndoStack *undo = UndoStack::instance();
01134 RedoStack *redo = RedoStack::instance();
01135
01136 if ( undo->isEmpty() )
01137 mActionUndo->setText( i18n( "Undo" ) );
01138 else
01139 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
01140
01141 mActionUndo->setEnabled( !undo->isEmpty() );
01142
01143 if ( !redo->top() )
01144 mActionRedo->setText( i18n( "Redo" ) );
01145 else
01146 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
01147
01148 mActionRedo->setEnabled( !redo->isEmpty() );
01149 }
01150
01151 KABC::Addressee KABCore::mergeContacts( const KABC::Addressee::List &list )
01152 {
01153 if ( list.count() == 0 )
01154 return KABC::Addressee();
01155 else if ( list.count() == 1 )
01156 return list.first();
01157
01158 KABC::Addressee masterAddressee = list.first();
01159
01160 KABC::Addressee::List::ConstIterator contactIt = list.begin();
01161 for ( ++contactIt; contactIt != list.end(); ++contactIt ) {
01162
01163 KABC::Address::List addresses = (*contactIt).addresses();
01164 KABC::Address::List masterAddresses = masterAddressee.addresses();
01165 KABC::Address::List::Iterator addrIt ;
01166 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
01167 if ( !masterAddresses.contains( *addrIt ) )
01168 masterAddressee.insertAddress( *addrIt );
01169 }
01170
01171 if ( masterAddressee.birthday().isNull() && !(*contactIt).birthday().isNull() )
01172 masterAddressee.setBirthday( (*contactIt).birthday() );
01173
01174
01175
01176 QStringList::Iterator it;
01177 QStringList categories = (*contactIt).categories();
01178 QStringList masterCategories = masterAddressee.categories();
01179 QStringList newCategories( masterCategories );
01180 for ( it = categories.begin(); it != categories.end(); ++it )
01181 if ( !masterCategories.contains( *it ) )
01182 newCategories.append( *it );
01183 masterAddressee.setCategories( newCategories );
01184
01185
01186 if ( !masterAddressee.secrecy().isValid() && (*contactIt).secrecy().isValid() )
01187 masterAddressee.setSecrecy( (*contactIt).secrecy() );
01188
01189
01190 QStringList emails = (*contactIt).emails();
01191 QStringList masterEmails = masterAddressee.emails();
01192 for ( it = emails.begin(); it != emails.end(); ++it )
01193 if ( !masterEmails.contains( *it ) )
01194 masterAddressee.insertEmail( *it, false );
01195
01196
01197 if ( masterAddressee.formattedName().isEmpty() && !(*contactIt).formattedName().isEmpty() )
01198 masterAddressee.setFormattedName( (*contactIt).formattedName() );
01199
01200
01201 if ( !masterAddressee.geo().isValid() && (*contactIt).geo().isValid() )
01202 masterAddressee.setGeo( (*contactIt).geo() );
01203
01204
01205
01206
01207
01208
01209
01210 if ( masterAddressee.mailer().isEmpty() && !(*contactIt).mailer().isEmpty() )
01211 masterAddressee.setMailer( (*contactIt).mailer() );
01212
01213
01214 if ( masterAddressee.assembledName().isEmpty() && !(*contactIt).assembledName().isEmpty() )
01215 masterAddressee.setNameFromString( (*contactIt).assembledName() );
01216
01217
01218 if ( masterAddressee.nickName().isEmpty() && !(*contactIt).nickName().isEmpty() )
01219 masterAddressee.setNickName( (*contactIt).nickName() );
01220
01221
01222 if ( masterAddressee.note().isEmpty() && !(*contactIt).note().isEmpty() )
01223 masterAddressee.setNote( (*contactIt).note() );
01224
01225
01226 if ( masterAddressee.organization().isEmpty() && !(*contactIt).organization().isEmpty() )
01227 masterAddressee.setOrganization( (*contactIt).organization() );
01228
01229
01230
01231
01232
01233
01234 if ( masterAddressee.productId().isEmpty() && !(*contactIt).productId().isEmpty() )
01235 masterAddressee.setProductId( (*contactIt).productId() );
01236
01237
01238 if ( masterAddressee.revision().isNull() && !(*contactIt).revision().isNull() )
01239 masterAddressee.setRevision( (*contactIt).revision() );
01240
01241
01242 if ( masterAddressee.role().isEmpty() && !(*contactIt).role().isEmpty() )
01243 masterAddressee.setRole( (*contactIt).role() );
01244
01245
01246 if ( masterAddressee.sortString().isEmpty() && !(*contactIt).sortString().isEmpty() )
01247 masterAddressee.setSortString( (*contactIt).sortString() );
01248
01249
01250
01251
01252
01253
01254 KABC::PhoneNumber::List phones = (*contactIt).phoneNumbers();
01255 KABC::PhoneNumber::List masterPhones = masterAddressee.phoneNumbers();
01256 KABC::PhoneNumber::List::ConstIterator phoneIt;
01257 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt )
01258 if ( !masterPhones.contains( *it ) )
01259 masterAddressee.insertPhoneNumber( *it );
01260
01261
01262 if ( masterAddressee.title().isEmpty() && !(*contactIt).title().isEmpty() )
01263 masterAddressee.setTitle( (*contactIt).title() );
01264
01265
01266 if ( !masterAddressee.timeZone().isValid() && (*contactIt).timeZone().isValid() )
01267 masterAddressee.setTimeZone( (*contactIt).timeZone() );
01268
01269
01270
01271
01272 if ( masterAddressee.url().isEmpty() && !(*contactIt).url().isEmpty() )
01273 masterAddressee.setUrl( (*contactIt).url() );
01274
01275
01276 QStringList customs = (*contactIt).customs();
01277 QStringList masterCustoms = masterAddressee.customs();
01278 QStringList newCustoms( masterCustoms );
01279 for ( it = customs.begin(); it != customs.end(); ++it )
01280 if ( !masterCustoms.contains( *it ) )
01281 newCustoms.append( *it );
01282 masterAddressee.setCustoms( newCustoms );
01283 }
01284
01285 return masterAddressee;
01286 }
01287
01288 void KABCore::setCategories()
01289 {
01290
01291 if ( mCategorySelectDialog == 0 ) {
01292 mCategorySelectDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), mWidget );
01293 connect( mCategorySelectDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
01294 SLOT( categoriesSelected( const QStringList& ) ) );
01295 connect( mCategorySelectDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) );
01296 }
01297
01298 QStringList selected = mCategorySelectDialog->selectedCategories();
01299 mCategorySelectDialog->setCategories();
01300 mCategorySelectDialog->setSelected( selected );
01301 mCategorySelectDialog->show();
01302 mCategorySelectDialog->raise();
01303 }
01304
01305 void KABCore::categoriesSelected( const QStringList &categories )
01306 {
01307 bool merge = false;
01308 QString msg = i18n( "Merge with existing categories?" );
01309 if ( KMessageBox::questionYesNo( mWidget, msg ) == KMessageBox::Yes )
01310 merge = true;
01311
01312 QStringList uids = mViewManager->selectedUids();
01313 QStringList::ConstIterator it;
01314 for ( it = uids.begin(); it != uids.end(); ++it ) {
01315 KABC::Addressee addr = mAddressBook->findByUid( *it );
01316 if ( !addr.isEmpty() ) {
01317 if ( !merge )
01318 addr.setCategories( categories );
01319 else {
01320 QStringList addrCategories = addr.categories();
01321 QStringList::ConstIterator catIt;
01322 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
01323 if ( !addrCategories.contains( *catIt ) )
01324 addrCategories.append( *catIt );
01325 }
01326 addr.setCategories( addrCategories );
01327 }
01328
01329 mAddressBook->insertAddressee( addr );
01330 }
01331 }
01332
01333 if ( uids.count() > 0 )
01334 setModified( true );
01335 }
01336
01337 void KABCore::editCategories()
01338 {
01339 if ( mCategoryEditDialog == 0 ) {
01340 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), mWidget );
01341 connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
01342 SLOT( setCategories() ) );
01343 }
01344
01345 mCategoryEditDialog->show();
01346 mCategoryEditDialog->raise();
01347 }
01348
01349 bool KABCore::handleCommandLine( KAddressBookIface* iface )
01350 {
01351 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
01352 QCString addrStr = args->getOption( "addr" );
01353 QCString uidStr = args->getOption( "uid" );
01354
01355 QString addr, uid, vcard;
01356 if ( !addrStr.isEmpty() )
01357 addr = QString::fromLocal8Bit( addrStr );
01358 if ( !uidStr.isEmpty() )
01359 uid = QString::fromLocal8Bit( uidStr );
01360
01361 bool doneSomething = false;
01362
01363
01364 if ( !addr.isEmpty() ) {
01365 iface->addEmail( addr );
01366 doneSomething = true;
01367 }
01368
01369 if ( !uid.isEmpty() ) {
01370 iface->showContactEditor( uid );
01371 doneSomething = true;
01372 }
01373
01374 if ( args->isSet( "new-contact" ) ) {
01375 iface->newContact();
01376 doneSomething = true;
01377 }
01378
01379 if ( args->count() >= 1 ) {
01380 for ( int i = 0; i < args->count(); ++i )
01381 iface->importVCard( args->url( i ).url() );
01382 doneSomething = true;
01383 }
01384 return doneSomething;
01385 }
01386
01387 KPIM::DistributionList::List KABCore::distributionLists() const
01388 {
01389 return mSearchManager->distributionLists();
01390 }
01391
01392 QStringList KABCore::distributionListNames() const
01393 {
01394 return mSearchManager->distributionListNames();
01395 }
01396
01397 #include "kabcore.moc"