aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/Wizard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/Wizard.cpp')
-rw-r--r--src/ui/Wizard.cpp482
1 files changed, 275 insertions, 207 deletions
diff --git a/src/ui/Wizard.cpp b/src/ui/Wizard.cpp
index 8b482675..de0107c4 100644
--- a/src/ui/Wizard.cpp
+++ b/src/ui/Wizard.cpp
@@ -1,7 +1,7 @@
/**
- * This file is part of GPGFrontend.
+ * This file is part of GpgFrontend.
*
- * GPGFrontend is free software: you can redistribute it and/or modify
+ * GpgFrontend 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 3 of the License, or
* (at your option) any later version.
@@ -24,234 +24,302 @@
#include "ui/Wizard.h"
-Wizard::Wizard(GpgME::GpgContext *ctx, KeyMgmt *keyMgmt, QWidget *parent)
- : QWizard(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) {
- mCtx = ctx;
- mKeyMgmt = keyMgmt;
+#include "ui/settings/GlobalSettingStation.h"
- setPage(Page_Intro, new IntroPage(this));
- setPage(Page_Choose, new ChoosePage(this));
- setPage(Page_GenKey, new KeyGenPage(mCtx, this));
- setPage(Page_Conclusion, new ConclusionPage(this));
+namespace GpgFrontend::UI {
+
+Wizard::Wizard(QWidget* parent) : QWizard(parent) {
+ setPage(Page_Intro, new IntroPage(this));
+ setPage(Page_Choose, new ChoosePage(this));
+ setPage(Page_GenKey, new KeyGenPage(this));
+ setPage(Page_Conclusion, new ConclusionPage(this));
#ifndef Q_WS_MAC
- setWizardStyle(ModernStyle);
+ setWizardStyle(ModernStyle);
#endif
- setWindowTitle(tr("First Start Wizard"));
-
- // http://www.flickr.com/photos/laureenp/6141822934/
- setPixmap(QWizard::WatermarkPixmap, QPixmap(":/keys2.jpg"));
- setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
- setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
-
- setStartId(settings.value("wizard/nextPage", -1).toInt());
- settings.remove("wizard/nextPage");
-
- connect(this, SIGNAL(accepted()), this, SLOT(slotWizardAccepted()));
-
+ setWindowTitle(_("First Start Wizard"));
+
+ // http://www.flickr.com/photos/laureenp/6141822934/
+ setPixmap(QWizard::WatermarkPixmap, QPixmap(":/keys2.jpg"));
+ setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
+ setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
+
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ int next_page_id = -1;
+ try {
+ next_page_id = settings.lookup("wizard.next_page");
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error");
+ }
+ setStartId(next_page_id);
+
+ connect(this, SIGNAL(accepted()), this, SLOT(slotWizardAccepted()));
}
void Wizard::slotWizardAccepted() {
- // Don't show is mapped to show -> negation
- settings.setValue("wizard/showWizard", !field("showWizard").toBool());
-
- if (field("openHelp").toBool()) {
- emit signalOpenHelp("docu.html#content");
- }
-}
-
-IntroPage::IntroPage(QWidget *parent)
- : QWizardPage(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) {
- setTitle(tr("Getting Started..."));
- setSubTitle(tr("... with GPGFrontend"));
-
- auto *topLabel = new QLabel(tr("Welcome to use GPGFrontend for decrypting and signing text or file!") +
- " <br><br><a href='https://gpgfrontend.pub'>GpgFrontend</a> " +
- tr("is a Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP Crypto Tool.") +
- tr("For brief information have a look at the") +
- " <a href='https://gpgfrontend.pub/index.html#/overview'>" +
- tr("Overview") + "</a> (" +
- tr("by clicking the link, the page will open in the web browser") +
- "). <br>");
- topLabel->setTextFormat(Qt::RichText);
- topLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
- topLabel->setOpenExternalLinks(true);
- topLabel->setWordWrap(true);
-
- // QComboBox for language selection
- auto *langLabel = new QLabel(tr("Choose a Language"));
- langLabel->setWordWrap(true);
-
- languages = SettingsDialog::listLanguages();
- auto *langSelectBox = new QComboBox();
-
- for (const auto &l : languages) {
- langSelectBox->addItem(l);
+ LOG(INFO) << _("Called");
+ // Don't show is mapped to show -> negation
+ try {
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ if (!settings.exists("wizard")) {
+ settings.add("wizard", libconfig::Setting::TypeGroup);
}
- // selected entry from config
- QString langKey = settings.value("int/lang").toString();
- QString langValue = languages.value(langKey);
- if (langKey != "") {
- langSelectBox->setCurrentIndex(langSelectBox->findText(langValue));
+ auto& wizard = settings["wizard"];
+ if (!wizard.exists("show_wizard")) {
+ wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = false;
+ } else {
+ wizard["show_wizard"] = false;
}
-
- connect(langSelectBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotLangChange(QString)));
-
- // set layout and add widgets
- auto *layout = new QVBoxLayout;
- layout->addWidget(topLabel);
- layout->addWidget(langLabel);
- layout->addWidget(langSelectBox);
- setLayout(layout);
-}
-
-void IntroPage::slotLangChange(const QString &lang) {
- settings.setValue("int/lang", languages.key(lang));
- settings.setValue("wizard/nextPage", this->wizard()->currentId());
- qApp->exit(RESTART_CODE);
+ GlobalSettingStation::GetInstance().Sync();
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error");
+ }
+ if (field("openHelp").toBool()) {
+ emit signalOpenHelp("docu.html#content");
+ }
}
-int IntroPage::nextId() const {
- return Wizard::Page_Choose;
+IntroPage::IntroPage(QWidget* parent) : QWizardPage(parent) {
+ setTitle(_("Getting Started..."));
+ setSubTitle(_("... with GpgFrontend"));
+
+ auto* topLabel = new QLabel(
+ QString(_("Welcome to use GpgFrontend for decrypting and signing text or "
+ "file!")) +
+ " <br><br><a href='https://gpgfrontend.pub'>GpgFrontend</a> " +
+ _("is a Powerful, Easy-to-Use, Compact, Cross-Platform, and "
+ "Installation-Free OpenPGP Crypto Tool.") +
+ _("For brief information have a look at the") +
+ " <a href='https://gpgfrontend.pub/index.html#/overview'>" +
+ _("Overview") + "</a> (" +
+ _("by clicking the link, the page will open in the web browser") +
+ "). <br>");
+ topLabel->setTextFormat(Qt::RichText);
+ topLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ topLabel->setOpenExternalLinks(true);
+ topLabel->setWordWrap(true);
+
+ // QComboBox for language selection
+ auto* langLabel =
+ new QLabel(_("If it supports the language currently being used in your "
+ "system, GpgFrontend will automatically set it."));
+ langLabel->setWordWrap(true);
+
+ languages = SettingsDialog::listLanguages();
+ auto* langSelectBox = new QComboBox();
+
+ for (const auto& l : languages) {
+ langSelectBox->addItem(l);
+ }
+ // selected entry from config
+
+ // auto lang = "";
+ // auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // try {
+ // lang = settings.lookup("general.lang");
+ // } catch (...) {
+ // LOG(INFO) << "Read for general.lang failed";
+ // }
+ //
+ // QString langKey = lang;
+ // QString langValue = languages.value(langKey);
+ // LOG(INFO) << "lang key" << langKey.toStdString() << "lang value"
+ // << langValue.toStdString();
+ // langSelectBox->setCurrentIndex(langSelectBox->findText(langValue));
+
+ // connect(langSelectBox, SIGNAL(currentIndexChanged(QString)), this,
+ // SLOT(slotLangChange(QString)));
+
+ // set layout and add widgets
+ auto* layout = new QVBoxLayout;
+ layout->addWidget(topLabel);
+ layout->addStretch();
+ layout->addWidget(langLabel);
+ // layout->addWidget(langSelectBox);
+
+ setLayout(layout);
}
-ChoosePage::ChoosePage(QWidget *parent)
- : QWizardPage(parent) {
- setTitle(tr("Choose your action..."));
- setSubTitle(tr("...by clicking on the appropriate link."));
-
- auto *keygenLabel = new QLabel(tr("If you have never used GPGFrontend before and also don't own a gpg key yet you "
- "may possibly want to read how to") +
- " <a href=\"https://gpgfrontend.pub/index.html#/manual/generate-key\">"
- + tr("Generate Key") + "</a><hr>");
- keygenLabel->setTextFormat(Qt::RichText);
- keygenLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
- keygenLabel->setOpenExternalLinks(true);
- keygenLabel->setWordWrap(true);
-
- auto *encrDecyTextLabel = new QLabel(
- tr("If you want to learn how to encrypt, decrypt, sign and verify text, you can read ")
- + "<a href=\"https://gpgfrontend.pub/index.html#/manual/encrypt-decrypt-text\">"
- + tr("Encrypt & Decrypt Text") + "</a> " + tr("or")
- + " <a href=\"https://gpgfrontend.pub/index.html#/manual/sign-verify-text\">"
- + tr("Sign & Verify Text")
- + "</a><hr>");
-
- encrDecyTextLabel->setTextFormat(Qt::RichText);
- encrDecyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
- encrDecyTextLabel->setOpenExternalLinks(true);
- encrDecyTextLabel->setWordWrap(true);
-
- auto *signVerifyTextLabel = new QLabel(tr("If you want to operate file, you can read ")
- +
- "<a href=\"https://gpgfrontend.pub/index.html#/manual/encrypt-decrypt-file\">"
- + tr("Encrypt & Sign File") + "</a> " + tr("or")
- +
- " <a href=\"https://gpgfrontend.pub/index.html#/manual/sign-verify-file\">"
- + tr("Sign & Verify File")
- + "</a><hr>");
- signVerifyTextLabel->setTextFormat(Qt::RichText);
- signVerifyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
- signVerifyTextLabel->setOpenExternalLinks(true);
- signVerifyTextLabel->setWordWrap(true);
-
- auto *layout = new QVBoxLayout();
- layout->addWidget(keygenLabel);
- layout->addWidget(encrDecyTextLabel);
- layout->addWidget(signVerifyTextLabel);
- setLayout(layout);
- nextPage = Wizard::Page_Conclusion;
+// void IntroPage::slotLangChange(const QString& lang) {
+// auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+//
+// if (!settings.exists("general") ||
+// settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
+// settings.add("general", libconfig::Setting::TypeGroup);
+//
+// auto& general = settings["general"];
+// if (!general.exists("lang"))
+// general.add("lang", libconfig::Setting::TypeString) =
+// languages.key(lang).toStdString();
+// else {
+// general["lang"] = languages.key(lang).toStdString();
+// }
+//
+// if (!settings.exists("wizard") ||
+// settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup)
+// settings.add("wizard", libconfig::Setting::TypeGroup);
+//
+// auto& wizard = settings["wizard"];
+// if (!wizard.exists("next_page"))
+// wizard.add("next_page", libconfig::Setting::TypeInt) =
+// this->wizard()->currentId();
+// else {
+// wizard["next_page"] = this->wizard()->currentId();
+// }
+//
+// GlobalSettingStation::GetInstance().Sync();
+//
+// qApp->exit(RESTART_CODE);
+// }
+
+int IntroPage::nextId() const { return Wizard::Page_Choose; }
+
+ChoosePage::ChoosePage(QWidget* parent) : QWizardPage(parent) {
+ setTitle(_("Choose your action..."));
+ setSubTitle(_("...by clicking on the appropriate link."));
+
+ auto* keygenLabel = new QLabel(
+ QString(_(
+ "If you have never used GpgFrontend before and also don't own a gpg "
+ "key yet you "
+ "may possibly want to read how to")) +
+ " <a href=\"https://gpgfrontend.pub/index.html#/manual/generate-key\">" +
+ _("Generate Key") + "</a><hr>");
+ keygenLabel->setTextFormat(Qt::RichText);
+ keygenLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ keygenLabel->setOpenExternalLinks(true);
+ keygenLabel->setWordWrap(true);
+
+ auto* encrDecyTextLabel = new QLabel(
+ QString(_(
+ "If you want to learn how to encrypt, decrypt, sign and verify text, "
+ "you can read ")) +
+ "<a "
+ "href=\"https://gpgfrontend.pub/index.html#/manual/"
+ "encrypt-decrypt-text\">" +
+ _("Encrypt & Decrypt Text") + "</a> " + _("or") +
+ " <a "
+ "href=\"https://gpgfrontend.pub/index.html#/manual/sign-verify-text\">" +
+ _("Sign & Verify Text") + "</a><hr>");
+
+ encrDecyTextLabel->setTextFormat(Qt::RichText);
+ encrDecyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ encrDecyTextLabel->setOpenExternalLinks(true);
+ encrDecyTextLabel->setWordWrap(true);
+
+ auto* signVerifyTextLabel = new QLabel(
+ QString(_("If you want to operate file, you can read ")) +
+ "<a "
+ "href=\"https://gpgfrontend.pub/index.html#/manual/"
+ "encrypt-decrypt-file\">" +
+ _("Encrypt & Sign File") + "</a> " + _("or") +
+ " <a "
+ "href=\"https://gpgfrontend.pub/index.html#/manual/sign-verify-file\">" +
+ _("Sign & Verify File") + "</a><hr>");
+ signVerifyTextLabel->setTextFormat(Qt::RichText);
+ signVerifyTextLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ signVerifyTextLabel->setOpenExternalLinks(true);
+ signVerifyTextLabel->setWordWrap(true);
+
+ auto* layout = new QVBoxLayout();
+ layout->addWidget(keygenLabel);
+ layout->addWidget(encrDecyTextLabel);
+ layout->addWidget(signVerifyTextLabel);
+ setLayout(layout);
+ nextPage = Wizard::Page_Conclusion;
}
-int ChoosePage::nextId() const {
- return nextPage;
-}
+int ChoosePage::nextId() const { return nextPage; }
-void ChoosePage::slotJumpPage(const QString &page) {
- QMetaObject qmo = Wizard::staticMetaObject;
- int index = qmo.indexOfEnumerator("WizardPages");
- QMetaEnum m = qmo.enumerator(index);
+void ChoosePage::slotJumpPage(const QString& page) {
+ QMetaObject qmo = Wizard::staticMetaObject;
+ int index = qmo.indexOfEnumerator("WizardPages");
+ QMetaEnum m = qmo.enumerator(index);
- nextPage = m.keyToValue(page.toUtf8().data());
- wizard()->next();
+ nextPage = m.keyToValue(page.toUtf8().data());
+ wizard()->next();
}
-KeyGenPage::KeyGenPage(GpgME::GpgContext *ctx, QWidget *parent)
- : QWizardPage(parent) {
- mCtx = ctx;
- setTitle(tr("Create a keypair..."));
- setSubTitle(tr("...for decrypting and signing messages"));
- auto *topLabel = new QLabel(tr("You should create a new keypair."
- "The pair consists of a public and a private key.<br>"
- "Other users can use the public key to encrypt messages for you "
- "and verify messages signed by you."
- "You can use the private key to decrypt and sign messages.<br>"
- "For more information have a look at the offline tutorial (which then is shown in the main window):"));
- topLabel->setWordWrap(true);
- auto *linkLabel = new QLabel("<a href=""docu_keygen.html#content"">" + tr("Offline tutorial") + "</a>");
- //linkLabel->setOpenExternalLinks(true);
-
- // connect(linkLabel, SIGNAL(linkActivated(QString)), parentWidget()->parentWidget(), SLOT(openHelp(QString)));
-
- auto *createKeyButtonBox = new QWidget(this);
- auto *createKeyButtonBoxLayout = new QHBoxLayout(createKeyButtonBox);
- auto *createKeyButton = new QPushButton(tr("Create New Key"));
- createKeyButtonBoxLayout->addWidget(createKeyButton);
- createKeyButtonBoxLayout->addStretch(1);
- auto *layout = new QVBoxLayout();
- layout->addWidget(topLabel);
- layout->addWidget(linkLabel);
- layout->addWidget(createKeyButtonBox);
- connect(createKeyButton, SIGNAL(clicked(bool)), this, SLOT(slotGenerateKeyDialog()));
-
- setLayout(layout);
+KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) {
+ setTitle(_("Create a keypair..."));
+ setSubTitle(_("...for decrypting and signing messages"));
+ auto* topLabel = new QLabel(
+ _("You should create a new keypair."
+ "The pair consists of a public and a private key.<br>"
+ "Other users can use the public key to encrypt messages for you "
+ "and verify messages signed by you."
+ "You can use the private key to decrypt and sign messages.<br>"
+ "For more information have a look at the offline tutorial (which then "
+ "is shown in the main window):"));
+ topLabel->setWordWrap(true);
+ auto* linkLabel = new QLabel(
+ "<a href="
+ "docu_keygen.html#content"
+ ">" +
+ QString(_("Offline tutorial")) + "</a>");
+ // linkLabel->setOpenExternalLinks(true);
+
+ // connect(linkLabel, SIGNAL(linkActivated(QString)),
+ // parentWidget()->parentWidget(), SLOT(openHelp(QString)));
+
+ auto* createKeyButtonBox = new QWidget(this);
+ auto* createKeyButtonBoxLayout = new QHBoxLayout(createKeyButtonBox);
+ auto* createKeyButton = new QPushButton(_("Create New Key"));
+ createKeyButtonBoxLayout->addWidget(createKeyButton);
+ createKeyButtonBoxLayout->addStretch(1);
+ auto* layout = new QVBoxLayout();
+ layout->addWidget(topLabel);
+ layout->addWidget(linkLabel);
+ layout->addWidget(createKeyButtonBox);
+ connect(createKeyButton, SIGNAL(clicked(bool)), this,
+ SLOT(slotGenerateKeyDialog()));
+
+ setLayout(layout);
}
-int KeyGenPage::nextId() const {
- return Wizard::Page_Conclusion;
-}
+int KeyGenPage::nextId() const { return Wizard::Page_Conclusion; }
void KeyGenPage::slotGenerateKeyDialog() {
- qDebug() << "Try Opening KeyGenDialog";
- auto *keyGenDialog = new KeyGenDialog(mCtx, this);
- keyGenDialog->show();
- wizard()->next();
+ LOG(INFO) << "Try Opening KeyGenDialog";
+ (new KeyGenDialog(this))->show();
+ wizard()->next();
}
-ConclusionPage::ConclusionPage(QWidget *parent)
- : QWizardPage(parent) {
- setTitle(tr("Ready."));
- setSubTitle(tr("Have fun with GPGFrontend!"));
-
- auto *bottomLabel = new QLabel(tr("You are ready to use GPGFrontend now.<br><br>") +
- "<a href=\"https://saturneric.github.io/GpgFrontend/index.html#/overview\">"
- + tr("The Online Document") + "</a>"
- +
- tr(" will get you started with GPGFrontend. It will open in the main window.<br>"));
-
- bottomLabel->setTextFormat(Qt::RichText);
- bottomLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
- bottomLabel->setOpenExternalLinks(true);
- bottomLabel->setWordWrap(true);
-
- openHelpCheckBox = new QCheckBox(tr("Open offline help."));
- openHelpCheckBox->setChecked(Qt::Checked);
-
- dontShowWizardCheckBox = new QCheckBox(tr("Dont show the wizard again."));
- dontShowWizardCheckBox->setChecked(Qt::Checked);
-
- registerField("showWizard", dontShowWizardCheckBox);
- // registerField("openHelp", openHelpCheckBox);
-
- auto *layout = new QVBoxLayout;
- layout->addWidget(bottomLabel);
- // layout->addWidget(openHelpCheckBox);
- layout->addWidget(dontShowWizardCheckBox);
- setLayout(layout);
- setVisible(true);
+ConclusionPage::ConclusionPage(QWidget* parent) : QWizardPage(parent) {
+ setTitle(_("Ready."));
+ setSubTitle(_("Have fun with GpgFrontend!"));
+
+ auto* bottomLabel =
+ new QLabel(QString(_("You are ready to use GpgFrontend now.<br><br>")) +
+ "<a "
+ "href=\"https://saturneric.github.io/GpgFrontend/index.html#/"
+ "overview\">" +
+ _("The Online Document") + "</a>" +
+ _(" will get you started with GpgFrontend. It will open in "
+ "the main window.") +
+ "<br>");
+
+ bottomLabel->setTextFormat(Qt::RichText);
+ bottomLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ bottomLabel->setOpenExternalLinks(true);
+ bottomLabel->setWordWrap(true);
+
+ openHelpCheckBox = new QCheckBox(_("Open offline help."));
+ openHelpCheckBox->setChecked(Qt::Checked);
+
+ dontShowWizardCheckBox = new QCheckBox(_("Dont show the wizard again."));
+ dontShowWizardCheckBox->setChecked(Qt::Checked);
+
+ registerField("showWizard", dontShowWizardCheckBox);
+ // registerField("openHelp", openHelpCheckBox);
+
+ auto* layout = new QVBoxLayout;
+ layout->addWidget(bottomLabel);
+ // layout->addWidget(openHelpCheckBox);
+ layout->addWidget(dontShowWizardCheckBox);
+ setLayout(layout);
+ setVisible(true);
}
-int ConclusionPage::nextId() const {
- return -1;
-}
+int ConclusionPage::nextId() const { return -1; }
+
+} // namespace GpgFrontend::UI