kaddressbook Library API Documentation

xxportselectdialog.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> 00004 Tobias Koenig <tokoe@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <kabc/addressbook.h> 00026 #include <kapplication.h> 00027 #include <kcombobox.h> 00028 #include <klocale.h> 00029 00030 #include <qbuttongroup.h> 00031 #include <qcombobox.h> 00032 #include <qheader.h> 00033 #include <qlabel.h> 00034 #include <qlayout.h> 00035 #include <qlistview.h> 00036 #include <qpushbutton.h> 00037 #include <qradiobutton.h> 00038 #include <qstringlist.h> 00039 #include <qwhatsthis.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 QWidget* 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, SIGNAL( activated( int ) ), 00055 SLOT( filterChanged( int ) ) ); 00056 connect( mCategoriesView, SIGNAL( clicked( QListViewItem* ) ), 00057 SLOT( categoryClicked( QListViewItem* ) ) ); 00058 00059 // setup filters 00060 mFilters = Filter::restore( kapp->config(), "Filter" ); 00061 Filter::List::iterator filterIt; 00062 QStringList 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 // setup categories 00070 QStringList categories = KABPrefs::instance()->mCustomCategories; 00071 QStringList::Iterator it; 00072 for ( it = categories.begin(); it != categories.end(); ++it ) 00073 new QCheckListItem( mCategoriesView, *it, QCheckListItem::CheckBox ); 00074 mUseCategories->setEnabled( categories.count() > 0 ); 00075 00076 int count = mCore->selectedUIDs().count(); 00077 mUseSelection->setEnabled( count != 0 ); 00078 mUseSelection->setChecked( count > 1 ); 00079 00080 mSortTypeCombo->insertItem( i18n( "Ascending" ) ); 00081 mSortTypeCombo->insertItem( i18n( "Descending" ) ); 00082 00083 mFields = mCore->addressBook()->fields( KABC::Field::All ); 00084 KABC::Field::List::Iterator fieldIt; 00085 for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt ) 00086 mFieldCombo->insertItem( (*fieldIt)->label() ); 00087 } 00088 00089 KABC::AddresseeList XXPortSelectDialog::contacts() 00090 { 00091 QStringList selection = mCore->selectedUIDs(); 00092 00093 KABC::AddresseeList list; 00094 if ( mUseSelection->isChecked() ) { 00095 QStringList::Iterator 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 // find contacts that can pass selected filter 00103 Filter::List::Iterator 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 QStringList categorieList = categories(); 00115 KABC::AddressBook::Iterator it; 00116 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { 00117 QStringList tmp( (*it).categories() ); 00118 QStringList::Iterator tmpIt; 00119 for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt ) 00120 if ( categorieList.contains( *tmpIt ) ) { 00121 list.append( *it ); 00122 break; 00123 } 00124 } 00125 } else { 00126 // create a string list of all entries: 00127 KABC::AddressBook::Iterator it; 00128 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) 00129 list.append( *it ); 00130 } 00131 00132 if ( mUseSorting ) { 00133 list.setReverseSorting( mSortTypeCombo->currentItem() == 1 ); 00134 uint pos = mFieldCombo->currentItem(); 00135 if ( pos < mFields.count() ) 00136 list.sortByField( mFields[ pos ] ); 00137 } 00138 00139 return list; 00140 } 00141 00142 QStringList XXPortSelectDialog::categories() const 00143 { 00144 QStringList list; 00145 00146 QListViewItemIterator it( mCategoriesView ); 00147 for ( ; it.current(); ++it ) { 00148 QCheckListItem* qcli = static_cast<QCheckListItem*>(it.current()); 00149 if ( qcli->isOn() ) 00150 list.append( it.current()->text( 0 ) ); 00151 } 00152 00153 return list; 00154 } 00155 00156 void XXPortSelectDialog::filterChanged( int ) 00157 { 00158 mUseFilters->setChecked( true ); 00159 } 00160 00161 void XXPortSelectDialog::categoryClicked( QListViewItem *i ) 00162 { 00163 QCheckListItem *qcli = static_cast<QCheckListItem*>( i ); 00164 if ( qcli->isOn() ) 00165 mUseCategories->setChecked( true ); 00166 } 00167 00168 void XXPortSelectDialog::slotHelp() 00169 { 00170 kapp->invokeHelp( "import-and-export" ); 00171 } 00172 00173 void XXPortSelectDialog::initGUI() 00174 { 00175 QFrame *page = plainPage(); 00176 00177 QVBoxLayout *topLayout = new QVBoxLayout( page, KDialog::marginHint(), 00178 KDialog::spacingHint() ); 00179 00180 QLabel *label = new QLabel( i18n( "Which contacts do you want to export?" ), page ); 00181 topLayout->addWidget( label ); 00182 00183 mButtonGroup = new QButtonGroup( i18n( "Selection" ), page ); 00184 mButtonGroup->setColumnLayout( 0, Qt::Vertical ); 00185 mButtonGroup->layout()->setSpacing( KDialog::spacingHint() ); 00186 mButtonGroup->layout()->setMargin( KDialog::marginHint() ); 00187 00188 QGridLayout *groupLayout = new QGridLayout( mButtonGroup->layout() ); 00189 groupLayout->setAlignment( Qt::AlignTop ); 00190 00191 mUseWholeBook = new QRadioButton( i18n( "&All contacts" ), mButtonGroup ); 00192 mUseWholeBook->setChecked( true ); 00193 QWhatsThis::add( mUseWholeBook, i18n( "Export the entire address book" ) ); 00194 groupLayout->addWidget( mUseWholeBook, 0, 0 ); 00195 00196 mUseSelection = new QRadioButton( i18n( "&Selected contacts" ), mButtonGroup ); 00197 QWhatsThis::add( mUseSelection, i18n( "Only export contacts selected in KAddressBook.\n" 00198 "This option is disabled if no contacts are selected." ) ); 00199 groupLayout->addWidget( mUseSelection, 1, 0 ); 00200 00201 mUseFilters = new QRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup ); 00202 QWhatsThis::add( mUseFilters, i18n( "Only export contacts matching the selected filter.\n" 00203 "This option is disabled if you have not defined any filters" ) ); 00204 groupLayout->addWidget( mUseFilters, 2, 0 ); 00205 00206 mUseCategories = new QRadioButton( i18n( "Category &members" ), mButtonGroup ); 00207 QWhatsThis::add( mUseCategories, i18n( "Only export contacts who are members of a category that is checked on the list to the left.\n" 00208 "This option is disabled if you have no categories." ) ); 00209 groupLayout->addWidget( mUseCategories, 3, 0, Qt::AlignTop ); 00210 00211 mFiltersCombo = new QComboBox( false, mButtonGroup ); 00212 QWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to export." ) ); 00213 groupLayout->addWidget( mFiltersCombo, 2, 1 ); 00214 00215 mCategoriesView = new QListView( mButtonGroup ); 00216 mCategoriesView->addColumn( "" ); 00217 mCategoriesView->header()->hide(); 00218 QWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to export." ) ); 00219 groupLayout->addWidget( mCategoriesView, 3, 1 ); 00220 00221 topLayout->addWidget( mButtonGroup ); 00222 00223 QButtonGroup *sortingGroup = new QButtonGroup( i18n( "Sorting" ), page ); 00224 sortingGroup->setColumnLayout( 0, Qt::Vertical ); 00225 QGridLayout *sortLayout = new QGridLayout( sortingGroup->layout(), 2, 2, 00226 KDialog::spacingHint() ); 00227 sortLayout->setAlignment( Qt::AlignTop ); 00228 00229 label = new QLabel( i18n( "Criterion:" ), sortingGroup ); 00230 sortLayout->addWidget( label, 0, 0 ); 00231 00232 mFieldCombo = new KComboBox( false, sortingGroup ); 00233 sortLayout->addWidget( mFieldCombo, 0, 1 ); 00234 00235 label = new QLabel( i18n( "Order:" ), sortingGroup ); 00236 sortLayout->addWidget( label, 1, 0 ); 00237 00238 mSortTypeCombo = new KComboBox( false, sortingGroup ); 00239 sortLayout->addWidget( mSortTypeCombo, 1, 1 ); 00240 00241 topLayout->addWidget( sortingGroup ); 00242 00243 if ( !mUseSorting ) 00244 sortingGroup->hide(); 00245 } 00246 00247 #include "xxportselectdialog.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:37 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003