diff --git a/src/gpgolgui/gpgolconfigpage.cpp b/src/gpgolgui/gpgolconfigpage.cpp index a572a24..df1a23a 100644 --- a/src/gpgolgui/gpgolconfigpage.cpp +++ b/src/gpgolgui/gpgolconfigpage.cpp @@ -1,267 +1,276 @@ /* Copyright (C) 2018 by Intevation GmbH * * 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 #include #include #include #include #include #include #include /* 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.")); + /* This should be only temporary until we fix crashes with that for everyone. */ + mSynEncChk = new QCheckBox("Disable non-blocking encrypt / sign."); + generalLay->addWidget(mAlwaysSigChk); generalLay->addWidget(mAlwaysEncChk); generalLay->addWidget(mReplyCryptChk); generalLay->addWidget(mInlinePGPChk); + generalLay->addWidget(mSynEncChk); 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 never exceed level 2.")); /* Dsiabled for now */ mAutoTrustChk->setVisible(false); autoLayout->addWidget(mAutoTrustChk); baseLay->addWidget(mAutomationGrp); // 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); }); } 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 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 &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"]); + mSynEncChk->setChecked(values["syncEnc"]); mAutomationGrp->setChecked(values["automation"]); mAutoSecureChk->setChecked(values["autosecure"]); mAutoTrustChk->setChecked(values["autotrust"]); mAutoResolveChk->setChecked(values["autoresolve"]); - mAutoSecureChk->setEnabled(mAutoResolveChk->isChecked()); + mAutoSecureChk->setEnabled(mAutoResolveChk->isChecked() && mAutomationGrp->isChecked()); mPreferSMIMEChk->setEnabled(mAutoResolveChk->isChecked() && smimeEnabled); } void GpgOLConfigPage::load() { QMap 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"; } } 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; } } 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("syncEnc", mSynEncChk->isChecked()); saveBool("automation", mAutomationGrp->isChecked()); saveBool("autosecure", mAutoSecureChk->isChecked()); saveBool("autotrust", mAutoTrustChk->isChecked()); + saveBool("autoresolve", mAutoResolveChk->isChecked()); W32::writeRegStr(nullptr, GPGOL_REG_PATH, "config-version", CONFIG_VERSION); } #include "gpgolconfigpage.moc" diff --git a/src/gpgolgui/gpgolconfigpage.h b/src/gpgolgui/gpgolconfigpage.h index 5209c78..66656ff 100644 --- a/src/gpgolgui/gpgolconfigpage.h +++ b/src/gpgolgui/gpgolconfigpage.h @@ -1,46 +1,47 @@ #ifndef GPGOLCONFIGPAGE_H #define GPGOLCONFIGPAGE_H /* Copyright (C) 2018 by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ #include #include #include class QGroupBox; class QCheckBox; class QLabel; 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 &values); private: QGroupBox *mSMIMEGrp, *mAutomationGrp; QCheckBox *mPreferSMIMEChk, *mAutoSecureChk, *mAlwaysEncChk, *mAlwaysSigChk, *mInlinePGPChk, *mAutoTrustChk, *mAutoResolveChk, - *mReplyCryptChk; + *mReplyCryptChk, + *mSynEncChk; }; #endif