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 <qstringlist.h>
00032 #include <qptrlist.h>
00033 #include <qptrdict.h>
00034 #include <kdepimmacros.h>
00035 
00036 namespace KPIM {
00037 
00038   class AddresseeViewItem : public QObject, 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 QString& name, Category cat=Group );
00054     AddresseeViewItem( AddresseeViewItem *parent, const QString& name, const KABC::Addressee::List &lst );
00055     AddresseeViewItem( AddresseeViewItem *parent, const QString& name );
00056     ~AddresseeViewItem();
00057 
00058     KABC::Addressee       addressee() const;
00059     KABC::Addressee::List addresses() const;
00060     Category              category() const;
00061 
00062     QString name()  const;
00063     QString email() const;
00064 
00065     bool matches( const QString& ) const;
00066 
00067     virtual int compare( QListViewItem * 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( QWidget *widget=0, const char *name=0 );
00083     ~AddressesDialog();
00084 
00088     QStringList to()  const;
00092     QStringList cc()  const;
00096     QStringList 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     QStringList toDistributionLists() const;
00129     QStringList ccDistributionLists() const;
00134     QStringList 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 QStringList& l );
00159     void setSelectedCC( const QStringList& l );
00163     void setSelectedBCC( const QStringList& l );
00164 
00165   protected slots:
00166     void addSelectedTo();
00167     void addSelectedCC();
00168     void addSelectedBCC();
00169 
00170     void removeEntry();
00171     void saveAs();
00172     void launchAddressBook();
00173 
00174     void filterChanged( const QString & );
00175 
00176     void updateAvailableAddressees();
00177     void availableSelectionChanged();
00178     void selectedSelectionChanged();
00179     void availableAddressSelected( AddresseeViewItem* item, bool selected );
00180     void selectedAddressSelected( AddresseeViewItem* item, bool selected );
00181 
00182   protected:
00183     AddresseeViewItem* selectedToItem();
00184     AddresseeViewItem* selectedCcItem();
00185     AddresseeViewItem* selectedBccItem();
00186 
00187     void initConnections();
00188     void addDistributionLists();
00189     void addAddresseeToAvailable( const KABC::Addressee& addr,
00190                                   AddresseeViewItem* defaultParent=0, bool useCategory=true );
00191     void addAddresseeToSelected( const KABC::Addressee& addr,
00192                                  AddresseeViewItem* defaultParent=0 );
00193     void addAddresseesToSelected( AddresseeViewItem *parent,
00194                                   const QPtrList<AddresseeViewItem>& addresses );
00195     QStringList entryToString( const KABC::Addressee::List& l ) const;
00196     KABC::Addressee::List allAddressee( AddresseeViewItem* parent ) const;
00197     KABC::Addressee::List allAddressee( KListView* view, bool onlySelected = true ) const;
00198     QStringList allDistributionLists( AddresseeViewItem* parent ) const;
00199 
00200   private:
00201     // if there's only one group in the available list, open it
00202     void checkForSingleAvailableGroup();
00203 
00204     // used to re-show items in the available list
00205     // it is recursive, but should only ever recurse once so should be fine
00206     void unmapSelectedAddress(AddresseeViewItem* item);
00207     void updateRecentAddresses();
00208 
00209     struct AddressesDialogPrivate;
00210     AddressesDialogPrivate *d;
00211 
00212     QPtrList<AddresseeViewItem> selectedAvailableAddresses;
00213     QPtrList<AddresseeViewItem> selectedSelectedAddresses;
00214     QPtrDict<AddresseeViewItem> selectedToAvailableMapping;
00215   };
00216 
00217 }
00218 
00219 #endif /* ADDRESSESDIALOG_H */
KDE Home | KDE Accessibility Home | Description of Access Keys