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., 675 Mass Ave, Cambridge, MA 02139, 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 
00025 #include "kaddressbookview.h"
00026 
00027 
00028 #include <qlayout.h>
00029 #include <qapplication.h>
00030 #include <kdebug.h>
00031 #include <klocale.h>
00032 #include <kconfig.h>
00033 #include <kabc/addressbook.h>
00034 #include <kabc/distributionlistdialog.h>
00035 
00037 // KAddressBookView
00038 
00039 KAddressBookView::KAddressBookView(KABC::AddressBook *doc, QWidget *parent, 
00040                                    const char *name)
00041     : QWidget(parent, name), mDocument(doc), mFieldList()
00042 {
00043     initGUI();
00044 }
00045 
00046 KAddressBookView::~KAddressBookView()
00047 {
00048   kdDebug() << "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   
00060   mDefaultFilterType = (DefaultFilterType)config->
00061                                 readNumEntry("DefaultFilterType", 1);
00062   mDefaultFilterName = config->readEntry("DefaultFilterName", QString::null);
00063 }
00064 
00065 void KAddressBookView::writeConfig(KConfig *)
00066 {
00067   // Most of writing the config is handled by the ConfigureViewDialog
00068 }
00069 
00070 QString KAddressBookView::selectedEmails()
00071 {
00072   bool first = true;
00073   QString emailAddrs;
00074   QStringList uidList = selectedUids();
00075   KABC::Addressee a;
00076   QString email;
00077   
00078   // Loop through the list of selected addressees, geting each one from the
00079   // document and asking it for the email address.
00080   QStringList::Iterator iter;
00081   for (iter = uidList.begin(); iter != uidList.end(); ++iter)
00082   {
00083       a = mDocument->findByUid(*iter);
00084       
00085       if (!a.isEmpty())
00086       {
00087         QString m = QString::null;
00088 
00089         if ( a.emails().count() > 1 )
00090           m = KABC::EmailSelector::getEmail( a.emails(), a.preferredEmail(), this );
00091 
00092         email = a.fullEmail( m );
00093         
00094         if (!first)
00095           emailAddrs += ", ";
00096         else
00097           first = false;
00098           
00099         emailAddrs += email;
00100       }
00101   }
00102   
00103   return emailAddrs;
00104 }
00105 
00106 KABC::Addressee::List KAddressBookView::addressees()
00107 {
00108   KABC::Addressee::List addresseeList;
00109   
00110   KABC::AddressBook::Iterator iter;
00111   for (iter = mDocument->begin(); iter != mDocument->end(); ++iter)
00112   {
00113     if (mFilter.filterAddressee(*iter))
00114       addresseeList.append(*iter);
00115   }
00116     
00117   return addresseeList;
00118 }
00119 
00120 void KAddressBookView::initGUI()
00121 {
00122     // Create the layout
00123     QVBoxLayout *layout = new QVBoxLayout(this);
00124     
00125     // Add the view widget
00126     mViewWidget = new QWidget(this, "mViewWidget");
00127     layout->addWidget(mViewWidget);
00128     
00129 }
00130 
00131 void KAddressBookView::incrementalSearch(const QString &, 
00132                                          KABC::Field *)
00133 {
00134     // Does nothing unless overloaded
00135 }
00136 
00137 void KAddressBookView::setFilter(const Filter &f)
00138 {
00139   mFilter = f;
00140 }
00141 
00142 #include "kaddressbookview.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:37 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001