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

kopete/libkopete

addressbookselectorwidget.cpp

Go to the documentation of this file.
00001 /*
00002     AddressBookSelectorWidget
00003 
00004     Copyright (c) 2005 by Duncan Mac-Vicar Prett <duncan@kde.org>
00005 
00006     Based on LinkAddressBookUI whose code was shamelessly stolen from
00007     kopete's add new contact wizard, used in Konversation, and then
00008     reappropriated by Kopete.
00009 
00010     LinkAddressBookUI:
00011     Copyright (c) 2004 by John Tapsell           <john@geola.co.uk>
00012     Copyright (c) 2003-2005 by Will Stephenson   <will@stevello.free-online.co.uk>
00013     Copyright (c) 2002 by Nick Betcher           <nbetcher@kde.org>
00014     Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org>
00015 
00016     Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
00017 
00018     *************************************************************************
00019     *                                                                       *
00020     * This program is free software; you can redistribute it and/or modify  *
00021     * it under the terms of the GNU General Public License as published by  *
00022     * the Free Software Foundation; either version 2 of the License, or     *
00023     * (at your option) any later version.                                   *
00024     *                                                                       *
00025     *************************************************************************
00026 */
00027 
00028 #include <qcheckbox.h>
00029 #include <kconfig.h>
00030 #include <klocale.h>
00031 #include <kiconloader.h>
00032 
00033 #include <kdeversion.h>
00034 #include <kinputdialog.h>
00035 
00036 #include <kpushbutton.h>
00037 #include <k3activelabel.h>
00038 #include <kdebug.h>
00039 #include <k3listview.h>
00040 #include <k3listviewsearchline.h>
00041 #include <qlabel.h>
00042 
00043 
00044 #include "addressbookselectorwidget.h"
00045 #include <addresseeitem.h>
00046 #include "kabcpersistence.h"
00047 
00048 using namespace Kopete::UI;
00049 
00050 namespace Kopete
00051 {
00052 namespace UI
00053 {
00054 
00055 AddressBookSelectorWidget::AddressBookSelectorWidget( QWidget *parent, const char *name )
00056         : QWidget(parent), Ui::AddressBookSelectorWidget_Base()
00057 {
00058     setObjectName(name);
00059     setupUi(this);
00060 
00061     m_addressBook = Kopete::KABCPersistence::self()->addressBook();
00062 
00063     // Addressee validation connections
00064     connect( addAddresseeButton, SIGNAL( clicked() ), SLOT( slotAddAddresseeClicked() ) );
00065     connect( addAddresseeButton, SIGNAL( clicked() ), SIGNAL( addAddresseeClicked() ) );
00066 
00067     connect( addresseeListView, SIGNAL( clicked(Q3ListViewItem * ) ),
00068             SIGNAL( addresseeListClicked( Q3ListViewItem * ) ) );
00069     connect( addresseeListView, SIGNAL( selectionChanged( Q3ListViewItem * ) ),
00070             SIGNAL( addresseeListClicked( Q3ListViewItem * ) ) );
00071     connect( addresseeListView, SIGNAL( spacePressed( Q3ListViewItem * ) ),
00072             SIGNAL( addresseeListClicked( Q3ListViewItem * ) ) );
00073 
00074     connect( m_addressBook, SIGNAL( addressBookChanged( AddressBook * ) ), this, SLOT( slotLoadAddressees() ) );
00075 
00076     //We should add a clear KAction here.  But we can't really do that with a designer file :\  this sucks
00077 
00078     addresseeListView->setColumnText(2, KIcon(QLatin1String("email")), i18n("Email"));
00079 
00080     kListViewSearchLine->setListView(addresseeListView);
00081     slotLoadAddressees();
00082 
00083     addresseeListView->setColumnWidthMode(0, Q3ListView::Manual);
00084     addresseeListView->setColumnWidth(0, 63); //Photo is 60, and it's nice to have a small gap, imho
00085 }
00086 
00087 
00088 AddressBookSelectorWidget::~AddressBookSelectorWidget()
00089 {
00090     disconnect( m_addressBook, SIGNAL( addressBookChanged( AddressBook * ) ), this, SLOT( slotLoadAddressees() ) );
00091 }
00092 
00093 
00094 KABC::Addressee AddressBookSelectorWidget::addressee()
00095 {
00096     AddresseeItem *item = 0L;
00097     item = static_cast<AddresseeItem *>( addresseeListView->selectedItem() );
00098 
00099     if ( item )
00100         m_addressee = item->addressee();
00101 
00102     return m_addressee;
00103 }
00104 
00105 void AddressBookSelectorWidget::selectAddressee( const QString &uid )
00106 {
00107     // iterate trough list view
00108     Q3ListViewItemIterator it( addresseeListView );
00109     while( it.current() )
00110     {
00111         AddresseeItem *addrItem = (AddresseeItem *) it.current();
00112         if ( addrItem->addressee().uid() == uid )
00113         {
00114             // select the contact item
00115             addresseeListView->setSelected( addrItem, true );
00116             addresseeListView->ensureItemVisible( addrItem );
00117         }
00118         ++it;
00119     }
00120 }
00121 
00122 bool AddressBookSelectorWidget::addresseeSelected()
00123 {
00124     return addresseeListView->selectedItem() ? true : false;
00125 }
00126 
00128 void AddressBookSelectorWidget::slotLoadAddressees()
00129 {
00130     addresseeListView->clear();
00131     KABC::AddressBook::Iterator it;
00132     AddresseeItem *addr;
00133     for( it = m_addressBook->begin(); it != m_addressBook->end(); ++it )
00134     {
00135          addr = new AddresseeItem( addresseeListView, (*it));
00136     }
00137 
00138 }
00139 
00140 void AddressBookSelectorWidget::setLabelMessage( const QString &msg )
00141 {
00142     lblHeader->setPlainText(msg);
00143 }
00144 
00145 void AddressBookSelectorWidget::slotAddAddresseeClicked()
00146 {
00147     // Pop up add addressee dialog
00148     QString addresseeName = KInputDialog::getText( i18n( "New Address Book Entry" ), i18n( "Name the new entry:" ), QString::null, 0, this );   //krazy:exclude=nullstrassign for old broken gcc
00149 
00150     if ( !addresseeName.isEmpty() )
00151     {
00152         KABC::Addressee addr;
00153         addr.setNameFromString( addresseeName );
00154         m_addressBook->insertAddressee(addr);
00155         Kopete::KABCPersistence::self()->writeAddressBook( 0 );
00156         slotLoadAddressees();
00157         // select the addressee we just added
00158         Q3ListViewItem * added = addresseeListView->findItem( addresseeName, 1 );
00159         kListViewSearchLine->clear();
00160         kListViewSearchLine->updateSearch();
00161         kListViewSearchLine->clear();
00162         kListViewSearchLine->updateSearch();
00163         addresseeListView->setSelected( added, true );
00164         addresseeListView->ensureItemVisible( added );
00165     }
00166 }
00167 
00168 } // namespace UI
00169 } // namespace Kopete
00170 
00171 #include "addressbookselectorwidget.moc"
00172 
00173 // vim: set noet ts=4 sts=4 sw=4:
00174 

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork 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