I added support to kmail to use the KDE address book, finally.

Two operations are currently supported:
° picking the email address from an entry of the address database to
put it into a to- (etc.) -field.
° adding the sender or any other address that appears in a displayed
message to the address book, by either creating a new entry, or adding
this email address to an existing entry

Everything else is, in my opinion, no task for the mailer.

The files
kmaddrbook.h kmaddrbook.cpp kmaddrbookdlg.cpp  kmaddrbookdlg.h
are no more needed, I think, but I did not remove them for now.

The files
addtoaddressbook.cpp addtoaddressbook.h
have been added by me.

There seems to be a problem when using the address database from
different clients at the same time. I will investigate that tomorrow.
--Mirko.

svn path=/trunk/kdenetwork/kmail/; revision=49369
wilder-work
Mirko Boehm 26 years ago
parent 85ba852060
commit b4c94dcc96
  1. 5
      Makefile.am
  2. 236
      addtoaddressbook.cpp
  3. 59
      addtoaddressbook.h
  4. 103
      kmcomposewin.cpp
  5. 33
      kmkernel.cpp
  6. 15
      kmkernel.h
  7. 25
      kmmainwin.cpp

@ -1,7 +1,7 @@
SUBDIRS = pics
INCLUDES = $(all_includes)
LDADD = $(LIB_KHTML) -lkspell -lmimelib $(LIB_KFILE)
LDADD = $(LIB_KHTML) -lkspell -lmimelib -lkab $(LIB_KFILE)
bin_PROGRAMS = kmail
@ -26,7 +26,8 @@ kmail_SOURCES = kmmessage.cpp kmmainwin.cpp \
kmundostack.cpp kmbroadcaststatus.cpp \
kmacctexppop.cpp configuredialog.cpp colorlistbox.cpp \
kmkernel.cpp kmailIface.skel kmailIface.stub main.cpp \
accountdialog.cpp
accountdialog.cpp \
addtoaddressbook.cpp
METASOURCES = kmmainwin.moc kmfolderdia.moc kmfolder.moc \
kmfoldertree.moc kmheaders.moc \

