32 #include "completionordereditor.h"
33 #include "ldapclient.h"
34 #include "resourceabc.h"
36 #include <tdeabc/stdaddressbook.h>
37 #include <tdeabc/resource.h>
40 #include <tdelocale.h>
41 #include <kiconloader.h>
42 #include <tdelistview.h>
43 #include <kpushbutton.h>
48 #include <tqtoolbutton.h>
49 #include <tdeapplication.h>
50 #include <dcopclient.h>
79 int CompletionItemList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
81 int w1 = ( (CompletionItem*)s1 )->completionWeight();
82 int w2 = ( (CompletionItem*)s2 )->completionWeight();
87 class LDAPCompletionItem :
public CompletionItem
90 LDAPCompletionItem(
LdapClient* ldapClient ) : mLdapClient( ldapClient ) {}
91 virtual TQString label()
const {
return i18n(
"LDAP server %1" ).arg( mLdapClient->server().host() ); }
92 virtual int completionWeight()
const {
return mLdapClient->completionWeight(); }
93 virtual void save( CompletionOrderEditor* );
95 virtual void setCompletionWeight(
int weight ) { mWeight = weight; }
101 void LDAPCompletionItem::save( CompletionOrderEditor* )
103 TDEConfig * config = LdapSearch::config();
104 config->setGroup(
"LDAP" );
105 config->writeEntry( TQString(
"SelectedCompletionWeight%1" ).arg( mLdapClient->clientNumber() ),
111 class SimpleCompletionItem :
public CompletionItem
114 SimpleCompletionItem( CompletionOrderEditor* editor,
const TQString& label,
const TQString& identifier,
int weight )
115 : mLabel( label ), mIdentifier( identifier ) {
116 TDEConfigGroup group( editor->configFile(),
"CompletionWeights" );
117 mWeight = group.readNumEntry( mIdentifier, weight );
119 virtual TQString label()
const {
return mLabel; }
120 virtual int completionWeight()
const {
return mWeight; }
121 virtual void save( CompletionOrderEditor* );
123 virtual void setCompletionWeight(
int weight ) { mWeight = weight; }
125 TQString mLabel, mIdentifier;
129 void SimpleCompletionItem::save( CompletionOrderEditor* editor )
133 TDEConfigGroup group( editor->configFile(),
"CompletionWeights" );
134 group.writeEntry( mIdentifier, mWeight );
138 class KABCImapSubResCompletionItem :
public CompletionItem
141 KABCImapSubResCompletionItem(
ResourceABC* resource,
const TQString& subResource )
142 : mResource( resource ), mSubResource( subResource ), mWeight( completionWeight() ) {}
143 virtual TQString label()
const {
144 return TQString(
"%1 %2" ).arg( mResource->resourceName() ).arg( mResource->subresourceLabel( mSubResource ) );
146 virtual int completionWeight()
const {
147 return mResource->subresourceCompletionWeight( mSubResource );
149 virtual void setCompletionWeight(
int weight ) {
152 virtual void save( CompletionOrderEditor* ) {
153 mResource->setSubresourceCompletionWeight( mSubResource, mWeight );
157 TQString mSubResource;
163 class CompletionViewItem :
public TQListViewItem
166 CompletionViewItem( TQListView* lv, CompletionItem* item )
167 : TQListViewItem( lv, lv->lastItem(), item->label() ), mItem( item ) {}
168 CompletionItem* item()
const {
return mItem; }
169 void setItem( CompletionItem* i ) { mItem = i; setText( 0, mItem->label() ); }
172 CompletionItem* mItem;
176 TQWidget* parent,
const char* name )
177 : KDialogBase( parent, name, true, i18n(
"Edit Completion Order"), Ok|Cancel, Ok, true ),
178 mConfig(
"kpimcompletionorder" ), mDirty( false )
180 mItems.setAutoDelete(
true );
182 TQValueList< LdapClient* > ldapClients = ldapSearch->clients();
183 for( TQValueList<LdapClient*>::const_iterator it = ldapClients.begin(); it != ldapClients.end(); ++it ) {
185 mItems.append(
new LDAPCompletionItem( *it ) );
187 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
188 TQPtrList<TDEABC::Resource> resources = addressBook->resources();
189 for( TQPtrListIterator<TDEABC::Resource> resit( resources ); *resit; ++resit ) {
194 for( TQStringList::const_iterator it = subresources.begin(); it != subresources.end(); ++it ) {
195 mItems.append(
new KABCImapSubResCompletionItem( res, *it ) );
198 mItems.append(
new SimpleCompletionItem(
this, (*resit)->resourceName(),
199 (*resit)->identifier(), 60 ) );
203 #ifndef TDEPIM_NEW_DISTRLISTS
205 mItems.append(
new SimpleCompletionItem(
this, i18n(
"Distribution Lists" ),
"DistributionLists" ), 60 );
208 mItems.append(
new SimpleCompletionItem(
this, i18n(
"Recent Addresses" ),
"Recent Addresses", 10 ) );
213 TQHBox* page = makeHBoxMainWidget();
214 mListView =
new TDEListView( page );
215 mListView->setSorting( -1 );
216 mListView->addColumn( TQString() );
217 mListView->header()->hide();
219 for( TQPtrListIterator<CompletionItem> compit( mItems ); *compit; ++compit ) {
220 new CompletionViewItem( mListView, *compit );
221 kdDebug(5300) <<
" " << (*compit)->label() <<
" " << (*compit)->completionWeight() << endl;
224 TQVBox* upDownBox =
new TQVBox( page );
225 mUpButton =
new KPushButton( upDownBox,
"mUpButton" );
226 mUpButton->setIconSet( BarIconSet(
"go-up", TDEIcon::SizeSmall ) );
227 mUpButton->setEnabled(
false );
228 mUpButton->setFocusPolicy( TQWidget::StrongFocus );
230 mDownButton =
new KPushButton( upDownBox,
"mDownButton" );
231 mDownButton->setIconSet( BarIconSet(
"go-down", TDEIcon::SizeSmall ) );
232 mDownButton->setEnabled(
false );
233 mDownButton->setFocusPolicy( TQWidget::StrongFocus );
235 TQWidget* spacer =
new TQWidget( upDownBox );
236 upDownBox->setStretchFactor( spacer, 100 );
238 connect( mListView, TQ_SIGNAL( selectionChanged( TQListViewItem* ) ),
239 TQ_SLOT( slotSelectionChanged( TQListViewItem* ) ) );
240 connect( mUpButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotMoveUp() ) );
241 connect( mDownButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotMoveDown() ) );
244 CompletionOrderEditor::~CompletionOrderEditor()
248 void CompletionOrderEditor::slotSelectionChanged( TQListViewItem *item )
250 mDownButton->setEnabled( item && item->itemBelow() );
251 mUpButton->setEnabled( item && item->itemAbove() );
254 static void swapItems( CompletionViewItem *one, CompletionViewItem *other )
256 CompletionItem* i = one->item();
257 one->setItem( other->item() );
261 void CompletionOrderEditor::slotMoveUp()
263 CompletionViewItem *item =
static_cast<CompletionViewItem *
>( mListView->selectedItem() );
265 CompletionViewItem *above =
static_cast<CompletionViewItem *
>( item->itemAbove() );
266 if ( !above )
return;
267 swapItems( item, above );
268 mListView->setCurrentItem( above );
269 mListView->setSelected( above,
true );
273 void CompletionOrderEditor::slotMoveDown()
275 CompletionViewItem *item =
static_cast<CompletionViewItem *
>( mListView->selectedItem() );
277 CompletionViewItem *below =
static_cast<CompletionViewItem *
>( item->itemBelow() );
278 if ( !below )
return;
279 swapItems( item, below );
280 mListView->setCurrentItem( below );
281 mListView->setSelected( below,
true );
285 void CompletionOrderEditor::slotOk()
289 for ( TQListViewItem* it = mListView->firstChild(); it; it = it->nextSibling() ) {
290 CompletionViewItem *item =
static_cast<CompletionViewItem *
>( it );
291 item->item()->setCompletionWeight( w );
292 item->item()->save(
this );
293 kdDebug(5300) <<
"slotOk: " << item->item()->label() <<
" " << w << endl;
300 kapp->dcopClient()->emitDCOPSignal(
"KPIM::IMAPCompletionOrder",
"orderChanged()", TQByteArray() );
302 KDialogBase::slotOk();
307 #include "completionordereditor.moc"
This class is the implementation of subfolder resources for KABC.
virtual TQStringList subresources() const
If this resource has subresources, return a TQStringList of them.
TDEPIM classes for drag and drop of mails.