summaryrefslogtreecommitdiffstats
path: root/kmymoney2/widgets/kmymoneygpgconfig.cpp
blob: e2dc761a0534baa3a4959f67619d1377e3e3ade1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
                          kmymoneyonlinequoteconfig.cpp  -  description
                             -------------------
    begin                : Thu Dec 30 2004
    copyright            : (C) 2004 by Thomas Baumgart
    email                : Thomas Baumgart <[email protected]>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// ----------------------------------------------------------------------------
// QT Includes

#include <tqcheckbox.h>
#include <tqgroupbox.h>

// ----------------------------------------------------------------------------
// KDE Includes

#include <tdeconfig.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <klineedit.h>
#include <kled.h>

// ----------------------------------------------------------------------------
// Project Includes

#include "kmymoneygpgconfig.h"
#include "libkgpgfile/kgpgfile.h"

#define RECOVER_KEY_ID  "0xD2B08440"

kMyMoneyGPGConfig::kMyMoneyGPGConfig(TQWidget *parent, const char *name )
  : kMyMoneyGPGConfigDecl(parent, name),
  m_checkCount(0)
{
  m_idGroup->setEnabled(KGPGFile::GPGAvailable());
  m_recoveryGroup->setEnabled(KGPGFile::keyAvailable(RECOVER_KEY_ID));

  m_userKeyFound->off();
  m_recoverKeyFound->off();

  connect(m_useEncryption, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotStatusChanged(bool)));
  connect(m_userId, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotIdChanged(const TQString&)));
}

void kMyMoneyGPGConfig::resetConfig(void)
{
  m_useEncryption->setChecked(m_resetUseEncryption);
  m_userId->setText(m_resetUserId);
  m_recover->setChecked(m_resetRecover);
  slotStatusChanged(m_resetUseEncryption);
  writeConfig();
}

void kMyMoneyGPGConfig::readConfig(void)
{
  TDEConfig *config = TDEGlobal::config();
  config->setGroup("General Options");
  m_resetUseEncryption = config->readBoolEntry("WriteDataEncrypted", false);
  m_resetRecover = config->readBoolEntry("EncryptRecover", false);
  m_resetUserId = config->readEntry("GPG-Recipient");

  resetConfig();
}

void kMyMoneyGPGConfig::writeConfig(void)
{
  TDEConfig *config = TDEGlobal::config();
  config->setGroup("General Options");
  config->writeEntry("WriteDataEncrypted", m_useEncryption->isChecked());
  config->writeEntry("EncryptRecover", m_recover->isChecked());
  config->writeEntry("GPG-Recipient", m_userId->text());
}

void kMyMoneyGPGConfig::slotIdChanged(const TQString& /*txt*/)
{
  // this looks a bit awkward. Here's why: KGPGFile::keyAvailable() starts
  // an external task and processes UI events while it waits for the external
  // process to finish. Thus, the first time we get here, the external process
  // is started and the user my press a second key which calls this routine
  // again.
  //
  // The second invocation is counted, but the check is not started until the
  // first one finishes. Once the external process finishes, we check if we
  // were called in the meantime and restart the check.
  if(++m_checkCount == 1) {
    while(1) {
      if(m_userId->text().stripWhiteSpace().length() > 0) {
        m_userKeyFound->setState((KLed::State) (KGPGFile::keyAvailable(m_userId->text()) ? KLed::On : KLed::Off));
        if(m_checkCount > 1) {
          m_checkCount = 1;
          continue;
        }
      } else {
        m_userKeyFound->setState(KLed::Off);
      }
      break;
    }
    --m_checkCount;
  }
}

void kMyMoneyGPGConfig::slotStatusChanged(bool state)
{
  if(state) {
    m_idGroup->setEnabled(KGPGFile::GPGAvailable());
    m_recoveryGroup->setEnabled(KGPGFile::GPGAvailable());
    m_recoverKeyFound->setState((KLed::State) (KGPGFile::keyAvailable(RECOVER_KEY_ID) ? KLed::On : KLed::Off));
    if(m_userId->text().isEmpty())
      m_userKeyFound->setState(KLed::Off);
    else
      m_userKeyFound->setState((KLed::State) (KGPGFile::keyAvailable(m_userId->text()) ? KLed::On : KLed::Off));
  } else {
    m_idGroup->setEnabled(false);
    m_recoveryGroup->setEnabled(false);
    m_recoverKeyFound->setState(KLed::Off);
    m_userKeyFound->setState(KLed::Off);
  }
}

#include "kmymoneygpgconfig.moc"