23 #include <tqstringlist.h>
24 #include <tqlineedit.h>
25 #include <tqlistview.h>
28 #include <tqpushbutton.h>
29 #include <tdelocale.h>
31 #include "kpimprefs.h"
33 #include "categoryeditdialog.h"
37 class CategoryEditDialog::Private
41 TQPushButton *mAddButton;
42 TQPushButton *mEditButton;
43 TQPushButton *mDeleteButton;
46 class CategoryListViewItem :
public TQListViewItem
49 CategoryListViewItem( TQListView *view,
const TQString &text ) :
50 TQListViewItem( view, text )
54 void okRename (
int col )
56 TQListViewItem::okRename( col );
60 CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, TQWidget* parent,
61 const char* name,
bool modal )
62 : KDialogBase::KDialogBase( parent, name, modal,
63 i18n(
"Edit Categories"), Ok|Apply|Cancel|Help, Ok, true ),
64 mPrefs( prefs ), d( new Private )
66 TQWidget *widget =
new TQWidget(
this );
67 setMainWidget( widget );
69 TQGridLayout *layout =
new TQGridLayout( widget, 4, 2, marginHint(), spacingHint() );
71 d->mView =
new TQListView( widget );
72 d->mView->addColumn(
"" );
73 d->mView->header()->hide();
74 d->mView->setDefaultRenameAction( TQListView::Accept );
76 layout->addMultiCellWidget( d->mView, 0, 3, 0, 0 );
78 d->mAddButton =
new TQPushButton( i18n(
"Add" ), widget );
79 layout->addWidget( d->mAddButton, 0, 1 );
81 d->mEditButton =
new TQPushButton( i18n(
"Edit" ), widget );
82 layout->addWidget( d->mEditButton, 1, 1 );
84 d->mDeleteButton =
new TQPushButton( i18n(
"Remove" ), widget );
85 layout->addWidget( d->mDeleteButton, 2, 1 );
90 connect( d->mAddButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( add() ) );
91 connect( d->mEditButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( edit() ) );
92 connect( d->mDeleteButton, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( remove() ) );
98 CategoryEditDialog::~CategoryEditDialog()
103 void CategoryEditDialog::fillList()
106 TQStringList::Iterator it;
107 bool categoriesExist=
false;
108 for ( it = mPrefs->mCustomCategories.begin();
109 it != mPrefs->mCustomCategories.end(); ++it ) {
111 TQListViewItem *item =
new CategoryListViewItem( d->mView, *it );
112 item->setRenameEnabled( 0,
true );
114 categoriesExist =
true;
117 d->mEditButton->setEnabled( categoriesExist );
118 d->mDeleteButton->setEnabled( categoriesExist );
119 d->mView->setSelected( d->mView->firstChild(),
true );
122 void CategoryEditDialog::add()
124 if ( d->mView->firstChild() )
125 d->mView->setCurrentItem( d->mView->firstChild() );
127 TQListViewItem *item =
new CategoryListViewItem( d->mView, i18n(
"New category" ) );
128 item->setRenameEnabled( 0,
true );
130 d->mView->setSelected( item,
true );
131 d->mView->ensureItemVisible( item );
132 item->startRename( 0 );
134 bool itemCount = d->mView->childCount() > 0;
135 d->mEditButton->setEnabled( itemCount );
136 d->mDeleteButton->setEnabled( itemCount );
139 void CategoryEditDialog::edit()
141 if ( d->mView->currentItem() )
142 d->mView->currentItem()->startRename( 0 );
145 void CategoryEditDialog::remove()
147 if ( d->mView->currentItem() ) {
148 delete d->mView->currentItem();
150 d->mView->setSelected( d->mView->currentItem(),
true );
152 bool itemCount = d->mView->childCount() > 0;
153 d->mEditButton->setEnabled( itemCount );
154 d->mDeleteButton->setEnabled( itemCount );
158 void CategoryEditDialog::slotOk()
161 if ( d->mView->selectedItem() )
162 static_cast<CategoryListViewItem*
>( d->mView->selectedItem() )->okRename( 0 );
167 void CategoryEditDialog::slotApply()
169 mPrefs->mCustomCategories.clear();
171 TQListViewItem *item = d->mView->firstChild();
173 if ( !item->text( 0 ).isEmpty() )
174 mPrefs->mCustomCategories.append( item->text( 0 ) );
175 item = item->nextSibling();
177 mPrefs->writeConfig();
179 emit categoryConfigChanged();
182 void CategoryEditDialog::slotCancel()
185 KDialogBase::slotCancel();
188 void CategoryEditDialog::reload()
193 #include "categoryeditdialog.moc"
TDEPIM classes for drag and drop of mails.