mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 01:41:19 +00:00
* Fix empty help message bug Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add --region option Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix: initial selection even without --region * Enable 'full --region' Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Enable 'screen --region' Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow negative width/height Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix screen intersection bug Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Change output format of --print-geometry Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
95 lines
2.7 KiB
C++
95 lines
2.7 KiB
C++
// 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();
|
|
}
|
|
}
|