krop's commit fixes my problem in a better way, reverting
[kdepim.git] / libkdepim / addressesdialog.h
blobcd7167ebc2e6a0795274a92bbee93c2d28eeb6dc
1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 * This file is part of libkdepim.
5 * Copyright (c) 2003 Zack Rusin <zack@kde.org>
6 * Copyright (c) 2003 Aaron J. Seigo <aseigo@kde.org>
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.
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.
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.
25 #ifndef KDEPIM_ADDRESSESDIALOG_H
26 #define KDEPIM_ADDRESSESDIALOG_H
28 #include "kdepim_export.h"
29 #include "ui_addresspicker.h"
31 #include <kabc/addressee.h>
33 #include <KDialog>
35 #include <QList>
36 #include <QSet>
37 #include <QStringList>
38 #include <QTreeWidget>
40 class AddressPickerUI : public QWidget, public Ui::AddressPickerUI
42 public:
43 AddressPickerUI( QWidget *parent ) : QWidget( parent ) {
44 setupUi( this );
50 namespace KPIM {
52 class AddresseeViewItem : public QObject, public QTreeWidgetItem
54 Q_OBJECT
56 public:
57 enum Category {
58 To =0,
59 CC =1,
60 BCC =2,
61 Group =3,
62 Entry =4,
63 FilledGroup =5,
64 DistList =6
66 AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, int emailIndex = 0 );
67 AddresseeViewItem( QTreeWidget *lv, const QString& name, Category cat=Group );
68 AddresseeViewItem( AddresseeViewItem *parent, const QString& name, const KABC::Addressee::List &lst );
69 AddresseeViewItem( AddresseeViewItem *parent, const QString& name );
70 ~AddresseeViewItem();
72 KABC::Addressee addressee() const;
73 KABC::Addressee::List addresses() const;
74 Category category() const;
76 QString name() const;
77 QString email() const;
79 bool matches( const QString& ) const;
81 virtual bool operator < ( const QTreeWidgetItem& other ) const;
83 private:
84 struct AddresseeViewItemPrivate;
85 AddresseeViewItemPrivate *d;
88 class KDEPIM_EXPORT AddressesDialog : public KDialog
90 Q_OBJECT
91 public:
92 AddressesDialog( QWidget *widget=0 );
93 ~AddressesDialog();
95 /**
96 * Returns the list of picked "To" addresses as a QStringList.
98 QStringList to() const;
99 /**
100 * Returns the list of picked "CC" addresses as a QStringList.
102 QStringList cc() const;
104 * Returns the list of picked "BCC" addresses as a QStringList.
106 QStringList bcc() const;
109 * Returns the list of picked "To" addresses as KABC::Addressee::List.
110 * Note that this doesn't include the distribution lists
112 KABC::Addressee::List toAddresses() const;
114 * Returns the list of picked "To" addresses as KABC::Addressee::List.
115 * Note that this does include the distribution lists
116 * Multiple Addressees are removed
118 KABC::Addressee::List allToAddressesNoDuplicates() const;
120 * Returns the list of picked "CC" addresses as KABC::Addressee::List.
121 * Note that this doesn't include the distribution lists
123 KABC::Addressee::List ccAddresses() const;
125 * Returns the list of picked "BCC" addresses as KABC::Addressee::List.
126 * Note that this doesn't include the distribution lists
128 KABC::Addressee::List bccAddresses() const;
131 * Returns the list of picked "To" distribution lists.
132 * This complements @ref toAddresses.
134 QStringList toDistributionLists() const;
136 * Returns the list of picked "CC" distribution lists.
137 * This complements @ref ccAddresses.
139 QStringList ccDistributionLists() const;
141 * Returns the list of picked "BCC" distribution lists.
142 * This complements @ref bccAddresses.
144 QStringList bccDistributionLists() const;
146 public Q_SLOTS:
148 * Displays the CC field if @p b is true, else
149 * hides it. By default displays it.
151 void setShowCC( bool b );
153 * Displays the BCC field if @p b is true, else
154 * hides it. By default displays it.
156 void setShowBCC( bool b );
158 * If called adds "Recent Addresses" item to the picker list view,
159 * with the addresses given in @p addr.
161 void setRecentAddresses( const KABC::Addressee::List& addr );
163 * Adds addresses in @p l to the selected "To" group.
165 void setSelectedTo( const QStringList& l );
167 * Adds addresses in @p l to the selected "CC" group.
169 void setSelectedCC( const QStringList& l );
171 * Adds addresses in @p l to the selected "BCC" group.
173 void setSelectedBCC( const QStringList& l );
175 protected Q_SLOTS:
176 void addSelectedTo();
177 void addSelectedCC();
178 void addSelectedBCC();
180 void removeEntry();
181 void saveAs();
182 void searchLdap();
183 void ldapSearchResult();
185 void filterChanged( const QString & );
187 void updateAvailableAddressees();
188 void availableSelectionChanged();
189 void selectedSelectionChanged();
191 protected:
192 AddresseeViewItem* selectedToItem();
193 AddresseeViewItem* selectedCcItem();
194 AddresseeViewItem* selectedBccItem();
196 QList<AddresseeViewItem*> selectedAvailableAddresses() const;
197 QList<AddresseeViewItem*> selectedSelectedAddresses() const;
199 void initConnections();
200 void addDistributionLists();
201 void addAddresseeToAvailable( const KABC::Addressee& addr,
202 AddresseeViewItem* defaultParent=0, bool useCategory=true );
203 void addAddresseeToSelected( const KABC::Addressee& addr,
204 AddresseeViewItem* defaultParent=0 );
205 void addAddresseesToSelected( AddresseeViewItem *parent,
206 const QList<AddresseeViewItem*> addresses );
207 QStringList entryToString( const KABC::Addressee::List& l ) const;
208 KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const;
209 KABC::Addressee::List allAddressee( QTreeWidget* view, bool onlySelected = true ) const;
210 QStringList allDistributionLists( AddresseeViewItem* parent ) const;
212 private:
213 // if there's only one group in the available list, open it
214 void checkForSingleAvailableGroup();
216 // used to re-show items in the available list
217 // it is recursive, but should only ever recurse once so should be fine
218 void unmapSelectedAddress(AddresseeViewItem* item);
219 void updateRecentAddresses();
221 struct AddressesDialogPrivate;
222 AddressesDialogPrivate *d;
224 QMap<AddresseeViewItem*,AddresseeViewItem*> selectedToAvailableMapping;
229 #endif /* ADDRESSESDIALOG_H */