kmail
recipientspicker.h
Go to the documentation of this file.00001 /* 00002 This file is part of KMail. 00003 00004 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef RECIPIENTSPICKER_H 00022 #define RECIPIENTSPICKER_H 00023 00024 #include <config.h> // for KDEPIM_NEW_DISTRLISTS 00025 00026 #include "recipientseditor.h" 00027 00028 #include <klistview.h> 00029 #include <klistviewsearchline.h> 00030 #include <kabc/addressee.h> 00031 #include <kabc/stdaddressbook.h> 00032 00033 #include <qwidget.h> 00034 #include <qdialog.h> 00035 #include <qtooltip.h> 00036 00037 class QComboBox; 00038 00039 #ifdef KDEPIM_NEW_DISTRLISTS 00040 #include <libkdepim/distributionlist.h> 00041 #else 00042 namespace KABC { 00043 class DistributionList; 00044 class DistributionListManager; 00045 } 00046 #endif 00047 00048 namespace KPIM { 00049 class LDAPSearchDialog; 00050 } 00051 00052 class RecipientItem 00053 { 00054 public: 00055 typedef QValueList<RecipientItem *> List; 00056 00057 #ifdef KDEPIM_NEW_DISTRLISTS 00058 RecipientItem( KABC::AddressBook *ab ); 00059 void setDistributionList( KPIM::DistributionList& ); 00060 KPIM::DistributionList& distributionList(); 00061 #else 00062 RecipientItem(); 00063 void setDistributionList( KABC::DistributionList * ); 00064 KABC::DistributionList * distributionList(); 00065 #endif 00066 void setAddressee( const KABC::Addressee &, const QString &email ); 00067 00068 void setRecipientType( const QString &type ); 00069 QString recipientType() const; 00070 00071 QString recipient() const; 00072 00073 QPixmap icon() const; 00074 QString name() const; 00075 QString email() const; 00076 00077 QString key() const { return mKey; } 00078 00079 QString tooltip() const; 00080 00081 private: 00082 #ifdef KDEPIM_NEW_DISTRLISTS 00083 QString createTooltip( KPIM::DistributionList & ) const; 00084 #else 00085 QString createTooltip( KABC::DistributionList * ) const; 00086 #endif 00087 00088 KABC::Addressee mAddressee; 00089 QString mName; 00090 QString mEmail; 00091 QString mRecipient; 00092 #ifdef KDEPIM_NEW_DISTRLISTS 00093 KPIM::DistributionList mDistributionList; 00094 KABC::AddressBook *mAddressBook; 00095 #else 00096 KABC::DistributionList *mDistributionList; 00097 #endif 00098 QString mType; 00099 QString mTooltip; 00100 00101 QPixmap mIcon; 00102 00103 QString mKey; 00104 }; 00105 00106 class RecipientViewItem : public KListViewItem 00107 { 00108 public: 00109 RecipientViewItem( RecipientItem *, KListView * ); 00110 00111 RecipientItem *recipientItem() const; 00112 00113 private: 00114 RecipientItem *mRecipientItem; 00115 }; 00116 00117 class RecipientsListToolTip : public QToolTip 00118 { 00119 public: 00120 RecipientsListToolTip( QWidget *parent, KListView * ); 00121 00122 protected: 00123 void maybeTip( const QPoint &pos ); 00124 00125 private: 00126 KListView *mListView; 00127 }; 00128 00129 class RecipientsCollection 00130 { 00131 public: 00132 RecipientsCollection( const QString & ); 00133 ~RecipientsCollection(); 00134 00135 void setReferenceContainer( bool ); 00136 bool isReferenceContainer() const; 00137 00138 void setTitle( const QString & ); 00139 QString title() const; 00140 00141 void addItem( RecipientItem * ); 00142 00143 RecipientItem::List items() const; 00144 00145 bool hasEquivalentItem( RecipientItem * ) const; 00146 RecipientItem * getEquivalentItem( RecipientItem *) const; 00147 00148 void clear(); 00149 00150 void deleteAll(); 00151 00152 QString id() const; 00153 00154 private: 00155 // flag to indicate if this collection contains just references 00156 // or should manage memory (de)allocation as well. 00157 bool mIsReferenceContainer; 00158 QString mId; 00159 QString mTitle; 00160 QMap<QString, RecipientItem *> mKeyMap; 00161 }; 00162 00163 class SearchLine : public KListViewSearchLine 00164 { 00165 Q_OBJECT 00166 public: 00167 SearchLine( QWidget *parent, KListView *listView ); 00168 00169 signals: 00170 void downPressed(); 00171 00172 protected: 00173 void keyPressEvent( QKeyEvent * ); 00174 }; 00175 00176 using namespace KABC; 00177 00178 class RecipientsPicker : public QDialog 00179 { 00180 Q_OBJECT 00181 public: 00182 RecipientsPicker( QWidget *parent ); 00183 ~RecipientsPicker(); 00184 00185 void setRecipients( const Recipient::List & ); 00186 void updateRecipient( const Recipient & ); 00187 00188 void setDefaultType( Recipient::Type ); 00189 00190 signals: 00191 void pickedRecipient( const Recipient & ); 00192 00193 protected: 00194 void initCollections(); 00195 void insertDistributionLists(); 00196 void insertRecentAddresses(); 00197 void insertCollection( RecipientsCollection *coll ); 00198 00199 void keyPressEvent( QKeyEvent *ev ); 00200 00201 void readConfig(); 00202 void writeConfig(); 00203 00204 void pick( Recipient::Type ); 00205 00206 void setDefaultButton( QPushButton *button ); 00207 00208 void rebuildAllRecipientsList(); 00209 00210 protected slots: 00211 void updateList(); 00212 void slotToClicked(); 00213 void slotCcClicked(); 00214 void slotBccClicked(); 00215 void slotPicked( QListViewItem * ); 00216 void slotPicked(); 00217 void setFocusList(); 00218 void resetSearch(); 00219 void insertAddressBook( AddressBook * ); 00220 void slotSearchLDAP(); 00221 void ldapSearchResult(); 00222 private: 00223 KABC::StdAddressBook *mAddressBook; 00224 00225 QComboBox *mCollectionCombo; 00226 KListView *mRecipientList; 00227 KListViewSearchLine *mSearchLine; 00228 00229 QPushButton *mToButton; 00230 QPushButton *mCcButton; 00231 QPushButton *mBccButton; 00232 00233 QPushButton *mSearchLDAPButton; 00234 KPIM::LDAPSearchDialog *mLdapSearchDialog; 00235 00236 QMap<int,RecipientsCollection *> mCollectionMap; 00237 RecipientsCollection *mAllRecipients; 00238 RecipientsCollection *mDistributionLists; 00239 RecipientsCollection *mSelectedRecipients; 00240 00241 #ifndef KDEPIM_NEW_DISTRLISTS 00242 KABC::DistributionListManager *mDistributionListManager; 00243 #endif 00244 00245 Recipient::Type mDefaultType; 00246 }; 00247 00248 #endif