addresseeselector.h
00001 /* 00002 This file is part of libkdepim. 00003 00004 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef KPIM_ADDRESSEESELECTOR_H 00023 #define KPIM_ADDRESSEESELECTOR_H 00024 00025 #include <kabc/addressee.h> 00026 #include <kabc/distributionlist.h> 00027 #include <kabc/resource.h> 00028 #include <kdialogbase.h> 00029 #include <kdepimmacros.h> 00030 00031 #include <tqbitarray.h> 00032 #include <tqpixmap.h> 00033 #include <tqwidget.h> 00034 00035 class KComboBox; 00036 class KLineEdit; 00037 class KListView; 00038 class TQSignalMapper; 00039 00040 namespace KPIM { 00041 00042 class AddresseeSelector; 00043 00044 class KDE_EXPORT Selection 00045 { 00046 friend class AddresseeSelector; 00047 00048 public: 00049 virtual ~Selection() {} 00050 00054 virtual uint fieldCount() const = 0; 00055 00059 virtual TQString fieldTitle( uint index ) const = 0; 00060 00064 virtual uint itemCount( const KABC::Addressee &addresse ) const = 0; 00065 00069 virtual TQString itemText( const KABC::Addressee &addresse, uint index ) const = 0; 00070 00074 virtual TQPixmap itemIcon( const KABC::Addressee &addresse, uint index ) const = 0; 00075 00079 virtual bool itemEnabled( const KABC::Addressee &addresse, uint index ) const = 0; 00080 00084 virtual bool itemMatches( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; 00085 00089 virtual bool itemEquals( const KABC::Addressee &addresse, uint index, const TQString &pattern ) const = 0; 00090 00094 virtual TQString distributionListText( const KABC::DistributionList *distributionList ) const = 0; 00095 00099 virtual TQPixmap distributionListIcon( const KABC::DistributionList *distributionList ) const = 0; 00100 00104 virtual bool distributionListEnabled( const KABC::DistributionList *distributionList ) const = 0; 00105 00109 virtual bool distributionListMatches( const KABC::DistributionList *distributionList, 00110 const TQString &pattern ) const = 0; 00111 00115 virtual uint addressBookCount() const = 0; 00116 00120 virtual TQString addressBookTitle( uint index ) const = 0; 00121 00125 virtual KABC::Addressee::List addressBookContent( uint index ) const = 0; 00126 00127 protected: 00128 AddresseeSelector* selector() { return mSelector; } 00129 00130 private: 00131 virtual void addSelectedAddressees( uint fieldIndex, const KABC::Addressee&, uint itemIndex ) = 0; 00132 virtual void addSelectedDistributionList( uint fieldIndex, const KABC::DistributionList* ) = 0; 00133 00134 void setSelector( AddresseeSelector *selector ) { mSelector = selector; } 00135 00136 AddresseeSelector *mSelector; 00137 }; 00138 00142 class SelectionItem 00143 { 00144 public: 00145 typedef TQValueList<SelectionItem> List; 00146 00147 SelectionItem( const KABC::Addressee &addressee, uint index ); 00148 SelectionItem( KABC::DistributionList *list, uint index ); 00149 SelectionItem(); 00150 00151 void addToField( int index ); 00152 void removeFromField( int index ); 00153 bool isInField( int index ); 00154 00155 KABC::Addressee addressee() const; 00156 KABC::DistributionList* distributionList() const; 00157 uint index() const; 00158 00159 private: 00160 KABC::Addressee mAddressee; 00161 KABC::DistributionList *mDistributionList; 00162 uint mIndex; 00163 TQBitArray mField; 00164 }; 00165 00166 class KDE_EXPORT AddresseeSelector : public TQWidget 00167 { 00168 Q_OBJECT 00169 TQ_OBJECT 00170 00171 public: 00172 AddresseeSelector( Selection *selection, 00173 TQWidget *parent, const char *name = 0 ); 00174 ~AddresseeSelector(); 00175 00179 void finish(); 00180 00181 void setItemSelected( uint fieldIndex, const KABC::Addressee&, uint itemIndex ); 00182 void setItemSelected( uint fieldIndex, const KABC::Addressee&, 00183 uint itemIndex, const TQString& ); 00184 00185 private slots: 00186 void move( int index ); 00187 void remove( int index ); 00188 00189 void updateAddresseeView(); 00190 void reloadAddressBook(); 00191 00192 private: 00193 void init(); 00194 void initGUI(); 00195 00196 void updateSelectionView( int index ); 00197 void updateSelectionViews(); 00198 00199 Selection *mSelection; 00200 00201 KComboBox *mAddressBookCombo; 00202 KLineEdit *mAddresseeFilter; 00203 KListView *mAddresseeView; 00204 SelectionItem::List mSelectionItems; 00205 00206 TQValueList<KListView*> mSelectionViews; 00207 TQSignalMapper *mMoveMapper; 00208 TQSignalMapper *mRemoveMapper; 00209 00210 KABC::DistributionListManager *mManager; 00211 00212 class AddressBookManager; 00213 AddressBookManager *mAddressBookManager; 00214 }; 00215 00216 class KDE_EXPORT AddresseeSelectorDialog : public KDialogBase 00217 { 00218 Q_OBJECT 00219 TQ_OBJECT 00220 00221 public: 00222 AddresseeSelectorDialog( Selection *selection, 00223 TQWidget *parent = 0, const char *name = 0 ); 00224 00225 protected slots: 00226 void accept(); 00227 00228 private: 00229 AddresseeSelector *mSelector; 00230 }; 00231 00232 } 00233 00234 #endif