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 
00042   public:
00043     enum Category {
00044       To          =0,
00045       CC          =1,
00046       BCC         =2,
00047       Group       =3,
00048       Entry       =4,
00049       FilledGroup =5,
00050       DistList    =6
00051     };
00052     AddresseeViewItem( AddresseeViewItem *parent, const KABC::Addressee& addr, int emailIndex = 0 );
00053     AddresseeViewItem( KListView *lv, const TQString& name, Category cat=Group );
00054     AddresseeViewItem( AddresseeViewItem *parent, const TQString& name, const KABC::Addressee::List &lst );
00055     AddresseeViewItem( AddresseeViewItem *parent, const TQString& name );
00056     ~AddresseeViewItem();
00057 
00058     KABC::Addressee       addressee() const;
00059     KABC::Addressee::List addresses() const;
00060     Category              category() const;
00061 
00062     TQString name()  const;
00063     TQString email() const;
00064 
00065     bool matches( const TQString& ) const;
00066 
00067     virtual int compare( TQListViewItem * i, int col, bool ascending ) const;
00068     virtual void setSelected( bool );
00069 
00070   signals:
00071     void addressSelected( AddresseeViewItem*, bool );
00072 
00073   private:
00074     struct AddresseeViewItemPrivate;
00075     AddresseeViewItemPrivate *d;
00076   };
00077 
00078   class KDE_EXPORT AddressesDialog : public KDialogBase
00079   {
00080     Q_OBJECT
00081   public:
00082     AddressesDialog( TQWidget *widget=0, const char *name=0 );
00083     ~AddressesDialog();
00084 
00088     TQStringList to()  const;
00092     TQStringList cc()  const;
00096     TQStringList bcc() const;
00097 
00102     KABC::Addressee::List toAddresses()  const;
00108     KABC::Addressee::List allToAddressesNoDuplicates()  const;
00113     KABC::Addressee::List ccAddresses()  const;
00118     KABC::Addressee::List bccAddresses() const;
00119 
00124     TQStringList toDistributionLists() const;
00129     TQStringList ccDistributionLists() const;
00134     TQStringList bccDistributionLists() const;
00135 
00136   public slots:
00141     void setShowCC( bool b );
00146     void setShowBCC( bool b );
00151     void setRecentAddresses( const KABC::Addressee::List& addr );
00155     void setSelectedTo( const TQStringList& l );
00159     void setSelectedCC( const TQStringList& l );
00163     void setSelectedBCC( const TQStringList& l );
00164 
00165   protected slots:
00166     void addSelectedTo();
00167     void addSelectedCC();
00168     void addSelectedBCC();
00169 
00170     void removeEntry();
00171     void saveAs();
00172     void searchLdap();
00173     void ldapSearchResult();
00174     void launchAddressBook();
00175 
00176     void filterChanged( const TQString & );
00177 
00178     void updateAvailableAddressees();
00179     void availableSelectionChanged();
00180     void selectedSelectionChanged();
00181     void availableAddressSelected( AddresseeViewItem* item, bool selected );
00182     void selectedAddressSelected( AddresseeViewItem* item, bool selected );
00183 
00184   protected:
00185     AddresseeViewItem* selectedToItem();
00186     AddresseeViewItem* selectedCcItem();
00187     AddresseeViewItem* selectedBccItem();
00188 
00189     void initConnections();
00190     void addDistributionLists();
00191     void addAddresseeToAvailable( const KABC::Addressee& addr,
00192                                   AddresseeViewItem* defaultParent=0, bool useCategory=true );
00193     void addAddresseeToSelected( const KABC::Addressee& addr,
00194                                  AddresseeViewItem* defaultParent=0 );
00195     void addAddresseesToSelected( AddresseeViewItem *parent,
00196                                   const TQPtrList<AddresseeViewItem>& addresses );
00197     TQStringList entryToString( const KABC::Addressee::List& l ) const;
00198     KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const;
00199     KABC::Addressee::List allAddressee( KListView* view, bool onlySelected = true ) const;
00200     TQStringList allDistributionLists( AddresseeViewItem* parent ) const;
00201 
00202   private:
00203     // if there's only one group in the available list, open it
00204     void checkForSingleAvailableGroup();
00205 
00206     // used to re-show items in the available list
00207     // it is recursive, but should only ever recurse once so should be fine
00208     void unmapSelectedAddress(AddresseeViewItem* item);
00209     void updateRecentAddresses();
00210 
00211     struct AddressesDialogPrivate;
00212     AddressesDialogPrivate *d;
00213 
00214     TQPtrList<AddresseeViewItem> selectedAvailableAddresses;
00215     TQPtrList<AddresseeViewItem> selectedSelectedAddresses;
00216     TQPtrDict<AddresseeViewItem> selectedToAvailableMapping;
00217   };
00218 
00219 }
00220 
00221 #endif /* ADDRESSESDIALOG_H */