[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: recent email addresses
From: Carsten Pfeiffer <carpdjih () cetus ! zrz ! tu-berlin ! de>
Date: 2001-05-30 0:13:31
[Download RAW message or body]
Hiya,
here's a patch that does the following:
Whenever you send a mail, the to, cc and bcc address(es) are added to a
stringlist. If you had multiple addresses in one line, they are kept that way.
Now when you open the address-list in the composer this list is added on top,
before the entries from the addressbook. The list is also added to the
completion. The list has a maximum number of entries (default 40) and is
persistent.
eventual TODO:
- make that configurable?
- make the number of items configurable?
- save the list more often, than just in KMKernel::cleanup()?
Cheers,
Carsten Pfeiffer
["recent.patch" (text/x-c)]
? recent.patch
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdenetwork/kmail/Makefile.am,v
retrieving revision 1.114
diff -u -p -B -w -r1.114 Makefile.am
--- Makefile.am 2001/05/11 11:43:37 1.114
+++ Makefile.am 2001/05/30 00:01:00
@@ -30,7 +30,7 @@ kmail_SOURCES = kmmessage.cpp kmmainwin.
kmkernel.cpp kmailIface.skel kmailIface.stub main.cpp \
accountdialog.cpp kmfldsearch.cpp addtoaddressbook.cpp \
kmdisplayvcard.cpp vcard.cpp \
- smtp.cpp mailinglist-magic.cpp
+ smtp.cpp mailinglist-magic.cpp kmrecentaddr.cpp
include_HEADERS = kmailIface.h
Index: kmaddrbookdlg.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmaddrbookdlg.cpp,v
retrieving revision 1.27
diff -u -p -B -w -r1.27 kmaddrbookdlg.cpp
--- kmaddrbookdlg.cpp 2001/05/20 19:16:16 1.27
+++ kmaddrbookdlg.cpp 2001/05/30 00:01:00
@@ -4,6 +4,8 @@
#include "kmaddrbookdlg.h"
#include "kmaddrbook.h"
#include "kmkernel.h"
+#include "kmrecentaddr.h"
+
#include <assert.h>
#include <kapp.h>
#include <klocale.h>
@@ -11,25 +13,20 @@
#include <kabapi.h>
//-----------------------------------------------------------------------------
-KMAddrBookSelDlg::KMAddrBookSelDlg(KMAddrBook* aAddrBook, const char* aCap):
- KMAddrBookSelDlgInherited(NULL, aCap, TRUE), mGrid(this, 2, 2),
+KMAddrBookSelDlg::KMAddrBookSelDlg(KMAddrBook* aAddrBook, const QString& aCap):
+ KMAddrBookSelDlgInherited(0L, 0L, TRUE), mGrid(this, 2, 2),
mListBox(this),
mBtnOk(i18n("OK"),this),
mBtnCancel(i18n("Cancel"),this)
{
QString addr;
- setCaption(aCap ? QString(aCap) : i18n("Addressbook"));
+ setCaption(aCap.isNull() ? i18n("Addressbook") : aCap);
assert(aAddrBook != NULL);
mAddrBook = aAddrBook;
mAddress = QString::null;
- mBtnOk.adjustSize();
- mBtnOk.setMinimumSize(mBtnOk.size());
- mBtnCancel.adjustSize();
- mBtnCancel.setMinimumSize(mBtnCancel.size());
-
mGrid.addMultiCellWidget(&mListBox, 0, 0, 0, 1);
mGrid.addWidget(&mBtnOk, 1, 0);
mGrid.addWidget(&mBtnCancel, 1, 1);
@@ -41,6 +38,7 @@ KMAddrBookSelDlg::KMAddrBookSelDlg(KMAdd
mGrid.activate();
mListBox.setSelectionMode(QListBox::Multi);
+ mBtnOk.setDefault(true);
connect(&mBtnOk, SIGNAL(clicked()), SLOT(slotOk()));
connect(&mListBox, SIGNAL(selected(int)), SLOT(slotOk()));
@@ -55,6 +53,9 @@ KMAddrBookSelDlg::KMAddrBookSelDlg(KMAdd
mListBox.insertStringList(addresses);
}
+ // insert all recent address on top
+ mListBox.insertStringList( KMRecentAddresses::self()->addresses(), 0 );
+
resize(350, 450);
}
Index: kmaddrbookdlg.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmaddrbookdlg.h,v
retrieving revision 1.9
diff -u -p -B -w -r1.9 kmaddrbookdlg.h
--- kmaddrbookdlg.h 2001/04/17 20:45:44 1.9
+++ kmaddrbookdlg.h 2001/05/30 00:01:00
@@ -24,7 +24,7 @@ class KMAddrBookSelDlg: public QDialog
{
Q_OBJECT
public:
- KMAddrBookSelDlg(KMAddrBook* addrBook, const char* caption=NULL);
+ KMAddrBookSelDlg(KMAddrBook* addrBook, const QString& caption=QString::null);
virtual ~KMAddrBookSelDlg();
/** returns selected address(es) or NULL if none was selected or the cancel
Index: kmcomposewin.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmcomposewin.cpp,v
retrieving revision 1.339
diff -u -p -B -w -r1.339 kmcomposewin.cpp
--- kmcomposewin.cpp 2001/05/24 17:55:20 1.339
+++ kmcomposewin.cpp 2001/05/30 00:01:01
@@ -79,6 +79,7 @@
#include <fcntl.h>
#include "kmglobal.h"
+#include "kmrecentaddr.h"
#include "kmcomposewin.moc"
@@ -1963,6 +1964,10 @@ void KMComposeWin::doSend(int aSendNow,
if (sentOk)
{
+ KMRecentAddresses::self()->add( bcc() );
+ KMRecentAddresses::self()->add( cc() );
+ KMRecentAddresses::self()->add( to() );
+
mAutoDeleteMsg = FALSE;
mFolder = NULL;
close();
@@ -2377,11 +2382,10 @@ KMLineEdit::KMLineEdit(KMComposeWin* com
connect (this, SIGNAL(completion()), this, SLOT(slotCompletion()));
KCompletionBox *box = completionBox();
- // ### this disconnect has to be fixed in kdeui
- disconnect( box, SIGNAL( highlighted( const QString& )),
- this, SLOT( setText( const QString& )));
connect( box, SIGNAL( highlighted( const QString& )),
this, SLOT( slotPopupCompletion( const QString& ) ));
+ connect( completionBox(), SIGNAL( userCancelled( const QString& )),
+ SLOT( slotPopupCompletion( const QString& )));
// Whenever a new KMLineEdit is created (== a new composer is created),
@@ -2592,6 +2596,11 @@ void KMLineEdit::loadAddresses()
s_completion->clear();
s_addressesDirty = false;
+ QStringList recent = KMRecentAddresses::self()->addresses();
+ QStringList::Iterator it = recent.begin();
+ for ( ; it != recent.end(); ++it )
+ s_completion->addItem( *it );
+
KMAddrBook adb;
adb.readConfig();
Index: kmcomposewin.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmcomposewin.h,v
retrieving revision 1.114
diff -u -p -B -w -r1.114 kmcomposewin.h
Index: kmkernel.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmkernel.cpp,v
retrieving revision 1.50
diff -u -p -B -w -r1.50 kmkernel.cpp
--- kmkernel.cpp 2001/05/22 09:05:35 1.50
+++ kmkernel.cpp 2001/05/30 00:01:02
@@ -34,6 +34,7 @@
#include "kfileio.h"
#include "kmpgpwrap.h"
#include "kmversion.h"
+#include "kmrecentaddr.h"
#include <kabapi.h>
#include <kwin.h>
@@ -579,6 +580,7 @@ void KMKernel::cleanup(void)
if (the_kbp) delete the_kbp;
//qInstallMsgHandler(oldMsgHandler);
+ KMRecentAddresses::self()->save( KGlobal::config() );
kapp->config()->sync();
//--- Sven's save attachments to /tmp start ---
//kdDebug() << "cleaned" << endl;
Index: kmrecentaddr.cpp
===================================================================
RCS file: kmrecentaddr.cpp
diff -N kmrecentaddr.cpp
--- /dev/null Tue May 5 20:32:27 1998
+++ kmrecentaddr.cpp Wed May 30 00:01:02 2001
@@ -0,0 +1,60 @@
+#include <kconfig.h>
+#include <kglobal.h>
+
+#include "kmrecentaddr.h"
+
+KMRecentAddresses * KMRecentAddresses::s_self = 0L;
+
+KMRecentAddresses * KMRecentAddresses::self()
+{
+ if ( !s_self )
+ s_self = new KMRecentAddresses();
+ return s_self;
+}
+
+KMRecentAddresses::KMRecentAddresses()
+{
+ load( KGlobal::config() );
+}
+
+KMRecentAddresses::~KMRecentAddresses()
+{
+}
+
+void KMRecentAddresses::load( KConfig *config )
+{
+ m_addresses.clear();
+ KConfigGroupSaver cs( config, "General" );
+ m_maxCount = config->readNumEntry( "Maximum Recent Addresses", 40 );
+ m_addresses = config->readListEntry( "Recent Addresses" );
+
+ adjustSize();
+}
+
+void KMRecentAddresses::save( KConfig *config )
+{
+ KConfigGroupSaver cs( config, "General" );
+ config->writeEntry( "Recent Addresses", m_addresses );
+}
+
+void KMRecentAddresses::add( const QString& entry )
+{
+ if ( !entry.isEmpty() && m_maxCount > 0 && m_addresses.first() != entry ) {
+ m_addresses.remove( entry ); // removes all existing "entry" items
+ m_addresses.prepend( entry );
+ adjustSize();
+ }
+}
+
+void KMRecentAddresses::setMaxCount( int count )
+{
+ m_maxCount = count;
+ adjustSize();
+}
+
+void KMRecentAddresses::adjustSize()
+{
+ // for convenience, we don't sync the completion objects here.
+ while ( m_addresses.count() > m_maxCount )
+ m_addresses.remove( m_addresses.fromLast() );
+}
Index: kmrecentaddr.h
===================================================================
RCS file: kmrecentaddr.h
diff -N kmrecentaddr.h
--- /dev/null Tue May 5 20:32:27 1998
+++ kmrecentaddr.h Wed May 30 00:01:02 2001
@@ -0,0 +1,73 @@
+#ifndef KMRECENTADDR_H
+#define KMRECENTADDR_H
+
+#include <qstringlist.h>
+
+/**
+ * Handles a list of "recent email-addresses". Simply set a max-count and
+ * call @ref add() to add entries.
+ *
+ * @author Carsten Pfeiffer <pfeiffer@kde.org>
+ */
+
+class KMRecentAddresses
+{
+ friend class foobar; // private destructor
+
+public:
+ /**
+ * @returns the only possible instance of this class.
+ */
+ static KMRecentAddresses * KMRecentAddresses::self();
+
+ /**
+ * @returns the list of recent addresses.
+ * Note: an entry doesn't have to be one email address, it can be multiple,
+ * like "Foo <foo@bar.org>, Bar Baz <bar@baz.org>".
+ */
+ QStringList addresses() const { return m_addresses; }
+
+ /**
+ * Adds an entry to the list.
+ * Note: an entry doesn't have to be one email address, it can be multiple,
+ * like "Foo <foo@bar.org>, Bar Baz <bar@baz.org>".
+ */
+ void add( const QString& entry );
+
+ /**
+ * Sets the maximum number, the list can hold. The list adjusts to this
+ * size if necessary. Default maximum is 40.
+ */
+ void setMaxCount( int count );
+
+ /**
+ * @returns the current maximum number of entries.
+ */
+ int maxCount() const { return m_maxCount; }
+
+ /**
+ * Loads the list of recently used addresses from the configfile.
+ * Automatically done on startup.
+ */
+ void load( KConfig * );
+
+ /**
+ * Saves the list of recently used addresses to the configfile.
+ * Make sure to call KGlobal::config()->sync() afterwards, to really save.
+ */
+ void save( KConfig * );
+
+private:
+ KMRecentAddresses();
+ ~KMRecentAddresses();
+
+ void adjustSize();
+
+ int m_maxCount;
+ QStringList m_addresses;
+
+ static KMRecentAddresses *s_self;
+
+};
+
+#endif // KMRECENTADDR_H
_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.kde.org/mailman/listinfo/kmail
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic