00001
00002 #include "defines.h"
00003 #include "editaccounts.h"
00004
00005
00006 #include <opie2/odebug.h>
00007 #include <qpe/qpeapplication.h>
00008
00009
00010 #include <qt.h>
00011 #include <qstringlist.h>
00012
00013 #include <libmailwrapper/nntpwrapper.h>
00014
00015 using namespace Opie::Core;
00016
00017 AccountListItem::AccountListItem( QListView *parent, Account *a)
00018 : QListViewItem( parent )
00019 {
00020 account = a;
00021 setText( 0, account->getAccountName() );
00022 QString ttext = "";
00023 switch (account->getType()) {
00024 case MAILLIB::A_NNTP:
00025 ttext="NNTP";
00026 break;
00027 case MAILLIB::A_POP3:
00028 ttext = "POP3";
00029 break;
00030 case MAILLIB::A_IMAP:
00031 ttext = "IMAP";
00032 break;
00033 case MAILLIB::A_SMTP:
00034 ttext = "SMTP";
00035 break;
00036 default:
00037 ttext = "UNKNOWN";
00038 break;
00039 }
00040 setText( 1, ttext);
00041 }
00042
00043 EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags )
00044 : EditAccountsUI( parent, name, modal, flags )
00045 {
00046 odebug << "New Account Configuration Widget" << oendl;
00047 settings = s;
00048
00049 mailList->addColumn( tr( "Account" ) );
00050 mailList->addColumn( tr( "Type" ) );
00051
00052 newsList->addColumn( tr( "Account" ) );
00053
00054 connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) );
00055 connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) );
00056 connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) );
00057 connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) );
00058 connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) );
00059 connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) );
00060
00061 slotFillLists();
00062 }
00063
00064 void EditAccounts::slotFillLists()
00065 {
00066 mailList->clear();
00067 newsList->clear();
00068
00069 QList<Account> accounts = settings->getAccounts();
00070 Account *it;
00071 for ( it = accounts.first(); it; it = accounts.next() )
00072 {
00073 if ( it->getType()==MAILLIB::A_NNTP )
00074 {
00075 (void) new AccountListItem( newsList, it );
00076 }
00077 else
00078 {
00079 (void) new AccountListItem( mailList, it );
00080 }
00081 }
00082 }
00083
00084 void EditAccounts::slotNewMail()
00085 {
00086 odebug << "New Mail Account" << oendl;
00087 QString *selection = new QString();
00088 SelectMailType selType( selection, this, 0, true );
00089 selType.show();
00090 if ( QDialog::Accepted == selType.exec() )
00091 {
00092 slotNewAccount( *selection );
00093 }
00094 }
00095
00096 void EditAccounts::slotNewAccount( const QString &type )
00097 {
00098 if ( type.compare( "IMAP" ) == 0 )
00099 {
00100 odebug << "-> config IMAP" << oendl;
00101 IMAPaccount *account = new IMAPaccount();
00102 IMAPconfig imap( account, this, 0, true );
00103 if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) )
00104 {
00105 settings->addAccount( account );
00106 account->save();
00107 slotFillLists();
00108 }
00109 else
00110 {
00111 account->remove();
00112 }
00113 }
00114 else if ( type.compare( "POP3" ) == 0 )
00115 {
00116 odebug << "-> config POP3" << oendl;
00117 POP3account *account = new POP3account();
00118 POP3config pop3( account, this, 0, true, WStyle_ContextHelp );
00119 if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) )
00120 {
00121 settings->addAccount( account );
00122 account->save();
00123 slotFillLists();
00124 }
00125 else
00126 {
00127 account->remove();
00128 }
00129 }
00130 else if ( type.compare( "SMTP" ) == 0 )
00131 {
00132 odebug << "-> config SMTP" << oendl;
00133 SMTPaccount *account = new SMTPaccount();
00134 SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp );
00135 if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) )
00136 {
00137 settings->addAccount( account );
00138 account->save();
00139 slotFillLists();
00140
00141 }
00142 else
00143 {
00144 account->remove();
00145 }
00146 }
00147 else if ( type.compare( "NNTP" ) == 0 )
00148 {
00149 odebug << "-> config NNTP" << oendl;
00150 NNTPaccount *account = new NNTPaccount();
00151 NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp );
00152 if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) )
00153 {
00154 settings->addAccount( account );
00155 account->save();
00156 slotFillLists();
00157 }
00158 else
00159 {
00160 account->remove();
00161 }
00162 }
00163 }
00164
00165 void EditAccounts::slotEditAccount( Account *account )
00166 {
00167 if ( account->getType() == MAILLIB::A_IMAP )
00168 {
00169 IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account);
00170 IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp );
00171 if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) )
00172 {
00173 slotFillLists();
00174 }
00175 }
00176 else if ( account->getType()==MAILLIB::A_POP3 )
00177 {
00178 POP3account *pop3Acc = static_cast<POP3account *>(account);
00179 POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp );
00180 if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) )
00181 {
00182 slotFillLists();
00183 }
00184 }
00185 else if ( account->getType()==MAILLIB::A_SMTP )
00186 {
00187 SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account);
00188 SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp );
00189 if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) )
00190 {
00191 slotFillLists();
00192 }
00193 }
00194 else if ( account->getType()==MAILLIB::A_NNTP)
00195 {
00196 NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account);
00197 NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp );
00198 if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) )
00199 {
00200 slotFillLists();
00201 }
00202 }
00203 }
00204
00205 void EditAccounts::slotDeleteAccount( Account *account )
00206 {
00207 if ( QMessageBox::information( this, tr( "Question" ),
00208 tr( "<p>Do you really want to delete the selected Account?</p>" ),
00209 tr( "Yes" ), tr( "No" ) ) == 0 )
00210 {
00211 settings->delAccount( account );
00212 slotFillLists();
00213 }
00214 }
00215
00216 void EditAccounts::slotEditMail()
00217 {
00218 odebug << "Edit Mail Account" << oendl;
00219 if ( !mailList->currentItem() )
00220 {
00221 QMessageBox::information( this, tr( "Error" ),
00222 tr( "<p>Please select an account.</p>" ),
00223 tr( "Ok" ) );
00224 return;
00225 }
00226
00227 Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
00228 slotEditAccount( a );
00229 }
00230
00231 void EditAccounts::slotDeleteMail()
00232 {
00233 if ( !mailList->currentItem() )
00234 {
00235 QMessageBox::information( this, tr( "Error" ),
00236 tr( "<p>Please select an account.</p>" ),
00237 tr( "Ok" ) );
00238 return;
00239 }
00240
00241 Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
00242 slotDeleteAccount( a );
00243 }
00244
00245 void EditAccounts::slotNewNews()
00246 {
00247 odebug << "New News Account" << oendl;
00248 slotNewAccount( "NNTP" );
00249 }
00250
00251 void EditAccounts::slotEditNews()
00252 {
00253 odebug << "Edit News Account" << oendl;
00254 if ( !newsList->currentItem() )
00255 {
00256 QMessageBox::information( this, tr( "Error" ),
00257 tr( "<p>Please select an account.</p>" ),
00258 tr( "Ok" ) );
00259 return;
00260 }
00261
00262 Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
00263 slotEditAccount( a );
00264 }
00265
00266 void EditAccounts::slotDeleteNews()
00267 {
00268 odebug << "Delete News Account" << oendl;
00269 if ( !newsList->currentItem() )
00270 {
00271 QMessageBox::information( this, tr( "Error" ),
00272 tr( "<p>Please select an account.</p>" ),
00273 tr( "Ok" ) );
00274 return;
00275 }
00276
00277 Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
00278 slotDeleteAccount( a );
00279 }
00280
00281 void EditAccounts::slotAdjustColumns()
00282 {
00283 int currPage = configTab->currentPageIndex();
00284
00285 configTab->showPage( mailTab );
00286 mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 );
00287 mailList->setColumnWidth( 1, 50 );
00288
00289 configTab->showPage( newsTab );
00290 newsList->setColumnWidth( 0, newsList->visibleWidth() );
00291
00292 configTab->setCurrentPage( currPage );
00293 }
00294
00295 void EditAccounts::accept()
00296 {
00297 settings->saveAccounts();
00298
00299 QDialog::accept();
00300 }
00301
00306 SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags )
00307 : SelectMailTypeUI( parent, name, modal, flags )
00308 {
00309 selected = selection;
00310 selected->replace( 0, selected->length(), typeBox->currentText() );
00311 connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) );
00312 }
00313
00314 void SelectMailType::slotSelection( const QString &sel )
00315 {
00316 selected->replace( 0, selected->length(), sel );
00317 }
00318
00323 IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
00324 : IMAPconfigUI( parent, name, modal, flags )
00325 {
00326 data = account;
00327
00328 fillValues();
00329
00330 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
00331 ComboBox1->insertItem( "Only if available", 0 );
00332 ComboBox1->insertItem( "Always, Negotiated", 1 );
00333 ComboBox1->insertItem( "Connect on secure port", 2 );
00334 ComboBox1->insertItem( "Run command instead", 3 );
00335 CommandEdit->hide();
00336 ComboBox1->setCurrentItem( data->ConnectionType() );
00337 }
00338
00339 void IMAPconfig::slotConnectionToggle( int index )
00340 {
00341 if ( index == 2 )
00342 {
00343 portLine->setText( IMAP_SSL_PORT );
00344 }
00345 else if ( index == 3 )
00346 {
00347 portLine->setText( IMAP_PORT );
00348 CommandEdit->show();
00349 }
00350 else
00351 {
00352 portLine->setText( IMAP_PORT );
00353 }
00354 }
00355
00356 void IMAPconfig::fillValues()
00357 {
00358 accountLine->setText( data->getAccountName() );
00359 serverLine->setText( data->getServer() );
00360 portLine->setText( data->getPort() );
00361 ComboBox1->setCurrentItem( data->ConnectionType() );
00362 userLine->setText( data->getUser() );
00363 passLine->setText( data->getPassword() );
00364 prefixLine->setText(data->getPrefix());
00365 }
00366
00367 void IMAPconfig::accept()
00368 {
00369 data->setAccountName( accountLine->text() );
00370 data->setServer( serverLine->text() );
00371 data->setPort( portLine->text() );
00372 data->setConnectionType( ComboBox1->currentItem() );
00373 data->setUser( userLine->text() );
00374 data->setPassword( passLine->text() );
00375 data->setPrefix(prefixLine->text());
00376
00377 QDialog::accept();
00378 }
00379
00384 POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags )
00385 : POP3configUI( parent, name, modal, flags )
00386 {
00387 data = account;
00388 fillValues();
00389
00390 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
00391 ComboBox1->insertItem( "Only if available", 0 );
00392 ComboBox1->insertItem( "Always, Negotiated", 1 );
00393 ComboBox1->insertItem( "Connect on secure port", 2 );
00394 ComboBox1->insertItem( "Run command instead", 3 );
00395 CommandEdit->hide();
00396 ComboBox1->setCurrentItem( data->ConnectionType() );
00397 }
00398
00399 void POP3config::slotConnectionToggle( int index )
00400 {
00401
00402 if ( index == 2 )
00403 {
00404 portLine->setText( POP3_SSL_PORT );
00405 }
00406 else if ( index == 3 )
00407 {
00408 portLine->setText( POP3_PORT );
00409 CommandEdit->show();
00410 }
00411 else
00412 {
00413 portLine->setText( POP3_PORT );
00414 }
00415 }
00416
00417 void POP3config::fillValues()
00418 {
00419 accountLine->setText( data->getAccountName() );
00420 serverLine->setText( data->getServer() );
00421 portLine->setText( data->getPort() );
00422 ComboBox1->setCurrentItem( data->ConnectionType() );
00423 userLine->setText( data->getUser() );
00424 passLine->setText( data->getPassword() );
00425 m_CheckSize->setChecked(data->getCheckMaxSize());
00426 m_MailLimitBox->setValue(data->getMaxSize());
00427 }
00428
00429 void POP3config::accept()
00430 {
00431 data->setAccountName( accountLine->text() );
00432 data->setServer( serverLine->text() );
00433 data->setPort( portLine->text() );
00434 data->setConnectionType( ComboBox1->currentItem() );
00435 data->setUser( userLine->text() );
00436 data->setPassword( passLine->text() );
00437 data->setMaxSize(m_MailLimitBox->value());
00438 data->setCheckMaxSize(m_CheckSize->isChecked());
00439
00440 QDialog::accept();
00441 }
00442
00447 SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
00448 : SMTPconfigUI( parent, name, modal, flags )
00449 {
00450 data = account;
00451
00452 connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) );
00453 connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) );
00454
00455 fillValues();
00456
00457 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
00458 ComboBox1->insertItem( "Only if available", 0 );
00459 ComboBox1->insertItem( "Always, Negotiated", 1 );
00460 ComboBox1->insertItem( "Connect on secure port", 2 );
00461 ComboBox1->insertItem( "Run command instead", 3 );
00462 CommandEdit->hide();
00463 ComboBox1->setCurrentItem( data->ConnectionType() );
00464 }
00465
00466 void SMTPconfig::slotConnectionToggle( int index )
00467 {
00468
00469 if ( index == 2 )
00470 {
00471 portLine->setText( SMTP_SSL_PORT );
00472 }
00473 else if ( index == 3 )
00474 {
00475 portLine->setText( SMTP_PORT );
00476 CommandEdit->show();
00477 }
00478 else
00479 {
00480 portLine->setText( SMTP_PORT );
00481 }
00482 }
00483
00484 void SMTPconfig::fillValues()
00485 {
00486 accountLine->setText( data->getAccountName() );
00487 serverLine->setText( data->getServer() );
00488 portLine->setText( data->getPort() );
00489 ComboBox1->setCurrentItem( data->ConnectionType() );
00490 loginBox->setChecked( data->getLogin() );
00491 userLine->setText( data->getUser() );
00492 passLine->setText( data->getPassword() );
00493 }
00494
00495 void SMTPconfig::accept()
00496 {
00497 data->setAccountName( accountLine->text() );
00498 data->setServer( serverLine->text() );
00499 data->setPort( portLine->text() );
00500 data->setConnectionType( ComboBox1->currentItem() );
00501 data->setLogin( loginBox->isChecked() );
00502 data->setUser( userLine->text() );
00503 data->setPassword( passLine->text() );
00504
00505 QDialog::accept();
00506 }
00507
00512 NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
00513 : NNTPconfigUI( parent, name, modal, flags )
00514 {
00515 data = account;
00516
00517 connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) );
00518 connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) );
00519 connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) );
00520 fillValues();
00521
00522 connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) );
00523 }
00524
00525 void NNTPconfig::slotGetNG() {
00526 save();
00527 data->save();
00528 NNTPwrapper* tmp = new NNTPwrapper( data );
00529 QStringList list = tmp->listAllNewsgroups();
00530
00531 ListViewGroups->clear();
00532
00533 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00534 QCheckListItem *item;
00535 item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox );
00536 if ( subscribedGroups.contains( (*it) ) >= 1 ) {
00537 item->setOn( true );
00538 }
00539 }
00540 }
00541
00542 void NNTPconfig::slotSSL( bool enabled )
00543 {
00544 if ( enabled )
00545 {
00546 portLine->setText( NNTP_SSL_PORT );
00547 }
00548 else
00549 {
00550 portLine->setText( NNTP_PORT );
00551 }
00552 }
00553
00554 void NNTPconfig::fillValues()
00555 {
00556 accountLine->setText( data->getAccountName() );
00557 serverLine->setText( data->getServer() );
00558 portLine->setText( data->getPort() );
00559 sslBox->setChecked( data->getSSL() );
00560 loginBox->setChecked( data->getLogin() );
00561 userLine->setText( data->getUser() );
00562 passLine->setText( data->getPassword() );
00563 subscribedGroups = data->getGroups();
00564
00565 for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) {
00566 QCheckListItem *item;
00567 item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox );
00568 item->setOn( true );
00569 }
00570 }
00571
00572 void NNTPconfig::save()
00573 {
00574 data->setAccountName( accountLine->text() );
00575 data->setServer( serverLine->text() );
00576 data->setPort( portLine->text() );
00577 data->setSSL( sslBox->isChecked() );
00578 data->setLogin( loginBox->isChecked() );
00579 data->setUser( userLine->text() );
00580 data->setPassword( passLine->text() );
00581
00582 QListViewItemIterator list_it( ListViewGroups );
00583
00584 QStringList groupList;
00585 for ( ; list_it.current(); ++list_it ) {
00586
00587 if ( ( (QCheckListItem*)list_it.current() )->isOn() ) {
00588 odebug << list_it.current()->text(0) << oendl;
00589 groupList.append( list_it.current()->text(0) );
00590 }
00591
00592 }
00593 data->setGroups( groupList );
00594 }
00595
00596 void NNTPconfig::accept()
00597 {
00598 save();
00599 QDialog::accept();
00600 }
00601