libtdepim

addresseeselector.h
1 /*
2  This file is part of libtdepim.
3 
4  Copyright (c) 2004 Tobias Koenig <tokoe@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 
22 #ifndef KPIM_ADDRESSEESELECTOR_H
23 #define KPIM_ADDRESSEESELECTOR_H
24 
25 #include <tdeabc/addressee.h>
26 #include <tdeabc/distributionlist.h>
27 #include <tdeabc/resource.h>
28 #include <kdialogbase.h>
29 #include <tdemacros.h>
30 
31 #include <tqbitarray.h>
32 #include <tqpixmap.h>
33 #include <tqwidget.h>
34 
35 class KComboBox;
36 class KLineEdit;
37 class TDEListView;
38 class TQSignalMapper;
39 
40 namespace KPIM {
41 
42 class AddresseeSelector;
43 
44 class TDE_EXPORT Selection
45 {
46  friend class AddresseeSelector;
47 
48  public:
49  virtual ~Selection() {}
50 
54  virtual uint fieldCount() const = 0;
55 
59  virtual TQString fieldTitle( uint index ) const = 0;
60 
64  virtual uint itemCount( const TDEABC::Addressee &addresse ) const = 0;
65 
69  virtual TQString itemText( const TDEABC::Addressee &addresse, uint index ) const = 0;
70 
74  virtual TQPixmap itemIcon( const TDEABC::Addressee &addresse, uint index ) const = 0;
75 
79  virtual bool itemEnabled( const TDEABC::Addressee &addresse, uint index ) const = 0;
80 
84  virtual bool itemMatches( const TDEABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0;
85 
89  virtual bool itemEquals( const TDEABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0;
90 
94  virtual TQString distributionListText( const TDEABC::DistributionList *distributionList ) const = 0;
95 
99  virtual TQPixmap distributionListIcon( const TDEABC::DistributionList *distributionList ) const = 0;
100 
104  virtual bool distributionListEnabled( const TDEABC::DistributionList *distributionList ) const = 0;
105 
109  virtual bool distributionListMatches( const TDEABC::DistributionList *distributionList,
110  const TQString &pattern ) const = 0;
111 
115  virtual uint addressBookCount() const = 0;
116 
120  virtual TQString addressBookTitle( uint index ) const = 0;
121 
125  virtual TDEABC::Addressee::List addressBookContent( uint index ) const = 0;
126 
127  protected:
128  AddresseeSelector* selector() { return mSelector; }
129 
130  private:
131  virtual void addSelectedAddressees( uint fieldIndex, const TDEABC::Addressee&, uint itemIndex ) = 0;
132  virtual void addSelectedDistributionList( uint fieldIndex, const TDEABC::DistributionList* ) = 0;
133 
134  void setSelector( AddresseeSelector *selector ) { mSelector = selector; }
135 
136  AddresseeSelector *mSelector;
137 };
138 
143 {
144  public:
145  typedef TQValueList<SelectionItem> List;
146 
147  SelectionItem( const TDEABC::Addressee &addressee, uint index );
148  SelectionItem( TDEABC::DistributionList *list, uint index );
149  SelectionItem();
150 
151  void addToField( int index );
152  void removeFromField( int index );
153  bool isInField( int index );
154 
155  TDEABC::Addressee addressee() const;
156  TDEABC::DistributionList* distributionList() const;
157  uint index() const;
158 
159  private:
160  TDEABC::Addressee mAddressee;
161  TDEABC::DistributionList *mDistributionList;
162  uint mIndex;
163  TQBitArray mField;
164 };
165 
166 class TDE_EXPORT AddresseeSelector : public TQWidget
167 {
168  TQ_OBJECT
169 
170 
171  public:
172  AddresseeSelector( Selection *selection,
173  TQWidget *parent, const char *name = 0 );
174  ~AddresseeSelector();
175 
179  void finish();
180 
181  void setItemSelected( uint fieldIndex, const TDEABC::Addressee&, uint itemIndex );
182  void setItemSelected( uint fieldIndex, const TDEABC::Addressee&,
183  uint itemIndex, const TQString& );
184 
185  private slots:
186  void move( int index );
187  void remove( int index );
188 
189  void updateAddresseeView();
190  void reloadAddressBook();
191 
192  private:
193  void init();
194  void initGUI();
195 
196  void updateSelectionView( int index );
197  void updateSelectionViews();
198 
199  Selection *mSelection;
200 
201  KComboBox *mAddressBookCombo;
202  KLineEdit *mAddresseeFilter;
203  TDEListView *mAddresseeView;
204  SelectionItem::List mSelectionItems;
205 
206  TQValueList<TDEListView*> mSelectionViews;
207  TQSignalMapper *mMoveMapper;
208  TQSignalMapper *mRemoveMapper;
209 
210  TDEABC::DistributionListManager *mManager;
211 
212  class AddressBookManager;
213  AddressBookManager *mAddressBookManager;
214 };
215 
216 class TDE_EXPORT AddresseeSelectorDialog : public KDialogBase
217 {
218  TQ_OBJECT
219 
220 
221  public:
222  AddresseeSelectorDialog( Selection *selection,
223  TQWidget *parent = 0, const char *name = 0 );
224 
225  protected slots:
226  void accept();
227 
228  private:
229  AddresseeSelector *mSelector;
230 };
231 
232 }
233 
234 #endif
Internal helper class.
TDEPIM classes for drag and drop of mails.