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