TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

accountmanager.cpp 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "accountmanager.h"
  19. #include "dcopdrop.h"
  20. #include "tdeio.h"
  21. #include "maildrop.h"
  22. #include "password.h"
  23. #include "protocol.h"
  24. #include "protocols.h"
  25. #include "subjectsdlg.h"
  26. #include <kaudioplayer.h>
  27. #include <tdeconfig.h>
  28. #include <kdebug.h>
  29. #include <tqptrlist.h>
  30. KornSubjectsDlg* AccountManager::_subjectsDlg = 0;
  31. AccountManager::AccountManager( TQObject * parent, const char * name )
  32. : TQObject( parent, name ),
  33. _kioList( new TQPtrList< KMailDrop > ),
  34. _dcopList( new TQPtrList< DCOPDrop > ),
  35. _dropInfo( new TQMap< KMailDrop*, Dropinfo* > )
  36. {
  37. _kioList->setAutoDelete( true );
  38. _dcopList->setAutoDelete( true );
  39. }
  40. AccountManager::~AccountManager()
  41. {
  42. delete _kioList;
  43. delete _dcopList;
  44. delete _dropInfo;
  45. }
  46. void AccountManager::readConfig( TDEConfig* config, const int index )
  47. {
  48. TDEConfigGroup *masterGroup = new TDEConfigGroup( config, TQString( "korn-%1" ).arg( index ) );
  49. TQStringList dcop = masterGroup->readListEntry( "dcop", ',' );
  50. TDEConfigGroup *accountGroup;
  51. int counter = 0;
  52. while( config->hasGroup( TQString( "korn-%1-%2" ).arg( index ).arg( counter ) ) )
  53. {
  54. accountGroup = new TDEConfigGroup( config, TQString( "korn-%1-%2" ).arg( index ).arg( counter ) );
  55. const Protocol *proto = Protocols::getProto( accountGroup->readEntry( "protocol" ) );
  56. if( !proto )
  57. {
  58. kdWarning() << "Protocol werd niet gevonden" << endl;
  59. ++counter;
  60. continue;
  61. }
  62. TQMap< TQString, TQString > *configmap = proto->createConfig( accountGroup,
  63. KOrnPassword::readKOrnPassword( index, counter, *accountGroup ) );
  64. KMailDrop *kiodrop = proto->createMaildrop( accountGroup );
  65. const Protocol *nproto = proto->getProtocol( accountGroup );
  66. Dropinfo *info = new Dropinfo;
  67. if( !kiodrop || !configmap || !nproto )
  68. {
  69. //Error occured when reading for config
  70. ++counter;
  71. delete info;
  72. continue;
  73. }
  74. //TODO: connect some stuff
  75. connect( kiodrop, TQT_SIGNAL( changed( int, KMailDrop* ) ), this, TQT_SLOT( slotChanged( int, KMailDrop* ) ) );
  76. connect( kiodrop, TQT_SIGNAL( showPassivePopup( TQPtrList< KornMailSubject >*, int, bool, const TQString& ) ),
  77. this, TQT_SLOT( slotShowPassivePopup( TQPtrList< KornMailSubject >*, int, bool, const TQString& ) ) );
  78. connect( kiodrop, TQT_SIGNAL( showPassivePopup( const TQString&, const TQString& ) ),
  79. this, TQT_SLOT( slotShowPassivePopup( const TQString&, const TQString& ) ) );
  80. connect( kiodrop, TQT_SIGNAL( validChanged( bool ) ), this, TQT_SLOT( slotValidChanged( bool ) ) );
  81. kiodrop->readGeneralConfigGroup( *masterGroup );
  82. if( !kiodrop->readConfigGroup( *accountGroup ) || !kiodrop->readConfigGroup( *configmap, nproto ) )
  83. {
  84. ++counter;
  85. delete info;
  86. continue;
  87. }
  88. kiodrop->startMonitor();
  89. _kioList->append( kiodrop );
  90. info->index = counter;
  91. info->reset = accountGroup->readNumEntry( "reset", 0 );
  92. info->msgnr = info->reset;
  93. info->newMessages = false;
  94. _dropInfo->insert( kiodrop, info );
  95. ++counter;
  96. }
  97. TQStringList::Iterator it;
  98. for( it = dcop.begin(); it != dcop.end(); ++it )
  99. {
  100. DCOPDrop *dcopdrop = new DCOPDrop;
  101. Dropinfo *info = new Dropinfo;
  102. connect( dcopdrop, TQT_SIGNAL( changed( int, KMailDrop* ) ), this, TQT_SLOT( slotChanged( int, KMailDrop* ) ) );
  103. connect( dcopdrop, TQT_SIGNAL( showPassivePopup( TQPtrList< KornMailSubject >*, int, bool, const TQString& ) ),
  104. this, TQT_SLOT( slotShowPassivePopup( TQPtrList< KornMailSubject >*, int, bool, const TQString& ) ) );
  105. dcopdrop->readConfigGroup( *masterGroup );
  106. dcopdrop->setDCOPName( *it );
  107. _dcopList->append( dcopdrop );
  108. info->index = 0;
  109. info->reset = 0;
  110. info->msgnr = 0;
  111. info->newMessages = false;
  112. _dropInfo->insert( dcopdrop, info );
  113. }
  114. setCount( totalMessages(), hasNewMessages() );
  115. }
  116. void AccountManager::writeConfig( TDEConfig* config, const int index )
  117. {
  118. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  119. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  120. {
  121. config->setGroup( TQString( "korn-%1-%2" ).arg( index ).arg( it.data()->index ) );
  122. config->writeEntry( "reset", it.data()->reset );
  123. }
  124. }
  125. TQString AccountManager::getTooltip() const
  126. {
  127. TQStringList result;
  128. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  129. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  130. if( it.key()->valid() )
  131. result.append( TQString( "%1: %2" ).arg( it.key()->realName() ).arg( it.data()->msgnr - it.data()->reset ));
  132. else
  133. result.append( TQString( "%1: invalid" ).arg( it.key()->realName() ) );
  134. result.sort();
  135. return result.join( TQChar( '\n' ) );
  136. }
  137. void AccountManager::doRecheck()
  138. {
  139. KMailDrop *item;
  140. for( item = _kioList->first(); item; item = _kioList->next() )
  141. item->forceRecheck();
  142. }
  143. void AccountManager::doReset()
  144. {
  145. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  146. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  147. {
  148. it.data()->reset = it.data()->msgnr;
  149. it.data()->newMessages = false;
  150. }
  151. setCount( 0, false );
  152. }
  153. void AccountManager::doView()
  154. {
  155. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  156. if( !_subjectsDlg )
  157. _subjectsDlg = new KornSubjectsDlg();
  158. _subjectsDlg->clear();
  159. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  160. _subjectsDlg->addMailBox( it.key() );
  161. _subjectsDlg->loadMessages();
  162. }
  163. void AccountManager::doStartTimer()
  164. {
  165. KMailDrop *item;
  166. for( item = _kioList->first(); item; item = _kioList->next() )
  167. item->startMonitor();
  168. }
  169. void AccountManager::doStopTimer()
  170. {
  171. KMailDrop *item;
  172. for( item = _kioList->first(); item; item = _kioList->next() )
  173. item->stopMonitor();
  174. }
  175. int AccountManager::totalMessages()
  176. {
  177. int result = 0;
  178. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  179. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  180. //if( it.date()->msgnr - it.date()->reset > 0 )
  181. result += it.data()->msgnr - it.data()->reset;
  182. return result;
  183. }
  184. bool AccountManager::hasNewMessages()
  185. {
  186. TQMap< KMailDrop*, Dropinfo* >::Iterator it;
  187. for( it = _dropInfo->begin(); it != _dropInfo->end(); ++it )
  188. if( it.data()->newMessages )
  189. return true;
  190. return false;
  191. }
  192. void AccountManager::playSound( const TQString& file )
  193. {
  194. KAudioPlayer::play( file );
  195. }
  196. void AccountManager::slotChanged( int count, KMailDrop* mailDrop )
  197. {
  198. Dropinfo *info = _dropInfo->find( mailDrop ).data();
  199. info->newMessages = count > info->msgnr || ( count == info->msgnr && info->newMessages );
  200. if( count > info->msgnr )
  201. {
  202. if( !mailDrop->soundFile().isEmpty() )
  203. playSound( mailDrop->soundFile() );
  204. if( !mailDrop->newMailCmd().isEmpty() )
  205. runCommand( mailDrop->newMailCmd() );
  206. }
  207. info->msgnr = count;
  208. if( info->msgnr - info->reset < 0 )
  209. info->reset = 0;
  210. setCount( totalMessages(), hasNewMessages() && totalMessages() > 0 );
  211. setTooltip( getTooltip() );
  212. }
  213. void AccountManager::slotValidChanged( bool )
  214. {
  215. setTooltip( getTooltip() );
  216. }
  217. #include "accountmanager.moc"