• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

knode

knconfigwidgets.cpp

Go to the documentation of this file.
00001 /*
00002     KNode, the KDE newsreader
00003     Copyright (c) 1999-2006 the KNode authors.
00004     See file AUTHORS for details
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     You should have received a copy of the GNU General Public License
00011     along with this program; if not, write to the Free Software Foundation,
00012     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00013 */
00014 
00015 
00016 #include <QPainter>
00017 
00018 #include <QLabel>
00019 //Added by qt3to4:
00020 #include <QGridLayout>
00021 #include <QBoxLayout>
00022 #include <QVBoxLayout>
00023 #include <QTextEdit>
00024 
00025 #include <kcharsets.h>
00026 #include <klocale.h>
00027 #include <knumvalidator.h>
00028 #include <kmessagebox.h>
00029 #include <kmimetypetrader.h>
00030 #include <kcolordialog.h>
00031 #include <kfontdialog.h>
00032 #include <kfiledialog.h>
00033 #include <kscoringeditor.h>
00034 #include <sonnet/configwidget.h>
00035 #include <kcombobox.h>
00036 #include <libkpgp/kpgp.h>
00037 #include <libkpgp/kpgpui.h>
00038 #include <kurlcompletion.h>
00039 #include <kiconloader.h>
00040 #include <kpushbutton.h>
00041 #include <kvbox.h>
00042 #include <krun.h>
00043 
00044 #include "knaccountmanager.h"
00045 #include "knconfig.h"
00046 #include "knconfigwidgets.h"
00047 #include "knconfigmanager.h"
00048 #include "kndisplayedheader.h"
00049 #include "kngroupmanager.h"
00050 #include "knglobals.h"
00051 #include "knnntpaccount.h"
00052 #include "utilities.h"
00053 #include "knfiltermanager.h"
00054 #include "knarticlefilter.h"
00055 #include "knscoring.h"
00056 #include "ui_postnewscomposerwidget_base.h"
00057 #include "ui_readnewsnavigationwidget_base.h"
00058 #include "ui_readnewsviewerwidget_base.h"
00059 #include "settings.h"
00060 
00061 KNode::IdentityWidget::IdentityWidget( Identity *d, const KComponentData &inst, QWidget *parent ) :
00062   KCModule( inst ,parent ),
00063   d_ata( d )
00064 {
00065   QString msg;
00066 
00067   QGridLayout *topL=new QGridLayout(this);
00068   topL->setSpacing(5);
00069   topL->setMargin(5);
00070 
00071   n_ame=new KLineEdit(this);
00072   QLabel *l=new QLabel(i18n("&Name:"),this);
00073   l->setBuddy(n_ame);
00074   topL->addWidget(l, 0,0);
00075   topL->addWidget(n_ame, 0, 1, 1,2);
00076   msg = i18n("<qt><p>Your name as it will appear to others reading your articles.</p>"
00077       "<p>Ex: <b>John Stuart Masterson III</b>.</p></qt>");
00078   n_ame->setWhatsThis( msg );
00079   l->setWhatsThis( msg );
00080   connect( n_ame, SIGNAL(textChanged(const QString&)), SLOT(changed()) );
00081 
00082   o_rga=new KLineEdit(this);
00083   l=new QLabel(i18n("Organi&zation:"),this);
00084   l->setBuddy(o_rga);
00085   topL->addWidget(l, 1,0);
00086   topL->addWidget(o_rga, 1, 1, 1,2);
00087   msg = i18n( "<qt><p>The name of the organization you work for.</p>"
00088       "<p>Ex: <b>KNode, Inc</b>.</p></qt>" );
00089   o_rga->setWhatsThis( msg );
00090   l->setWhatsThis( msg );
00091   connect( o_rga, SIGNAL(textChanged(const QString&)), SLOT(changed()) );
00092 
00093   e_mail=new KLineEdit(this);
00094   l=new QLabel(i18n("Email a&ddress:"),this);
00095   l->setBuddy(e_mail);
00096   topL->addWidget(l, 2,0);
00097   topL->addWidget(e_mail, 2, 1, 1,2);
00098   msg = i18n( "<qt><p>Your email address as it will appear to others "
00099       "reading your articles</p><p>Ex: <b>nospam@please.com</b>.</p></qt>" );
00100   l->setWhatsThis( msg );
00101   e_mail->setWhatsThis( msg );
00102   connect( e_mail, SIGNAL(textChanged(const QString&)), SLOT(changed()) );
00103 
00104   r_eplyTo=new KLineEdit(this);
00105   l=new QLabel(i18n("&Reply-to address:"),this);
00106   l->setBuddy(r_eplyTo);
00107   topL->addWidget(l, 3,0);
00108   topL->addWidget(r_eplyTo, 3, 1, 1,2);
00109   msg = i18n( "<qt><p>When someone reply to your article by email, this is the address the message "
00110       "will be sent. If you fill in this field, please do it with a real "
00111       "email address.</p><p>Ex: <b>john@example.com</b>.</p></qt>" );
00112   l->setWhatsThis( msg );
00113   r_eplyTo->setWhatsThis( msg );
00114   connect( r_eplyTo, SIGNAL(textChanged(const QString&)), SLOT(changed()) );
00115 
00116   m_ailCopiesTo=new KLineEdit(this);
00117   l=new QLabel(i18n("&Mail-copies-to:"),this);
00118   l->setBuddy(m_ailCopiesTo);
00119   topL->addWidget(l, 4,0);
00120   topL->addWidget(m_ailCopiesTo, 4, 1, 1,2);
00121   connect( m_ailCopiesTo, SIGNAL(textChanged(const QString&)), SLOT(changed()) );
00122 
00123   s_igningKey = new Kpgp::SecretKeyRequester(this);
00124   s_igningKey->dialogButton()->setText(i18n("Chan&ge..."));
00125   s_igningKey->setDialogCaption(i18n("Your OpenPGP Key"));
00126   s_igningKey->setDialogMessage(i18n("Select the OpenPGP key which should be "
00127       "used for signing articles."));
00128   l=new QLabel(i18n("Signing ke&y:"),this);
00129   l->setBuddy(s_igningKey);
00130   topL->addWidget(l, 5,0);
00131   topL->addWidget(s_igningKey, 5, 1, 1,2);
00132   msg = i18n("<qt><p>The OpenPGP key you choose here will be "
00133       "used to sign your articles.</p></qt>");
00134   l->setWhatsThis( msg );
00135   s_igningKey->setWhatsThis( msg );
00136   connect( s_igningKey, SIGNAL(changed()), SLOT(changed()) );
00137 
00138   b_uttonGroup = new QButtonGroup( this );
00139   connect( b_uttonGroup, SIGNAL( buttonClicked( int ) ),
00140            this, SLOT( slotSignatureType( int ) ) );
00141   b_uttonGroup->setExclusive( true );
00142 
00143   s_igFile = new QRadioButton( i18n("&Use a signature from file"), this );
00144   b_uttonGroup->addButton( s_igFile, 0 );
00145   topL->addWidget(s_igFile, 6, 0, 1, 3 );
00146   s_igFile->setWhatsThis(
00147                    i18n( "<qt><p>Mark this to let KNode read the signature from a file.</p></qt>" ) );
00148   s_ig = new KLineEdit(this);
00149 
00150   f_ileName = new QLabel(i18n("Signature &file:"),this);
00151   f_ileName->setBuddy(s_ig);
00152   topL->addWidget(f_ileName, 7, 0 );
00153   topL->addWidget(s_ig, 7, 1 );
00154   c_ompletion = new KUrlCompletion();
00155   s_ig->setCompletionObject(c_ompletion);
00156   msg = i18n( "<qt><p>The file from which the signature will be read.</p>"
00157       "<p>Ex: <b>/home/robt/.sig</b>.</p></qt>" );
00158   f_ileName->setWhatsThis( msg );
00159   s_ig->setWhatsThis( msg );
00160 
00161   c_hooseBtn = new QPushButton( i18n("Choo&se..."), this);
00162   connect(c_hooseBtn, SIGNAL(clicked()),
00163           this, SLOT(slotSignatureChoose()));
00164   topL->addWidget(c_hooseBtn, 7, 2 );
00165   e_ditBtn = new QPushButton( i18n("&Edit File"), this);
00166   connect(e_ditBtn, SIGNAL(clicked()),
00167           this, SLOT(slotSignatureEdit()));
00168   topL->addWidget(e_ditBtn, 8, 2);
00169 
00170   s_igGenerator = new QCheckBox(i18n("&The file is a program"), this);
00171   topL->addWidget(s_igGenerator, 8, 0, 1, 2 );
00172   msg = i18n( "<qt><p>Mark this option if the signature will be generated by a program</p>"
00173       "<p>Ex: <b>/home/robt/gensig.sh</b>.</p></qt>" );
00174   s_igGenerator->setWhatsThis( msg );
00175   connect( s_igGenerator, SIGNAL(toggled(bool)), SLOT(changed()) );
00176 
00177   s_igEdit = new QRadioButton( i18n("Specify signature &below"), this);
00178   b_uttonGroup->addButton( s_igEdit, 1 );
00179   topL->addWidget(s_igEdit, 9, 0, 1, 3 );
00180 
00181   s_igEditor = new QTextEdit( this );
00182   topL->addWidget(s_igEditor, 10, 0, 1, 3 );
00183   connect( s_igEditor, SIGNAL(textChanged()), SLOT(changed()) );
00184 
00185   topL->setColumnStretch(1,1);
00186   topL->setRowStretch(7,1);
00187   topL->setResizeMode(QLayout::SetMinimumSize);
00188   connect(s_ig,SIGNAL(textChanged ( const QString & )),
00189           this,SLOT(textFileNameChanged(const QString &)));
00190 
00191   load();
00192 }
00193 
00194 
00195 KNode::IdentityWidget::~IdentityWidget()
00196 {
00197   delete c_ompletion;
00198 }
00199 
00200 void KNode::IdentityWidget::textFileNameChanged(const QString &text)
00201 {
00202     e_ditBtn->setEnabled(!text.isEmpty());
00203     emit changed( true );
00204 }
00205 
00206 void KNode::IdentityWidget::load()
00207 {
00208   kDebug() <<"void KNConfig::IdentityWidget::load()";
00209   n_ame->setText(d_ata->n_ame);
00210   o_rga->setText(d_ata->o_rga);
00211   e_mail->setText(d_ata->e_mail);
00212   r_eplyTo->setText(d_ata->r_eplyTo);
00213   m_ailCopiesTo->setText(d_ata->m_ailCopiesTo);
00214   s_igningKey->setKeyIDs( Kpgp::KeyIDList() << d_ata->s_igningKey.toLatin1() );
00215   s_ig->setText(d_ata->s_igPath);
00216   s_igGenerator->setChecked(d_ata->useSigGenerator());
00217   s_igEditor->setPlainText( d_ata->s_igText );
00218   slotSignatureType(d_ata->useSigFile()? 0:1);
00219 }
00220 
00221 void KNode::IdentityWidget::save()
00222 {
00223   d_ata->n_ame=n_ame->text();
00224   d_ata->o_rga=o_rga->text();
00225   d_ata->e_mail=e_mail->text();
00226   d_ata->r_eplyTo=r_eplyTo->text();
00227   d_ata->m_ailCopiesTo=m_ailCopiesTo->text();
00228   d_ata->s_igningKey = s_igningKey->keyIDs().first();
00229   d_ata->u_seSigFile=s_igFile->isChecked();
00230   d_ata->u_seSigGenerator=s_igGenerator->isChecked();
00231   d_ata->s_igPath=c_ompletion->replacedPath(s_ig->text());
00232   d_ata->s_igText = s_igEditor->toPlainText();
00233 
00234   if(d_ata->isGlobal())
00235     d_ata->save();
00236 }
00237 
00238 void KNode::IdentityWidget::slotSignatureType(int type)
00239 {
00240   bool sigFromFile = (type==0);
00241 
00242   b_uttonGroup->button( type )->setChecked( true );
00243   f_ileName->setEnabled(sigFromFile);
00244   s_ig->setEnabled(sigFromFile);
00245   c_hooseBtn->setEnabled(sigFromFile);
00246   e_ditBtn->setEnabled(sigFromFile && !s_ig->text().isEmpty());
00247   s_igGenerator->setEnabled(sigFromFile);
00248   s_igEditor->setEnabled(!sigFromFile);
00249 
00250   if (sigFromFile)
00251     f_ileName->setFocus();
00252   else
00253     s_igEditor->setFocus();
00254   emit changed( true );
00255 }
00256 
00257 
00258 void KNode::IdentityWidget::slotSignatureChoose()
00259 {
00260   QString tmp = KFileDialog::getOpenFileName( c_ompletion->replacedPath( s_ig->text() ), QString(), this, i18n("Choose Signature") );
00261   if(!tmp.isEmpty()) s_ig->setText(tmp);
00262   emit changed( true );
00263 }
00264 
00265 
00266 void KNode::IdentityWidget::slotSignatureEdit()
00267 {
00268   QString fileName = c_ompletion->replacedPath(s_ig->text()).trimmed();
00269 
00270   if (fileName.isEmpty()) {
00271     KMessageBox::sorry(this, i18n("You must specify a filename."));
00272     return;
00273   }
00274 
00275   QFileInfo fileInfo( fileName );
00276   if (fileInfo.isDir()) {
00277     KMessageBox::sorry(this, i18n("You have specified a folder."));
00278     return;
00279   }
00280 
00281   KService::Ptr offer = KMimeTypeTrader::self()->preferredService("text/plain", "Application");
00282   KUrl u(fileName);
00283 
00284   if (offer)
00285     KRun::run(*offer, u, this);
00286   else
00287     KRun::displayOpenWithDialog(u, this);
00288   emit changed( true );
00289 }
00290 
00291 
00292 
00293 //==========================================================================================
00294 
00295 //BEGIN: NNTP account configuration widgets ----------------------------------
00296 
00297 KNode::NntpAccountListWidget::NntpAccountListWidget( const KComponentData &inst, QWidget *parent ) :
00298   KCModule( inst, parent )
00299 {
00300   setupUi( this );
00301 
00302   // account listbox
00303   connect( mAccountList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), SLOT( slotEditBtnClicked() ) );
00304   connect( mAccountList, SIGNAL( itemSelectionChanged() ), SLOT( slotSelectionChanged() ) );
00305 
00306   // buttons
00307   connect( mAddButton, SIGNAL( clicked() ), SLOT( slotAddBtnClicked() ) );
00308   connect( mEditButton, SIGNAL( clicked() ), SLOT( slotEditBtnClicked() ) );
00309   connect( mDeleteButton, SIGNAL( clicked() ), SLOT( slotDelBtnClicked() ) );
00310   connect( mSubscribeButton, SIGNAL( clicked() ), SLOT( slotSubBtnClicked() ) );
00311 
00312   load();
00313 
00314   // the settings dialog is non-modal, so we have to react to changes
00315   // made outside of the dialog
00316   KNAccountManager *am = knGlobals.accountManager();
00317   connect( am, SIGNAL( accountAdded( KNNntpAccount* ) ), SLOT( slotAddItem( KNNntpAccount* ) ) );
00318   connect( am, SIGNAL( accountRemoved( KNNntpAccount* ) ), SLOT( slotRemoveItem( KNNntpAccount* ) ) );
00319   connect( am, SIGNAL( accountModified( KNNntpAccount* ) ), SLOT( slotUpdateItem( KNNntpAccount* ) ) );
00320 
00321   slotSelectionChanged();     // disable Delete & Edit initially
00322 }
00323 
00324 
00325 void KNode::NntpAccountListWidget::load()
00326 {
00327   mAccountList->clear();
00328   KNAccountManager::List list = knGlobals.accountManager()->accounts();
00329   for ( KNAccountManager::List::Iterator it = list.begin(); it != list.end(); ++it )
00330     slotAddItem( *it );
00331 }
00332 
00333 
00334 void KNode::NntpAccountListWidget::slotAddItem(KNNntpAccount *a)
00335 {
00336   AccountListItem *item;
00337   item = new AccountListItem( a );
00338   item->setText( a->name() );
00339   item->setIcon( SmallIcon( "network-server" ) );
00340   mAccountList->addItem( item );
00341   emit changed( true );
00342 }
00343 
00344 
00345 void KNode::NntpAccountListWidget::slotRemoveItem(KNNntpAccount *a)
00346 {
00347   AccountListItem *item;
00348   for ( int i = 0; i < mAccountList->count(); ++i ) {
00349     item = static_cast<AccountListItem*>( mAccountList->item( i ) );
00350     if ( item && item->account() == a ) {
00351       delete mAccountList->takeItem( i );
00352       break;
00353     }
00354   }
00355   slotSelectionChanged();
00356   emit changed( true );
00357 }
00358 
00359 
00360 void KNode::NntpAccountListWidget::slotUpdateItem(KNNntpAccount *a)
00361 {
00362   AccountListItem *item;
00363   for ( int i = 0; i < mAccountList->count(); ++i ) {
00364     item = static_cast<AccountListItem*>( mAccountList->item( i ) );
00365     if ( item && item->account() == a )
00366       item->setText( a->name() );
00367   }
00368   slotSelectionChanged();
00369   emit changed( true );
00370 }
00371 
00372 
00373 
00374 void KNode::NntpAccountListWidget::slotSelectionChanged()
00375 {
00376   AccountListItem *item = static_cast<AccountListItem*>( mAccountList->currentItem() );
00377   mDeleteButton->setEnabled( item );
00378   mEditButton->setEnabled( item );
00379   mSubscribeButton->setEnabled( item );
00380 
00381   if ( item ) {
00382     mServerInfo->setText( i18n("Server: %1", item->account()->server() ) );
00383     mPortInfo->setText( i18n("Port: %1", item->account()->port() ) );
00384   } else {
00385     mServerInfo->setText( i18n("Server: ") );
00386     mPortInfo->setText( i18n("Port: ") );
00387   }
00388 }
00389 
00390 
00391 
00392 void KNode::NntpAccountListWidget::slotAddBtnClicked()
00393 {
00394   KNNntpAccount *acc = new KNNntpAccount();
00395 
00396   if(acc->editProperties(this)) {
00397     if(knGlobals.accountManager()->newAccount(acc))
00398       acc->saveInfo();
00399   }
00400   else
00401     delete acc;
00402 }
00403 
00404 
00405 
00406 void KNode::NntpAccountListWidget::slotDelBtnClicked()
00407 {
00408   AccountListItem *item = static_cast<AccountListItem*>( mAccountList->currentItem() );
00409   if ( item )
00410     knGlobals.accountManager()->removeAccount( item->account() );
00411 }
00412 
00413 
00414 
00415 void KNode::NntpAccountListWidget::slotEditBtnClicked()
00416 {
00417   AccountListItem *item = static_cast<AccountListItem*>( mAccountList->currentItem() );
00418   if ( item ) {
00419     item->account()->editProperties( this );
00420     slotUpdateItem( item->account() );
00421   }
00422 }
00423 
00424 
00425 void KNode::NntpAccountListWidget::slotSubBtnClicked()
00426 {
00427   AccountListItem *item = static_cast<AccountListItem*>( mAccountList->currentItem() );
00428   if( item )
00429     knGlobals.groupManager()->showGroupDialog( item->account(), this );
00430 }
00431 
00432 
00433 //=======================================================================================
00434 
00435 
00436 KNode::NntpAccountConfDialog::NntpAccountConfDialog( KNNntpAccount *a, QWidget *parent ) :
00437     KPageDialog( parent ),
00438     mAccount( a ),
00439     mUseServerForName( false )
00440 {
00441   if ( a->id() != -1 )
00442     setCaption( i18n("Properties of %1", a->name()) );
00443   else
00444     setCaption( i18n("New Account") );
00445   setFaceType( Tabbed );
00446   setButtons( Ok | Cancel | Help );
00447   setDefaultButton( Ok );
00448 
00449   // server config tab
00450   QFrame* page = new QFrame( this );
00451   addPage( page, i18n("Ser&ver") );
00452   setupUi( page );
00453 
00454   mName->setText( a->name() );
00455   mServer->setText( a->server() );
00456   mPort->setValue( a->port() );
00457 #ifndef Q_WS_WIN
00458 // don't know how to set this in KDE4, where no related methods exists
00459   mPort->setSliderEnabled( false );
00460 #endif
00461   mFetchDesc->setChecked( a->fetchDescriptions() );
00462 
00463   connect( mServer, SIGNAL( textChanged( const QString& ) ),
00464            this, SLOT( slotServerTextEdited() ) );
00465   connect( mServer, SIGNAL( editingFinished() ),
00466            this, SLOT( slotEditingFinished() ) );
00467 
00468   mLogin->setChecked( a->needsLogon() );
00469   mUser->setText( a->user() );
00470 
00471   connect( knGlobals.accountManager(), SIGNAL(passwordsChanged()), SLOT(slotPasswordChanged()) );
00472   if ( a->readyForLogin() )
00473     mPassword->setText( a->pass() );
00474   else
00475     if ( a->needsLogon() )
00476       knGlobals.accountManager()->loadPasswordsAsync();
00477 
00478   switch ( mAccount->encryption() ) {
00479     case KNServerInfo::None:
00480       mEncNone->setChecked( true );
00481       break;
00482     case KNServerInfo::SSL:
00483       mEncSSL->setChecked( true );
00484       break;
00485     case KNServerInfo::TLS:
00486       mEncTLS->setChecked( true );
00487       break;
00488   }
00489 
00490   mIntervalChecking->setChecked( a->intervalChecking() );
00491   mInterval->setValue( a->checkInterval() );
00492 
00493   // identity tab
00494   mIdentityWidget = new KNode::IdentityWidget( a->identity(), knGlobals.componentData(), this );
00495   addPage( mIdentityWidget, i18n("&Identity") );
00496 
00497   // per server cleanup configuration
00498   mCleanupWidget = new GroupCleanupWidget( a->cleanupConfig(), this );
00499   addPage( mCleanupWidget, i18n("&Cleanup") );
00500   mCleanupWidget->load();
00501 
00502   KNHelper::restoreWindowSize("accNewsPropDLG", this, sizeHint());
00503 
00504   setHelp("anc-setting-the-news-account");
00505 }
00506 
00507 
00508 KNode::NntpAccountConfDialog::~NntpAccountConfDialog()
00509 {
00510   KNHelper::saveWindowSize("accNewsPropDLG", size());
00511 }
00512 
00513 void KNode::NntpAccountConfDialog::slotServerTextEdited()
00514 {
00515   if ( mName->text().trimmed() == "" ) {
00516     mUseServerForName = true;
00517   }
00518 
00519   if ( mUseServerForName ) {
00520     mName->setText( mServer->text() );
00521   }
00522 }
00523 
00524 void KNode::NntpAccountConfDialog::slotEditingFinished()
00525 {
00526   mUseServerForName = false;
00527 }
00528 
00529 void KNode::NntpAccountConfDialog::slotButtonClicked( int button )
00530 {
00531   if ( button == KDialog::Ok ) {
00532     if ( mName->text().isEmpty() || mServer->text().trimmed().isEmpty() ) {
00533       KMessageBox::sorry(this, i18n("Please enter an arbitrary name for the account and the\nhostname of the news server."));
00534       return;
00535     }
00536 
00537     mAccount->setName( mName->text() );
00538     mAccount->setServer( mServer->text().trimmed() );
00539     mAccount->setPort( mPort->value() );
00540     mAccount->setFetchDescriptions( mFetchDesc->isChecked() );
00541     mAccount->setNeedsLogon( mLogin->isChecked() );
00542     mAccount->setUser( mUser->text() );
00543     mAccount->setPass( mPassword->text() );
00544 
00545     if ( mEncNone->isChecked() )
00546       mAccount->setEncryption( KNServerInfo::None );
00547     if ( mEncSSL->isChecked() )
00548       mAccount->setEncryption( KNServerInfo::SSL );
00549     if ( mEncTLS->isChecked() )
00550       mAccount->setEncryption( KNServerInfo::TLS );
00551 
00552     mAccount->setIntervalChecking( mIntervalChecking->isChecked() );
00553     mAccount->setCheckInterval( mInterval->value() );
00554 
00555     if ( mAccount->id() != -1 ) // only save if account has a valid id
00556       mAccount->saveInfo();
00557 
00558     mIdentityWidget->save();
00559     mCleanupWidget->save();
00560 
00561     accept();
00562   } else {
00563     KDialog::slotButtonClicked( button );
00564   }
00565 }
00566 
00567 
00568 void KNode::NntpAccountConfDialog::slotPasswordChanged()
00569 {
00570   if ( mPassword->text().isEmpty() )
00571     mPassword->setText( mAccount->pass() );
00572 }
00573 
00574 //END: NNTP account configuration widgets ------------------------------------
00575 
00576 //===================================================================================
00577 
00578 KNode::AppearanceWidget::ColorListItem::ColorListItem( const QString &text, const QColor &color, QListWidget *parent ) :
00579   QListWidgetItem( text, parent )
00580 {
00581   setColor( color );
00582 }
00583 
00584 
00585 void KNode::AppearanceWidget::ColorListItem::setColor( const QColor &color )
00586 {
00587   mColor = color;
00588   int height = QFontMetrics( font() ).height();
00589   QPixmap icon( height, height );
00590   QPainter p( &icon );
00591   p.setPen( Qt::black );
00592   p.drawRect( 0, 0, height - 1, height - 1 );
00593   p.fillRect( 1, 1, height - 2, height - 2, color );
00594   setIcon( icon );
00595   if ( listWidget() )
00596     listWidget()->update();
00597 }
00598 
00599 
00600 //===================================================================================
00601 
00602 
00603 KNode::AppearanceWidget::FontListItem::FontListItem( const QString &text, const QFont &font, QListWidget *parent ) :
00604   QListWidgetItem( parent ),
00605   mText( text )
00606 {
00607   setFont( font );
00608 }
00609 
00610 
00611 void KNode::AppearanceWidget::FontListItem::setFont( const QFont &font )
00612 {
00613   mFont = font;
00614   setText( QString("[%1 %2] %3").arg( mFont.family() ).arg( mFont.pointSize() ).arg( mText ) );
00615   if ( listWidget() )
00616     listWidget()->update();
00617 }
00618 
00619 
00620 //===================================================================================
00621 
00622 
00623 KNode::AppearanceWidget::AppearanceWidget( const KComponentData &inst, QWidget *parent ) :
00624   KCModule(inst, parent )
00625 {
00626   QGridLayout *topL = new QGridLayout( this );
00627 
00628   //color-list
00629   mColorList = new QListWidget( this );
00630   topL->addWidget( mColorList, 1, 0, 3, 2 );
00631   connect( mColorList, SIGNAL( itemActivated( QListWidgetItem* ) ), SLOT( slotColItemActivated( QListWidgetItem* ) ) );
00632   connect( mColorList, SIGNAL( itemSelectionChanged() ), SLOT( slotColSelectionChanged() ) );
00633 
00634   c_olorCB = new QCheckBox(i18n("&Use custom colors"),this);
00635   c_olorCB->setObjectName( "kcfg_useCustomColors" );
00636   topL->addWidget( c_olorCB, 0, 0, 1, 3 );
00637   connect(c_olorCB, SIGNAL(toggled(bool)), this, SLOT(slotColCheckBoxToggled(bool)));
00638 
00639   c_olChngBtn=new QPushButton(i18n("Cha&nge..."), this);
00640   connect(c_olChngBtn, SIGNAL(clicked()), this, SLOT(slotColChangeBtnClicked()));
00641   topL->addWidget( c_olChngBtn, 1, 2, 1, 1 );
00642 
00643   //font-list
00644   mFontList = new QListWidget( this );
00645   topL->addWidget( mFontList, 5, 0, 3, 2 );
00646   connect( mFontList, SIGNAL( itemActivated( QListWidgetItem* ) ), SLOT( slotFontItemActivated( QListWidgetItem* ) ) );
00647   connect( mFontList, SIGNAL( itemSelectionChanged() ), SLOT( slotFontSelectionChanged() ) );
00648 
00649   f_ontCB = new QCheckBox(i18n("Use custom &fonts"),this);
00650   f_ontCB->setObjectName( "kcfg_useCustomFonts" );
00651   topL->addWidget(f_ontCB , 4, 0, 1, 3 );
00652   connect(f_ontCB, SIGNAL(toggled(bool)), this, SLOT(slotFontCheckBoxToggled(bool)));
00653 
00654   f_ntChngBtn=new QPushButton(i18n("Chang&e..."), this);
00655   connect(f_ntChngBtn, SIGNAL(clicked()), this, SLOT(slotFontChangeBtnClicked()));
00656   topL->addWidget( f_ntChngBtn, 5, 2, 1, 1 );
00657 
00658   topL->setColumnStretch( 0, 1 );
00659 
00660   addConfig( knGlobals.settings(), this );
00661   load();
00662 }
00663 
00664 
00665 void KNode::AppearanceWidget::load()
00666 {
00667   KCModule::load();
00668 
00669   slotColCheckBoxToggled( c_olorCB->isChecked() );
00670   slotFontCheckBoxToggled( f_ontCB->isChecked() );
00671 
00672   KConfigSkeletonItem::List items = knGlobals.settings()->items();
00673   mColorList->clear();
00674   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00675     KConfigSkeleton::ItemColor *item = dynamic_cast<KConfigSkeleton::ItemColor*>( *it );
00676     if ( item )
00677       mColorList->addItem( new ColorListItem( item->label(), item->value() ) );
00678   }
00679 
00680   mFontList->clear();
00681   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00682     KConfigSkeleton::ItemFont *item = dynamic_cast<KConfigSkeleton::ItemFont*>( *it );
00683     if ( item )
00684       mFontList->addItem( new FontListItem( item->label(), item->value() ) );
00685   }
00686 }
00687 
00688 
00689 void KNode::AppearanceWidget::save()
00690 {
00691   KConfigSkeletonItem::List items = knGlobals.settings()->items();
00692   int row = 0;
00693   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00694     KConfigSkeleton::ItemColor *item = dynamic_cast<KConfigSkeleton::ItemColor*>( *it );
00695     if ( !item )
00696       continue;
00697     item->setValue( static_cast<ColorListItem*>( mColorList->item( row ) )->color() );
00698     ++row;
00699   }
00700 
00701   row = 0;
00702   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00703     KConfigSkeleton::ItemFont *item = dynamic_cast<KConfigSkeleton::ItemFont*>( *it );
00704     if ( !item )
00705       continue;
00706     item->setValue( static_cast<FontListItem*>( mFontList->item( row ) )->font() );
00707     ++row;
00708   }
00709 
00710   KCModule::save();
00711 
00712   knGlobals.configManager()->appearance()->recreateLVIcons();
00713 }
00714 
00715 
00716 void KNode::AppearanceWidget::defaults()
00717 {
00718   KCModule::defaults();
00719 
00720   KConfigSkeletonItem::List items = knGlobals.settings()->items();
00721   int row = 0;
00722   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00723     KConfigSkeleton::ItemColor *item = dynamic_cast<KConfigSkeleton::ItemColor*>( *it );
00724     if ( !item )
00725       continue;
00726     item->setDefault();
00727     static_cast<ColorListItem*>( mColorList->item( row ) )->setColor( item->value() );
00728     ++row;
00729   }
00730 
00731   row = 0;
00732   for ( KConfigSkeletonItem::List::Iterator it = items.begin(); it != items.end(); ++it ) {
00733     KConfigSkeleton::ItemFont *item = dynamic_cast<KConfigSkeleton::ItemFont*>( *it );
00734     if ( !item )
00735       continue;
00736     item->setDefault();
00737     static_cast<FontListItem*>( mFontList->item( row ) )->setFont( item->value() );
00738     ++row;
00739   }
00740 
00741   emit changed(true);
00742 }
00743 
00744 
00745 void KNode::AppearanceWidget::slotColCheckBoxToggled(bool b)
00746 {
00747   mColorList->setEnabled( b );
00748   c_olChngBtn->setEnabled( b && mColorList->currentItem() );
00749   if (b) mColorList->setFocus();
00750 }
00751 
00752 
00753 // show color dialog for the entry
00754 void KNode::AppearanceWidget::slotColItemActivated( QListWidgetItem *item )
00755 {
00756   if ( item ) {
00757     ColorListItem *colorItem = static_cast<ColorListItem*>( item );
00758     QColor col = colorItem->color();
00759     int result = KColorDialog::getColor(col,this);
00760 
00761     if (result == KColorDialog::Accepted) {
00762       colorItem->setColor(col);
00763     }
00764   }
00765   emit changed(true);
00766 }
00767 
00768 
00769 void KNode::AppearanceWidget::slotColChangeBtnClicked()
00770 {
00771   if ( mColorList->currentItem() )
00772     slotColItemActivated( mColorList->currentItem() );
00773 }
00774 
00775 
00776 void KNode::AppearanceWidget::slotColSelectionChanged()
00777 {
00778   c_olChngBtn->setEnabled( mColorList->currentItem() );
00779 }
00780 
00781 
00782 void KNode::AppearanceWidget::slotFontCheckBoxToggled(bool b)
00783 {
00784   mFontList->setEnabled( b );
00785   f_ntChngBtn->setEnabled( b && mFontList->currentItem() );
00786   if (b) mFontList->setFocus();
00787 }
00788 
00789 
00790 // show font dialog for the entry
00791 void KNode::AppearanceWidget::slotFontItemActivated( QListWidgetItem *item )
00792 {
00793   if ( item ) {
00794     FontListItem *fontItem = static_cast<FontListItem*>( item );
00795     QFont font = fontItem->font();
00796     int result = KFontDialog::getFont(font,false,this);
00797 
00798     if (result == KFontDialog::Accepted)
00799       fontItem->setFont(font);
00800   }
00801   emit changed(true);
00802 }
00803 
00804 
00805 void KNode::AppearanceWidget::slotFontChangeBtnClicked()
00806 {
00807   if ( mFontList->currentItem() )
00808     slotFontItemActivated( mFontList->currentItem() );
00809 }
00810 
00811 
00812 void