* Handle captures without sigslots Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Set {app,organization}Name and version consistently Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make 'full' dbus-free Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move CaptureRequest::exportCapture to Controller We need to wait until the upload widget (or similar widgets) have finished before exiting. This must be done using a signal. The problem is that CaptureRequest can't be guaranteed to survive until the widget has finished what it's doing. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Use QApplication with the 'full' subcommand Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Do unto 'screen' as we did to 'full' Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add FlameshotDaemon singleton class Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Support clipboard hosting for both pixmaps and text * Fix upload handling Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Do not show tray icon if not daemon Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Clean up handling of pin task Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove annoying Qt warning messages The messages were caused by the color wheel. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix small bug in Controller::exportCapture * Fix --raw output * Make 'gui' dbus-independent Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix accept on select bug Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix compile error on Windows Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make it work on Windows * Remove obsolete function in main.cpp Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make 'launcher' work without dbus Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * clang-format, sigh Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Enable CLI parsing on MacOS Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make 'config' work without dbus Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Small refactor of capture request handling Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove obsolete DBusUtils Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove unused D-Bus sigslots Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove D-Bus methods openConfig, autostartEnabled and trayIconEnabled Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove D-Bus method requestCapture Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove CaptureRequest id mechanism Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix 'launcher' crash Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Handle clipboard notifications properly Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add 'autoCloseIdleDaemon' option Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Document FlameshotDaemon class Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make 'flameshot gui' run in single-application mode Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add `allowmultipleGuiInstances` config option Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix endless loop with multiple GUI instances Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move upload confirmation dialog where it belongs Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add the new config options to the GUI as well Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build on Windows Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Handle persistence on MacOS Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * fixed notifications on macos * Fixed display on macos * Reformat tests/action_options.sh Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix infinite recursion in tests/action_options.sh Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> Co-authored-by: Dearsh Oberoi <59907159+deo002@users.noreply.github.com> Co-authored-by: Jeremy Borgman <borgman.jeremy@pm.me>
164 lines
6.8 KiB
C++
164 lines
6.8 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
|
|
|
|
#pragma once
|
|
|
|
#include "src/widgets/capture/capturetoolbutton.h"
|
|
#include <QSettings>
|
|
#include <QStringList>
|
|
#include <QVariant>
|
|
#include <QVector>
|
|
|
|
class QFileSystemWatcher;
|
|
class ValueHandler;
|
|
template<class T>
|
|
class QSharedPointer;
|
|
class QTextStream;
|
|
|
|
/**
|
|
* Declare and implement a getter for a config option. `KEY` is the option key
|
|
* as it appears in the config file, `TYPE` is the C++ type. At the same time
|
|
* `KEY` is the name of the generated getter function.
|
|
*/
|
|
#define CONFIG_GETTER(KEY, TYPE) \
|
|
TYPE KEY() { return value(QStringLiteral(#KEY)).value<TYPE>(); }
|
|
|
|
/**
|
|
* Declare and implement a setter for a config option. `FUNC` is the name of the
|
|
* generated function, `KEY` is the option key as it appears in the config file
|
|
* and `TYPE` is the C++ type.
|
|
*/
|
|
#define CONFIG_SETTER(FUNC, KEY, TYPE) \
|
|
void FUNC(const TYPE& val) \
|
|
{ \
|
|
QString key = QStringLiteral(#KEY); \
|
|
/* Without this check, multiple `flameshot gui` instances running */ \
|
|
/* simultaneously would cause an endless loop of fileWatcher calls */ \
|
|
if (QVariant::fromValue(val) != value(key)) { \
|
|
setValue(key, QVariant::fromValue(val)); \
|
|
} \
|
|
}
|
|
|
|
/**
|
|
* Combines the functionality of `CONFIG_GETTER` and `CONFIG_SETTER`. `GETFUNC`
|
|
* is simultaneously the name of the getter function and the option key as it
|
|
* appears in the config file. `SETFUNC` is the name of the setter function.
|
|
* `TYPE` is the C++ type of the value.
|
|
*/
|
|
#define CONFIG_GETTER_SETTER(GETFUNC, SETFUNC, TYPE) \
|
|
CONFIG_GETTER(GETFUNC, TYPE) \
|
|
CONFIG_SETTER(SETFUNC, GETFUNC, TYPE)
|
|
|
|
class ConfigHandler : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ConfigHandler(bool skipInitialErrorCheck = false);
|
|
|
|
static ConfigHandler* getInstance();
|
|
|
|
// Definitions of getters and setters for config options
|
|
// Some special cases are implemented regularly, without the macro
|
|
// NOTE: When adding new options, make sure to add an entry in
|
|
// recognizedGeneralOptions in the cpp file.
|
|
CONFIG_GETTER_SETTER(userColors, setUserColors, QVector<QColor>);
|
|
CONFIG_GETTER_SETTER(savePath, setSavePath, QString)
|
|
CONFIG_GETTER_SETTER(savePathFixed, setSavePathFixed, bool)
|
|
CONFIG_GETTER_SETTER(uiColor, setUiColor, QColor)
|
|
CONFIG_GETTER_SETTER(contrastUiColor, setContrastUiColor, QColor)
|
|
CONFIG_GETTER_SETTER(drawColor, setDrawColor, QColor)
|
|
CONFIG_GETTER_SETTER(fontFamily, setFontFamily, QString)
|
|
CONFIG_GETTER_SETTER(showHelp, setShowHelp, bool)
|
|
CONFIG_GETTER_SETTER(showSidePanelButton, setShowSidePanelButton, bool)
|
|
CONFIG_GETTER_SETTER(showDesktopNotification,
|
|
setShowDesktopNotification,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(filenamePattern, setFilenamePattern, QString)
|
|
CONFIG_GETTER_SETTER(disabledTrayIcon, setDisabledTrayIcon, bool)
|
|
CONFIG_GETTER_SETTER(drawThickness, setDrawThickness, int)
|
|
CONFIG_GETTER_SETTER(drawFontSize, setDrawFontSize, int)
|
|
CONFIG_GETTER_SETTER(keepOpenAppLauncher, setKeepOpenAppLauncher, bool)
|
|
CONFIG_GETTER_SETTER(checkForUpdates, setCheckForUpdates, bool)
|
|
CONFIG_GETTER_SETTER(allowMultipleGuiInstances,
|
|
setAllowMultipleGuiInstances,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(autoCloseIdleDaemon, setAutoCloseIdleDaemon, bool)
|
|
CONFIG_GETTER_SETTER(showStartupLaunchMessage,
|
|
setShowStartupLaunchMessage,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(contrastOpacity, setContrastOpacity, int)
|
|
CONFIG_GETTER_SETTER(copyAndCloseAfterUpload,
|
|
setCopyAndCloseAfterUpload,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(historyConfirmationToDelete,
|
|
setHistoryConfirmationToDelete,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(uploadHistoryMax, setUploadHistoryMax, int)
|
|
CONFIG_GETTER_SETTER(saveAfterCopy, setSaveAfterCopy, bool)
|
|
CONFIG_GETTER_SETTER(copyPathAfterSave, setCopyPathAfterSave, bool)
|
|
CONFIG_GETTER_SETTER(setSaveAsFileExtension,
|
|
setSaveAsFileExtension,
|
|
QString)
|
|
CONFIG_GETTER_SETTER(antialiasingPinZoom, setAntialiasingPinZoom, bool)
|
|
CONFIG_GETTER_SETTER(useJpgForClipboard, setUseJpgForClipboard, bool)
|
|
CONFIG_GETTER_SETTER(uploadWithoutConfirmation,
|
|
setUploadWithoutConfirmation,
|
|
bool)
|
|
CONFIG_GETTER_SETTER(ignoreUpdateToVersion,
|
|
setIgnoreUpdateToVersion,
|
|
QString)
|
|
CONFIG_GETTER_SETTER(undoLimit, setUndoLimit, int)
|
|
CONFIG_GETTER_SETTER(buttons, setButtons, QList<CaptureTool::Type>)
|
|
|
|
// SPECIAL CASES
|
|
bool startupLaunch();
|
|
void setStartupLaunch(const bool);
|
|
void setAllTheButtons();
|
|
void setToolSize(CaptureTool::Type toolType, int size);
|
|
int toolSize(CaptureTool::Type toolType);
|
|
|
|
// DEFAULTS
|
|
QString filenamePatternDefault();
|
|
void setDefaultSettings();
|
|
QString configFilePath() const;
|
|
|
|
// GENERIC GETTERS AND SETTERS
|
|
bool setShortcut(const QString& actionName, const QString& shortcut);
|
|
QString shortcut(const QString& actionName);
|
|
void setValue(const QString& key, const QVariant& value);
|
|
QVariant value(const QString& key) const;
|
|
|
|
// INFO
|
|
static QSet<QString>& recognizedGeneralOptions();
|
|
static QSet<QString>& recognizedShortcutNames();
|
|
QSet<QString> keysFromGroup(const QString& group) const;
|
|
|
|
// ERROR HANDLING
|
|
bool checkForErrors(QTextStream* log = nullptr) const;
|
|
bool checkUnrecognizedSettings(QTextStream* log = nullptr) const;
|
|
bool checkShortcutConflicts(QTextStream* log = nullptr) const;
|
|
bool checkSemantics(QTextStream* log = nullptr) const;
|
|
void checkAndHandleError() const;
|
|
void setErrorState(bool error) const;
|
|
bool hasError() const;
|
|
QString errorMessage() const;
|
|
|
|
signals:
|
|
void error() const;
|
|
void errorResolved() const;
|
|
void fileChanged() const;
|
|
|
|
private:
|
|
mutable QSettings m_settings;
|
|
|
|
static bool m_hasError, m_errorCheckPending, m_skipNextErrorCheck;
|
|
static QSharedPointer<QFileSystemWatcher> m_configWatcher;
|
|
|
|
void ensureFileWatched() const;
|
|
QSharedPointer<ValueHandler> valueHandler(const QString& key) const;
|
|
void assertKeyRecognized(const QString& key) const;
|
|
bool isShortcut(const QString& key) const;
|
|
QString baseName(QString key) const;
|
|
};
|