23 #include "distributionlistngwidget.h"
24 #include "interfaces/core.h"
25 #include "searchmanager.h"
27 #include <libtdepim/distributionlist.h>
28 #include <libtdepim/kvcarddrag.h>
30 #include <tdeabc/vcardconverter.h>
33 #include <kiconloader.h>
34 #include <tdelistview.h>
35 #include <tdelocale.h>
36 #include <tdepopupmenu.h>
39 #include <tqguardedptr.h>
44 #include <tqpushbutton.h>
45 #include <tqtooltip.h>
47 KAB::DistributionListNg::ListBox::ListBox( TQWidget* parent ) : TDEListBox( parent )
49 setAcceptDrops(
true );
52 void KAB::DistributionListNg::ListBox::dragMoveEvent( TQDragMoveEvent *event )
54 TQListBoxItem *item = itemAt( event->pos() );
59 event->accept( itemRect( item ) );
63 void KAB::DistributionListNg::ListBox::dragEnterEvent( TQDragEnterEvent *event )
65 TDEListBox::dragEnterEvent( event );
68 void KAB::DistributionListNg::ListBox::dropEvent( TQDropEvent *event )
70 TQListBoxItem *item = itemAt( event->pos() );
71 if ( !item || index( item ) == 0 )
74 TDEABC::Addressee::List list;
75 if ( !KVCardDrag::decode( event, list ) )
78 emit dropped( item->text(), list );
82 namespace DistributionListNg {
84 class Factory :
public KAB::ExtensionFactory
87 KAB::ExtensionWidget *extension( KAB::Core *core, TQWidget *parent,
const char *name )
89 return new KAB::DistributionListNg::MainWidget( core, parent, name );
92 TQString identifier()
const
94 return "distribution_list_editor";
102 void *init_libkaddrbk_distributionlistng()
104 return (
new KAB::DistributionListNg::Factory );
108 TQString KAB::DistributionListNg::MainWidget::title()
const
110 return i18n(
"Distribution List Editor NG" );
113 TQString KAB::DistributionListNg::MainWidget::identifier()
const
115 return "distribution_list_editor_ng";
118 KAB::DistributionListNg::MainWidget::MainWidget( KAB::Core *core, TQWidget *parent,
const char *name ) : KAB::ExtensionWidget( core, parent, name )
120 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
121 layout->setSpacing( KDialog::spacingHint() );
123 TQHBoxLayout *buttonLayout =
new TQHBoxLayout();
124 layout->addLayout( buttonLayout );
126 TQLabel *label =
new TQLabel(
this );
127 label->setText( i18n(
"Distribution Lists" ) );
128 buttonLayout->addWidget( label );
129 buttonLayout->addStretch( 1 );
131 mAddButton =
new TQPushButton(
this );
132 mAddButton->setIconSet( SmallIconSet(
"add" ) );
133 TQToolTip::add( mAddButton, i18n(
"Add distribution list" ) );
134 connect( mAddButton, TQ_SIGNAL(clicked()), core, TQ_SLOT(newDistributionList()) );
135 buttonLayout->addWidget( mAddButton );
137 mEditButton =
new TQPushButton(
this );
138 mEditButton->setIconSet( SmallIconSet(
"edit" ) );
139 TQToolTip::add( mEditButton, i18n(
"Edit distribution list" ) );
140 connect( mEditButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(editSelectedDistributionList()) );
141 buttonLayout->addWidget( mEditButton );
143 mRemoveButton =
new TQPushButton(
this );
144 mRemoveButton->setIconSet( SmallIconSet(
"remove" ) );
145 TQToolTip::add( mRemoveButton, i18n(
"Remove distribution list" ) );
146 connect( mRemoveButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(deleteSelectedDistributionList()) );
147 buttonLayout->addWidget( mRemoveButton );
149 mListBox =
new ListBox(
this );
150 connect( mListBox, TQ_SIGNAL( contextMenuRequested( TQListBoxItem*,
const TQPoint& ) ),
151 this, TQ_SLOT( contextMenuRequested( TQListBoxItem*,
const TQPoint& ) ) );
152 connect( mListBox, TQ_SIGNAL( dropped(
const TQString &,
const TDEABC::Addressee::List & ) ),
153 this, TQ_SLOT( contactsDropped(
const TQString &,
const TDEABC::Addressee::List & ) ) );
154 connect( mListBox, TQ_SIGNAL( highlighted(
int ) ),
155 this, TQ_SLOT( itemSelected(
int ) ) );
156 connect( mListBox, TQ_SIGNAL(doubleClicked(TQListBoxItem*)), TQ_SLOT(editSelectedDistributionList()) );
157 layout->addWidget( mListBox );
159 connect( core, TQ_SIGNAL( contactsUpdated() ),
160 this, TQ_SLOT( updateEntries() ) );
161 connect( core->addressBook(), TQ_SIGNAL( addressBookChanged( AddressBook* ) ),
162 this, TQ_SLOT( updateEntries() ) );
165 connect( core, TQ_SIGNAL( contactsUpdated() ),
166 this, TQ_SLOT( updateEntries() ) );
168 TQTimer::singleShot( 0,
this, TQ_SLOT( updateEntries() ) );
171 void KAB::DistributionListNg::MainWidget::contextMenuRequested( TQListBoxItem *item,
const TQPoint &point )
173 TQGuardedPtr<TDEPopupMenu> menu =
new TDEPopupMenu(
this );
174 menu->insertItem( i18n(
"New Distribution List..." ), core(), TQ_SLOT( newDistributionList() ) );
175 if ( item && ( item->text() !=i18n(
"All Contacts" ) ) )
177 menu->insertItem( i18n(
"Edit..." ),
this, TQ_SLOT( editSelectedDistributionList() ) );
178 menu->insertItem( i18n(
"Delete" ),
this, TQ_SLOT( deleteSelectedDistributionList() ) );
184 void KAB::DistributionListNg::MainWidget::editSelectedDistributionList()
186 const TQListBoxItem*
const item = mListBox->selectedItem();
189 core()->editDistributionList( item->text() );
192 void KAB::DistributionListNg::MainWidget::deleteSelectedDistributionList()
194 const TQListBoxItem*
const item = mListBox->selectedItem();
195 const TQString name = item ? item->text() : TQString();
198 const KPIM::DistributionList list = KPIM::DistributionList::findByName(
199 core()->addressBook(), name );
200 if ( list.isEmpty() )
202 core()->deleteDistributionLists( name );
205 void KAB::DistributionListNg::MainWidget::contactsDropped(
const TQString &listName,
const TDEABC::Addressee::List &addressees )
207 if ( addressees.isEmpty() )
210 KPIM::DistributionList list = KPIM::DistributionList::findByName(
211 core()->addressBook(), listName );
212 if ( list.isEmpty() )
215 for ( TDEABC::Addressee::List::ConstIterator it = addressees.begin(); it != addressees.end(); ++it ) {
216 list.insertEntry( *it );
219 core()->addressBook()->insertAddressee( list );
223 void KAB::DistributionListNg::MainWidget::changed(
const TDEABC::Addressee& dist )
225 emit modified( TDEABC::Addressee::List() << dist );
228 void KAB::DistributionListNg::MainWidget::updateEntries()
230 const bool hadSelection = mListBox->selectedItem() != 0;
231 const TQStringList newEntries = core()->distributionListNames();
232 if ( !mCurrentEntries.isEmpty() && newEntries == mCurrentEntries )
234 mCurrentEntries = newEntries;
236 mListBox->insertItem( i18n(
"All Contacts" ), 0 );
237 mListBox->insertStringList( mCurrentEntries );
239 mListBox->setSelected( 0,
true );
242 void KAB::DistributionListNg::MainWidget::itemSelected(
int index )
244 core()->setSelectedDistributionList( index == 0 ? TQString() : mListBox->item( index )->text() );
245 mEditButton->setEnabled( index > 0 );
246 mRemoveButton->setEnabled( index > 0 );
249 #include "distributionlistngwidget.moc"