diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GpgFrontend.h | 54 | ||||
-rw-r--r-- | src/GpgFrontend.h.in | 17 | ||||
-rw-r--r-- | src/main.cpp | 81 | ||||
-rw-r--r-- | src/ui/GpgFrontendUI.h | 1 | ||||
-rw-r--r-- | src/ui/MainWindow.cpp | 291 | ||||
-rw-r--r-- | src/ui/MainWindow.h | 12 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 96 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowUI.cpp | 2 | ||||
-rw-r--r-- | src/ui/settings/GlobalSettingStation.cpp | 87 | ||||
-rw-r--r-- | src/ui/settings/GlobalSettingStation.h | 80 |
10 files changed, 488 insertions, 233 deletions
diff --git a/src/GpgFrontend.h b/src/GpgFrontend.h deleted file mode 100644 index 7115b493..00000000 --- a/src/GpgFrontend.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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. - * - */ - -#ifndef GPGFRONTEND_H_IN -#define GPGFRONTEND_H_IN - -/** - * Platform Vars - */ -#define WINDOWS 0 -#define MACOS 1 -#define LINUX 2 - -#define OS_PLATFORM 2 - -/** - * Build Options Vars - */ -#define RELEASE 0 -#define DEBUG 1 - -/** - * Resources File(s) Path Vars - */ -#if OS_PLATFORM == MACOS && BUILD_FLAG == RELEASE -#define RESOURCE_DIR(appDir) (appDir + "/../Resources/") -#elif OS_PLATFORM == LINUX && BUILD_FLAG == RELEASE -#define RESOURCE_DIR(appDir) (appDir + "/../share/") -#else -#define RESOURCE_DIR(appDir) (appDir) -#endif - -#endif // GPGFRONTEND_H_IN diff --git a/src/GpgFrontend.h.in b/src/GpgFrontend.h.in index 814e037f..705b095f 100644 --- a/src/GpgFrontend.h.in +++ b/src/GpgFrontend.h.in @@ -25,27 +25,14 @@ #ifndef GPGFRONTEND_H_IN #define GPGFRONTEND_H_IN -/** - * Platform Vars - */ -#define WINDOWS 0 -#define MACOS 1 -#define LINUX 2 - #define OS_PLATFORM @OS_PLATFORM@ /** - * Build Options Vars - */ -#define RELEASE 0 -#define DEBUG 1 - -/** * Resources File(s) Path Vars */ -#if OS_PLATFORM == MACOS && BUILD_FLAG == RELEASE +#if defined(MACOS) && defined(RELEASE) #define RESOURCE_DIR(appDir) (appDir + "/../Resources/") -#elif OS_PLATFORM == LINUX && BUILD_FLAG == RELEASE +#elif defined(LINUX) && defined(RELEASE) #define RESOURCE_DIR(appDir) (appDir + "/../share/") #else #define RESOURCE_DIR(appDir) (appDir) diff --git a/src/main.cpp b/src/main.cpp index 36f549a9..7cde6b20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,19 +24,21 @@ #include "GpgFrontendBuildInfo.h" #include "ui/MainWindow.h" +#include "ui/settings/GlobalSettingStation.h" // Easy Logging Cpp INITIALIZE_EASYLOGGINGPP -int main(int argc, char* argv[]) { - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); +void init_logging(); +int main(int argc, char* argv[]) { Q_INIT_RESOURCE(gpgfrontend); - QApplication app(argc, argv); + init_logging(); + // get application path - QString appPath = qApp->applicationDirPath(); + auto app_path = GlobalSettingStation::GetInstance().GetAppDir(); QApplication::setApplicationVersion(BUILD_VERSION); QApplication::setApplicationName(PROJECT_NAME); @@ -47,7 +49,7 @@ int main(int argc, char* argv[]) { // unicode in source QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8")); -#if (OS_PLATFORM == WINDOWS) +#ifdef WINDOWS // css QFile file(RESOURCE_DIR(qApp->applicationDirPath()) + "/css/default.qss"); file.open(QFile::ReadOnly); @@ -60,32 +62,40 @@ int main(int argc, char* argv[]) { * internationalisation. loop to restart mainwindow * with changed translation when settings change. */ - if (!QDir(RESOURCE_DIR(appPath) + "/conf").exists()) { - QDir().mkdir(RESOURCE_DIR(appPath) + "/conf"); - } - QSettings::setDefaultFormat(QSettings::IniFormat); - QSettings settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", - QSettings::IniFormat); + 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) = + QLocale::system().name().toStdString(); + + GlobalSettingStation::GetInstance().Sync(); + QTranslator translator, translator2; int return_from_event_loop_code; - qDebug() << "Resource Directory" << RESOURCE_DIR(appPath); + LOG(INFO) << "Resource Directory" << RESOURCE_DIR(app_path); do { QApplication::removeTranslator(&translator); QApplication::removeTranslator(&translator2); - QString lang = - settings.value("int/lang", QLocale::system().name()).toString(); - if (lang.isEmpty()) { - lang = QLocale::system().name(); - } - qDebug() << "Language set" << lang; - translator.load(RESOURCE_DIR(appPath) + "/ts/" + "gpgfrontend_" + lang); + std::string lang; + if (!general.lookupValue("lang", lang)) { + LOG(ERROR) << "could not read properly from configure file"; + }; + + translator.load(QString::fromStdString(RESOURCE_DIR(app_path).string() + + "/ts/" + "gpgfrontend_" + lang)); QApplication::installTranslator(&translator); // set qt translations - translator2.load(RESOURCE_DIR(appPath) + "/ts/qt_" + lang); + translator2.load(QString::fromStdString(RESOURCE_DIR(app_path).string() + + "/ts/qt_" + lang)); QApplication::installTranslator(&translator2); QApplication::setQuitOnLastWindowClosed(true); @@ -99,14 +109,10 @@ int main(int argc, char* argv[]) { // the locale set here is used for the other setlocale calls which have // nullptr // -> nullptr means use default, which is configured here - setlocale( - LC_ALL, - settings.value("int/lang").toLocale().name().toUtf8().constData()); + setlocale(LC_ALL, lang.c_str()); /** set locale, because tests do also */ gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); -// qDebug() << "Locale set to" << LC_CTYPE << " - " << setlocale(LC_CTYPE, -// nullptr); #ifndef _WIN32 gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); #endif @@ -118,3 +124,28 @@ int main(int argc, char* argv[]) { return return_from_event_loop_code; } + +void init_logging() { + using namespace boost::posix_time; + using namespace boost::gregorian; + + ptime now = second_clock::local_time(); + + el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); + el::Configurations defaultConf; + defaultConf.setToDefault(); + el::Loggers::reconfigureLogger("default", defaultConf); + + defaultConf.setGlobally(el::ConfigurationType::Format, + "%datetime %level %func %msg"); + + auto logfile_path = + (GlobalSettingStation::GetInstance().GetLogDir() / to_iso_string(now)); + logfile_path.replace_extension(".log"); + defaultConf.setGlobally(el::ConfigurationType::Filename, + logfile_path.string()); + + el::Loggers::reconfigureLogger("default", defaultConf); + + LOG(INFO) << "Logfile Path" << logfile_path; +} diff --git a/src/ui/GpgFrontendUI.h b/src/ui/GpgFrontendUI.h index 42d125d6..593ed872 100644 --- a/src/ui/GpgFrontendUI.h +++ b/src/ui/GpgFrontendUI.h @@ -26,6 +26,7 @@ #define GPGFRONTEND_GPGFRONTENDUI_H #include <GpgFrontend.h> +#include <easyloggingpp/easylogging++.h> #include <QtCore> #include <QtNetwork> diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 497463aa..b986782b 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -23,14 +23,13 @@ */ #include "MainWindow.h" + #include "ui/help/VersionCheckThread.h" +#include "ui/settings/GlobalSettingStation.h" namespace GpgFrontend::UI { -MainWindow::MainWindow() - : appPath(qApp->applicationDirPath()), - settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", - QSettings::IniFormat) { +MainWindow::MainWindow() { networkAccessManager = new QNetworkAccessManager(this); auto waitingDialog = new WaitingDialog(tr("Loading Gnupg"), this); @@ -43,6 +42,7 @@ MainWindow::MainWindow() QNetworkReply* replay = networkAccessManager->get(request); +#ifdef RELEASE auto version_thread = new VersionCheckThread(replay); connect(version_thread, SIGNAL(finished()), version_thread, @@ -52,6 +52,7 @@ MainWindow::MainWindow() SLOT(slotVersionUpgrade(const QString&, const QString&))); version_thread->start(); +#endif // Check Context Status if (!GpgContext::GetInstance().good()) { @@ -96,7 +97,8 @@ MainWindow::MainWindow() keyMgmt->hide(); /* test attachmentdir for files alll 15s */ auto* timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(slotCheckAttachmentFolder())); + // connect(timer, SIGNAL(timeout()), this, + // SLOT(slotCheckAttachmentFolder())); timer->start(5000); createActions(); @@ -121,8 +123,7 @@ MainWindow::MainWindow() QStringList args = qApp->arguments(); if (args.size() > 1) { if (!args[1].startsWith("-")) { - if (QFile::exists(args[1])) - edit->loadFile(args[1]); + if (QFile::exists(args[1])) edit->loadFile(args[1]); } } edit->curTextPage()->setFocus(); @@ -133,95 +134,221 @@ MainWindow::MainWindow() this->setWindowTitle(qApp->applicationName()); this->show(); + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + + if (!settings.exists("wizard") || + settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup) + settings.add("wizard", libconfig::Setting::TypeGroup); + + auto& wizard = settings["wizard"]; + // Show wizard, if the don't show wizard message box wasn't checked // and keylist doesn't contain a private key - qDebug() << "wizard/showWizard" - << settings.value("wizard/showWizard", true).toBool(); - qDebug() << "wizard/nextPage" << settings.value("wizard/nextPage").isNull(); - if (settings.value("wizard/showWizard", true).toBool() || - !settings.value("wizard/nextPage").isNull()) { + + if (!wizard.exists("show_wizard")) + wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = true; + + bool show_wizard = true; + wizard.lookupValue("show_wizard", show_wizard); + + LOG(INFO) << "wizard show_wizard" << show_wizard; + + if (show_wizard) { slotStartWizard(); } } void MainWindow::restoreSettings() { - // state sets pos & size of dock-widgets - this->restoreState(settings.value("window/windowState").toByteArray()); - - // Restore window size & location - if (settings.value("window/windowSave").toBool()) { - QPoint pos = settings.value("window/pos", QPoint(100, 100)).toPoint(); - QSize size = settings.value("window/size", QSize(800, 450)).toSize(); - this->resize(size); - this->move(pos); - } else { - this->resize(QSize(800, 450)); - this->move(QPoint(100, 100)); - } + try { + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + + if (!settings.exists("window") || + settings.lookup("window").getType() != libconfig::Setting::TypeGroup) + settings.add("window", libconfig::Setting::TypeGroup); + + auto& window = settings["window"]; + + if (!window.exists("window_state")) + window.add("window_state", libconfig::Setting::TypeString) = + saveState().toBase64().toStdString(); + + std::string window_state = settings.lookup("window.window_state"); + // state sets pos & size of dock-widgets + this->restoreState( + QByteArray::fromBase64(QByteArray::fromStdString(window_state))); + + if (!window.exists("window_save")) + window.add("window_save", libconfig::Setting::TypeBoolean) = true; + + bool window_save; + window.lookupValue("window_save", window_save); + + // Restore window size & location + if (window_save) { + if (!window.exists("window_pos")) + window.add("window_pos", libconfig::Setting::TypeGroup); + + auto& window_pos = window["window_pos"]; + + if (!window_pos.exists("x")) + window_pos.add("x", libconfig::Setting::TypeInt) = 100; + + if (!window_pos.exists("y")) + window_pos.add("y", libconfig::Setting::TypeInt) = 100; + + int x, y; + window_pos.lookupValue("x", x); + window_pos.lookupValue("y", y); + + auto pos = QPoint(x, y); + + if (!window.exists("window_size")) + window.add("window_size", libconfig::Setting::TypeGroup); + + auto& window_size = window["window_size"]; + + if (!window_size.exists("width")) + window_size.add("width", libconfig::Setting::TypeInt) = 800; + + if (!window_size.exists("height")) + window_size.add("height", libconfig::Setting::TypeInt) = 450; + + int width, height; + window_size.lookupValue("width", width); + window_size.lookupValue("height", height); + + auto size = QSize(width, height); + this->resize(size); + this->move(pos); + } else { + this->resize(QSize(800, 450)); + this->move(QPoint(100, 100)); + } + + if (!window.exists("icon_size")) + window.add("icon_size", libconfig::Setting::TypeGroup); - // Iconsize - QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize(); - this->setIconSize(iconSize); - - importButton->setIconSize(iconSize); - fileEncButton->setIconSize(iconSize); - // set list of keyserver if not defined - QStringList* keyServerDefaultList; - keyServerDefaultList = new QStringList("http://keys.gnupg.net"); - keyServerDefaultList->append("https://keyserver.ubuntu.com"); - keyServerDefaultList->append("http://pool.sks-keyservers.net"); - - QStringList keyServerList = - settings.value("keyserver/keyServerList", *keyServerDefaultList) - .toStringList(); - settings.setValue("keyserver/keyServerList", keyServerList); - - // set default keyserver, if it's not set - QString defaultKeyServer = settings - .value("keyserver/defaultKeyServer", - QString("https://keyserver.ubuntu.com")) - .toString(); - settings.setValue("keyserver/defaultKeyServer", defaultKeyServer); - - // Iconstyle - Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>( - settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon) - .toUInt()); - this->setToolButtonStyle(buttonStyle); - importButton->setToolButtonStyle(buttonStyle); - fileEncButton->setToolButtonStyle(buttonStyle); - - // Checked Keys - if (settings.value("keys/saveKeyChecked").toBool()) { - QStringList keyIds = - settings.value("keys/savedCheckedKeyList").toStringList(); - auto key_ids_ptr = std::make_unique<KeyIdArgsList>(); - for (auto& key_id : keyIds) - key_ids_ptr->push_back(key_id.toStdString()); - mKeyList->setChecked(key_ids_ptr); + auto& icon_size = window["icon_size"]; + + if (!icon_size.exists("width")) + icon_size.add("width", libconfig::Setting::TypeInt) = 24; + + if (!icon_size.exists("height")) + icon_size.add("height", libconfig::Setting::TypeInt) = 24; + + int width = icon_size["width"], height = icon_size["height"]; + LOG(INFO) << "icon_size" << width << height; + + // icons ize + this->setIconSize(QSize(width, height)); + importButton->setIconSize(QSize(width, height)); + fileEncButton->setIconSize(QSize(width, height)); + + if (!settings.exists("keyserver") || + settings.lookup("keyserver").getType() != libconfig::Setting::TypeGroup) + settings.add("keyserver", libconfig::Setting::TypeGroup); + + auto& keyserver = settings["keyserver"]; + + if (!keyserver.exists("server_list")) { + keyserver.add("server_list", libconfig::Setting::TypeList); + + auto& server_list = keyserver["server_list"]; + server_list.add(libconfig::Setting::TypeString) = "http://keys.gnupg.net"; + server_list.add(libconfig::Setting::TypeString) = + "https://keyserver.ubuntu.com"; + server_list.add(libconfig::Setting::TypeString) = + "http://pool.sks-keyservers.net"; + } + + if (!keyserver.exists("default_server")) { + keyserver.add("default_server", libconfig::Setting::TypeString) = + "https://keyserver.ubuntu.com"; + } + + if (!window.exists("icon_style")) { + window.add("icon_style", libconfig::Setting::TypeInt) = + Qt::ToolButtonTextUnderIcon; + } + + int s_icon_style = window.lookup("icon_style"); + + // icon_style + auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style); + this->setToolButtonStyle(icon_style); + importButton->setToolButtonStyle(icon_style); + fileEncButton->setToolButtonStyle(icon_style); + + if (!settings.exists("general") || + settings.lookup("general").getType() != libconfig::Setting::TypeGroup) + settings.add("general", libconfig::Setting::TypeGroup); + + auto& general = settings["general"]; + + if (!general.exists("save_key_checked")) { + general.add("save_key_checked", libconfig::Setting::TypeBoolean) = true; + } + + bool save_key_checked = true; + general.lookupValue("save_key_checked", save_key_checked); + + // Checked Keys + if (save_key_checked) { + if (!general.exists("save_key_checked_key_ids")) { + general.add("save_key_checked_key_ids", libconfig::Setting::TypeList); + } + auto key_ids_ptr = std::make_unique<KeyIdArgsList>(); + ; + auto& save_key_checked_key_ids = general["save_key_checked_key_ids"]; + const auto key_ids_size = + general.lookup("save_key_checked_key_ids").getLength(); + for (auto i = 0; i < key_ids_size; i++) { + std::string key_id = save_key_checked_key_ids[i]; + key_ids_ptr->push_back(key_id); + } + mKeyList->setChecked(key_ids_ptr); + } + } catch (...) { + LOG(ERROR) << "cannot resolve settings"; } + + GlobalSettingStation::GetInstance().Sync(); } void MainWindow::saveSettings() { - // window position and size - settings.setValue("window/windowState", saveState()); - settings.setValue("window/pos", pos()); - settings.setValue("window/size", size()); - - // keyid-list of private checked keys - if (settings.value("keys/saveKeyChecked").toBool()) { - auto keyIds = mKeyList->getChecked(); - if (!keyIds->empty()) { - QStringList key_ids_str_list; - for (const auto& key_id : *keyIds) - key_ids_str_list << QString::fromStdString(key_id); - settings.setValue("keys/savedCheckedKeyList", key_ids_str_list); + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + + try { + // window position and size + settings["window"]["window_state"] = saveState().toBase64().toStdString(); + settings["window"]["window_pos"]["x"] = pos().x(); + settings["window"]["window_pos"]["y"] = pos().y(); + + settings["window"]["window_size"]["width"] = size().width(); + settings["window"]["window_size"]["height"] = size().height(); + + bool save_key_checked = settings.lookup("general.save_key_checked"); + + // keyid-list of private checked keys + if (save_key_checked) { + auto& key_ids = settings.lookup("general.save_key_checked_key_ids"); + const int key_ids_size = key_ids.getLength(); + for (auto i = 0; i < key_ids_size; i++) key_ids.remove(i); + auto key_ids_need_to_store = mKeyList->getChecked(); + + for (size_t i = 0; i < key_ids_need_to_store->size(); i++) { + std::string key_id = (*key_ids_need_to_store)[i]; + key_ids.add(libconfig::Setting::TypeString) = key_id; + } + } else { - settings.setValue("keys/savedCheckedKeyList", ""); + settings["general"].remove("save_key_checked"); } - } else { - settings.remove("keys/savedCheckedKeyList"); - } + } catch (...) { + LOG(ERROR) << "cannot save settings"; + }; + + GlobalSettingStation::GetInstance().Sync(); } void MainWindow::closeAttachmentDock() { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index f6de47d8..095bc974 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -230,11 +230,11 @@ class MainWindow : public QMainWindow { */ void slotOpenSettingsDialog(); - /** - * @details Show a warn message in status bar, if there are files in - * attachment folder. - */ - void slotCheckAttachmentFolder(); +// /** +// * @details Show a warn message in status bar, if there are files in +// * attachment folder. +// */ +// void slotCheckAttachmentFolder(); /** * @details Replace double linebreaks by single linebreaks in currently active @@ -409,8 +409,6 @@ class MainWindow : public QMainWindow { QLabel* statusBarIcon; /**< TODO */ - QString appPath; - QSettings settings; KeyList* mKeyList; InfoBoardWidget* infoBoard; diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index baade2b4..7310bd1c 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -23,16 +23,13 @@ */ #include "MainWindow.h" +#include "ui/settings/GlobalSettingStation.h" namespace GpgFrontend::UI { -void MainWindow::slotAbout() { - new AboutDialog(0, this); -} +void MainWindow::slotAbout() { new AboutDialog(0, this); } -void MainWindow::slotCheckUpdate() { - new AboutDialog(2, this); -} +void MainWindow::slotCheckUpdate() { new AboutDialog(2, this); } void MainWindow::slotSetStatusBarText(const QString& text) { statusBar()->showMessage(text, 20000); @@ -44,33 +41,32 @@ void MainWindow::slotStartWizard() { wizard->setModal(true); } -void MainWindow::slotCheckAttachmentFolder() { - // TODO: always check? - if (!settings.value("mime/parseMime").toBool()) { - return; - } - - QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; - // filenum minus . and .. - uint filenum = QDir(attachmentDir).count() - 2; - if (filenum > 0) { - QString statusText; - if (filenum == 1) { - statusText = tr("There is one unencrypted file in attachment folder"); - } else { - statusText = tr("There are ") + QString::number(filenum) + - tr(" unencrypted files in attachment folder"); - } - statusBarIcon->setStatusTip(statusText); - statusBarIcon->show(); - } else { - statusBarIcon->hide(); - } -} +// void MainWindow::slotCheckAttachmentFolder() { +// // TODO: always check? +// if (!settings.value("mime/parseMime").toBool()) { +// return; +// } +// +// QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; +// // filenum minus . and .. +// uint filenum = QDir(attachmentDir).count() - 2; +// if (filenum > 0) { +// QString statusText; +// if (filenum == 1) { +// statusText = tr("There is one unencrypted file in attachment folder"); +// } else { +// statusText = tr("There are ") + QString::number(filenum) + +// tr(" unencrypted files in attachment folder"); +// } +// statusBarIcon->setStatusTip(statusText); +// statusBarIcon->show(); +// } else { +// statusBarIcon->hide(); +// } +// } void MainWindow::slotImportKeyFromEdit() { - if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) - return; + if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return; keyMgmt->slotImportKeys(edit->curTextPage()->toPlainText().toStdString()); } @@ -80,9 +76,7 @@ void MainWindow::slotOpenKeyManagement() { keyMgmt->activateWindow(); } -void MainWindow::slotOpenFileTab() { - edit->slotNewFileTab(); -} +void MainWindow::slotOpenFileTab() { edit->slotNewFileTab(); } void MainWindow::slotDisableTabActions(int number) { bool disable; @@ -130,21 +124,24 @@ void MainWindow::slotOpenSettingsDialog() { auto dialog = new SettingsDialog(this); connect(dialog, &SettingsDialog::finished, this, [&]() -> void { - qDebug() << "Setting Dialog Finished"; + LOG(INFO) << "Setting Dialog Finished"; + + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); - // Iconsize - QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize(); - this->setIconSize(iconSize); - importButton->setIconSize(iconSize); - fileEncButton->setIconSize(iconSize); + int icon_width = settings["window"]["icon_size"]["width"]; + int icon_height = settings["window"]["icon_size"]["height"]; + + this->setIconSize(QSize(icon_width, icon_height)); + importButton->setIconSize(QSize(icon_width, icon_height)); + fileEncButton->setIconSize(QSize(icon_width, icon_height)); // Iconstyle - Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>( - settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon) - .toUInt()); - this->setToolButtonStyle(buttonStyle); - importButton->setToolButtonStyle(buttonStyle); - fileEncButton->setToolButtonStyle(buttonStyle); + + int icon_style = settings["window"]["icon_style"]; + auto button_style = static_cast<Qt::ToolButtonStyle>(icon_style); + this->setToolButtonStyle(button_style); + importButton->setToolButtonStyle(button_style); + fileEncButton->setToolButtonStyle(button_style); // restart mainwindow if necessary if (getRestartNeeded()) { @@ -153,7 +150,7 @@ void MainWindow::slotOpenSettingsDialog() { qApp->exit(RESTART_CODE); } } - +#ifdef ADVANCED_SUPPORT // steganography hide/show if (!settings.value("advanced/steganography").toBool()) { this->menuBar()->removeAction(steganoMenu->menuAction()); @@ -161,6 +158,7 @@ void MainWindow::slotOpenSettingsDialog() { this->menuBar()->insertAction(viewMenu->menuAction(), steganoMenu->menuAction()); } +#endif }); } @@ -215,8 +213,6 @@ void MainWindow::slotSetRestartNeeded(bool needed) { this->restartNeeded = needed; } -bool MainWindow::getRestartNeeded() const { - return this->restartNeeded; -} +bool MainWindow::getRestartNeeded() const { return this->restartNeeded; } } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 44fed8dc..cf5d1172 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -365,10 +365,12 @@ void MainWindow::createMenus() { steganoMenu->addAction(cutPgpHeaderAct); steganoMenu->addAction(addPgpHeaderAct); +#ifdef ADVANCED_SUPPORT // Hide menu, when steganography menu is disabled in settings if (!settings.value("advanced/steganography").toBool()) { this->menuBar()->removeAction(steganoMenu->menuAction()); } +#endif viewMenu = menuBar()->addMenu(tr("&View")); diff --git a/src/ui/settings/GlobalSettingStation.cpp b/src/ui/settings/GlobalSettingStation.cpp new file mode 100644 index 00000000..5d292446 --- /dev/null +++ b/src/ui/settings/GlobalSettingStation.cpp @@ -0,0 +1,87 @@ +/** + * 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 "GlobalSettingStation.h" + +std::unique_ptr<GlobalSettingStation> GlobalSettingStation::_instance = nullptr; + +GlobalSettingStation& GlobalSettingStation::GetInstance() { + if (_instance == nullptr) { + _instance = std::make_unique<GlobalSettingStation>(); + } + return *_instance; +} + +void GlobalSettingStation::Sync() noexcept { + using namespace libconfig; + try { + ui_cfg.writeFile(ui_config_path.c_str()); + LOG(INFO) << "Updated ui configuration successfully written to: " + << ui_config_path; + + } catch (const FileIOException& fioex) { + LOG(ERROR) << "I/O error while writing ui configuration file: " + << ui_config_path; + } +} + +GlobalSettingStation::GlobalSettingStation() noexcept { + using namespace boost::filesystem; + using namespace libconfig; + + LOG(INFO) << "App Configure Path" << app_configure_path; + LOG(INFO) << "App Data Path" << app_data_path; + LOG(INFO) << "App Log Path" << app_log_path; + + if (!is_directory(app_configure_path)) create_directory(app_configure_path); + + if (!is_directory(app_data_path)) create_directory(app_data_path); + + if (!is_directory(app_log_path)) create_directory(app_log_path); + + if (!is_directory(ui_config_dir_path)) create_directory(ui_config_dir_path); + + if (!exists(ui_config_path)) { + try { + this->ui_cfg.writeFile(ui_config_path.c_str()); + LOG(INFO) << "UserInterface configuration successfully written to: " + << ui_config_path; + + } catch (const FileIOException& fioex) { + LOG(ERROR) << "I/O error while writing UserInterface configuration file: " + << ui_config_path; + } + } else { + try { + this->ui_cfg.readFile(ui_config_path.c_str()); + LOG(INFO) << "UserInterface configuration successfully read from: " + << ui_config_path; + } catch (const FileIOException& fioex) { + LOG(ERROR) << "I/O error while reading UserInterface configure file"; + } catch (const ParseException& pex) { + LOG(ERROR) << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError(); + } + } +} diff --git a/src/ui/settings/GlobalSettingStation.h b/src/ui/settings/GlobalSettingStation.h new file mode 100644 index 00000000..03a362ba --- /dev/null +++ b/src/ui/settings/GlobalSettingStation.h @@ -0,0 +1,80 @@ +/** + * 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. + * + */ + +#ifndef GPGFRONTEND_GLOBALSETTINGSTATION_H +#define GPGFRONTEND_GLOBALSETTINGSTATION_H + +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> +#include <libconfig.h++> + +#include "ui/GpgFrontendUI.h" + +class GlobalSettingStation : public QObject { + Q_OBJECT + static std::unique_ptr<GlobalSettingStation> _instance; + + public: + static GlobalSettingStation& GetInstance(); + + GlobalSettingStation() noexcept; + + libconfig::Setting& GetUISettings() noexcept { return ui_cfg.getRoot(); } + + [[nodiscard]] boost::filesystem::path GetAppDir() const { return app_path; } + + [[nodiscard]] boost::filesystem::path GetLogDir() const { + return app_log_path; + } + + void Sync() noexcept; + + private: + // Program Location + boost::filesystem::path app_path = qApp->applicationDirPath().toStdString(); + + // Program Data Location + boost::filesystem::path app_data_path = + QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + .toStdString(); + + // Program Data Location + boost::filesystem::path app_log_path = app_data_path / "logs"; + + // Program Configure Location + boost::filesystem::path app_configure_path = + QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + .toStdString(); + + // Configure File Directory Location + boost::filesystem::path ui_config_dir_path = + app_configure_path / "UserInterface"; + + // UI Configure File Location + boost::filesystem::path ui_config_path = ui_config_dir_path / "ui.cfg"; + + libconfig::Config ui_cfg; +}; + +#endif // GPGFRONTEND_GLOBALSETTINGSTATION_H |