mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-02-04 01:28:07 +00:00
Introduce a config resolver (#2244)
* Add config resolver Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Enable resolver even when using systray Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bugs Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Do not show resolver for shortcut conflicts Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix build error on MacOS and Windows Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add missing translations Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Replace variable i with row Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Improve presentation Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Disambiguate shortcuts and general settings Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Wrap some strings in tr Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Update tooltips in ConfigResolver Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "abstractlogger.h"
|
||||
#include "pinwidget.h"
|
||||
#include "screenshotsaver.h"
|
||||
#include "src/config/configresolver.h"
|
||||
#include "src/config/configwindow.h"
|
||||
#include "src/core/qguiappcurrentscreen.h"
|
||||
#include "src/tools/imgupload/imguploadermanager.h"
|
||||
@@ -133,6 +134,16 @@ void Controller::setCheckForUpdatesEnabled(const bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::setOrigin(Origin origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
Controller::Origin Controller::origin()
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
void Controller::getLatestAvailableVersion()
|
||||
{
|
||||
// This features is required for MacOS and Windows user and for Linux users
|
||||
@@ -153,6 +164,38 @@ void Controller::getLatestAvailableVersion()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prompt the user to resolve config errors if necessary.
|
||||
* @return Whether errors were resolved.
|
||||
*/
|
||||
bool Controller::resolveAnyConfigErrors()
|
||||
{
|
||||
bool resolved = true;
|
||||
ConfigHandler config;
|
||||
if (!config.checkUnrecognizedSettings() || !config.checkSemantics()) {
|
||||
ConfigResolver* resolver = new ConfigResolver();
|
||||
QObject::connect(
|
||||
resolver, &ConfigResolver::rejected, [this, resolver, &resolved]() {
|
||||
resolved = false;
|
||||
resolver->deleteLater();
|
||||
if (origin() == CLI) {
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
QObject::connect(
|
||||
resolver, &ConfigResolver::accepted, [resolver, &resolved]() {
|
||||
resolved = true;
|
||||
resolver->close();
|
||||
resolver->deleteLater();
|
||||
// Ensure that the dialog is closed before starting capture
|
||||
qApp->processEvents();
|
||||
});
|
||||
resolver->exec();
|
||||
qApp->processEvents();
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
void Controller::handleReplyCheckUpdates(QNetworkReply* reply)
|
||||
{
|
||||
if (!ConfigHandler().checkForUpdates()) {
|
||||
@@ -207,6 +250,9 @@ void Controller::appUpdates()
|
||||
|
||||
void Controller::requestCapture(const CaptureRequest& request)
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
switch (request.captureMode()) {
|
||||
case CaptureRequest::FULLSCREEN_MODE:
|
||||
doLater(request.delay(), this, [this, request]() {
|
||||
@@ -235,6 +281,9 @@ void Controller::requestCapture(const CaptureRequest& request)
|
||||
// creation of a new capture in GUI mode
|
||||
void Controller::startVisualCapture(const CaptureRequest& req)
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
// This is required on MacOS because of Mission Control. If you'll switch to
|
||||
// another Desktop you cannot take a new screenshot from the tray, you have
|
||||
@@ -295,6 +344,9 @@ void Controller::startVisualCapture(const CaptureRequest& req)
|
||||
|
||||
void Controller::startScreenGrab(CaptureRequest req, const int screenNumber)
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
bool ok = true;
|
||||
QScreen* screen;
|
||||
|
||||
@@ -334,6 +386,9 @@ void Controller::startScreenGrab(CaptureRequest req, const int screenNumber)
|
||||
// creation of the configuration window
|
||||
void Controller::openConfigWindow()
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
if (!m_configWindow) {
|
||||
m_configWindow = new ConfigWindow();
|
||||
m_configWindow->show();
|
||||
@@ -358,6 +413,9 @@ void Controller::openInfoWindow()
|
||||
|
||||
void Controller::openLauncherWindow()
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
if (!m_launcherWindow) {
|
||||
m_launcherWindow = new CaptureLauncher();
|
||||
}
|
||||
@@ -629,6 +687,9 @@ void Controller::exportCapture(QPixmap capture,
|
||||
|
||||
void Controller::startFullscreenCapture(const CaptureRequest& req)
|
||||
{
|
||||
if (!resolveAnyConfigErrors())
|
||||
return;
|
||||
|
||||
bool ok = true;
|
||||
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
|
||||
QRect region = req.initialSelection();
|
||||
@@ -665,3 +726,6 @@ void Controller::doLater(int msec, QObject* receiver, lambda func)
|
||||
timer->setInterval(msec);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
// STATIC ATTRIBUTES
|
||||
Controller::Origin Controller::m_origin = Controller::DAEMON;
|
||||
|
||||
Reference in New Issue
Block a user