00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021
00022 #include <ntqfile.h>
00023
00024 #include <tdeconfig.h>
00025 #include <ksavefile.h>
00026 #include <tdeapplication.h>
00027 #include <kstandarddirs.h>
00028 #include <kaudioplayer.h>
00029 #include <kdebug.h>
00030
00031 #include "configlist.h"
00032 #include "filter.h"
00033
00034 ConfigList::ConfigList() : TQObject()
00035 {
00036 setAutoDelete (true);
00037
00038
00039 ctrOpenMessageWindows = 0;
00040
00041
00042 m_bShowMessage = DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW;
00043 m_bShowMainWindow = DEFAULT_ACTION_NEW_MAIL_MAINWINDOW;
00044 m_bBeep = DEFAULT_ACTION_NEW_MAIL_BEEP;
00045 m_bSound = DEFAULT_ACTION_NEW_MAIL_SOUND;
00046 m_bCommand = DEFAULT_ACTION_NEW_MAIL_COMMAND;
00047 m_bMinimize = DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE;
00048 m_bTerminate = DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE;
00049
00050 m_bConfirmClose = DEFAULT_CONFIRM_CLOSE;
00051 m_bConfirmDelete = DEFAULT_CONFIRM_DELETE;
00052 m_bStartMinimized = DEFAULT_START_MINIMIZED;
00053 m_bCloseMinimizes = DEFAULT_CLOSE_TO_TRAY;
00054 m_bMinimizeToTray = DEFAULT_MINIMIZE_TO_TRAY;
00055 m_bShowConnectionErrors = DEFAULT_SHOW_CONNECTION_ERRORS;
00056 m_bKeepNew = DEFAULT_KEEP_NEW;
00057 m_nInitTimer = DEFAULT_INITIAL_TIME;
00058 m_nIntervalTimer = DEFAULT_INTERVAL_TIME;
00059 m_nPop3Timer = DEFAULT_TIMEOUT_TIME;
00060 }
00061
00062 int ConfigList::compareItems( TQCollection::Item item1, TQCollection::Item item2 )
00063 {
00064 ConfigElem* p1 = (ConfigElem*)item1;
00065 ConfigElem* p2 = (ConfigElem*)item2;
00066
00067 return strcmp( p1->getAccountName(), p2->getAccountName() );
00068 }
00069
00070 TQCollection::Item ConfigList::newItem( TQCollection::Item item )
00071 {
00072 return new ConfigElem( (ConfigElem*)item );
00073 }
00074
00075 void ConfigList::saveOptions ()
00076 {
00077 kdDebug () << "ConfigList::saveOptions" << endl;
00078
00079
00080 TQDomDocument doc( "KShowmail" );
00081
00082
00083 TQDomElement accounts = doc.createElement( ROOT_ELEMENT );
00084
00085
00086
00087
00088 int i = 0;
00089 ConfigElem* account = NULL;
00090 TQPtrListIterator<ConfigElem> it( *this );
00091
00092
00093 while( ( account = it.current() ) != NULL )
00094 {
00095
00096 ++it;
00097
00098
00099 TQDomElement accElem = doc.createElement( TQString( ACCOUNT_ELEMENT ) + TQString( "%1" ).arg( i++ ) );
00100 account->saveOptions( doc, accElem );
00101 accounts.appendChild( accElem );
00102
00103 }
00104
00105
00106 doc.appendChild( accounts );
00107
00108
00109 TQCString str = doc.toCString();
00110 TQString cachefilename = locateLocal( "config", "kshowmail.xml" );
00111 KSaveFile file( cachefilename, 0600 );
00112
00113 if( file.status() != 0 )
00114 {
00115 kdError() << "Couldn't save mail cache. " << strerror( file.status() );
00116 return;
00117 }
00118
00119
00120 file.file()->writeBlock( str.data(), str.length() );
00121
00122
00123 if( !file.close() )
00124 {
00125 kdError () << "Couldn't save mail cache. " << strerror(file.status());
00126 return;
00127 }
00128 }
00129
00130
00131 void ConfigList::setList (TQListView* list)
00132 {
00133 TQPixmap pix (::locate ("data", "kshowmail/pics/ok.png"));
00134 list->clear ();
00135 int nIndex = at ();
00136 TQListViewItem* last = NULL;
00137 for (ConfigElem* pElem = first(); pElem; pElem = next())
00138 {
00139 last = new TQListViewItem (list, last, "", pElem->getAccountName(), pElem->getURL().host(), pElem->getURL().user(), "?");
00140 pElem->setListViewItem( last );
00141 if (pElem->isActive())
00142 pElem->getListViewItem()->setPixmap (0, pix);
00143 }
00144
00145 if (nIndex >= 0)
00146 {
00147 at (nIndex);
00148
00149 }
00150 }
00151
00152
00153 bool ConfigList::setItem (const char* item)
00154 {
00155 int nPos = at ();
00156 ConfigElem* pActive = new ConfigElem (this, item);
00157 bool result = (find (pActive) >= 0);
00158 delete pActive;
00159 if (result)
00160 return true;
00161 else
00162 {
00163 at (nPos);
00164 return false;
00165 }
00166 }
00167
00168 void ConfigList::beep ()
00169 {
00170 if (m_bBeep)
00171 kapp->beep ();
00172 }
00173
00174 void ConfigList::playSound ()
00175 {
00176 if (m_bSound)
00177 playSound (m_strSoundFile);
00178 }
00179
00180 void ConfigList::playSound (const char* file)
00181 {
00182 KAudioPlayer::play(file);
00183 }
00184
00185
00186 void ConfigList::applyFilters ()
00187 {
00188 if (Filter::_status != Filter::off)
00189 {
00190 for (ConfigElem* pElem = first(); pElem; pElem = next())
00191 {
00192 if (pElem->isActive() )
00193 {
00194 pElem->applyFilters ();
00195 }
00196 }
00197 }
00198 }
00199
00200 int ConfigList::getRefreshTimeInterval( ) const
00201 {
00202 return m_nIntervalTimer;
00203 }
00204
00205 void ConfigList::setRefreshTimeInterval( unsigned int interval )
00206 {
00207 m_nIntervalTimer = interval;
00208 }
00209
00210 bool ConfigList::AutoRefreshOn( ) const
00211 {
00212 return ( m_nIntervalTimer > 0 );
00213 }
00214
00215 bool ConfigList::hasActiveAccounts( )
00216 {
00217 bool activeAccountFound = false;
00218 ConfigElem* currentAccount;
00219 ConfigElem* Account;
00220
00221
00222 currentAccount = current();
00223
00224
00225 Account = first();
00226
00227
00228 while( Account != NULL && !activeAccountFound )
00229 {
00230
00231 activeAccountFound = Account->isActive();
00232
00233
00234 Account = next();
00235 }
00236
00237
00238 if( currentAccount != NULL )
00239 findRef( currentAccount );
00240
00241
00242 return activeAccountFound;
00243 }
00244
00245
00246 uint ConfigList::getTimeoutTime( ) const
00247 {
00248 return m_nPop3Timer;
00249 }
00250
00251 void ConfigList::setTimeoutTime( uint time )
00252 {
00253 if( time < MINIMUM_TIMEOUT_TIME )
00254 m_nPop3Timer = MINIMUM_TIMEOUT_TIME;
00255 else
00256 m_nPop3Timer = time;
00257 }
00258
00259 ConfigElem* ConfigList::getSelectedAccount( )
00260 {
00261
00262 ConfigElem* account = first();
00263
00264
00265 if( account == NULL )
00266 return NULL;
00267
00268
00269 if( account->isSelected() )
00270 return account;
00271
00272
00273 bool selectedAccountFound = false;
00274 while( account != NULL && !selectedAccountFound )
00275 {
00276
00277 account = next();
00278
00279
00280 if( account != NULL )
00281 selectedAccountFound = account->isSelected();
00282 else
00283 selectedAccountFound = false;
00284 }
00285
00286
00287
00288 if( selectedAccountFound )
00289 return account;
00290 else
00291 return NULL;
00292 }
00293
00294 void ConfigList::deleteSelectedMails( )
00295 {
00296 TQPtrListIterator<ConfigElem> it( *this );
00297 ConfigElem* account;
00298
00299
00300
00301 AccountDeletionMap.clear();
00302
00303
00304 connectAccounts();
00305
00306
00307
00308
00309
00310 while( ( account = it.current() ) != NULL )
00311 {
00312
00313 AccountDeletionMap.insert( account->getAccountName(), true );
00314
00315
00316 ++it;
00317 }
00318
00319
00320 it.toFirst();
00321 while( ( account = it.current() ) != NULL )
00322 {
00323 account->deleteSelectedMails();
00324
00325
00326 ++it;
00327 }
00328 }
00329
00330 void ConfigList::slotAccountConfigChanged( )
00331 {
00332 emit sigConfigChanged();
00333 }
00334
00335 void ConfigList::slotCheckDeletionState( TQString account )
00336 {
00337 bool accountDeleting = false;
00338 AccountTaskMap_Type::Iterator it;
00339
00340
00341 AccountDeletionMap[ account ] = false;
00342
00343
00344
00345 for ( it = AccountDeletionMap.begin(); it != AccountDeletionMap.end(); ++it )
00346 {
00347 if( *it == true )
00348 accountDeleting = true;
00349 }
00350
00351
00352 if( !accountDeleting )
00353 emit sigDeleteReady();
00354 }
00355
00356 void ConfigList::connectAccounts( )
00357 {
00358 TQPtrListIterator<ConfigElem> it( *this );
00359 ConfigElem* account;
00360
00361 while( ( account = it.current() ) != NULL )
00362 {
00363
00364 account->disconnect();
00365
00366
00367 connect( account, SIGNAL( sigConfigChanged() ), this, SLOT( slotAccountConfigChanged() ) );
00368 connect( account, SIGNAL( sigDeleteReady( TQString ) ), this, SLOT( slotCheckDeletionState( TQString ) ) );
00369 connect( account, SIGNAL( sigShowBodiesReady( TQString ) ), this, SLOT( slotCheckShowBodiesState( TQString ) ) );
00370 connect( account, SIGNAL( sigMessageWindowOpened() ), this, SLOT( slotMessageWindowOpened() ) );
00371 connect( account, SIGNAL( sigMessageWindowClosed() ), this, SLOT( slotMessageWindowClosed() ) );
00372 connect( account, SIGNAL( sigRefreshReady( TQString ) ), this, SLOT( slotCheckRefreshState( TQString ) ) );
00373
00374
00375 ++it;
00376 }
00377 }
00378
00379 void ConfigList::setConfirmDeletion( bool confirm )
00380 {
00381 m_bConfirmDelete = confirm;
00382 }
00383
00384 bool ConfigList::confirmDeletion( )
00385 {
00386 return m_bConfirmDelete;
00387 }
00388
00389 TQStringList ConfigList::getSelectedSubjects( ) const
00390 {
00391 TQStringList subjects;
00392 TQPtrListIterator<ConfigElem> it( *this );
00393 ConfigElem* account;
00394
00395 while( ( account = it.current() ) != NULL )
00396 {
00397
00398 subjects += account->getSelectedSubjects();
00399
00400
00401 ++it;
00402 }
00403
00404 return subjects;
00405 }
00406
00407 bool ConfigList::hasSelectedMails( )
00408 {
00409 bool foundSelected = false;
00410 TQPtrListIterator<ConfigElem> it( *this );
00411 ConfigElem* account;
00412
00413 while( ( account = it.current() ) != NULL && !foundSelected )
00414 {
00415 foundSelected = account->hasSelectedMails();
00416
00417
00418 ++it;
00419 }
00420
00421 return foundSelected;
00422
00423 }
00424
00425 void ConfigList::showSelectedMails( )
00426 {
00427 TQPtrListIterator<ConfigElem> it( *this );
00428 ConfigElem* account;
00429
00430
00431
00432 AccountShowBodiesMap.clear();
00433
00434
00435 connectAccounts();
00436
00437
00438
00439
00440
00441 while( ( account = it.current() ) != NULL )
00442 {
00443
00444 AccountShowBodiesMap.insert( account->getAccountName(), true );
00445
00446
00447 ++it;
00448 }
00449
00450
00451 it.toFirst();
00452 while( ( account = it.current() ) != NULL )
00453 {
00454 account->showSelectedMails();
00455
00456
00457 ++it;
00458 }
00459
00460 }
00461
00462 void ConfigList::slotCheckShowBodiesState( TQString account )
00463 {
00464 bool accountDownloading = false;
00465 AccountTaskMap_Type::Iterator it;
00466
00467
00468 AccountShowBodiesMap[ account ] = false;
00469
00470
00471
00472 for ( it = AccountShowBodiesMap.begin(); it != AccountShowBodiesMap.end(); ++it )
00473 {
00474 if( *it == true )
00475 accountDownloading = true;
00476 }
00477
00478
00479
00480 if( !accountDownloading )
00481 {
00482 emit sigShowBodiesReady();
00483 ctrOpenMessageWindows = 0;
00484 }
00485 }
00486
00487 void ConfigList::setAllowHTML( bool allowHTML )
00488 {
00489 m_bAllowHTML = allowHTML;
00490 }
00491
00492 bool ConfigList::allowHTML( ) const
00493 {
00494 return m_bAllowHTML;
00495 }
00496
00497 void ConfigList::slotMessageWindowOpened( )
00498 {
00499
00500 ctrOpenMessageWindows++;
00501
00502
00503
00504
00505 if( ctrOpenMessageWindows == 1 )
00506 emit sigMessageWindowOpened();
00507 }
00508
00509 void ConfigList::slotMessageWindowClosed( )
00510 {
00511
00512 ctrOpenMessageWindows--;
00513 if( ctrOpenMessageWindows < 0 )
00514 ctrOpenMessageWindows = 0;
00515
00516
00517
00518 if( ctrOpenMessageWindows == 0 )
00519 emit sigAllMessageWindowsClosed();
00520 }
00521
00522 void ConfigList::refreshMailLists( )
00523 {
00524 TQPtrListIterator<ConfigElem> it( *this );
00525 ConfigElem* account;
00526
00527
00528 if( count() == 0 )
00529 {
00530 emit sigRefreshReady();
00531 return;
00532 }
00533
00534
00535
00536 AccountRefreshMap.clear();
00537
00538
00539 connectAccounts();
00540
00541
00542
00543
00544
00545 while( ( account = it.current() ) != NULL )
00546 {
00547
00548 AccountRefreshMap.insert( account->getAccountName(), true );
00549
00550
00551 ++it;
00552 }
00553
00554
00555 it.toFirst();
00556 while( ( account = it.current() ) != NULL )
00557 {
00558 account->refreshMailList();
00559
00560
00561 ++it;
00562 }
00563
00564 }
00565
00566 void ConfigList::slotCheckRefreshState( TQString account )
00567 {
00568 bool accountRefreshing = false;
00569 AccountTaskMap_Type::Iterator it;
00570
00571
00572 AccountRefreshMap[ account ] = false;
00573
00574
00575
00576 for ( it = AccountRefreshMap.begin(); it != AccountRefreshMap.end(); ++it )
00577 {
00578 if( *it == true )
00579 accountRefreshing = true;
00580 }
00581
00582
00583 if( !accountRefreshing )
00584 {
00585 emit sigRefreshReady();
00586 }
00587
00588 }
00589
00590 int ConfigList::getNumberNewMails( )
00591 {
00592 TQPtrListIterator<ConfigElem> it( *this );
00593 ConfigElem* account;
00594 int number = 0;
00595
00596
00597 while( ( account = it.current() ) != NULL )
00598 {
00599 number += account->getNumberNewMails();
00600
00601
00602 ++it;
00603 }
00604
00605 return number;
00606 }
00607
00608 int ConfigList::getNumberMails( )
00609 {
00610 TQPtrListIterator<ConfigElem> it( *this );
00611 ConfigElem* account;
00612 int number = 0;
00613
00614
00615 while( ( account = it.current() ) != NULL )
00616 {
00617 number += account->getNumberMails();
00618
00619
00620 ++it;
00621 }
00622
00623 return number;
00624 }
00625
00626 long ConfigList::getTotalSize( )
00627 {
00628 TQPtrListIterator<ConfigElem> it( *this );
00629 ConfigElem* account;
00630 long size = 0;
00631
00632
00633 while( ( account = it.current() ) != NULL )
00634 {
00635 size += account->getTotalSize();
00636
00637
00638 ++it;
00639 }
00640
00641 return size;
00642 }
00643
00644 void ConfigList::fillMailListView( KshowmailView * view )
00645 {
00646 TQPtrListIterator<ConfigElem> it( *this );
00647 ConfigElem* account;
00648
00649
00650
00651 while( ( account = it.current() ) != NULL )
00652 {
00653 if( account->isActive() )
00654 account->fillMailListView( view );
00655
00656
00657 ++it;
00658 }
00659
00660 }
00661
00662 bool ConfigList::showMainWindowForNewMails( )
00663 {
00664 return m_bShowMainWindow;
00665 }
00666
00667 bool ConfigList::showAlertMessageForNewMails( )
00668 {
00669 return m_bShowMessage;
00670 }
00671
00672 bool ConfigList::quitNoNewMails( )
00673 {
00674 return m_bTerminate;
00675 }
00676
00677 bool ConfigList::minimizeMainWindowNoNewMails( )
00678 {
00679 return m_bMinimize;
00680 }
00681
00682 int ConfigList::getInitTime( )
00683 {
00684 return m_nInitTimer;
00685 }
00686
00687 void ConfigList::setInitTime( int time )
00688 {
00689 if( time >= 0 )
00690 m_nInitTimer = time;
00691 else
00692 m_nInitTimer = 0;
00693 }
00694
00695 bool ConfigList::hasInitTime( )
00696 {
00697 return m_nInitTimer > 0;
00698 }
00699
00700 void ConfigList::refreshAccountList( )
00701 {
00702 TQPtrListIterator<ConfigElem> it( *this );
00703 ConfigElem* account;
00704
00705
00706
00707 while( ( account = it.current() ) != NULL )
00708 {
00709 account->refreshAccountListItem();
00710
00711
00712 ++it;
00713 }
00714
00715 }
00716
00717 void ConfigList::killPOP3Jobs( )
00718 {
00719 TQPtrListIterator<ConfigElem> it( *this );
00720 ConfigElem* account;
00721
00722
00723
00724 while( ( account = it.current() ) != NULL )
00725 {
00726 account->killPOP3Job();
00727
00728
00729 ++it;
00730 }
00731 }
00732
00733 void ConfigList::showSelectedHeaders( )
00734 {
00735 TQPtrListIterator<ConfigElem> it( *this );
00736 ConfigElem* account;
00737 int showNextHeader = ConfigElem::continueShowHeaders;
00738
00739
00740
00741 while( ( account = it.current() ) != NULL && showNextHeader == ConfigElem::continueShowHeaders )
00742 {
00743 if( account->hasSelectedMails() )
00744 showNextHeader = account->showSelectedHeaders();
00745
00746
00747 ++it;
00748 }
00749 }
00750
00751 void ConfigList::refreshSetup( TDEListView* view )
00752 {
00753
00754 config = TDEApplication::kApplication()->config();
00755
00756
00757 config->setGroup( CONFIG_GROUP_ACTIONS );
00758
00759 m_bShowMessage = config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW );
00760 m_bShowMainWindow = config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, DEFAULT_ACTION_NEW_MAIL_MAINWINDOW );
00761 m_bBeep = config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, DEFAULT_ACTION_NEW_MAIL_BEEP );
00762 m_bSound = config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, DEFAULT_ACTION_NEW_MAIL_SOUND );
00763 m_strSoundFile = config->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH );
00764 m_bCommand = config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, DEFAULT_ACTION_NEW_MAIL_COMMAND );
00765 m_strCommandPath = config->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH );
00766 m_bMinimize = config->readBoolEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE );
00767 m_bTerminate = config->readBoolEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE );
00768
00769
00770 config->setGroup( CONFIG_GROUP_GENERAL );
00771 m_bConfirmClose = config->readBoolEntry( CONFIG_ENTRY_CONFIRM_CLOSE, DEFAULT_CONFIRM_CLOSE );
00772 m_bConfirmDelete = config->readBoolEntry( CONFIG_ENTRY_CONFIRM_DELETE, DEFAULT_CONFIRM_DELETE );
00773 m_bStartMinimized = config->readBoolEntry( CONFIG_ENTRY_START_MINIMIZED, DEFAULT_START_MINIMIZED );
00774 m_bCloseMinimizes = config->readBoolEntry( CONFIG_ENTRY_CLOSE_TO_TRAY, DEFAULT_CLOSE_TO_TRAY );
00775 m_bMinimizeToTray = config->readBoolEntry( CONFIG_ENTRY_MINIMIZE_TO_TRAY, DEFAULT_MINIMIZE_TO_TRAY );
00776 m_bShowConnectionErrors = config->readBoolEntry( CONFIG_ENTRY_SHOW_CONNECTION_ERRORS, DEFAULT_SHOW_CONNECTION_ERRORS );
00777 m_bKeepNew = config->readBoolEntry( CONFIG_ENTRY_KEEP_NEW, DEFAULT_KEEP_NEW );
00778
00779 m_nInitTimer = config->readNumEntry( CONFIG_ENTRY_INITIAL_TIME, DEFAULT_INITIAL_TIME );
00780 m_nIntervalTimer = config->readNumEntry( CONFIG_ENTRY_INTERVAL_TIME, DEFAULT_INTERVAL_TIME);
00781 m_nPop3Timer = config->readNumEntry( CONFIG_ENTRY_TIMEOUT_TIME, DEFAULT_TIMEOUT_TIME );
00782
00783
00784 config->setGroup( CONFIG_GROUP_VIEW );
00785 m_bAllowHTML = config->readBoolEntry( CONFIG_ENTRY_VIEW_USE_HTML, DEFAULT_VIEW_USE_HTML );
00786
00787
00788
00789
00790
00791 config->setGroup( CONFIG_GROUP_ACCOUNTS );
00792 TQStringList accounts = config->readListEntry( CONFIG_ENTRY_ACCOUNTS_LIST, TQStringList() );
00793
00794
00795
00796 ConfigElem* accountDel = NULL;
00797 TQPtrListIterator<ConfigElem> iter( *this );
00798
00799
00800 while( ( accountDel = iter.current() ) != NULL )
00801 {
00802
00803 ++iter;
00804
00805
00806 TQStringList::Iterator foundAccount = accounts.find( accountDel->getAccountName() );
00807
00808
00809 if( foundAccount == accounts.end() )
00810 remove( accountDel );
00811 }
00812
00813
00814 ConfigElem* acc;
00815
00816 for( TQStringList::Iterator it = accounts.begin(); it != accounts.end(); ++it )
00817 {
00818
00819
00820 if( !hasAccount( *it ) )
00821 {
00822
00823 acc = new ConfigElem( this, *it );
00824 inSort( acc );
00825
00826
00827
00828 delete acc;
00829 }
00830
00831
00832 acc = getAccount( *it );
00833
00834
00835 config->setGroup( *it );
00836
00837 acc->setHost( config->readEntry( CONFIG_ENTRY_ACCOUNT_SERVER, DEFAULT_ACCOUNT_SERVER ) );
00838 acc->setProtocol( config->readEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, DEFAULT_ACCOUNT_PROTOCOL ).lower() );
00839 acc->setPort( config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PORT, DEFAULT_ACCOUNT_PORT_POP3 ) );
00840 acc->setUser( config->readEntry( CONFIG_ENTRY_ACCOUNT_USER, DEFAULT_ACCOUNT_USER ) );
00841 acc->setActive( config->readBoolEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, DEFAULT_ACCOUNT_ACTIVE ) );
00842 int StorageType = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00843
00844 switch( StorageType )
00845 {
00846 case CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE:
00847 acc->setPasswordStorage( CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE );
00848 acc->setPassword( TQString::null );
00849 break;
00850
00851 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE:
00852 acc->setPasswordStorage( CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE );
00853 acc->setPassword( Encryption::decrypt( config->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, DEFAULT_ACCOUNT_PASSWORD ) ) );
00854 break;
00855
00856 case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_TDEWALLET:
00857 acc->setPasswordStorage( CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_TDEWALLET );
00858 acc->setPassword( TDEWalletAccess::getPassword( *it ) );
00859 break;
00860
00861 default:
00862 acc->setPasswordStorage( DEFAULT_ACCOUNT_PASSWORD_STORAGE );
00863 acc->setPassword( TQString::null );
00864 }
00865
00866 }
00867
00868
00869 connectAccounts();
00870
00871
00872 setList( view );
00873 }
00874
00875 void ConfigList::executeNewMailCommand( )
00876 {
00877 if( m_bCommand )
00878 {
00879 if( m_strCommandPath != TQString::null && m_strCommandPath != "" )
00880 {
00881 KShellProcess proc;
00882
00883 proc << m_strCommandPath;
00884
00885 proc.start( KShellProcess::DontCare );
00886 }
00887 }
00888 }
00889
00890 bool ConfigList::keepNew( )
00891 {
00892 return m_bKeepNew;
00893 }
00894
00895 bool ConfigList::confirmClose( ) const
00896 {
00897 return m_bConfirmClose;
00898 }
00899
00900 bool ConfigList::startMinimized( ) const
00901 {
00902 return m_bStartMinimized;
00903 }
00904
00905 bool ConfigList::closeToTray( ) const
00906 {
00907 return m_bCloseMinimizes;
00908 }
00909
00910 bool ConfigList::minimizesToTray( ) const
00911 {
00912 return m_bMinimizeToTray;
00913 }
00914
00915 bool ConfigList::showConnectionErrors( ) const
00916 {
00917 return m_bShowConnectionErrors;
00918 }
00919
00920 bool ConfigList::hasAccount( const TQString & name ) const
00921 {
00922 bool found = false;
00923 ConfigElem* account;
00924 TQPtrListIterator<ConfigElem> it( *this );
00925
00926
00927 while( ( account = it.current() ) != NULL && !found )
00928 {
00929
00930 ++it;
00931
00932
00933 if( account->getAccountName() == name )
00934 found = true;
00935 }
00936
00937 return found;
00938 }
00939
00940 ConfigElem * ConfigList::getAccount( const TQString & name ) const
00941 {
00942 bool found = false;
00943 ConfigElem* account = NULL;
00944 TQPtrListIterator<ConfigElem> it( *this );
00945 ConfigElem* returnValue = NULL;
00946
00947
00948 while( ( account = it.current() ) != NULL && !found )
00949 {
00950
00951 ++it;
00952
00953
00954 if( account->getAccountName() == name )
00955 {
00956 found = true;
00957 returnValue = account;
00958 }
00959 }
00960
00961 return returnValue;
00962 }
00963
00964 void ConfigList::printSetup( )
00965 {
00966 ConfigElem* account = NULL;
00967 TQPtrListIterator<ConfigElem> it( *this );
00968
00969
00970 while( ( account = it.current() ) != NULL )
00971 {
00972
00973 ++it;
00974
00975
00976 account->printSetup();
00977 }
00978 }
00979
00980 void ConfigList::readStoredMails( )
00981 {
00982
00983 TQString MailFileName = locateLocal( "config", MAIL_FILE );
00984 TQFile file( MailFileName );
00985 bool fileOpen = file.open( IO_ReadOnly );
00986
00987
00988 if( !fileOpen )
00989 {
00990 kdError() << "ConfigList::readStoredMails: File " << MailFileName << " could not be opened." << endl;
00991 return;
00992 }
00993
00994
00995 TQDomDocument doc( MAIL_FILE_DOCTYPE );
00996 TQString* errorMsg = new TQString();
00997
00998 bool success = doc.setContent( &file );
00999 if( !success )
01000 {
01001 kdError() << "ConfigList::readStoredMails: Invalid content in " << MAIL_FILE << ". " << *errorMsg << endl;
01002 }
01003
01004
01005 TQDomElement accounts = doc.namedItem ( ROOT_ELEMENT ).toElement();
01006
01007
01008 TQDomNode accNode = accounts.firstChild();
01009
01010
01011 while( !accNode.isNull() )
01012 {
01013
01014 TQDomElement accElem = accNode.toElement();
01015
01016
01017 TQString accName = accElem.attribute( ATTRIBUTE_ACCOUNT_NAME );
01018
01019
01020 ConfigElem* account = getAccount( accName );
01021
01022
01023 account->readStoredMails( accElem );
01024
01025
01026 accNode = accNode.nextSibling();
01027 }
01028
01029
01030 file.close();
01031 }
01032
01033