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