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

@@ -48,8 +48,8 @@
// an area of selection with its respective buttons.
// enableSaveWindow
CaptureWidget::CaptureWidget(uint id,
const QString& savePath,
CaptureWidget::CaptureWidget(const CaptureRequest& req,
bool fullScreen,
QWidget* parent)
: QWidget(parent)
@@ -90,7 +90,7 @@ CaptureWidget::CaptureWidget(uint id,
m_uiColor = m_config.uiColor();
m_contrastUiColor = m_config.contrastUiColor();
setMouseTracking(true);
initContext(fullScreen, id);
initContext(fullScreen, req);
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
// Top left of the whole set of screens
QPoint topLeft(0, 0);
@@ -251,9 +251,12 @@ CaptureWidget::~CaptureWidget()
}
#endif
if (m_captureDone) {
emit captureTaken(m_context.requestId, pixmap(), m_context.selection);
QRect geometry(m_context.selection);
geometry.setTopLeft(geometry.topLeft() + m_context.widgetOffset);
Controller::getInstance()->exportCapture(
pixmap(), geometry, m_context.request);
} else {
emit captureFailed(m_context.requestId);
Controller::getInstance()->handleCaptureFailed();
}
}
@@ -261,7 +264,7 @@ void CaptureWidget::initButtons()
{
auto allButtonTypes = CaptureToolButton::getIterableButtonTypes();
auto visibleButtonTypes = m_config.buttons();
if (m_context.request()->tasks() == CaptureRequest::NO_TASK) {
if (m_context.request.tasks() == CaptureRequest::NO_TASK) {
allButtonTypes.removeOne(CaptureTool::TYPE_ACCEPT);
visibleButtonTypes.removeOne(CaptureTool::TYPE_ACCEPT);
} else {
@@ -891,7 +894,7 @@ void CaptureWidget::changeEvent(QEvent* e)
}
}
void CaptureWidget::initContext(bool fullscreen, uint requestId)
void CaptureWidget::initContext(bool fullscreen, const CaptureRequest& req)
{
m_context.color = m_config.drawColor();
m_context.widgetOffset = mapToGlobal(QPoint(0, 0));
@@ -900,15 +903,7 @@ void CaptureWidget::initContext(bool fullscreen, uint requestId)
m_context.fullscreen = fullscreen;
// initialize m_context.request
if (requestId != 0) {
m_context.requestId = requestId;
} else {
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE);
uint id = req.id();
req.setStaticID(id);
Controller::getInstance()->requests().insert(id, req);
m_context.requestId = id;
}
m_context.request = req;
}
void CaptureWidget::initPanel()
@@ -1040,7 +1035,7 @@ void CaptureWidget::initSelection()
{
// Be mindful of the order of statements, so that slots are called properly
m_selection = new SelectionWidget(m_uiColor, this);
QRect initialSelection = m_context.request()->initialSelection();
QRect initialSelection = m_context.request.initialSelection();
connect(m_selection, &SelectionWidget::geometryChanged, this, [this]() {
QRect constrainedToCaptureArea =
m_selection->geometry().intersected(rect());
@@ -1052,16 +1047,10 @@ void CaptureWidget::initSelection()
});
connect(m_selection, &SelectionWidget::geometrySettled, this, [this]() {
if (m_selection->isVisibleTo(this)) {
auto req = m_context.request();
if (req->tasks() & CaptureRequest::ACCEPT_ON_SELECT) {
req->removeTask(CaptureRequest::ACCEPT_ON_SELECT);
auto& req = m_context.request;
if (req.tasks() & CaptureRequest::ACCEPT_ON_SELECT) {
req.removeTask(CaptureRequest::ACCEPT_ON_SELECT);
m_captureDone = true;
if (req->tasks() & CaptureRequest::PIN) {
QRect geometry = m_context.selection;
geometry.setTopLeft(geometry.topLeft() +
m_context.widgetOffset);
req->addPinTask(geometry);
}
close();
}
m_buttonHandler->updatePosition(m_selection->geometry());

View File

@@ -41,8 +41,7 @@ class CaptureWidget : public QWidget
Q_OBJECT
public:
explicit CaptureWidget(uint id = 0,
const QString& savePath = QString(),
explicit CaptureWidget(const CaptureRequest& req,
bool fullScreen = true,
QWidget* parent = nullptr);
~CaptureWidget();
@@ -57,8 +56,6 @@ public slots:
void deleteToolWidgetOrClose();
signals:
void captureTaken(uint id, const QPixmap& capture, const QRect& selection);
void captureFailed(uint id);
void colorChanged(const QColor& c);
void toolSizeChanged(int size);
@@ -105,7 +102,7 @@ private:
void showColorPicker(const QPoint& pos);
bool startDrawObjectTool(const QPoint& pos);
QPointer<CaptureTool> activeToolObject();
void initContext(bool fullscreen, uint requestId);
void initContext(bool fullscreen, const CaptureRequest& req);
void initPanel();
void initSelection();
void initShortcuts();

View File

@@ -21,7 +21,6 @@
CaptureLauncher::CaptureLauncher(QDialog* parent)
: QDialog(parent)
, m_id(0)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowIcon(QIcon(GlobalValues::iconPath()));
@@ -108,7 +107,6 @@ void CaptureLauncher::startCapture()
auto mode = static_cast<CaptureRequest::CaptureMode>(
m_captureType->currentData().toInt());
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
m_id = req.id();
connectCaptureSlots();
Controller::getInstance()->requestCapture(req);
}
@@ -166,16 +164,13 @@ void CaptureLauncher::disconnectCaptureSlots()
&CaptureLauncher::captureFailed);
}
void CaptureLauncher::captureTaken(uint id, QPixmap p, const QRect& selection)
void CaptureLauncher::captureTaken(QPixmap p, const QRect&)
{
// MacOS specific, more details in the function disconnectCaptureSlots()
disconnectCaptureSlots();
if (id == m_id) {
m_id = 0;
m_imageLabel->setScreenshot(p);
show();
}
m_imageLabel->setScreenshot(p);
show();
auto mode = static_cast<CaptureRequest::CaptureMode>(
m_captureType->currentData().toInt());
@@ -186,14 +181,10 @@ void CaptureLauncher::captureTaken(uint id, QPixmap p, const QRect& selection)
m_launchButton->setEnabled(true);
}
void CaptureLauncher::captureFailed(uint id)
void CaptureLauncher::captureFailed()
{
// MacOS specific, more details in the function disconnectCaptureSlots()
disconnectCaptureSlots();
if (id == m_id) {
m_id = 0;
show();
}
show();
m_launchButton->setEnabled(true);
}

View File

@@ -26,8 +26,8 @@ private:
private slots:
void startCapture();
void startDrag();
void captureTaken(uint id, QPixmap p, const QRect& selection);
void captureFailed(uint id);
void captureTaken(QPixmap p, const QRect& selection);
void captureFailed();
private:
QSpinBox* m_delaySpinBox;
@@ -36,5 +36,4 @@ private:
QPushButton* m_launchButton;
QLabel* m_CaptureModeLabel;
ImageLabel* m_imageLabel;
uint m_id;
};

View File

@@ -1,11 +1,10 @@
#include "historywidget.h"
#include "src/core/flameshotdaemon.h"
#include "src/tools/imgupload/imguploadermanager.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include "src/utils/history.h"
#include "src/widgets/notificationwidget.h"
#include <QApplication>
#include <QClipboard>
#include <QDateTime>
#include <QDesktopServices>
#include <QDesktopWidget>
@@ -143,7 +142,7 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
buttonCopyUrl->setText(tr("Copy URL"));
buttonCopyUrl->setMinimumHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
connect(buttonCopyUrl, &QPushButton::clicked, this, [=]() {
QApplication::clipboard()->setText(url);
FlameshotDaemon::copyToClipboard(url);
m_notification->showMessage(tr("URL copied to clipboard."));
this->close();
});

View File

@@ -2,10 +2,8 @@
#define HISTORYWIDGET_H
#include <QDialog>
#include <QObject>
#include <QString>
#include <QWidget>
class QString;
class QLayout;
class QVBoxLayout;
class NotificationWidget;

View File

@@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#include "infowindow.h"
#include "src/core/flameshotdaemon.h"
#include "src/core/qguiappcurrentscreen.h"
#include "src/utils/globalvalues.h"
#include <QApplication>
@@ -88,9 +89,8 @@ void InfoWindow::initLabels()
void InfoWindow::copyInfo()
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(GlobalValues::versionInfo() + "\n" +
generateKernelString());
FlameshotDaemon::copyToClipboard(GlobalValues::versionInfo() + "\n" +
generateKernelString());
}
void InfoWindow::keyPressEvent(QKeyEvent* e)