kmail
recipientspicker.h
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 "recipientseditor.h" 00025 00026 #include <klistview.h> 00027 #include <klistviewsearchline.h> 00028 #include <kabc/addressee.h> 00029 #include <kabc/stdaddressbook.h> 00030 00031 #include <qwidget.h> 00032 #include <qdialog.h> 00033 #include <qtooltip.h> 00034 00035 class QComboBox; 00036 00037 namespace KABC { 00038 class DistributionList; 00039 class DistributionListManager; 00040 } 00041 00042 class RecipientItem 00043 { 00044 public: 00045 typedef QValueList<RecipientItem *> List; 00046 00047 RecipientItem(); 00048 00049 void setDistributionList( KABC::DistributionList * ); 00050 void setAddressee( const KABC::Addressee &, const QString &email ); 00051 00052 void setRecipientType( const QString &type ); 00053 QString recipientType() const; 00054 00055 QString recipient() const; 00056 00057 QPixmap icon() const; 00058 QString name() const; 00059 QString email() const; 00060 00061 QString key() const { return mKey; } 00062 00063 QString toolTip() const; 00064 00065 private: 00066 KABC::Addressee mAddressee; 00067 QString mEmail; 00068 KABC::DistributionList *mDistributionList; 00069 QString mType; 00070 00071 QPixmap mIcon; 00072 00073 QString mKey; 00074 }; 00075 00076 class RecipientViewItem : public KListViewItem 00077 { 00078 public: 00079 RecipientViewItem( RecipientItem *, KListView * ); 00080 00081 RecipientItem *recipientItem() const; 00082 00083 private: 00084 RecipientItem *mRecipientItem; 00085 }; 00086 00087 class RecipientsListToolTip : public QToolTip 00088 { 00089 public: 00090 RecipientsListToolTip( QWidget *parent, KListView * ); 00091 00092 protected: 00093 void maybeTip( const QPoint &pos ); 00094 00095 private: 00096 KListView *mListView; 00097 }; 00098 00099 class RecipientsCollection 00100 { 00101 public: 00102 RecipientsCollection(); 00103 ~RecipientsCollection(); 00104 00105 void setTitle( const QString & ); 00106 QString title() const; 00107 00108 void addItem( RecipientItem * ); 00109 00110 RecipientItem::List items() const; 00111 00112 bool hasEquivalentItem( RecipientItem * ) const; 00113 00114 void clear(); 00115 00116 void deleteAll(); 00117 00118 private: 00119 QString mTitle; 00120 RecipientItem::List mItems; 00121 QMap<QString, RecipientItem *> mKeyMap; 00122 }; 00123 00124 class SearchLine : public KListViewSearchLine 00125 { 00126 Q_OBJECT 00127 public: 00128 SearchLine( QWidget *parent, KListView *listView ); 00129 00130 signals: 00131 void downPressed(); 00132 00133 protected: 00134 void keyPressEvent( QKeyEvent * ); 00135 }; 00136 00137 using namespace KABC; 00138 00139 class RecipientsPicker : public QDialog 00140 { 00141 Q_OBJECT 00142 public: 00143 RecipientsPicker( QWidget *parent ); 00144 ~RecipientsPicker(); 00145 00146 void setRecipients( const Recipient::List & ); 00147 void updateRecipient( const Recipient & ); 00148 00149 void setDefaultType( Recipient::Type ); 00150 00151 signals: 00152 void pickedRecipient( const Recipient & ); 00153 00154 protected: 00155 void initCollections(); 00156 void insertDistributionLists(); 00157 void insertRecentAddresses(); 00158 void insertCollection( RecipientsCollection *coll ); 00159 00160 void keyPressEvent( QKeyEvent *ev ); 00161 00162 void readConfig(); 00163 void writeConfig(); 00164 00165 void pick( Recipient::Type ); 00166 00167 void setDefaultButton( QPushButton *button ); 00168 00169 protected slots: 00170 void updateList(); 00171 void slotToClicked(); 00172 void slotCcClicked(); 00173 void slotBccClicked(); 00174 void slotPicked( QListViewItem * ); 00175 void slotPicked(); 00176 void setFocusList(); 00177 void resetSearch(); 00178 void insertAddressBook( AddressBook * ); 00179 00180 private: 00181 KABC::StdAddressBook *mAddressBook; 00182 00183 QComboBox *mCollectionCombo; 00184 KListView *mRecipientList; 00185 KListViewSearchLine *mSearchLine; 00186 00187 QPushButton *mToButton; 00188 QPushButton *mCcButton; 00189 QPushButton *mBccButton; 00190 00191 QMap<int,RecipientsCollection *> mCollectionMap; 00192 RecipientsCollection *mAllRecipients; 00193 RecipientsCollection *mSelectedRecipients; 00194 00195 KABC::DistributionListManager *mDistributionListManager; 00196 00197 Recipient::Type mDefaultType; 00198 }; 00199 00200 #endif