00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <kabc/addressbook.h>
00026 #include <kapplication.h>
00027 #include <kcombobox.h>
00028 #include <klocale.h>
00029
00030 #include <tqbuttongroup.h>
00031 #include <tqcombobox.h>
00032 #include <tqheader.h>
00033 #include <tqlabel.h>
00034 #include <tqlayout.h>
00035 #include <tqlistview.h>
00036 #include <tqpushbutton.h>
00037 #include <tqradiobutton.h>
00038 #include <tqstringlist.h>
00039 #include <tqwhatsthis.h>
00040
00041 #include "core.h"
00042 #include "kabprefs.h"
00043
00044 #include "xxportselectdialog.h"
00045
00046 XXPortSelectDialog::XXPortSelectDialog( KAB::Core *core, bool sort,
00047 TQWidget* parent, const char* name )
00048 : KDialogBase( Plain, i18n( "Choose Which Contacts to Export" ), Help | Ok | Cancel,
00049 Ok, parent, name, true, true ), mCore( core ),
00050 mUseSorting( sort )
00051 {
00052 initGUI();
00053
00054 connect( mFiltersCombo, TQT_SIGNAL( activated( int ) ),
00055 TQT_SLOT( filterChanged( int ) ) );
00056 connect( mCategoriesView, TQT_SIGNAL( clicked( TQListViewItem* ) ),
00057 TQT_SLOT( categoryClicked( TQListViewItem* ) ) );
00058
00059
00060 mFilters = Filter::restore( kapp->config(), "Filter" );
00061 Filter::List::ConstIterator filterIt;
00062 TQStringList filters;
00063 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
00064 filters.append( (*filterIt).name() );
00065
00066 mFiltersCombo->insertStringList( filters );
00067 mUseFilters->setEnabled( filters.count() > 0 );
00068
00069
00070 const TQStringList categories = KABPrefs::instance()->customCategories();
00071 TQStringList::ConstIterator it;
00072 for ( it = categories.begin(); it != categories.end(); ++it )
00073 new TQCheckListItem( mCategoriesView, *it, TQCheckListItem::CheckBox );
00074 mUseCategories->setEnabled( categories.count() > 0 );
00075
00076 int count = mCore->selectedUIDs().count();
00077 mUseSelection->setEnabled( count != 0 );
00078 mUseSelection->setChecked( count > 0 );
00079
00080 mSortTypeCombo->insertItem( i18n( "Ascending" ) );
00081 mSortTypeCombo->insertItem( i18n( "Descending" ) );
00082
00083 mFields = mCore->addressBook()->fields( KABC::Field::All );
00084 KABC::Field::List::ConstIterator fieldIt;
00085 for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt )
00086 mFieldCombo->insertItem( (*fieldIt)->label() );
00087 }
00088
00089 KABC::AddresseeList XXPortSelectDialog::contacts()
00090 {
00091 const TQStringList selection = mCore->selectedUIDs();
00092
00093 KABC::AddresseeList list;
00094 if ( mUseSelection->isChecked() ) {
00095 TQStringList::ConstIterator it;
00096 for ( it = selection.begin(); it != selection.end(); ++it ) {
00097 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
00098 if ( !addr.isEmpty() )
00099 list.append( addr );
00100 }
00101 } else if ( mUseFilters->isChecked() ) {
00102
00103 Filter::List::ConstIterator filterIt;
00104 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
00105 if ( (*filterIt).name() == mFiltersCombo->currentText() )
00106 break;
00107
00108 KABC::AddressBook::Iterator it;
00109 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
00110 if ( (*filterIt).filterAddressee( *it ) )
00111 list.append( *it );
00112 }
00113 } else if ( mUseCategories->isChecked() ) {
00114 const TQStringList categorieList = categories();
00115
00116 KABC::AddressBook::ConstIterator it;
00117 KABC::AddressBook::ConstIterator addressBookEnd( mCore->addressBook()->end() );
00118 for ( it = mCore->addressBook()->begin(); it != addressBookEnd; ++it ) {
00119 const TQStringList tmp( (*it).categories() );
00120 TQStringList::ConstIterator tmpIt;
00121 for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
00122 if ( categorieList.contains( *tmpIt ) ) {
00123 list.append( *it );
00124 break;
00125 }
00126 }
00127 } else {
00128
00129 KABC::AddressBook::ConstIterator it;
00130 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it )
00131 list.append( *it );
00132 }
00133
00134 if ( mUseSorting ) {
00135 list.setReverseSorting( mSortTypeCombo->currentItem() == 1 );
00136 uint pos = mFieldCombo->currentItem();
00137 if ( pos < mFields.count() )
00138 list.sortByField( mFields[ pos ] );
00139 }
00140
00141 return list;
00142 }
00143
00144 TQStringList XXPortSelectDialog::categories() const
00145 {
00146 TQStringList list;
00147
00148 TQListViewItemIterator it( mCategoriesView );
00149 for ( ; it.current(); ++it ) {
00150 TQCheckListItem* qcli = static_cast<TQCheckListItem*>(it.current());
00151 if ( qcli->isOn() )
00152 list.append( it.current()->text( 0 ) );
00153 }
00154
00155 return list;
00156 }
00157
00158 void XXPortSelectDialog::filterChanged( int )
00159 {
00160 mUseFilters->setChecked( true );
00161 }
00162
00163 void XXPortSelectDialog::categoryClicked( TQListViewItem *i )
00164 {
00165 if ( !i )
00166 return;
00167
00168 TQCheckListItem *qcli = static_cast<TQCheckListItem*>( i );
00169 if ( qcli->isOn() )
00170 mUseCategories->setChecked( true );
00171 }
00172
00173 void XXPortSelectDialog::slotHelp()
00174 {
00175 kapp->invokeHelp( "import-and-export" );
00176 }
00177
00178 void XXPortSelectDialog::initGUI()
00179 {
00180 TQFrame *page = plainPage();
00181
00182 TQVBoxLayout *topLayout = new TQVBoxLayout( page, KDialog::marginHint(),
00183 KDialog::spacingHint() );
00184
00185 TQLabel *label = new TQLabel( i18n( "Which contacts do you want to export?" ), page );
00186 topLayout->addWidget( label );
00187
00188 mButtonGroup = new TQButtonGroup( i18n( "Selection" ), page );
00189 mButtonGroup->setColumnLayout( 0, Qt::Vertical );
00190 mButtonGroup->layout()->setSpacing( KDialog::spacingHint() );
00191 mButtonGroup->layout()->setMargin( KDialog::marginHint() );
00192
00193 TQGridLayout *groupLayout = new TQGridLayout( mButtonGroup->layout() );
00194 groupLayout->setAlignment( TQt::AlignTop );
00195
00196 mUseWholeBook = new TQRadioButton( i18n( "&All contacts" ), mButtonGroup );
00197 mUseWholeBook->setChecked( true );
00198 TQWhatsThis::add( mUseWholeBook, i18n( "Export the entire address book" ) );
00199 groupLayout->addWidget( mUseWholeBook, 0, 0 );
00200 mUseSelection = new TQRadioButton( i18n("&Selected contact", "&Selected contacts (%n selected)", mCore->selectedUIDs().count() ), mButtonGroup );
00201 TQWhatsThis::add( mUseSelection, i18n( "Only export contacts selected in KAddressBook.\n"
00202 "This option is disabled if no contacts are selected." ) );
00203 groupLayout->addWidget( mUseSelection, 1, 0 );
00204
00205 mUseFilters = new TQRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup );
00206 TQWhatsThis::add( mUseFilters, i18n( "Only export contacts matching the selected filter.\n"
00207 "This option is disabled if you have not defined any filters" ) );
00208 groupLayout->addWidget( mUseFilters, 2, 0 );
00209
00210 mUseCategories = new TQRadioButton( i18n( "Category &members" ), mButtonGroup );
00211 TQWhatsThis::add( mUseCategories, i18n( "Only export contacts who are members of a category that is checked on the list to the left.\n"
00212 "This option is disabled if you have no categories." ) );
00213 groupLayout->addWidget( mUseCategories, 3, 0, TQt::AlignTop );
00214
00215 mFiltersCombo = new TQComboBox( false, mButtonGroup );
00216 TQWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to export." ) );
00217 groupLayout->addWidget( mFiltersCombo, 2, 1 );
00218
00219 mCategoriesView = new TQListView( mButtonGroup );
00220 mCategoriesView->addColumn( "" );
00221 mCategoriesView->header()->hide();
00222 TQWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to export." ) );
00223 groupLayout->addWidget( mCategoriesView, 3, 1 );
00224
00225 topLayout->addWidget( mButtonGroup );
00226
00227 TQButtonGroup *sortingGroup = new TQButtonGroup( i18n( "Sorting" ), page );
00228 sortingGroup->setColumnLayout( 0, Qt::Vertical );
00229 TQGridLayout *sortLayout = new TQGridLayout( sortingGroup->layout(), 2, 2,
00230 KDialog::spacingHint() );
00231 sortLayout->setAlignment( TQt::AlignTop );
00232
00233 label = new TQLabel( i18n( "Criterion:" ), sortingGroup );
00234 sortLayout->addWidget( label, 0, 0 );
00235
00236 mFieldCombo = new KComboBox( false, sortingGroup );
00237 sortLayout->addWidget( mFieldCombo, 0, 1 );
00238
00239 label = new TQLabel( i18n( "Order:" ), sortingGroup );
00240 sortLayout->addWidget( label, 1, 0 );
00241
00242 mSortTypeCombo = new KComboBox( false, sortingGroup );
00243 sortLayout->addWidget( mSortTypeCombo, 1, 1 );
00244
00245 topLayout->addWidget( sortingGroup );
00246
00247 if ( !mUseSorting )
00248 sortingGroup->hide();
00249 }
00250
00251 #include "xxportselectdialog.moc"