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