• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

kaddressbookview.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <QtGui/QMenu>
00025 #include <QtGui/QVBoxLayout>
00026 
00027 #include <kabc/addressbook.h>
00028 #include <kabc/distributionlistdialog.h>
00029 #include <kconfig.h>
00030 #include <kconfiggroup.h>
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033 #include <kxmlguifactory.h>
00034 #include <kxmlguiclient.h>
00035 
00036 #include "core.h"
00037 #include "searchmanager.h"
00038 
00039 #include "kaddressbookview.h"
00040 
00041 KAddressBookView::KAddressBookView( KAB::Core *core, QWidget *parent )
00042     : QWidget( parent ), mCore( core ), mFieldList()
00043 {
00044   initGUI();
00045 
00046   connect( mCore->searchManager(), SIGNAL( contactsUpdated() ),
00047            SLOT( updateView() ) );
00048 }
00049 
00050 KAddressBookView::~KAddressBookView()
00051 {
00052   kDebug(5720) <<"KAddressBookView::~KAddressBookView: destroying -"
00053                 << objectName();
00054 }
00055 
00056 void KAddressBookView::readConfig( KConfigGroup &config )
00057 {
00058   mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
00059 
00060   if ( mFieldList.isEmpty() )
00061     mFieldList = KABC::Field::defaultFields();
00062 
00063   mDefaultFilterType = (DefaultFilterType)config.readEntry( "DefaultFilterType", 1 );
00064   mDefaultFilterName = config.readEntry( "DefaultFilterName" );
00065 }
00066 
00067 void KAddressBookView::writeConfig( KConfigGroup& )
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   const QStringList uidList = selectedUids();
00077   KABC::Addressee addr;
00078   QString email;
00079 
00080   QStringList::ConstIterator 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();
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   if ( mFilter.isEmpty() )
00107     return mCore->searchManager()->contacts();
00108 
00109   KABC::Addressee::List addresseeList;
00110   const KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00111 
00112   KABC::Addressee::List::ConstIterator it;
00113   KABC::Addressee::List::ConstIterator contactsEnd( contacts.end() );
00114   for ( it = contacts.begin(); it != contactsEnd; ++it ) {
00115     if ( mFilter.filterAddressee( *it ) )
00116       addresseeList.append( *it );
00117   }
00118 
00119   return addresseeList;
00120 }
00121 
00122 void KAddressBookView::initGUI()
00123 {
00124   // Create the layout
00125   QVBoxLayout *layout = new QVBoxLayout( this );
00126   layout->setMargin( 0 );
00127 
00128   // Add the view widget
00129   mViewWidget = new QWidget( this );
00130   layout->addWidget( mViewWidget );
00131 }
00132 
00133 KABC::Field::List KAddressBookView::fields() const
00134 {
00135   return mFieldList;
00136 }
00137 
00138 void KAddressBookView::setFilter( const Filter &filter )
00139 {
00140   mFilter = filter;
00141 }
00142 
00143 KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
00144 {
00145   return mDefaultFilterType;
00146 }
00147 
00148 const QString &KAddressBookView::defaultFilterName() const
00149 {
00150   return mDefaultFilterName;
00151 }
00152 
00153 KAB::Core *KAddressBookView::core() const
00154 {
00155   return mCore;
00156 }
00157 
00158 void KAddressBookView::popup( const QPoint &point )
00159 {
00160   if ( !mCore->guiClient() ) {
00161     kWarning() <<"No GUI client set!";
00162     return;
00163   }
00164 
00165   QMenu *menu = static_cast<QMenu*>( mCore->guiClient()->factory()->container( "RMBPopup",
00166                                                mCore->guiClient() ) );
00167   if ( menu )
00168     menu->popup( point );
00169 }
00170 
00171 QWidget *KAddressBookView::viewWidget()
00172 {
00173   return mViewWidget;
00174 }
00175 
00176 void KAddressBookView::updateView()
00177 {
00178   const QStringList uidList = selectedUids();
00179 
00180   refresh(); // This relists and deselects everything, in all views
00181 
00182   if ( !uidList.isEmpty() ) {
00183     // Keep previous selection
00184     QStringList::ConstIterator it, uidListEnd( uidList.end() );
00185     for ( it = uidList.begin(); it != uidListEnd; ++it )
00186       setSelected( *it, true );
00187 
00188   } else {
00189     const KABC::Addressee::List contacts = mCore->searchManager()->contacts();
00190     if ( !contacts.isEmpty() )
00191       setFirstSelected( true );
00192     else
00193       emit selected( QString() );
00194   }
00195 }
00196 
00197 ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
00198                                                    QWidget *parent )
00199 {
00200   return new ViewConfigureWidget( ab, parent );
00201 }
00202 
00203 #include "kaddressbookview.moc"

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal