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