kaddressbook Library API Documentation

kaddressbookview.cpp

00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlayout.h>
00025 #include <qpopupmenu.h>
00026 
00027 #include <kabc/addressbook.h>
00028 #include <kabc/distributionlistdialog.h>
00029 #include <kconfig.h>
00030 #include <kdebug.h>
00031 #include <klocale.h>
00032 #include <kxmlguifactory.h>
00033 #include <kxmlguiclient.h>
00034 
00035 #include "core.h"
00036 #include "searchmanager.h"
00037 
00038 #include "kaddressbookview.h"
00039 
00040 KAddressBookView::KAddressBookView( KAB::Core *core, QWidget *parent,
00041                                     const char *name )
00042     : QWidget( parent, name ), mCore( core ), mFieldList()
00043 {
00044   initGUI();
00045 
00046   connect( mCore->searchManager(), SIGNAL( contactsUpdated() ),
00047            SLOT( updateView() ) );
00048 }
00049 
00050 KAddressBookView::~KAddressBookView()
00051 {
00052   kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
00053                 << name() << endl;
00054 }
00055 
00056 void KAddressBookView::readConfig( KConfig *config )
00057 {
00058   mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
00059 
00060   if ( mFieldList.isEmpty() )
00061     mFieldList = KABC::Field::defaultFields();
00062 
00063   mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
00064   mDefaultFilterName = config->readEntry( "DefaultFilterName" );
00065 }
00066 
00067 void KAddressBookView::writeConfig( KConfig* )
00068 {
00069   // Most of writing the config is handled by the ConfigureViewDialog
00070 }
00071 
00072 QString KAddressBookView::selectedEmails()
00073 {
00074   bool first = true;
00075   QString emailAddrs;
00076   QStringList uidList = selectedUids();
00077   KABC::Addressee addr;
00078   QString email;
00079 
00080   QStringList::Iterator it;
00081   for ( it = uidList.begin(); it != uidList.end(); ++it ) {
00082     addr = mCore->addressBook()->findByUid( *it );
00083 
00084     if ( !addr.isEmpty() ) {
00085       QString m = QString::null;
00086 
00087       if ( addr.emails().count() > 1 )
00088         m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
00089 
00090       email = addr.fullEmail( m );
00091 
00092       if ( !first )
00093         emailAddrs += ", ";
00094       else
00095         first = false;
00096 
00097       emailAddrs += email;
00098     }
00099   }
00100 
00101   return emailAddrs;
00102 }
00103 
00104 KABC::Addressee::List KAddressBookView::addressees()
00105 {
00106   KABC::Addressee::List addresseeList;
00107   KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00108 
00109   KABC::Addressee::List::Iterator it;
00110   for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00111     if ( mFilter.filterAddressee( *it ) )
00112       addresseeList.append( *it );
00113   }
00114 
00115   return addresseeList;
00116 }
00117 
00118 void KAddressBookView::initGUI()
00119 {
00120   // Create the layout
00121   QVBoxLayout *layout = new QVBoxLayout( this );
00122 
00123   // Add the view widget
00124   mViewWidget = new QWidget( this );
00125   layout->addWidget( mViewWidget );
00126 }
00127 
00128 KABC::Field::List KAddressBookView::fields() const
00129 {
00130   return mFieldList;
00131 }
00132 
00133 void KAddressBookView::setFilter( const Filter &filter )
00134 {
00135   mFilter = filter;
00136 }
00137 
00138 KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
00139 {
00140   return mDefaultFilterType;
00141 }
00142 
00143 const QString &KAddressBookView::defaultFilterName() const
00144 {
00145   return mDefaultFilterName;
00146 }
00147 
00148 KAB::Core *KAddressBookView::core() const
00149 {
00150   return mCore;
00151 }
00152 
00153 void KAddressBookView::popup( const QPoint &point )
00154 {
00155   if ( !mCore->guiClient() ) {
00156     kdWarning() << "No GUI client set!" << endl;
00157     return;
00158   }
00159 
00160   QPopupMenu *menu = static_cast<QPopupMenu*>( mCore->guiClient()->factory()->container( "RMBPopup",
00161                                                mCore->guiClient() ) );
00162   if ( menu )
00163     menu->popup( point );
00164 }
00165 
00166 QWidget *KAddressBookView::viewWidget()
00167 {
00168   return mViewWidget;
00169 }
00170 
00171 void KAddressBookView::updateView()
00172 {
00173   QStringList uidList = selectedUids();
00174 
00175   refresh(); // This relists and deselects everything, in all views
00176 
00177   if ( !uidList.isEmpty() ) {
00178       // Keep previous selection
00179       for( QStringList::Iterator it = uidList.begin(); it != uidList.end(); ++it ) {
00180           setSelected( *it, true );
00181       }
00182   } else {
00183       KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00184       if ( !contacts.isEmpty() )
00185           setSelected( contacts.first().uid(), true );
00186       else {
00187           emit selected( QString::null );
00188       }
00189   }
00190 }
00191 
00192 ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
00193                                                    QWidget *parent,
00194                                                    const char *name )
00195 {
00196   return new ViewConfigureWidget( ab, parent, name );
00197 }
00198 
00199 #include "kaddressbookview.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 2 09:54:31 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003