summaryrefslogtreecommitdiffstats
path: root/kab/kabapi.cc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kab/kabapi.cc
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kab/kabapi.cc')
-rw-r--r--kab/kabapi.cc220
1 files changed, 220 insertions, 0 deletions
diff --git a/kab/kabapi.cc b/kab/kabapi.cc
new file mode 100644
index 000000000..0f5d76222
--- /dev/null
+++ b/kab/kabapi.cc
@@ -0,0 +1,220 @@
+/* -*- C++ -*-
+ This file implements the application programming interface
+ for using kab's addressbook files within other programs.
+ Parse it with kdoc to get the API documentation.
+
+ the KDE addressbook
+
+ $ Author: Mirko Boehm $
+ $ Copyright: (C) 1996-2001, Mirko Boehm $
+ $ Contact: mirko@kde.org
+ http://www.kde.org $
+ $ License: GPL with the following explicit clarification:
+ This code may be linked against any version of the Qt toolkit
+ from Troll Tech, Norway. $
+
+ $Id$
+*/
+
+#include "kabapi.h"
+#include <klistbox.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kdebug.h>
+
+
+#include "kabapi.moc"
+
+#ifdef KAB_KDEBUG_AREA
+#undef KAB_KDEBUG_AREA
+#endif
+
+#define KAB_KDEBUG_AREA 800
+
+using namespace std;
+
+KabAPI::KabAPI(QWidget* parent, const char* name)
+ : KDialogBase(parent, name),
+ book(0),
+ listbox(new KListBox(this)),
+ selection(-1)
+{
+ Q_CHECK_PTR(listbox);
+ setMainWidget(listbox);
+ showButtonApply(false);
+ enableButtonSeparator(true);
+ connect(listbox, SIGNAL(highlighted(int)), SLOT(entrySelected(int)));
+ connect(listbox, SIGNAL(doubleClicked ( QListBoxItem * )),SLOT(slotDoubleClicked ( QListBoxItem * )));
+}
+
+
+void KabAPI::slotDoubleClicked ( QListBoxItem * )
+{
+ accept();
+}
+
+int KabAPI::exec()
+{
+ QStringList names;
+ // -----
+ if(book==0)
+ {
+ kdDebug(KAB_KDEBUG_AREA)
+ << "KabAPI::exec: you have to call init before using the API."
+ << endl;
+ return -1;
+ } else {
+ if(book->getListOfNames(&names, true, false)==AddressBook::NoError)
+ {
+ listbox->clear();
+ listbox->insertStringList(names);
+ if(names.count()>0)
+ {
+ listbox->setCurrentItem(0);
+ }
+ listbox->setMinimumSize(listbox->sizeHint());
+ adjustSize();
+ resize(minimumSize());
+ return KDialogBase::exec();
+ } else {
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::exec: error creating interface."
+ << endl;
+ return -1;
+ }
+ }
+}
+
+AddressBook::ErrorCode KabAPI::init()
+{
+ // ############################################################################
+ book=new AddressBook(0, "KABAPI::book", true); //change parent from "this" to "0" //dsweet
+ if(book->getState()==AddressBook::NoError)
+ {
+ connect(book, SIGNAL(setStatus(const QString&)),
+ SLOT(setStatusSlot(const QString&)));
+ return AddressBook::NoError;
+ } else {
+ return AddressBook::InternError;
+ }
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::getEntry(AddressBook::Entry& entry, KabKey& key)
+{
+ // ############################################################################
+ if(book->noOfEntries()==0)
+ {
+ return AddressBook::NoEntry;
+ }
+ if(selection>=0)
+ {
+ if(book->getKey(selection, key)==AddressBook::NoError)
+ {
+ if(book->getEntry(key, entry)==AddressBook::NoError)
+ {
+ return AddressBook::NoError;
+ } else {
+ return AddressBook::InternError; // this may not happen
+ }
+ } else {
+ return AddressBook::NoEntry;
+ }
+ } else {
+ return AddressBook::InternError;
+ }
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::add(const AddressBook::Entry& entry, KabKey& key,
+ bool update)
+{
+ // ############################################################################
+ if(book->add(entry, key, update)!=AddressBook::NoError)
+ {
+ KMessageBox::sorry(this, i18n("Your new entry could not be added."));
+ return AddressBook::InternError;
+ } else {
+ return AddressBook::NoError;
+ }
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::remove(const KabKey& key)
+{
+ Q_CHECK_PTR(book);
+ // ############################################################################
+ if(book->AddressBook::remove(key)==AddressBook::NoError)
+ {
+ return AddressBook::NoError;
+ } else {
+ return AddressBook::NoEntry;
+ }
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::getEntryByName(const QString&,
+ list<AddressBook::Entry>&, const int)
+{
+ // ############################################################################
+ return AddressBook::NotImplemented;
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::getEntryByName(const AddressBook::Entry&,
+ list<AddressBook::Entry>&, const int)
+{
+ // ############################################################################
+ return AddressBook::NotImplemented;
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::getEntries(list<AddressBook::Entry>& entries)
+{
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::getEntries: called." << endl;
+ // ############################################################################
+ if(book->noOfEntries()==0)
+ { // ----- database is valid, but empty:
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::getEntries: no entries." << endl;
+ return AddressBook::NoEntry;
+ }
+ if(book->getEntries(entries)!=AddressBook::NoError)
+ {
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::getEntries: intern error." << endl;
+ return AddressBook::InternError;
+ } else {
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::getEntries: done." << endl;
+ return AddressBook::NoError;
+ }
+ // ############################################################################
+}
+
+AddressBook* KabAPI::addressbook()
+{
+ // ############################################################################
+ return book;
+ // ############################################################################
+}
+
+AddressBook::ErrorCode KabAPI::save(bool force)
+{
+ // ############################################################################
+ if(book->save("", force)!=AddressBook::NoError)
+ {
+ return AddressBook::PermDenied;
+ } else {
+ return AddressBook::NoError;
+ }
+ // ############################################################################
+}
+
+void KabAPI::entrySelected(int index)
+{
+ kdDebug(KAB_KDEBUG_AREA) << "KabAPI::entrySelected: entry " << index
+ <<" selected." << endl;
+ selection=index;
+}
+
+void KabAPI::setStatusSlot(const QString& text)
+{
+ emit(setStatus(text));
+}