From b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 24 Jul 2013 15:57:00 -0500 Subject: Initial import from kshowmail 3.3.1 sources --- doc/html/configlist_8cpp-source.html | 1055 ++++++++++++++++++++++++++++++++++ 1 file changed, 1055 insertions(+) create mode 100644 doc/html/configlist_8cpp-source.html (limited to 'doc/html/configlist_8cpp-source.html') diff --git a/doc/html/configlist_8cpp-source.html b/doc/html/configlist_8cpp-source.html new file mode 100644 index 0000000..2564682 --- /dev/null +++ b/doc/html/configlist_8cpp-source.html @@ -0,0 +1,1055 @@ + + +kshowmail: kshowmail/configlist.cpp Source File + + + + +
+
+ +

configlist.cpp

00001 /***************************************************************************
+00002                           configlist.cpp  -  description
+00003                              -------------------
+00004     begin                : Tue May 9 2000
+00005     copyright            : (C) 2000-2001 by Eggert Ehmke
+00006     email                : eggert.ehmke@berlin.de
+00007 
+00008     26 Sep 2002 - Allow for columns to be hidden. Allistar Melville
+00009  ***************************************************************************/
+00010 
+00011 /***************************************************************************
+00012  *                                                                         *
+00013  *   This program is free software; you can redistribute it and/or modify  *
+00014  *   it under the terms of the GNU General Public License as published by  *
+00015  *   the Free Software Foundation; either version 2 of the License, or     *
+00016  *   (at your option) any later version.                                   *
+00017  *                                                                         *
+00018  ***************************************************************************/
+00019 #include <stdio.h>
+00020 #include <stdlib.h>
+00021 
+00022 #include <qfile.h>
+00023 
+00024 #include <kconfig.h>
+00025 #include <ksavefile.h>
+00026 #include <kapplication.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() : QObject()
+00035 {
+00036        setAutoDelete (true);
+00037 
+00038     //assume, no window to show a mail is open at beginning
+00039     ctrOpenMessageWindows = 0;
+00040 
+00041     //set default values
+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( QCollection::Item item1, QCollection::Item item2 )
+00063 {
+00064   ConfigElem* p1 = (ConfigElem*)item1;
+00065   ConfigElem* p2 = (ConfigElem*)item2;
+00066 
+00067   return strcmp( p1->getAccountName(), p2->getAccountName() );
+00068 }
+00069 
+00070 QCollection::Item ConfigList::newItem( QCollection::Item item )
+00071 {
+00072   return new ConfigElem( (ConfigElem*)item );
+00073 }
+00074 
+00075 void ConfigList::saveOptions ()
+00076 {
+00077   kdDebug () << "ConfigList::saveOptions" << endl;
+00078 
+00079   //create XML document
+00080   QDomDocument doc( "KShowmail" );
+00081 
+00082   //create root element
+00083   QDomElement accounts = doc.createElement( ROOT_ELEMENT );
+00084 
+00085   //create for every account an element
+00086   //the account saves its mails into this element
+00087   //after that the element will be appended to the root element
+00088   int i = 0;
+00089   ConfigElem* account = NULL;               //current processed account
+00090   QPtrListIterator<ConfigElem> it( *this ); //iterator for the account list
+00091 
+00092   //iterate over all accounts
+00093   while( ( account = it.current() ) != NULL )
+00094   {
+00095     //increment iterator to next account
+00096     ++it;
+00097 
+00098     //save mails
+00099     QDomElement accElem = doc.createElement( QString( ACCOUNT_ELEMENT ) + QString( "%1" ).arg( i++ ) );
+00100     account->saveOptions( doc, accElem ); //account saves the mails into given XML document and the setup into the application config file
+00101     accounts.appendChild( accElem );
+00102 
+00103   }
+00104 
+00105   //append root element to XML document
+00106   doc.appendChild( accounts );
+00107 
+00108   //save XML document
+00109   QCString str = doc.toCString(); //convert XML document to a string
+00110   QString cachefilename = locateLocal( "config", "kshowmail.xml" ); //get file path
+00111   KSaveFile file( cachefilename, 0600 );  //create file
+00112 
+00113   if( file.status() != 0 )
+00114   {
+00115     kdError() << "Couldn't save mail cache. " << strerror( file.status() );
+00116     return;
+00117   }
+00118 
+00119     //write data
+00120   file.file()->writeBlock( str.data(), str.length() );
+00121 
+00122     //close file
+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 (QListView* list)
+00132 {
+00133        QPixmap pix (::locate ("data", "kshowmail/pics/ok.png"));
+00134        list->clear ();
+00135        int nIndex = at ();
+00136        QListViewItem* last = NULL;
+00137        for (ConfigElem* pElem = first(); pElem; pElem = next())
+00138        {
+00139               last = new QListViewItem (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 //            list->setCurrentItem (nIndex);
+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;    //when a active account was found, this will be set to TRUE
+00218   ConfigElem* currentAccount;         //saved current account
+00219   ConfigElem* Account;                //used by the search
+00220 
+00221   //save the current account
+00222   currentAccount = current();
+00223 
+00224   //get the first account
+00225   Account = first();
+00226 
+00227   //looking for an active account
+00228   while( Account != NULL && !activeAccountFound )
+00229   {
+00230     //have we found one?
+00231     activeAccountFound = Account->isActive();
+00232 
+00233     //get next account
+00234     Account = next();
+00235   }
+00236 
+00237   //set the saved account to current
+00238   if( currentAccount != NULL )
+00239     findRef( currentAccount );
+00240 
+00241   //return the result
+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   //get the first account in the list
+00262   ConfigElem* account = first();
+00263 
+00264   //return NULL if there are no accounts
+00265   if( account == NULL )
+00266     return NULL;
+00267 
+00268   //return the account, if it is selected
+00269   if( account->isSelected() )
+00270     return account;
+00271 
+00272   //iterate over all accounts
+00273   bool selectedAccountFound = false;  //is TRUE, if a selected account was found
+00274   while( account != NULL && !selectedAccountFound )
+00275   {
+00276     //get next account
+00277     account = next();
+00278 
+00279     //is the account selected?
+00280     if( account != NULL )
+00281       selectedAccountFound = account->isSelected();
+00282     else
+00283       selectedAccountFound = false;
+00284   }
+00285 
+00286   //return the current account if we have found a selected account
+00287   //otherwise return FALSE
+00288   if( selectedAccountFound )
+00289     return account;
+00290   else
+00291     return NULL;
+00292 }
+00293 
+00294 void ConfigList::deleteSelectedMails( )
+00295 {
+00296   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00297   ConfigElem* account;                        //account to process
+00298 
+00299   //clear the map, which contains the names of the accounts,
+00300   //which have gotten an order to delete
+00301   AccountDeletionMap.clear();
+00302 
+00303   //refresh connects
+00304   connectAccounts();
+00305 
+00306   //inserts an item for every account which will get an order to delete
+00307   //its selected mails. The key is the account name and the data is TRUE.
+00308   //it is important to do this in a seperate iteration because this avoids
+00309   //race conditions
+00310   while( ( account = it.current() ) != NULL )
+00311   {
+00312     //insert item
+00313     AccountDeletionMap.insert( account->getAccountName(), true );
+00314 
+00315     //get next account
+00316     ++it;
+00317   }
+00318 
+00319   //order all accounts to delete its selected mail
+00320   it.toFirst();
+00321   while( ( account = it.current() ) != NULL )
+00322   {
+00323     account->deleteSelectedMails();
+00324 
+00325     //get next account
+00326     ++it;
+00327   }
+00328 }
+00329 
+00330 void ConfigList::slotAccountConfigChanged( )
+00331 {
+00332   emit sigConfigChanged();
+00333 }
+00334 
+00335 void ConfigList::slotCheckDeletionState( QString account )
+00336 {
+00337   bool accountDeleting = false;     //set to TRUE if an account is still deleting
+00338   AccountTaskMap_Type::Iterator it; //iterator over the account deletion map
+00339 
+00340   //set the appropriate item in AccountDeletionMap to FALSE
+00341   AccountDeletionMap[ account ] = false;
+00342 
+00343   //iterate over the account deletion map to check, whether all accounts
+00344   //are ready
+00345   for ( it = AccountDeletionMap.begin(); it != AccountDeletionMap.end(); ++it )
+00346   {
+00347     if( *it == true )
+00348       accountDeleting = true;
+00349   }
+00350 
+00351   //emit sigDeleteReady if all accounts are ready
+00352   if( !accountDeleting )
+00353     emit sigDeleteReady();
+00354 }
+00355 
+00356 void ConfigList::connectAccounts( )
+00357 {
+00358   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00359   ConfigElem* account;                        //account to connect
+00360 
+00361   while( ( account = it.current() ) != NULL )
+00362   {
+00363     //disconnect old connections
+00364     account->disconnect();
+00365 
+00366     //connect
+00367     connect( account, SIGNAL( sigConfigChanged() ), this, SLOT( slotAccountConfigChanged() ) );
+00368     connect( account, SIGNAL( sigDeleteReady( QString ) ), this, SLOT( slotCheckDeletionState( QString ) ) );
+00369     connect( account, SIGNAL( sigShowBodiesReady( QString ) ), this, SLOT( slotCheckShowBodiesState( QString ) ) );
+00370     connect( account, SIGNAL( sigMessageWindowOpened() ), this, SLOT( slotMessageWindowOpened() ) );
+00371     connect( account, SIGNAL( sigMessageWindowClosed() ), this, SLOT( slotMessageWindowClosed() ) );
+00372     connect( account, SIGNAL( sigRefreshReady( QString ) ), this, SLOT( slotCheckRefreshState( QString ) ) );
+00373 
+00374     //get next account
+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 QStringList ConfigList::getSelectedSubjects( ) const
+00390 {
+00391   QStringList subjects;                       //contains all subjects
+00392   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00393   ConfigElem* account;                        //current account
+00394 
+00395   while( ( account = it.current() ) != NULL )
+00396   {
+00397     //get subjects of the current account and append them to the list
+00398     subjects += account->getSelectedSubjects();
+00399 
+00400     //get next account
+00401     ++it;
+00402   }
+00403 
+00404   return subjects;
+00405 }
+00406 
+00407 bool ConfigList::hasSelectedMails( )
+00408 {
+00409   bool foundSelected = false;                 //set to TRUE, when an account with selected mails was found
+00410   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00411   ConfigElem* account;                        //current account
+00412 
+00413   while( ( account = it.current() ) != NULL && !foundSelected )
+00414   {
+00415     foundSelected = account->hasSelectedMails();
+00416 
+00417     //get next account
+00418     ++it;
+00419   }
+00420 
+00421   return foundSelected;
+00422 
+00423 }
+00424 
+00425 void ConfigList::showSelectedMails( )
+00426 {
+00427   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00428   ConfigElem* account;                        //account to process
+00429 
+00430   //clear the map, which contains the names of the accounts,
+00431   //which have gotten an order to show mails
+00432   AccountShowBodiesMap.clear();
+00433 
+00434   //refresh connects
+00435   connectAccounts();
+00436 
+00437   //inserts an item for every account which will get an order to show
+00438   //its selected mails. The key is the account name and the data is TRUE.
+00439   //it is important to do this in a seperate iteration because this avoids
+00440   //race conditions
+00441   while( ( account = it.current() ) != NULL )
+00442   {
+00443     //insert item
+00444     AccountShowBodiesMap.insert( account->getAccountName(), true );
+00445 
+00446     //get next account
+00447     ++it;
+00448   }
+00449 
+00450   //order all accounts to show its selected mail
+00451   it.toFirst();
+00452   while( ( account = it.current() ) != NULL )
+00453   {
+00454     account->showSelectedMails();
+00455 
+00456     //get next account
+00457     ++it;
+00458   }
+00459 
+00460 }
+00461 
+00462 void ConfigList::slotCheckShowBodiesState( QString account )
+00463 {
+00464   bool accountDownloading = false;    //set to TRUE if an account is downloading mail body yet
+00465   AccountTaskMap_Type::Iterator it;   //iterator over the account map
+00466 
+00467   //set the appropriate item in AccountShowBodiesMap to FALSE
+00468   AccountShowBodiesMap[ account ] = false;
+00469 
+00470   //iterate over the account map to check, whether all accounts
+00471   //are ready
+00472   for ( it = AccountShowBodiesMap.begin(); it != AccountShowBodiesMap.end(); ++it )
+00473   {
+00474     if( *it == true )
+00475       accountDownloading = true;
+00476   }
+00477 
+00478   //emit sigShowBodiesReady if all accounts are ready
+00479   //and assume all windows to show the mails are closed
+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   //increment the window counter
+00500   ctrOpenMessageWindows++;
+00501 
+00502   //if the counter was incremented from zero
+00503   //(the first window was opened), emit the
+00504   //signal
+00505   if( ctrOpenMessageWindows == 1 )
+00506     emit sigMessageWindowOpened();
+00507 }
+00508 
+00509 void ConfigList::slotMessageWindowClosed( )
+00510 {
+00511   //decrement the window counter
+00512   ctrOpenMessageWindows--;
+00513   if( ctrOpenMessageWindows < 0 )
+00514     ctrOpenMessageWindows = 0;
+00515 
+00516   //if counter is zero (all windows was closed),
+00517   //emit signal
+00518   if( ctrOpenMessageWindows == 0 )
+00519     emit sigAllMessageWindowsClosed();
+00520 }
+00521 
+00522 void ConfigList::refreshMailLists( )
+00523 {
+00524   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00525   ConfigElem* account;                        //account to process
+00526 
+00527   //return, if no accounts available
+00528   if( count() == 0 )
+00529   {
+00530     emit sigRefreshReady();
+00531     return;
+00532   }
+00533 
+00534   //clear the map, which contains the names of the accounts,
+00535   //which have gotten an order to show mails
+00536   AccountRefreshMap.clear();
+00537 
+00538   //refresh connects
+00539   connectAccounts();
+00540 
+00541   //inserts an item for every account which will get an order to refresh
+00542   //its mail list. The key is the account name and the data is TRUE.
+00543   //it is important to do this in a seperate iteration because this avoids
+00544   //race conditions
+00545   while( ( account = it.current() ) != NULL )
+00546   {
+00547     //insert item
+00548     AccountRefreshMap.insert( account->getAccountName(), true );
+00549 
+00550     //get next account
+00551     ++it;
+00552   }
+00553 
+00554   //order all accounts to refresh their mail lists
+00555   it.toFirst();
+00556   while( ( account = it.current() ) != NULL )
+00557   {
+00558     account->refreshMailList();
+00559 
+00560     //get next account
+00561     ++it;
+00562   }
+00563 
+00564 }
+00565 
+00566 void ConfigList::slotCheckRefreshState( QString account )
+00567 {
+00568   bool accountRefreshing = false;    //set to TRUE if an account is still refreshing
+00569   AccountTaskMap_Type::Iterator it;   //iterator over the account map
+00570 
+00571   //set the appropriate item in AccountRefreshMap to FALSE
+00572   AccountRefreshMap[ account ] = false;
+00573 
+00574   //iterate over the account map to check whether all accounts
+00575   //are ready
+00576   for ( it = AccountRefreshMap.begin(); it != AccountRefreshMap.end(); ++it )
+00577   {
+00578     if( *it == true )
+00579       accountRefreshing = true;
+00580   }
+00581 
+00582   //emit sigRefreshReady if all accounts are ready
+00583   if( !accountRefreshing )
+00584   {
+00585     emit sigRefreshReady();
+00586   }
+00587 
+00588 }
+00589 
+00590 int ConfigList::getNumberNewMails( )
+00591 {
+00592   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00593   ConfigElem* account;                        //account to process
+00594   int number = 0;                             //number of new mails
+00595 
+00596   //iterate over all accounts and sum up the number of new mails
+00597   while( ( account = it.current() ) != NULL )
+00598   {
+00599    number += account->getNumberNewMails();
+00600 
+00601     //get next account
+00602     ++it;
+00603   }
+00604 
+00605   return number;
+00606 }
+00607 
+00608 int ConfigList::getNumberMails( )
+00609 {
+00610   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00611   ConfigElem* account;                        //account to process
+00612   int number = 0;                             //number of mails
+00613 
+00614   //iterate over all accounts and sum up the number of mails
+00615   while( ( account = it.current() ) != NULL )
+00616   {
+00617     number += account->getNumberMails();
+00618 
+00619     //get next account
+00620     ++it;
+00621   }
+00622 
+00623   return number;
+00624 }
+00625 
+00626 long ConfigList::getTotalSize( )
+00627 {
+00628   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00629   ConfigElem* account;                        //account to process
+00630   long size = 0;                               //total size of all mails
+00631 
+00632   //iterate over all accounts and sum up the size of all mails
+00633   while( ( account = it.current() ) != NULL )
+00634   {
+00635     size += account->getTotalSize();
+00636 
+00637     //get next account
+00638     ++it;
+00639   }
+00640 
+00641   return size;
+00642 }
+00643 
+00644 void ConfigList::fillMailListView( KshowmailView * view )
+00645 {
+00646   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00647   ConfigElem* account;                        //account to process
+00648 
+00649   //iterate over all accounts and order the active accounts to fill their mails
+00650   //into the list view
+00651   while( ( account = it.current() ) != NULL )
+00652   {
+00653     if( account->isActive() )
+00654       account->fillMailListView( view );
+00655 
+00656     //get next account
+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   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00703   ConfigElem* account;                        //account to process
+00704 
+00705   //iterate over all accounts and order the account to refresh its
+00706   //account list view item
+00707   while( ( account = it.current() ) != NULL )
+00708   {
+00709     account->refreshAccountListItem();
+00710 
+00711     //get next account
+00712     ++it;
+00713   }
+00714 
+00715 }
+00716 
+00717 void ConfigList::killPOP3Jobs( )
+00718 {
+00719   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00720   ConfigElem* account;                        //account to process
+00721 
+00722   //iterate over all accounts and order the account to kill
+00723   //a running pop3 job
+00724   while( ( account = it.current() ) != NULL )
+00725   {
+00726     account->killPOP3Job();
+00727 
+00728     //get next account
+00729     ++it;
+00730   }
+00731 }
+00732 
+00733 void ConfigList::showSelectedHeaders( )
+00734 {
+00735   QPtrListIterator<ConfigElem> it( *this );   //to iterate over all accounts
+00736   ConfigElem* account;                        //account to process
+00737   int showNextHeader = ConfigElem::continueShowHeaders; //return value of ConfigElem::showSelectedHeaders
+00738 
+00739   //iterate over all accounts and order the account to show
+00740   //the headers of all selected mails.
+00741   while( ( account = it.current() ) != NULL && showNextHeader == ConfigElem::continueShowHeaders )
+00742   {
+00743     if( account->hasSelectedMails() )
+00744       showNextHeader = account->showSelectedHeaders();
+00745 
+00746     //get next account
+00747     ++it;
+00748   }
+00749 }
+00750 
+00751 void ConfigList::refreshSetup( KListView* view )
+00752 {
+00753   //get application config object (kshowmailrc)
+00754   config = KApplication::kApplication()->config();
+00755 
+00756   //read actions group
+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   //read general group
+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   //read display group
+00784   config->setGroup( CONFIG_GROUP_VIEW );
+00785   m_bAllowHTML = config->readBoolEntry( CONFIG_ENTRY_VIEW_USE_HTML, DEFAULT_VIEW_USE_HTML );
+00786 
+00787   //read account configuration and setup accounts
+00788   //---------------------------------------------
+00789 
+00790   //get account names from the config file
+00791   config->setGroup( CONFIG_GROUP_ACCOUNTS );
+00792   QStringList accounts = config->readListEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() );
+00793 
+00794   //remove deleted accounts from the account list
+00795   //accounts are deleted, if the are in ConfigList yet, but not in the list of the config file (accounts)
+00796   ConfigElem* accountDel = NULL;               //current processed account
+00797   QPtrListIterator<ConfigElem> iter( *this ); //iterator for the account list (ConfigList)
+00798 
+00799     //iterate over all accounts (ConfigList)
+00800   while( ( accountDel = iter.current() ) != NULL )
+00801   {
+00802     //increment iterator to get next account
+00803     ++iter;
+00804 
+00805     //search for the current account in the account list of the config file
+00806     QStringList::Iterator foundAccount = accounts.find( accountDel->getAccountName() );
+00807 
+00808     //remove account from ConfigList, if it is not in the list of the config file
+00809     if( foundAccount == accounts.end() )
+00810       remove( accountDel );
+00811   }
+00812 
+00813   //add or edit accounts
+00814   ConfigElem* acc;
+00815     //iterate over all items of the account list of the config file
+00816   for( QStringList::Iterator it = accounts.begin(); it != accounts.end(); ++it )
+00817   {
+00818     //create a new account, if it is not in the list yet (ConfigList)
+00819     //or get the account
+00820     if( !hasAccount( *it ) )
+00821     {
+00822       //create new account
+00823       acc = new ConfigElem( this, *it );
+00824       inSort( acc );
+00825 
+00826       //the pointer list inserts a copy of the new account object
+00827       //we have to delete the original
+00828       delete acc;
+00829     }
+00830 
+00831     //get account from ConfigList
+00832     acc = getAccount( *it );
+00833 
+00834     //get the setup of the account from the config file and setup the account
+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( QString::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_KWALLET:
+00857         acc->setPasswordStorage( CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET );
+00858         acc->setPassword( KWalletAccess::getPassword( *it ) );
+00859         break;
+00860 
+00861       default:
+00862         acc->setPasswordStorage( DEFAULT_ACCOUNT_PASSWORD_STORAGE );
+00863         acc->setPassword( QString::null );
+00864     }
+00865 
+00866   }
+00867 
+00868   //connect the signals of the accounts with ConfigList
+00869   connectAccounts();
+00870 
+00871   //refresh account list view
+00872   setList( view );
+00873 }
+00874 
+00875 void ConfigList::executeNewMailCommand( )
+00876 {
+00877   if( m_bCommand )
+00878   {
+00879     if( m_strCommandPath != QString::null && m_strCommandPath != "" )
+00880     {
+00881       KShellProcess proc;    //process handler to execute the binary
+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 QString & name ) const
+00921 {
+00922   bool found = false;                       //TRUE if we have found the given account
+00923   ConfigElem* account;                      //account from which we want to get its name
+00924   QPtrListIterator<ConfigElem> it( *this ); //iterator for the account list
+00925 
+00926   //iterate over all accounts
+00927   while( ( account = it.current() ) != NULL && !found )
+00928   {
+00929     //increment iterator to next account
+00930     ++it;
+00931 
+00932     //if current account is the searched one set found to TRUE
+00933     if( account->getAccountName() == name )
+00934       found = true;
+00935   }
+00936 
+00937   return found;
+00938 }
+00939 
+00940 ConfigElem * ConfigList::getAccount( const QString & name ) const
+00941 {
+00942   bool found = false;                       //TRUE if we have found the given account
+00943   ConfigElem* account = NULL;               //account from which we want to get its name
+00944   QPtrListIterator<ConfigElem> it( *this ); //iterator for the account list
+00945   ConfigElem* returnValue = NULL;
+00946 
+00947   //iterate over all accounts
+00948   while( ( account = it.current() ) != NULL && !found )
+00949   {
+00950     //increment iterator to next account
+00951     ++it;
+00952 
+00953     //if current account is the searched one set found to TRUE
+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;               //account from which we want to print the setup
+00967   QPtrListIterator<ConfigElem> it( *this ); //iterator for the account list
+00968 
+00969   //iterate over all accounts
+00970   while( ( account = it.current() ) != NULL )
+00971   {
+00972     //increment iterator to next account
+00973     ++it;
+00974 
+00975     //print setup
+00976     account->printSetup();
+00977   }
+00978 }
+00979 
+00980 void ConfigList::readStoredMails( )
+00981 {
+00982   //open file
+00983   QString MailFileName = locateLocal( "config", MAIL_FILE );
+00984   QFile file( MailFileName );
+00985   bool fileOpen = file.open( IO_ReadOnly );
+00986 
+00987   //return, if the file could not be opened
+00988   if( !fileOpen )
+00989   {
+00990     kdError() << "ConfigList::readStoredMails: File " << MailFileName << " could not be opened." << endl;
+00991     return;
+00992   }
+00993 
+00994   //create DOM document with the content read from the file
+00995   QDomDocument doc( MAIL_FILE_DOCTYPE );
+00996   QString* errorMsg = new QString();
+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   //get the root element
+01005   QDomElement accounts = doc.namedItem ( ROOT_ELEMENT ).toElement();
+01006 
+01007   //get the first account element
+01008   QDomNode accNode = accounts.firstChild();
+01009 
+01010   //get all account elements
+01011   while( !accNode.isNull() )
+01012   {
+01013     //convert account node to DOM element
+01014     QDomElement accElem = accNode.toElement();
+01015 
+01016     //get the account name
+01017     QString accName = accElem.attribute( ATTRIBUTE_ACCOUNT_NAME );
+01018 
+01019     //get the proper account object
+01020     ConfigElem* account = getAccount( accName );
+01021 
+01022     //order the account to read its stored mails
+01023     account->readStoredMails( accElem );
+01024 
+01025     //get next account node
+01026     accNode = accNode.nextSibling();
+01027   }
+01028 
+01029   //close file
+01030   file.close();
+01031 }
+01032 
+01033 
+

Generated on Thu Jul 5 19:36:06 2007 for kshowmail by  + +doxygen 1.5.0
+ + -- cgit v1.2.3