genericeditaccountwidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "genericeditaccountwidget.h"
00021 #include "genericeditaccountwidget.moc"
00022
00023 #include "../blokkalaccount.h"
00024 #include "../blokkalaccountmanager.h"
00025 #include "../blokkalprotocol.h"
00026
00027 #include <klocale.h>
00028 #include <kdialog.h>
00029 #include <klineedit.h>
00030 #include <kdebug.h>
00031
00032 #include <QLayout>
00033 #include <QLabel>
00034 #include <QGroupBox>
00035 #include <QCheckBox>
00036
00037 class Blokkal::Ui::GenericEditAccountWidget::Private {
00038 public:
00039 Private( void ):
00040 accountNameModifiedManually( FALSE ) {}
00041
00042 QVBoxLayout * mainLayout;
00043
00044 QGroupBox * networkGroupBox;
00045
00046 QHBoxLayout * serverNameLayout;
00047 QLabel * serverNameLabel;
00048 KLineEdit * serverNameLineEdit;
00049 QCheckBox * useStandardAddressCheckBox;
00050 KLineEdit * serverAddressLineEdit;
00051 QCheckBox * noAutoConnectCheckBox;
00052
00053 QGroupBox * userGroupBox;
00054
00055 QHBoxLayout * userNameLayout;
00056 QLabel * userNameLabel;
00057 KLineEdit * userNameLineEdit;
00058
00059 QGroupBox * accountGroupBox;
00060
00061 QHBoxLayout * accountNameLayout;
00062 QLabel * accountNameLabel;
00063 KLineEdit * accountNameLineEdit;
00064
00065 bool accountNameModifiedManually;
00066 };
00067
00068 Blokkal::Ui::GenericEditAccountWidget::GenericEditAccountWidget( Blokkal::Protocol * protocol, Blokkal::Account * account, QWidget *parent ):
00069 EditAccountWidget( protocol, account, parent ),
00070 d( new Private() )
00071 {
00072 d->mainLayout = new QVBoxLayout( this );
00073 d->mainLayout->setSpacing( KDialog::spacingHint() );
00074
00075
00076 d->networkGroupBox = new QGroupBox( i18n( "Network" ), this );
00077 new QVBoxLayout( d->networkGroupBox );
00078
00079 d->serverNameLayout = new QHBoxLayout( 0 );
00080 d->serverNameLayout->setSpacing( KDialog::spacingHint() );
00081 d->serverNameLabel = new QLabel( i18n( "&Server Name" ), d->networkGroupBox );
00082 d->serverNameLayout->addWidget( d->serverNameLabel );
00083 d->serverNameLineEdit = new KLineEdit( d->networkGroupBox );
00084 d->serverNameLabel->setBuddy( d->serverNameLineEdit );
00085 d->serverNameLayout->addWidget( d->serverNameLineEdit );
00086 d->networkGroupBox->layout()->addItem( d->serverNameLayout );
00087
00088 d->useStandardAddressCheckBox = new QCheckBox( i18n( "&Use standard address" ), d->networkGroupBox );
00089 d->useStandardAddressCheckBox->setChecked( TRUE );
00090 d->networkGroupBox->layout()->addWidget( d->useStandardAddressCheckBox );
00091
00092 d->serverAddressLineEdit = new KLineEdit( d->networkGroupBox );
00093 d->serverAddressLineEdit->setEnabled( FALSE );
00094 QHBoxLayout * serverAddressLayout = new QHBoxLayout( 0 );
00095 serverAddressLayout->addSpacing( KDialog::spacingHint() );
00096 serverAddressLayout->addWidget( d->serverAddressLineEdit );
00097 d->networkGroupBox->layout()->addItem( serverAddressLayout );
00098 d->noAutoConnectCheckBox = new QCheckBox( i18n( "&Do not connect automatically" ), d->networkGroupBox );
00099 d->networkGroupBox->layout()->addWidget( d->noAutoConnectCheckBox );
00100
00101 d->mainLayout->addWidget( d->networkGroupBox );
00102
00103
00104 d->userGroupBox = new QGroupBox( i18n( "User" ), this );
00105 new QVBoxLayout( d->userGroupBox );
00106
00107 d->userNameLayout = new QHBoxLayout( 0 );
00108 d->userNameLayout->setSpacing( KDialog::spacingHint() );
00109 d->userNameLabel = new QLabel( i18n( "Us&er Name" ), d->userGroupBox );
00110 d->userNameLayout->addWidget( d->userNameLabel );
00111 d->userNameLineEdit = new KLineEdit( d->userGroupBox );
00112 d->userNameLabel->setBuddy( d->userNameLineEdit );
00113 d->userNameLayout->addWidget( d->userNameLineEdit );
00114 d->userGroupBox->layout()->addItem( d->userNameLayout );
00115
00116 d->mainLayout->addWidget( d->userGroupBox );
00117
00118
00119 d->accountGroupBox = new QGroupBox( i18n( "Account" ), this );
00120 new QVBoxLayout( d->accountGroupBox );
00121
00122 d->accountNameLayout = new QHBoxLayout( 0 );
00123 d->accountNameLayout->setSpacing( KDialog::spacingHint() );
00124 d->accountNameLabel = new QLabel( i18n( "&Account Name" ), d->accountGroupBox );
00125
00126 d->accountNameLayout->addWidget( d->accountNameLabel );
00127 d->accountNameLineEdit = new KLineEdit( d->accountGroupBox );
00128 d->accountNameLabel->setBuddy( d->accountNameLineEdit );
00129 d->accountNameLayout->addWidget( d->accountNameLineEdit );
00130 d->accountGroupBox->layout()->addItem( d->accountNameLayout );
00131
00132 d->mainLayout->addWidget( d->accountGroupBox );
00133
00134 d->mainLayout->addStretch( 1 );
00135
00136 if( account ) {
00137 d->serverNameLineEdit->setText( account->serverName() );
00138 d->useStandardAddressCheckBox->setChecked( account->usesDefaultConnectAddress() );
00139 d->serverAddressLineEdit->setDisabled( account->usesDefaultConnectAddress() );
00140 d->serverAddressLineEdit->setText( account->connectAddress().url() );
00141 d->noAutoConnectCheckBox->setChecked( !account->autoConnect() );
00142
00143 d->userNameLineEdit->setText( account->userName() );
00144
00145 d->accountNameModifiedManually = TRUE;
00146 d->accountNameLineEdit->setDisabled( TRUE );
00147 d->accountNameLineEdit->setText( account->id() );
00148 }
00149
00150 connect( d->serverNameLineEdit, SIGNAL( textChanged( const QString & ) ),
00151 this, SLOT( setServerAddress( const QString & ) ) );
00152 connect( d->useStandardAddressCheckBox, SIGNAL( toggled( bool ) ),
00153 d->serverAddressLineEdit, SLOT( setDisabled( bool ) ) );
00154 connect( d->useStandardAddressCheckBox, SIGNAL( toggled( bool ) ),
00155 this, SLOT( useStandardAddressToggled( void ) ) );
00156
00157 connect( d->serverNameLineEdit, SIGNAL( textChanged( const QString & ) ),
00158 this, SLOT( emitValuesChanged( void ) ) );
00159 connect( d->serverAddressLineEdit, SIGNAL( textChanged( const QString & ) ),
00160 this, SLOT( emitValuesChanged( void ) ) );
00161 connect( d->userNameLineEdit, SIGNAL( textChanged( const QString & ) ),
00162 this, SLOT( emitValuesChanged( void ) ) );
00163 connect( d->accountNameLineEdit, SIGNAL( textChanged( const QString & ) ),
00164 this, SLOT( emitValuesChanged( void ) ) );
00165
00166 }
00167
00168 Blokkal::Ui::GenericEditAccountWidget::~GenericEditAccountWidget( void )
00169 {
00170 delete d;
00171 }
00172
00173 Blokkal::Account * Blokkal::Ui::GenericEditAccountWidget::apply( void )
00174 {
00175 Blokkal::Account * account = EditAccountWidget::account();
00176
00177 if( !account ) {
00178 account = protocol()->createAccount( d->accountNameLineEdit->text() );
00179 }
00180
00181 account->setServerName( d->serverNameLineEdit->text() );
00182 account->setConnectAddress( d->serverAddressLineEdit->text() );
00183 account->setUsesDefaultConnectAddress( d->useStandardAddressCheckBox->isChecked() );
00184 account->setUserName( d->userNameLineEdit->text() );
00185 account->setAutoConnect( !d->noAutoConnectCheckBox->isChecked() );
00186
00187 return account;
00188 }
00189
00190 bool Blokkal::Ui::GenericEditAccountWidget::isValid( void ) const
00191 {
00192
00193 if( d->serverNameLineEdit->text().isEmpty()
00194 || d->serverAddressLineEdit->text().isEmpty()
00195 || d->userNameLineEdit->text().isEmpty()
00196 || d->accountNameLineEdit->text().isEmpty() )
00197 {
00198 return FALSE;
00199 }
00200
00201
00202 Blokkal::Account * accountTest = Blokkal::AccountManager::self()->account( d->accountNameLineEdit->text() );
00203 if( !accountTest ) {
00204 return TRUE;
00205 }
00206
00207 if( accountTest == account() ) {
00208 return TRUE;
00209 }
00210
00211 return FALSE;
00212 }
00213
00214 QCheckBox * Blokkal::Ui::GenericEditAccountWidget::useStandardAddressCheckBox( void ) const
00215 {
00216 return d->useStandardAddressCheckBox;
00217 }
00218
00219 KLineEdit * Blokkal::Ui::GenericEditAccountWidget::connectAddressLineEdit( void ) const
00220 {
00221 return d->serverAddressLineEdit;
00222 }
00223
00224 void Blokkal::Ui::GenericEditAccountWidget::emitValuesChanged( void )
00225 {
00226 if( d->accountNameLineEdit->hasFocus() ) {
00227 d->accountNameModifiedManually = TRUE;
00228 }
00229
00230 if( !d->accountNameModifiedManually ) {
00231 d->accountNameLineEdit->setText( d->userNameLineEdit->text() + "@" + d->serverNameLineEdit->text() );
00232 }
00233
00234 emit valuesChanged();
00235 }
00236
00237 KLineEdit * Blokkal::Ui::GenericEditAccountWidget::serverNameLineEdit( void ) const
00238 {
00239 return d->serverNameLineEdit;
00240 }
00241
00242 void Blokkal::Ui::GenericEditAccountWidget::useStandardAddressToggled( void )
00243 {
00244 setServerAddress( serverNameLineEdit()->text() );
00245 }
00246
00247 QGroupBox * Blokkal::Ui::GenericEditAccountWidget::accountGroupBox( void ) const
00248 {
00249 return d->accountGroupBox;
00250 }
00251
00252 QGroupBox * Blokkal::Ui::GenericEditAccountWidget::userGroupBox( void ) const
00253 {
00254 return d->userGroupBox;
00255 }
00256
00257 QGroupBox * Blokkal::Ui::GenericEditAccountWidget::networkGroupBox( void ) const
00258 {
00259 return d->networkGroupBox;
00260 }
00261
00262 KLineEdit * Blokkal::Ui::GenericEditAccountWidget::userNameLineEdit( void ) const
00263 {
00264 return d->userNameLineEdit;
00265 }