libtdepim

addressesdialog.h
1 /*
2  *
3  * This file is part of libtdepim.
4  *
5  * Copyright (c) 2003 Zack Rusin <zack@kde.org>
6  * Copyright (c) 2003 Aaron J. Seigo <aseigo@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #ifndef ADDRESSESDIALOG_H
26 #define ADDRESSESDIALOG_H
27 
28 #include <tdeabc/addressee.h>
29 #include <kdialogbase.h>
30 #include <tdelistview.h>
31 #include <tqstringlist.h>
32 #include <tqptrlist.h>
33 #include <tqptrdict.h>
34 #include <tdemacros.h>
35 
36 namespace KPIM {
37 
38  class AddresseeViewItem : public TQObject, public TDEListViewItem
39  {
40  TQ_OBJECT
41 
42 
43  public:
44  enum Category {
45  To =0,
46  CC =1,
47  BCC =2,
48  Group =3,
49  Entry =4,
50  FilledGroup =5,
51  DistList =6
52  };
53  AddresseeViewItem( AddresseeViewItem *parent, const TDEABC::Addressee& addr, int emailIndex = 0 );
54  AddresseeViewItem( TDEListView *lv, const TQString& name, Category cat=Group );
55  AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, const TDEABC::Addressee::List &lst );
56  AddresseeViewItem( AddresseeViewItem *parent, const TQString& name );
57  ~AddresseeViewItem();
58 
59  TDEABC::Addressee addressee() const;
60  TDEABC::Addressee::List addresses() const;
61  Category category() const;
62 
63  TQString name() const;
64  TQString email() const;
65 
66  bool matches( const TQString& ) const;
67 
68  virtual int compare( TQListViewItem * i, int col, bool ascending ) const;
69  virtual void setSelected( bool );
70 
71  signals:
72  void addressSelected( AddresseeViewItem*, bool );
73 
74  private:
75  struct AddresseeViewItemPrivate;
76  AddresseeViewItemPrivate *d;
77  };
78 
79  class TDE_EXPORT AddressesDialog : public KDialogBase
80  {
81  TQ_OBJECT
82 
83  public:
84  AddressesDialog( TQWidget *widget=0, const char *name=0 );
85  ~AddressesDialog();
86 
90  TQStringList to() const;
94  TQStringList cc() const;
98  TQStringList bcc() const;
99 
104  TDEABC::Addressee::List toAddresses() const;
110  TDEABC::Addressee::List allToAddressesNoDuplicates() const;
115  TDEABC::Addressee::List ccAddresses() const;
120  TDEABC::Addressee::List bccAddresses() const;
121 
126  TQStringList toDistributionLists() const;
131  TQStringList ccDistributionLists() const;
136  TQStringList bccDistributionLists() const;
137 
138  public slots:
143  void setShowCC( bool b );
148  void setShowBCC( bool b );
153  void setRecentAddresses( const TDEABC::Addressee::List& addr );
157  void setSelectedTo( const TQStringList& l );
161  void setSelectedCC( const TQStringList& l );
165  void setSelectedBCC( const TQStringList& l );
166 
167  protected slots:
168  void addSelectedTo();
169  void addSelectedCC();
170  void addSelectedBCC();
171 
172  void removeEntry();
173  void saveAs();
174  void searchLdap();
175  void ldapSearchResult();
176  void launchAddressBook();
177 
178  void filterChanged( const TQString & );
179 
180  void updateAvailableAddressees();
181  void availableSelectionChanged();
182  void selectedSelectionChanged();
183  void availableAddressSelected( AddresseeViewItem* item, bool selected );
184  void selectedAddressSelected( AddresseeViewItem* item, bool selected );
185 
186  protected:
187  AddresseeViewItem* selectedToItem();
188  AddresseeViewItem* selectedCcItem();
189  AddresseeViewItem* selectedBccItem();
190 
191  void initConnections();
192  void addDistributionLists();
193  void addAddresseeToAvailable( const TDEABC::Addressee& addr,
194  AddresseeViewItem* defaultParent=0, bool useCategory=true );
195  void addAddresseeToSelected( const TDEABC::Addressee& addr,
196  AddresseeViewItem* defaultParent=0 );
197  void addAddresseesToSelected( AddresseeViewItem *parent,
198  const TQPtrList<AddresseeViewItem>& addresses );
199  TQStringList entryToString( const TDEABC::Addressee::List& l ) const;
200  TDEABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const;
201  TDEABC::Addressee::List allAddressee( TDEListView* view, bool onlySelected = true ) const;
202  TQStringList allDistributionLists( AddresseeViewItem* parent ) const;
203 
204  private:
205  // if there's only one group in the available list, open it
206  void checkForSingleAvailableGroup();
207 
208  // used to re-show items in the available list
209  // it is recursive, but should only ever recurse once so should be fine
210  void unmapSelectedAddress(AddresseeViewItem* item);
211  void updateRecentAddresses();
212 
213  struct AddressesDialogPrivate;
214  AddressesDialogPrivate *d;
215 
216  TQPtrList<AddresseeViewItem> selectedAvailableAddresses;
217  TQPtrList<AddresseeViewItem> selectedSelectedAddresses;
218  TQPtrDict<AddresseeViewItem> selectedToAvailableMapping;
219  };
220 
221 }
222 
223 #endif /* ADDRESSESDIALOG_H */
TDEPIM classes for drag and drop of mails.