25 #include "addressesdialog.h"
26 #include "addresspicker.h"
27 #include "ldapsearchdialog.h"
31 #include <libemailfunctions/email.h>
33 #ifdef TDEPIM_NEW_DISTRLISTS
34 #include "distributionlist.h"
35 #include <tderesources/selectdialog.h>
36 #include <tdeabc/resource.h>
38 #include <tdeabc/distributionlist.h>
41 #include <tdeabc/stdaddressbook.h>
42 #include <tdeapplication.h>
44 #include <tdeglobal.h>
45 #include <kiconloader.h>
46 #include <kinputdialog.h>
47 #include <klineedit.h>
48 #include <tdelocale.h>
49 #include <tdemessagebox.h>
50 #include <tdeprocess.h>
51 #include <kpushbutton.h>
53 #include <kstandarddirs.h>
63 struct AddresseeViewItem::AddresseeViewItemPrivate {
64 TDEABC::Addressee address;
65 AddresseeViewItem::Category category;
66 TDEABC::Addressee::List addresses;
69 struct AddressesDialog::AddressesDialogPrivate {
70 AddressesDialogPrivate() :
71 ui(0), personal(0), recent(0),
72 toItem(0), ccItem(0), bccItem(0),
78 AddresseeViewItem *personal;
79 AddresseeViewItem *recent;
80 AddresseeViewItem *topdist;
81 TQPtrList<AddresseeViewItem> dists;
83 AddresseeViewItem *toItem;
84 AddresseeViewItem *ccItem;
85 AddresseeViewItem *bccItem;
87 TQDict<AddresseeViewItem> groupDict;
89 TDEABC::Addressee::List recentAddresses;
90 LDAPSearchDialog *ldapSearchDialog;
94 AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent,
const TDEABC::Addressee& addr,
96 : TQObject( 0 ), TDEListViewItem( parent, addr.realName(),
97 ( emailIndex == 0 ? addr.preferredEmail() : addr.emails()[ emailIndex ] ) )
99 d =
new AddresseeViewItemPrivate;
103 if ( text( 0 ).stripWhiteSpace().isEmpty() )
104 setText( 0, addr.preferredEmail() );
106 if ( addr.photo().url().isEmpty() ) {
107 if ( addr.photo().data().isNull() )
108 setPixmap( 0, TDEGlobal::iconLoader()->loadIcon(
"preferences-desktop-personal", TDEIcon::Small ) );
110 setPixmap( 0, addr.photo().data().smoothScale( 16, 16 ) );
112 setPixmap( 0, TDEGlobal::iconLoader()->loadIcon( addr.photo().url(), TDEIcon::Small ) );
116 AddresseeViewItem::AddresseeViewItem( TDEListView *lv,
const TQString& name, Category cat )
117 : TQObject(0), TDEListViewItem( lv, name )
119 d =
new AddresseeViewItemPrivate;
123 AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent,
const TQString& name,
124 const TDEABC::Addressee::List &lst )
125 : TQObject(0), TDEListViewItem( parent, name, i18n(
"<group>") )
127 d =
new AddresseeViewItemPrivate;
128 d->category = FilledGroup;
132 AddresseeViewItem::AddresseeViewItem( AddresseeViewItem *parent,
const TQString& name )
133 : TQObject(0), TDEListViewItem( parent, name, i18n(
"<group>") )
135 d =
new AddresseeViewItemPrivate;
136 d->category = DistList;
138 setPixmap( 0, TDEGlobal::iconLoader()->loadIcon(
"tdmconfig", TDEIcon::Small ) );
141 AddresseeViewItem::~AddresseeViewItem()
148 AddresseeViewItem::addressee()
const
153 TDEABC::Addressee::List
154 AddresseeViewItem::addresses()
const
159 AddresseeViewItem::Category
160 AddresseeViewItem::category()
const
166 AddresseeViewItem::name()
const
172 AddresseeViewItem::email()
const
177 bool AddresseeViewItem::matches(
const TQString& txt)
const
179 return d->address.realName().contains(txt,
false) || d->address.preferredEmail().contains(txt,
false);
182 void AddresseeViewItem::setSelected(
bool selected)
184 if (selected == isSelected())
189 emit addressSelected(
this, selected );
190 TQListViewItem::setSelected(selected);
194 AddresseeViewItem::compare( TQListViewItem * i,
int col,
bool ascending )
const
196 if ( category() == Group || category() == Entry )
197 return TDEListViewItem::compare( i , col, ascending );
199 AddresseeViewItem *item =
static_cast<AddresseeViewItem*
>( i );
200 int a =
static_cast<int>( category() );
201 int b =
static_cast<int>( item->category() );
215 AddressesDialog::AddressesDialog( TQWidget *widget,
const char *name )
216 : KDialogBase( widget, name, true, i18n(
"Address Selection"),
217 Ok|Cancel, Ok, true )
219 TQVBox *page = makeVBoxMainWidget();
220 d =
new AddressesDialogPrivate;
221 d->ui =
new AddressPickerUI( page );
223 TDEABC::StdAddressBook::self(
true );
224 updateAvailableAddressees();
227 d->ui->mAvailableView->setFocus();
229 setMainWidget( page );
230 page->setMinimumSize( 750, 400 );
233 AddressesDialog::~AddressesDialog()
239 AddresseeViewItem* AddressesDialog::selectedToItem()
243 d->toItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"To"), AddresseeViewItem::To );
244 connect(d->toItem, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
245 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
250 AddresseeViewItem* AddressesDialog::selectedCcItem()
254 d->ccItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"CC"), AddresseeViewItem::CC );
255 connect(d->ccItem, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
256 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
261 AddresseeViewItem* AddressesDialog::selectedBccItem()
265 d->bccItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"BCC"), AddresseeViewItem::BCC );
266 connect(d->bccItem, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
267 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
273 AddressesDialog::setSelectedTo(
const TQStringList& l )
275 TQString name, email;
276 for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
277 TDEABC::Addressee addr;
278 TDEABC::Addressee::parseEmailAddress( *it, name, email );
279 addr.setNameFromString( name );
280 addr.insertEmail( email );
281 addAddresseeToSelected( addr, selectedToItem() );
286 AddressesDialog::setSelectedCC(
const TQStringList& l )
288 TQString name, email;
289 for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
290 TDEABC::Addressee addr;
291 TDEABC::Addressee::parseEmailAddress( *it, name, email );
292 addr.setNameFromString( name );
293 addr.insertEmail( email );
294 addAddresseeToSelected( addr, selectedCcItem() );
299 AddressesDialog::setSelectedBCC(
const TQStringList& l )
301 TQString name, email;
302 for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
303 TDEABC::Addressee addr;
304 TDEABC::Addressee::parseEmailAddress( *it, name, email );
305 addr.setNameFromString( name );
306 addr.insertEmail( email );
307 addAddresseeToSelected( addr, selectedBccItem() );
312 AddressesDialog::setRecentAddresses(
const TDEABC::Addressee::List& list )
314 d->recentAddresses = list;
316 updateRecentAddresses();
318 checkForSingleAvailableGroup();
322 AddressesDialog::updateRecentAddresses()
324 static const TQString &recentGroup = TDEGlobal::staticQString( i18n(
"Recent Addresses" ) );
327 d->recent =
new AddresseeViewItem( d->ui->mAvailableView, recentGroup );
328 connect(d->recent, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
329 this, TQ_SLOT(availableAddressSelected(AddresseeViewItem*,
bool)));
330 d->recent->setVisible(
false );
331 d->groupDict.insert( recentGroup, d->recent );
334 TDEABC::Addressee::List::ConstIterator it;
335 for ( it = d->recentAddresses.begin(); it != d->recentAddresses.end(); ++it )
336 addAddresseeToAvailable( *it, d->recent );
338 if ( d->recent->childCount() > 0 ) {
339 d->recent->setOpen(
true );
340 d->recent->setVisible(
true );
345 AddressesDialog::setShowCC(
bool b )
347 d->ui->mCCButton->setShown( b );
351 AddressesDialog::setShowBCC(
bool b )
353 d->ui->mBCCButton->setShown( b );
357 AddressesDialog::to()
const
359 TQStringList emails = allDistributionLists( d->toItem );
360 TDEABC::Addressee::List l = toAddresses();
361 emails += entryToString( l );
367 AddressesDialog::cc()
const
369 TQStringList emails = allDistributionLists( d->ccItem );
370 TDEABC::Addressee::List l = ccAddresses();
371 emails += entryToString( l );
377 AddressesDialog::bcc()
const
379 TQStringList emails = allDistributionLists( d->bccItem );
381 TDEABC::Addressee::List l = bccAddresses();
382 emails += entryToString( l );
387 TDEABC::Addressee::List
388 AddressesDialog::toAddresses()
const
390 return allAddressee( d->toItem );
392 TDEABC::Addressee::List
393 AddressesDialog::allToAddressesNoDuplicates()
const
395 TDEABC::Addressee::List aList = allAddressee( d->toItem );
396 const TQStringList dList = toDistributionLists();
397 TDEABC::AddressBook* abook = TDEABC::StdAddressBook::self(
true );
398 #ifdef TDEPIM_NEW_DISTRLISTS
399 for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) {
400 const TQValueList<KPIM::DistributionList::Entry> eList
401 = KPIM::DistributionList::findByName(abook, *it).
entries(abook);
402 TQValueList<KPIM::DistributionList::Entry>::ConstIterator eit;
403 for( eit = eList.begin(); eit != eList.end(); ++eit ) {
404 TDEABC::Addressee a = (*eit).addressee;
405 if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
411 TDEABC::DistributionListManager manager( abook );
413 for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) {
414 const TQValueList<TDEABC::DistributionList::Entry> eList = manager.list( *it )->entries();
415 TQValueList<TDEABC::DistributionList::Entry>::ConstIterator eit;
416 for( eit = eList.begin(); eit != eList.end(); ++eit ) {
417 TDEABC::Addressee a = (*eit).addressee;
418 if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
427 TDEABC::Addressee::List
428 AddressesDialog::ccAddresses()
const
430 return allAddressee( d->ccItem );
433 TDEABC::Addressee::List
434 AddressesDialog::bccAddresses()
const
436 return allAddressee( d->bccItem );
441 AddressesDialog::toDistributionLists()
const
443 return allDistributionLists( d->toItem );
447 AddressesDialog::ccDistributionLists()
const
449 return allDistributionLists( d->ccItem );
453 AddressesDialog::bccDistributionLists()
const
455 return allDistributionLists( d->bccItem );
459 AddressesDialog::updateAvailableAddressees()
461 d->ui->mAvailableView->clear();
462 d->groupDict.clear();
464 static const TQString &personalGroup = TDEGlobal::staticQString( i18n(
"Other Addresses" ) );
465 d->ui->mAvailableView->setRootIsDecorated(
true );
466 d->personal =
new AddresseeViewItem( d->ui->mAvailableView, personalGroup );
469 d->personal->setVisible(
false );
470 d->groupDict.insert( personalGroup, d->personal );
472 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
473 for( TDEABC::AddressBook::Iterator it = addressBook->begin();
474 it != addressBook->end(); ++it ) {
475 addAddresseeToAvailable( *it, d->personal );
479 updateRecentAddresses();
482 addDistributionLists();
483 if ( d->personal->childCount() > 0 ) {
484 d->personal->setOpen(
true );
485 d->personal->setVisible(
true );
488 checkForSingleAvailableGroup();
491 void AddressesDialog::checkForSingleAvailableGroup()
493 TQListViewItem* item = d->ui->mAvailableView->firstChild();
494 TQListViewItem* firstGroup = 0;
498 if (item->isVisible())
500 if (!firstGroup &&
static_cast<AddresseeViewItem*
>(item)->category() != AddresseeViewItem::Entry)
506 item = item->nextSibling();
509 if (found == 1 && firstGroup)
511 firstGroup->setOpen(
true);
516 AddressesDialog::availableSelectionChanged()
518 bool selection = !selectedAvailableAddresses.isEmpty();
519 d->ui->mToButton->setEnabled(selection);
520 d->ui->mCCButton->setEnabled(selection);
521 d->ui->mBCCButton->setEnabled(selection);
525 AddressesDialog::selectedSelectionChanged()
527 bool selection = !selectedSelectedAddresses.isEmpty();
528 d->ui->mRemoveButton->setEnabled(selection);
532 AddressesDialog::availableAddressSelected( AddresseeViewItem* item,
bool selected )
536 selectedAvailableAddresses.append(item);
540 selectedAvailableAddresses.remove(item);
545 AddressesDialog::selectedAddressSelected( AddresseeViewItem* item,
bool selected )
550 AddresseeViewItem* parent =
static_cast<AddresseeViewItem*
>(((TQListViewItem*)item)->parent());
551 if ( parent && selected )
552 parent->setSelected(
false );
555 selectedSelectedAddresses.append(item);
559 selectedSelectedAddresses.remove(item);
562 AddresseeViewItem* child =
static_cast<AddresseeViewItem*
>(item->firstChild());
564 child->setSelected(
false );
565 child =
static_cast<AddresseeViewItem*
>(child->nextSibling());
571 AddressesDialog::initConnections()
573 connect( d->ui->mFilterEdit, TQ_SIGNAL(textChanged(
const TQString &)),
574 TQ_SLOT(filterChanged(
const TQString &)) );
575 connect( d->ui->mToButton, TQ_SIGNAL(clicked()),
576 TQ_SLOT(addSelectedTo()) );
577 connect( d->ui->mCCButton, TQ_SIGNAL(clicked()),
578 TQ_SLOT(addSelectedCC()) );
579 connect( d->ui->mBCCButton, TQ_SIGNAL(clicked()),
580 TQ_SLOT(addSelectedBCC()) );
581 connect( d->ui->mSaveAs, TQ_SIGNAL(clicked()),
583 connect( d->ui->mLdapSearch, TQ_SIGNAL(clicked()),
584 TQ_SLOT(searchLdap()) );
585 connect( d->ui->mRemoveButton, TQ_SIGNAL(clicked()),
586 TQ_SLOT(removeEntry()) );
587 connect( d->ui->mAvailableView, TQ_SIGNAL(selectionChanged()),
588 TQ_SLOT(availableSelectionChanged()) );
589 connect( d->ui->mAvailableView, TQ_SIGNAL(doubleClicked(TQListViewItem*)),
590 TQ_SLOT(addSelectedTo()) );
591 connect( d->ui->mSelectedView, TQ_SIGNAL(selectionChanged()),
592 TQ_SLOT(selectedSelectionChanged()) );
593 connect( d->ui->mSelectedView, TQ_SIGNAL(doubleClicked(TQListViewItem*)),
594 TQ_SLOT(removeEntry()) );
596 #ifndef TDEPIM_NEW_DISTRLISTS
597 connect( TDEABC::DistributionListWatcher::self(), TQ_SIGNAL( changed() ),
598 this, TQ_SLOT( updateAvailableAddressees() ) );
601 connect( TDEABC::StdAddressBook::self(
true ), TQ_SIGNAL( addressBookChanged(AddressBook*) ),
602 this, TQ_SLOT( updateAvailableAddressees() ) );
606 AddressesDialog::addAddresseeToAvailable(
const TDEABC::Addressee& addr, AddresseeViewItem* defaultParent,
bool useCategory )
608 if ( addr.preferredEmail().isEmpty() )
612 TQStringList categories = addr.categories();
614 for ( TQStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) {
615 if ( !d->groupDict[ *it ] ) {
616 AddresseeViewItem* category =
new AddresseeViewItem( d->ui->mAvailableView, *it );
617 d->groupDict.insert( *it, category );
620 for ( uint i = 0; i < addr.emails().count(); ++i ) {
621 AddresseeViewItem* addressee =
new AddresseeViewItem( d->groupDict[ *it ], addr, i );
622 connect(addressee, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
623 this, TQ_SLOT(availableAddressSelected(AddresseeViewItem*,
bool)));
628 bool noCategory =
false;
630 if ( addr.categories().isEmpty() )
635 if ( defaultParent && noCategory ) {
636 AddresseeViewItem* addressee =
new AddresseeViewItem( defaultParent, addr );
637 connect(addressee, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
638 this, TQ_SLOT(availableAddressSelected(AddresseeViewItem*,
bool)));
643 AddressesDialog::addAddresseeToSelected(
const TDEABC::Addressee& addr, AddresseeViewItem* defaultParent )
645 if ( addr.preferredEmail().isEmpty() )
648 if ( defaultParent ) {
649 AddresseeViewItem *myChild =
static_cast<AddresseeViewItem*
>( defaultParent->firstChild() );
651 if ( myChild->addressee().preferredEmail() == addr.preferredEmail() )
653 myChild =
static_cast<AddresseeViewItem*
>( myChild->nextSibling() );
655 AddresseeViewItem* addressee =
new AddresseeViewItem( defaultParent, addr );
656 connect(addressee, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
657 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
658 defaultParent->setOpen(
true );
661 d->ui->mSaveAs->setEnabled(
true);
665 AddressesDialog::addAddresseesToSelected( AddresseeViewItem *parent,
666 const TQPtrList<AddresseeViewItem>& addresses )
670 TQPtrListIterator<AddresseeViewItem> itr( addresses );
674 d->ui->mSaveAs->setEnabled(
true);
677 while ( itr.current() ) {
678 AddresseeViewItem* address = itr.current();
681 if (selectedToAvailableMapping.find(address) != 0)
686 AddresseeViewItem* newItem = 0;
687 if (address->category() == AddresseeViewItem::Entry)
689 newItem =
new AddresseeViewItem( parent, address->addressee() );
691 else if (address->category() == AddresseeViewItem::DistList)
693 newItem =
new AddresseeViewItem( parent, address->name() );
697 newItem =
new AddresseeViewItem( parent, address->name(), allAddressee( address ) );
700 address->setSelected(
false );
701 address->setVisible(
false );
702 selectedToAvailableMapping.insert(address, newItem);
703 selectedToAvailableMapping.insert(newItem, address);
704 connect(newItem, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
705 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
708 parent->setOpen(
true );
712 AddressesDialog::entryToString(
const TDEABC::Addressee::List& l )
const
714 TQStringList entries;
716 for( TDEABC::Addressee::List::ConstIterator it = l.begin(); it != l.end(); ++it ) {
717 entries += (*it).fullEmail();
723 AddressesDialog::addSelectedTo()
727 d->toItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"To"), AddresseeViewItem::To );
728 connect(d->toItem, TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
729 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
732 addAddresseesToSelected( d->toItem, selectedAvailableAddresses );
733 selectedAvailableAddresses.clear();
735 if ( d->toItem->childCount() > 0 ) {
736 d->toItem->setVisible(
true );
744 AddressesDialog::addSelectedCC()
748 d->ccItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"CC"), AddresseeViewItem::CC );
749 connect(d->ccItem , TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
750 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
753 addAddresseesToSelected( d->ccItem, selectedAvailableAddresses );
754 selectedAvailableAddresses.clear();
756 if ( d->ccItem->childCount() > 0 ) {
757 d->ccItem->setVisible(
true );
765 AddressesDialog::addSelectedBCC()
769 d->bccItem =
new AddresseeViewItem( d->ui->mSelectedView, i18n(
"BCC"), AddresseeViewItem::BCC );
770 connect(d->bccItem , TQ_SIGNAL(addressSelected(AddresseeViewItem*,
bool)),
771 this, TQ_SLOT(selectedAddressSelected(AddresseeViewItem*,
bool)));
774 addAddresseesToSelected( d->bccItem, selectedAvailableAddresses );
775 selectedAvailableAddresses.clear();
777 if ( d->bccItem->childCount() > 0 ) {
778 d->bccItem->setVisible(
true );
785 void AddressesDialog::unmapSelectedAddress(AddresseeViewItem* item)
787 AddresseeViewItem* correspondingItem = selectedToAvailableMapping[item];
788 if (correspondingItem)
790 correspondingItem->setVisible(
true );
791 selectedToAvailableMapping.remove( item );
792 selectedToAvailableMapping.remove( correspondingItem );
795 AddresseeViewItem* child =
static_cast<AddresseeViewItem*
>(item->firstChild());
798 unmapSelectedAddress(child);
799 child =
static_cast<AddresseeViewItem*
>(child->nextSibling());
804 AddressesDialog::removeEntry()
806 TQPtrList<AddresseeViewItem> lst;
807 bool resetTo =
false;
808 bool resetCC =
false;
809 bool resetBCC =
false;
811 lst.setAutoDelete(
false );
812 TQPtrListIterator<AddresseeViewItem> it( selectedSelectedAddresses );
813 while ( it.current() ) {
814 AddresseeViewItem* item = it.current();
816 if ( d->toItem == item )
818 else if ( d->ccItem == item )
820 else if( d->bccItem == item )
823 unmapSelectedAddress(item);
826 selectedSelectedAddresses.clear();
827 lst.setAutoDelete(
true );
831 else if ( d->toItem && d->toItem->childCount() == 0 )
838 else if ( d->ccItem && d->ccItem->childCount() == 0 )
845 else if ( d->bccItem && d->bccItem->childCount() == 0 )
850 d->ui->mSaveAs->setEnabled(d->ui->mSelectedView->firstChild() != 0);
853 #ifdef TDEPIM_NEW_DISTRLISTS
857 static TDEABC::Resource *requestResource( TDEABC::AddressBook* abook, TQWidget *parent )
859 TQPtrList<TDEABC::Resource> tdeabcResources = abook->resources();
861 TQPtrList<KRES::Resource> kresResources;
862 TQPtrListIterator<TDEABC::Resource> resIt( tdeabcResources );
863 TDEABC::Resource *resource;
864 while ( ( resource = resIt.current() ) != 0 ) {
866 if ( !resource->readOnly() ) {
867 KRES::Resource *res =
static_cast<KRES::Resource*
>( resource );
869 kresResources.append( res );
873 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
874 return static_cast<TDEABC::Resource*
>( res );
879 AddressesDialog::saveAs()
881 #ifndef TDEPIM_NEW_DISTRLISTS
882 TDEABC::DistributionListManager manager( TDEABC::StdAddressBook::self(
true ) );
886 if ( !d->ui->mSelectedView->firstChild() ) {
887 KMessageBox::information( 0,
888 i18n(
"There are no addresses in your list. "
889 "First add some addresses from your address book, "
890 "then try again.") );
895 TQString name = KInputDialog::getText( i18n(
"New Distribution List"),
896 i18n(
"Please enter name:"),
899 if ( !ok || name.isEmpty() )
902 bool alreadyExists =
false;
903 #ifdef TDEPIM_NEW_DISTRLISTS
904 TDEABC::AddressBook* abook = TDEABC::StdAddressBook::self(
true );
906 alreadyExists = !dlist.isEmpty();
908 alreadyExists = manager.list( name );
911 if ( alreadyExists ) {
912 KMessageBox::information( 0,
913 i18n(
"<qt>Distribution list with the given name <b>%1</b> "
914 "already exists. Please select a different name.</qt>" )
919 #ifdef TDEPIM_NEW_DISTRLISTS
920 TDEABC::Resource* resource = requestResource( abook,
this );
924 dlist.setResource( resource );
926 TDEABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView,
false );
927 for ( TDEABC::Addressee::List::iterator itr = addrl.begin();
928 itr != addrl.end(); ++itr ) {
931 abook->insertAddressee( dlist );
933 TDEABC::DistributionList *dlist =
new TDEABC::DistributionList( &manager, name );
934 TDEABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView,
false );
935 for ( TDEABC::Addressee::List::iterator itr = addrl.begin();
936 itr != addrl.end(); ++itr ) {
937 dlist->insertEntry( *itr );
945 AddressesDialog::searchLdap()
947 if ( !d->ldapSearchDialog ) {
948 d->ldapSearchDialog =
new LDAPSearchDialog(
this );
949 connect( d->ldapSearchDialog, TQ_SIGNAL( addresseesAdded() ),
950 TQ_SLOT(ldapSearchResult() ) );
952 d->ldapSearchDialog->show();
956 AddressesDialog::ldapSearchResult()
958 TQStringList emails = KPIM::splitEmailAddrList( d->ldapSearchDialog->selectedEMails() );
959 TQStringList::iterator it( emails.begin() );
960 TQStringList::iterator end( emails.end() );
961 for ( ; it != end; ++it ){
964 KPIM::getNameAndMail( (*it), name, email );
965 TDEABC::Addressee ad;
966 ad.setNameFromString( name );
967 ad.insertEmail( email );
968 addAddresseeToSelected( ad, selectedToItem() );
973 AddressesDialog::launchAddressBook()
975 kapp->startServiceByDesktopName(
"kaddressbook", TQString() );
979 AddressesDialog::filterChanged(
const TQString& txt )
981 TQListViewItemIterator it( d->ui->mAvailableView );
982 bool showAll =
false;
987 int personalVisible = 0;
988 int recentVisible = 0;
989 while ( it.current() ) {
990 AddresseeViewItem* item =
static_cast<AddresseeViewItem*
>( it.current() );
994 item->setOpen(
true );
995 item->setVisible(
true );
1002 if ( item->category() == AddresseeViewItem::Entry ) {
1003 bool matches = item->matches( txt );
1004 item->setVisible( matches );
1005 TQListViewItem *parent =
static_cast<TQListViewItem*
>( item )->parent();
1006 if ( matches && parent ) {
1007 if ( parent == d->personal ) {
1009 }
else if ( parent == d->recent ) {
1014 if ( item->category() == AddresseeViewItem::Group ) {
1015 item->setOpen(
true );
1016 item->setVisible(
true );
1020 if ( !showAll && personalVisible == 0 ) {
1021 d->personal->setOpen(
false );
1022 d->personal->setVisible(
false );
1024 if ( !showAll && recentVisible == 0 ) {
1025 d->recent->setOpen(
false );
1026 d->recent->setVisible(
false );
1029 int distlistgroupVisible = 0;
1031 TQPtrListIterator<AddresseeViewItem> it( d->dists );
1032 for ( ; it.current(); ++it ) {
1033 TQListViewItem *p = *it;
1034 p->setVisible(
true );
1035 AddresseeViewItem *p2 =
static_cast<AddresseeViewItem*
>( p->firstChild() );
1038 if ( p2->matches( txt ) ) {
1039 p2->setVisible(
true );
1042 p2->setVisible(
false );
1044 p2 =
static_cast<AddresseeViewItem*
>( p2->nextSibling() );
1046 if ( !pcount && !p->text( 0 ).contains( txt,
false ) ) {
1047 p->setVisible(
false );
1049 distlistgroupVisible += pcount;
1050 if ( p->text( 0 ).contains( txt,
false ) ) {
1051 distlistgroupVisible++;
1056 if ( showAll || distlistgroupVisible > 0 ) {
1057 d->topdist->setOpen(
true );
1059 d->topdist->setOpen(
false );
1060 d->topdist->setVisible(
false );
1065 TDEABC::Addressee::List
1066 AddressesDialog::allAddressee( TDEListView* view,
bool onlySelected )
const
1068 TDEABC::Addressee::List lst;
1069 TQListViewItemIterator it( view );
1070 while ( it.current() ) {
1071 AddresseeViewItem* item =
static_cast<AddresseeViewItem*
>( it.current() );
1072 if ( !onlySelected || item->isSelected() ) {
1073 if ( item->category() != AddresseeViewItem::Entry ) {
1074 AddresseeViewItem *myChild =
static_cast<AddresseeViewItem*
>( item->firstChild() );
1076 lst.append( myChild->addressee() );
1077 myChild =
static_cast<AddresseeViewItem*
>( myChild->nextSibling() );
1080 lst.append( item->addressee() );
1089 TDEABC::Addressee::List
1090 AddressesDialog::allAddressee( AddresseeViewItem* parent )
const
1092 TDEABC::Addressee::List lst;
1094 if ( !parent )
return lst;
1096 if ( parent->category() == AddresseeViewItem::Entry )
1098 lst.append( parent->addressee() );
1102 AddresseeViewItem *myChild =
static_cast<AddresseeViewItem*
>( parent->firstChild() );
1104 if ( myChild->category() == AddresseeViewItem::FilledGroup )
1105 lst += myChild->addresses();
1106 else if ( !myChild->addressee().isEmpty() )
1107 lst.append( myChild->addressee() );
1108 myChild =
static_cast<AddresseeViewItem*
>( myChild->nextSibling() );
1115 AddressesDialog::allDistributionLists( AddresseeViewItem* parent )
const
1120 return TQStringList();
1122 AddresseeViewItem *item =
static_cast<AddresseeViewItem*
>( parent->firstChild() );
1124 if ( item->category() == AddresseeViewItem::DistList && !item->name().isEmpty() )
1125 lists.append( item->name() );
1127 item =
static_cast<AddresseeViewItem*
>( item->nextSibling() );
1134 AddressesDialog::addDistributionLists()
1136 TDEABC::AddressBook* abook = TDEABC::StdAddressBook::self(
true );
1138 #ifdef TDEPIM_NEW_DISTRLISTS
1139 const TQValueList<KPIM::DistributionList> distLists =
1140 KPIM::DistributionList::allDistributionLists( abook );
1142 TDEABC::DistributionListManager manager( abook );
1145 TQStringList distLists = manager.listNames();
1148 if ( distLists.isEmpty() )
1151 if ( !d->topdist ) {
1152 d->topdist =
new AddresseeViewItem( d->ui->mAvailableView, i18n(
"Distribution Lists" ) );
1155 #ifdef TDEPIM_NEW_DISTRLISTS
1156 TQValueList<KPIM::DistributionList>::ConstIterator listIt;
1158 TQStringList::Iterator listIt;
1161 for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) {
1162 #ifdef TDEPIM_NEW_DISTRLISTS
1164 KPIM::DistributionList::Entry::List entries = dlist.
entries(abook);
1166 TDEABC::DistributionList& dlist = *manager.list( *listIt );
1167 TDEABC::DistributionList::Entry::List entries = dlist.
entries();
1170 AddresseeViewItem *item =
new AddresseeViewItem( d->topdist, dlist.name() );
1171 d->dists.append( item );
1172 connect( item, TQ_SIGNAL( addressSelected( AddresseeViewItem*,
bool ) ),
1173 this, TQ_SLOT( availableAddressSelected( AddresseeViewItem*,
bool ) ) );
1175 #ifdef TDEPIM_NEW_DISTRLISTS
1176 KPIM::DistributionList::Entry::List::Iterator itemIt;
1178 TDEABC::DistributionList::Entry::List::Iterator itemIt;
1180 for ( itemIt = entries.begin(); itemIt != entries.end(); ++itemIt ) {
1181 addAddresseeToAvailable( (*itemIt).addressee, item,
false );
1183 if ( item->childCount() > 0 ) {
1184 item->setOpen(
true );
1185 item->setVisible(
true );
1187 total += item->childCount();
1190 d->topdist->setOpen(
true );
1191 d->topdist->setVisible(
true );
1197 #include "addressesdialog.moc"
Distribution list of email addresses.
void insertEntry(const Addressee &, const TQString &email=TQString())
Insert an entry into this distribution list.
void setName(const TQString &name)
HACK: reimplemented from Addressee, but it's NOT virtual there.
Entry::List entries(TDEABC::AddressBook *book) const
Return list of entries belonging to this distribution list.
TDEPIM classes for drag and drop of mails.