libkdepim

addressesdialog.h

00001 /*  -*- mode: C++; c-file-style: "gnu" -*-
00002  *
00003  *  This file is part of libkdepim.
00004  *
00005  *  Copyright (c) 2003 Zack Rusin <zack@kde.org>
00006  *  Copyright (c) 2003 Aaron J. Seigo <aseigo@kde.org>
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Library General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Library General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Library General Public License
00019  *  along with this library; see the file COPYING.LIB.  If not, write to
00020  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  *  Boston, MA 02110-1301, USA.
00022  *
00023  */
00024 
00025 #ifndef ADDRESSESDIALOG_H
00026 #define ADDRESSESDIALOG_H
00027 
00028 #include <kabc/addressee.h>
00029 #include <kdialogbase.h>
00030 #include <klistview.h>
00031 #include <tqstringlist.h>
00032 #include <tqptrlist.h>
00033 #include <tqptrdict.h>
00034 #include <kdepimmacros.h>
00035 
00036 namespace KPIM {
00037 
00038   class AddresseeViewItem : public TQObject, public KListViewItem
00039   {
00040   Q_OBJECT
00041   TQ_OBJECT
00042 
00043   public:
00044     enum Category {
00045       To          =0,
00046       CC          =1,
00047       BCC         =2,
00048       Group       =3,
00049       Entry       =4,
00050       FilledGroup =5,
00051       DistList    =6
00052     };
00053     AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, int emailIndex = 0 );
00054     AddresseeViewItem( KListView *lv, const TQString& name, Category cat=Group );
00055     AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, const KABC::Addressee::List &lst );
00056     AddresseeViewItem( AddresseeViewItem *parent, const TQString& name );
00057     ~AddresseeViewItem();
00058 
00059     KABC::Addressee       addressee() const;
00060     KABC::Addressee::List addresses() const;
00061     Category              category() const;
00062 
00063     TQString name()  const;
00064     TQString email() const;
00065 
00066     bool matches( const TQString& ) const;
00067 
00068     virtual int compare( TQListViewItem * i, int col, bool ascending ) const;
00069     virtual void setSelected( bool );
00070 
00071   signals:
00072     void addressSelected( AddresseeViewItem*, bool );
00073 
00074   private:
00075     struct AddresseeViewItemPrivate;
00076     AddresseeViewItemPrivate *d;
00077   };
00078 
00079   class KDE_EXPORT AddressesDialog : public KDialogBase
00080   {
00081     Q_OBJECT
00082   TQ_OBJECT
00083   public:
00084     AddressesDialog( TQWidget *widget=0, const char *name=0 );
00085     ~AddressesDialog();
00086 
00090     TQStringList to()  const;
00094     TQStringList cc()  const;
00098     TQStringList bcc() const;
00099 
00104     KABC::Addressee::List toAddresses()  const;
00110     KABC::Addressee::List allToAddressesNoDuplicates()  const;
00115     KABC::Addressee::List ccAddresses()  const;
00120     KABC::Addressee::List bccAddresses() const;
00121 
00126     TQStringList toDistributionLists() const;
00131     TQStringList ccDistributionLists() const;
00136     TQStringList bccDistributionLists() const;
00137 
00138   public slots:
00143     void setShowCC( bool b );
00148     void setShowBCC( bool b );
00153     void setRecentAddresses( const KABC::Addressee::List& addr );
00157     void setSelectedTo( const TQStringList& l );
00161     void setSelectedCC( const TQStringList& l );
00165     void setSelectedBCC( const TQStringList& l );
00166 
00167   protected slots:
00168     void addSelectedTo();
00169     void addSelectedCC();
00170     void addSelectedBCC();
00171 
00172     void removeEntry();
00173     void saveAs();
00174     void searchLdap();
00175     void ldapSearchResult();
00176     void launchAddressBook();
00177 
00178     void filterChanged( const TQString & );
00179 
00180     void updateAvailableAddressees();
00181     void availableSelectionChanged();
00182     void selectedSelectionChanged();
00183     void availableAddressSelected( AddresseeViewItem* item, bool selected );
00184     void selectedAddressSelected( AddresseeViewItem* item, bool selected );
00185 
00186   protected:
00187     AddresseeViewItem* selectedToItem();
00188     AddresseeViewItem* selectedCcItem();
00189     AddresseeViewItem* selectedBccItem();
00190 
00191     void initConnections();
00192     void addDistributionLists();
00193     void addAddresseeToAvailable( const KABC::Addressee& addr,
00194                                   AddresseeViewItem* defaultParent=0, bool useCategory=true );
00195     void addAddresseeToSelected( const KABC::Addressee& addr,
00196                                  AddresseeViewItem* defaultParent=0 );
00197     void addAddresseesToSelected( AddresseeViewItem *parent,
00198                                   const TQPtrList<AddresseeViewItem>& addresses );
00199     TQStringList entryToString( const KABC::Addressee::List& l ) const;
00200     KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const;
00201     KABC::Addressee::List allAddressee( KListView* view, bool onlySelected = true ) const;
00202     TQStringList allDistributionLists( AddresseeViewItem* parent ) const;
00203 
00204   private:
00205     // if there's only one group in the available list, open it
00206     void checkForSingleAvailableGroup();
00207 
00208     // used to re-show items in the available list
00209     // it is recursive, but should only ever recurse once so should be fine
00210     void unmapSelectedAddress(AddresseeViewItem* item);
00211     void updateRecentAddresses();
00212 
00213     struct AddressesDialogPrivate;
00214     AddressesDialogPrivate *d;
00215 
00216     TQPtrList<AddresseeViewItem> selectedAvailableAddresses;
00217     TQPtrList<AddresseeViewItem> selectedSelectedAddresses;
00218     TQPtrDict<AddresseeViewItem> selectedToAvailableMapping;
00219   };
00220 
00221 }
00222 
00223 #endif /* ADDRESSESDIALOG_H */