[PATCH] Replacing email selection dialog in kmail

Tobias Koenig tokoe at kde.org
Sun Nov 30 16:18:30 GMT 2003


Hi,

the current email selection dialog (the one which appears when you click
on the button next to the 'To', 'Cc' or 'Bcc' field in the mail composer
window) really sucks from the technical (bugs) and usability point of
view (too much buttons, splitter, missing scrollbars and 3 actions
merged into one dialog).

For this reasons I'd like to ask if the attached patches can be commited
to CVS HEAD. With them KMail will use the contact selection dialog from
libkabc (KABC::AddresseeDialog) which needs a small extension for this
purpose.

I know it's quite late in the release schedule, but also the kmail
developer would like to see this dialog be used for 3.2.

Ciao,
Tobias
-- 
Can a government that shoots at reporters be democratic?
Separate politics from religion and economy!
-------------- next part --------------
? plugins/xmlrpc
Index: addresseedialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/addresseedialog.cpp,v
retrieving revision 1.9
diff -p -u -b -r1.9 addresseedialog.cpp
--- addresseedialog.cpp	4 Oct 2003 15:43:21 -0000	1.9
+++ addresseedialog.cpp	30 Nov 2003 16:06:54 -0000
@@ -88,7 +88,6 @@ AddresseeDialog::AddresseeDialog( QWidge
     QBoxLayout *selectedLayout = new QVBoxLayout;
     topLayout->addLayout( selectedLayout );
     topLayout->setSpacing( spacingHint() );
-//    selectedLayout->addSpacing( spacingHint() );
 
     QGroupBox *selectedGroup = new QGroupBox( 1, Horizontal, i18n("Selected"),
                                               topWidget );
@@ -97,6 +96,8 @@ AddresseeDialog::AddresseeDialog( QWidge
     mSelectedList = new KListView( selectedGroup );
     mSelectedList->addColumn( i18n("Name") );
     mSelectedList->addColumn( i18n("Email") );
+    mSelectedList->setAllColumnsShowFocus( true );
+    mSelectedList->setResizeMode( QListView::LastColumn );
     connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
              SLOT( removeSelected() ) );
 
@@ -232,7 +233,15 @@ Addressee AddresseeDialog::getAddressee(
 
 Addressee::List AddresseeDialog::getAddressees( QWidget *parent )
 {
+  return AddresseeDialog::getAddressees( parent, QStringList() );
+}
+
+Addressee::List AddresseeDialog::getAddressees( QWidget *parent, const QStringList &emails )
+{
   AddresseeDialog *dlg = new AddresseeDialog( parent, true );
+  if ( !emails.isEmpty() )
+    dlg->setSelectedEmails( emails );
+
   Addressee::List addressees;
   int result = dlg->exec();
   if ( result == QDialog::Accepted ) {
@@ -247,3 +256,17 @@ void AddresseeDialog::addressBookChanged
 {
   loadAddressBook();
 }
+
+void AddresseeDialog::setSelectedEmails( const QStringList &emails )
+{
+  QListViewItemIterator itemIt( mAddresseeList );
+  while ( itemIt.current() ) {
+    AddresseeItem *item = dynamic_cast<AddresseeItem *>( itemIt.current() );
+    if ( item ) {
+      if ( emails.find( item->addressee().preferredEmail() ) != emails.end() )
+        addSelected( item );
+    }
+
+    ++itemIt;
+  }
+}
Index: addresseedialog.h
===================================================================
RCS file: /home/kde/kdelibs/kabc/addresseedialog.h,v
retrieving revision 1.14
diff -p -u -b -r1.14 addresseedialog.h
--- addresseedialog.h	16 Aug 2003 19:44:56 -0000	1.14
+++ addresseedialog.h	30 Nov 2003 16:06:54 -0000
@@ -127,6 +127,16 @@ class AddresseeDialog : public KDialogBa
     */
     static Addressee::List getAddressees( QWidget *parent );
 
+    /**
+      Select multiple address book entries.
+      
+      Open addressee select dialog and return the entries selected by the user.
+      If the user doesn't select an entry or presses cancel, the returned
+      addressee list is empty. In the second argument you can pass a list of 
+      email addresses which shall already be selected.
+    */
+    static Addressee::List getAddressees( QWidget *parent, const QStringList &emails );
+
   private slots:
     void selectItem( const QString & );
     void updateEdit( QListViewItem *item );
@@ -139,6 +149,7 @@ class AddresseeDialog : public KDialogBa
   private:
     void loadAddressBook();
     void addCompletionItem( const QString &str, QListViewItem *item );
+    void setSelectedEmails( const QStringList &emails );
 
     bool mMultiple;
 
-------------- next part --------------
Index: kmcomposewin.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmcomposewin.cpp,v
retrieving revision 1.766
diff -p -u -b -r1.766 kmcomposewin.cpp
--- kmcomposewin.cpp	23 Nov 2003 18:03:22 -0000	1.766
+++ kmcomposewin.cpp	30 Nov 2003 16:09:12 -0000
@@ -37,8 +37,6 @@
 using KMail::AttachmentListView;
 #include "dictionarycombobox.h"
 using KMail::DictionaryComboBox;
-#include "addressesdialog.h"
-using KPIM::AddressesDialog;
 #include <maillistdrag.h>
 using KPIM::MailListDrag;
 #include "recentaddresses.h"
@@ -48,6 +46,7 @@ using KRecentAddress::RecentAddresses;
 
 #include "klistboxdialog.h"
 
+#include <kabc/addresseedialog.h>
 #include <kcharsets.h>
 #include <kcompletionbox.h>
 #include <kcursor.h>
@@ -222,8 +221,8 @@ KMComposeWin::KMComposeWin( KMMessage *a
   connect(mEdtSubject,SIGNAL(textChanged(const QString&)),
 	  SLOT(slotUpdWinTitle(const QString&)));
   connect(mBtnTo,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
-  connect(mBtnCc,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
-  connect(mBtnBcc,SIGNAL(clicked()),SLOT(slotAddrBookTo()));
+  connect(mBtnCc,SIGNAL(clicked()),SLOT(slotAddrBookCc()));
+  connect(mBtnBcc,SIGNAL(clicked()),SLOT(slotAddrBookBcc()));
   connect(mBtnReplyTo,SIGNAL(clicked()),SLOT(slotAddrBookReplyTo()));
   connect(mBtnFrom,SIGNAL(clicked()),SLOT(slotAddrBookFrom()));
   connect(mIdentity,SIGNAL(identityChanged(uint)),
@@ -3874,47 +3873,6 @@ bool KMComposeWin::signFlagOfAttachment(
     : false;
 }
 
-
-//-----------------------------------------------------------------------------
-void KMComposeWin::addrBookSelInto()
-{
-  AddressesDialog dlg( this );
-  QString txt;
-  QStringList lst;
-
-  txt = mEdtTo->text().stripWhiteSpace();
-  if ( !txt.isEmpty() ) {
-      lst = KMMessage::splitEmailAddrList( txt );
-      dlg.setSelectedTo( lst );
-  }
-
-  txt = mEdtCc->text().stripWhiteSpace();
-  if ( !txt.isEmpty() ) {
-      lst = KMMessage::splitEmailAddrList( txt );
-      dlg.setSelectedCC( lst );
-  }
-
-  txt = mEdtBcc->text().stripWhiteSpace();
-  if ( !txt.isEmpty() ) {
-      lst = KMMessage::splitEmailAddrList( txt );
-      dlg.setSelectedBCC( lst );
-  }
-
-  dlg.setRecentAddresses( RecentAddresses::self()->kabcAddresses() );
-
-  if (dlg.exec()==QDialog::Rejected) return;
-
-  mEdtTo->setText( dlg.to().join(", ") );
-  mEdtTo->setEdited( true );
-
-  mEdtCc->setText( dlg.cc().join(", ") );
-  mEdtCc->setEdited( true );
-
-  mEdtBcc->setText( dlg.bcc().join(", ") );
-  mEdtBcc->setEdited( true );
-}
-
-
 //-----------------------------------------------------------------------------
 void KMComposeWin::setCharset(const QCString& aCharset, bool forceDefault)
 {
@@ -3963,21 +3921,57 @@ void KMComposeWin::slotAddrBook()
 //-----------------------------------------------------------------------------
 void KMComposeWin::slotAddrBookFrom()
 {
-  addrBookSelInto();
+  addrBookXXX( mEdtFrom );
 }
 
 
 //-----------------------------------------------------------------------------
 void KMComposeWin::slotAddrBookReplyTo()
 {
-  addrBookSelInto();
+  addrBookXXX( mEdtReplyTo );
 }
 
 
 //-----------------------------------------------------------------------------
 void KMComposeWin::slotAddrBookTo()
 {
-  addrBookSelInto();
+  addrBookXXX( mEdtTo );
+}
+
+//-----------------------------------------------------------------------------
+void KMComposeWin::slotAddrBookCc()
+{
+  addrBookXXX( mEdtCc );
+}
+
+//-----------------------------------------------------------------------------
+void KMComposeWin::slotAddrBookBcc()
+{
+  addrBookXXX( mEdtBcc );
+}
+
+//-----------------------------------------------------------------------------
+void KMComposeWin::addrBookXXX( KMLineEdit *lineEdit )
+{
+  if ( !lineEdit )
+    return;
+
+  QStringList emails;
+  QString txt = lineEdit->text().stripWhiteSpace();
+  if ( !txt.isEmpty() )
+    emails = KMMessage::splitEmailAddrList( txt );
+
+  KABC::Addressee::List addrs = KABC::AddresseeDialog::getAddressees( this, emails );
+
+  emails.clear();
+
+  KABC::Addressee::List::Iterator it;
+  for ( it = addrs.begin(); it != addrs.end(); ++it )
+    if ( !(*it).preferredEmail().isEmpty() )
+      emails.append( (*it).preferredEmail() );
+
+  lineEdit->setText( emails.join( ", " ) );
+  lineEdit->setEdited( true );
 }
 
 //-----------------------------------------------------------------------------
Index: kmcomposewin.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmcomposewin.h,v
retrieving revision 1.225
diff -p -u -b -r1.225 kmcomposewin.h
--- kmcomposewin.h	23 Nov 2003 18:03:23 -0000	1.225
+++ kmcomposewin.h	30 Nov 2003 16:09:14 -0000
@@ -500,6 +500,8 @@ public slots:
    * the pressed button belongs to.
    */
   void slotAddrBookTo();
+  void slotAddrBookCc();
+  void slotAddrBookBcc();
   void slotAddrBookFrom();
   void slotAddrBookReplyTo();
 
@@ -831,6 +833,8 @@ private slots:
   void slotConfigChanged();
 
 private:
+  void addrBookXXX( KMLineEdit* );
+
   QColor mForeColor,mBackColor;
   struct atmLoadData
   {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20031130/e7467ec1/attachment.sig>


More information about the kde-core-devel mailing list