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
00018
00019
00020
00021 #include <ksimpleconfig.h>
00022 #include <kstandarddirs.h>
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025
00026
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
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
00049 QHBoxLayout * hlay = new QHBoxLayout( vlay );
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
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
00067 radio = new QRadioButton( i18n("&Use Control Center settings"), page );
00068 mButtonGroup->insert( radio, ControlCenter );
00069 vlay->addWidget( radio );
00070
00071
00072 radio = new QRadioButton( i18n("&Duplicate existing identity"), page );
00073 mButtonGroup->insert( radio, ExistingEntry );
00074 vlay->addWidget( radio );
00075
00076
00077 hlay = new QHBoxLayout( vlay );
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 );
00087
00088
00089
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 );
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
00108 QString name = proposedIdentityName.stripWhiteSpace();
00109
00110 if ( name.isEmpty() ) {
00111 enableButtonOK( false );
00112 return;
00113 }
00114
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
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
00206 QStringList suppressedAcronyms;
00207 for ( LanguageItemList::Iterator lit = suppressedLangs.begin();
00208 lit != suppressedLangs.end(); ++lit )
00209 suppressedAcronyms << (*lit).mLanguage;
00210
00211
00212 for ( QStringList::ConstIterator it = pathList.begin();
00213 it != pathList.end(); ++it )
00214 {
00215 KSimpleConfig entry( *it );
00216 entry.setGroup( "KCM Locale" );
00217
00218 QString name = entry.readEntry( "Name" );
00219
00220
00221 QString acronym = (*it).section( '/', -2, -2 );
00222
00223 if ( suppressedAcronyms.find( acronym ) == suppressedAcronyms.end() ) {
00224
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
00273 if ( text(i).find( parenthizedLanguage ) >= 0 ) {
00274 setCurrentItem(i);
00275 return;
00276 }
00277 }
00278
00279
00280
00281
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
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(QListViewItem*)),
00308 SLOT(slotSelectionChanged(QListViewItem*)) );
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( QListViewItem * item ) {
00318 enableButtonOK( item );
00319 }
00320
00321 void ProfileDialog::setup() {
00322 mListView->clear();
00323
00324 const QString profileFilenameFilter = QString::fromLatin1("kmail/profile-*-rc");
00325 mProfileList = KGlobal::dirs()->findAllResources( "data", profileFilenameFilter );
00326
00327 kdDebug(5006) << "Profile manager: found " << mProfileList.count()
00328 << " profiles:" << endl;
00329
00330
00331 QListViewItem * listItem = 0;
00332 for ( QStringList::const_iterator it = mProfileList.begin() ;
00333 it != mProfileList.end() ; ++it ) {
00334 KConfig profile( *it, true , false );
00335 profile.setGroup("KMail Profile");
00336 QString name = profile.readEntry( "Name" );
00337 if ( name.isEmpty() ) {
00338 kdWarning(5006) << "File \"" << (*it)
00339 << "\" doesn't provide a profile name!" << endl;
00340 name = i18n("Missing profile name placeholder","Unnamed");
00341 }
00342 QString desc = profile.readEntry( "Comment" );
00343 if ( desc.isEmpty() ) {
00344 kdWarning(5006) << "File \"" << (*it)
00345 << "\" doesn't provide a description!" << endl;
00346 desc = i18n("Missing profile description placeholder","Not available");
00347 }
00348 listItem = new QListViewItem( mListView, listItem, name, desc );
00349 }
00350 }
00351
00352 void ProfileDialog::slotOk() {
00353 const int index = mListView->itemIndex( mListView->selectedItem() );
00354 if ( index < 0 )
00355 return;
00356
00357 assert( (unsigned int)index < mProfileList.count() );
00358
00359 KConfig profile( *mProfileList.at(index), true, false );
00360 emit profileSelected( &profile );
00361 KDialogBase::slotOk();
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371 TabbedConfigurationPage::TabbedConfigurationPage( QWidget * parent,
00372 const char * name )
00373 : ConfigurationPage( parent, name )
00374 {
00375 QVBoxLayout *vlay = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00376 mTabWidget = new QTabWidget( this );
00377 vlay->addWidget( mTabWidget );
00378 }
00379
00380 void TabbedConfigurationPage::addTab( QWidget * tab, const QString & title ) {
00381 mTabWidget->addTab( tab, title );
00382 }
00383
00384 ConfigurationPage * TabbedConfigurationPage::configTab( int i, const char * func ) const {
00385 ConfigurationPage * tab =
00386 dynamic_cast<ConfigurationPage*>( mTabWidget->page( i ) );
00387 kdWarning( !tab ) << "Tab with index " << i << " and label \""
00388 << mTabWidget->label( i )
00389 << "\" is not a ConfigurationPage." << endl
00390 << "Better overload " << func << "() in this page!"
00391 << endl;
00392 return tab;
00393 }
00394
00395 void TabbedConfigurationPage::setup() {
00396 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00397 ConfigurationPage * tab = configTab( i, "setup" );
00398 if ( tab )
00399 tab->setup();
00400 }
00401 }
00402
00403 void TabbedConfigurationPage::dismiss() {
00404 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00405 ConfigurationPage * tab = configTab( i, "dismiss" );
00406 if ( tab )
00407 tab->dismiss();
00408 }
00409 }
00410
00411 void TabbedConfigurationPage::installProfile( KConfig * profile ) {
00412 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00413 ConfigurationPage * tab = configTab( i, "installProfile" );
00414 if ( tab )
00415 tab->installProfile( profile );
00416 }
00417 }
00418
00419 void TabbedConfigurationPage::apply() {
00420 for ( int i = 0 ; i < mTabWidget->count() ; ++i ) {
00421 ConfigurationPage * tab = configTab( i, "apply" );
00422 if ( tab )
00423 tab->apply();
00424 }
00425 }
00426
00427
00428
00429 #include "configuredialog_p.moc"