# Conflicts: # .travis.yml # appveyor.yml # data/graphics.qrc # data/img/app/keyboard.svg # data/img/material/black/delete.png # data/img/material/black/delete.svg # data/img/material/black/filepath.svg # data/img/material/black/shortcut.svg # data/img/material/white/filepath.svg # data/img/material/white/shortcut.svg # data/translations/Internationalization_hu.ts # data/translations/Internationalization_ka.ts # external/Qt-Color-Widgets/src/color_wheel.cpp # external/singleapplication/singleapplication.cpp # flameshot.pro # src/cli/commandlineparser.cpp # src/config/buttonlistview.cpp # src/config/configwindow.cpp # src/config/configwindow.h # src/config/geneneralconf.cpp # src/config/geneneralconf.h # src/config/uicoloreditor.cpp # src/config/uicoloreditor.h # src/core/controller.cpp # src/core/globalshortcutfilter.cpp # src/main.cpp # src/third-party/Qt-Color-Widgets/src/color_utils.cpp # src/tools/abstractactiontool.h # src/tools/abstractpathtool.h # src/tools/arrow/arrowtool.cpp # src/tools/arrow/arrowtool.h # src/tools/blur/blurtool.cpp # src/tools/capturetool.h # src/tools/circle/circletool.cpp # src/tools/circle/circletool.h # src/tools/copy/copytool.cpp # src/tools/copy/copytool.h # src/tools/exit/exittool.cpp # src/tools/exit/exittool.h # src/tools/imgur/imguruploader.cpp # src/tools/launcher/applaunchertool.cpp # src/tools/launcher/applaunchertool.h # src/tools/launcher/applauncherwidget.cpp # src/tools/launcher/openwithprogram.cpp # src/tools/line/linetool.cpp # src/tools/line/linetool.h # src/tools/marker/markertool.cpp # src/tools/marker/markertool.h # src/tools/move/movetool.cpp # src/tools/pencil/penciltool.cpp # src/tools/pencil/penciltool.h # src/tools/pin/pintool.cpp # src/tools/pin/pintool.h # src/tools/pin/pinwidget.cpp # src/tools/pixelate/pixelatetool.h # src/tools/rectangle/rectangletool.cpp # src/tools/rectangle/rectangletool.h # src/tools/redo/redotool.cpp # src/tools/redo/redotool.h # src/tools/save/savetool.cpp # src/tools/save/savetool.h # src/tools/selection/selectiontool.cpp # src/tools/selection/selectiontool.h # src/tools/sizeindicator/sizeindicatortool.cpp # src/tools/sizeindicator/sizeindicatortool.h # src/tools/storage/imgur/imguruploader.h # src/tools/storage/imgur/imguruploadertool.cpp # src/tools/storage/imgur/imguruploadertool.h # src/tools/text/textconfig.cpp # src/tools/text/texttool.cpp # src/tools/text/texttool.h # src/tools/toolfactory.cpp # src/tools/toolfactory.h # src/tools/undo/undotool.cpp # src/tools/undo/undotool.h # src/utils/confighandler.cpp # src/utils/confighandler.h # src/utils/dbusutils.cpp # src/utils/screenshotsaver.cpp # src/utils/screenshotsaver.h # src/widgets/capture/buttonhandler.cpp # src/widgets/capture/buttonhandler.h # src/widgets/capture/capturebutton.cpp # src/widgets/capture/capturebutton.h # src/widgets/capture/capturewidget.cpp # src/widgets/capture/capturewidget.h # src/widgets/capture/colorpicker.cpp # src/widgets/capturelauncher.cpp # src/widgets/infowindow.cpp # src/widgets/infowindow.h # src/widgets/panel/sidepanelwidget.cpp # src/widgets/panel/utilitypanel.cpp # src/widgets/panel/utilitypanel.h # translations/Internationalization_ca.ts # translations/Internationalization_de_DE.ts # translations/Internationalization_es.ts # translations/Internationalization_fr.ts # translations/Internationalization_ja.ts # translations/Internationalization_nl.ts # translations/Internationalization_pl.ts # translations/Internationalization_pt_br.ts # translations/Internationalization_ru.ts # translations/Internationalization_sk.ts # translations/Internationalization_sr.ts # translations/Internationalization_tr.ts # translations/Internationalization_uk.ts # translations/Internationalization_zh_CN.ts # translations/Internationalization_zh_TW.ts
442 lines
14 KiB
C++
442 lines
14 KiB
C++
// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
|
|
//
|
|
// This file is part of Flameshot.
|
|
//
|
|
// Flameshot 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.
|
|
//
|
|
// Flameshot 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 Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#include "geneneralconf.h"
|
|
#include "filepathconfiguration.h"
|
|
#include "src/core/controller.h"
|
|
#include "src/utils/confighandler.h"
|
|
#include "src/utils/filenamehandler.h"
|
|
#include "src/tools/storage/imgstorages.h"
|
|
#include "src/utils/confighandler.h"
|
|
#include <QCheckBox>
|
|
#include <QFile>
|
|
#include <QFileDialog>
|
|
#include <QGroupBox>
|
|
#include <QHBoxLayout>
|
|
#include <QLineEdit>
|
|
#include <QMessageBox>
|
|
#include <QPushButton>
|
|
#include <QRadioButton>
|
|
#include <QStandardPaths>
|
|
#include <QTextCodec>
|
|
#include <QVBoxLayout>
|
|
GeneneralConf::GeneneralConf(QWidget* parent)
|
|
: QWidget(parent)
|
|
{
|
|
m_layout = new QVBoxLayout(this);
|
|
m_layout->setAlignment(Qt::AlignTop);
|
|
initShowHelp();
|
|
initShowSidePanelButton();
|
|
initShowDesktopNotification();
|
|
initShowTrayIcon();
|
|
initAutostart();
|
|
initShowStartupLaunchMessage();
|
|
initCloseAfterCapture();
|
|
initCopyAndCloseAfterUpload();
|
|
initSaveAfterCopy();
|
|
initCopyPathAfterSave();
|
|
initUploadStorage();
|
|
initFilePathConfiguration();
|
|
|
|
// this has to be at the end
|
|
initConfingButtons();
|
|
updateComponents();
|
|
}
|
|
|
|
void GeneneralConf::updateComponents()
|
|
{
|
|
ConfigHandler config;
|
|
m_helpMessage->setChecked(config.showHelpValue());
|
|
m_sidePanelButton->setChecked(config.showSidePanelButtonValue());
|
|
m_sysNotifications->setChecked(config.desktopNotificationValue());
|
|
m_autostart->setChecked(config.startupLaunchValue());
|
|
m_closeAfterCapture->setChecked(config.closeAfterScreenshotValue());
|
|
m_copyAndCloseAfterUpload->setChecked(
|
|
config.copyAndCloseAfterUploadEnabled());
|
|
m_saveAfterCopy->setChecked(config.saveAfterCopyValue());
|
|
|
|
if (!config.saveAfterCopyPathValue().isEmpty()) {
|
|
m_savePath->setText(config.saveAfterCopyPathValue());
|
|
} else {
|
|
ConfigHandler().setSaveAfterCopyPath(
|
|
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
|
|
}
|
|
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
|
m_showTray->setChecked(!config.disabledTrayIconValue());
|
|
#endif
|
|
}
|
|
|
|
void GeneneralConf::showHelpChanged(bool checked)
|
|
{
|
|
ConfigHandler().setShowHelp(checked);
|
|
}
|
|
|
|
void GeneneralConf::showSidePanelButtonChanged(bool checked)
|
|
{
|
|
ConfigHandler().setShowSidePanelButton(checked);
|
|
}
|
|
|
|
void GeneneralConf::showDesktopNotificationChanged(bool checked)
|
|
{
|
|
ConfigHandler().setDesktopNotification(checked);
|
|
}
|
|
|
|
void GeneneralConf::showTrayIconChanged(bool checked)
|
|
{
|
|
auto controller = Controller::getInstance();
|
|
if (checked) {
|
|
controller->enableTrayIcon();
|
|
} else {
|
|
controller->disableTrayIcon();
|
|
}
|
|
}
|
|
|
|
void GeneneralConf::autostartChanged(bool checked)
|
|
{
|
|
ConfigHandler().setStartupLaunch(checked);
|
|
}
|
|
|
|
void GeneneralConf::showStartupLaunchMessageChanged(bool checked)
|
|
{
|
|
ConfigHandler().setShowStartupLaunchMessage(checked);
|
|
}
|
|
|
|
void GeneneralConf::closeAfterCaptureChanged(bool checked)
|
|
{
|
|
ConfigHandler().setCloseAfterScreenshot(checked);
|
|
}
|
|
|
|
void GeneneralConf::importConfiguration()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Import"));
|
|
if (fileName.isEmpty()) {
|
|
return;
|
|
}
|
|
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::exportFileConfiguration()
|
|
{
|
|
QString fileName = QFileDialog::getSaveFileName(
|
|
this, tr("Save File"), QStringLiteral("flameshot.conf"));
|
|
|
|
// Cancel button
|
|
if (fileName.isNull()) {
|
|
return;
|
|
}
|
|
|
|
QFile targetFile(fileName);
|
|
if (targetFile.exists()) {
|
|
targetFile.remove();
|
|
}
|
|
bool ok = QFile::copy(ConfigHandler().configFilePath(), fileName);
|
|
if (!ok) {
|
|
QMessageBox::about(this, tr("Error"), tr("Unable to write file."));
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
m_helpMessage = new QCheckBox(tr("Show help message"), this);
|
|
ConfigHandler config;
|
|
bool checked = config.showHelpValue();
|
|
m_helpMessage->setChecked(checked);
|
|
m_helpMessage->setToolTip(tr("Show the help message at the beginning "
|
|
"in the capture mode."));
|
|
m_layout->addWidget(m_helpMessage);
|
|
|
|
connect(m_helpMessage,
|
|
&QCheckBox::clicked,
|
|
this,
|
|
&GeneneralConf::showHelpChanged);
|
|
}
|
|
|
|
void GeneneralConf::initShowSidePanelButton()
|
|
{
|
|
m_sidePanelButton = new QCheckBox(tr("Show the side panel button"), this);
|
|
m_sidePanelButton->setChecked(ConfigHandler().showSidePanelButtonValue());
|
|
m_sidePanelButton->setToolTip(
|
|
tr("Show the side panel toggle button in the capture mode."));
|
|
m_layout->addWidget(m_sidePanelButton);
|
|
|
|
connect(m_sidePanelButton,
|
|
&QCheckBox::clicked,
|
|
this,
|
|
&GeneneralConf::showSidePanelButtonChanged);
|
|
}
|
|
void GeneneralConf::initShowDesktopNotification()
|
|
{
|
|
m_sysNotifications = new QCheckBox(tr("Show desktop notifications"), this);
|
|
ConfigHandler config;
|
|
bool checked = config.desktopNotificationValue();
|
|
m_sysNotifications->setChecked(checked);
|
|
m_sysNotifications->setToolTip(tr("Show desktop notifications"));
|
|
m_layout->addWidget(m_sysNotifications);
|
|
|
|
connect(m_sysNotifications,
|
|
&QCheckBox::clicked,
|
|
this,
|
|
&GeneneralConf::showDesktopNotificationChanged);
|
|
}
|
|
|
|
void GeneneralConf::initShowTrayIcon()
|
|
{
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
|
m_showTray = new QCheckBox(tr("Show tray icon"), this);
|
|
ConfigHandler config;
|
|
bool checked = !config.disabledTrayIconValue();
|
|
m_showTray->setChecked(checked);
|
|
m_showTray->setToolTip(tr("Show the systemtray icon"));
|
|
m_layout->addWidget(m_showTray);
|
|
|
|
connect(m_showTray,
|
|
&QCheckBox::stateChanged,
|
|
this,
|
|
&GeneneralConf::showTrayIconChanged);
|
|
#endif
|
|
}
|
|
|
|
void GeneneralConf::initConfingButtons()
|
|
{
|
|
QHBoxLayout* buttonLayout = new QHBoxLayout();
|
|
m_layout->addStretch();
|
|
QGroupBox* box = new QGroupBox(tr("Configuration File"));
|
|
box->setFlat(true);
|
|
box->setLayout(buttonLayout);
|
|
m_layout->addWidget(box);
|
|
|
|
m_exportButton = new QPushButton(tr("Export"));
|
|
buttonLayout->addWidget(m_exportButton);
|
|
connect(m_exportButton,
|
|
&QPushButton::clicked,
|
|
this,
|
|
&GeneneralConf::exportFileConfiguration);
|
|
|
|
m_importButton = new QPushButton(tr("Import"));
|
|
buttonLayout->addWidget(m_importButton);
|
|
connect(m_importButton,
|
|
&QPushButton::clicked,
|
|
this,
|
|
&GeneneralConf::importConfiguration);
|
|
|
|
m_resetButton = new QPushButton(tr("Reset"));
|
|
buttonLayout->addWidget(m_resetButton);
|
|
connect(m_resetButton,
|
|
&QPushButton::clicked,
|
|
this,
|
|
&GeneneralConf::resetConfiguration);
|
|
}
|
|
|
|
void GeneneralConf::initAutostart()
|
|
{
|
|
m_autostart = new QCheckBox(tr("Launch at startup"), this);
|
|
ConfigHandler config;
|
|
bool checked = config.startupLaunchValue();
|
|
m_autostart->setChecked(checked);
|
|
m_autostart->setToolTip(tr("Launch Flameshot"));
|
|
m_layout->addWidget(m_autostart);
|
|
|
|
connect(
|
|
m_autostart, &QCheckBox::clicked, this, &GeneneralConf::autostartChanged);
|
|
}
|
|
|
|
void GeneneralConf::initShowStartupLaunchMessage()
|
|
{
|
|
m_showStartupLaunchMessage =
|
|
new QCheckBox(tr("Show welcome message on launch"), this);
|
|
ConfigHandler config;
|
|
bool checked = config.showStartupLaunchMessage();
|
|
m_showStartupLaunchMessage->setChecked(checked);
|
|
m_showStartupLaunchMessage->setToolTip(tr("Launch Flameshot"));
|
|
m_layout->addWidget(m_showStartupLaunchMessage);
|
|
|
|
connect(m_showStartupLaunchMessage, &QCheckBox::clicked, [](bool checked) {
|
|
ConfigHandler().setShowStartupLaunchMessage(checked);
|
|
});
|
|
}
|
|
|
|
void GeneneralConf::initCloseAfterCapture()
|
|
{
|
|
m_closeAfterCapture =
|
|
new QCheckBox(tr("Close application after capture"), this);
|
|
ConfigHandler config;
|
|
bool checked = config.closeAfterScreenshotValue();
|
|
m_closeAfterCapture->setChecked(checked);
|
|
m_closeAfterCapture->setToolTip(tr("Close after taking a screenshot"));
|
|
m_layout->addWidget(m_closeAfterCapture);
|
|
|
|
connect(m_closeAfterCapture,
|
|
&QCheckBox::clicked,
|
|
this,
|
|
&GeneneralConf::closeAfterCaptureChanged);
|
|
}
|
|
|
|
void GeneneralConf::initCopyAndCloseAfterUpload()
|
|
{
|
|
m_copyAndCloseAfterUpload =
|
|
new QCheckBox(tr("Copy URL after upload"), this);
|
|
ConfigHandler config;
|
|
m_copyAndCloseAfterUpload->setChecked(
|
|
config.copyAndCloseAfterUploadEnabled());
|
|
m_copyAndCloseAfterUpload->setToolTip(
|
|
tr("Copy URL and close window after upload"));
|
|
m_layout->addWidget(m_copyAndCloseAfterUpload);
|
|
|
|
connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) {
|
|
ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked);
|
|
});
|
|
}
|
|
|
|
void GeneneralConf::initSaveAfterCopy()
|
|
{
|
|
m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this);
|
|
m_saveAfterCopy->setToolTip(tr("Save image file after copying it"));
|
|
m_layout->addWidget(m_saveAfterCopy);
|
|
connect(m_saveAfterCopy,
|
|
&QCheckBox::clicked,
|
|
this,
|
|
&GeneneralConf::saveAfterCopyChanged);
|
|
|
|
QHBoxLayout* pathLayout = new QHBoxLayout();
|
|
m_layout->addStretch();
|
|
QGroupBox* box = new QGroupBox(tr("Save Path"));
|
|
box->setFlat(true);
|
|
box->setLayout(pathLayout);
|
|
m_layout->addWidget(box);
|
|
|
|
m_savePath = new QLineEdit(
|
|
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), this);
|
|
m_savePath->setDisabled(true);
|
|
QString foreground = this->palette().foreground().color().name();
|
|
m_savePath->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
|
|
pathLayout->addWidget(m_savePath);
|
|
|
|
m_changeSaveButton = new QPushButton(tr("Change..."), this);
|
|
pathLayout->addWidget(m_changeSaveButton);
|
|
connect(m_changeSaveButton,
|
|
&QPushButton::clicked,
|
|
this,
|
|
&GeneneralConf::changeSavePath);
|
|
}
|
|
|
|
void GeneneralConf::saveAfterCopyChanged(bool checked)
|
|
{
|
|
ConfigHandler().setSaveAfterCopy(checked);
|
|
}
|
|
|
|
void GeneneralConf::changeSavePath()
|
|
{
|
|
QString path = QFileDialog::getExistingDirectory(
|
|
this,
|
|
tr("Choose a Folder"),
|
|
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation),
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
if (path.isEmpty()) {
|
|
return;
|
|
}
|
|
if (!QFileInfo(path).isWritable()) {
|
|
QMessageBox::about(
|
|
this, tr("Error"), tr("Unable to write to directory."));
|
|
return;
|
|
}
|
|
m_savePath->setText(path);
|
|
ConfigHandler().setSaveAfterCopyPath(path);
|
|
}
|
|
|
|
void GeneneralConf::initCopyPathAfterSave()
|
|
{
|
|
m_copyPathAfterSave = new QCheckBox(tr("Copy file path after save"), this);
|
|
ConfigHandler config;
|
|
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
|
|
m_copyPathAfterSave->setToolTip(tr("Copy file path after save"));
|
|
m_layout->addWidget(m_copyPathAfterSave);
|
|
connect(m_copyPathAfterSave, &QCheckBox::clicked, [](bool checked) {
|
|
ConfigHandler().setCopyPathAfterSaveEnabled(checked);
|
|
});
|
|
}
|
|
|
|
void GeneneralConf::initUploadStorage()
|
|
{
|
|
QGroupBox* groupBox = new QGroupBox(tr("Upload storage"));
|
|
|
|
// TODO - remove dependency injection (s3 & imgur)
|
|
// imgur
|
|
QRadioButton* storageImgUr = new QRadioButton(tr("Imgur storage"));
|
|
connect(storageImgUr, &QCheckBox::clicked, [](bool checked) {
|
|
ConfigHandler().setUploadStorage(SCREENSHOT_STORAGE_TYPE_IMGUR);
|
|
});
|
|
|
|
// s3
|
|
QRadioButton* storageImgS3 = new QRadioButton(
|
|
tr("S3 storage (require config.ini file with s3 credentials)"));
|
|
connect(storageImgS3, &QCheckBox::clicked, [](bool checked) {
|
|
ConfigHandler().setUploadStorage(SCREENSHOT_STORAGE_TYPE_S3);
|
|
});
|
|
|
|
// set current storage radiobutton active
|
|
if (ConfigHandler().uploadStorage() == SCREENSHOT_STORAGE_TYPE_IMGUR) {
|
|
storageImgUr->setChecked(true);
|
|
|
|
} else {
|
|
storageImgS3->setChecked(true);
|
|
}
|
|
|
|
// draw configuration options for uploadStorage
|
|
QVBoxLayout* vbox = new QVBoxLayout;
|
|
vbox->addWidget(storageImgUr);
|
|
vbox->addWidget(storageImgS3);
|
|
vbox->addStretch(1);
|
|
groupBox->setLayout(vbox);
|
|
m_layout->addWidget(groupBox);
|
|
}
|
|
|
|
void GeneneralConf::initFilePathConfiguration()
|
|
{
|
|
m_filePathConfiguration = new FilePathConfiguration();
|
|
m_layout->addWidget(m_filePathConfiguration);
|
|
}
|