summaryrefslogtreecommitdiffstats
path: root/libtdepim/addresseeselector.h
blob: 2fa40f4e43ee0b6ca80c2213ea07b3c6ba990b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
    This file is part of libtdepim.

    Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef KPIM_ADDRESSEESELECTOR_H
#define KPIM_ADDRESSEESELECTOR_H

#include <tdeabc/addressee.h>
#include <tdeabc/distributionlist.h>
#include <tdeabc/resource.h>
#include <kdialogbase.h>
#include <tdepimmacros.h>

#include <tqbitarray.h>
#include <tqpixmap.h>
#include <tqwidget.h>

class KComboBox;
class KLineEdit;
class TDEListView;
class TQSignalMapper;

namespace KPIM {

class AddresseeSelector;

class KDE_EXPORT Selection
{
  friend class AddresseeSelector;

  public:
    virtual ~Selection() {}

    /**
      Returns the number of fields the selection offers.
     */
    virtual uint fieldCount() const = 0;

    /**
      Returns the title for the field specified by index.
     */
    virtual TQString fieldTitle( uint index ) const = 0;

    /**
      Returns the number of items for the given addressee.
     */
    virtual uint itemCount( const TDEABC::Addressee &addresse ) const = 0;

    /**
      Returns the text that's used for the item specified by index.
     */
    virtual TQString itemText( const TDEABC::Addressee &addresse, uint index ) const = 0;

    /**
      Returns the icon that's used for the item specified by index.
     */
    virtual TQPixmap itemIcon( const TDEABC::Addressee &addresse, uint index ) const = 0;

    /**
      Returns whether the item specified by index is enabled.
     */
    virtual bool itemEnabled( const TDEABC::Addressee &addresse, uint index ) const = 0;

    /**
      Returns whether the item specified by index matches the passed pattern.
     */
    virtual bool itemMatches( const TDEABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0;

    /**
      Returns whether the item specified by index equals the passed pattern.
     */
    virtual bool itemEquals( const TDEABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0;

    /**
      Returns the text that's used for the given distribution list.
     */
    virtual TQString distributionListText( const TDEABC::DistributionList *distributionList ) const = 0;

    /**
      Returns the icon that's used for the given distribution list.
     */
    virtual TQPixmap distributionListIcon( const TDEABC::DistributionList *distributionList ) const = 0;

    /**
      Returns whether the given distribution list is enabled.
     */
    virtual bool distributionListEnabled( const TDEABC::DistributionList *distributionList ) const = 0;

    /**
      Returns whether the given distribution list matches the passed pattern.
     */
    virtual bool distributionListMatches(  const TDEABC::DistributionList *distributionList,
                                           const TQString &pattern ) const = 0;

    /**
      Returns the number of additional address books.
     */
    virtual uint addressBookCount() const = 0;

    /**
      Returns the title for an additional address book.
     */
    virtual TQString addressBookTitle( uint index ) const = 0;

    /**
      Returns the content for an additional address book.
     */
    virtual TDEABC::Addressee::List addressBookContent( uint index ) const = 0;

  protected:
    AddresseeSelector* selector() { return mSelector; }

  private:
    virtual void addSelectedAddressees( uint fieldIndex, const TDEABC::Addressee&, uint itemIndex ) = 0;
    virtual void addSelectedDistributionList( uint fieldIndex, const TDEABC::DistributionList* ) = 0;

    void setSelector( AddresseeSelector *selector ) { mSelector = selector; }

    AddresseeSelector *mSelector;
};

/**
  Internal helper class
 */
class SelectionItem
{
  public:
    typedef TQValueList<SelectionItem> List;

    SelectionItem( const TDEABC::Addressee &addressee, uint index );
    SelectionItem( TDEABC::DistributionList *list, uint index );
    SelectionItem();

    void addToField( int index );
    void removeFromField( int index );
    bool isInField( int index );

    TDEABC::Addressee addressee() const;
    TDEABC::DistributionList* distributionList() const;
    uint index() const;

  private:
    TDEABC::Addressee mAddressee;
    TDEABC::DistributionList *mDistributionList;
    uint mIndex;
    TQBitArray mField;
};

class KDE_EXPORT AddresseeSelector : public TQWidget
{
  Q_OBJECT
  

  public:
    AddresseeSelector( Selection *selection,
                       TQWidget *parent, const char *name = 0 );
    ~AddresseeSelector();

    /**
      Writes back the selected items to the selection.
     */
    void finish();

    void setItemSelected( uint fieldIndex, const TDEABC::Addressee&, uint itemIndex );
    void setItemSelected( uint fieldIndex, const TDEABC::Addressee&,
                          uint itemIndex, const TQString& );

  private slots:
    void move( int index );
    void remove( int index );

    void updateAddresseeView();
    void reloadAddressBook();

  private:
    void init();
    void initGUI();

    void updateSelectionView( int index );
    void updateSelectionViews();

    Selection *mSelection;

    KComboBox *mAddressBookCombo;
    KLineEdit *mAddresseeFilter;
    TDEListView *mAddresseeView;
    SelectionItem::List mSelectionItems;

    TQValueList<TDEListView*> mSelectionViews;
    TQSignalMapper *mMoveMapper;
    TQSignalMapper *mRemoveMapper;

    TDEABC::DistributionListManager *mManager;

    class AddressBookManager;
    AddressBookManager *mAddressBookManager;
};

class KDE_EXPORT AddresseeSelectorDialog : public KDialogBase
{
  Q_OBJECT
  

  public:
    AddresseeSelectorDialog( Selection *selection,
                             TQWidget *parent = 0, const char *name = 0 );

  protected slots:
    void accept();

  private:
    AddresseeSelector *mSelector;
};

}

#endif