• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

addresseedialog.cpp
00001 /*
00002     This file is part of libtdeabc.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <tqlayout.h>
00022 #include <tqpushbutton.h>
00023 #include <tqgroupbox.h>
00024 #include <tqregexp.h>
00025 
00026 #include <tdelocale.h>
00027 #include <kdebug.h>
00028 
00029 #include "stdaddressbook.h"
00030 
00031 #include "addresseedialog.h"
00032 #include "addresseedialog.moc"
00033 
00034 using namespace TDEABC;
00035 
00036 AddresseeItem::AddresseeItem( TQListView *parent, const Addressee &addressee ) :
00037   TQListViewItem( parent ),
00038   mAddressee( addressee )
00039 {
00040   setText( Name, addressee.realName() );
00041   setText( Email, addressee.preferredEmail() );
00042 }
00043 
00044 TQString AddresseeItem::key( int column, bool ) const
00045 {
00046   if (column == Email) {
00047     TQString value = text(Email);
00048     TQRegExp emailRe("<\\S*>");
00049     int match = emailRe.search(value);
00050     if (match > -1)
00051       value = value.mid(match + 1, emailRe.matchedLength() - 2);
00052 
00053     return value.lower();
00054   }
00055 
00056   return text(column).lower();
00057 }
00058 
00059 AddresseeDialog::AddresseeDialog( TQWidget *parent, bool multiple ) :
00060   KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
00061                Ok|Cancel, Ok, parent ), mMultiple( multiple )
00062 {
00063   TQWidget *topWidget = plainPage();
00064 
00065   TQBoxLayout *topLayout = new TQHBoxLayout( topWidget );
00066   TQBoxLayout *listLayout = new TQVBoxLayout;
00067   topLayout->addLayout( listLayout );
00068 
00069   mAddresseeList = new TDEListView( topWidget );
00070   mAddresseeList->addColumn( i18n("Name") );
00071   mAddresseeList->addColumn( i18n("Email") );
00072   mAddresseeList->setAllColumnsShowFocus( true );
00073   mAddresseeList->setFullWidth( true );
00074   listLayout->addWidget( mAddresseeList );
00075   connect( mAddresseeList, TQT_SIGNAL( doubleClicked( TQListViewItem * ) ),
00076            TQT_SLOT( slotOk() ) );
00077   connect( mAddresseeList, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ),
00078            TQT_SLOT( updateEdit( TQListViewItem * ) ) );
00079 
00080   mAddresseeEdit = new KLineEdit( topWidget );
00081   mAddresseeEdit->setCompletionMode( TDEGlobalSettings::CompletionAuto );
00082   connect( mAddresseeEdit->completionObject(), TQT_SIGNAL( match( const TQString & ) ),
00083            TQT_SLOT( selectItem( const TQString & ) ) );
00084   mAddresseeEdit->setFocus();
00085   mAddresseeEdit->completionObject()->setIgnoreCase( true );
00086   listLayout->addWidget( mAddresseeEdit );
00087 
00088   setInitialSize( TQSize( 450, 300 ) );
00089 
00090   if ( mMultiple ) {
00091     TQBoxLayout *selectedLayout = new TQVBoxLayout;
00092     topLayout->addLayout( selectedLayout );
00093     topLayout->setSpacing( spacingHint() );
00094 
00095     TQGroupBox *selectedGroup = new TQGroupBox( 1, Qt::Horizontal, i18n("Selected"),
00096                                               topWidget );
00097     selectedLayout->addWidget( selectedGroup );
00098 
00099     mSelectedList = new TDEListView( selectedGroup );
00100     mSelectedList->addColumn( i18n("Name") );
00101     mSelectedList->addColumn( i18n("Email") );
00102     mSelectedList->setAllColumnsShowFocus( true );
00103     mSelectedList->setFullWidth( true );
00104     connect( mSelectedList, TQT_SIGNAL( doubleClicked( TQListViewItem * ) ),
00105              TQT_SLOT( removeSelected() ) );
00106 
00107     TQPushButton *unselectButton = new TQPushButton( i18n("Unselect"), selectedGroup );
00108     connect ( unselectButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeSelected() ) );
00109 
00110     connect( mAddresseeList, TQT_SIGNAL( clicked( TQListViewItem * ) ),
00111              TQT_SLOT( addSelected( TQListViewItem * ) ) );
00112 
00113     setInitialSize( TQSize( 650, 350 ) );
00114   }
00115 
00116   mAddressBook = StdAddressBook::self( true );
00117   connect( mAddressBook, TQT_SIGNAL( addressBookChanged( AddressBook* ) ),
00118            TQT_SLOT( addressBookChanged() ) );
00119   connect( mAddressBook, TQT_SIGNAL( loadingFinished( Resource* ) ),
00120            TQT_SLOT( addressBookChanged() ) );
00121 
00122   loadAddressBook();
00123 }
00124 
00125 AddresseeDialog::~AddresseeDialog()
00126 {
00127 }
00128 
00129 void AddresseeDialog::loadAddressBook()
00130 {
00131   mAddresseeList->clear();
00132   mItemDict.clear();
00133   mAddresseeEdit->completionObject()->clear();
00134 
00135   AddressBook::Iterator it;
00136   for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
00137     AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
00138     addCompletionItem( (*it).realName(), item );
00139     addCompletionItem( (*it).preferredEmail(), item );
00140   }
00141 }
00142 
00143 void AddresseeDialog::addCompletionItem( const TQString &str, TQListViewItem *item )
00144 {
00145   if ( str.isEmpty() ) return;
00146 
00147   mItemDict.insert( str, item );
00148   mAddresseeEdit->completionObject()->addItem( str );
00149 }
00150 
00151 void AddresseeDialog::selectItem( const TQString &str )
00152 {
00153   if ( str.isEmpty() ) return;
00154 
00155   TQListViewItem *item = mItemDict.find( str );
00156   if ( item ) {
00157     mAddresseeList->blockSignals( true );
00158     mAddresseeList->setSelected( item, true );
00159     mAddresseeList->ensureItemVisible( item );
00160     mAddresseeList->blockSignals( false );
00161   }
00162 }
00163 
00164 void AddresseeDialog::updateEdit( TQListViewItem *item )
00165 {
00166   mAddresseeEdit->setText( item->text( 0 ) );
00167   mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
00168 }
00169 
00170 void AddresseeDialog::addSelected( TQListViewItem *item )
00171 {
00172   AddresseeItem *addrItem = dynamic_cast<AddresseeItem *>( item );
00173   if ( !addrItem ) return;
00174 
00175   Addressee a = addrItem->addressee();
00176 
00177   TQListViewItem *selectedItem = mSelectedDict.find( a.uid() );
00178   if ( !selectedItem ) {
00179     selectedItem = new AddresseeItem( mSelectedList, a );
00180     mSelectedDict.insert( a.uid(), selectedItem );
00181   }
00182 }
00183 
00184 void AddresseeDialog::removeSelected()
00185 {
00186   TQListViewItem *item = mSelectedList->selectedItem();
00187   AddresseeItem *addrItem = dynamic_cast<AddresseeItem *>( item );
00188   if ( !addrItem ) return;
00189 
00190   mSelectedDict.remove( addrItem->addressee().uid() );
00191   delete addrItem;
00192 }
00193 
00194 Addressee AddresseeDialog::addressee()
00195 {
00196   AddresseeItem *aItem = 0;
00197 
00198   if ( mMultiple )
00199     aItem = dynamic_cast<AddresseeItem *>( mSelectedList->firstChild() );
00200   else
00201     aItem = dynamic_cast<AddresseeItem *>( mAddresseeList->selectedItem() );
00202 
00203   if (aItem) return aItem->addressee();
00204   return Addressee();
00205 }
00206 
00207 Addressee::List AddresseeDialog::addressees()
00208 {
00209   Addressee::List al;
00210   AddresseeItem *aItem = 0;
00211 
00212   if ( mMultiple ) {
00213     TQListViewItem *item = mSelectedList->firstChild();
00214     while( item ) {
00215       aItem = dynamic_cast<AddresseeItem *>( item );
00216       if ( aItem ) al.append( aItem->addressee() );
00217       item = item->nextSibling();
00218     }
00219   }
00220   else
00221   {
00222     aItem = dynamic_cast<AddresseeItem *>( mAddresseeList->selectedItem() );
00223     if (aItem) al.append( aItem->addressee() );
00224   }
00225 
00226   return al;
00227 }
00228 
00229 Addressee AddresseeDialog::getAddressee( TQWidget *parent )
00230 {
00231   AddresseeDialog *dlg = new AddresseeDialog( parent );
00232   Addressee addressee;
00233   int result = dlg->exec();
00234 
00235   if ( result == TQDialog::Accepted ) {
00236     addressee =  dlg->addressee();
00237   }
00238 
00239   delete dlg;
00240   return addressee;
00241 }
00242 
00243 Addressee::List AddresseeDialog::getAddressees( TQWidget *parent )
00244 {
00245   AddresseeDialog *dlg = new AddresseeDialog( parent, true );
00246   Addressee::List addressees;
00247   int result = dlg->exec();
00248   if ( result == TQDialog::Accepted ) {
00249     addressees =  dlg->addressees();
00250   }
00251 
00252   delete dlg;
00253   return addressees;
00254 }
00255 
00256 void AddresseeDialog::addressBookChanged()
00257 {
00258   loadAddressBook();
00259 }

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.