diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index efa3e11c1..bf9a4ba80 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -22,8 +22,9 @@ #include "kpgp.h" #include "kmaddrbookdlg.h" #include "kmaddrbook.h" -#include "kfontutils.h" #include "kmidentity.h" +#include +#include #include #include @@ -84,6 +85,7 @@ extern KBusyPtr *kbp; extern KRNSender *msgSender; extern KMIdentity *identity; extern KMAddrBook *addrBook; +extern KabApi *KABaddrBook; typedef QList WindowList; WindowList* windowList=new WindowList; #define aboutText "KRN" @@ -1310,31 +1312,95 @@ void KMComposeWin::removeAttach(int idx) //----------------------------------------------------------------------------- void KMComposeWin::addrBookSelInto(KMLineEdit* aLineEdit) { - KMAddrBookSelDlg dlg(kernel->addrBook()); - QString txt; - - //assert(aLineEdit!=NULL); - if(!aLineEdit) - { - debug("KMComposeWin::addrBookSelInto() : aLineEdit == NULL\n"); - return; + if (kernel->useKAB()) { + if(kernel->KABaddrBook()!=0) + { + if(kernel->KABaddrBook()->addressbook()->noOfEntries()==0) + { + KMessageBox::information + (this, + i18n("Your address book does not contain entries."), + i18n("No addresses")); + } else { + QString address; + AddressBook::Entry entry; + KabKey key; + for(;;) + { + if(!kernel->KABaddrBook()->exec()) break; // rejected + switch(kernel->KABaddrBook()->getEntry(entry, key)) + { + case AddressBook::NoError: // an entry has been selected + // ----- a test: + if(entry.emails.isEmpty()) + { // may be allow to enter one? + KMessageBox::information + (this, + i18n("This address has no email address.\n" + "Please try another one."), + i18n("No email addresses")); + continue; + } else { + // ----- assemble address string: + // here you see how to use the AddressBook + // object from the KabApi: + kernel->KABaddrBook()->addressbook()->literalName + (entry, address); + if(entry.emails.count()>1) + { // select one of the addresses: + // ... WORK_TO_DO + // append selected address to address: + address=address + " <" + entry.emails.first() + +">"; + } else { + address=address + " <" + entry.emails.first() + +">"; + } + aLineEdit->setText(address); + } + break; + default: + KMessageBox::information + (this, + i18n("Some error occured while browsing the address book."), + i18n("Error")); + } + break; + } + } } - if (dlg.exec()==QDialog::Rejected) return; - txt = QString(aLineEdit->text()).stripWhiteSpace(); - if (!txt.isEmpty()) - { - if (txt.right(1).at(0)!=',') txt += ", "; - else txt += ' '; } - aLineEdit->setText(txt + dlg.address()); + else { + KMAddrBookSelDlg dlg(kernel->addrBook()); + QString txt; + + //assert(aLineEdit!=NULL); + if(!aLineEdit) + { + debug("KMComposeWin::addrBookSelInto() : aLineEdit == NULL\n"); + return; + } + if (dlg.exec()==QDialog::Rejected) return; + txt = QString(aLineEdit->text()).stripWhiteSpace(); + if (!txt.isEmpty()) + { + if (txt.right(1).at(0)!=',') txt += ", "; + else txt += ' '; + } + aLineEdit->setText(txt + dlg.address()); + } } //----------------------------------------------------------------------------- void KMComposeWin::slotAddrBook() { - KMAddrBookEditDlg dlg( kernel->addrBook(), this ); - dlg.exec(); + if (!kernel->useKAB()) { + KMAddrBookEditDlg dlg( kernel->addrBook(), this ); + dlg.exec(); + } + else + debug("KMComposeWin::slotAddrBook: not implemented."); } diff --git a/kmkernel.cpp b/kmkernel.cpp index f0ebbdadf..5124b65d3 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -29,6 +29,7 @@ #include "kmacctmgr.h" #include "kbusyptr.h" #include "kmaddrbook.h" +#include #include @@ -303,6 +304,7 @@ void KMKernel::init() the_checkingMail = false; the_shuttingDown = false; the_server_is_ready = false; + mUseKAB = false; the_kbp = new KBusyPtr; cfg = kapp->config(); @@ -331,7 +333,17 @@ void KMKernel::init() the_filterMgr = new KMFilterMgr; the_filterActionDict = new KMFilterActionDict; the_addrBook = new KMAddrBook; - + the_KAB_addrBook = new KabAPI; // KabApi is a dialog; + CHECK_PTR(the_KAB_addrBook); + if(KABaddrBook()->init()!=AddressBook::NoError) + { // this connects to the default address book and opens it: + debug( "Error initializing the connection to your KAB address book." ); + the_KAB_addrBook=0; + } + else { + debug ("KMKernel::init: KabApi initialized."); + } + initFolders(cfg); the_acctMgr->readConfig(); the_filterMgr->readConfig(); diff --git a/kmkernel.h b/kmkernel.h index 862b744e7..09edd9799 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -19,6 +19,7 @@ class KMAcctMgr; class KMFilterMgr; class KMFilterActionDict; class KMAddrBook; +class KabAPI; class KMSender; class KMIdentity; class KMKernel; @@ -72,6 +73,9 @@ public: inline KMFilterMgr *filterMgr() { return the_filterMgr; } inline KMFilterActionDict *filterActionDict() { return the_filterActionDict; } inline KMAddrBook *addrBook() { return the_addrBook; } + inline KabAPI *KABaddrBook() { return the_KAB_addrBook; } + inline bool useKAB() { return mUseKAB; } + inline void setUseKAB( bool useKAB ) { mUseKAB = useKAB; } inline KMSender *msgSender() { return the_msgSender; } inline bool firstStart() { return the_firstStart; } @@ -92,12 +96,14 @@ private: KMFilterMgr *the_filterMgr; KMFilterActionDict *the_filterActionDict; KMAddrBook *the_addrBook; + KabAPI *the_KAB_addrBook; KMSender *the_msgSender; bool the_firstStart; // is this the first start? read from config bool the_shuttingDown; // are we going down? set from here bool the_checkingMail; // are we checking mail? set from... where the mail is checked bool the_server_is_ready; // are we in the middle of network operations (needed?) + bool mUseKAB; static KMKernel *mySelf; }; diff --git a/kmmainwin.cpp b/kmmainwin.cpp index ba3c448cf..1ca2f5c26 100644 --- a/kmmainwin.cpp +++ b/kmmainwin.cpp @@ -56,6 +56,7 @@ #include "kmaddrbookdlg.h" #include "kmaddrbook.h" #include "kwm.h" +#include "addtoaddressbook.h" #include #include @@ -222,6 +223,7 @@ void KMMainWin::readConfig(void) mExecOnNew = config->readBoolEntry("exec-on-mail", false); mNewMailCmd = config->readEntry("exec-on-mail-cmd", ""); mUseKab = config->readBoolEntry("use-kab", false); + kernel->setUseKAB( mUseKab ); // Re-activate panners if (mStartupDone) @@ -499,8 +501,12 @@ void KMMainWin::slotFilter() //----------------------------------------------------------------------------- void KMMainWin::slotAddrBook() { - KMAddrBookEditDlg dlg( kernel->addrBook(), this ); - dlg.exec(); + if (!kernel->useKAB()) { + KMAddrBookEditDlg dlg( kernel->addrBook(), this ); + dlg.exec(); + } + else + debug("KMMainWin::slotAddrBook: not implemented."); } @@ -509,6 +515,7 @@ void KMMainWin::slotUseKab() { mUseKab = !mUseKab; fileMenu->setItemChecked( mUseKabId, mUseKab ); + kernel->setUseKAB( mUseKab ); } @@ -1111,10 +1118,15 @@ void KMMainWin::slotMailtoForward() //----------------------------------------------------------------------------- void KMMainWin::slotMailtoAddAddrBook() { - + if (!kernel->useKAB()) { if (mUrlCurrent.isEmpty()) return; kernel->addrBook()->insert(mUrlCurrent.mid(7,255)); statusMsg(i18n("Address added to addressbook.")); + } + else { + AddToKabDialog dialog(mUrlCurrent, kernel->KABaddrBook(), this); + dialog.exec(); + } } @@ -1590,26 +1602,6 @@ void KMMainWin::updateFolderMenu() else mFolderMenu->changeItem(threadId, i18n( "Don't thread messages" )); mFolderMenu->setItemChecked(threadId, !mFolderThreadPref); - - /* - if (mHtmlPref && mFolderHtmlPref) - mFolderMenu->changeItem(htmlId, i18n( "Prefer HTML to plain text (default)" )); - else if (mHtmlPref && !mFolderHtmlPref) - mFolderMenu->changeItem(htmlId, i18n( "Prefer plain text to HTML (override default)" )); - else if (!mHtmlPref && mFolderHtmlPref) - mFolderMenu->changeItem(htmlId, i18n( "Prefer plain text to HTML (default)" )); - else if (!mHtmlPref && !mFolderHtmlPref) - mFolderMenu->changeItem(htmlId, i18n( "Prefer HTML to plain text (override default)" )); - - if (mThreadPref && mFolderThreadPref) - mFolderMenu->changeItem(threadId, i18n( "Thread messages (default)" )); - else if (mThreadPref && !mFolderThreadPref) - mFolderMenu->changeItem(threadId, i18n( "Don't thread messages (override default)" )); - else if (!mThreadPref && mFolderThreadPref) - mFolderMenu->changeItem(threadId, i18n( "Don't thread messages (default)" )); - else if (!mThreadPref && !mFolderThreadPref) - mFolderMenu->changeItem(threadId, i18n( "Thread messages (override default)" )); - */ } #ifdef MALLOC_DEBUG