00001 #ifndef KDE_USE_FINAL
00002 #define QT_NO_CAST_ASCII
00003 #endif
00004
00005
00006
00007
00008 #ifdef HAVE_CONFIG_H
00009 #include <config.h>
00010 #endif
00011
00012
00013 #include "configuredialog_p.h"
00014
00015
00016 #include "kmtransport.h"
00017 #include "globalsettings.h"
00018 #include "kmacctcachedimap.h"
00019
00020
00021
00022
00023 #include <ksimpleconfig.h>
00024 #include <kstandarddirs.h>
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027
00028
00029 #include <tqheader.h>
00030 #include <tqtabwidget.h>
00031 #include <tqradiobutton.h>
00032 #include <tqbuttongroup.h>
00033 #include <tqlabel.h>
00034 #include <tqlayout.h>
00035
00036
00037 #include <assert.h>
00038
00039
00040 NewIdentityDialog::NewIdentityDialog( const TQStringList & identities,
00041 TQWidget *parent, const char *name,
00042 bool modal )
00043 : KDialogBase( parent, name, modal, i18n("New Identity"),
00044 Ok|Cancel|Help, Ok, true )
00045 {
00046 setHelp( TQString::fromLatin1("configure-identity-newidentitydialog") );
00047 TQWidget * page = makeMainWidget();
00048 TQVBoxLayout * vlay = new TQVBoxLayout( page, 0, spacingHint() );
00049
00050
00051 TQHBoxLayout * hlay = new TQHBoxLayout( vlay );
00052 mLineEdit = new KLineEdit( page );
00053 mLineEdit->setFocus();
00054 hlay->addWidget( new TQLabel( mLineEdit, i18n("&New identity:"), page ) );
00055 hlay->addWidget( mLineEdit, 1 );
00056 connect( mLineEdit, TQT_SIGNAL(textChanged(const TQString&)),
00057 this, TQT_SLOT(slotEnableOK(const TQString&)) );
00058
00059 mButtonGroup = new TQButtonGroup( page );
00060 mButtonGroup->hide();
00061
00062
00063 TQRadioButton *radio = new TQRadioButton( i18n("&With empty fields"), page );
00064 radio->setChecked( true );
00065 mButtonGroup->insert( radio, Empty );
00066 vlay->addWidget( radio );
00067
00068
00069 radio = new TQRadioButton( i18n("&Use Control Center settings"), page );
00070 mButtonGroup->insert( radio, ControlCenter );
00071 vlay->addWidget( radio );
00072
00073
00074 radio = new TQRadioButton( i18n("&Duplicate existing identity"), page );
00075 mButtonGroup->insert( radio, ExistingEntry );
00076 vlay->addWidget( radio );
00077
00078
00079 hlay = new TQHBoxLayout( vlay );
00080 mComboBox = new TQComboBox( false, page );
00081 mComboBox->insertStringList( identities );
00082 mComboBox->setEnabled( false );
00083 TQLabel *label = new TQLabel( mComboBox, i18n("&Existing identities:"), page );
00084 label->setEnabled( false );
00085 hlay->addWidget( label );
00086 hlay->addWidget( mComboBox, 1 );
00087
00088 vlay->addStretch( 1 );
00089
00090
00091
00092 connect( radio, TQT_SIGNAL(toggled(bool)),
00093 label, TQT_SLOT(setEnabled(bool)) );
00094 connect( radio, TQT_SIGNAL(toggled(bool)),
00095 mComboBox, TQT_SLOT(setEnabled(bool)) );
00096
00097 enableButtonOK( false );
00098 }
00099
00100 NewIdentityDialog::DuplicateMode NewIdentityDialog::duplicateMode() const {
00101 int id = mButtonGroup->id( mButtonGroup->selected() );
00102 assert( id == (int)Empty
00103 || id == (int)ControlCenter
00104 || id == (int)ExistingEntry );
00105 return static_cast<DuplicateMode>( id );
00106 }
00107
00108 void NewIdentityDialog::slotEnableOK( const TQString & proposedIdentityName ) {
00109
00110 TQString name = proposedIdentityName.stripWhiteSpace();
00111
00112 if ( name.isEmpty() ) {
00113 enableButtonOK( false );
00114 return;
00115 }
00116
00117 for ( int i = 0 ; i < mComboBox->count() ; i++ )
00118 if ( mComboBox->text(i) == name ) {
00119 enableButtonOK( false );
00120 return;
00121 }
00122 enableButtonOK( true );
00123 }
00124
00125 ListView::ListView( TQWidget *parent, const char *name,
00126 int visibleItem )
00127 : KListView( parent, name )
00128 {
00129 setVisibleItem(visibleItem);
00130 }
00131
00132
00133 void ListView::resizeEvent( TQResizeEvent *e )
00134 {
00135 KListView::resizeEvent(e);
00136 resizeColums();
00137 }
00138
00139
00140 void ListView::showEvent( TQShowEvent *e )
00141 {
00142 KListView::showEvent(e);
00143 resizeColums();
00144 }
00145
00146
00147 void ListView::resizeColums()
00148 {
00149 int c = columns();
00150 if( c == 0 )
00151 {
00152 return;
00153 }
00154
00155 int w1 = viewport()->width();
00156 int w2 = w1 / c;
00157 int w3 = w1 - (c-1)*w2;
00158
00159 for( int i=0; i<c-1; i++ )
00160 {
00161 setColumnWidth( i, w2 );
00162 }
00163 setColumnWidth( c-1, w3 );
00164 }
00165
00166
00167 void ListView::setVisibleItem( int visibleItem, bool updateSize )
00168 {
00169 mVisibleItem = QMAX( 1, visibleItem );
00170 if( updateSize == true )
00171 {
00172 TQSize s = sizeHint();
00173 setMinimumSize( s.width() + verticalScrollBar()->sizeHint().width() +
00174 lineWidth() * 2, s.height() );
00175 }
00176 }
00177
00178
00179 TQSize ListView::sizeHint() const
00180 {
00181 TQSize s = TQListView::sizeHint();
00182
00183 int h = fontMetrics().height() + 2*itemMargin();
00184 if( h % 2 > 0 ) { h++; }
00185
00186 s.setHeight( h*mVisibleItem + lineWidth()*2 + header()->sizeHint().height());
00187 return s;
00188 }
00189
00190
00191 static TQString flagPng = TQString::fromLatin1("/flag.png");
00192
00193 NewLanguageDialog::NewLanguageDialog( LanguageItemList & suppressedLangs,
00194 TQWidget *parent, const char *name,
00195 bool modal )
00196 : KDialogBase( parent, name, modal, i18n("New Language"), Ok|Cancel, Ok, true )
00197 {
00198
00199 TQWidget *page = makeMainWidget();
00200 TQHBoxLayout *hlay = new TQHBoxLayout( page, 0, spacingHint() );
00201 mComboBox = new TQComboBox( false, page );
00202 hlay->addWidget( new TQLabel( mComboBox, i18n("Choose &language:"), page ) );
00203 hlay->addWidget( mComboBox, 1 );
00204
00205 TQStringList pathList = KGlobal::dirs()->findAllResources( "locale",
00206 TQString::fromLatin1("*/entry.desktop") );
00207
00208 TQStringList suppressedAcronyms;
00209 for ( LanguageItemList::Iterator lit = suppressedLangs.begin();
00210 lit != suppressedLangs.end(); ++lit )
00211 suppressedAcronyms << (*lit).mLanguage;
00212
00213
00214 for ( TQStringList::ConstIterator it = pathList.begin();
00215 it != pathList.end(); ++it )
00216 {
00217 KSimpleConfig entry( *it );
00218 entry.setGroup( "KCM Locale" );
00219
00220 TQString name = entry.readEntry( "Name" );
00221
00222
00223 TQString acronym = (*it).section( '/', -2, -2 );
00224
00225 if ( suppressedAcronyms.find( acronym ) == suppressedAcronyms.end() ) {
00226
00227 TQString displayname = TQString::fromLatin1("%1 (%2)")
00228 .arg( name ).arg( acronym );
00229 TQPixmap flag( locate("locale", acronym + flagPng ) );
00230 mComboBox->insertItem( flag, displayname );
00231 }
00232 }
00233 if ( !mComboBox->count() ) {
00234 mComboBox->insertItem( i18n("No More Languages Available") );
00235 enableButtonOK( false );
00236 } else mComboBox->listBox()->sort();
00237 }
00238
00239 TQString NewLanguageDialog::language() const
00240 {
00241 TQString s = mComboBox->currentText();
00242 int i = s.findRev( '(' );
00243 return s.mid( i + 1, s.length() - i - 2 );
00244 }
00245
00246
00247 LanguageComboBox::LanguageComboBox( bool rw, TQWidget *parent, const char *name )
00248 : TQComboBox( rw, parent, name )
00249 {
00250 }
00251
00252 int LanguageComboBox::insertLanguage( const TQString & language )
00253 {
00254 static TQString entryDesktop = TQString::fromLatin1("/entry.desktop");
00255 KSimpleConfig entry( locate("locale", language + entryDesktop) );
00256 entry.setGroup( "KCM Locale" );
00257 TQString name = entry.readEntry( "Name" );
00258 TQString output = TQString::fromLatin1("%1 (%2)").arg( name ).arg( language );
00259 insertItem( TQPixmap( locate("locale", language + flagPng ) ), output );
00260 return listBox()->index( listBox()->findItem(output) );
00261 }
00262
00263 TQString LanguageComboBox::language() const
00264 {
00265 TQString s = currentText();
00266 int i = s.findRev( '(' );
00267 return s.mid( i + 1, s.length() - i - 2 );
00268 }
00269
00270 void LanguageComboBox::setLanguage( const TQString & language )
00271 {
00272 TQString parenthizedLanguage = TQString::fromLatin1("(%1)").arg( language );
00273 for (int i = 0; i < count(); i++)
00274
00275 if ( text(i).find( parenthizedLanguage ) >= 0 ) {
00276 setCurrentItem(i);
00277 return;
00278 }
00279 }
00280
00281
00282
00283
00284
00285
00286
00287 ProfileDialog::ProfileDialog( TQWidget * parent, const char * name, bool modal )
00288 : KDialogBase( parent, name, modal, i18n("Load Profile"), Ok|Cancel, Ok, true )
00289 {
00290
00291 TQWidget * page = makeMainWidget();
00292 TQVBoxLayout * vlay = new TQVBoxLayout( page, 0, spacingHint() );
00293
00294 mListView = new KListView( page, "mListView" );
00295 mListView->addColumn( i18n("Available Profiles") );
00296 mListView->addColumn( i18n("Description") );
00297 mListView->setFullWidth( true );
00298 mListView->setAllColumnsShowFocus( true );
00299 mListView->setSorting( -1 );
00300
00301 vlay->addWidget( new TQLabel( mListView,
00302 i18n("&Select a profile and click 'OK' to "
00303 "load its settings:"), page ) );
00304 vlay->addWidget( mListView, 1 );
00305
00306 setup();
00307
00308 connect( mListView, TQT_SIGNAL(selectionChanged()),
00309 TQT_SLOT(slotSelectionChanged()) );
00310 connect( mListView, TQT_SIGNAL(doubleClicked ( TQListViewItem *, const TQPoint &, int ) ),
00311 TQT_SLOT(slotOk()) );
00312
00313 connect( this, TQT_SIGNAL(finished()), TQT_SLOT(delayedDestruct()) );
00314
00315 enableButtonOK( false );
00316 }
00317
00318 void ProfileDialog::slotSelectionChanged()
00319 {
00320 enableButtonOK( mListView->selectedItem() );
00321 }
00322
00323 void ProfileDialog::setup() {
00324 mListView->clear();
00325
00326 const TQString profileFilenameFilter = TQString::fromLatin1("kmail/profile-*-rc");
00327 mProfileList = KGlobal::dirs()->findAllResources( "data", profileFilenameFilter );
00328
00329 kdDebug(5006) << "Profile manager: found " << mProfileList.count()
00330 << " profiles:" << endl;
00331
00332
00333 TQListViewItem * listItem = 0;
00334 for ( TQStringList::const_iterator it = mProfileList.begin() ;
00335 it != mProfileList.end() ; ++it ) {
00336 KConfig profile( *it, true , false );
00337 profile.setGroup("KMail Profile");
00338 TQString name = profile.readEntry( "Name" );
00339 if ( name.isEmpty() ) {
00340 kdWarning(5006) << "File \"" << (*it)
00341 << "\" doesn't provide a profile name!" << endl;
00342 name = i18n("Missing profile name placeholder","Unnamed");
00343 }
00344 TQString desc = profile.readEntry( "Comment" );
00345 if ( desc.isEmpty() ) {
00346 kdWarning(5006) << "File \"" << (*it)
00347 << "\" doesn't provide a description!" << endl;
00348 desc = i18n("Missing profile description placeholder","Not available");
00349 }
00350 listItem = new TQListViewItem( mListView, listItem, name, desc );
00351 }
00352 }
00353
00354 void ProfileDialog::slotOk() {
00355 const int index = mListView->itemIndex( mListView->selectedItem() );
00356 if ( index < 0 )
00357 return;
00358
00359 assert( (unsigned int)index < mProfileList.count() );
00360
00361 KConfig profile( *mProfileList.at(index), true, false );
00362 emit profileSelected( &profile );
00363 KDialogBase::slotOk();
00364 }
00365
00366
00367 ConfigModuleWithTabs::ConfigModuleWithTabs( TQWidget * parent,
00368 const char * name )
00369 : ConfigModule( parent, name )
00370 {
00371 TQVBoxLayout *vlay = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
00372 mTabWidget = new TQTabWidget( this );
00373 vlay->addWidget( mTabWidget );
00374 }
00375
00376 void ConfigModuleWithTabs::addTab( ConfigModuleTab* tab, const TQString & title ) {
00377 mTabWidget->addTab( tab, title );
00378 connect( tab, TQT_SIGNAL(changed( bool )),
00379 this, TQT_SIGNAL(changed( bool )) );
00380 }
00381
00382 void ConfigModuleWithTabs::load() {
00383 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00384 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
00385 if ( tab )
00386 tab->load();
00387 }
00388 KCModule::load();
00389 }
00390
00391 void ConfigModuleWithTabs::save() {
00392 KCModule::save();
00393 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00394 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
00395 if ( tab )
00396 tab->save();
00397 }
00398 }
00399
00400 void ConfigModuleWithTabs::defaults() {
00401 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->currentPage() );
00402 if ( tab )
00403 tab->defaults();
00404 KCModule::defaults();
00405 }
00406
00407 void ConfigModuleWithTabs::installProfile(KConfig * ) {
00408 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00409 ConfigModuleTab *tab = dynamic_cast<ConfigModuleTab*>( mTabWidget->page(i) );
00410 if ( tab )
00411 tab->installProfile();
00412 }
00413 }
00414
00415 void ConfigModuleTab::load()
00416 {
00417 doLoadFromGlobalSettings();
00418 doLoadOther();
00419 }
00420
00421 void ConfigModuleTab::defaults()
00422 {
00423
00424
00425 const bool bUseDefaults = GlobalSettings::self()->useDefaults( true );
00426 doLoadFromGlobalSettings();
00427 GlobalSettings::self()->useDefaults( bUseDefaults );
00428
00429 doResetToDefaultsOther();
00430 }
00431
00432 void ConfigModuleTab::slotEmitChanged( void ) {
00433 emit changed( true );
00434 }
00435
00436
00437 #include "configuredialog_p.moc"