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.

korncfgimpl.cpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "korncfgimpl.h"
  19. #include "keditlistboxman.h"
  20. #include "kornboxcfgimpl.h"
  21. #include "password.h"
  22. #include <tdeconfig.h>
  23. #include <kdebug.h>
  24. #include <kdialogbase.h>
  25. #include <tdelocale.h>
  26. #include <tqcolor.h>
  27. #include <tqcheckbox.h>
  28. #include <tqradiobutton.h>
  29. #include <tqstring.h>
  30. #include <tqtimer.h>
  31. /*
  32. * parent should be of type KDialogBase
  33. */
  34. KornCfgImpl::KornCfgImpl( TQWidget * parent, const char * name )
  35. : KornCfgWidget( parent, name ),
  36. _config( new TDEConfig( "kornrc" ) ),
  37. _base( 0 )
  38. {
  39. elbBoxes->setSubGroupName( "korn-%1-%2" );
  40. elbBoxes->setGroupName( "korn-%1" );
  41. elbBoxes->setConfig( _config );
  42. elbBoxes->setTitle( i18n( "Boxes" ) );
  43. connect( parent, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( slotOK() ) );
  44. connect( parent, TQT_SIGNAL( cancelClicked() ), this, TQT_SLOT( slotCancel() ) );
  45. connect( parent, TQT_SIGNAL( applyClicked() ), this, TQT_SLOT( slotApply() ) );
  46. connect( elbBoxes, TQT_SIGNAL( elementsSwapped( int, int ) ), this, TQT_SLOT( slotElementsSwapped( int, int ) ) );
  47. connect( elbBoxes, TQT_SIGNAL( elementDeleted( int ) ), this, TQT_SLOT( slotElementDeleted( int ) ) );
  48. readConfig();
  49. }
  50. KornCfgImpl::~KornCfgImpl()
  51. {
  52. _config->sync();
  53. }
  54. void KornCfgImpl::slotEditBox()
  55. {
  56. if( _base )
  57. return; //Already a dialog open
  58. if( elbBoxes->listBox()->currentItem() < 0 )
  59. return; //No item selected
  60. elbBoxes->setEnabled( false );
  61. _base = new KDialogBase( this, "Box Dialog", false, "Box Configuration",
  62. KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true );
  63. KornBoxCfgImpl *widget = new KornBoxCfgImpl( _base, "Box Widget" );
  64. connect( _base, TQT_SIGNAL( finished() ), this, TQT_SLOT( slotDialogDestroyed() ) );
  65. _base->setMainWidget( widget );
  66. widget->readConfig( _config, elbBoxes->listBox()->currentItem() );
  67. _base->show();
  68. }
  69. void KornCfgImpl::slotDialogDestroyed()
  70. {
  71. _base->deleteLater(); _base = 0;
  72. elbBoxes->setEnabled( true );
  73. }
  74. void KornCfgImpl::slotElementsSwapped( int box1, int box2 )
  75. {
  76. int accountnumber1 = 0, accountnumber2 = 0;
  77. while( _config->hasGroup( TQString( "korn-%1-%2" ).arg( box1 ).arg( accountnumber1 ) ) )
  78. ++accountnumber1;
  79. while( _config->hasGroup( TQString( "korn-%1-%2" ).arg( box2 ).arg( accountnumber2 ) ) )
  80. ++accountnumber2;
  81. KOrnPassword::swapKOrnWalletPasswords( box1, accountnumber1, box2, accountnumber2 );
  82. }
  83. void KornCfgImpl::slotElementDeleted( int box )
  84. {
  85. int accountnumber = 0;
  86. while( _config->hasGroup( TQString( "korn-%1-%2" ).arg( box ).arg( accountnumber ) ) )
  87. {
  88. KOrnPassword::deleteKOrnPassword( box, accountnumber );
  89. ++accountnumber;
  90. }
  91. }
  92. void KornCfgImpl::slotActivated( const TQString& )
  93. {
  94. slotEditBox();
  95. }
  96. void KornCfgImpl::slotActivated( const int )
  97. {
  98. slotEditBox();
  99. }
  100. void KornCfgImpl::slotSetDefaults( const TQString& name, const int index, TDEConfig* config )
  101. {
  102. config->writeEntry( "name", name );
  103. config->writeEntry( "hasnormalfgcolour", true );
  104. config->writeEntry( "hasnewfgcolour", true );
  105. config->writeEntry( "hasnormalbgcolour", false );
  106. config->writeEntry( "hasnewbgcolour", false );
  107. config->writeEntry( "hasnormalicon", false );
  108. config->writeEntry( "hasnewicon", false );
  109. config->writeEntry( "hasnormalanim", false );
  110. config->writeEntry( "hasnewanim", false );
  111. config->writeEntry( "normalfgcolour", TQt::black );
  112. config->writeEntry( "newfgcolour", TQt::black );
  113. config->writeEntry( "normalbgcolour", TQString() );
  114. config->writeEntry( "newbgcolour", TQString() );
  115. config->writeEntry( "normalicon", TQString() );
  116. config->writeEntry( "newicon", TQString() );
  117. config->writeEntry( "normalanim", TQString() );
  118. config->writeEntry( "newanim", TQString() );
  119. config->writeEntry( "leftrecheck", true );
  120. config->writeEntry( "middlerecheck", false );
  121. config->writeEntry( "rightrecheck", false );
  122. config->writeEntry( "leftreset", false );
  123. config->writeEntry( "middlereset", false );
  124. config->writeEntry( "rightreset", false );
  125. config->writeEntry( "leftview", false );
  126. config->writeEntry( "middleview", false );
  127. config->writeEntry( "rightview", false );
  128. config->writeEntry( "leftcommand", false );
  129. config->writeEntry( "middlecommand", false );
  130. config->writeEntry( "rightcommand", false );
  131. config->writeEntry( "leftpopup", false );
  132. config->writeEntry( "middlepopupk", false );
  133. config->writeEntry( "rightpopup", true );
  134. config->writeEntry( "command", "" );
  135. config->writeEntry( "newcommand", "" );
  136. config->writeEntry( "sound", "" );
  137. config->writeEntry( "passivepopup", false );
  138. config->writeEntry( "passivedate", false );
  139. config->writeEntry( "numaccounts", 1 );
  140. config->writeEntry( "dcop", TQStringList() );
  141. config->setGroup( TQString( "korn-%1-0" ).arg( index ) );
  142. config->writeEntry( "name", name );
  143. config->writeEntry( "protocol", "mbox" );
  144. config->writeEntry( "server", TQString() );
  145. config->writeEntry( "port", TQString() );
  146. config->writeEntry( "username", TQString() );
  147. config->writeEntry( "mailbox", "/var/spool/mail/" );
  148. config->writeEntry( "savepassword", 0 );
  149. config->writeEntry( "password", TQString() );
  150. config->writeEntry( "auth", TQString() );
  151. config->writeEntry( "interval", 300 );
  152. config->writeEntry( "boxsettings", true );
  153. config->writeEntry( "command", "" );
  154. config->writeEntry( "sound", "" );
  155. config->writeEntry( "passivepopup", false );
  156. config->writeEntry( "passivedate", false );
  157. }
  158. void KornCfgImpl::slotOK()
  159. {
  160. writeConfig();
  161. }
  162. void KornCfgImpl::slotCancel()
  163. {
  164. _config->rollback();
  165. }
  166. void KornCfgImpl::slotApply()
  167. {
  168. writeConfig();
  169. }
  170. void KornCfgImpl::readConfig()
  171. {
  172. _config->setGroup( "korn" );
  173. TQChar layout = _config->readEntry( "layout" ).stripWhiteSpace()[0].upper();
  174. if( layout == TQChar( 'H' ) )
  175. rbHorizontal->setChecked( true );
  176. else if( layout == TQChar( 'V' ) )
  177. rbVertical->setChecked( true );
  178. else
  179. rbDocked->setChecked( true );
  180. chUseWallet->setChecked( _config->readBoolEntry( "usewallet", true ) );
  181. }
  182. void KornCfgImpl::writeConfig()
  183. {
  184. _config->setGroup( "korn" );
  185. if( rbHorizontal->isChecked() )
  186. _config->writeEntry( "layout", "Horizontal" );
  187. if( rbVertical->isChecked() )
  188. _config->writeEntry( "layout", "Vertical" );
  189. if( rbDocked->isChecked() )
  190. _config->writeEntry( "layout", "Docked" );
  191. //Default is 'false' here, because if no option is set, TDEWallet isn't used.
  192. if( _config->readBoolEntry( "usewallet", false ) != chUseWallet->isChecked() )
  193. //Configuration box changed => setting over configuration
  194. rewritePasswords();
  195. _config->writeEntry( "usewallet", chUseWallet->isChecked() );
  196. _config->sync();
  197. }
  198. void KornCfgImpl::rewritePasswords()
  199. {
  200. int box = 0 - 1;
  201. int account = 0 - 1;
  202. TDEConfigGroup *group;
  203. while( _config->hasGroup( TQString( "korn-%1" ).arg( ++box ) ) )
  204. {
  205. account = 0 - 1;
  206. while( _config->hasGroup( TQString( "korn-%1-%2" ).arg( box ).arg( ++account ) ) )
  207. {
  208. group = new TDEConfigGroup( _config, TQString( "korn-%1-%2" ).arg( box ).arg( account ) );
  209. KOrnPassword::rewritePassword( box, account, *group, chUseWallet->isChecked() );
  210. delete group;
  211. }
  212. }
  213. _config->setGroup( "korn" );
  214. }
  215. #include "korncfgimpl.moc"