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