mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-02-14 06:24:02 +00:00
Add configuration import, export and reset
This commit is contained in:
@@ -17,9 +17,16 @@
|
||||
|
||||
#include "geneneralconf.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/core/controller.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
#include <QTextCodec>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ void ConfigHandler::setDefaults() {
|
||||
setDrawColor(QColor(Qt::red));
|
||||
setUIMainColor(QColor(116, 0, 150));
|
||||
setUIContrastColor(QColor(86, 0, 120));
|
||||
setdrawThickness(0);
|
||||
setAllTheButtons();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user