kmail

recipientspicker.h
1 /*
2  This file is part of KMail.
3 
4  Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #ifndef RECIPIENTSPICKER_H
22 #define RECIPIENTSPICKER_H
23 
24 #include <config.h> // for TDEPIM_NEW_DISTRLISTS
25 
26 #include "recipientseditor.h"
27 
28 #include <tdelistview.h>
29 #include <tdelistviewsearchline.h>
30 #include <tdeabc/addressee.h>
31 #include <tdeabc/stdaddressbook.h>
32 
33 #include <tqwidget.h>
34 #include <tqdialog.h>
35 #include <tqtooltip.h>
36 
37 class TQComboBox;
38 
39 #ifdef TDEPIM_NEW_DISTRLISTS
40 #include <libtdepim/distributionlist.h>
41 #else
42 namespace TDEABC {
43 class DistributionList;
44 class DistributionListManager;
45 }
46 #endif
47 
48 namespace KPIM {
49 class LDAPSearchDialog;
50 }
51 
52 class RecipientItem
53 {
54  public:
55  typedef TQValueList<RecipientItem *> List;
56 
57 #ifdef TDEPIM_NEW_DISTRLISTS
58  RecipientItem( TDEABC::AddressBook *ab );
59  void setDistributionList( KPIM::DistributionList& );
60  KPIM::DistributionList& distributionList();
61 #else
62  RecipientItem();
63  void setDistributionList( TDEABC::DistributionList * );
64  TDEABC::DistributionList * distributionList();
65 #endif
66  void setAddressee( const TDEABC::Addressee &, const TQString &email );
67 
68  void setRecipientType( const TQString &type );
69  TQString recipientType() const;
70 
71  TQString recipient() const;
72 
73  TQPixmap icon() const;
74  TQString name() const;
75  TQString email() const;
76 
77  TQString key() const { return mKey; }
78 
79  TQString tooltip() const;
80 
81  private:
82 #ifdef TDEPIM_NEW_DISTRLISTS
83  TQString createTooltip( KPIM::DistributionList & ) const;
84 #else
85  TQString createTooltip( TDEABC::DistributionList * ) const;
86 #endif
87 
88  TDEABC::Addressee mAddressee;
89  TQString mName;
90  TQString mEmail;
91  TQString mRecipient;
92 #ifdef TDEPIM_NEW_DISTRLISTS
93  KPIM::DistributionList mDistributionList;
94  TDEABC::AddressBook *mAddressBook;
95 #else
96  TDEABC::DistributionList *mDistributionList;
97 #endif
98  TQString mType;
99  TQString mTooltip;
100 
101  TQPixmap mIcon;
102 
103  TQString mKey;
104 };
105 
106 class RecipientViewItem : public TDEListViewItem
107 {
108  public:
109  RecipientViewItem( RecipientItem *, TDEListView * );
110 
111  RecipientItem *recipientItem() const;
112 
113  private:
114  RecipientItem *mRecipientItem;
115 };
116 
117 class RecipientsListToolTip : public TQToolTip
118 {
119  public:
120  RecipientsListToolTip( TQWidget *parent, TDEListView * );
121 
122  protected:
123  void maybeTip( const TQPoint &pos );
124 
125  private:
126  TDEListView *mListView;
127 };
128 
129 class RecipientsCollection
130 {
131  public:
132  RecipientsCollection( const TQString & );
133  ~RecipientsCollection();
134 
135  void setReferenceContainer( bool );
136  bool isReferenceContainer() const;
137 
138  void setTitle( const TQString & );
139  TQString title() const;
140 
141  void addItem( RecipientItem * );
142 
143  RecipientItem::List items() const;
144 
145  bool hasEquivalentItem( RecipientItem * ) const;
146  RecipientItem * getEquivalentItem( RecipientItem *) const;
147 
148  void clear();
149 
150  void deleteAll();
151 
152  TQString id() const;
153 
154  private:
155  // flag to indicate if this collection contains just references
156  // or should manage memory (de)allocation as well.
157  bool mIsReferenceContainer;
158  TQString mId;
159  TQString mTitle;
160  TQMap<TQString, RecipientItem *> mKeyMap;
161 };
162 
163 class SearchLine : public TDEListViewSearchLine
164 {
165  TQ_OBJECT
166 
167  public:
168  SearchLine( TQWidget *parent, TDEListView *listView );
169 
170  signals:
171  void downPressed();
172 
173  protected:
174  void keyPressEvent( TQKeyEvent * );
175 };
176 
177 using namespace TDEABC;
178 
179 class RecipientsPicker : public TQDialog
180 {
181  TQ_OBJECT
182 
183  public:
184  RecipientsPicker( TQWidget *parent );
185  ~RecipientsPicker();
186 
187  void setRecipients( const Recipient::List & );
188  void updateRecipient( const Recipient & );
189 
190  void setDefaultType( Recipient::Type );
191 
192  signals:
193  void pickedRecipient( const Recipient & );
194 
195  protected:
196  void initCollections();
197  void insertDistributionLists();
198  void insertRecentAddresses();
199  void insertCollection( RecipientsCollection *coll );
200 
201  void keyPressEvent( TQKeyEvent *ev );
202 
203  void readConfig();
204  void writeConfig();
205 
206  void pick( Recipient::Type );
207 
208  void setDefaultButton( TQPushButton *button );
209 
210  void rebuildAllRecipientsList();
211 
212  protected slots:
213  void updateList();
214  void slotToClicked();
215  void slotCcClicked();
216  void slotBccClicked();
217  void slotPicked( TQListViewItem * );
218  void slotPicked();
219  void setFocusList();
220  void resetSearch();
221  void insertAddressBook( AddressBook * );
222  void slotSearchLDAP();
223  void ldapSearchResult();
224  private:
225  TDEABC::StdAddressBook *mAddressBook;
226 
227  TQComboBox *mCollectionCombo;
228  TDEListView *mRecipientList;
229  TDEListViewSearchLine *mSearchLine;
230 
231  TQPushButton *mToButton;
232  TQPushButton *mCcButton;
233  TQPushButton *mBccButton;
234 
235  TQPushButton *mSearchLDAPButton;
236  KPIM::LDAPSearchDialog *mLdapSearchDialog;
237 
238  TQMap<int,RecipientsCollection *> mCollectionMap;
239  RecipientsCollection *mAllRecipients;
240  RecipientsCollection *mDistributionLists;
241  RecipientsCollection *mSelectedRecipients;
242 
243 #ifndef TDEPIM_NEW_DISTRLISTS
244  TDEABC::DistributionListManager *mDistributionListManager;
245 #endif
246 
247  Recipient::Type mDefaultType;
248 };
249 
250 #endif