00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "recipientspicker.h"
00023
00024 #include "globalsettings.h"
00025
00026 #include <libkdepim/recentaddresses.h>
00027
00028 #ifndef KDEPIM_NEW_DISTRLISTS
00029 #include <kabc/distributionlist.h>
00030 #endif
00031
00032 #include <klistview.h>
00033 #include <klocale.h>
00034 #include <kabc/resource.h>
00035 #include <kiconloader.h>
00036 #include <kdialog.h>
00037 #include <kwin.h>
00038 #include <kmessagebox.h>
00039
00040 #include <qlayout.h>
00041 #include <qcombobox.h>
00042 #include <qpushbutton.h>
00043 #include <qtoolbutton.h>
00044 #include <qlabel.h>
00045
00046 #ifdef KDEPIM_NEW_DISTRLISTS
00047 RecipientItem::RecipientItem( KABC::AddressBook *ab )
00048 : mAddressBook( ab )
00049 {
00050 }
00051 #else
00052 RecipientItem::RecipientItem()
00053 : mDistributionList( 0 )
00054 {
00055 }
00056 #endif
00057
00058 #ifdef KDEPIM_NEW_DISTRLISTS
00059 void RecipientItem::setDistributionList( const KPIM::DistributionList &list )
00060 {
00061 mDistributionList = list;
00062
00063 mIcon = KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small );
00064
00065 mKey = "D" + list.name();
00066 }
00067 #else
00068 void RecipientItem::setDistributionList( KABC::DistributionList *list )
00069 {
00070 mDistributionList = list;
00071
00072 mIcon = KGlobal::iconLoader()->loadIcon( "kdmconfig", KIcon::Small );
00073
00074 mKey = "D" + list->name();
00075 }
00076 #endif
00077
00078 void RecipientItem::setAddressee( const KABC::Addressee &a,
00079 const QString &email )
00080 {
00081 mAddressee = a;
00082 mEmail = email;
00083
00084 QImage img = a.photo().data();
00085 if ( !img.isNull() )
00086 mIcon = img.smoothScale( 20, 20, QImage::ScaleMin );
00087 else
00088 mIcon = KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small );
00089
00090 mKey = "A" + a.preferredEmail();
00091 }
00092
00093 QPixmap RecipientItem::icon() const
00094 {
00095 return mIcon;
00096 }
00097
00098 QString RecipientItem::name() const
00099 {
00100 #ifdef KDEPIM_NEW_DISTRLISTS
00101 if ( !mAddressee.isEmpty() ) return mAddressee.realName();
00102 else if ( !mDistributionList.isEmpty() ) return mDistributionList.name();
00103 else return QString::null;
00104 #else
00105 if ( !mAddressee.isEmpty() ) return mAddressee.realName();
00106 else if ( mDistributionList ) return mDistributionList->name();
00107 else return QString::null;
00108 #endif
00109 }
00110
00111 QString RecipientItem::email() const
00112 {
00113 #ifdef KDEPIM_NEW_DISTRLISTS
00114 if ( mAddressee.isEmpty() && !mDistributionList.isEmpty() ) {
00115 int count = mDistributionList.entries( mAddressBook ).count();
00116 return i18n( "1 email address", "%n email addresses", count );
00117 } else {
00118 return mEmail;
00119 }
00120 #else
00121 if ( mAddressee.isEmpty() && mDistributionList ) {
00122 int count = mDistributionList->entries().count();
00123 return i18n( "1 email address", "%n email addresses", count );
00124 } else {
00125 return mEmail;
00126 }
00127 #endif
00128 return QString::null;
00129 }
00130
00131 #ifdef KDEPIM_NEW_DISTRLISTS
00132 QString RecipientItem::recipient() const
00133 {
00134 QString r;
00135 if ( !mAddressee.isEmpty() ) r = mAddressee.fullEmail( mEmail );
00136 else if ( !mDistributionList.isEmpty() ) r = mDistributionList.name();
00137 return r;
00138 }
00139 #else
00140 QString RecipientItem::recipient() const
00141 {
00142 QString r;
00143 if ( !mAddressee.isEmpty() ) r = mAddressee.fullEmail( mEmail );
00144 else if ( mDistributionList ) r = mDistributionList->name();
00145 return r;
00146 }
00147 #endif
00148
00149 QString RecipientItem::toolTip() const
00150 {
00151 QString txt = "<qt>";
00152
00153 if ( !mAddressee.isEmpty() ) {
00154 if ( !mAddressee.realName().isEmpty() ) {
00155 txt += mAddressee.realName() + "<br/>";
00156 }
00157 txt += "<b>" + mEmail + "</b>";
00158 #ifdef KDEPIM_NEW_DISTRLISTS
00159 } else if ( !mDistributionList.isEmpty() ) {
00160 txt += "<b>" + i18n("Distribution List %1")
00161 .arg( mDistributionList.name() ) + "</b>";
00162 txt += "<ul>";
00163 KPIM::DistributionList::Entry::List entries = mDistributionList.entries( mAddressBook );
00164 KPIM::DistributionList::Entry::List::ConstIterator it;
00165 for( it = entries.begin(); it != entries.end(); ++it ) {
00166 txt += "<li>";
00167 txt += (*it).addressee.realName() + " ";
00168 txt += "<em>";
00169 if ( (*it).email.isEmpty() ) txt += (*it).addressee.preferredEmail();
00170 else txt += (*it).email;
00171 txt += "</em>";
00172 txt += "<li/>";
00173 }
00174 txt += "</ul>";
00175 }
00176 #else
00177 } else if ( mDistributionList ) {
00178 txt += "<b>" + i18n("Distribution List %1")
00179 .arg( mDistributionList->name() ) + "</b>";
00180 txt += "<ul>";
00181 KABC::DistributionList::Entry::List entries = mDistributionList->entries();
00182 KABC::DistributionList::Entry::List::ConstIterator it;
00183 for( it = entries.begin(); it != entries.end(); ++it ) {
00184 txt += "<li>";
00185 txt += (*it).addressee.realName() + " ";
00186 txt += "<em>";
00187 if ( (*it).email.isEmpty() ) txt += (*it).addressee.preferredEmail();
00188 else txt += (*it).email;
00189 txt += "</em>";
00190 txt += "<li/>";
00191 }
00192 txt += "</ul>";
00193 }
00194 #endif
00195
00196 return txt;
00197 }
00198
00199 void RecipientItem::setRecipientType( const QString &type )
00200 {
00201 mType = type;
00202 }
00203
00204 QString RecipientItem::recipientType() const
00205 {
00206 return mType;
00207 }
00208
00209
00210 RecipientViewItem::RecipientViewItem( RecipientItem *item, KListView *listView )
00211 : KListViewItem( listView ), mRecipientItem( item )
00212 {
00213 setText( 0, item->recipientType() );
00214 setText( 1, item->name() );
00215 setText( 2, item->email() );
00216
00217 setPixmap( 1, item->icon() );
00218 }
00219
00220 RecipientItem *RecipientViewItem::recipientItem() const
00221 {
00222 return mRecipientItem;
00223 }
00224
00225
00226 RecipientsListToolTip::RecipientsListToolTip( QWidget *parent,
00227 KListView *listView )
00228 : QToolTip( parent )
00229 {
00230 mListView = listView;
00231 }
00232
00233 void RecipientsListToolTip::maybeTip( const QPoint & pos )
00234 {
00235 QRect r;
00236 QListViewItem *item = mListView->itemAt( pos );
00237 RecipientViewItem *i = static_cast<RecipientViewItem *>( item );
00238
00239 if( item ) {
00240 r = mListView->itemRect( item );
00241 QString tipText( i->recipientItem()->toolTip() );
00242 if ( !tipText.isEmpty() ) {
00243 tip( r, tipText );
00244 }
00245 }
00246 }
00247
00248
00249 RecipientsCollection::RecipientsCollection()
00250 {
00251 }
00252
00253 RecipientsCollection::~RecipientsCollection()
00254 {
00255 clear();
00256 }
00257
00258 void RecipientsCollection::setTitle( const QString &title )
00259 {
00260 mTitle = title;
00261 }
00262
00263 QString RecipientsCollection::title() const
00264 {
00265 return mTitle;
00266 }
00267
00268 void RecipientsCollection::addItem( RecipientItem *item )
00269 {
00270 mItems.append( item );
00271
00272 mKeyMap.insert( item->key(), item );
00273 }
00274
00275 RecipientItem::List RecipientsCollection::items() const
00276 {
00277 return mItems;
00278 }
00279
00280 bool RecipientsCollection::hasEquivalentItem( RecipientItem *item ) const
00281 {
00282 return mKeyMap.find( item->key() ) != mKeyMap.end();
00283 }
00284
00285 void RecipientsCollection::clear()
00286 {
00287 mKeyMap.clear();
00288 }
00289
00290 void RecipientsCollection::deleteAll()
00291 {
00292 QMap<QString, RecipientItem *>::ConstIterator it;
00293 for( it = mKeyMap.begin(); it != mKeyMap.end(); ++it ) {
00294 delete *it;
00295 }
00296 clear();
00297 }
00298
00299
00300 SearchLine::SearchLine( QWidget *parent, KListView *listView )
00301 : KListViewSearchLine( parent, listView )
00302 {
00303 }
00304
00305 void SearchLine::keyPressEvent( QKeyEvent *ev )
00306 {
00307 if ( ev->key() == Key_Down ) emit downPressed();
00308
00309 KListViewSearchLine::keyPressEvent( ev );
00310 }
00311
00312
00313 RecipientsPicker::RecipientsPicker( QWidget *parent )
00314 : QDialog( parent, "RecipientsPicker" )
00315 #ifndef KDEPIM_NEW_DISTRLISTS
00316 , mDistributionListManager( 0 )
00317 #endif
00318 {
00319
00320
00321 setCaption( i18n("Select Recipient") );
00322
00323 QBoxLayout *topLayout = new QVBoxLayout( this );
00324 topLayout->setSpacing( KDialog::spacingHint() );
00325 topLayout->setMargin( KDialog::marginHint() );
00326
00327 QBoxLayout *resLayout = new QHBoxLayout( topLayout );
00328
00329 QLabel *label = new QLabel( i18n("Address book:"), this );
00330 resLayout->addWidget( label );
00331
00332 mCollectionCombo = new QComboBox( this );
00333 resLayout->addWidget( mCollectionCombo );
00334 resLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding));
00335
00336 connect( mCollectionCombo, SIGNAL( highlighted( int ) ),
00337 SLOT( updateList() ) );
00338 connect( mCollectionCombo, SIGNAL( activated( int ) ),
00339 SLOT( updateList() ) );
00340
00341 QBoxLayout *searchLayout = new QHBoxLayout( topLayout );
00342
00343 QToolButton *button = new QToolButton( this );
00344 button->setIconSet( KGlobal::iconLoader()->loadIconSet(
00345 KApplication::reverseLayout() ? "clear_left":"locationbar_erase", KIcon::Small, 0 ) );
00346 searchLayout->addWidget( button );
00347 connect( button, SIGNAL( clicked() ), SLOT( resetSearch() ) );
00348
00349 label = new QLabel( i18n("&Search:"), this );
00350 searchLayout->addWidget( label );
00351
00352 mRecipientList = new KListView( this );
00353 mRecipientList->setSelectionMode( QListView::Extended );
00354 mRecipientList->setAllColumnsShowFocus( true );
00355 mRecipientList->setFullWidth( true );
00356 topLayout->addWidget( mRecipientList );
00357 mRecipientList->addColumn( i18n("->") );
00358 mRecipientList->addColumn( i18n("Name") );
00359 mRecipientList->addColumn( i18n("Email") );
00360 connect( mRecipientList, SIGNAL( doubleClicked( QListViewItem *,
00361 const QPoint &, int ) ), SLOT( slotPicked() ) );
00362 connect( mRecipientList, SIGNAL( returnPressed( QListViewItem * ) ),
00363 SLOT( slotPicked() ) );
00364
00365 new RecipientsListToolTip( mRecipientList->viewport(), mRecipientList );
00366
00367 mSearchLine = new SearchLine( this, mRecipientList );
00368 searchLayout->addWidget( mSearchLine );
00369 label->setBuddy( label );
00370 connect( mSearchLine, SIGNAL( downPressed() ), SLOT( setFocusList() ) );
00371
00372 QBoxLayout *buttonLayout = new QHBoxLayout( topLayout );
00373
00374 buttonLayout->addStretch( 1 );
00375
00376 mToButton = new QPushButton( i18n("Add as To"), this );
00377 buttonLayout->addWidget( mToButton );
00378 connect( mToButton, SIGNAL( clicked() ), SLOT( slotToClicked() ) );
00379
00380 mCcButton = new QPushButton( i18n("Add as CC"), this );
00381 buttonLayout->addWidget( mCcButton );
00382 connect( mCcButton, SIGNAL( clicked() ), SLOT( slotCcClicked() ) );
00383
00384 mBccButton = new QPushButton( i18n("Add as BCC"), this );
00385 buttonLayout->addWidget( mBccButton );
00386 connect( mBccButton, SIGNAL( clicked() ), SLOT( slotBccClicked() ) );
00387
00388
00389
00390 QPushButton *closeButton = new QPushButton( i18n("&Cancel"), this );
00391 buttonLayout->addWidget( closeButton );
00392 connect( closeButton, SIGNAL( clicked() ), SLOT( close() ) );
00393
00394 {
00395 using namespace KABC;
00396 mAddressBook = KABC::StdAddressBook::self( true );
00397 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
00398 this, SLOT( insertAddressBook( AddressBook * ) ) );
00399 }
00400
00401 initCollections();
00402
00403 mCollectionCombo->setCurrentItem( 0 );
00404
00405 updateList();
00406
00407 mSearchLine->setFocus();
00408
00409 readConfig();
00410
00411 setTabOrder( mCollectionCombo, mSearchLine );
00412 setTabOrder( mSearchLine, mRecipientList );
00413 setTabOrder( closeButton, mCollectionCombo );
00414 }
00415
00416 RecipientsPicker::~RecipientsPicker()
00417 {
00418 writeConfig();
00419
00420 #ifndef KDEPIM_NEW_DISTRLISTS
00421 delete mDistributionListManager;
00422 #endif
00423
00424 mAllRecipients->deleteAll();
00425
00426 QMap<int,RecipientsCollection *>::ConstIterator it;
00427 for( it = mCollectionMap.begin(); it != mCollectionMap.end(); ++it ) {
00428 delete *it;
00429 }
00430 }
00431
00432 void RecipientsPicker::initCollections()
00433 {
00434 mAllRecipients = new RecipientsCollection;
00435 mAllRecipients->setTitle( i18n("All") );
00436 insertCollection( mAllRecipients );
00437
00438 insertAddressBook( mAddressBook );
00439
00440 insertDistributionLists();
00441
00442 insertRecentAddresses();
00443
00444 mSelectedRecipients = new RecipientsCollection;
00445 mSelectedRecipients->setTitle( i18n("Selected Recipients") );
00446 insertCollection( mSelectedRecipients );
00447 }
00448
00449 void RecipientsPicker::insertAddressBook( KABC::AddressBook *addressbook )
00450 {
00451 QMap<KABC::Resource *,RecipientsCollection *> collectionMap;
00452
00453 QPtrList<KABC::Resource> resources = addressbook->resources();
00454 KABC::Resource *res;
00455 for( res = resources.first(); res; res = resources.next() ) {
00456 RecipientsCollection *collection = new RecipientsCollection;
00457 collectionMap.insert( res, collection );
00458 collection->setTitle( res->resourceName() );
00459 }
00460
00461 QMap<QString,RecipientsCollection *> categoryMap;
00462
00463 KABC::AddressBook::Iterator it;
00464 for( it = addressbook->begin(); it != addressbook->end(); ++it ) {
00465 QStringList emails = (*it).emails();
00466 QStringList::ConstIterator it3;
00467 for( it3 = emails.begin(); it3 != emails.end(); ++it3 ) {
00468 #ifdef KDEPIM_NEW_DISTRLISTS
00469 RecipientItem *item = new RecipientItem( mAddressBook );
00470 #else
00471 RecipientItem *item = new RecipientItem;
00472 #endif
00473 item->setAddressee( *it, *it3 );
00474 mAllRecipients->addItem( item );
00475
00476 QMap<KABC::Resource *,RecipientsCollection *>::ConstIterator collIt;
00477 collIt = collectionMap.find( it->resource() );
00478 if ( collIt != collectionMap.end() ) {
00479 (*collIt)->addItem( item );
00480 }
00481
00482 QStringList categories = (*it).categories();
00483 QStringList::ConstIterator catIt;
00484 for( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
00485 QMap<QString, RecipientsCollection *>::ConstIterator catMapIt;
00486 catMapIt = categoryMap.find( *catIt );
00487 RecipientsCollection *collection;
00488 if ( catMapIt == categoryMap.end() ) {
00489 collection = new RecipientsCollection;
00490 collection->setTitle( *catIt );
00491 categoryMap.insert( *catIt, collection );
00492 } else {
00493 collection = *catMapIt;
00494 }
00495 collection->addItem( item );
00496 }
00497 }
00498 }
00499
00500 QMap<KABC::Resource *,RecipientsCollection *>::ConstIterator it2;
00501 for( it2 = collectionMap.begin(); it2 != collectionMap.end(); ++it2 ) {
00502 insertCollection( *it2 );
00503 }
00504
00505 QMap<QString, RecipientsCollection *>::ConstIterator it3;
00506 for( it3 = categoryMap.begin(); it3 != categoryMap.end(); ++it3 ) {
00507 insertCollection( *it3 );
00508 }
00509
00510 updateList();
00511 }
00512
00513 void RecipientsPicker::insertDistributionLists()
00514 {
00515 RecipientsCollection *collection = new RecipientsCollection;
00516 collection->setTitle( i18n("Distribution Lists") );
00517
00518 #ifdef KDEPIM_NEW_DISTRLISTS
00519 QValueList<KPIM::DistributionList> lists = KPIM::DistributionList::allDistributionLists( mAddressBook );
00520 for ( uint i = 0; i < lists.count(); ++i ) {
00521 RecipientItem *item = new RecipientItem( mAddressBook );
00522 item->setDistributionList( lists[ i ] );
00523 mAllRecipients->addItem( item );
00524 collection->addItem( item );
00525 }
00526 #else
00527 delete mDistributionListManager;
00528 mDistributionListManager =
00529 new KABC::DistributionListManager( KABC::StdAddressBook::self( true ) );
00530
00531 mDistributionListManager->load();
00532
00533 QStringList lists = mDistributionListManager->listNames();
00534
00535 QStringList::Iterator listIt;
00536 for ( listIt = lists.begin(); listIt != lists.end(); ++listIt ) {
00537 KABC::DistributionList *list = mDistributionListManager->list( *listIt );
00538 RecipientItem *item = new RecipientItem;
00539 item->setDistributionList( list );
00540 mAllRecipients->addItem( item );
00541 collection->addItem( item );
00542 }
00543 #endif
00544
00545 insertCollection( collection );
00546 }
00547
00548 void RecipientsPicker::insertRecentAddresses()
00549 {
00550 RecipientsCollection *collection = new RecipientsCollection;
00551 collection->setTitle( i18n("Recent Addresses") );
00552
00553 KConfig config( "kmailrc" );
00554 KABC::Addressee::List recents =
00555 KRecentAddress::RecentAddresses::self( &config )->kabcAddresses();
00556
00557 KABC::Addressee::List::ConstIterator it;
00558 for( it = recents.begin(); it != recents.end(); ++it ) {
00559 #ifdef KDEPIM_NEW_DISTRLISTS
00560 RecipientItem *item = new RecipientItem( mAddressBook );
00561 #else
00562 RecipientItem *item = new RecipientItem;
00563 #endif
00564 item->setAddressee( *it, (*it).preferredEmail() );
00565 if ( !mAllRecipients->hasEquivalentItem( item ) ) {
00566 mAllRecipients->addItem( item );
00567 }
00568 collection->addItem( item );
00569 }
00570
00571 insertCollection( collection );
00572 }
00573
00574 void RecipientsPicker::insertCollection( RecipientsCollection *coll )
00575 {
00576 int index = mCollectionMap.count();
00577
00578 kdDebug() << "RecipientsPicker::insertCollection() " << coll->title()
00579 << " index: " << index << endl;
00580
00581 mCollectionCombo->insertItem( coll->title(), index );
00582 mCollectionMap.insert( index, coll );
00583 }
00584
00585 void RecipientsPicker::updateRecipient( const Recipient &recipient )
00586 {
00587 RecipientItem::List allRecipients = mAllRecipients->items();
00588 RecipientItem::List::ConstIterator itAll;
00589 for( itAll = allRecipients.begin(); itAll != allRecipients.end(); ++itAll ) {
00590 if ( (*itAll)->recipient() == recipient.email() ) {
00591 (*itAll)->setRecipientType( recipient.typeLabel() );
00592 }
00593 }
00594 updateList();
00595 }
00596
00597 void RecipientsPicker::setRecipients( const Recipient::List &recipients )
00598 {
00599 RecipientItem::List allRecipients = mAllRecipients->items();
00600 RecipientItem::List::ConstIterator itAll;
00601 for( itAll = allRecipients.begin(); itAll != allRecipients.end(); ++itAll ) {
00602 (*itAll)->setRecipientType( QString::null );
00603 }
00604
00605 mSelectedRecipients->clear();
00606
00607 Recipient::List::ConstIterator it;
00608 for( it = recipients.begin(); it != recipients.end(); ++it ) {
00609 RecipientItem *item = 0;
00610 for( itAll = allRecipients.begin(); itAll != allRecipients.end(); ++itAll ) {
00611 if ( (*itAll)->recipient() == (*it).email() ) {
00612 (*itAll)->setRecipientType( (*it).typeLabel() );
00613 item = *itAll;
00614 }
00615 }
00616 if ( !item ) {
00617 KABC::Addressee a;
00618 QString name;
00619 QString email;
00620 KABC::Addressee::parseEmailAddress( (*it).email(), name, email );
00621 a.setNameFromString( name );
00622 a.insertEmail( email );
00623
00624 #ifdef KDEPIM_NEW_DISTRLISTS
00625 item = new RecipientItem( mAddressBook );
00626 #else
00627 item = new RecipientItem;
00628 #endif
00629 item->setAddressee( a, a.preferredEmail() );
00630 item->setRecipientType( (*it).typeLabel() );
00631 mAllRecipients->addItem( item );
00632 }
00633 mSelectedRecipients->addItem( item );
00634 }
00635
00636 updateList();
00637 }
00638
00639 void RecipientsPicker::setDefaultButton( QPushButton *button )
00640 {
00641
00642 button->setDefault( true );
00643 }
00644
00645 void RecipientsPicker::setDefaultType( Recipient::Type type )
00646 {
00647 mDefaultType = type;
00648
00649 if ( type == Recipient::To ) {
00650 setDefaultButton( mToButton );
00651 } else if ( type == Recipient::Cc ) {
00652 setDefaultButton( mCcButton );
00653 } else if ( type == Recipient::Bcc ) {
00654 setDefaultButton( mBccButton );
00655 }
00656 }
00657
00658 void RecipientsPicker::updateList()
00659 {
00660 mRecipientList->clear();
00661
00662 RecipientsCollection *coll = mCollectionMap[ mCollectionCombo->currentItem() ];
00663
00664 RecipientItem::List items = coll->items();
00665 RecipientItem::List::ConstIterator it;
00666 for( it = items.begin(); it != items.end(); ++it ) {
00667 new RecipientViewItem( *it, mRecipientList );
00668 }
00669
00670 mSearchLine->updateSearch();
00671 }
00672
00673 void RecipientsPicker::slotToClicked()
00674 {
00675 pick( Recipient::To );
00676 }
00677
00678 void RecipientsPicker::slotCcClicked()
00679 {
00680 pick( Recipient::Cc );
00681 }
00682
00683 void RecipientsPicker::slotBccClicked()
00684 {
00685 pick( Recipient::Bcc );
00686 }
00687
00688 void RecipientsPicker::slotPicked( QListViewItem *viewItem )
00689 {
00690 RecipientViewItem *item = static_cast<RecipientViewItem *>( viewItem );
00691 if ( item ) {
00692 RecipientItem *i = item->recipientItem();
00693 emit pickedRecipient( Recipient( i->recipient(), Recipient::Undefined ) );
00694 }
00695 close();
00696 }
00697
00698 void RecipientsPicker::slotPicked()
00699 {
00700 pick( mDefaultType );
00701 }
00702
00703 void RecipientsPicker::pick( Recipient::Type type )
00704 {
00705 kdDebug() << "RecipientsPicker::pick " << int( type ) << endl;
00706
00707 int count = 0;
00708 QListViewItemIterator it( mRecipientList ,
00709 QListViewItemIterator::Visible | QListViewItemIterator::Selected );
00710 for ( ; it.current(); ++it )
00711 ++count;
00712
00713 if ( count > GlobalSettings::self()->maximumRecipients() ) {
00714 KMessageBox::sorry( this,
00715 i18n("You selected 1 recipient. The maximum supported number of "
00716 "recipients is %1. Please adapt the selection.",
00717 "You selected %n recipients. The maximum supported number of "
00718 "recipients is %1. Please adapt the selection.", count)
00719 .arg( GlobalSettings::self()->maximumRecipients() ) );
00720 return;
00721 }
00722
00723 it = QListViewItemIterator( mRecipientList ,
00724 QListViewItemIterator::Visible | QListViewItemIterator::Selected );
00725 for ( ; it.current(); ++it ) {
00726 RecipientViewItem *item = static_cast<RecipientViewItem *>( it.current() );
00727 if ( item ) {
00728 RecipientItem *i = item->recipientItem();
00729 Recipient r = i->recipient();
00730 r.setType( type );
00731 emit pickedRecipient( r );
00732 }
00733 }
00734 close();
00735 }
00736
00737 void RecipientsPicker::keyPressEvent( QKeyEvent *ev )
00738 {
00739 if ( ev->key() == Key_Escape ) close();
00740
00741 QWidget::keyPressEvent( ev );
00742 }
00743
00744 void RecipientsPicker::readConfig()
00745 {
00746 KConfig *cfg = KGlobal::config();
00747 cfg->setGroup( "RecipientsPicker" );
00748 QSize size = cfg->readSizeEntry( "Size" );
00749 if ( !size.isEmpty() ) {
00750 resize( size );
00751 }
00752 int currentCollection = cfg->readNumEntry( "CurrentCollection", -1 );
00753 if ( currentCollection >= 0 &&
00754 currentCollection < mCollectionCombo->count() ) {
00755 mCollectionCombo->setCurrentItem( currentCollection );
00756 }
00757 }
00758
00759 void RecipientsPicker::writeConfig()
00760 {
00761 KConfig *cfg = KGlobal::config();
00762 cfg->setGroup( "RecipientsPicker" );
00763 cfg->writeEntry( "Size", size() );
00764 cfg->writeEntry( "CurrentCollection", mCollectionCombo->currentItem() );
00765 }
00766
00767 void RecipientsPicker::setFocusList()
00768 {
00769 mRecipientList->setFocus();
00770 }
00771
00772 void RecipientsPicker::resetSearch()
00773 {
00774 mSearchLine->setText( QString::null );
00775 }
00776
00777 #include "recipientspicker.moc"