aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-08-11 05:21:57 +0000
committerSaturneric <[email protected]>2021-08-11 05:21:57 +0000
commita5cf56e93e4e6a856b2f21730c7bfbfa413410ff (patch)
treecdfd1bb9eaf5ba7bfce4a7e4512f371d9d75107d
parentSplit some source files that are too large. (diff)
downloadGpgFrontend-a5cf56e93e4e6a856b2f21730c7bfbfa413410ff.tar.gz
GpgFrontend-a5cf56e93e4e6a856b2f21730c7bfbfa413410ff.zip
Continue to improve functions.
Split source files that are too long.
Diffstat (limited to '')
-rw-r--r--include/gpg/GpgContext.h4
-rw-r--r--include/gpg/GpgKeySignature.h7
-rw-r--r--include/server/ComUtils.h11
-rwxr-xr-xinclude/ui/SettingsDialog.h4
-rw-r--r--resource/conf/gpgfrontend.ini35
-rw-r--r--src/server/ComUtils.cpp82
-rw-r--r--src/ui/CMakeLists.txt1
-rwxr-xr-xsrc/ui/SettingsDialog.cpp687
-rw-r--r--src/ui/main_window/MainWindowServerSlotFunction.cpp102
-rw-r--r--src/ui/settings/SettingsAdvanced.cpp56
-rw-r--r--src/ui/settings/SettingsAppearance.cpp187
-rw-r--r--src/ui/settings/SettingsGeneral.cpp314
-rw-r--r--src/ui/settings/SettingsKeyServer.cpp100
-rw-r--r--src/ui/settings/SettingsSendMail.cpp175
14 files changed, 1036 insertions, 729 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h
index ac01c532..858566d5 100644
--- a/include/gpg/GpgContext.h
+++ b/include/gpg/GpgContext.h
@@ -190,14 +190,14 @@ namespace GpgME {
bool debug;
bool good = true;
- static gpgme_error_t readToBuffer(gpgme_data_t dataIn, QByteArray *outBuffer);
-
QByteArray mPasswordCache;
QSettings settings;
GpgKeyList mKeyList;
QMap<QString, GpgKey *> mKeyMap;
+ static gpgme_error_t readToBuffer(gpgme_data_t dataIn, QByteArray *outBuffer);
+
void fetch_keys();
static void checkErr(gpgme_error_t gpgmeError);
diff --git a/include/gpg/GpgKeySignature.h b/include/gpg/GpgKeySignature.h
index 05a212a7..0dd2f893 100644
--- a/include/gpg/GpgKeySignature.h
+++ b/include/gpg/GpgKeySignature.h
@@ -54,9 +54,12 @@ struct GpgKeySignature {
explicit GpgKeySignature(gpgme_key_sig_t key_sig);
GpgKeySignature(GpgKeySignature &&) noexcept = default;
+
GpgKeySignature(const GpgKeySignature &) = default;
- GpgKeySignature& operator=(GpgKeySignature &&) noexcept = default;
- GpgKeySignature& operator=(const GpgKeySignature &) = default;
+
+ GpgKeySignature &operator=(GpgKeySignature &&) noexcept = default;
+
+ GpgKeySignature &operator=(const GpgKeySignature &) = default;
};
diff --git a/include/server/ComUtils.h b/include/server/ComUtils.h
index 64f80e87..5f27998e 100644
--- a/include/server/ComUtils.h
+++ b/include/server/ComUtils.h
@@ -32,16 +32,24 @@ class ComUtils : public QWidget {
Q_OBJECT
public:
+ enum ServiceType { GetServiceToken, ShortenCryptText, GetFullCryptText };
+
explicit ComUtils(QWidget *parent) : QWidget(parent), appPath(qApp->applicationDirPath()),
settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
QSettings::IniFormat) {
}
+ QString getUrl(ServiceType type);
+
bool checkServerReply(const QByteArray &reply);
QString getDataValue(const QString &key);
+ bool checkDataValue(const QString &key);
+
+ bool checkServiceTokenFormat(const QString& serviceToken);
+
[[nodiscard]] bool good() const { return is_good; }
private:
@@ -50,6 +58,9 @@ private:
QSettings settings;
rapidjson::Document replyDoc;
rapidjson::Value dataVal;
+
+ QRegularExpression re_uuid{R"(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)"};
+
bool is_good = false;
};
diff --git a/include/ui/SettingsDialog.h b/include/ui/SettingsDialog.h
index 358ab2d1..2f289a4c 100755
--- a/include/ui/SettingsDialog.h
+++ b/include/ui/SettingsDialog.h
@@ -58,10 +58,6 @@ private:
QNetworkAccessManager manager;
- QRegularExpression re_uuid{R"(\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)"};
-
- bool checkUUIDFormat(const QString& uuid);
-
private slots:
void slotOwnKeyIdChanged();
diff --git a/resource/conf/gpgfrontend.ini b/resource/conf/gpgfrontend.ini
index 3fc1c1b8..fc7c0c2b 100644
--- a/resource/conf/gpgfrontend.ini
+++ b/resource/conf/gpgfrontend.ini
@@ -15,3 +15,38 @@ showWizard=true
windowState=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\x1\0\0\x1\xcc\0\0\x2V\xfc\x2\0\0\0\x1\xfb\0\0\0\x16\0\x45\0n\0\x63\0r\0y\0p\0t\0\x44\0o\0\x63\0k\x1\0\0\0I\0\0\x2V\0\0\0]\0\xff\xff\xff\0\0\0\x3\0\0\x2\xe0\0\0\0\xf5\xfc\x1\0\0\0\x1\xfb\0\0\0\"\0I\0n\0\x66\0o\0r\0m\0\x61\0t\0i\0o\0n\0 \0\x42\0o\0\x61\0r\0\x64\x1\0\0\0\0\0\0\x2\xe0\0\0\x1\xe0\0\xff\xff\xff\0\0\x2\xe0\0\0\x1]\0\0\0\x4\0\0\0\x4\0\0\0\x1\0\0\0\x2\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x5\0\0\0\x16\0\x66\0i\0l\0\x65\0T\0o\0o\0l\0\x42\0\x61\0r\0\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x18\0\x63\0r\0y\0p\0t\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x14\0k\0\x65\0y\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\x1z\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x16\0\x65\0\x64\0i\0t\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\x2\f\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0$\0s\0p\0\x65\0\x63\0i\0\x61\0l\0\x45\0\x64\0i\0t\0T\0o\0o\0l\0\x42\0\x61\0r\0\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
pos=@Point(100 100)
size=@Size(1200 700)
+windowSave=false
+
+[advanced]
+steganography=false
+
+[gpgpaths]
+keydbpath=.
+
+[sendMail]
+smtpAddress=
+username=
+password=
+port=25
+connectionType=None
+defaultSender=
+enable=false
+
+[toolbar]
+iconsize=@Size(24 24)
+iconstyle=3
+
+[%General]
+currentGpgfrontendServer=service.gpgfrontend.pub
+gpgfrontendServerList=service.gpgfrontend.pub, localhost
+ownKeyId=
+serviceToken=
+confirmImportKeys=true
+
+[keymgmt]
+pos=@Point(100 100)
+size=@Size(900 600)
+setWindowSize=true
+
+[informationBoard]
+fontSize=10 \ No newline at end of file
diff --git a/src/server/ComUtils.cpp b/src/server/ComUtils.cpp
index 637b5c12..25d471af 100644
--- a/src/server/ComUtils.cpp
+++ b/src/server/ComUtils.cpp
@@ -31,11 +31,14 @@
*/
bool ComUtils::checkServerReply(const QByteArray &reply) {
+ qDebug() << "Reply" << reply;
+
/**
* Server Reply Format(Except Timeout)
* {
* "status": 200,
- * "message": "OK",
+ * "msg": "OK",
+ * "timestamp": 1628652783895
* "data" : {
* ...
* }
@@ -49,21 +52,40 @@ bool ComUtils::checkServerReply(const QByteArray &reply) {
}
// check status(int) and message(string)
- if (replyDoc.HasMember("status") && replyDoc.HasMember("message")
- && replyDoc["status"].IsInt() && replyDoc["message"].IsString()) {
+ if (replyDoc.HasMember("status") && replyDoc.HasMember("msg") && replyDoc.HasMember("timestamp") &&
+ replyDoc.HasMember("data")
+ && replyDoc["status"].IsNumber() && replyDoc["msg"].IsString() && replyDoc["timestamp"].IsNumber() &&
+ replyDoc["data"].IsObject()) {
int status = replyDoc["status"].GetInt();
- QString message = replyDoc["status"].GetString();
+ QDateTime time;
+ time.setMSecsSinceEpoch(replyDoc["timestamp"].GetInt64());
+ auto message = replyDoc["msg"].GetString();
+ dataVal = replyDoc["data"].GetObjectA();
+
+ qDebug() << "Reply Date & Time" << time;
+
+ // check reply timestamp
+ if (time < QDateTime::currentDateTime().addSecs(-10)) {
+ QMessageBox::critical(this, tr("Network Error"), tr("Outdated Reply"));
+ return false;
+ }
// check status code if successful (200-299)
// check data object
- if (status / 10 == 2 && replyDoc.HasMember("data") && replyDoc["data"].IsObject()) {
- dataVal = replyDoc["data"].GetObjectA();
+ if (status / 100 == 2) {
is_good = true;
return true;
- } else QMessageBox::critical(this, tr("Error"), message);
+ } else {
+ dataVal = replyDoc["data"].GetObjectA();
+ if (dataVal.HasMember("exceptionMessage") && dataVal["exceptionMessage"].IsString())
+ QMessageBox::critical(this, message, dataVal["exceptionMessage"].GetString());
+ else QMessageBox::critical(this, message, tr("Unknown Reason"));
+ }
+
+ } else QMessageBox::critical(this, tr("Network Error"), tr("Unknown Reply Format"));
- } else QMessageBox::critical(this, tr("Error"), tr("Unknown Reply Format"));
+ return false;
}
/**
@@ -79,3 +101,47 @@ QString ComUtils::getDataValue(const QString &key) {
} else return {};
} else return {};
}
+
+/**
+ * Get eventually url by service type
+ * @param type service which server provides
+ * @return url
+ */
+QString ComUtils::getUrl(ComUtils::ServiceType type) {
+ auto host = settings.value("general/currentGpgfrontendServer",
+ "service.gpgfrontend.pub").toString();
+
+ auto protocol = QString();
+ // Debug Server
+ if (host == "localhost") protocol = "http://";
+ else protocol = "https://";
+
+ auto url = protocol + host + "/";
+
+ switch (type) {
+ case GetServiceToken:
+ url += "/user";
+ break;
+ case ShortenCryptText:
+ url += "/text/new";
+ break;
+ case GetFullCryptText:
+ url += "/text/get";
+ break;
+ }
+
+ qDebug() << "ComUtils getUrl" << url;
+
+ return url;
+}
+
+bool ComUtils::checkDataValue(const QString &key) {
+ auto key_byte_array_data = key.toUtf8().constData();
+ if (is_good) {
+ return dataVal.HasMember(key_byte_array_data) && dataVal[key_byte_array_data].IsString();
+ } else return false;
+}
+
+bool ComUtils::checkServiceTokenFormat(const QString &uuid) {
+ return re_uuid.match(uuid).hasMatch();
+}
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 618b5d28..b6552227 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -4,6 +4,7 @@ aux_source_directory(./widgets UI_SOURCE)
aux_source_directory(./keygen UI_SOURCE)
aux_source_directory(./main_window UI_SOURCE)
aux_source_directory(./help UI_SOURCE)
+aux_source_directory(./settings UI_SOURCE)
add_library(gpgfrontend-ui STATIC ${UI_SOURCE})
diff --git a/src/ui/SettingsDialog.cpp b/src/ui/SettingsDialog.cpp
index 00b26e7b..d110a64a 100755
--- a/src/ui/SettingsDialog.cpp
+++ b/src/ui/SettingsDialog.cpp
@@ -23,12 +23,8 @@
*/
#include "ui/SettingsDialog.h"
-#include "smtp/SmtpMime"
#include "ui/WaitingDialog.h"
-#include "rapidjson/document.h"
-#include "rapidjson/prettywriter.h"
-
SettingsDialog::SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent)
: QDialog(parent) {
mCtx = ctx;
@@ -128,689 +124,6 @@ QHash<QString, QString> SettingsDialog::listLanguages() {
return languages;
}
-GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
- mCtx = ctx;
-
- /*****************************************
- * GpgFrontend Server
- *****************************************/
- auto *serverBox = new QGroupBox(tr("GpgFrontend Server"));
- auto *serverBoxLayout = new QVBoxLayout();
- serverSelectBox = new QComboBox();
- serverBoxLayout->addWidget(serverSelectBox);
- serverBoxLayout->addWidget(new QLabel(
- tr("Server that provides short key and key exchange services")));
- serverBox->setLayout(serverBoxLayout);
-
- /*****************************************
- * Save-Checked-Keys-Box
- *****************************************/
- auto *saveCheckedKeysBox = new QGroupBox(tr("Save Checked Keys"));
- auto *saveCheckedKeysBoxLayout = new QHBoxLayout();
- saveCheckedKeysCheckBox = new QCheckBox(
- tr("Save checked private keys on exit and restore them on next start."),
- this);
- saveCheckedKeysBoxLayout->addWidget(saveCheckedKeysCheckBox);
- saveCheckedKeysBox->setLayout(saveCheckedKeysBoxLayout);
-
- /*****************************************
- * Key-Impport-Confirmation Box
- *****************************************/
- auto *importConfirmationBox =
- new QGroupBox(tr("Confirm drag'n'drop key import"));
- auto *importConfirmationBoxLayout = new QHBoxLayout();
- importConfirmationCheckBox = new QCheckBox(
- tr("Import files dropped on the keylist without confirmation."), this);
- importConfirmationBoxLayout->addWidget(importConfirmationCheckBox);
- importConfirmationBox->setLayout(importConfirmationBoxLayout);
-
- /*****************************************
- * Language Select Box
- *****************************************/
- auto *langBox = new QGroupBox(tr("Language"));
- auto *langBoxLayout = new QVBoxLayout();
- langSelectBox = new QComboBox;
- lang = SettingsDialog::listLanguages();
-
- for (const auto &l: lang) { langSelectBox->addItem(l); }
-
- langBoxLayout->addWidget(langSelectBox);
- langBoxLayout->addWidget(
- new QLabel(tr("<b>NOTE: </b> GpgFrontend will restart automatically if "
- "you change the language!")));
- langBox->setLayout(langBoxLayout);
- connect(langSelectBox, SIGNAL(currentIndexChanged(int)), this,
- SLOT(slotLanguageChanged()));
-
- /*****************************************
- * Own Key Select Box
- *****************************************/
- auto *ownKeyBox = new QGroupBox(tr("Own key"));
- auto *ownKeyBoxLayout = new QVBoxLayout();
- auto *ownKeyServiceTokenLayout = new QHBoxLayout();
- ownKeySelectBox = new QComboBox;
- getServiceTokenButton = new QPushButton(tr("Get Service Token"));
- serviceTokenLabel = new QLabel(tr("No Service Token Found"));
-
- ownKeyBox->setLayout(ownKeyBoxLayout);
- mKeyList = new KeyList(mCtx);
-
- // Fill the keyid hashmap
- keyIds.insert("", tr("<none>"));
-
- for (const auto &keyid : *mKeyList->getAllPrivateKeys()) {
- auto &key = mCtx->getKeyById(keyid);
- keyIds.insert(key.id, key.uids.first().uid);
- }
- for (const auto &k : keyIds.keys()) {
- ownKeySelectBox->addItem(keyIds.find(k).value());
- keyIdsList.append(k);
- }
- connect(ownKeySelectBox, SIGNAL(currentIndexChanged(int)), this,
- SLOT(slotOwnKeyIdChanged()));
- connect(getServiceTokenButton, SIGNAL(clicked(bool)), this,
- SLOT(slotGetServiceToken()));
-
- ownKeyBoxLayout->addWidget(new QLabel(
- tr("Key pair for synchronization and identity authentication")));
- ownKeyBoxLayout->addWidget(ownKeySelectBox);
- ownKeyBoxLayout->addLayout(ownKeyServiceTokenLayout);
- ownKeyServiceTokenLayout->addWidget(getServiceTokenButton);
- ownKeyServiceTokenLayout->addWidget(serviceTokenLabel);
- ownKeyServiceTokenLayout->stretch(0);
-
- /*****************************************
- * Mainlayout
- *****************************************/
- auto *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(serverBox);
- mainLayout->addWidget(saveCheckedKeysBox);
- mainLayout->addWidget(importConfirmationBox);
- mainLayout->addWidget(langBox);
- mainLayout->addWidget(ownKeyBox);
-
- setSettings();
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
-
-/**********************************
- * Read the settings from config
- * and set the buttons and checkboxes
- * appropriately
- **********************************/
-void GeneralTab::setSettings() {
- // Keysaving
- if (settings.value("keys/saveKeyChecked").toBool()) {
- saveCheckedKeysCheckBox->setCheckState(Qt::Checked);
- }
-
- auto serverList = settings.value("general/gpgfrontendServerList").toStringList();
- if(serverList.empty()) {
- serverList.append("service.gpgfrontend.pub");
- }
- for(const auto &s : serverList)
- serverSelectBox->addItem(s);
- serverSelectBox->setCurrentText(settings.value("general/currentGpgfrontendServer",
- "service.gpgfrontend.pub").toString());
-
- // Language setting
- QString langKey = settings.value("int/lang").toString();
- QString langValue = lang.value(langKey);
- if (langKey != "") {
- langSelectBox->setCurrentIndex(langSelectBox->findText(langValue));
- }
-
- QString own_key_id = settings.value("general/ownKeyId").toString();
- qDebug() << "OwnKeyId" << own_key_id;
- if (own_key_id.isEmpty()) {
- ownKeySelectBox->setCurrentText("<none>");
- } else {
- const auto text = keyIds.find(own_key_id).value();
- qDebug() << "OwnKey" << own_key_id << text;
- ownKeySelectBox->setCurrentText(text);
- }
-
- serviceToken = settings.value("general/serviceToken").toString();
- qDebug() << "Load Service Token" << serviceToken;
- if(!serviceToken.isEmpty()) {
- serviceTokenLabel->setText(serviceToken);
- }
-
- // Get own key information from keydb/gpg.conf (if contained)
- if (settings.value("general/confirmImportKeys", Qt::Checked).toBool()) {
- importConfirmationCheckBox->setCheckState(Qt::Checked);
- }
-}
-
-/***********************************
- * get the values of the buttons and
- * write them to settings-file
- *************************************/
-void GeneralTab::applySettings() {
- settings.setValue("keys/saveKeyChecked",
- saveCheckedKeysCheckBox->isChecked());
-
- settings.setValue("general/currentGpgfrontendServer",
- serverSelectBox->currentText());
-
- auto *serverList = new QStringList();
- for(int i = 0; i < serverSelectBox->count(); i++)
- serverList->append(serverSelectBox->itemText(i));
- settings.setValue("general/gpgfrontendServerList",
- *serverList);
- delete serverList;
-
- settings.setValue("int/lang", lang.key(langSelectBox->currentText()));
-
- settings.setValue("general/ownKeyId",
- keyIdsList[ownKeySelectBox->currentIndex()]);
-
- settings.setValue("general/serviceToken",
- serviceToken);
-
- settings.setValue("general/confirmImportKeys",
- importConfirmationCheckBox->isChecked());
-}
-
-void GeneralTab::slotLanguageChanged() { emit signalRestartNeeded(true); }
-
-void GeneralTab::slotOwnKeyIdChanged() {
- // Set ownKeyId to currently selected
- this->serviceTokenLabel->setText(tr("No Service Token Found"));
- serviceToken.clear();
-}
-
-void GeneralTab::slotGetServiceToken() {
- QUrl reqUrl("http://127.0.0.1:9048/user");
- QNetworkRequest request(reqUrl);
- request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
-
- // Building Post Data
- QByteArray keyDataBuf;
-
- const auto keyId = keyIdsList[ownKeySelectBox->currentIndex()];
-
- qDebug() << "KeyId" << keyIdsList[ownKeySelectBox->currentIndex()];
-
- if(keyId.isEmpty()) {
- QMessageBox::critical(this, tr("Invalid Operation"), tr("Own Key can not be None while getting service token."));
- return;
- }
-
- QStringList selectedKeyIds(keyIdsList[ownKeySelectBox->currentIndex()]);
- mCtx->exportKeys(&selectedKeyIds, &keyDataBuf);
-
- qDebug() << "keyDataBuf" << keyDataBuf;
-
- rapidjson::Value p, v;
-
- rapidjson::Document doc;
- doc.SetObject();
-
- p.SetString(keyDataBuf.constData(), keyDataBuf.count());
-
- auto version = qApp->applicationVersion();
- v.SetString(version.toUtf8().constData(), qApp->applicationVersion().count());
-
- doc.AddMember("publicKey", p, doc.GetAllocator());
- doc.AddMember("version", v, doc.GetAllocator());
-
- rapidjson::StringBuffer sb;
- rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
- doc.Accept(writer);
-
- QByteArray postData(sb.GetString());
-
- QNetworkReply *reply = manager.post(request, postData);
-
- auto dialog = new WaitingDialog("Getting Token From Server", this);
- dialog->show();
-
- while (reply->isRunning()) {
- QApplication::processEvents();
- }
-
- dialog->close();
-
- if(reply->error() == QNetworkReply::NoError) {
- rapidjson::Document docReply;
- docReply.Parse(reply->readAll().constData());
- QString serviceTokenTemp = docReply["serviceToken"].GetString();
- if(checkUUIDFormat(serviceTokenTemp)) {
- serviceToken = serviceTokenTemp;
- qDebug() << "Get Service Token" << serviceToken;
- serviceTokenLabel->setText(serviceToken);
- } else {
- QMessageBox::critical(this, tr("Error"), tr("Invalid Service Token Format"));
- }
- } else {
- QMessageBox::critical(this, tr("Error"), reply->errorString());
- }
-
-}
-
-bool GeneralTab::checkUUIDFormat(const QString& uuid) {
- return re_uuid.match(uuid).hasMatch();
-}
-
-SendMailTab::SendMailTab(QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
-
- enableCheckBox = new QCheckBox(tr("Enable"));
- enableCheckBox->setTristate(false);
-
- smtpAddress = new QLineEdit();
- username = new QLineEdit();
- password = new QLineEdit();
- password->setEchoMode(QLineEdit::Password);
-
- portSpin = new QSpinBox();
- portSpin->setMinimum(1);
- portSpin->setMaximum(65535);
- connectionTypeComboBox = new QComboBox();
- connectionTypeComboBox->addItem("None");
- connectionTypeComboBox->addItem("SSL");
- connectionTypeComboBox->addItem("TLS");
- connectionTypeComboBox->addItem("STARTTLS");
-
- defaultSender = new QLineEdit();;
- checkConnectionButton = new QPushButton(tr("Check Connection"));
-
- auto layout = new QGridLayout();
- layout->addWidget(enableCheckBox, 0, 0);
- layout->addWidget(new QLabel(tr("SMTP Address")), 1, 0);
- layout->addWidget(smtpAddress, 1, 1, 1, 4);
- layout->addWidget(new QLabel(tr("Username")), 2, 0);
- layout->addWidget(username, 2, 1, 1, 4);
- layout->addWidget(new QLabel(tr("Password")), 3, 0);
- layout->addWidget(password, 3, 1, 1, 4);
- layout->addWidget(new QLabel(tr("Port")), 4, 0);
- layout->addWidget(portSpin, 4, 1, 1, 1);
- layout->addWidget(new QLabel(tr("Connection Security")), 5, 0);
- layout->addWidget(connectionTypeComboBox, 5, 1, 1, 1);
-
- layout->addWidget(new QLabel(tr("Default Sender")), 6, 0);
- layout->addWidget(defaultSender, 6, 1, 1, 4);
- layout->addWidget(checkConnectionButton, 7, 0);
-
- connect(enableCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotCheckBoxSetEnableDisable(int)));
- connect(checkConnectionButton, SIGNAL(clicked(bool)), this, SLOT(slotCheckConnection()));
-
-
- this->setLayout(layout);
- setSettings();
-}
-
-/**********************************
- * Read the settings from config
- * and set the buttons and checkboxes
- * appropriately
- **********************************/
-void SendMailTab::setSettings() {
-
- if (settings.value("sendMail/enable", false).toBool())
- enableCheckBox->setCheckState(Qt::Checked);
- else {
- enableCheckBox->setCheckState(Qt::Unchecked);
- smtpAddress->setDisabled(true);
- username->setDisabled(true);
- password->setDisabled(true);
- portSpin->setDisabled(true);
- connectionTypeComboBox->setDisabled(true);
- defaultSender->setDisabled(true);
- checkConnectionButton->setDisabled(true);
- }
-
- smtpAddress->setText(settings.value("sendMail/smtpAddress", QString()).toString());
- username->setText(settings.value("sendMail/username", QString()).toString());
- password->setText(settings.value("sendMail/password", QString()).toString());
- portSpin->setValue(settings.value("sendMail/port", 25).toInt());
- connectionTypeComboBox->setCurrentText(settings.value("sendMail/connectionType", "None").toString());
- defaultSender->setText(settings.value("sendMail/defaultSender", QString()).toString());
-
-}
-
-/***********************************
- * get the values of the buttons and
- * write them to settings-file
- *************************************/
-void SendMailTab::applySettings() {
-
- settings.setValue("sendMail/smtpAddress", smtpAddress->text());
- settings.setValue("sendMail/username", username->text());
- settings.setValue("sendMail/password", password->text());
- settings.setValue("sendMail/port", portSpin->value());
- settings.setValue("sendMail/connectionType", connectionTypeComboBox->currentText());
- settings.setValue("sendMail/defaultSender", defaultSender->text());
-
- settings.setValue("sendMail/enable", enableCheckBox->isChecked());
-}
-
-void SendMailTab::slotCheckConnection() {
-
- SmtpClient::ConnectionType connectionType;
- const auto selectedConnType = connectionTypeComboBox->currentText();
- if (selectedConnType == "SSL") {
- connectionType = SmtpClient::ConnectionType::SslConnection;
- } else if (selectedConnType == "TLS" || selectedConnType == "STARTTLS") {
- connectionType = SmtpClient::ConnectionType::TlsConnection;
- } else {
- connectionType = SmtpClient::ConnectionType::TcpConnection;
- }
-
- SmtpClient smtp(smtpAddress->text(), portSpin->value(), connectionType);
-
- smtp.setUser(username->text());
- smtp.setPassword(password->text());
-
- bool if_success = true;
-
- if (!smtp.connectToHost()) {
- QMessageBox::critical(this, tr("Fail"), tr("Fail to Connect SMTP Server"));
- if_success = false;
- }
- if (if_success && !smtp.login()) {
- QMessageBox::critical(this, tr("Fail"), tr("Fail to Login"));
- if_success = false;
- }
-
- if (if_success)
- QMessageBox::information(this, tr("Success"), tr("Succeed in connecting and login"));
-
-}
-
-void SendMailTab::slotCheckBoxSetEnableDisable(int state) {
- if (state == Qt::Checked) {
- smtpAddress->setEnabled(true);
- username->setEnabled(true);
- password->setEnabled(true);
- portSpin->setEnabled(true);
- connectionTypeComboBox->setEnabled(true);
- defaultSender->setEnabled(true);
- checkConnectionButton->setEnabled(true);
- } else {
- smtpAddress->setDisabled(true);
- username->setDisabled(true);
- password->setDisabled(true);
- portSpin->setDisabled(true);
- connectionTypeComboBox->setDisabled(true);
- defaultSender->setDisabled(true);
- checkConnectionButton->setDisabled(true);
- }
-}
-
-AppearanceTab::AppearanceTab(QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
- /*****************************************
- * Icon-Size-Box
- *****************************************/
- auto *iconSizeBox = new QGroupBox(tr("Iconsize"));
- iconSizeGroup = new QButtonGroup();
- iconSizeSmall = new QRadioButton(tr("small"));
- iconSizeMedium = new QRadioButton(tr("medium"));
- iconSizeLarge = new QRadioButton(tr("large"));
-
- iconSizeGroup->addButton(iconSizeSmall, 1);
- iconSizeGroup->addButton(iconSizeMedium, 2);
- iconSizeGroup->addButton(iconSizeLarge, 3);
-
- auto *iconSizeBoxLayout = new QHBoxLayout();
- iconSizeBoxLayout->addWidget(iconSizeSmall);
- iconSizeBoxLayout->addWidget(iconSizeMedium);
- iconSizeBoxLayout->addWidget(iconSizeLarge);
-
- iconSizeBox->setLayout(iconSizeBoxLayout);
-
- /*****************************************
- * Icon-Style-Box
- *****************************************/
- auto *iconStyleBox = new QGroupBox(tr("Iconstyle"));
- iconStyleGroup = new QButtonGroup();
- iconTextButton = new QRadioButton(tr("just text"));
- iconIconsButton = new QRadioButton(tr("just icons"));
- iconAllButton = new QRadioButton(tr("text and icons"));
-
- iconStyleGroup->addButton(iconTextButton, 1);
- iconStyleGroup->addButton(iconIconsButton, 2);
- iconStyleGroup->addButton(iconAllButton, 3);
-
- auto *iconStyleBoxLayout = new QHBoxLayout();
- iconStyleBoxLayout->addWidget(iconTextButton);
- iconStyleBoxLayout->addWidget(iconIconsButton);
- iconStyleBoxLayout->addWidget(iconAllButton);
-
- iconStyleBox->setLayout(iconStyleBoxLayout);
-
- /*****************************************
- * Window-Size-Box
- *****************************************/
- auto *windowSizeBox = new QGroupBox(tr("Windowstate"));
- auto *windowSizeBoxLayout = new QHBoxLayout();
- windowSizeCheckBox =
- new QCheckBox(tr("Save window size and position on exit."), this);
- windowSizeBoxLayout->addWidget(windowSizeCheckBox);
- windowSizeBox->setLayout(windowSizeBoxLayout);
-
- /*****************************************
- * Info-Board-Font-Size-Box
- *****************************************/
-
- auto *infoBoardBox = new QGroupBox(tr("Information Board"));
- auto *infoBoardLayout = new QHBoxLayout();
- infoBoardFontSizeSpin = new QSpinBox();
- infoBoardFontSizeSpin->setRange(9, 18);
- infoBoardFontSizeSpin->setValue(10);
- infoBoardFontSizeSpin->setSingleStep(1);
- infoBoardLayout->addWidget(new QLabel(tr(" Front Size")));
- infoBoardLayout->addWidget(infoBoardFontSizeSpin);
- infoBoardBox->setLayout(infoBoardLayout);
-
- auto *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(iconSizeBox);
- mainLayout->addWidget(iconStyleBox);
- mainLayout->addWidget(windowSizeBox);
- mainLayout->addWidget(infoBoardBox);
- mainLayout->addStretch(1);
- setSettings();
- setLayout(mainLayout);
-}
-
-/**********************************
- * Read the settings from config
- * and set the buttons and checkboxes
- * appropriately
- **********************************/
-void AppearanceTab::setSettings() {
-
- // Iconsize
- QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
- switch (iconSize.height()) {
- case 12:
- iconSizeSmall->setChecked(true);
- break;
- case 24:
- iconSizeMedium->setChecked(true);
- break;
- case 32:
- iconSizeLarge->setChecked(true);
- break;
- }
- // Iconstyle
- Qt::ToolButtonStyle iconStyle = static_cast<Qt::ToolButtonStyle>(
- settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
- .toUInt());
- switch (iconStyle) {
- case Qt::ToolButtonTextOnly:
- iconTextButton->setChecked(true);
- break;
- case Qt::ToolButtonIconOnly:
- iconIconsButton->setChecked(true);
- break;
- case Qt::ToolButtonTextUnderIcon:
- iconAllButton->setChecked(true);
- break;
- default:
- break;
- }
-
- // Window Save and Position
- if (settings.value("window/windowSave").toBool())
- windowSizeCheckBox->setCheckState(Qt::Checked);
-
- // infoBoardFontSize
- auto infoBoardFontSize = settings.value("informationBoard/fontSize", 10).toInt();
- if (infoBoardFontSize < 9 || infoBoardFontSize > 18)
- infoBoardFontSize = 10;
- infoBoardFontSizeSpin->setValue(infoBoardFontSize);
-}
-
-/***********************************
- * get the values of the buttons and
- * write them to settings-file
- *************************************/
-void AppearanceTab::applySettings() {
- switch (iconSizeGroup->checkedId()) {
- case 1:
- settings.setValue("toolbar/iconsize", QSize(12, 12));
- break;
- case 2:
- settings.setValue("toolbar/iconsize", QSize(24, 24));
- break;
- case 3:
- settings.setValue("toolbar/iconsize", QSize(32, 32));
- break;
- }
-
- switch (iconStyleGroup->checkedId()) {
- case 1:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextOnly);
- break;
- case 2:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonIconOnly);
- break;
- case 3:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon);
- break;
- }
-
- settings.setValue("window/windowSave", windowSizeCheckBox->isChecked());
-
- settings.setValue("informationBoard/fontSize", infoBoardFontSizeSpin->value());
-}
-
-KeyserverTab::KeyserverTab(QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
-
- auto keyServerList = settings.value("keyserver/keyServerList").toStringList();
-
- auto *mainLayout = new QVBoxLayout(this);
-
- auto *label = new QLabel(tr("Default Key Server for import:"));
- comboBox = new QComboBox;
- comboBox->setEditable(false);
- comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
-
- for (const auto &keyServer : keyServerList) {
- comboBox->addItem(keyServer);
- qDebug() << "KeyserverTab Get ListItemText" << keyServer;
- }
-
- comboBox->setCurrentText(
- settings.value("keyserver/defaultKeyServer").toString());
-
- auto *addKeyServerBox = new QWidget(this);
- auto *addKeyServerLayout = new QHBoxLayout(addKeyServerBox);
- auto *http = new QLabel("URL: ");
- newKeyServerEdit = new QLineEdit(this);
- auto *newKeyServerButton = new QPushButton(tr("Add"), this);
- connect(newKeyServerButton, SIGNAL(clicked()), this, SLOT(addKeyServer()));
- addKeyServerLayout->addWidget(http);
- addKeyServerLayout->addWidget(newKeyServerEdit);
- addKeyServerLayout->addWidget(newKeyServerButton);
-
- mainLayout->addWidget(label);
- mainLayout->addWidget(comboBox);
- mainLayout->addWidget(addKeyServerBox);
- mainLayout->addStretch(1);
-
- // Read keylist from ini-file and fill it into combobox
- setSettings();
-}
-
-/**********************************
- * Read the settings from config
- * and set the buttons and checkboxes
- * appropriately
- **********************************/
-void KeyserverTab::setSettings() {
- auto *keyServerList = new QStringList();
- for (int i = 0; i < comboBox->count(); i++) {
- keyServerList->append(comboBox->itemText(i));
- qDebug() << "KeyserverTab ListItemText" << comboBox->itemText(i);
- }
- settings.setValue("keyserver/keyServerList", *keyServerList);
- delete keyServerList;
- settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
-}
-
-void KeyserverTab::addKeyServer() {
- if (newKeyServerEdit->text().startsWith("http://") ||
- newKeyServerEdit->text().startsWith("https://")) {
- comboBox->addItem(newKeyServerEdit->text());
- } else {
- comboBox->addItem("http://" + newKeyServerEdit->text());
- }
- comboBox->setCurrentIndex(comboBox->count() - 1);
-}
-
-/***********************************
- * get the values of the buttons and
- * write them to settings-file
- *************************************/
-void KeyserverTab::applySettings() {
- settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
-}
-
-AdvancedTab::AdvancedTab(QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
- /*****************************************
- * Steganography Box
- *****************************************/
- auto *steganoBox = new QGroupBox(tr("Show Steganography Options [Advanced]"));
- auto *steganoBoxLayout = new QHBoxLayout();
- steganoCheckBox = new QCheckBox(tr("Show Steganographic Options."), this);
- steganoBoxLayout->addWidget(steganoCheckBox);
- steganoBox->setLayout(steganoBoxLayout);
-
- auto *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(steganoBox);
- setSettings();
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
-
-void AdvancedTab::setSettings() {
- if (settings.value("advanced/steganography").toBool()) {
- steganoCheckBox->setCheckState(Qt::Checked);
- }
-}
-
-void AdvancedTab::applySettings() {
- settings.setValue("advanced/steganography", steganoCheckBox->isChecked());
-}
-
GpgPathsTab::GpgPathsTab(QWidget *parent)
: QWidget(parent), appPath(qApp->applicationDirPath()),
settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp
index c9d89fac..fec60063 100644
--- a/src/ui/main_window/MainWindowServerSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp
@@ -35,8 +35,7 @@
* @return
*/
QString MainWindow::getCryptText(const QString &shortenCryptoText) {
- auto host = settings.value("general/currentGpgfrontendServer",
- "service.gpgfrontend.pub").toString();
+
QString ownKeyId = settings.value("general/ownKeyId").toString();
@@ -46,14 +45,16 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) {
return {};
}
+ auto utils = new ComUtils(this);
+
QString serviceToken = settings.value("general/serviceToken").toString();
- if (serviceToken.isEmpty()) {
+ if (serviceToken.isEmpty() || !utils->checkServiceTokenFormat(serviceToken)) {
QMessageBox::critical(this, tr("Error"),
tr("Please obtain a Service Token from the server in the settings."));
return {};
}
- QUrl reqUrl("http://127.0.0.1:9048/text/get");
+ QUrl reqUrl(utils->getUrl(ComUtils::GetFullCryptText));
QNetworkRequest request(reqUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
@@ -89,29 +90,63 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) {
auto dialog = new WaitingDialog("Getting Crypt Text From Server", this);
dialog->show();
- while (reply->isRunning()) {
- QApplication::processEvents();
- }
+ while (reply->isRunning()) QApplication::processEvents();
dialog->close();
QByteArray replyData = reply->readAll().constData();
- auto comUtils = new ComUtils(this);
- if (comUtils->checkServerReply(replyData)) {
- //TODO Logic
- } else QMessageBox::critical(this, tr("Error"), tr("Unknown Error"));
+ if (utils->checkServerReply(replyData)) {
+ /**
+ * {
+ * "cryptoText" : ...
+ * "sha": ...
+ * "serviceToken": ...
+ * "date": ...
+ * }
+ */
+
+ if (!utils->checkDataValue("cryptoText")
+ || !utils->checkDataValue("sha")
+ || !utils->checkDataValue("serviceToken")) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("The communication content with the server does not meet the requirements"));
+ return {};
+ }
+
+ auto cryptoText = utils->getDataValue("cryptoText");
+ auto sha = utils->getDataValue("sha");
+ auto serviceTokenFromServer = utils->getDataValue("serviceToken");
+
+ QCryptographicHash sha_generator(QCryptographicHash::Sha256);
+ sha_generator.addData(cryptoText.toUtf8());
+
+ if (serviceTokenFromServer == serviceToken &&
+ sha_generator.result().toHex() == sha) {
+ return cryptoText;
+ } else QMessageBox::critical(this, tr("Error"), tr("Invalid short ciphertext"));
+
+ return {};
+ }
return {};
}
void MainWindow::shortenCryptText() {
+ // gather information
QString serviceToken = settings.value("general/serviceToken").toString();
QString ownKeyId = settings.value("general/ownKeyId").toString();
-
QByteArray cryptoText = edit->curTextPage()->toPlainText().toUtf8();
- QUrl reqUrl("http://127.0.0.1:9048/text/new");
+ auto utils = new ComUtils(this);
+
+ if (serviceToken.isEmpty() || !utils->checkServiceTokenFormat(serviceToken)) {
+ QMessageBox::critical(this, tr("Invalid Service Token"),
+ tr("Please go to the setting interface to get a ServiceToken."));
+ return;
+ }
+
+ QUrl reqUrl(utils->getUrl(ComUtils::ShortenCryptText));
QNetworkRequest request(reqUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
@@ -166,20 +201,35 @@ void MainWindow::shortenCryptText() {
QNetworkReply *reply = networkAccessManager->post(request, postData);
- while (reply->isRunning()) {
- QApplication::processEvents();
+ while (reply->isRunning()) QApplication::processEvents();
+
+ if (utils->checkServerReply(reply->readAll().constData())) {
+
+ /**
+ * {
+ * "shortenText" : ...
+ * "md5": ...
+ * }
+ */
+
+ if (!utils->checkDataValue("shortenText") || !utils->checkDataValue("md5")) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("The communication content with the server does not meet the requirements"));
+ return;
+ }
+
+ QString shortenText = utils->getDataValue("shortenText");
+
+ QCryptographicHash md5_generator(QCryptographicHash::Md5);
+ md5_generator.addData(shortenText.toUtf8());
+ if (md5_generator.result().toHex() == utils->getDataValue("md5")) {
+ auto *dialog = new ShowCopyDialog(shortenText, this);
+ dialog->show();
+ } else {
+ QMessageBox::critical(this, tr("Error"), tr("There is a problem with the communication with the server"));
+ return;
+ }
}
- if (reply->error() == QNetworkReply::NoError) {
- rapidjson::Document docReply;
- docReply.Parse(reply->readAll().constData());
- QString shortenText = docReply["shortenText"].GetString();
- auto *dialog = new ShowCopyDialog(shortenText, this);
- dialog->show();
- } else {
- QMessageBox::critical(this, tr("Error"), reply->errorString());
- }
-
-
}
diff --git a/src/ui/settings/SettingsAdvanced.cpp b/src/ui/settings/SettingsAdvanced.cpp
new file mode 100644
index 00000000..c49ba9ce
--- /dev/null
+++ b/src/ui/settings/SettingsAdvanced.cpp
@@ -0,0 +1,56 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/SettingsDialog.h"
+
+AdvancedTab::AdvancedTab(QWidget *parent)
+: QWidget(parent), appPath(qApp->applicationDirPath()),
+settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+ /*****************************************
+ * Steganography Box
+ *****************************************/
+ auto *steganoBox = new QGroupBox(tr("Show Steganography Options [Advanced]"));
+ auto *steganoBoxLayout = new QHBoxLayout();
+ steganoCheckBox = new QCheckBox(tr("Show Steganographic Options."), this);
+ steganoBoxLayout->addWidget(steganoCheckBox);
+ steganoBox->setLayout(steganoBoxLayout);
+
+ auto *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(steganoBox);
+ setSettings();
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+
+void AdvancedTab::setSettings() {
+ if (settings.value("advanced/steganography").toBool()) {
+ steganoCheckBox->setCheckState(Qt::Checked);
+ }
+}
+
+void AdvancedTab::applySettings() {
+ settings.setValue("advanced/steganography", steganoCheckBox->isChecked());
+}
+
diff --git a/src/ui/settings/SettingsAppearance.cpp b/src/ui/settings/SettingsAppearance.cpp
new file mode 100644
index 00000000..aeb7ed70
--- /dev/null
+++ b/src/ui/settings/SettingsAppearance.cpp
@@ -0,0 +1,187 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/SettingsDialog.h"
+
+AppearanceTab::AppearanceTab(QWidget *parent)
+: QWidget(parent), appPath(qApp->applicationDirPath()),
+settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+ /*****************************************
+ * Icon-Size-Box
+ *****************************************/
+ auto *iconSizeBox = new QGroupBox(tr("Iconsize"));
+ iconSizeGroup = new QButtonGroup();
+ iconSizeSmall = new QRadioButton(tr("small"));
+ iconSizeMedium = new QRadioButton(tr("medium"));
+ iconSizeLarge = new QRadioButton(tr("large"));
+
+ iconSizeGroup->addButton(iconSizeSmall, 1);
+ iconSizeGroup->addButton(iconSizeMedium, 2);
+ iconSizeGroup->addButton(iconSizeLarge, 3);
+
+ auto *iconSizeBoxLayout = new QHBoxLayout();
+ iconSizeBoxLayout->addWidget(iconSizeSmall);
+ iconSizeBoxLayout->addWidget(iconSizeMedium);
+ iconSizeBoxLayout->addWidget(iconSizeLarge);
+
+ iconSizeBox->setLayout(iconSizeBoxLayout);
+
+ /*****************************************
+ * Icon-Style-Box
+ *****************************************/
+ auto *iconStyleBox = new QGroupBox(tr("Iconstyle"));
+ iconStyleGroup = new QButtonGroup();
+ iconTextButton = new QRadioButton(tr("just text"));
+ iconIconsButton = new QRadioButton(tr("just icons"));
+ iconAllButton = new QRadioButton(tr("text and icons"));
+
+ iconStyleGroup->addButton(iconTextButton, 1);
+ iconStyleGroup->addButton(iconIconsButton, 2);
+ iconStyleGroup->addButton(iconAllButton, 3);
+
+ auto *iconStyleBoxLayout = new QHBoxLayout();
+ iconStyleBoxLayout->addWidget(iconTextButton);
+ iconStyleBoxLayout->addWidget(iconIconsButton);
+ iconStyleBoxLayout->addWidget(iconAllButton);
+
+ iconStyleBox->setLayout(iconStyleBoxLayout);
+
+ /*****************************************
+ * Window-Size-Box
+ *****************************************/
+ auto *windowSizeBox = new QGroupBox(tr("Windowstate"));
+ auto *windowSizeBoxLayout = new QHBoxLayout();
+ windowSizeCheckBox =
+ new QCheckBox(tr("Save window size and position on exit."), this);
+ windowSizeBoxLayout->addWidget(windowSizeCheckBox);
+ windowSizeBox->setLayout(windowSizeBoxLayout);
+
+ /*****************************************
+ * Info-Board-Font-Size-Box
+ *****************************************/
+
+ auto *infoBoardBox = new QGroupBox(tr("Information Board"));
+ auto *infoBoardLayout = new QHBoxLayout();
+ infoBoardFontSizeSpin = new QSpinBox();
+ infoBoardFontSizeSpin->setRange(9, 18);
+ infoBoardFontSizeSpin->setValue(10);
+ infoBoardFontSizeSpin->setSingleStep(1);
+ infoBoardLayout->addWidget(new QLabel(tr(" Front Size")));
+ infoBoardLayout->addWidget(infoBoardFontSizeSpin);
+ infoBoardBox->setLayout(infoBoardLayout);
+
+ auto *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(iconSizeBox);
+ mainLayout->addWidget(iconStyleBox);
+ mainLayout->addWidget(windowSizeBox);
+ mainLayout->addWidget(infoBoardBox);
+ mainLayout->addStretch(1);
+ setSettings();
+ setLayout(mainLayout);
+}
+
+/**********************************
+ * Read the settings from config
+ * and set the buttons and checkboxes
+ * appropriately
+ **********************************/
+void AppearanceTab::setSettings() {
+
+ // Iconsize
+ QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
+ switch (iconSize.height()) {
+ case 12:
+ iconSizeSmall->setChecked(true);
+ break;
+ case 24:
+ iconSizeMedium->setChecked(true);
+ break;
+ case 32:
+ iconSizeLarge->setChecked(true);
+ break;
+ }
+ // Iconstyle
+ Qt::ToolButtonStyle iconStyle = static_cast<Qt::ToolButtonStyle>(
+ settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
+ .toUInt());
+ switch (iconStyle) {
+ case Qt::ToolButtonTextOnly:
+ iconTextButton->setChecked(true);
+ break;
+ case Qt::ToolButtonIconOnly:
+ iconIconsButton->setChecked(true);
+ break;
+ case Qt::ToolButtonTextUnderIcon:
+ iconAllButton->setChecked(true);
+ break;
+ default:
+ break;
+ }
+
+ // Window Save and Position
+ if (settings.value("window/windowSave").toBool())
+ windowSizeCheckBox->setCheckState(Qt::Checked);
+
+ // infoBoardFontSize
+ auto infoBoardFontSize = settings.value("informationBoard/fontSize", 10).toInt();
+ if (infoBoardFontSize < 9 || infoBoardFontSize > 18)
+ infoBoardFontSize = 10;
+ infoBoardFontSizeSpin->setValue(infoBoardFontSize);
+}
+
+/***********************************
+ * get the values of the buttons and
+ * write them to settings-file
+ *************************************/
+void AppearanceTab::applySettings() {
+ switch (iconSizeGroup->checkedId()) {
+ case 1:
+ settings.setValue("toolbar/iconsize", QSize(12, 12));
+ break;
+ case 2:
+ settings.setValue("toolbar/iconsize", QSize(24, 24));
+ break;
+ case 3:
+ settings.setValue("toolbar/iconsize", QSize(32, 32));
+ break;
+ }
+
+ switch (iconStyleGroup->checkedId()) {
+ case 1:
+ settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextOnly);
+ break;
+ case 2:
+ settings.setValue("toolbar/iconstyle", Qt::ToolButtonIconOnly);
+ break;
+ case 3:
+ settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon);
+ break;
+ }
+
+ settings.setValue("window/windowSave", windowSizeCheckBox->isChecked());
+
+ settings.setValue("informationBoard/fontSize", infoBoardFontSizeSpin->value());
+}
+
diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp
new file mode 100644
index 00000000..ede15182
--- /dev/null
+++ b/src/ui/settings/SettingsGeneral.cpp
@@ -0,0 +1,314 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/SettingsDialog.h"
+#include "ui/WaitingDialog.h"
+
+#include "server/ComUtils.h"
+
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+
+GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent)
+ : QWidget(parent), appPath(qApp->applicationDirPath()),
+ settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+ mCtx = ctx;
+
+ /*****************************************
+ * GpgFrontend Server
+ *****************************************/
+ auto *serverBox = new QGroupBox(tr("GpgFrontend Server"));
+ auto *serverBoxLayout = new QVBoxLayout();
+ serverSelectBox = new QComboBox();
+ serverBoxLayout->addWidget(serverSelectBox);
+ serverBoxLayout->addWidget(new QLabel(
+ tr("Server that provides short key and key exchange services")));
+ serverBox->setLayout(serverBoxLayout);
+
+ /*****************************************
+ * Save-Checked-Keys-Box
+ *****************************************/
+ auto *saveCheckedKeysBox = new QGroupBox(tr("Save Checked Keys"));
+ auto *saveCheckedKeysBoxLayout = new QHBoxLayout();
+ saveCheckedKeysCheckBox = new QCheckBox(
+ tr("Save checked private keys on exit and restore them on next start."),
+ this);
+ saveCheckedKeysBoxLayout->addWidget(saveCheckedKeysCheckBox);
+ saveCheckedKeysBox->setLayout(saveCheckedKeysBoxLayout);
+
+ /*****************************************
+ * Key-Impport-Confirmation Box
+ *****************************************/
+ auto *importConfirmationBox =
+ new QGroupBox(tr("Confirm drag'n'drop key import"));
+ auto *importConfirmationBoxLayout = new QHBoxLayout();
+ importConfirmationCheckBox = new QCheckBox(
+ tr("Import files dropped on the keylist without confirmation."), this);
+ importConfirmationBoxLayout->addWidget(importConfirmationCheckBox);
+ importConfirmationBox->setLayout(importConfirmationBoxLayout);
+
+ /*****************************************
+ * Language Select Box
+ *****************************************/
+ auto *langBox = new QGroupBox(tr("Language"));
+ auto *langBoxLayout = new QVBoxLayout();
+ langSelectBox = new QComboBox;
+ lang = SettingsDialog::listLanguages();
+
+ for (const auto &l: lang) { langSelectBox->addItem(l); }
+
+ langBoxLayout->addWidget(langSelectBox);
+ langBoxLayout->addWidget(
+ new QLabel(tr("<b>NOTE: </b> GpgFrontend will restart automatically if "
+ "you change the language!")));
+ langBox->setLayout(langBoxLayout);
+ connect(langSelectBox, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(slotLanguageChanged()));
+
+ /*****************************************
+ * Own Key Select Box
+ *****************************************/
+ auto *ownKeyBox = new QGroupBox(tr("Own key"));
+ auto *ownKeyBoxLayout = new QVBoxLayout();
+ auto *ownKeyServiceTokenLayout = new QHBoxLayout();
+ ownKeySelectBox = new QComboBox;
+ getServiceTokenButton = new QPushButton(tr("Get Service Token"));
+ serviceTokenLabel = new QLabel(tr("No Service Token Found"));
+
+ ownKeyBox->setLayout(ownKeyBoxLayout);
+ mKeyList = new KeyList(mCtx);
+
+ // Fill the keyid hashmap
+ keyIds.insert("", tr("<none>"));
+
+ for (const auto &keyid : *mKeyList->getAllPrivateKeys()) {
+ auto &key = mCtx->getKeyById(keyid);
+ keyIds.insert(key.id, key.uids.first().uid);
+ }
+ for (const auto &k : keyIds.keys()) {
+ ownKeySelectBox->addItem(keyIds.find(k).value());
+ keyIdsList.append(k);
+ }
+ connect(ownKeySelectBox, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(slotOwnKeyIdChanged()));
+ connect(getServiceTokenButton, SIGNAL(clicked(bool)), this,
+ SLOT(slotGetServiceToken()));
+
+ ownKeyBoxLayout->addWidget(new QLabel(
+ tr("Key pair for synchronization and identity authentication")));
+ ownKeyBoxLayout->addWidget(ownKeySelectBox);
+ ownKeyBoxLayout->addLayout(ownKeyServiceTokenLayout);
+ ownKeyServiceTokenLayout->addWidget(getServiceTokenButton);
+ ownKeyServiceTokenLayout->addWidget(serviceTokenLabel);
+ ownKeyServiceTokenLayout->stretch(0);
+
+ /*****************************************
+ * Mainlayout
+ *****************************************/
+ auto *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(serverBox);
+ mainLayout->addWidget(saveCheckedKeysBox);
+ mainLayout->addWidget(importConfirmationBox);
+ mainLayout->addWidget(langBox);
+ mainLayout->addWidget(ownKeyBox);
+
+ setSettings();
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+
+/**********************************
+ * Read the settings from config
+ * and set the buttons and checkboxes
+ * appropriately
+ **********************************/
+void GeneralTab::setSettings() {
+ // Keysaving
+ if (settings.value("keys/saveKeyChecked").toBool()) {
+ saveCheckedKeysCheckBox->setCheckState(Qt::Checked);
+ }
+
+ auto serverList = settings.value("general/gpgfrontendServerList").toStringList();
+ if (serverList.empty()) {
+ serverList.append("service.gpgfrontend.pub");
+ serverList.append("localhost");
+ }
+ for (const auto &s : serverList)
+ serverSelectBox->addItem(s);
+ serverSelectBox->setCurrentText(settings.value("general/currentGpgfrontendServer",
+ "service.gpgfrontend.pub").toString());
+
+ // Language setting
+ QString langKey = settings.value("int/lang").toString();
+ QString langValue = lang.value(langKey);
+ if (langKey != "") {
+ langSelectBox->setCurrentIndex(langSelectBox->findText(langValue));
+ }
+
+ QString own_key_id = settings.value("general/ownKeyId").toString();
+ qDebug() << "OwnKeyId" << own_key_id;
+ if (own_key_id.isEmpty()) {
+ ownKeySelectBox->setCurrentText("<none>");
+ } else {
+ const auto text = keyIds.find(own_key_id).value();
+ qDebug() << "OwnKey" << own_key_id << text;
+ ownKeySelectBox->setCurrentText(text);
+ }
+
+ serviceToken = settings.value("general/serviceToken").toString();
+ qDebug() << "Load Service Token" << serviceToken;
+ if (!serviceToken.isEmpty()) {
+ serviceTokenLabel->setText(serviceToken);
+ }
+
+ // Get own key information from keydb/gpg.conf (if contained)
+ if (settings.value("general/confirmImportKeys", Qt::Checked).toBool()) {
+ importConfirmationCheckBox->setCheckState(Qt::Checked);
+ }
+}
+
+/***********************************
+ * get the values of the buttons and
+ * write them to settings-file
+ *************************************/
+void GeneralTab::applySettings() {
+ settings.setValue("keys/saveKeyChecked",
+ saveCheckedKeysCheckBox->isChecked());
+
+ settings.setValue("general/currentGpgfrontendServer",
+ serverSelectBox->currentText());
+
+ auto *serverList = new QStringList();
+ for (int i = 0; i < serverSelectBox->count(); i++)
+ serverList->append(serverSelectBox->itemText(i));
+ settings.setValue("general/gpgfrontendServerList",
+ *serverList);
+ delete serverList;
+
+ settings.setValue("int/lang", lang.key(langSelectBox->currentText()));
+
+ settings.setValue("general/ownKeyId",
+ keyIdsList[ownKeySelectBox->currentIndex()]);
+
+ settings.setValue("general/serviceToken",
+ serviceToken);
+
+ settings.setValue("general/confirmImportKeys",
+ importConfirmationCheckBox->isChecked());
+}
+
+void GeneralTab::slotLanguageChanged() { emit signalRestartNeeded(true); }
+
+void GeneralTab::slotOwnKeyIdChanged() {
+ // Set ownKeyId to currently selected
+ this->serviceTokenLabel->setText(tr("No Service Token Found"));
+ serviceToken.clear();
+}
+
+void GeneralTab::slotGetServiceToken() {
+
+ auto utils = new ComUtils(this);
+
+ QUrl reqUrl(utils->getUrl(ComUtils::GetServiceToken));
+ QNetworkRequest request(reqUrl);
+ request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+
+ // Building Post Data
+ QByteArray keyDataBuf;
+
+ const auto keyId = keyIdsList[ownKeySelectBox->currentIndex()];
+
+ qDebug() << "KeyId" << keyIdsList[ownKeySelectBox->currentIndex()];
+
+ if (keyId.isEmpty()) {
+ QMessageBox::critical(this, tr("Invalid Operation"),
+ tr("Own Key can not be None while getting service token."));
+ return;
+ }
+
+ QStringList selectedKeyIds(keyIdsList[ownKeySelectBox->currentIndex()]);
+ mCtx->exportKeys(&selectedKeyIds, &keyDataBuf);
+
+ qDebug() << "keyDataBuf" << keyDataBuf;
+
+ rapidjson::Value p, v;
+
+ rapidjson::Document doc;
+ doc.SetObject();
+
+ p.SetString(keyDataBuf.constData(), keyDataBuf.count());
+
+ auto version = qApp->applicationVersion();
+ v.SetString(version.toUtf8().constData(), qApp->applicationVersion().count());
+
+ doc.AddMember("publicKey", p, doc.GetAllocator());
+ doc.AddMember("version", v, doc.GetAllocator());
+
+ rapidjson::StringBuffer sb;
+ rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
+ doc.Accept(writer);
+
+ QByteArray postData(sb.GetString());
+
+ QNetworkReply *reply = manager.post(request, postData);
+
+ auto dialog = new WaitingDialog("Getting Token From Server", this);
+ dialog->show();
+
+ while (reply->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ dialog->close();
+
+ if (utils->checkServerReply(reply->readAll().constData())) {
+
+ /**
+ * {
+ * "serviceToken" : ...
+ * "fpr": ...
+ * }
+ */
+
+ if(!utils->checkDataValue("serviceToken") || !utils->checkDataValue("fpr")) {
+ QMessageBox::critical(this, tr("Error"), tr("The communication content with the server does not meet the requirements"));
+ return;
+ }
+
+ QString serviceTokenTemp = utils->getDataValue("serviceToken");
+ QString fpr = utils->getDataValue("fpr");
+ auto key = mCtx->getKeyByFpr(fpr);
+ if (utils->checkServiceTokenFormat(serviceTokenTemp) && key.good) {
+ serviceToken = serviceTokenTemp;
+ qDebug() << "Get Service Token" << serviceToken;
+ // Auto update settings
+ settings.setValue("general/serviceToken", serviceToken);
+ serviceTokenLabel->setText(serviceToken);
+ } else {
+ QMessageBox::critical(this, tr("Error"), tr("There is a problem with the communication with the server"));
+ }
+ }
+
+}
diff --git a/src/ui/settings/SettingsKeyServer.cpp b/src/ui/settings/SettingsKeyServer.cpp
new file mode 100644
index 00000000..ade33a46
--- /dev/null
+++ b/src/ui/settings/SettingsKeyServer.cpp
@@ -0,0 +1,100 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/SettingsDialog.h"
+
+KeyserverTab::KeyserverTab(QWidget *parent)
+: QWidget(parent), appPath(qApp->applicationDirPath()),
+settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+
+ auto keyServerList = settings.value("keyserver/keyServerList").toStringList();
+
+ auto *mainLayout = new QVBoxLayout(this);
+
+ auto *label = new QLabel(tr("Default Key Server for import:"));
+ comboBox = new QComboBox;
+ comboBox->setEditable(false);
+ comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ for (const auto &keyServer : keyServerList) {
+ comboBox->addItem(keyServer);
+ qDebug() << "KeyserverTab Get ListItemText" << keyServer;
+ }
+
+ comboBox->setCurrentText(
+ settings.value("keyserver/defaultKeyServer").toString());
+
+ auto *addKeyServerBox = new QWidget(this);
+ auto *addKeyServerLayout = new QHBoxLayout(addKeyServerBox);
+ auto *http = new QLabel("URL: ");
+ newKeyServerEdit = new QLineEdit(this);
+ auto *newKeyServerButton = new QPushButton(tr("Add"), this);
+ connect(newKeyServerButton, SIGNAL(clicked()), this, SLOT(addKeyServer()));
+ addKeyServerLayout->addWidget(http);
+ addKeyServerLayout->addWidget(newKeyServerEdit);
+ addKeyServerLayout->addWidget(newKeyServerButton);
+
+ mainLayout->addWidget(label);
+ mainLayout->addWidget(comboBox);
+ mainLayout->addWidget(addKeyServerBox);
+ mainLayout->addStretch(1);
+
+ // Read keylist from ini-file and fill it into combobox
+ setSettings();
+}
+
+/**********************************
+ * Read the settings from config
+ * and set the buttons and checkboxes
+ * appropriately
+ **********************************/
+void KeyserverTab::setSettings() {
+ auto *keyServerList = new QStringList();
+ for (int i = 0; i < comboBox->count(); i++) {
+ keyServerList->append(comboBox->itemText(i));
+ qDebug() << "KeyserverTab ListItemText" << comboBox->itemText(i);
+ }
+ settings.setValue("keyserver/keyServerList", *keyServerList);
+ delete keyServerList;
+ settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
+}
+
+void KeyserverTab::addKeyServer() {
+ if (newKeyServerEdit->text().startsWith("http://") ||
+ newKeyServerEdit->text().startsWith("https://")) {
+ comboBox->addItem(newKeyServerEdit->text());
+ } else {
+ comboBox->addItem("http://" + newKeyServerEdit->text());
+ }
+ comboBox->setCurrentIndex(comboBox->count() - 1);
+}
+
+/***********************************
+ * get the values of the buttons and
+ * write them to settings-file
+ *************************************/
+void KeyserverTab::applySettings() {
+ settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
+}
diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp
new file mode 100644
index 00000000..4c80dc89
--- /dev/null
+++ b/src/ui/settings/SettingsSendMail.cpp
@@ -0,0 +1,175 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/SettingsDialog.h"
+#include "smtp/SmtpMime"
+
+SendMailTab::SendMailTab(QWidget *parent)
+ : QWidget(parent), appPath(qApp->applicationDirPath()),
+ settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+
+ enableCheckBox = new QCheckBox(tr("Enable"));
+ enableCheckBox->setTristate(false);
+
+ smtpAddress = new QLineEdit();
+ username = new QLineEdit();
+ password = new QLineEdit();
+ password->setEchoMode(QLineEdit::Password);
+
+ portSpin = new QSpinBox();
+ portSpin->setMinimum(1);
+ portSpin->setMaximum(65535);
+ connectionTypeComboBox = new QComboBox();
+ connectionTypeComboBox->addItem("None");
+ connectionTypeComboBox->addItem("SSL");
+ connectionTypeComboBox->addItem("TLS");
+ connectionTypeComboBox->addItem("STARTTLS");
+
+ defaultSender = new QLineEdit();;
+ checkConnectionButton = new QPushButton(tr("Check Connection"));
+
+ auto layout = new QGridLayout();
+ layout->addWidget(enableCheckBox, 0, 0);
+ layout->addWidget(new QLabel(tr("SMTP Address")), 1, 0);
+ layout->addWidget(smtpAddress, 1, 1, 1, 4);
+ layout->addWidget(new QLabel(tr("Username")), 2, 0);
+ layout->addWidget(username, 2, 1, 1, 4);
+ layout->addWidget(new QLabel(tr("Password")), 3, 0);
+ layout->addWidget(password, 3, 1, 1, 4);
+ layout->addWidget(new QLabel(tr("Port")), 4, 0);
+ layout->addWidget(portSpin, 4, 1, 1, 1);
+ layout->addWidget(new QLabel(tr("Connection Security")), 5, 0);
+ layout->addWidget(connectionTypeComboBox, 5, 1, 1, 1);
+
+ layout->addWidget(new QLabel(tr("Default Sender")), 6, 0);
+ layout->addWidget(defaultSender, 6, 1, 1, 4);
+ layout->addWidget(checkConnectionButton, 7, 0);
+
+ connect(enableCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotCheckBoxSetEnableDisable(int)));
+ connect(checkConnectionButton, SIGNAL(clicked(bool)), this, SLOT(slotCheckConnection()));
+
+
+ this->setLayout(layout);
+ setSettings();
+}
+
+/**********************************
+ * Read the settings from config
+ * and set the buttons and checkboxes
+ * appropriately
+ **********************************/
+void SendMailTab::setSettings() {
+
+ if (settings.value("sendMail/enable", false).toBool())
+ enableCheckBox->setCheckState(Qt::Checked);
+ else {
+ enableCheckBox->setCheckState(Qt::Unchecked);
+ smtpAddress->setDisabled(true);
+ username->setDisabled(true);
+ password->setDisabled(true);
+ portSpin->setDisabled(true);
+ connectionTypeComboBox->setDisabled(true);
+ defaultSender->setDisabled(true);
+ checkConnectionButton->setDisabled(true);
+ }
+
+ smtpAddress->setText(settings.value("sendMail/smtpAddress", QString()).toString());
+ username->setText(settings.value("sendMail/username", QString()).toString());
+ password->setText(settings.value("sendMail/password", QString()).toString());
+ portSpin->setValue(settings.value("sendMail/port", 25).toInt());
+ connectionTypeComboBox->setCurrentText(settings.value("sendMail/connectionType", "None").toString());
+ defaultSender->setText(settings.value("sendMail/defaultSender", QString()).toString());
+
+}
+
+/***********************************
+ * get the values of the buttons and
+ * write them to settings-file
+ *************************************/
+void SendMailTab::applySettings() {
+
+ settings.setValue("sendMail/smtpAddress", smtpAddress->text());
+ settings.setValue("sendMail/username", username->text());
+ settings.setValue("sendMail/password", password->text());
+ settings.setValue("sendMail/port", portSpin->value());
+ settings.setValue("sendMail/connectionType", connectionTypeComboBox->currentText());
+ settings.setValue("sendMail/defaultSender", defaultSender->text());
+
+ settings.setValue("sendMail/enable", enableCheckBox->isChecked());
+}
+
+void SendMailTab::slotCheckConnection() {
+
+ SmtpClient::ConnectionType connectionType;
+ const auto selectedConnType = connectionTypeComboBox->currentText();
+ if (selectedConnType == "SSL") {
+ connectionType = SmtpClient::ConnectionType::SslConnection;
+ } else if (selectedConnType == "TLS" || selectedConnType == "STARTTLS") {
+ connectionType = SmtpClient::ConnectionType::TlsConnection;
+ } else {
+ connectionType = SmtpClient::ConnectionType::TcpConnection;
+ }
+
+ SmtpClient smtp(smtpAddress->text(), portSpin->value(), connectionType);
+
+ smtp.setUser(username->text());
+ smtp.setPassword(password->text());
+
+ bool if_success = true;
+
+ if (!smtp.connectToHost()) {
+ QMessageBox::critical(this, tr("Fail"), tr("Fail to Connect SMTP Server"));
+ if_success = false;
+ }
+ if (if_success && !smtp.login()) {
+ QMessageBox::critical(this, tr("Fail"), tr("Fail to Login"));
+ if_success = false;
+ }
+
+ if (if_success)
+ QMessageBox::information(this, tr("Success"), tr("Succeed in connecting and login"));
+
+}
+
+void SendMailTab::slotCheckBoxSetEnableDisable(int state) {
+ if (state == Qt::Checked) {
+ smtpAddress->setEnabled(true);
+ username->setEnabled(true);
+ password->setEnabled(true);
+ portSpin->setEnabled(true);
+ connectionTypeComboBox->setEnabled(true);
+ defaultSender->setEnabled(true);
+ checkConnectionButton->setEnabled(true);
+ } else {
+ smtpAddress->setDisabled(true);
+ username->setDisabled(true);
+ password->setDisabled(true);
+ portSpin->setDisabled(true);
+ connectionTypeComboBox->setDisabled(true);
+ defaultSender->setDisabled(true);
+ checkConnectionButton->setDisabled(true);
+ }
+}
+