Reduce dependence on D-Bus (#2003)

* 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>
This commit is contained in:
Haris Gušić
2021-12-08 22:18:39 +01:00
committed by GitHub
parent 203b5baab6
commit 233c765b1f
38 changed files with 768 additions and 766 deletions

View File

@@ -1,8 +1,7 @@
# Required to generate MOC
target_sources(
flameshot
PRIVATE dbusutils.h
filenamehandler.h
PRIVATE filenamehandler.h
screengrabber.h
systemnotification.h
valuehandler.h
@@ -18,7 +17,6 @@ target_sources(
systemnotification.cpp
valuehandler.cpp
screenshotsaver.cpp
dbusutils.cpp
globalvalues.cpp
desktopfileparse.cpp
desktopinfo.cpp

View File

@@ -81,6 +81,10 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
OPTION("disabledTrayIcon" ,Bool ( false )),
OPTION("historyConfirmationToDelete" ,Bool ( true )),
OPTION("checkForUpdates" ,Bool ( true )),
OPTION("allowMultipleGuiInstances" ,Bool ( false )),
#if !defined(Q_OS_WIN)
OPTION("autoCloseIdleDaemon" ,Bool ( false )),
#endif
#if defined(Q_OS_MACOS)
OPTION("startupLaunch" ,Bool ( false )),
#else

View File

@@ -29,9 +29,14 @@ class QTextStream;
* and `TYPE` is the C++ type.
*/
#define CONFIG_SETTER(FUNC, KEY, TYPE) \
void FUNC(const TYPE& value) \
void FUNC(const TYPE& val) \
{ \
setValue(QStringLiteral(#KEY), QVariant::fromValue(value)); \
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)); \
} \
}
/**
@@ -75,6 +80,10 @@ public:
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)

View File

@@ -1,94 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#include "dbusutils.h"
#include "src/utils/systemnotification.h"
#include <QApplication>
#include <QFile>
#include <QRect>
#include <QTextStream>
DBusUtils::DBusUtils(QObject* parent)
: QObject(parent)
{}
void DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
{
m_id = id;
// captureTaken
session.connect(QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"),
QLatin1String(""),
QStringLiteral("captureTaken"),
this,
SLOT(captureTaken(uint, QByteArray, QRect)));
// captureFailed
session.connect(QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"),
QLatin1String(""),
QStringLiteral("captureFailed"),
this,
SLOT(captureFailed(uint)));
}
void DBusUtils::connectSelectionCapture(QDBusConnection& session, uint id)
{
m_id = id;
// captureTaken
session.connect(QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"),
QLatin1String(""),
QStringLiteral("captureTaken"),
this,
SLOT(selectionTaken(uint, QByteArray, QRect)));
// captureFailed
session.connect(QStringLiteral("org.flameshot.Flameshot"),
QStringLiteral("/"),
QLatin1String(""),
QStringLiteral("captureFailed"),
this,
SLOT(captureFailed(uint)));
}
void DBusUtils::checkDBusConnection(const QDBusConnection& connection)
{
if (!connection.isConnected()) {
SystemNotification().sendMessage(tr("Unable to connect via DBus"));
qApp->exit(1);
}
}
void DBusUtils::captureTaken(uint id, QByteArray rawImage, QRect selection)
{
if (m_id == id) {
QFile file;
file.open(stdout, QIODevice::WriteOnly);
file.write(rawImage);
file.close();
qApp->exit();
}
}
void DBusUtils::captureFailed(uint id)
{
if (m_id == id) {
QTextStream(stdout) << "screenshot aborted\n";
qApp->exit(1);
}
}
void DBusUtils::selectionTaken(uint id, QByteArray rawImage, QRect selection)
{
if (m_id == id) {
QFile file;
file.open(stdout, QIODevice::WriteOnly);
QTextStream out(&file);
// TODO also make this change in D-Bus refactor branch
out << selection.width() << "x" << selection.height() << "+"
<< selection.x() << "+" << selection.y() << "\n";
file.close();
qApp->exit();
}
}

View File

@@ -1,27 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#pragma once
#include "src/cli/commandlineparser.h"
#include <QDBusConnection>
#include <QObject>
class DBusUtils : public QObject
{
Q_OBJECT
public:
explicit DBusUtils(QObject* parent = nullptr);
void connectPrintCapture(QDBusConnection& session, uint id);
void checkDBusConnection(const QDBusConnection& connection);
void connectSelectionCapture(QDBusConnection& session, uint id);
public slots:
void selectionTaken(uint id, QByteArray rawImage, QRect selection);
void captureTaken(uint id, QByteArray rawImage, QRect selection);
void captureFailed(uint id);
private:
uint m_id;
};

View File

@@ -3,6 +3,7 @@
#include "screenshotsaver.h"
#include "src/core/controller.h"
#include "src/core/flameshotdaemon.h"
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/globalvalues.h"
@@ -22,13 +23,7 @@
#include "src/widgets/capture/capturewidget.h"
#endif
ScreenshotSaver::ScreenshotSaver()
: m_id(0)
{}
ScreenshotSaver::ScreenshotSaver(const unsigned id)
: m_id(id)
{}
ScreenshotSaver::ScreenshotSaver() {}
void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture,
const QString& imageType)
@@ -102,8 +97,6 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
if (ok) {
saveMessage += QObject::tr("Capture saved as ") + completePath;
Controller::getInstance()->sendCaptureSaved(
m_id, QFileInfo(completePath).canonicalFilePath());
} else {
saveMessage += QObject::tr("Error trying to save as ") + completePath;
if (file.error() != QFile::NoError) {
@@ -192,20 +185,11 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
ConfigHandler().setSavePath(pathNoFile);
QString msg = QObject::tr("Capture saved as ") + savePath;
if (config.copyPathAfterSave()) {
msg =
QObject::tr("Capture is saved and copied to the clipboard as ") +
savePath;
}
SystemNotification().sendMessage(msg, savePath);
Controller::getInstance()->sendCaptureSaved(
m_id, QFileInfo(savePath).canonicalFilePath());
if (config.copyPathAfterSave()) {
QApplication::clipboard()->setText(savePath);
FlameshotDaemon::copyToClipboard(
savePath, QObject::tr("Path copied to clipboard as ") + savePath);
}
} else {

View File

@@ -12,7 +12,6 @@ class ScreenshotSaver
{
public:
ScreenshotSaver();
ScreenshotSaver(const unsigned id);
void saveToClipboard(const QPixmap& capture);
void saveToClipboardMime(const QPixmap& capture, const QString& imageType);
@@ -22,7 +21,6 @@ public:
bool saveToFilesystemGUI(const QPixmap& capture);
private:
unsigned m_id;
QString ShowSaveFileDialog(QWidget* parent,
const QString& title,
const QString& directory);

View File

@@ -4,7 +4,7 @@
#include <QApplication>
#include <QUrl>
#if not(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
#if !(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusMessage>
@@ -14,7 +14,7 @@ SystemNotification::SystemNotification(QObject* parent)
: QObject(parent)
, m_interface(nullptr)
{
#if not(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
#if !(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
m_interface =
new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
QStringLiteral("/org/freedesktop/Notifications"),