diff options
Diffstat (limited to 'libkdepim/addressesdialog.cpp')
-rw-r--r-- | libkdepim/addressesdialog.cpp | 123 |
1 files changed, 100 insertions, 23 deletions
diff --git a/libkdepim/addressesdialog.cpp b/libkdepim/addressesdialog.cpp index 8a33d7999..14feafb67 100644 --- a/libkdepim/addressesdialog.cpp +++ b/libkdepim/addressesdialog.cpp @@ -67,7 +67,7 @@ struct AddresseeViewItem::AddresseeViewItemPrivate { }; struct AddressesDialog::AddressesDialogPrivate { - AddressesDialogPrivate() : + AddressesDialogPrivate() : ui(0), personal(0), recent(0), toItem(0), ccItem(0), bccItem(0), ldapSearchDialog(0) @@ -77,6 +77,8 @@ struct AddressesDialog::AddressesDialogPrivate { AddresseeViewItem *personal; AddresseeViewItem *recent; + AddresseeViewItem *topdist; + TQPtrList<AddresseeViewItem> dists; AddresseeViewItem *toItem; AddresseeViewItem *ccItem; @@ -181,11 +183,11 @@ void AddresseeViewItem::setSelected(bool selected) { if (selected == isSelected()) { - return; + return; } - emit addressSelected( this, selected ); - TQListViewItem::setSelected(selected); + emit addressSelected( this, selected ); + TQListViewItem::setSelected(selected); } int @@ -223,6 +225,9 @@ AddressesDialog::AddressesDialog( TQWidget *widget, const char *name ) initConnections(); d->ui->mAvailableView->setFocus(); + + setMainWidget( page ); + page->setMinimumSize( 750, 400 ); } AddressesDialog::~AddressesDialog() @@ -331,6 +336,7 @@ AddressesDialog::updateRecentAddresses() addAddresseeToAvailable( *it, d->recent ); if ( d->recent->childCount() > 0 ) { + d->recent->setOpen( true ); d->recent->setVisible( true ); } } @@ -472,8 +478,10 @@ AddressesDialog::updateAvailableAddressees() d->recent = 0; updateRecentAddresses(); + d->topdist = 0; addDistributionLists(); if ( d->personal->childCount() > 0 ) { + d->personal->setOpen( true ); d->personal->setVisible( true ); } @@ -724,10 +732,9 @@ AddressesDialog::addSelectedTo() addAddresseesToSelected( d->toItem, selectedAvailableAddresses ); selectedAvailableAddresses.clear(); - if ( d->toItem->childCount() > 0 ) + if ( d->toItem->childCount() > 0 ) { d->toItem->setVisible( true ); - else - { + } else { delete d->toItem; d->toItem = 0; } @@ -746,10 +753,9 @@ AddressesDialog::addSelectedCC() addAddresseesToSelected( d->ccItem, selectedAvailableAddresses ); selectedAvailableAddresses.clear(); - if ( d->ccItem->childCount() > 0 ) + if ( d->ccItem->childCount() > 0 ) { d->ccItem->setVisible( true ); - else - { + } else { delete d->ccItem; d->ccItem = 0; } @@ -768,10 +774,9 @@ AddressesDialog::addSelectedBCC() addAddresseesToSelected( d->bccItem, selectedAvailableAddresses ); selectedAvailableAddresses.clear(); - if ( d->bccItem->childCount() > 0 ) + if ( d->bccItem->childCount() > 0 ) { d->bccItem->setVisible( true ); - else - { + } else { delete d->bccItem; d->bccItem = 0; } @@ -950,7 +955,7 @@ AddressesDialog::searchLdap() void AddressesDialog::ldapSearchResult() { - TQStringList emails = TQStringList::split(',', d->ldapSearchDialog->selectedEMails() ); + TQStringList emails = KPIM::splitEmailAddrList( d->ldapSearchDialog->selectedEMails() ); TQStringList::iterator it( emails.begin() ); TQStringList::iterator end( emails.end() ); for ( ; it != end; ++it ){ @@ -979,22 +984,81 @@ AddressesDialog::filterChanged( const TQString& txt ) if ( txt.isEmpty() ) showAll = true; + int personalVisible = 0; + int recentVisible = 0; while ( it.current() ) { AddresseeViewItem* item = static_cast<AddresseeViewItem*>( it.current() ); ++it; + if ( showAll ) { + item->setOpen( true ); item->setVisible( true ); - if ( item->category() == AddresseeViewItem::Group ) - item->setOpen( false );//close to not have too many entries + // allen: I do not like the following behavior. comment out and see if anyone screams + //if ( item->category() == AddresseeViewItem::Group ) + // item->setOpen( false );//close to not have too many entries continue; } + if ( item->category() == AddresseeViewItem::Entry ) { - bool matches = item->matches( txt ) ; + bool matches = item->matches( txt ); item->setVisible( matches ); - if ( matches && static_cast<TQListViewItem*>(item)->parent() ) { - static_cast<TQListViewItem*>(item)->parent()->setOpen( true );//open the parents with found entries + TQListViewItem *parent = static_cast<TQListViewItem*>( item )->parent(); + if ( matches && parent ) { + if ( parent == d->personal ) { + personalVisible++; + } else if ( parent == d->recent ) { + recentVisible++; + } } } + if ( item->category() == AddresseeViewItem::Group ) { + item->setOpen( true ); + item->setVisible( true ); + } + } + + if ( !showAll && personalVisible == 0 ) { + d->personal->setOpen( false ); + d->personal->setVisible( false ); + } + if ( !showAll && recentVisible == 0 ) { + d->recent->setOpen( false ); + d->recent->setVisible( false ); + } + + int distlistgroupVisible = 0; + if ( !showAll ) { + TQPtrListIterator<AddresseeViewItem> it( d->dists ); + for ( ; it.current(); ++it ) { + TQListViewItem *p = *it; + p->setVisible( true ); + AddresseeViewItem *p2 = static_cast<AddresseeViewItem*>( p->firstChild() ); + int pcount = 0; + while ( p2 ) { + if ( p2->matches( txt ) ) { + p2->setVisible( true ); + pcount++; + } else { + p2->setVisible( false ); + } + p2 = static_cast<AddresseeViewItem*>( p2->nextSibling() ); + } + if ( !pcount && !p->text( 0 ).contains( txt, false ) ) { + p->setVisible( false ); + } + distlistgroupVisible += pcount; + if ( p->text( 0 ).contains( txt, false ) ) { + distlistgroupVisible++; + } + } + } + if ( d->topdist ) { + if ( showAll || distlistgroupVisible > 0 ) { + d->topdist->setOpen( true ); + } else { + d->topdist->setOpen( false ); + d->topdist->setVisible( false ); + } } } @@ -1084,14 +1148,16 @@ AddressesDialog::addDistributionLists() if ( distLists.isEmpty() ) return; - AddresseeViewItem *topItem = new AddresseeViewItem( d->ui->mAvailableView, - i18n( "Distribution Lists" ) ); + if ( !d->topdist ) { + d->topdist = new AddresseeViewItem( d->ui->mAvailableView, i18n( "Distribution Lists" ) ); + } #ifdef KDEPIM_NEW_DISTRLISTS TQValueList<KPIM::DistributionList>::ConstIterator listIt; #else TQStringList::Iterator listIt; #endif + int total = 0; for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) { #ifdef KDEPIM_NEW_DISTRLISTS KPIM::DistributionList dlist = *listIt; @@ -1101,7 +1167,8 @@ AddressesDialog::addDistributionLists() KABC::DistributionList::Entry::List entries = dlist.entries(); #endif - AddresseeViewItem *item = new AddresseeViewItem( topItem, dlist.name() ); + AddresseeViewItem *item = new AddresseeViewItem( d->topdist, dlist.name() ); + d->dists.append( item ); connect( item, TQT_SIGNAL( addressSelected( AddresseeViewItem*, bool ) ), this, TQT_SLOT( availableAddressSelected( AddresseeViewItem*, bool ) ) ); @@ -1110,8 +1177,18 @@ AddressesDialog::addDistributionLists() #else KABC::DistributionList::Entry::List::Iterator itemIt; #endif - for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt ) + for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt ) { addAddresseeToAvailable( (*itemIt).addressee, item, false ); + } + if ( item->childCount() > 0 ) { + item->setOpen( true ); + item->setVisible( true ); + } + total += item->childCount(); + } + if ( total > 0 ) { + d->topdist->setOpen( true ); + d->topdist->setVisible( true ); } } |