Emit dbus captureSaved signal when saving files

New captureSaved signal contains the request ID and canonical path of the saved
file. This allows a dbus listener interested in postprocessing files access to
the path most recently written.
This commit is contained in:
brimston3
2021-01-14 18:45:00 -05:00
committed by borgmanJeremy
parent 635c2a3eef
commit e07829ec55
8 changed files with 42 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "screenshotsaver.h"
#include "src/core/controller.h"
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/systemnotification.h"
@@ -25,7 +26,13 @@
#include <QImageWriter>
#include <QMessageBox>
ScreenshotSaver::ScreenshotSaver() {}
ScreenshotSaver::ScreenshotSaver()
: m_id(0)
{}
ScreenshotSaver::ScreenshotSaver(const unsigned id)
: m_id(id)
{}
// TODO: If data is saved to the clipboard before the notification is sent via
// dbus, the application freezes.
@@ -63,6 +70,12 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
ConfigHandler().setSavePath(path);
saveMessage =
messagePrefix + QObject::tr("Capture saved as ") + completePath;
QString fileNoPath =
completePath.right(completePath.lastIndexOf(QLatin1String("/")));
Controller::getInstance()->sendCaptureSaved(
m_id,
QFileInfo(completePath).canonicalPath() + QLatin1String("/") +
fileNoPath);
} else {
saveMessage = messagePrefix + QObject::tr("Error trying to save as ") +
completePath;
@@ -103,6 +116,8 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
if (ok) {
QString pathNoFile =
savePath.left(savePath.lastIndexOf(QLatin1String("/")));
QString fileNoPath =
savePath.right(savePath.lastIndexOf(QLatin1String("/")));
ConfigHandler().setSavePath(pathNoFile);
QString msg = QObject::tr("Capture saved as ") + savePath;
if (config.copyPathAfterSaveEnabled()) {
@@ -112,6 +127,10 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
savePath;
}
SystemNotification().sendMessage(msg, savePath);
Controller::getInstance()->sendCaptureSaved(
m_id,
QFileInfo(savePath).canonicalPath() + QLatin1String("/") +
fileNoPath);
} else {
QString msg = QObject::tr("Error trying to save as ") + savePath;
QMessageBox saveErrBox(