diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 783a3fb3..afddda82 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -17,9 +17,16 @@ #include "geneneralconf.h" #include "src/utils/confighandler.h" +#include "src/utils/confighandler.h" #include "src/core/controller.h" #include +#include #include +#include +#include +#include +#include +#include GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { m_layout = new QVBoxLayout(this); @@ -27,6 +34,7 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { initShowHelp(); initShowDesktopNotification(); initShowTrayIcon(); + initConfingButtons(); updateComponents(); } @@ -51,7 +59,44 @@ void GeneneralConf::showTrayIconChanged(bool checked) { controller->enableTrayIcon(); } else { controller->disableTrayIcon(); - } + } +} + +void GeneneralConf::importConfiguration() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Import")); + QFile file(fileName); + QTextCodec *codec = QTextCodec::codecForLocale(); + if (!file.open(QFile::ReadOnly)) { + QMessageBox::about(this, tr("Error"), tr("Unable to read file.")); + return; + } + QString text = codec->toUnicode(file.readAll()); + file.close(); + + QFile config(ConfigHandler().configFilePath()); + if (!config.open(QFile::WriteOnly)) { + QMessageBox::about(this, tr("Error"), tr("Unable to write file.")); + return; + } + config.write(codec->fromUnicode(text)); + config.close(); +} + +void GeneneralConf::exportConfiguration() { + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), + "flameshot.conf"); + QFile::copy(ConfigHandler().configFilePath(), fileName); +} + +void GeneneralConf::resetConfiguration() { + QMessageBox::StandardButton reply; + reply = QMessageBox::question( + this, tr("Confirm Reset"), + tr("Are you sure you want to reset the configuration?"), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + ConfigHandler().setDefaults(); + } } void GeneneralConf::initShowHelp() { @@ -89,5 +134,26 @@ void GeneneralConf::initShowTrayIcon() { m_layout->addWidget(m_showTray); connect(m_showTray, &QCheckBox::clicked, this, - &GeneneralConf::showTrayIconChanged); + &GeneneralConf::showTrayIconChanged); +} + +void GeneneralConf::initConfingButtons() { + QHBoxLayout *buttonLayout = new QHBoxLayout(); + m_layout->addStretch(); + m_layout->addLayout(buttonLayout); + + m_exportButton = new QPushButton(tr("Export configuration")); + buttonLayout->addWidget(m_exportButton); + connect(m_exportButton, &QPushButton::clicked, this, + &GeneneralConf::exportConfiguration); + + m_importButton = new QPushButton(tr("Import configuration")); + buttonLayout->addWidget(m_importButton); + connect(m_importButton, &QPushButton::clicked, this, + &GeneneralConf::importConfiguration); + + m_resetButton = new QPushButton(tr("Reset configuration")); + buttonLayout->addWidget(m_resetButton); + connect(m_resetButton, &QPushButton::clicked, this, + &GeneneralConf::resetConfiguration); } diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index 6aa5c2b9..0f17ee6b 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -22,6 +22,7 @@ class QVBoxLayout; class QCheckBox; +class QPushButton; class GeneneralConf : public QGroupBox { Q_OBJECT @@ -35,16 +36,23 @@ private slots: void showHelpChanged(bool checked); void showDesktopNotificationChanged(bool checked); void showTrayIconChanged(bool checked); + void importConfiguration(); + void exportConfiguration(); + void resetConfiguration(); private: QVBoxLayout *m_layout; QCheckBox *m_sysNotifications; QCheckBox *m_showTray; QCheckBox *m_helpMessage; + QPushButton *m_importButton; + QPushButton *m_exportButton; + QPushButton *m_resetButton; void initShowHelp(); void initShowDesktopNotification(); void initShowTrayIcon(); + void initConfingButtons(); }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index f4aa934b..7c0928fd 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -134,6 +134,7 @@ void ConfigHandler::setDefaults() { setDrawColor(QColor(Qt::red)); setUIMainColor(QColor(116, 0, 150)); setUIContrastColor(QColor(86, 0, 120)); + setdrawThickness(0); setAllTheButtons(); }