@ -0,0 +1,236 @@
/* This file implements the dialog to add an address to the KDE
addressbook database.
*
* copyright: (C) Mirko Sucker, 1998, 1999, 2000
* mail to: Mirko Sucker <mirko@kde.org>
* requires: recent C++-compiler, at least Qt 2.0
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
* $Revision$
*/
#include <qlabel.h>
#include <qlistbox.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qstring.h>
#include <qstringlist.h>
#include <kdialogbase.h>
#include <klocale.h>
#include <kabapi.h>
#include <kmessagebox.h>
#include "kmmainwin.h"
#include "kmkernel.h"
#include "addtoaddressbook.h"
AddToKabDialog::AddToKabDialog(QString url_, KabAPI * api_, QWidget *parent)
: KDialogBase(parent, "AddToKabDialog", true,
i18n("Add address to the address book"),
KDialogBase::User1|KDialogBase::User2|KDialogBase::Cancel,
KDialogBase::User1, true,
i18n("Create a new entry..."),
i18n("Add email address")),
api(api_),
url(url_)
{
QStringList names;
// -----
QWidget *mainwidget=new QWidget(this);
QBoxLayout *layout=new QBoxLayout
(mainwidget, QBoxLayout::TopToBottom,
KDialog::marginHint(), KDialog::spacingHint());
layout->setAutoAdd(true);
QLabel *headline=new QLabel
(url + "\n"
+i18n("Select entry to add email address to or create a new one\n"
"using the New button:"),
mainwidget);
headline=headline; // shut up the "unused ..." - warning
list=new QListBox(mainwidget);
if(api->addressbook()->getListOfNames(&names, false, false)
==AddressBook::NoError)
{
list->insertStringList(names);
}
setMainWidget(mainwidget);
if(actionButton(User1)!=0)
{
connect(actionButton(User1), SIGNAL(clicked()),
SLOT(newEntry()));
}
if(actionButton(User2)!=0)
{
connect(actionButton(User2), SIGNAL(clicked()),
SLOT(addToEntry()));
actionButton(User2)->setEnabled(false);
}
connect(list, SIGNAL(highlighted(int)), SLOT(highlighted(int)));
}
AddToKabDialog::~AddToKabDialog()
{
}
void KMMainWin::slotMailtoAddAddrBook()
{
AddToKabDialog dialog(mUrlCurrent, kernel->addrBook(), this);
dialog.exec();
}
void AddToKabDialog::addToEntry()
{
KabKey key;
AddressBook::Entry entry;
QString address;
// ----- get the selected entries key:
if(list->currentItem()<0)
{
debug("AddToKabDialog::addToEntry: called, but no selection.");
accept(); // this should not return
return;
}
if(api->addressbook()->getKey(list->currentItem(), key)
==AddressBook::NoError)
{ // ----- get the entry
if(api->addressbook()->getEntry(key, entry)
==AddressBook::NoError)
{ // everything works fine:
address=url.mid(7, 255);
address=address.stripWhiteSpace();
entry.emails.append(address);
if(api->addressbook()->change(key, entry)
==AddressBook::NoError)
{
debug("AddToKabDialog::addToEntry: changes done.");
if(api->save(true)==AddressBook::NoError)
{
debug("AddToKabDialog::addToEntry: "
"changes done.");
} else {
KMessageBox::information
(this,
i18n("The changes could not be saved.\n"
"Maybe the database is locked by "
"another process.\nTry again."),
i18n("Error"));
}
} else {
KMessageBox::information
(this,
i18n("The entry could not be changed.\n"
"Maybe the database is locked by another"
" process.\nTry again."),
i18n("Error"));
}
} else {
KMessageBox::information
(this,
i18n("Sorry - address database changed meanwhile.\n"
"Try again."),
i18n("Error"));
}
} else {
KMessageBox::information
(this,
i18n("Sorry - address database changed meanwhile.\n"
"Try again."),
i18n("Error"));
}
accept();
}
void AddToKabDialog::newEntry()
{
KDialogBase dialog(this, 0, true, "Create new address",
KDialogBase::Ok|KDialogBase::Cancel,
KDialogBase::Ok,
true);
AddressBook::Entry entry;
KabKey dummy;
QString address; // the email address to add
const QString texts[]={
i18n("First name:"), i18n("Last name:"), i18n("Email address:")
};
QString *fields[]= { &entry.firstname, &entry.lastname, &address };
const int Size=sizeof(texts)/sizeof(texts[0]);
QLineEdit *lineedits[Size];
int count, row=0;
QWidget *mainwidget=new QWidget(&dialog);
QGridLayout layout(mainwidget, 5, 2, KDialog::marginHint(),
KDialog::spacingHint());
QFrame *frame;
// -----
layout.addWidget(new QLabel(i18n("Field"), mainwidget), row, 0);
layout.addWidget(new QLabel(i18n("Content"), mainwidget), row, 1);
++row;
frame=new QFrame(mainwidget);
frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
layout.addMultiCellWidget(frame, row, row, 0, 1);
++row;
for(count=0; count<Size; ++count)
{
layout.addWidget(new QLabel(texts[count], mainwidget), row, 0);
lineedits[count]=new QLineEdit(mainwidget);
layout.addWidget(lineedits[count], row, 1);
++row;
}
lineedits[2]->setText(url.mid(7, 255));
dialog.setMainWidget(mainwidget);
dialog.adjustSize();
if(dialog.exec())
{
for(count=0; count<Size; ++count)
{
*fields[count]=lineedits[count]->text();
}
entry.emails.append(address);
if(api->add(entry, dummy)==AddressBook::NoError)
{
debug("AddToKabDialog::newEntry: entry added.");
if(api->save(true)==AddressBook::NoError)
{
debug("AddToKabDialog::newEntry: "
"changes saved.");
accept();
} else {
KMessageBox::information
(this,
i18n("The changes could not be saved.\n"
"Maybe the database is locked by "
"another process.\nTry again."),
i18n("Error"));
}
} else {
KMessageBox::information
(this,
i18n("The changes could not be saved.\n"
"Maybe the database is locked by "
"another process.\nTry again."),
i18n("Error"));
}
}
}
void AddToKabDialog::highlighted(int)
{
if(actionButton(User2)!=0)
{
actionButton(User2)->setEnabled(true);
}
}

