kmail Library API Documentation

configuredialog_p.cpp

00001 #ifndef KDE_USE_FINAL 00002 #define QT_NO_CAST_ASCII 00003 #endif 00004 // configuredialog_p.cpp: classes internal to ConfigureDialog 00005 // see configuredialog.cpp for details. 00006 00007 // This must be first 00008 #ifdef HAVE_CONFIG_H 00009 #include <config.h> 00010 #endif 00011 00012 // my header: 00013 #include "configuredialog_p.h" 00014 00015 // other KMail headers: 00016 #include "kmtransport.h" 00017 00018 // other kdenetwork headers: (none) 00019 00020 // other KDE headers: 00021 #include <ksimpleconfig.h> 00022 #include <kstandarddirs.h> 00023 #include <klocale.h> 00024 #include <kdebug.h> 00025 00026 // Qt headers: 00027 #include <qheader.h> 00028 #include <qtabwidget.h> 00029 #include <qradiobutton.h> 00030 #include <qbuttongroup.h> 00031 #include <qlabel.h> 00032 #include <qlayout.h> 00033 00034 // Other headers: 00035 #include <assert.h> 00036 00037 00038 NewIdentityDialog::NewIdentityDialog( const QStringList & identities, 00039 QWidget *parent, const char *name, 00040 bool modal ) 00041 : KDialogBase( parent, name, modal, i18n("New Identity"), 00042 Ok|Cancel|Help, Ok, true ) 00043 { 00044 setHelp( QString::fromLatin1("configure-identity-newidentitydialog") ); 00045 QWidget * page = makeMainWidget(); 00046 QVBoxLayout * vlay = new QVBoxLayout( page, 0, spacingHint() ); 00047 00048 // row 0: line edit with label 00049 QHBoxLayout * hlay = new QHBoxLayout( vlay ); // inherits spacing 00050 mLineEdit = new KLineEdit( page ); 00051 mLineEdit->setFocus(); 00052 hlay->addWidget( new QLabel( mLineEdit, i18n("&New identity:"), page ) ); 00053 hlay->addWidget( mLineEdit, 1 ); 00054 connect( mLineEdit, SIGNAL(textChanged(const QString&)), 00055 this, SLOT(slotEnableOK(const QString&)) ); 00056 00057 mButtonGroup = new QButtonGroup( page ); 00058 mButtonGroup->hide(); 00059 00060 // row 1: radio button 00061 QRadioButton *radio = new QRadioButton( i18n("&With empty fields"), page ); 00062 radio->setChecked( true ); 00063 mButtonGroup->insert( radio, Empty ); 00064 vlay->addWidget( radio ); 00065 00066 // row 2: radio button 00067 radio = new QRadioButton( i18n("&Use Control Center settings"), page ); 00068 mButtonGroup->insert( radio, ControlCenter ); 00069 vlay->addWidget( radio ); 00070 00071 // row 3: radio button 00072 radio = new QRadioButton( i18n("&Duplicate existing identity"), page ); 00073 mButtonGroup->insert( radio, ExistingEntry ); 00074 vlay->addWidget( radio ); 00075 00076 // row 4: combobox with existing identities and label 00077 hlay = new QHBoxLayout( vlay ); // inherits spacing 00078 mComboBox = new QComboBox( false, page ); 00079 mComboBox->insertStringList( identities ); 00080 mComboBox->setEnabled( false ); 00081 QLabel *label = new QLabel( mComboBox, i18n("&Existing identities:"), page ); 00082 label->setEnabled( false ); 00083 hlay->addWidget( label ); 00084 hlay->addWidget( mComboBox, 1 ); 00085 00086 vlay->addStretch( 1 ); // spacer 00087 00088 // enable/disable combobox and label depending on the third radio 00089 // button's state: 00090 connect( radio, SIGNAL(toggled(bool)), 00091 label, SLOT(setEnabled(bool)) ); 00092 connect( radio, SIGNAL(toggled(bool)), 00093 mComboBox, SLOT(setEnabled(bool)) ); 00094 00095 enableButtonOK( false ); // since line edit is empty 00096 } 00097 00098 NewIdentityDialog::DuplicateMode NewIdentityDialog::duplicateMode() const { 00099 int id = mButtonGroup->id( mButtonGroup->selected() ); 00100 assert( id == (int)Empty 00101 || id == (int)ControlCenter 00102 || id == (int)ExistingEntry ); 00103 return static_cast<DuplicateMode>( id ); 00104 } 00105 00106 void NewIdentityDialog::slotEnableOK( const QString & proposedIdentityName ) { 00107 // OK button is disabled if 00108 QString name = proposedIdentityName.stripWhiteSpace(); 00109 // name isn't empty 00110 if ( name.isEmpty() ) { 00111 enableButtonOK( false ); 00112 return; 00113 } 00114 // or name doesn't yet exist. 00115 for ( int i = 0 ; i < mComboBox->count() ; i++ ) 00116 if ( mComboBox->text(i) == name ) { 00117 enableButtonOK( false ); 00118 return; 00119 } 00120 enableButtonOK( true ); 00121 } 00122 00123 ListView::ListView( QWidget *parent, const char *name, 00124 int visibleItem ) 00125 : KListView( parent, name ) 00126 { 00127 setVisibleItem(visibleItem); 00128 } 00129 00130 00131 void ListView::resizeEvent( QResizeEvent *e ) 00132 { 00133 KListView::resizeEvent(e); 00134 resizeColums(); 00135 } 00136 00137 00138 void ListView::showEvent( QShowEvent *e ) 00139 { 00140 KListView::showEvent(e); 00141 resizeColums(); 00142 } 00143 00144 00145 void ListView::resizeColums() 00146 { 00147 int c = columns(); 00148 if( c == 0 ) 00149 { 00150 return; 00151 } 00152 00153 int w1 = viewport()->width(); 00154 int w2 = w1 / c; 00155 int w3 = w1 - (c-1)*w2; 00156 00157 for( int i=0; i<c-1; i++ ) 00158 { 00159 setColumnWidth( i, w2 ); 00160 } 00161 setColumnWidth( c-1, w3 ); 00162 } 00163 00164 00165 void ListView::setVisibleItem( int visibleItem, bool updateSize ) 00166 { 00167 mVisibleItem = QMAX( 1, visibleItem ); 00168 if( updateSize == true ) 00169 { 00170 QSize s = sizeHint(); 00171 setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() + 00172 lineWidth() * 2, s.height() ); 00173 } 00174 } 00175 00176 00177 QSize ListView::sizeHint() const 00178 { 00179 QSize s = QListView::sizeHint(); 00180 00181 int h = fontMetrics().height() + 2*itemMargin(); 00182 if( h % 2 > 0 ) { h++; } 00183 00184 s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height()); 00185 return s; 00186 } 00187 00188 00189 static QString flagPng = QString::fromLatin1("/flag.png"); 00190 00191 NewLanguageDialog::NewLanguageDialog( LanguageItemList & suppressedLangs, 00192 QWidget *parent, const char *name, 00193 bool modal ) 00194 : KDialogBase( parent, name, modal, i18n("New Language"), Ok|Cancel, Ok, true ) 00195 { 00196 // layout the page (a combobox with label): 00197 QWidget *page = makeMainWidget(); 00198 QHBoxLayout *hlay = new QHBoxLayout( page, 0, spacingHint() ); 00199 mComboBox = new QComboBox( false, page ); 00200 hlay->addWidget( new QLabel( mComboBox, i18n("Choose &language:"), page ) ); 00201 hlay->addWidget( mComboBox, 1 ); 00202 00203 QStringList pathList = KGlobal::dirs()->findAllResources( "locale", 00204 QString::fromLatin1("*/entry.desktop") ); 00205 // extract a list of language tags that should not be included: 00206 QStringList suppressedAcronyms; 00207 for ( LanguageItemList::Iterator lit = suppressedLangs.begin(); 00208 lit != suppressedLangs.end(); ++lit ) 00209 suppressedAcronyms << (*lit).mLanguage; 00210 00211 // populate the combo box: 00212 for ( QStringList::ConstIterator it = pathList.begin(); 00213 it != pathList.end(); ++it ) 00214 { 00215 KSimpleConfig entry( *it ); 00216 entry.setGroup( "KCM Locale" ); 00217 // full name: 00218 QString name = entry.readEntry( "Name" ); 00219 // {2,3}-letter abbreviation: 00220 // we extract it from the path: "/prefix/de/entry.desktop" -> "de" 00221 QString acronym = (*it).section( '/', -2, -2 ); 00222 00223 if ( suppressedAcronyms.find( acronym ) == suppressedAcronyms.end() ) { 00224 // not found: 00225 QString displayname = QString::fromLatin1("%1 (%2)") 00226 .arg( name ).arg( acronym ); 00227 QPixmap flag( locate("locale", acronym + flagPng ) ); 00228 mComboBox->insertItem( flag, displayname ); 00229 } 00230 } 00231 if ( !mComboBox->count() ) { 00232 mComboBox->insertItem( i18n("No More Languages Available") ); 00233 enableButtonOK( false ); 00234 } else mComboBox->listBox()->sort(); 00235 } 00236 00237 QString NewLanguageDialog::language() const 00238 { 00239 QString s = mComboBox->currentText(); 00240 int i = s.findRev( '(' ); 00241 return s.mid( i + 1, s.length() - i - 2 ); 00242 } 00243 00244 00245 LanguageComboBox::LanguageComboBox( bool rw, QWidget *parent, const char *name ) 00246 : QComboBox( rw, parent, name ) 00247 { 00248 } 00249 00250 int LanguageComboBox::insertLanguage( const QString & language ) 00251 { 00252 static QString entryDesktop = QString::fromLatin1("/entry.desktop"); 00253 KSimpleConfig entry( locate("locale", language + entryDesktop) ); 00254 entry.setGroup( "KCM Locale" ); 00255 QString name = entry.readEntry( "Name" ); 00256 QString output = QString::fromLatin1("%1 (%2)").arg( name ).arg( language ); 00257 insertItem( QPixmap( locate("locale", language + flagPng ) ), output ); 00258 return listBox()->index( listBox()->findItem(output) ); 00259 } 00260 00261 QString LanguageComboBox::language() const 00262 { 00263 QString s = currentText(); 00264 int i = s.findRev( '(' ); 00265 return s.mid( i + 1, s.length() - i - 2 ); 00266 } 00267 00268 void LanguageComboBox::setLanguage( const QString & language ) 00269 { 00270 QString parenthizedLanguage = QString::fromLatin1("(%1)").arg( language ); 00271 for (int i = 0; i < count(); i++) 00272 // ### FIXME: use .endWith(): 00273 if ( text(i).find( parenthizedLanguage ) >= 0 ) { 00274 setCurrentItem(i); 00275 return; 00276 } 00277 } 00278 00279 // 00280 // 00281 // ProfileDialog 00282 // 00283 // 00284 00285 ProfileDialog::ProfileDialog( QWidget * parent, const char * name, bool modal ) 00286 : KDialogBase( parent, name, modal, i18n("Load Profile"), Ok|Cancel, Ok, true ) 00287 { 00288 // tmp. vars: 00289 QWidget * page = makeMainWidget(); 00290 QVBoxLayout * vlay = new QVBoxLayout( page, 0, spacingHint() ); 00291 00292 mListView = new KListView( page, "mListView" ); 00293 mListView->addColumn( i18n("Available Profiles") ); 00294 mListView->addColumn( i18n("Description") ); 00295 mListView->setFullWidth( true ); 00296 mListView->setAllColumnsShowFocus( true ); 00297 mListView->setFrameStyle( QFrame::WinPanel + QFrame::Sunken ); 00298 mListView->setSorting( -1 ); 00299 00300 vlay->addWidget( new QLabel( mListView, 00301 i18n("&Select a profile and click 'OK' to " 00302 "load its settings:"), page ) ); 00303 vlay->addWidget( mListView, 1 ); 00304 00305 setup(); 00306 00307 connect( mListView, SIGNAL(selectionChanged()), 00308 SLOT(slotSelectionChanged()) ); 00309 connect( mListView, SIGNAL(doubleClicked ( QListViewItem *, const QPoint &, int ) ), 00310 SLOT(slotOk()) ); 00311 00312 connect( this, SIGNAL(finished()), SLOT(delayedDestruct()) ); 00313 00314 enableButtonOK( false ); 00315 } 00316 00317 void ProfileDialog::slotSelectionChanged() 00318 { 00319 enableButtonOK( mListView->selectedItem() ); 00320 } 00321 00322 void ProfileDialog::setup() { 00323 mListView->clear(); 00324 // find all profiles (config files named "profile-xyz-rc"): 00325 const QString profileFilenameFilter = QString::fromLatin1("kmail/profile-*-rc"); 00326 mProfileList = KGlobal::dirs()->findAllResources( "data", profileFilenameFilter ); 00327 00328 kdDebug(5006) << "Profile manager: found " << mProfileList.count() 00329 << " profiles:" << endl; 00330 00331 // build the list and populate the list view: 00332 QListViewItem * listItem = 0; 00333 for ( QStringList::const_iterator it = mProfileList.begin() ; 00334 it != mProfileList.end() ; ++it ) { 00335 KConfig profile( *it, true /* read-only */, false /* no KDE global */ ); 00336 profile.setGroup("KMail Profile"); 00337 QString name = profile.readEntry( "Name" ); 00338 if ( name.isEmpty() ) { 00339 kdWarning(5006) << "File \"" << (*it) 00340 << "\" doesn't provide a profile name!" << endl; 00341 name = i18n("Missing profile name placeholder","Unnamed"); 00342 } 00343 QString desc = profile.readEntry( "Comment" ); 00344 if ( desc.isEmpty() ) { 00345 kdWarning(5006) << "File \"" << (*it) 00346 << "\" doesn't provide a description!" << endl; 00347 desc = i18n("Missing profile description placeholder","Not available"); 00348 } 00349 listItem = new QListViewItem( mListView, listItem, name, desc ); 00350 } 00351 } 00352 00353 void ProfileDialog::slotOk() { 00354 const int index = mListView->itemIndex( mListView->selectedItem() ); 00355 if ( index < 0 ) 00356 return; // none selected 00357 00358 assert( (unsigned int)index < mProfileList.count() ); 00359 00360 KConfig profile( *mProfileList.at(index), true, false ); 00361 emit profileSelected( &profile ); 00362 KDialogBase::slotOk(); 00363 } 00364 00365 00366 ConfigModuleWithTabs::ConfigModuleWithTabs( QWidget * parent, 00367 const char * name ) 00368 : ConfigModule( parent, name ) 00369 { 00370 QVBoxLayout *vlay = new QVBoxLayout( this, 0, KDialog::spacingHint() ); 00371 mTabWidget = new QTabWidget( this ); 00372 vlay->addWidget( mTabWidget ); 00373 } 00374 00375 void ConfigModuleWithTabs::addTab( ConfigModuleTab* tab, const QString & title ) { 00376 mTabWidget->addTab( tab, title ); 00377 connect( tab, SIGNAL(changed( bool )), 00378 this, SIGNAL(changed( bool )) ); 00379 } 00380 00381 void ConfigModuleWithTabs::load() { 00382 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) { 00383 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) ); 00384 if ( tab ) 00385 tab->load(); 00386 } 00387 } 00388 00389 void ConfigModuleWithTabs::save() { 00390 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) { 00391 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) ); 00392 if ( tab ) 00393 tab->save(); 00394 } 00395 } 00396 00397 void ConfigModuleWithTabs::defaults() { 00398 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) { 00399 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) ); 00400 if ( tab ) 00401 tab->defaults(); 00402 } 00403 } 00404 00405 void ConfigModuleWithTabs::installProfile(KConfig * /* profile */ ) { 00406 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) { 00407 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) ); 00408 if ( tab ) 00409 tab->installProfile(); 00410 } 00411 } 00412 00413 void ConfigModuleTab::slotEmitChanged( void ) { 00414 emit changed( true ); 00415 } 00416 00417 00418 00419 #include "configuredialog_p.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:52:15 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003