25 #include <tdeabc/addressbook.h>
26 #include <tdeapplication.h>
27 #include <kcombobox.h>
28 #include <tdelocale.h>
30 #include <tqbuttongroup.h>
31 #include <tqcombobox.h>
35 #include <tqlistview.h>
36 #include <tqpushbutton.h>
37 #include <tqradiobutton.h>
38 #include <tqstringlist.h>
39 #include <tqwhatsthis.h>
44 #include "xxportselectdialog.h"
46 XXPortSelectDialog::XXPortSelectDialog( KAB::Core *core,
bool sort,
47 TQWidget* parent,
const char* name )
48 : KDialogBase( Plain, i18n(
"Choose Which Contacts to Export" ), Help | Ok | Cancel,
49 Ok, parent, name, true, true ), mCore( core ),
54 connect( mFiltersCombo, TQ_SIGNAL( activated(
int ) ),
55 TQ_SLOT( filterChanged(
int ) ) );
56 connect( mCategoriesView, TQ_SIGNAL( clicked( TQListViewItem* ) ),
57 TQ_SLOT( categoryClicked( TQListViewItem* ) ) );
61 Filter::List::ConstIterator filterIt;
63 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
64 filters.append( (*filterIt).name() );
66 mFiltersCombo->insertStringList( filters );
67 mUseFilters->setEnabled( filters.count() > 0 );
70 const TQStringList categories = KABPrefs::instance()->customCategories();
71 TQStringList::ConstIterator it;
72 for ( it = categories.begin(); it != categories.end(); ++it )
73 new TQCheckListItem( mCategoriesView, *it, TQCheckListItem::CheckBox );
74 mUseCategories->setEnabled( categories.count() > 0 );
76 int count = mCore->selectedUIDs().count();
77 mUseSelection->setEnabled( count != 0 );
78 mUseSelection->setChecked( count > 0 );
80 mSortTypeCombo->insertItem( i18n(
"Ascending" ) );
81 mSortTypeCombo->insertItem( i18n(
"Descending" ) );
83 mFields = mCore->addressBook()->fields( TDEABC::Field::All );
84 TDEABC::Field::List::ConstIterator fieldIt;
85 for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt )
86 mFieldCombo->insertItem( (*fieldIt)->label() );
89 TDEABC::AddresseeList XXPortSelectDialog::contacts()
91 const TQStringList selection = mCore->selectedUIDs();
93 TDEABC::AddresseeList list;
94 if ( mUseSelection->isChecked() ) {
95 TQStringList::ConstIterator it;
96 for ( it = selection.begin(); it != selection.end(); ++it ) {
97 TDEABC::Addressee addr = mCore->addressBook()->findByUid( *it );
98 if ( !addr.isEmpty() )
101 }
else if ( mUseFilters->isChecked() ) {
103 Filter::List::ConstIterator filterIt;
104 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
105 if ( (*filterIt).name() == mFiltersCombo->currentText() )
108 TDEABC::AddressBook::Iterator it;
109 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
110 if ( (*filterIt).filterAddressee( *it ) )
113 }
else if ( mUseCategories->isChecked() ) {
114 const TQStringList categorieList = categories();
116 TDEABC::AddressBook::ConstIterator it;
117 TDEABC::AddressBook::ConstIterator addressBookEnd( mCore->addressBook()->end() );
118 for ( it = mCore->addressBook()->begin(); it != addressBookEnd; ++it ) {
119 const TQStringList tmp( (*it).categories() );
120 TQStringList::ConstIterator tmpIt;
121 for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
122 if ( categorieList.contains( *tmpIt ) ) {
129 TDEABC::AddressBook::ConstIterator it;
130 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it )
135 list.setReverseSorting( mSortTypeCombo->currentItem() == 1 );
136 uint pos = mFieldCombo->currentItem();
137 if ( pos < mFields.count() )
138 list.sortByField( mFields[ pos ] );
144 TQStringList XXPortSelectDialog::categories()
const
148 TQListViewItemIterator it( mCategoriesView );
149 for ( ; it.current(); ++it ) {
150 TQCheckListItem* qcli =
static_cast<TQCheckListItem*
>(it.current());
152 list.append( it.current()->text( 0 ) );
158 void XXPortSelectDialog::filterChanged(
int )
160 mUseFilters->setChecked(
true );
163 void XXPortSelectDialog::categoryClicked( TQListViewItem *i )
168 TQCheckListItem *qcli =
static_cast<TQCheckListItem*
>( i );
170 mUseCategories->setChecked(
true );
173 void XXPortSelectDialog::slotHelp()
175 kapp->invokeHelp(
"import-and-export" );
178 void XXPortSelectDialog::initGUI()
180 TQFrame *page = plainPage();
182 TQVBoxLayout *topLayout =
new TQVBoxLayout( page, KDialog::marginHint(),
183 KDialog::spacingHint() );
185 TQLabel *label =
new TQLabel( i18n(
"Which contacts do you want to export?" ), page );
186 topLayout->addWidget( label );
188 mButtonGroup =
new TQButtonGroup( i18n(
"Selection" ), page );
189 mButtonGroup->setColumnLayout( 0, TQt::Vertical );
190 mButtonGroup->layout()->setSpacing( KDialog::spacingHint() );
191 mButtonGroup->layout()->setMargin( KDialog::marginHint() );
193 TQGridLayout *groupLayout =
new TQGridLayout( mButtonGroup->layout() );
194 groupLayout->setAlignment( TQt::AlignTop );
196 mUseWholeBook =
new TQRadioButton( i18n(
"&All contacts" ), mButtonGroup );
197 mUseWholeBook->setChecked(
true );
198 TQWhatsThis::add( mUseWholeBook, i18n(
"Export the entire address book" ) );
199 groupLayout->addWidget( mUseWholeBook, 0, 0 );
200 mUseSelection =
new TQRadioButton( i18n(
"&Selected contact",
"&Selected contacts (%n selected)", mCore->selectedUIDs().count() ), mButtonGroup );
201 TQWhatsThis::add( mUseSelection, i18n(
"Only export contacts selected in KAddressBook.\n"
202 "This option is disabled if no contacts are selected." ) );
203 groupLayout->addWidget( mUseSelection, 1, 0 );
205 mUseFilters =
new TQRadioButton( i18n(
"Contacts matching &filter" ), mButtonGroup );
206 TQWhatsThis::add( mUseFilters, i18n(
"Only export contacts matching the selected filter.\n"
207 "This option is disabled if you have not defined any filters" ) );
208 groupLayout->addWidget( mUseFilters, 2, 0 );
210 mUseCategories =
new TQRadioButton( i18n(
"Category &members" ), mButtonGroup );
211 TQWhatsThis::add( mUseCategories, i18n(
"Only export contacts who are members of a category that is checked on the list to the left.\n"
212 "This option is disabled if you have no categories." ) );
213 groupLayout->addWidget( mUseCategories, 3, 0, TQt::AlignTop );
215 mFiltersCombo =
new TQComboBox(
false, mButtonGroup );
216 TQWhatsThis::add( mFiltersCombo, i18n(
"Select a filter to decide which contacts to export." ) );
217 groupLayout->addWidget( mFiltersCombo, 2, 1 );
219 mCategoriesView =
new TQListView( mButtonGroup );
220 mCategoriesView->addColumn(
"" );
221 mCategoriesView->header()->hide();
222 TQWhatsThis::add( mCategoriesView, i18n(
"Check the categories whose members you want to export." ) );
223 groupLayout->addWidget( mCategoriesView, 3, 1 );
225 topLayout->addWidget( mButtonGroup );
227 TQButtonGroup *sortingGroup =
new TQButtonGroup( i18n(
"Sorting" ), page );
228 sortingGroup->setColumnLayout( 0, TQt::Vertical );
229 TQGridLayout *sortLayout =
new TQGridLayout( sortingGroup->layout(), 2, 2,
230 KDialog::spacingHint() );
231 sortLayout->setAlignment( TQt::AlignTop );
233 label =
new TQLabel( i18n(
"Criterion:" ), sortingGroup );
234 sortLayout->addWidget( label, 0, 0 );
236 mFieldCombo =
new KComboBox(
false, sortingGroup );
237 sortLayout->addWidget( mFieldCombo, 0, 1 );
239 label =
new TQLabel( i18n(
"Order:" ), sortingGroup );
240 sortLayout->addWidget( label, 1, 0 );
242 mSortTypeCombo =
new KComboBox(
false, sortingGroup );
243 sortLayout->addWidget( mSortTypeCombo, 1, 1 );
245 topLayout->addWidget( sortingGroup );
248 sortingGroup->hide();
251 #include "xxportselectdialog.moc"
void restore(TDEConfig *config)
Loads the filter from the config file.