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 
00037 #include "kaddressbookview.h"
00038 
00039 KAddressBookView::KAddressBookView( KAB::Core *core, QWidget *parent,
00040                                     const char *name )
00041     : QWidget( parent, name ), mCore( core ), mFieldList()
00042 {
00043   initGUI();
00044 }
00045 
00046 KAddressBookView::~KAddressBookView()
00047 {
00048   kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
00049                 << name() << endl;
00050 }
00051 
00052 void KAddressBookView::readConfig( KConfig *config )
00053 {
00054   mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
00055 
00056   if ( mFieldList.isEmpty() )
00057     mFieldList = KABC::Field::defaultFields();
00058   
00059   mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
00060   mDefaultFilterName = config->readEntry( "DefaultFilterName" );
00061 }
00062 
00063 void KAddressBookView::writeConfig( KConfig* )
00064 {
00065   // Most of writing the config is handled by the ConfigureViewDialog
00066 }
00067 
00068 QString KAddressBookView::selectedEmails()
00069 {
00070   bool first = true;
00071   QString emailAddrs;
00072   QStringList uidList = selectedUids();
00073   KABC::Addressee addr;
00074   QString email;
00075   
00076   QStringList::Iterator it;
00077   for ( it = uidList.begin(); it != uidList.end(); ++it ) {
00078     addr = mCore->addressBook()->findByUid( *it );
00079       
00080     if ( !addr.isEmpty() ) {
00081       QString m = QString::null;
00082 
00083       if ( addr.emails().count() > 1 )
00084         m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
00085 
00086       email = addr.fullEmail( m );
00087         
00088       if ( !first )
00089         emailAddrs += ", ";
00090       else
00091         first = false;
00092           
00093       emailAddrs += email;
00094     }
00095   }
00096   
00097   return emailAddrs;
00098 }
00099 
00100 KABC::Addressee::List KAddressBookView::addressees()
00101 {
00102   KABC::Addressee::List addresseeList;
00103 
00104   KABC::AddressBook::Iterator it;
00105   for (it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
00106     if ( mFilter.filterAddressee( *it ) )
00107       addresseeList.append( *it );
00108   }
00109 
00110   return addresseeList;
00111 }
00112 
00113 void KAddressBookView::initGUI()
00114 {
00115   // Create the layout
00116   QVBoxLayout *layout = new QVBoxLayout( this );
00117     
00118   // Add the view widget
00119   mViewWidget = new QWidget( this );
00120   layout->addWidget( mViewWidget );
00121 }
00122 
00123 KABC::Field::List KAddressBookView::fields() const
00124 {
00125   return mFieldList;
00126 }
00127 
00128 void KAddressBookView::setFilter( const Filter &filter )
00129 {
00130   mFilter = filter;
00131 }
00132 
00133 KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
00134 {
00135   return mDefaultFilterType;
00136 }
00137 
00138 const QString &KAddressBookView::defaultFilterName() const
00139 {
00140   return mDefaultFilterName;
00141 }
00142     
00143 KAB::Core *KAddressBookView::core() const
00144 {
00145   return mCore;
00146 }
00147 
00148 void KAddressBookView::popup( const QPoint &point )
00149 {
00150   if ( !mCore->guiClient() ) {
00151     kdWarning() << "No GUI client set!" << endl;
00152     return;
00153   }
00154 
00155   QPopupMenu *menu = static_cast<QPopupMenu*>( mCore->guiClient()->factory()->container( "RMBPopup",
00156                                                mCore->guiClient() ) );
00157   if ( menu )
00158     menu->popup( point );
00159 }
00160 
00161 QWidget *KAddressBookView::viewWidget()
00162 {
00163   return mViewWidget;
00164 }
00165 
00166 ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
00167                                                    QWidget *parent,
00168                                                    const char *name )
00169 {
00170   return new ViewConfigureWidget( ab, parent, name );
00171 }
00172 
00173 #include "kaddressbookview.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:52 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003