00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "accountsetupdialogcontext.h"
00019
00020 AccountSetupDialogContext::AccountSetupDialogContext( QWidget* parent, QString accountName )
00021 : KDialog( parent )
00022 {
00023
00024
00025 accName = accountName;
00026
00027
00028 KTabWidget* tabs = new KTabWidget( this );
00029
00030
00031 QWidget* pgGeneral = new QWidget( this );
00032 QWidget* pgSecurity = new QWidget( this );
00033 setMainWidget( tabs );
00034
00035
00036 QVBoxLayout* layGeneral = new QVBoxLayout( pgGeneral );
00037 QGridLayout* layTop = new QGridLayout();
00038 layGeneral->addLayout( layTop );
00039
00040
00041 QVBoxLayout* laySecurity = new QVBoxLayout( pgSecurity );
00042 laySecurity->setAlignment( Qt::AlignTop );
00043
00044
00045 QLabel* lblAccount = new QLabel( i18nc( "@label:textbox account name", "Account:" ), pgGeneral );
00046 txtAccount = new KLineEdit( pgGeneral );
00047 txtAccount->setEnabled( false );
00048 txtAccount->setFocus();
00049 lblAccount->setToolTip( i18nc( "@info:tooltip", "Unique Account Name" ) );
00050 txtAccount->setToolTip( i18nc( "@info:tooltip", "Unique Account Name" ) );
00051 layTop->addWidget( lblAccount, 0, 0 );
00052 layTop->addWidget( txtAccount, 0, 1 );
00053
00054 QLabel* lblServer = new QLabel( i18nc( "@label:textbox server host name", "Server:" ), pgGeneral );
00055 txtServer = new KLineEdit( pgGeneral );
00056 lblServer->setToolTip( i18nc( "@info:tooltip", "Server Name" ) );
00057 txtServer->setToolTip( i18nc( "@info:tooltip", "Server Name" ) );
00058 layTop->addWidget( lblServer, 1, 0 );
00059 layTop->addWidget( txtServer, 1, 1 );
00060
00061 QLabel* lblProtocol = new QLabel( i18nc( "@label:listbox mail fetching protocol", "Protocol:" ), pgGeneral );
00062 cboProtocol = new KComboBox( pgGeneral );
00063 cboProtocol->insertItem( 0, "POP3" );
00064 lblProtocol->setToolTip( i18nc( "@info:tooltip", "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") );
00065 cboProtocol->setToolTip( i18nc( "@info:tooltip", "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") );
00066 layTop->addWidget( lblProtocol, 2, 0 );
00067 layTop->addWidget( cboProtocol, 2, 1 );
00068
00069 QLabel* lblPort = new QLabel( i18nc( "@label:spinbox TCP port, on which the server is listening", "Port:" ), pgGeneral );
00070 spbPort = new QSpinBox( pgGeneral );
00071 spbPort->setRange( 0, 65535 );
00072 spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 );
00073 lblPort->setToolTip( i18nc( "@info:tooltip", "Port Number. Normally POP3 uses port 110." ) );
00074 spbPort->setToolTip( i18nc( "@info:tooltip", "Port Number. Normally POP3 uses port 110." ) );
00075 layTop->addWidget( lblPort, 3, 0 );
00076 layTop->addWidget( spbPort, 3, 1 );
00077
00078 QLabel* lblUser = new QLabel( i18nc( "@label:textbox user name to authenticate", "User:" ), pgGeneral );
00079 txtUser = new KLineEdit( pgGeneral );
00080 lblUser->setToolTip( i18nc( "@info:tooltip", "To authenticate to the mail server you need an user name." ) );
00081 txtUser->setToolTip( i18nc( "@info:tooltip", "To authenticate to the mail server you need an user name." ) );
00082 layTop->addWidget( lblUser, 4, 0 );
00083 layTop->addWidget( txtUser, 4, 1 );
00084
00085
00086 QGroupBox* gboxPassword = new QGroupBox( i18nc( "@title:group contains password storage options and passwort input textbox", "Password" ), pgGeneral );
00087 layGeneral->addWidget( gboxPassword );
00088
00089 QVBoxLayout* layPassword = new QVBoxLayout( );
00090 gboxPassword->setLayout( layPassword );
00091 QGridLayout* layPasswordStorage = new QGridLayout();
00092 layPassword->addLayout( layPasswordStorage );
00093
00094
00095
00096 grpPasswordStorage = new QButtonGroup( NULL );
00097 connect( grpPasswordStorage, SIGNAL( buttonClicked( int ) ), this, SLOT( slotPasswordStorageChanged( int ) ) );
00098
00099 QRadioButton* btnPasswordDontSave = new QRadioButton( i18nc( "@option:radio don't save the password", "Don't save" ), gboxPassword );
00100 QRadioButton* btnPasswordSaveFile = new QRadioButton( i18nc( "@option:radio save passwort in config file", "Save password "), gboxPassword );
00101 QRadioButton* btnPasswordSaveKWallet = new QRadioButton( i18nc( "@option:radio use KWallet to save the password", "Use KWallet" ), gboxPassword );
00102 grpPasswordStorage->addButton( btnPasswordDontSave, ID_BUTTON_PASSWORD_DONT_SAVE );
00103 grpPasswordStorage->addButton( btnPasswordSaveFile, ID_BUTTON_PASSWORD_SAVE_FILE );
00104 grpPasswordStorage->addButton( btnPasswordSaveKWallet, ID_BUTTON_PASSWORD_SAVE_KWALLET );
00105 btnPasswordDontSave->setToolTip( i18nc( "@info:tooltip", "Don't save password. KShowmail will ask you for it at first server connect." ) );
00106 btnPasswordSaveFile->setToolTip( i18nc( "@info:tooltip", "Save password in the configuration file. Not recommended, because the password is just lightly encrypted" ) );
00107 btnPasswordSaveKWallet->setToolTip( i18nc( "@info:tooltip", "Use KWallet to save the password. Maybe you have to type in the KWallet master password at first server connect." ) );
00108 layPasswordStorage->addWidget( btnPasswordDontSave, 0, 0 );
00109 layPasswordStorage->addWidget( btnPasswordSaveFile, 0, 1 );
00110 layPasswordStorage->addWidget( btnPasswordSaveKWallet, 1, 0 );
00111
00112
00113
00114 txtPassword = new KLineEdit( gboxPassword );
00115 txtPassword->setPasswordMode( true );
00116 layPassword->addWidget( txtPassword );
00117
00118
00119 QRadioButton* btnToCheck = static_cast<QRadioButton*>( grpPasswordStorage->button( DEFAULT_ACCOUNT_PASSWORD_STORAGE ) );
00120 btnToCheck->setChecked( true );
00121 slotPasswordStorageChanged( DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00122
00123
00124 QGridLayout* layActive = new QGridLayout();
00125 layGeneral->addLayout( layActive );
00126 layActive->setAlignment( Qt::AlignCenter );
00127 chkActive = new QCheckBox( i18nc( "@option:check to activate this account", "Active"), pgGeneral );
00128 chkActive->setToolTip( i18nc( "@info:tooltip", "Select it to activate this account." ) );
00129 layActive->addWidget( chkActive, 0, 0 );
00130 chkActive->setChecked( DEFAULT_ACCOUNT_ACTIVE );
00131
00132
00133 QGroupBox* gboxSecureTransfer = new QGroupBox( i18nc( "@title:group transfer encryption", "Encryption" ), pgSecurity );
00134 gboxSecureTransfer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum ) );
00135 laySecurity->addWidget( gboxSecureTransfer );
00136
00137 QHBoxLayout* laySecureTransfer = new QHBoxLayout();
00138 gboxSecureTransfer->setLayout( laySecureTransfer );
00139
00140
00141 grpSecureTransfer = new QButtonGroup( NULL );
00142 connect( grpSecureTransfer, SIGNAL( buttonClicked( int ) ), this, SLOT( slotSecureTransferChanged ( int ) ) );
00143
00144 QRadioButton* btnSecureTransferNone = new QRadioButton( i18nc( "@option:radio encryption", "None" ), gboxSecureTransfer );
00145 QRadioButton* btnSecureTransferSSL = new QRadioButton( i18nc( "@option:radio encryption", "SSL"), gboxSecureTransfer );
00146 QRadioButton* btnSecureTransferTLS = new QRadioButton( i18nc( "@option:radio encryption", "TLS" ), gboxSecureTransfer );
00147 grpSecureTransfer->addButton( btnSecureTransferNone, ID_BUTTON_SECTRANSFER_NONE );
00148 grpSecureTransfer->addButton( btnSecureTransferSSL, ID_BUTTON_SECTRANSFER_SSL );
00149 grpSecureTransfer->addButton( btnSecureTransferTLS, ID_BUTTON_SECTRANSFER_TLS );
00150 btnSecureTransferNone->setToolTip( i18nc( "@info:tooltip", "The download of the mail header and body will not be encrypted. Use this, if your provider doesn't make a secure transfer available." ) );
00151 btnSecureTransferSSL->setToolTip( i18nc( "@info:tooltip", "Secure Sockets Layer (SSL), is a cryptographic protocol that provides secure communications on the Internet." ) );
00152 btnSecureTransferTLS->setToolTip( i18nc( "@info:tooltip", "Transport Layer Security (TLS) is a cryptographic protocol that provides secure communications on the Internet. It is the successor of SSL." ) );
00153 laySecureTransfer->addWidget( btnSecureTransferNone );
00154 laySecureTransfer->addWidget( btnSecureTransferSSL );
00155 laySecureTransfer->addWidget( btnSecureTransferTLS );
00156
00157 btnToCheck = static_cast<QRadioButton*>( grpSecureTransfer->button( DEFAULT_ACCOUNT_SECTRANSFER ) );
00158 btnToCheck->setChecked( true );
00159
00160
00161 chkAllowUnsecureLogin = new QCheckBox( i18nc( "@option:check whether login without security shall be allowed", "Allow unsafe login"), pgSecurity );
00162 chkAllowUnsecureLogin->setToolTip( i18nc( "@info:tooltip", "Select it to allow an unsafe login if necessary.\nThe password will be transmit unencrypted. Maybe someone can read it!" ) );
00163 laySecurity->addWidget( chkAllowUnsecureLogin );
00164 chkAllowUnsecureLogin->setChecked( DEFAULT_ACCOUNT_ALLOW_UNSECURE_LOGIN );
00165
00166
00167
00168 tabs->addTab( pgGeneral, i18nc( "@title:tab general account options", "General" ) );
00169 tabs->addTab( pgSecurity, i18nc( "@title:tab account security options", "Security" ) );
00170
00171
00172 setCaption( i18nc( "@title:window title of account setup dialog", "Edit Account <resource>%1</resource>", accName ) );
00173
00174
00175 load();
00176 }
00177
00178
00179 AccountSetupDialogContext::~AccountSetupDialogContext()
00180 {
00181 }
00182
00183 void AccountSetupDialogContext::slotPasswordStorageChanged( int id )
00184 {
00185 if( id == ID_BUTTON_PASSWORD_DONT_SAVE )
00186 {
00187 txtPassword->setEnabled( false );
00188 txtPassword->clear();
00189 }
00190 else
00191 txtPassword->setEnabled( true );
00192 }
00193
00194 void AccountSetupDialogContext::slotButtonClicked( int button )
00195 {
00196
00197 if( button != KDialog::Ok )
00198 {
00199 KDialog::slotButtonClicked( button );
00200 return;
00201 }
00202
00203
00204 if( txtServer->text().isEmpty() )
00205 {
00206 KMessageBox::error( this, i18nc( "@info error message: no server was entered", "Please enter an server." ) );
00207 return;
00208 }
00209
00210 if( txtUser->text().isEmpty() )
00211 {
00212 KMessageBox::error( this, i18nc( "@info error message: no user name was entered", "Please enter an user name." ) );
00213 return;
00214 }
00215
00216 save();
00217
00218
00219
00220 KDialog::slotButtonClicked( KDialog::Ok );
00221 }
00222
00223 void AccountSetupDialogContext::load()
00224 {
00225
00226 KConfigGroup* configAcc = new KConfigGroup( KGlobal::config(), accName );
00227
00228
00229 txtAccount->setText( accName );
00230
00231 txtServer->setText( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_SERVER, DEFAULT_ACCOUNT_SERVER ) );
00232
00233 QString strProto = configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, DEFAULT_ACCOUNT_PROTOCOL ).toUpper();
00234 if( strProto == CONFIG_VALUE_ACCOUNT_PROTOCOL_POP3 ) {
00235 cboProtocol->setCurrentIndex( 0 );
00236 }
00237
00238 spbPort->setValue( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_PORT, DEFAULT_ACCOUNT_PORT_POP3 ) );
00239
00240 txtUser->setText( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_USER, DEFAULT_ACCOUNT_USER ) );
00241
00242 int type = configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00243 if( type != CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
00244 type = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
00245
00246 QRadioButton* btnToCheck;
00247 switch( type )
00248 {
00249 case CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE : btnToCheck = static_cast<QRadioButton*>( grpPasswordStorage->button( ID_BUTTON_PASSWORD_DONT_SAVE ) );
00250 txtPassword->setEnabled( false );
00251 txtPassword->clear();
00252 break;
00253 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE : btnToCheck = static_cast<QRadioButton*>( grpPasswordStorage->button( ID_BUTTON_PASSWORD_SAVE_FILE ) );
00254 txtPassword->setEnabled( true );
00255 txtPassword->setText( decrypt( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, DEFAULT_ACCOUNT_PASSWORD ) ) );
00256 break;
00257 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET : btnToCheck = static_cast<QRadioButton*>( grpPasswordStorage->button( ID_BUTTON_PASSWORD_SAVE_KWALLET ) );
00258 txtPassword->setEnabled( true );
00259 txtPassword->setText( KWalletAccess::getPassword( accName ) );
00260 break;
00261 default : btnToCheck = static_cast<QRadioButton*>( grpPasswordStorage->button( 1 ) );
00262 txtPassword->clear();
00263 }
00264 btnToCheck->setChecked( true );
00265
00266 chkActive->setChecked( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, DEFAULT_ACCOUNT_ACTIVE ) );
00267
00268 int transferSecurity = configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, DEFAULT_ACCOUNT_SECTRANSFER );
00269 if( transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE && transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL && transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS )
00270 transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER;
00271
00272 switch( transferSecurity )
00273 {
00274 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE : btnToCheck = static_cast<QRadioButton*>( grpSecureTransfer->button( ID_BUTTON_SECTRANSFER_NONE ) ); break;
00275 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL : btnToCheck = static_cast<QRadioButton*>( grpSecureTransfer->button( ID_BUTTON_SECTRANSFER_SSL ) ); break;
00276 case CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS : btnToCheck = static_cast<QRadioButton*>( grpSecureTransfer->button( ID_BUTTON_SECTRANSFER_TLS ) ); break;
00277 default : btnToCheck = static_cast<QRadioButton*>( grpSecureTransfer->button( ID_BUTTON_SECTRANSFER_NONE ) ); break;
00278 }
00279 btnToCheck->setChecked( true );
00280
00281 chkAllowUnsecureLogin->setChecked( configAcc->readEntry( CONFIG_ENTRY_ACCOUNT_ALLOW_UNSECURE_LOGIN, DEFAULT_ACCOUNT_ALLOW_UNSECURE_LOGIN ) );
00282
00283
00284 enableLoginCheckbox();
00285
00286 }
00287
00288 void AccountSetupDialogContext::slotSecureTransferChanged( int id )
00289 {
00290 switch( id )
00291 {
00292 case ID_BUTTON_SECTRANSFER_NONE : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); break;
00293 case ID_BUTTON_SECTRANSFER_SSL : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3SSL ); break;
00294 case ID_BUTTON_SECTRANSFER_TLS : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); break;
00295 }
00296
00297
00298 enableLoginCheckbox();
00299
00300 }
00301
00302 void AccountSetupDialogContext::save()
00303 {
00304
00305 KConfigGroup* configAcc = new KConfigGroup( KGlobal::config(), accName );
00306
00307
00308 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_SERVER, txtServer->text() );
00309
00310
00311 if( cboProtocol->currentIndex() == 0 ) {
00312
00313 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, CONFIG_VALUE_ACCOUNT_PROTOCOL_POP3 );
00314 }
00315
00316
00317 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PORT, spbPort->value() );
00318
00319
00320 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_USER, txtUser->text() );
00321
00322
00323 QString pass = txtPassword->text();
00324
00325 KUrl url;
00326 url.setUser( txtUser->text() );
00327 url.setHost( txtServer->text() );
00328 url.setPass( pass );
00329
00330
00331 switch( grpPasswordStorage->checkedId() )
00332 {
00333 case ID_BUTTON_PASSWORD_DONT_SAVE : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE );
00334 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, "" );
00335 break;
00336 case ID_BUTTON_PASSWORD_SAVE_FILE : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE );
00337 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, crypt( url ) );
00338 break;
00339 case ID_BUTTON_PASSWORD_SAVE_KWALLET : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET );
00340 KWalletAccess::savePassword( accName, pass );
00341 break;
00342 default : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE );
00343 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, "" );
00344 }
00345
00346
00347 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, chkActive->isChecked() );
00348
00349
00350 switch( grpSecureTransfer->checkedId() ) {
00351
00352 case ID_BUTTON_SECTRANSFER_NONE : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE ); break;
00353 case ID_BUTTON_SECTRANSFER_SSL : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL ); break;
00354 case ID_BUTTON_SECTRANSFER_TLS : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS ); break;
00355 default : configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, DEFAULT_ACCOUNT_SECTRANSFER );
00356 }
00357
00358
00359 configAcc->writeEntry( CONFIG_ENTRY_ACCOUNT_ALLOW_UNSECURE_LOGIN, chkAllowUnsecureLogin->isChecked() );
00360
00361
00362 configAcc->sync();
00363 }
00364
00365
00366 void AccountSetupDialogContext::enableLoginCheckbox()
00367 {
00368
00369 int transSec = grpSecureTransfer->checkedId();
00370
00371 if( transSec == ID_BUTTON_SECTRANSFER_NONE ) {
00372
00373 chkAllowUnsecureLogin->setEnabled( true );
00374
00375 } else {
00376
00377 chkAllowUnsecureLogin->setEnabled( false );
00378 }
00379
00380 }
00381
00382
00383 #include "accountsetupdialogcontext.moc"