Add --raw flag

Updated dbus API. Now it sends a signal with every capture, it may
be captureFailed or a captureTaken which contains the raw image
bytes in png format. You have to add an id to the screenshot calls
so it will be returned as a way to know the origin of the signal.
This commit is contained in:
lupoDharkael
2017-11-09 18:14:04 +01:00
parent 567c99a75e
commit bb6ac04d60
16 changed files with 362 additions and 49 deletions

View File

@@ -61,9 +61,13 @@ void Controller::initDefaults() {
}
// creation of a new capture in GUI mode
void Controller::createVisualCapture(const QString &forcedSavePath) {
void Controller::createVisualCapture(const uint id, const QString &forcedSavePath) {
if (!m_captureWindow) {
m_captureWindow = new CaptureWidget(forcedSavePath);
m_captureWindow = new CaptureWidget(id, forcedSavePath);
connect(m_captureWindow, &CaptureWidget::captureFailed,
this, &Controller::captureFailed);
connect(m_captureWindow, &CaptureWidget::captureTaken,
this, &Controller::captureTaken);
m_captureWindow->showFullScreen();
}
}

View File

@@ -20,6 +20,7 @@
#include <QObject>
#include <QPointer>
#include <QPixmap>
class CaptureWidget;
class ConfigWindow;
@@ -35,8 +36,13 @@ public:
Controller(const Controller&) = delete;
void operator =(const Controller&) = delete;
signals:
void captureTaken(uint id, QByteArray p);
void captureFailed(uint id);
public slots:
void createVisualCapture(const QString &forcedSavePath = QString());
void createVisualCapture(const uint id = 0,
const QString &forcedSavePath = QString());
void openConfigWindow();
void openInfoWindow();

View File

@@ -22,6 +22,7 @@
#include "src/core/resourceexporter.h"
#include <QTimer>
#include <functional>
#include <QBuffer>
namespace {
using std::function;
@@ -41,33 +42,53 @@ namespace {
FlameshotDBusAdapter::FlameshotDBusAdapter(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
auto controller = Controller::getInstance();
connect(controller, &Controller::captureFailed,
this, &FlameshotDBusAdapter::captureFailed);
connect(controller, &Controller::captureTaken,
this, &FlameshotDBusAdapter::captureTaken);
}
FlameshotDBusAdapter::~FlameshotDBusAdapter() {
}
void FlameshotDBusAdapter::graphicCapture(QString path, int delay) {
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id) {
auto controller = Controller::getInstance();
auto f = [controller, path, this]() {
controller->createVisualCapture(path);
auto f = [controller, id, path, this]() {
controller->createVisualCapture(id, path);
};
// QTimer::singleShot(delay, controller, f); // requires Qt 5.4
doLater(delay, controller, f);
}
void FlameshotDBusAdapter::fullScreen(QString path, bool toClipboard, int delay) {
auto f = [path, toClipboard, this]() {
QPixmap p(ScreenGrabber().grabEntireDesktop());
void FlameshotDBusAdapter::fullScreen(
QString path, bool toClipboard, int delay, uint id)
{
auto f = [id, path, toClipboard, this]() {
bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (!ok) {
// TODO notify
Q_EMIT captureFailed(id);
return;
}
if (!toClipboard && path.isEmpty()) {
ResourceExporter().captureToFileUi(p);
goto emit_signal;
}
if(toClipboard) {
ResourceExporter().captureToClipboard(p);
}
if(path.isEmpty()) {
ResourceExporter().captureToFileUi(p);
} else {
if(!path.isEmpty()) {
ResourceExporter().captureToFile(p, path);
}
emit_signal:
QByteArray byteArray;
QBuffer buffer(&byteArray);
p.save(&buffer, "PNG");
Q_EMIT captureTaken(id, byteArray);
};
//QTimer::singleShot(delay, this, f); // // requires Qt 5.4
doLater(delay, this, f);

View File

@@ -30,9 +30,13 @@ public:
FlameshotDBusAdapter(QObject *parent = nullptr);
virtual ~FlameshotDBusAdapter();
signals:
void captureTaken(uint id, QByteArray rawImage);
void captureFailed(uint id);
public slots:
Q_NOREPLY void graphicCapture(QString path, int delay);
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay);
Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id);
Q_NOREPLY void openConfig();
Q_NOREPLY void trayIconEnabled(bool enabled);