@ -0,0 +1,59 @@
/* This file implements the dialog to add an email address to the KDE
addressbook database.
*
* copyright: (C) Mirko Sucker, 1998, 1999, 2000
* mail to: Mirko Sucker <mirko@kde.org>
* requires: recent C++-compiler, at least Qt 2.0
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
* $Revision$
*/
#ifndef ADDTOADDRESSBOOK_H
#define ADDTOADDRESSBOOK_H
#include <kdialogbase.h>
#include <qstring.h>
class QWidget;
class KabAPI;
class QListBox;
class AddToKabDialog : public KDialogBase
{
Q_OBJECT
public:
AddToKabDialog(QString url, KabAPI *, QWidget *parent);
~AddToKabDialog();
protected slots:
/** Create a new entry and add it to the address book. */
void newEntry();
/** Add the email address to the selected entry. */
void addToEntry();
/** An entry has been highlighted from the list. */
void highlighted(int);
protected:
/** Remember the pointer to the address database interface. */
KabAPI *api;
/** Remember the url to store. */
QString url;
/** The list box showing the entries. */
QListBox *list;
};
#endif // ADDTOADDRESSBOOK_H

@ -20,8 +20,11 @@
#include "kbusyptr.h"
#include "kmmsgpartdlg.h"
#include "kpgp.h"
#include "kmaddrbookdlg.h"
#include "kmaddrbook.h"
// ----- <mirko>:
// #include "kmaddrbookdlg.h"
// #include "kmaddrbook.h"
#include <kabapi.h>
// ----- </mirko>
#include "kfontutils.h"
#include "kmidentity.h"
@ -83,7 +86,7 @@ extern KApplication *app;
extern KBusyPtr *kbp;
extern KRNSender *msgSender;
extern KMIdentity *identity;
extern KMAddrBook *addrBook;
extern KabApi *addrBook;
typedef QList<QWidget> WindowList;
WindowList* windowList=new WindowList;
#define aboutText "KRN"
@ -1310,31 +1313,93 @@ void KMComposeWin::removeAttach(int idx)
//-----------------------------------------------------------------------------
void KMComposeWin::addrBookSelInto(KMLineEdit* aLineEdit)
{
KMAddrBookSelDlg dlg(kernel->addrBook());
QString txt;
//assert(aLineEdit!=NULL);
if(!aLineEdit)
// ----- <mirko>:
/*
KMAddrBookSelDlg dlg(kernel->addrBook());
QString txt;
// assert(aLineEdit!=NULL);
if(!aLineEdit)
{
debug("KMComposeWin::addrBookSelInto() : aLineEdit == NULL\n");
return;
debug("KMComposeWin::addrBookSelInto() : aLineEdit == NULL\n");
return;
}
if (dlg.exec()==QDialog::Rejected) return;
txt = QString(aLineEdit->text()).stripWhiteSpace();
if (!txt.isEmpty())
{
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());
}
aLineEdit->setText(txt + dlg.address());
*/
if(kernel->addrBook()!=0)
{
if(kernel->addrBook()->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->addrBook()->exec()) break; // rejected
switch(kernel->addrBook()->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->addrBook()->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;
}
}
}
// ----- </mirko>
}
//-----------------------------------------------------------------------------
void KMComposeWin::slotAddrBook()
{
KMAddrBookEditDlg dlg(kernel->addrBook());
dlg.exec();
// ----- <mirko>:
// KMAddrBookEditDlg dlg(kernel->addrBook());
// dlg.exec();
// ----- </mirko>
}
@ -2206,6 +2271,7 @@ void KMLineEdit::markAll()
//-----------------------------------------------------------------------------
void KMLineEdit::slotCompletion()
{
/*
QString t;
QString Name(name());
@ -2269,6 +2335,7 @@ void KMLineEdit::slotCompletion()
setFocus();
cursorAtEnd();
*/
}
//-----------------------------------------------------------------------------

