summaryrefslogtreecommitdiffabout
path: root/kmicromail/editaccounts.cpp
authorzautrix <zautrix>2004-07-03 16:33:12 (UTC)
committer zautrix <zautrix>2004-07-03 16:33:12 (UTC)
commite3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff)
tree162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/editaccounts.cpp
parent2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff)
downloadkdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2
Initial revision
Diffstat (limited to 'kmicromail/editaccounts.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/editaccounts.cpp594
1 files changed, 594 insertions, 0 deletions
diff --git a/kmicromail/editaccounts.cpp b/kmicromail/editaccounts.cpp
new file mode 100644
index 0000000..d272c3b
--- a/dev/null
+++ b/kmicromail/editaccounts.cpp
@@ -0,0 +1,594 @@
1
2#include "defines.h"
3#include "editaccounts.h"
4#include "kapplication.h"
5/* OPIE */
6#include <qpe/qpeapplication.h>
7
8/* QT */
9#include <qstringlist.h>
10
11#include <qcombobox.h>
12#include <qcheckbox.h>
13#include <qmessagebox.h>
14#include <qpushbutton.h>
15#include <qlineedit.h>
16#include <qlabel.h>
17#include <qtabwidget.h>
18#include <qlistview.h>
19
20#include <libmailwrapper/nntpwrapper.h>
21
22using namespace Opie::Core;
23
24AccountListItem::AccountListItem( QListView *parent, Account *a)
25 : QListViewItem( parent )
26{
27 account = a;
28 setText( 0, account->getAccountName() );
29 QString ttext = "";
30 switch (account->getType()) {
31 case MAILLIB::A_NNTP:
32 ttext="NNTP";
33 break;
34 case MAILLIB::A_POP3:
35 ttext = "POP3";
36 break;
37 case MAILLIB::A_IMAP:
38 ttext = "IMAP";
39 break;
40 case MAILLIB::A_SMTP:
41 ttext = "SMTP";
42 break;
43 default:
44 ttext = "UNKNOWN";
45 break;
46 }
47 setText( 1, ttext);
48}
49
50EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags )
51 : EditAccountsUI( parent, name, modal, flags )
52{
53 settings = s;
54
55 mailList->addColumn( tr( "Account" ) );
56 mailList->addColumn( tr( "Type" ) );
57
58 newsList->addColumn( tr( "Account" ) );
59
60 connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) );
61 connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) );
62 connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) );
63 connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) );
64 connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) );
65 connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) );
66
67 slotFillLists();
68}
69
70void EditAccounts::slotFillLists()
71{
72 mailList->clear();
73 newsList->clear();
74
75 QList<Account> accounts = settings->getAccounts();
76 Account *it;
77 for ( it = accounts.first(); it; it = accounts.next() )
78 {
79 if ( it->getType()==MAILLIB::A_NNTP )
80 {
81 (void) new AccountListItem( newsList, it );
82 }
83 else
84 {
85 (void) new AccountListItem( mailList, it );
86 }
87 }
88}
89
90void EditAccounts::slotNewMail()
91{
92 QString *selection = new QString();
93 SelectMailType selType( selection, this, 0, true );
94 selType.show();
95 if ( QDialog::Accepted == selType.exec() )
96 {
97 slotNewAccount( *selection );
98 }
99}
100
101void EditAccounts::slotNewAccount( const QString &type )
102{
103 if ( type.compare( "IMAP" ) == 0 )
104 {
105 IMAPaccount *account = new IMAPaccount();
106 IMAPconfig imap( account, this, 0, true );
107 imap.showMaximized();
108 if ( QDialog::Accepted == imap.exec() )
109 {
110 settings->addAccount( account );
111 account->save();
112 slotFillLists();
113 }
114 else
115 {
116 account->remove();
117 }
118 }
119 else if ( type.compare( "POP3" ) == 0 )
120 {
121 POP3account *account = new POP3account();
122 POP3config pop3( account, this, 0, true, WStyle_ContextHelp );
123 if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) )
124 {
125 settings->addAccount( account );
126 account->save();
127 slotFillLists();
128 }
129 else
130 {
131 account->remove();
132 }
133 }
134 else if ( type.compare( "SMTP" ) == 0 )
135 {
136 SMTPaccount *account = new SMTPaccount();
137 SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp );
138 if ( QDialog::Accepted == KApplication::execDialog( &smtp ) )
139 {
140 settings->addAccount( account );
141 account->save();
142 slotFillLists();
143
144 }
145 else
146 {
147 account->remove();
148 }
149 }
150 else if ( type.compare( "NNTP" ) == 0 )
151 {
152 NNTPaccount *account = new NNTPaccount();
153 NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp );
154 if ( QDialog::Accepted == KApplication::execDialog( &nntp ) )
155 {
156 settings->addAccount( account );
157 account->save();
158 slotFillLists();
159 }
160 else
161 {
162 account->remove();
163 }
164 }
165}
166
167void EditAccounts::slotEditAccount( Account *account )
168{
169 if ( account->getType() == MAILLIB::A_IMAP )
170 {
171 IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account);
172 IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp );
173 if ( QDialog::Accepted == KApplication::execDialog( &imap ) )
174 {
175 slotFillLists();
176 }
177 }
178 else if ( account->getType()==MAILLIB::A_POP3 )
179 {
180 POP3account *pop3Acc = static_cast<POP3account *>(account);
181 POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp );
182 if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) )
183 {
184 slotFillLists();
185 }
186 }
187 else if ( account->getType()==MAILLIB::A_SMTP )
188 {
189 SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account);
190 SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp );
191 if ( QDialog::Accepted == KApplication::execDialog( &smtp ) )
192 {
193 slotFillLists();
194 }
195 }
196 else if ( account->getType()==MAILLIB::A_NNTP)
197 {
198 NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account);
199 NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp );
200 if ( QDialog::Accepted == KApplication::execDialog( &nntp ) )
201 {
202 slotFillLists();
203 }
204 }
205}
206
207void EditAccounts::slotDeleteAccount( Account *account )
208{
209 if ( QMessageBox::information( this, tr( "Question" ),
210 tr( "<p>Do you really want to delete the selected Account?</p>" ),
211 tr( "Yes" ), tr( "No" ) ) == 0 )
212 {
213 settings->delAccount( account );
214 slotFillLists();
215 }
216}
217
218void EditAccounts::slotEditMail()
219{
220 if ( !mailList->currentItem() )
221 {
222 QMessageBox::information( this, tr( "Error" ),
223 tr( "<p>Please select an account.</p>" ),
224 tr( "Ok" ) );
225 return;
226 }
227
228 Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
229 slotEditAccount( a );
230}
231
232void EditAccounts::slotDeleteMail()
233{
234 if ( !mailList->currentItem() )
235 {
236 QMessageBox::information( this, tr( "Error" ),
237 tr( "<p>Please select an account.</p>" ),
238 tr( "Ok" ) );
239 return;
240 }
241
242 Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
243 slotDeleteAccount( a );
244}
245
246void EditAccounts::slotNewNews()
247{
248 slotNewAccount( "NNTP" );
249}
250
251void EditAccounts::slotEditNews()
252{
253 if ( !newsList->currentItem() )
254 {
255 QMessageBox::information( this, tr( "Error" ),
256 tr( "<p>Please select an account.</p>" ),
257 tr( "Ok" ) );
258 return;
259 }
260
261 Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
262 slotEditAccount( a );
263}
264
265void EditAccounts::slotDeleteNews()
266{
267 if ( !newsList->currentItem() )
268 {
269 QMessageBox::information( this, tr( "Error" ),
270 tr( "<p>Please select an account.</p>" ),
271 tr( "Ok" ) );
272 return;
273 }
274
275 Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
276 slotDeleteAccount( a );
277}
278
279void EditAccounts::slotAdjustColumns()
280{
281 int currPage = configTab->currentPageIndex();
282
283 configTab->showPage( mailTab );
284 mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 );
285 mailList->setColumnWidth( 1, 50 );
286
287 configTab->showPage( newsTab );
288 newsList->setColumnWidth( 0, newsList->visibleWidth() );
289
290 configTab->setCurrentPage( currPage );
291}
292
293void EditAccounts::accept()
294{
295 settings->saveAccounts();
296
297 QDialog::accept();
298}
299
300/**
301 * SelectMailType
302 */
303
304SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags )
305 : SelectMailTypeUI( parent, name, modal, flags )
306{
307 selected = selection;
308 selected->replace( 0, selected->length(), typeBox->currentText() );
309 connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) );
310}
311
312void SelectMailType::slotSelection( const QString &sel )
313{
314 selected->replace( 0, selected->length(), sel );
315}
316
317/**
318 * IMAPconfig
319 */
320
321IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
322 : IMAPconfigUI( parent, name, modal, flags )
323{
324 data = account;
325
326 fillValues();
327
328 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
329 ComboBox1->insertItem( "Only if available", 0 );
330 ComboBox1->insertItem( "Always, Negotiated", 1 );
331 ComboBox1->insertItem( "Connect on secure port", 2 );
332 ComboBox1->insertItem( "Run command instead", 3 );
333 CommandEdit->hide();
334 ComboBox1->setCurrentItem( data->ConnectionType() );
335}
336
337void IMAPconfig::slotConnectionToggle( int index )
338{
339 if ( index == 2 )
340 {
341 portLine->setText( IMAP_SSL_PORT );
342 }
343 else if ( index == 3 )
344 {
345 portLine->setText( IMAP_PORT );
346 CommandEdit->show();
347 }
348 else
349 {
350 portLine->setText( IMAP_PORT );
351 }
352}
353
354void IMAPconfig::fillValues()
355{
356 accountLine->setText( data->getAccountName() );
357 serverLine->setText( data->getServer() );
358 portLine->setText( data->getPort() );
359 ComboBox1->setCurrentItem( data->ConnectionType() );
360 userLine->setText( data->getUser() );
361 passLine->setText( data->getPassword() );
362 prefixLine->setText(data->getPrefix());
363}
364
365void IMAPconfig::accept()
366{
367 data->setAccountName( accountLine->text() );
368 data->setServer( serverLine->text() );
369 data->setPort( portLine->text() );
370 data->setConnectionType( ComboBox1->currentItem() );
371 data->setUser( userLine->text() );
372 data->setPassword( passLine->text() );
373 data->setPrefix(prefixLine->text());
374
375 QDialog::accept();
376}
377
378/**
379 * POP3config
380 */
381
382POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags )
383 : POP3configUI( parent, name, modal, flags )
384{
385 data = account;
386 fillValues();
387
388 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
389 ComboBox1->insertItem( "Only if available", 0 );
390 ComboBox1->insertItem( "Always, Negotiated", 1 );
391 ComboBox1->insertItem( "Connect on secure port", 2 );
392 ComboBox1->insertItem( "Run command instead", 3 );
393 CommandEdit->hide();
394 ComboBox1->setCurrentItem( data->ConnectionType() );
395}
396
397void POP3config::slotConnectionToggle( int index )
398{
399 // 2 is ssl connection
400 if ( index == 2 )
401 {
402 portLine->setText( POP3_SSL_PORT );
403 }
404 else if ( index == 3 )
405 {
406 portLine->setText( POP3_PORT );
407 CommandEdit->show();
408 }
409 else
410 {
411 portLine->setText( POP3_PORT );
412 }
413}
414
415void POP3config::fillValues()
416{
417 accountLine->setText( data->getAccountName() );
418 serverLine->setText( data->getServer() );
419 portLine->setText( data->getPort() );
420 ComboBox1->setCurrentItem( data->ConnectionType() );
421 userLine->setText( data->getUser() );
422 passLine->setText( data->getPassword() );
423}
424
425void POP3config::accept()
426{
427 data->setAccountName( accountLine->text() );
428 data->setServer( serverLine->text() );
429 data->setPort( portLine->text() );
430 data->setConnectionType( ComboBox1->currentItem() );
431 data->setUser( userLine->text() );
432 data->setPassword( passLine->text() );
433
434 QDialog::accept();
435}
436
437/**
438 * SMTPconfig
439 */
440
441SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
442 : SMTPconfigUI( parent, name, modal, flags )
443{
444 data = account;
445
446 connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) );
447 connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) );
448
449 fillValues();
450
451 connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
452 ComboBox1->insertItem( "Only if available", 0 );
453 ComboBox1->insertItem( "Always, Negotiated", 1 );
454 ComboBox1->insertItem( "Connect on secure port", 2 );
455 ComboBox1->insertItem( "Run command instead", 3 );
456 CommandEdit->hide();
457 ComboBox1->setCurrentItem( data->ConnectionType() );
458}
459
460void SMTPconfig::slotConnectionToggle( int index )
461{
462 // 2 is ssl connection
463 if ( index == 2 )
464 {
465 portLine->setText( SMTP_SSL_PORT );
466 }
467 else if ( index == 3 )
468 {
469 portLine->setText( SMTP_PORT );
470 CommandEdit->show();
471 }
472 else
473 {
474 portLine->setText( SMTP_PORT );
475 }
476}
477
478void SMTPconfig::fillValues()
479{
480 accountLine->setText( data->getAccountName() );
481 serverLine->setText( data->getServer() );
482 portLine->setText( data->getPort() );
483 ComboBox1->setCurrentItem( data->ConnectionType() );
484 loginBox->setChecked( data->getLogin() );
485 userLine->setText( data->getUser() );
486 passLine->setText( data->getPassword() );
487}
488
489void SMTPconfig::accept()
490{
491 data->setAccountName( accountLine->text() );
492 data->setServer( serverLine->text() );
493 data->setPort( portLine->text() );
494 data->setConnectionType( ComboBox1->currentItem() );
495 data->setLogin( loginBox->isChecked() );
496 data->setUser( userLine->text() );
497 data->setPassword( passLine->text() );
498
499 QDialog::accept();
500}
501
502/**
503 * NNTPconfig
504 */
505
506NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
507 : NNTPconfigUI( parent, name, modal, flags )
508{
509 data = account;
510
511 connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) );
512 connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) );
513 connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) );
514 fillValues();
515
516 connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) );
517}
518
519void NNTPconfig::slotGetNG() {
520 save();
521 data->save();
522 NNTPwrapper* tmp = new NNTPwrapper( data );
523 QStringList list = tmp->listAllNewsgroups();
524
525 ListViewGroups->clear();
526
527 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
528 QCheckListItem *item;
529 item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox );
530 if ( subscribedGroups.contains( (*it) ) >= 1 ) {
531 item->setOn( true );
532 }
533 }
534}
535
536void NNTPconfig::slotSSL( bool enabled )
537{
538 if ( enabled )
539 {
540 portLine->setText( NNTP_SSL_PORT );
541 }
542 else
543 {
544 portLine->setText( NNTP_PORT );
545 }
546}
547
548void NNTPconfig::fillValues()
549{
550 accountLine->setText( data->getAccountName() );
551 serverLine->setText( data->getServer() );
552 portLine->setText( data->getPort() );
553 sslBox->setChecked( data->getSSL() );
554 loginBox->setChecked( data->getLogin() );
555 userLine->setText( data->getUser() );
556 passLine->setText( data->getPassword() );
557 subscribedGroups = data->getGroups();
558 /* don't forget that - you will overwrite values if user clicks cancel! */
559 for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) {
560 QCheckListItem *item;
561 item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox );
562 item->setOn( true );
563 }
564}
565
566void NNTPconfig::save()
567{
568 data->setAccountName( accountLine->text() );
569 data->setServer( serverLine->text() );
570 data->setPort( portLine->text() );
571 data->setSSL( sslBox->isChecked() );
572 data->setLogin( loginBox->isChecked() );
573 data->setUser( userLine->text() );
574 data->setPassword( passLine->text() );
575
576 QListViewItemIterator list_it( ListViewGroups );
577
578 QStringList groupList;
579 for ( ; list_it.current(); ++list_it ) {
580
581 if ( ( (QCheckListItem*)list_it.current() )->isOn() ) {
582 groupList.append( list_it.current()->text(0) );
583 }
584
585 }
586 data->setGroups( groupList );
587}
588
589void NNTPconfig::accept()
590{
591 save();
592 QDialog::accept();
593}
594