Page MenuHome GnuPG

No OneTemporary

diff --git a/src/gpgolconfig/CMakeLists.txt b/src/gpgolconfig/CMakeLists.txt
index 95b6084..e7c34ec 100644
--- a/src/gpgolconfig/CMakeLists.txt
+++ b/src/gpgolconfig/CMakeLists.txt
@@ -1,40 +1,41 @@
# Copyright (C) 2018 Intevation GmbH <info@intevation.de>
#
# This file is Free Software under the GNU GPL (v>=2)
# and comes with ABSOLUTELY NO WARRANTY!
# See LICENSE.txt for details.
set(EXECUTABLE_NAME "gpgolconfig")
set(EXECUTABLE_SRC
main.cpp
gpgolconfig-options.h
gpgolconfig.cpp
gpgolconfigpage.cpp
+ gpgoldebugpage.cpp
cryptoconfigpage.cpp
${CMAKE_SOURCE_DIR}/src/img/icon.rc
${CMAKE_SOURCE_DIR}/src/util/strhelp.c
${CMAKE_SOURCE_DIR}/src/util/w32-util.cpp
${CMAKE_SOURCE_DIR}/src/util/w32-gettext.c
)
qt5_add_resources(EXECUTABLE_SRC gpgolconfig.qrc)
add_executable(${EXECUTABLE_NAME}
${_add_executable_params}
${EXECUTABLE_SRC}
)
target_link_libraries(${EXECUTABLE_NAME}
Qt5::Widgets
KF5::WidgetsAddons
KF5::Libkleo
Gpgmepp
QGpgme
)
if (WIN32)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "-municode")
endif(WIN32)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
diff --git a/src/gpgolconfig/gpgolconfig.cpp b/src/gpgolconfig/gpgolconfig.cpp
index 541b762..e22ee8a 100644
--- a/src/gpgolconfig/gpgolconfig.cpp
+++ b/src/gpgolconfig/gpgolconfig.cpp
@@ -1,106 +1,116 @@
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include "gpgolconfig.h"
#include "w32-gettext.h"
#include "w32-util.h"
#include "gpgolconfigpage.h"
+#include "gpgoldebugpage.h"
#include "cryptoconfigpage.h"
#include <QLabel>
#include <QWidget>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QCommandLineParser>
#include <QDebug>
#include <KPageDialog>
#include <KGuiItem>
#include <KStandardGuiItem>
GpgOLConfig::GpgOLConfig(const QCommandLineParser &parser):
KPageDialog(nullptr)
{
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
setWindowTitle(_("Configure GpgOL"));
setWindowIcon(QIcon(":/gpgol-icon.svg"));
const auto hwnd = parser.value(QStringLiteral("hwnd"));
if (!hwnd.isEmpty()) {
bool ok;
WId id = (WId) hwnd.toInt(&ok);
if (!ok) {
qDebug() << "invalid hwnd value";
} else {
W32::setupForeignParent(id, this, true);
setModal(true);
}
}
if (parser.isSet("gpgol-version")) {
mVersion = parser.value("gpgol-version");
} else {
mVersion = QStringLiteral("unknown version");
}
setupGUI();
resize(800, 500);
}
void GpgOLConfig::setupGUI()
{
setFaceType(KPageDialog::List);
QDialogButtonBox *buttonBox = new QDialogButtonBox();
buttonBox->setStandardButtons(QDialogButtonBox::RestoreDefaults |
QDialogButtonBox::Cancel |
QDialogButtonBox::Ok);
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults),
KStandardGuiItem::defaults());
setButtonBox(buttonBox);
auto cryptoConfWidget = new CryptoConfigPage;
auto gpgolConfWidget = new GpgOLConfigPage;
+ auto gpgolDbgWidget = new GpgOLDebugPage;
connect(buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked,
- this, [this, cryptoConfWidget, gpgolConfWidget] () {
+ this, [this, cryptoConfWidget, gpgolConfWidget, gpgolDbgWidget] () {
cryptoConfWidget->save();
gpgolConfWidget->save();
+ gpgolDbgWidget->save();
close();
});
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked,
- this, [this, cryptoConfWidget, gpgolConfWidget] () {
+ this, [this, cryptoConfWidget, gpgolConfWidget, gpgolDbgWidget] () {
if (currentPage()->widget() == cryptoConfWidget) {
cryptoConfWidget->defaults();
- } else {
+ } else if (currentPage()->widget() == gpgolConfWidget){
gpgolConfWidget->defaults();
+ } else if (currentPage()->widget() == gpgolDbgWidget){
+ gpgolDbgWidget->defaults();
}
});
connect(buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked,
this, [this] () {
close();
});
KPageWidgetItem *page = new KPageWidgetItem(gpgolConfWidget, _("GpgOL"));
page->setHeader(QStringLiteral("%1 - %2%3").arg(_("Configure GpgOL")).arg(
_("Version ")).arg(mVersion));
page->setIcon(QIcon(":/gpgol-icon.svg"));
addPage(page);
page = new KPageWidgetItem(cryptoConfWidget, QStringLiteral("%1\n%2").arg(_("GnuPG System")).arg(_("(Technical)")));
page->setHeader(_("Configuration of GnuPG System options"));
page->setIcon(QIcon::fromTheme("document-encrypt"));
addPage(page);
+
+ page = new KPageWidgetItem(gpgolDbgWidget, _("Debug"));
+ page->setHeader(_("Configuration of debug options"));
+ page->setIcon(QIcon::fromTheme("tools-report-bug"));
+ addPage(page);
}
diff --git a/src/gpgolconfig/gpgolconfigpage.cpp b/src/gpgolconfig/gpgolconfigpage.cpp
index 1ebaff6..574784e 100644
--- a/src/gpgolconfig/gpgolconfigpage.cpp
+++ b/src/gpgolconfig/gpgolconfigpage.cpp
@@ -1,405 +1,270 @@
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include "gpgolconfigpage.h"
#include "w32-gettext.h"
#include "w32-util.h"
#include <QDebug>
#include <QGroupBox>
#include <QLabel>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QToolTip>
#include <QPushButton>
-#include <QFileDialog>
-#include <QComboBox>
-#include <QLineEdit>
-#include <QStandardPaths>
-#include <QDir>
-
-/* See gpgol/src/debug.h */
-#define DBG_OOM (1<<1)
-#define DBG_MEMORY (1<<2)
-#define DBG_TRACE (1<<3)
-#define DBG_DATA (1<<4)
/*
class ExplainingChkBox: public QWidget
{
Q_OBJECT
public:
explicit ExplainingChkBox(const QString &text, const QString &explanation):
mChkBox(new QCheckBox(text)),
mExplanation(explanation)
{
auto hBox = new QHBoxLayout(this);
hBox->addWidget(mChkBox);
auto infoBtn = new QPushButton;
infoBtn->setIcon(QIcon::fromTheme("help-contextual"));
hBox->addWidget(infoBtn);
hBox->addStretch(1);
connect(infoBtn, &QPushButton::clicked, this, [this, infoBtn] () {
QToolTip::showText(infoBtn->mapToGlobal(QPoint()), mExplanation, infoBtn);
});
}
void setChecked(bool value)
{
mChkBox->setChecked(value);
}
private:
QCheckBox *mChkBox;
QString mExplanation;
};
*/
GpgOLConfigPage::GpgOLConfigPage(QWidget *parent):
QWidget(parent)
{
setupGUI();
load();
}
/* Helper to build an "About" style layout.
static QLayout *buildAboutLayout(const QString &version)
{
auto hLay = new QHBoxLayout;
auto vLay = new QVBoxLayout;
hLay->addLayout(vLay);
hLay->addStretch(1);
auto iconLbl = new QLabel;
iconLbl->setPixmap(QIcon(":/gpgol-logo.png").pixmap(128, 80));
auto versionLbl = new QLabel(QStringLiteral(" ") + QString::fromUtf8(_("Version ")) + version);
vLay->addWidget(iconLbl);
vLay->addWidget(versionLbl);
return hLay;
}
*/
void GpgOLConfigPage::setupGUI()
{
auto baseLay = new QVBoxLayout(this);
mSMIMEGrp = new QGroupBox(_("Enable the S/MIME support"));
mSMIMEGrp->setCheckable(true);
mSMIMEGrp->setAlignment(Qt::AlignLeft);
auto smimeLay = new QVBoxLayout(mSMIMEGrp);
mPreferSMIMEChk = new QCheckBox(_("&Prefer S/MIME when automatically resolving recipients"));
mPreferSMIMEChk->setToolTip(_("If automatic resolution is enabled, prefer S/MIME over OpenPGP if both are possible."));
smimeLay->addWidget(mPreferSMIMEChk);
baseLay->addWidget(mSMIMEGrp);
// The general group
auto generalGrp = new QGroupBox(_("General"));
auto generalLay = new QVBoxLayout(generalGrp);
generalGrp->setAlignment(Qt::AlignLeft);
mAlwaysSigChk = new QCheckBox(_("&Sign new messages by default"));
mAlwaysSigChk->setToolTip(_("Toggles the sign option for all new mails."));
mAlwaysEncChk = new QCheckBox(_("&Encrypt new messages by default"));
mAlwaysSigChk->setToolTip(_("Toggles the encrypt option for all new mails."));
mReplyCryptChk = new QCheckBox(_("S&elect crypto settings automatically "
"for reply and forward"));
mReplyCryptChk->setToolTip(_("Toggles sign, encrypt options if the original mail was signed or encrypted."));
mInlinePGPChk = new QCheckBox(_("&Send OpenPGP mails without attachments as PGP/Inline"));
mInlinePGPChk->setToolTip(_("Instead of using the PGP/MIME format, "
"which properly handles attachments and encoding, "
"the deprecated PGP/Inline is used.\n"
"This can be useful for compatibility but should generally not "
"be used."));
generalLay->addWidget(mAlwaysSigChk);
generalLay->addWidget(mAlwaysEncChk);
generalLay->addWidget(mReplyCryptChk);
generalLay->addWidget(mInlinePGPChk);
baseLay->addWidget(generalGrp);
// The automation checkboxes
mAutomationGrp = new QGroupBox(_("Automation"));
mAutomationGrp->setToolTip(_("Enable or disable any automated key handling."));
auto autoLayout = new QVBoxLayout(mAutomationGrp);
mAutomationGrp->setCheckable(true);
mAutoResolveChk = new QCheckBox(_("&Resolve recipient keys automatically"));
autoLayout->addWidget(mAutoResolveChk);
auto subLay = new QHBoxLayout;
mAutoSecureChk = new QCheckBox(_("Automatically secure &messages"));
mAutoSecureChk->setToolTip(_("Automatically toggles secure if keys with at least level 1 trust were found for all recipients."));
subLay->addSpacing(20);
subLay->addWidget(mAutoSecureChk);
autoLayout->addLayout(subLay);
mAutoTrustChk = new QCheckBox(QStringLiteral("%1 (%2)").arg(_("Include OpenPGP &trust based on communication history")).arg(_("experimental")));
mAutoTrustChk->setToolTip(_("This changes the trust model to \"tofu+pgp\" which tracks the history of key usage. "
"Automated trust can <b>never</b> exceed level 2."));
/* Dsiabled for now */
mAutoTrustChk->setVisible(false);
autoLayout->addWidget(mAutoTrustChk);
baseLay->addWidget(mAutomationGrp);
- // The debugging group
- mDbgGrp = new QGroupBox(_("Enable Logging"));
- mDbgGrp->setCheckable(true);
-
- mDbgCombo = new QComboBox;
- mDbgCombo->addItem(_("Default"), 1);
- mDbgCombo->addItem(_("+Outlook API calls"), (DBG_OOM));
- mDbgCombo->addItem(_("+Memory analysis"), (DBG_OOM | DBG_MEMORY));
- mDbgCombo->addItem(_("+Call tracing"), (DBG_OOM | DBG_MEMORY | DBG_TRACE));
-
- mDbgVerboseWarningLabel = new QLabel(_("<b>Warning:</b> Decreased performance. Huge logs!"));
-
- mDbgComboLabel = new QLabel(_("Log level:"));
-
- mDbgLogFileLabel = new QLabel(_("Log File (required):"));
-
- mDbgDataChk = new QCheckBox(_("Include Mail contents (decrypted!) and meta information."));
-
- mDbgLogFileName = new QLineEdit;
-
- auto dbgLay = new QVBoxLayout(mDbgGrp);
-
- auto logFileLay = new QHBoxLayout;
-
- mDbgLogFileBtn = new QPushButton;
- mDbgLogFileBtn->setIcon(style()->standardIcon(QStyle::SP_FileDialogStart));
-
- logFileLay->addWidget(mDbgLogFileLabel, 0);
- logFileLay->addWidget(mDbgLogFileName, 1);
- logFileLay->addWidget(mDbgLogFileBtn, 0);
- dbgLay->addLayout(logFileLay);
-
- auto dbgComboLay = new QHBoxLayout;
- dbgLay->addLayout(dbgComboLay);
-
- dbgComboLay->addWidget(mDbgComboLabel);
- dbgComboLay->addWidget(mDbgCombo);
- dbgComboLay->addWidget(mDbgVerboseWarningLabel);
- dbgComboLay->addStretch(1);
-
- dbgLay->addWidget(mDbgDataChk);
-
- baseLay->addWidget(mDbgGrp);
-
- // End debugging group
-
// baseLay->addLayout(buildAboutLayout(mVersion));
baseLay->addStretch(1);
connect(mAutoResolveChk, &QCheckBox::toggled, [this] (bool on) {
mAutoSecureChk->setEnabled(on);
mPreferSMIMEChk->setEnabled(mSMIMEGrp->isChecked() && on);
});
connect(mSMIMEGrp, &QGroupBox::toggled, [this] (bool on) {
- mPreferSMIMEChk->setEnabled(mAutoSecureChk->isChecked() && on);
- });
- connect(mDbgGrp, &QGroupBox::toggled, [this] (bool) {
- enableDisableDbgWidgets();
+ mPreferSMIMEChk->setEnabled(mAutoResolveChk->isChecked() && on);
});
-
- connect(mDbgCombo, &QComboBox::currentTextChanged, [this] (QString) {
- mDbgVerboseWarningLabel->setVisible((mDbgCombo->currentData().toInt() & DBG_TRACE));
- });
-
- connect(mDbgLogFileBtn, &QPushButton::clicked, [this] () {
- const auto fileName = QFileDialog::getSaveFileName(this, _("Select log file"),
- mDbgLogFileName->text(),
- "(*.txt)");
- if (!fileName.isEmpty()) {
- mDbgLogFileName->setText(QDir::toNativeSeparators(fileName));
- }
- });
- enableDisableDbgWidgets();
}
static bool strToBool(const std::string &str, bool defaultVal = false)
{
if (str.empty()) {
return defaultVal;
}
if (str == "1") {
return true;
}
if (str == "0") {
return false;
}
qDebug() << "Unknown bool val" << str.c_str();
return defaultVal;
}
static bool loadBool(const char *name, bool defaultVal)
{
return strToBool(W32::readRegStr(nullptr, GPGOL_REG_PATH, name), defaultVal);
}
/* Bump this if you remove a config value */
#define CONFIG_VERSION "1"
static const QMap<QString, bool> defaultMap {
{ QStringLiteral("enableSmime"), false },
{ QStringLiteral("encryptDefault"), false },
{ QStringLiteral("signDefault"), false },
{ QStringLiteral("inlinePGP"), false },
{ QStringLiteral("replyCrypt"), true },
{ QStringLiteral("preferSmime"), false },
{ QStringLiteral("debugGPGME"), false },
{ QStringLiteral("automation"), true },
{ QStringLiteral("autoresolve"), true },
{ QStringLiteral("autosecure"), true },
{ QStringLiteral("autotrust"), false },
{ QStringLiteral("automation"), true },
{ QStringLiteral("syncEnc"), false },
};
void GpgOLConfigPage::updateGUI(const QMap<QString, bool> &values)
{
bool smimeEnabled = values["enableSmime"];
mSMIMEGrp->setChecked(smimeEnabled);
mPreferSMIMEChk->setChecked(values["preferSmime"]);
mAlwaysEncChk->setChecked(values["encryptDefault"]);
mAlwaysSigChk->setChecked(values["signDefault"]);
mInlinePGPChk->setChecked(values["inlinePGP"]);
mReplyCryptChk->setChecked(values["replyCrypt"]);
mAutomationGrp->setChecked(values["automation"]);
mAutoSecureChk->setChecked(values["autosecure"]);
mAutoTrustChk->setChecked(values["autotrust"]);
mAutoResolveChk->setChecked(values["autoresolve"]);
mAutoSecureChk->setEnabled(mAutoResolveChk->isChecked() && mAutomationGrp->isChecked());
mPreferSMIMEChk->setEnabled(mAutoResolveChk->isChecked() && smimeEnabled);
}
void GpgOLConfigPage::load()
{
QMap<QString, bool> confValues;
for (const auto &key: defaultMap.keys()) {
confValues[key] = loadBool(key.toLocal8Bit().constData(), defaultMap[key]);
}
updateGUI(confValues);
const std::string version = W32::readRegStr(nullptr, GPGOL_REG_PATH, "config-version");
if (version != CONFIG_VERSION) {
qDebug() << "Config update. Cleaning old values";
}
-
- const auto logFile = W32::readRegStr(nullptr, GPGOL_REG_PATH, "logFile");
- mDbgLogFileName->setText(logFile.empty() ?
- QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/gpgol.txt") :
- QString::fromStdString(logFile));
-
- const auto logLevelS = W32::readRegStr(nullptr, GPGOL_REG_PATH, "enableDebug");
-
- bool ok;
- int logLevel = QString::fromStdString(logLevelS).toInt(&ok);
- if (!ok) {
- logLevel = 0;
- }
-
- mDbgGrp->setChecked(logLevel > 0);
-
- int idx = 0;
- if ((logLevel & DBG_OOM)) {
- idx++;
- }
- if ((logLevel & DBG_MEMORY)) {
- idx++;
- }
- if ((logLevel & DBG_TRACE)) {
- idx++;
- }
-
- mDbgCombo->setCurrentIndex(idx);
-
- mDbgDataChk->setChecked((logLevel & DBG_DATA));
}
void GpgOLConfigPage::defaults()
{
updateGUI(defaultMap);
}
static void saveBool(const char *name, bool value)
{
const char *val = value ? "1" : "0";
if (!W32::writeRegStr(nullptr, GPGOL_REG_PATH, name, val)) {
qWarning() << "Failed to write registry value for" << name;
}
}
-static void saveInt(const char *name, int value)
-{
- const std::string val = std::to_string(value);
-
- if (!W32::writeRegStr(nullptr, GPGOL_REG_PATH, name, val.c_str())) {
- qWarning() << "Failed to write registry value for" << name;
- }
-}
-
void GpgOLConfigPage::save() const
{
saveBool("enableSmime", mSMIMEGrp->isChecked());
saveBool("preferSmime", mPreferSMIMEChk->isChecked());
saveBool("encryptDefault", mAlwaysEncChk->isChecked());
saveBool("signDefault", mAlwaysSigChk->isChecked());
saveBool("inlinePGP", mInlinePGPChk->isChecked());
saveBool("replyCrypt", mReplyCryptChk->isChecked());
saveBool("automation", mAutomationGrp->isChecked());
saveBool("autosecure", mAutoSecureChk->isChecked());
saveBool("autotrust", mAutoTrustChk->isChecked());
saveBool("autoresolve", mAutoResolveChk->isChecked());
- int logLevel = mDbgCombo->currentData().toInt();
- logLevel |= mDbgDataChk->isChecked() ? DBG_DATA : 0;
-
- saveInt("enableDebug", logLevel);
- W32::writeRegStr(nullptr, GPGOL_REG_PATH, "logFile", QDir::toNativeSeparators(
- mDbgLogFileName->text()).toLocal8Bit().constData());
-
W32::writeRegStr(nullptr, GPGOL_REG_PATH, "config-version", CONFIG_VERSION);
}
-void GpgOLConfigPage::enableDisableDbgWidgets()
-{
- bool vis = mDbgGrp->isChecked();
-
- mDbgDataChk->setVisible(vis);
- mDbgCombo->setVisible(vis);
- mDbgComboLabel->setVisible(vis);
-
- mDbgLogFileName->setVisible(vis);
- mDbgLogFileLabel->setVisible(vis);
- mDbgLogFileBtn->setVisible(vis);
-
- mDbgVerboseWarningLabel->setVisible(vis && (mDbgCombo->currentData().toInt() & DBG_TRACE));
-}
-
#include "gpgolconfigpage.moc"
diff --git a/src/gpgolconfig/gpgolconfigpage.h b/src/gpgolconfig/gpgolconfigpage.h
index be7b90f..5209c78 100644
--- a/src/gpgolconfig/gpgolconfigpage.h
+++ b/src/gpgolconfig/gpgolconfigpage.h
@@ -1,57 +1,46 @@
#ifndef GPGOLCONFIGPAGE_H
#define GPGOLCONFIGPAGE_H
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include <QWidget>
#include <QMap>
#include <QString>
class QGroupBox;
class QCheckBox;
class QLabel;
-class QLineEdit;
-class QComboBox;
-class QPushButton;
+class ExplainingChkBox;
class GpgOLConfigPage: public QWidget
{
Q_OBJECT
public:
explicit GpgOLConfigPage(QWidget *parent = nullptr);
void save() const;
void load();
void defaults();
protected:
void setupGUI();
void updateGUI(const QMap<QString, bool> &values);
- void enableDisableDbgWidgets();
private:
QGroupBox *mSMIMEGrp,
- *mAutomationGrp,
- *mDbgGrp;
+ *mAutomationGrp;
QCheckBox *mPreferSMIMEChk,
*mAutoSecureChk,
*mAlwaysEncChk,
*mAlwaysSigChk,
*mInlinePGPChk,
*mAutoTrustChk,
*mAutoResolveChk,
- *mReplyCryptChk,
- *mDbgDataChk;
- QLineEdit *mDbgLogFileName;
- QLabel *mDbgLogFileLabel,
- *mDbgComboLabel,
- *mDbgVerboseWarningLabel;
- QComboBox *mDbgCombo;
- QPushButton *mDbgLogFileBtn;
+ *mReplyCryptChk;
};
#endif
diff --git a/src/gpgolconfig/gpgoldebugpage.cpp b/src/gpgolconfig/gpgoldebugpage.cpp
new file mode 100644
index 0000000..2c0ac06
--- /dev/null
+++ b/src/gpgolconfig/gpgoldebugpage.cpp
@@ -0,0 +1,251 @@
+/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details.
+ */
+
+#include "gpgoldebugpage.h"
+#include "w32-gettext.h"
+#include "w32-util.h"
+
+#include <QDebug>
+#include <QGroupBox>
+#include <QLabel>
+#include <QCheckBox>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QToolTip>
+#include <QPushButton>
+#include <QFileDialog>
+#include <QComboBox>
+#include <QLineEdit>
+#include <QStandardPaths>
+#include <QDir>
+
+/* See gpgol/src/debug.h */
+#define DBG_OOM (1<<1)
+#define DBG_MEMORY (1<<2)
+#define DBG_TRACE (1<<3)
+#define DBG_DATA (1<<4)
+
+GpgOLDebugPage::GpgOLDebugPage(QWidget *parent):
+ QWidget(parent)
+{
+ setupGUI();
+
+ load();
+}
+
+void GpgOLDebugPage::setupGUI()
+{
+ auto baseLay = new QVBoxLayout(this);
+
+ // The debugging group
+ mDbgGrp = new QGroupBox(_("Enable Logging"));
+ mDbgGrp->setCheckable(true);
+
+ mDbgCombo = new QComboBox;
+ mDbgCombo->addItem(_("Default"), 1);
+ mDbgCombo->addItem(_("+Outlook API calls"), (DBG_OOM));
+ mDbgCombo->addItem(_("+Memory analysis"), (DBG_OOM | DBG_MEMORY));
+ mDbgCombo->addItem(_("+Call tracing"), (DBG_OOM | DBG_MEMORY | DBG_TRACE));
+
+ mDbgVerboseWarningLabel = new QLabel(_("<b>Warning:</b> Decreased performance. Huge logs!"));
+
+ mDbgComboLabel = new QLabel(_("Log level:"));
+
+ mDbgLogFileLabel = new QLabel(_("Log File (required):"));
+
+ mDbgDataChk = new QCheckBox(_("Include Mail contents (decrypted!) and meta information."));
+
+ mDbgLogFileName = new QLineEdit;
+
+ auto dbgLay = new QVBoxLayout(mDbgGrp);
+
+ auto logFileLay = new QHBoxLayout;
+
+ mDbgLogFileBtn = new QPushButton;
+ mDbgLogFileBtn->setIcon(style()->standardIcon(QStyle::SP_FileDialogStart));
+
+ logFileLay->addWidget(mDbgLogFileLabel, 0);
+ logFileLay->addWidget(mDbgLogFileName, 1);
+ logFileLay->addWidget(mDbgLogFileBtn, 0);
+ dbgLay->addLayout(logFileLay);
+
+ auto dbgComboLay = new QHBoxLayout;
+ dbgLay->addLayout(dbgComboLay);
+
+ dbgComboLay->addWidget(mDbgComboLabel);
+ dbgComboLay->addWidget(mDbgCombo);
+ dbgComboLay->addWidget(mDbgVerboseWarningLabel);
+ dbgComboLay->addStretch(1);
+
+ dbgLay->addWidget(mDbgDataChk);
+
+ baseLay->addWidget(mDbgGrp);
+
+
+ connect(mDbgGrp, &QGroupBox::toggled, [this] (bool) {
+ enableDisableDbgWidgets();
+ });
+
+ connect(mDbgCombo, &QComboBox::currentTextChanged, [this] (QString) {
+ mDbgVerboseWarningLabel->setVisible((mDbgCombo->currentData().toInt() & DBG_TRACE));
+ });
+
+ connect(mDbgLogFileBtn, &QPushButton::clicked, [this] () {
+ const auto fileName = QFileDialog::getSaveFileName(this, _("Select log file"),
+ mDbgLogFileName->text(),
+ "(*.txt)");
+ if (!fileName.isEmpty()) {
+ mDbgLogFileName->setText(QDir::toNativeSeparators(fileName));
+ }
+ });
+ enableDisableDbgWidgets();
+
+ // End debugging group
+ auto othersGrp = new QGroupBox(_("Potential workarounds"));
+ mSyncEncChk = new QCheckBox (_("Block Outlook during encrypt / sign"));
+ mSyncDecChk = new QCheckBox (_("Block Outlook during decrypt / verify"));
+
+ auto othersLay = new QVBoxLayout(othersGrp);
+ othersLay->addWidget(mSyncDecChk);
+ othersLay->addWidget(mSyncEncChk);
+
+ baseLay->addWidget(othersGrp);
+
+ auto bugReportLabel = new QLabel(QStringLiteral("<a href=\"https://www.gpg4win.org/reporting-bugs.html\">%1</a>").arg(_("How to report a problem?")));
+ bugReportLabel->setOpenExternalLinks(true);
+
+ baseLay->addWidget(bugReportLabel);
+
+ baseLay->addStretch(1);
+}
+
+static bool strToBool(const std::string &str, bool defaultVal = false)
+{
+ if (str.empty()) {
+ return defaultVal;
+ }
+
+ if (str == "1") {
+ return true;
+ }
+ if (str == "0") {
+ return false;
+ }
+
+ qDebug() << "Unknown bool val" << str.c_str();
+ return defaultVal;
+}
+
+static bool loadBool(const char *name, bool defaultVal)
+{
+ return strToBool(W32::readRegStr(nullptr, GPGOL_REG_PATH, name), defaultVal);
+}
+
+static const QMap<QString, bool> defaultMap {
+ { QStringLiteral("syncEnc"), false },
+ { QStringLiteral("syncDec"), false },
+};
+
+void GpgOLDebugPage::updateGUI(const QMap<QString, bool> &values)
+{
+ mSyncDecChk->setChecked(values["syncDec"]);
+ mSyncEncChk->setChecked(values["syncEnc"]);
+}
+
+void GpgOLDebugPage::load()
+{
+ QMap<QString, bool> confValues;
+
+ for (const auto &key: defaultMap.keys()) {
+ confValues[key] = loadBool(key.toLocal8Bit().constData(), defaultMap[key]);
+ }
+ updateGUI(confValues);
+
+ const auto logFile = W32::readRegStr(nullptr, GPGOL_REG_PATH, "logFile");
+ mDbgLogFileName->setText(logFile.empty() ?
+ QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/gpgol.txt") :
+ QString::fromStdString(logFile));
+
+ const auto logLevelS = W32::readRegStr(nullptr, GPGOL_REG_PATH, "enableDebug");
+
+ bool ok;
+ int logLevel = QString::fromStdString(logLevelS).toInt(&ok);
+ if (!ok) {
+ logLevel = 0;
+ }
+
+ mDbgGrp->setChecked(logLevel > 0);
+
+ int idx = 0;
+ if ((logLevel & DBG_OOM)) {
+ idx++;
+ }
+ if ((logLevel & DBG_MEMORY)) {
+ idx++;
+ }
+ if ((logLevel & DBG_TRACE)) {
+ idx++;
+ }
+
+ mDbgCombo->setCurrentIndex(idx);
+
+ mDbgDataChk->setChecked((logLevel & DBG_DATA));
+}
+
+void GpgOLDebugPage::defaults()
+{
+ updateGUI(defaultMap);
+ mDbgGrp->setChecked(false);
+}
+
+static void saveBool(const char *name, bool value)
+{
+ const char *val = value ? "1" : "0";
+
+ if (!W32::writeRegStr(nullptr, GPGOL_REG_PATH, name, val)) {
+ qWarning() << "Failed to write registry value for" << name;
+ }
+}
+
+static void saveInt(const char *name, int value)
+{
+ const std::string val = std::to_string(value);
+
+ if (!W32::writeRegStr(nullptr, GPGOL_REG_PATH, name, val.c_str())) {
+ qWarning() << "Failed to write registry value for" << name;
+ }
+}
+
+void GpgOLDebugPage::save() const
+{
+ saveBool("syncEnc", mSyncEncChk->isChecked());
+ saveBool("syncDec", mSyncDecChk->isChecked());
+
+ int logLevel = mDbgCombo->currentData().toInt();
+ logLevel |= mDbgDataChk->isChecked() ? DBG_DATA : 0;
+
+ saveInt("enableDebug", logLevel);
+ W32::writeRegStr(nullptr, GPGOL_REG_PATH, "logFile", QDir::toNativeSeparators(
+ mDbgLogFileName->text()).toLocal8Bit().constData());
+}
+
+void GpgOLDebugPage::enableDisableDbgWidgets()
+{
+ bool vis = mDbgGrp->isChecked();
+
+ mDbgDataChk->setVisible(vis);
+ mDbgCombo->setVisible(vis);
+ mDbgComboLabel->setVisible(vis);
+
+ mDbgLogFileName->setVisible(vis);
+ mDbgLogFileLabel->setVisible(vis);
+ mDbgLogFileBtn->setVisible(vis);
+
+ mDbgVerboseWarningLabel->setVisible(vis && (mDbgCombo->currentData().toInt() & DBG_TRACE));
+}
+
+#include "gpgoldebugpage.moc"
diff --git a/src/gpgolconfig/gpgolconfigpage.h b/src/gpgolconfig/gpgoldebugpage.h
similarity index 63%
copy from src/gpgolconfig/gpgolconfigpage.h
copy to src/gpgolconfig/gpgoldebugpage.h
index be7b90f..5885309 100644
--- a/src/gpgolconfig/gpgolconfigpage.h
+++ b/src/gpgolconfig/gpgoldebugpage.h
@@ -1,57 +1,49 @@
-#ifndef GPGOLCONFIGPAGE_H
-#define GPGOLCONFIGPAGE_H
+#ifndef GPGOLDEBUGPAGE_H
+#define GPGOLDEBUGPAGE_H
/* Copyright (C) 2018 by Intevation GmbH <info@intevation.de>
*
* This file is Free Software under the GNU GPL (v>=2)
* and comes with ABSOLUTELY NO WARRANTY!
* See LICENSE.txt for details.
*/
#include <QWidget>
#include <QMap>
#include <QString>
class QGroupBox;
class QCheckBox;
class QLabel;
class QLineEdit;
class QComboBox;
class QPushButton;
-class GpgOLConfigPage: public QWidget
+class GpgOLDebugPage: public QWidget
{
Q_OBJECT
public:
- explicit GpgOLConfigPage(QWidget *parent = nullptr);
+ explicit GpgOLDebugPage(QWidget *parent = nullptr);
void save() const;
void load();
void defaults();
protected:
void setupGUI();
void updateGUI(const QMap<QString, bool> &values);
void enableDisableDbgWidgets();
private:
- QGroupBox *mSMIMEGrp,
- *mAutomationGrp,
- *mDbgGrp;
- QCheckBox *mPreferSMIMEChk,
- *mAutoSecureChk,
- *mAlwaysEncChk,
- *mAlwaysSigChk,
- *mInlinePGPChk,
- *mAutoTrustChk,
- *mAutoResolveChk,
- *mReplyCryptChk,
+ QGroupBox *mDbgGrp;
+ QCheckBox *mSyncEncChk,
+ *mSyncDecChk,
*mDbgDataChk;
QLineEdit *mDbgLogFileName;
QLabel *mDbgLogFileLabel,
*mDbgComboLabel,
*mDbgVerboseWarningLabel;
QComboBox *mDbgCombo;
QPushButton *mDbgLogFileBtn;
};
#endif

File Metadata

Mime Type
text/x-diff
Expires
Sat, Dec 6, 11:58 PM (20 m, 19 s)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d9/d3/dcada720163accda8408c93a6996

Event Timeline