@ -28,7 +28,11 @@
#include "kmidentity.h"
#include "kmacctmgr.h"
#include "kbusyptr.h"
#include "kmaddrbook.h"
// ----- <mirko>: replaced by KabApi:
// KMAddrBook *the_addrBook;
// #include "kmaddrbook.h"
#include <kabapi.h>
// ----- </mirko>
#include <X11/Xlib.h>
@ -330,16 +334,29 @@ void KMKernel::init()
the_acctMgr = new KMAcctMgr(acctPath);
the_filterMgr = new KMFilterMgr;
the_filterActionDict = new KMFilterActionDict;
the_addrBook = new KMAddrBook;
// ----- <mirko>: replaced by KabApi:
// the_addrBook = new KMAddrBook;
the_addrBook=new KabAPI; // KabApi is a dialog
CHECK_PTR(the_addrBook);
if(addrBook()->init()!=AddressBook::NoError)
{ // this connects to the default address book and opens it:
KMessageBox::information
(0, i18n("Error initializing the connection to your address book.\n"
"The address book will not be available."),
i18n("Error"));
the_addrBook=0;
} else {
debug ("KMKernel::init: KabApi initialized.");
}
// ----- </mirko>
initFolders(cfg);
the_acctMgr->readConfig();
the_filterMgr->readConfig();
the_addrBook->readConfig();
if(the_addrBook->load() == IO_FatalError)
{
KMessageBox::sorry(0, i18n("The addressbook could not be loaded."));
}
// the_addrBook->readConfig();
// if(the_addrBook->load() == IO_FatalError)
// {
// KMessageBox::sorry(0, i18n("The addressbook could not be loaded."));
// }
KMMessage::readConfig();
the_msgSender = new KMSender;

@ -18,7 +18,10 @@ class KMUndoStack;
class KMAcctMgr;
class KMFilterMgr;
class KMFilterActionDict;
class KMAddrBook;
// ----- <mirko>: replaced by KabApi:
// class KMAddrBook;
class KabAPI;
// ----- </mirko>
class KMSender;
class KMIdentity;
class KMKernel;
@ -71,7 +74,10 @@ public:
inline KMAcctMgr *acctMgr() { return the_acctMgr; }
inline KMFilterMgr *filterMgr() { return the_filterMgr; }
inline KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
inline KMAddrBook *addrBook() { return the_addrBook; }
// ----- <mirko>: replaced by a KabApi object:
// inline KMAddrBook *addrBook() { return the_addrBook; }
inline KabAPI* addrBook() { return the_addrBook; }
// ----- </mirko>
inline KMSender *msgSender() { return the_msgSender; }
inline bool firstStart() { return the_firstStart; }
@ -91,7 +97,10 @@ private:
KMAcctMgr *the_acctMgr;
KMFilterMgr *the_filterMgr;
KMFilterActionDict *the_filterActionDict;
KMAddrBook *the_addrBook;
// ----- <mirko>: replaced by KabApi:
// KMAddrBook *the_addrBook;
KabAPI *the_addrBook;
// ----- </mirko>
KMSender *the_msgSender;
bool the_firstStart; // is this the first start? read from config

@ -43,8 +43,10 @@
#include "kmfolderseldlg.h"
#include "kmfiltermgr.h"
#include "kmsender.h"
#include "kmaddrbookdlg.h"
#include "kmaddrbook.h"
// ----- <mirko>:
// #include "kmaddrbookdlg.h"
// #include "kmaddrbook.h"
// ----- </mirko>
#include "kwm.h"
#include <errno.h>
@ -467,8 +469,12 @@ void KMMainWin::slotFilter()
//-----------------------------------------------------------------------------
void KMMainWin::slotAddrBook()
{
KMAddrBookEditDlg dlg(kernel->addrBook());
dlg.exec();
// ----- <mirko>:
// KMAddrBookEditDlg dlg(kernel->addrBook());
// dlg.exec();
// editing the address book should probaby be done in kab:
debug("KMMainWin::slotAddrBook: not implemented.");
// ----- </mirko>:
}
@ -1055,15 +1061,12 @@ void KMMainWin::slotMailtoForward()
win->show();
}
//-----------------------------------------------------------------------------
void KMMainWin::slotMailtoAddAddrBook()
{
if (mUrlCurrent.isEmpty()) return;
kernel->addrBook()->insert(mUrlCurrent.mid(7,255));
statusMsg(i18n("Address added to addressbook."));
}
// <mirko>:
// moved KMMainWin::slotMailtoAddAddrBook to addtoaddressbook.cpp as
// it grew to much
// </mirko>
//-----------------------------------------------------------------------------
void KMMainWin::slotUrlCopy()

Loading…
Cancel
Save