00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "serverdialog.h"
00019
00020 ServerDialog::ServerDialog( QWidget* parent, ConfigElem* item )
00021 : KDialogBase( parent, "ServerDialog", true, QString::null, Ok|Cancel, Ok, true )
00022 {
00023
00024 account = item;
00025
00026
00027 QWidget* page = new QWidget( this );
00028 setMainWidget( page );
00029
00030
00031 QVBoxLayout* layMain = new QVBoxLayout( page, 0, spacingHint() );
00032 QGridLayout* layTop = new QGridLayout( layMain, 5, 2 );
00033
00034
00035 QLabel* lblAccount = new QLabel( i18n( "Account:" ), page, "lblAccount" );
00036 txtAccount = new KLineEdit( page, "txtAccount" );
00037 txtAccount->setEnabled( false );
00038 QToolTip::add( lblAccount, i18n( "Unique Account Name" ) );
00039 QToolTip::add( txtAccount, i18n( "Unique Account Name" ) );
00040 layTop->addWidget( lblAccount, 0, 0 );
00041 layTop->addWidget( txtAccount, 0, 1 );
00042
00043 QLabel* lblServer = new QLabel( i18n( "Server:" ), page, "lblServer" );
00044 txtServer = new KLineEdit( page, "txtServer" );
00045 txtServer->setFocus();
00046 QToolTip::add( lblServer, i18n( "Server Name" ) );
00047 QToolTip::add( txtAccount, i18n( "Server Name" ) );
00048 layTop->addWidget( lblServer, 1, 0 );
00049 layTop->addWidget( txtServer, 1, 1 );
00050
00051 QLabel* lblProtocol = new QLabel( i18n( "Protocol:" ), page, "lblProtocol" );
00052 cboProtocol = new KComboBox( page, "cboProtocol" );
00053 cboProtocol->insertItem( "POP3" );
00054 QToolTip::add( lblProtocol, i18n( "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") );
00055 QToolTip::add( cboProtocol, i18n( "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") );
00056 layTop->addWidget( lblProtocol, 2, 0 );
00057 layTop->addWidget( cboProtocol, 2, 1 );
00058
00059 QLabel* lblPort = new QLabel( i18n( "Port:" ), page, "lblPort" );
00060 spbPort = new QSpinBox( 0, 65535, 1, page, "spbPort" );
00061 spbPort->setValue( DEFAULT_PORT_POP3 );
00062 QToolTip::add( lblPort, i18n( "Port Number. Normally POP3 uses port 110." ) );
00063 QToolTip::add( spbPort, i18n( "Port Number. Normally POP3 uses port 110." ) );
00064 layTop->addWidget( lblPort, 3, 0 );
00065 layTop->addWidget( spbPort, 3, 1 );
00066
00067 QLabel* lblUser = new QLabel( i18n( "User:" ), page, "lblUser" );
00068 txtUser = new KLineEdit( page, "txtUser" );
00069 QToolTip::add( lblUser, i18n( "To authenticate to the mail server you need an user name." ) );
00070 QToolTip::add( txtUser, i18n( "To authenticate to the mail server you need an user name." ) );
00071 layTop->addWidget( lblUser, 4, 0 );
00072 layTop->addWidget( txtUser, 4, 1 );
00073
00074
00075 QGroupBox* gboxPassword = new QGroupBox( 0, Qt::Horizontal, i18n( "Password" ), page, "gboxPassword" );
00076 layMain->addWidget( gboxPassword );
00077
00078 QVBoxLayout* layPassword = new QVBoxLayout( gboxPassword->layout(), spacingHint() );
00079 QGridLayout* layPasswordStorage = new QGridLayout( layPassword, 2, 2, spacingHint() );
00080
00081
00082
00083 grpPasswordStorage = new QButtonGroup( NULL, "grpPasswordStorage" );
00084 connect( grpPasswordStorage, SIGNAL( clicked( int ) ), this, SLOT( slotPasswordStorageChanged( int ) ) );
00085
00086 QRadioButton* btnPasswordDontSave = new QRadioButton( i18n( "Don't save" ), gboxPassword, "btnPasswordDontSave" );
00087 QRadioButton* btnPasswordSaveFile = new QRadioButton( i18n( "Save password"), gboxPassword, "btnPasswordSaveFile" );
00088 QRadioButton* btnPasswordSaveKWallet = new QRadioButton( i18n( "Use KWallet" ), gboxPassword, "btnPasswordSaveKWallet" );
00089 grpPasswordStorage->insert( btnPasswordDontSave, ID_BUTTON_PASSWORD_DONT_SAVE );
00090 grpPasswordStorage->insert( btnPasswordSaveFile, ID_BUTTON_PASSWORD_SAVE_FILE );
00091 grpPasswordStorage->insert( btnPasswordSaveKWallet, ID_BUTTON_PASSWORD_SAVE_KWALLET );
00092 QToolTip::add( btnPasswordDontSave, i18n( "Don't save password. KShowmail will ask you for it at first server connect." ) );
00093 QToolTip::add( btnPasswordSaveFile, i18n( "Save password in the configuration file. Not recommended, because the password is just lightly encrypted" ) );
00094 QToolTip::add( btnPasswordSaveKWallet, i18n( "Use KWallet to save the password. Maybe you have to type in the KWallet master password at first server connect." ) );
00095 layPasswordStorage->addWidget( btnPasswordDontSave, 0, 0 );
00096 layPasswordStorage->addWidget( btnPasswordSaveFile, 0, 1 );
00097 layPasswordStorage->addWidget( btnPasswordSaveKWallet, 1, 0 );
00098
00099
00100 txtPassword = new KPasswordEdit( gboxPassword, "txtUser" );
00101 layPassword->addWidget( txtPassword );
00102
00103
00104 grpPasswordStorage->setButton( DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00105 slotPasswordStorageChanged( DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00106
00107
00108 QGridLayout* layActive = new QGridLayout( layMain, 1, 1 );
00109 layActive->setAlignment( Qt::AlignCenter );
00110 chkActive = new QCheckBox( i18n( "Active"), page, "chkActive" );
00111 QToolTip::add( chkActive, i18n( "Select it to activate this account." ) );
00112 layActive->addWidget( chkActive, 0, 0 );
00113 chkActive->setChecked( DEFAULT_ACCOUNT_ACTIVE );
00114
00115
00116 if( item == NULL )
00117 setCaption( i18n( "New account" ) );
00118 else
00119 setCaption( i18n( "Edit account" ) );
00120
00121
00122 if( account != NULL )
00123 fillDialog();
00124
00125
00126 }
00127
00128
00129 ServerDialog::~ServerDialog()
00130 {
00131 }
00132
00133 void ServerDialog::slotPasswordStorageChanged( int id )
00134 {
00135 if( id == ID_BUTTON_PASSWORD_DONT_SAVE )
00136 {
00137 txtPassword->setEnabled( false );
00138 txtPassword->clear();
00139 }
00140 else
00141 txtPassword->setEnabled( true );
00142 }
00143
00144 void ServerDialog::slotOk( )
00145 {
00146
00147 if( account == NULL )
00148 {
00149 kdError() << "ServerDialog::slotOk: Given account pointer is Null." << endl;
00150 return;
00151 }
00152 if( txtServer->text() == "" )
00153 {
00154 KMessageBox::error( this, i18n( "Please enter an server." ) );
00155 return;
00156 }
00157
00158 if( txtUser->text() == "" )
00159 {
00160 KMessageBox::error( this, i18n( "Please enter an user name." ) );
00161 return;
00162 }
00163
00164
00165 KConfig* config = KApplication::kApplication()->config();
00166
00167 config->setGroup( txtAccount->text() );
00168
00169 config->writeEntry( CONFIG_ENTRY_ACCOUNT_SERVER, txtServer->text() );
00170 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, cboProtocol->currentText().upper() );
00171 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PORT, spbPort->value() );
00172 config->writeEntry( CONFIG_ENTRY_ACCOUNT_USER, txtUser->text() );
00173
00174
00175
00176
00177
00178
00179 QString pass;
00180 if( txtPassword->password() == "" || txtPassword->password() == QString::null )
00181 pass = txtPassword->text();
00182 else
00183 pass = txtPassword->password();
00184
00185
00186 KURL url;
00187 url.setUser( txtUser->text() );
00188 url.setHost( txtServer->text() );
00189 url.setPass( pass );
00190
00191
00192 switch( grpPasswordStorage->selectedId() )
00193 {
00194 case ID_BUTTON_PASSWORD_DONT_SAVE : config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE );
00195 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, QString::null );
00196 break;
00197 case ID_BUTTON_PASSWORD_SAVE_FILE : config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE );
00198 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, crypt( url ) );
00199 break;
00200 case ID_BUTTON_PASSWORD_SAVE_KWALLET : config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET );
00201 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, QString::null );
00202 KWalletAccess::savePassword( txtAccount->text(), pass );
00203 break;
00204 default : config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE );
00205 config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, QString::null );
00206 }
00207
00208 config->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, chkActive->isChecked() );
00209
00210
00211 config->sync();
00212
00213
00214 KDialogBase::slotOk();
00215 }
00216
00217 void ServerDialog::fillDialog( )
00218 {
00219
00220 if( account == NULL )
00221 {
00222 kdError() << "ServerDialog::fillDialog: invalid pointer to account item." << endl;
00223 return;
00224 }
00225
00226 txtAccount->setText( account->getAccountName() );
00227 txtServer->setText( account->getHost() );
00228 cboProtocol->setCurrentText( account->getProtocol( true ) );
00229 spbPort->setValue( account->getPort() );
00230 txtUser->setText( account->getUser() );
00231
00232 int type = account->getPasswordStorage();
00233 if( type != CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET )
00234 type = DEFAULT_ACCOUNT_PASSWORD_STORAGE;
00235
00236 switch( type )
00237 {
00238 case CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_DONT_SAVE );
00239 txtPassword->setEnabled( false );
00240 txtPassword->clear();
00241 break;
00242 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_SAVE_FILE );
00243 txtPassword->setEnabled( true );
00244 txtPassword->setText( account->getPassword() );
00245 break;
00246 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_SAVE_KWALLET );
00247 txtPassword->setEnabled( true );
00248 txtPassword->setText( account->getPassword() );
00249 break;
00250 default : grpPasswordStorage->setButton( 1 );
00251 txtPassword->clear();
00252 }
00253
00254 chkActive->setChecked( account->isActive() );
00255 }
00256
00257 #include "serverdialog.moc"