Fixed it so a notification is always sent when saved to clipboard

This commit is contained in:
Jeremy Borgman
2020-09-10 09:50:24 -05:00
parent 72f52ac3ed
commit 9bc4ea5700
5 changed files with 26 additions and 14 deletions

View File

@@ -95,7 +95,7 @@ CaptureRequest::exportCapture(const QPixmap& p)
if (m_path.isEmpty()) {
ScreenshotSaver().saveToFilesystemGUI(p);
} else {
ScreenshotSaver().saveToFilesystem(p, m_path);
ScreenshotSaver().saveToFilesystem(p, m_path, "");
}
}

View File

@@ -71,7 +71,7 @@ SaveTool::pressed(const CaptureContext& context)
}
} else {
bool ok = ScreenshotSaver().saveToFilesystem(
context.selectedScreenshotArea(), context.savePath);
context.selectedScreenshotArea(), context.savePath, "");
if (ok) {
emit requestAction(REQ_CAPTURE_DONE_OK);
}

View File

@@ -30,19 +30,27 @@ ScreenshotSaver::ScreenshotSaver() {}
void
ScreenshotSaver::saveToClipboard(const QPixmap& capture)
{
if (ConfigHandler().saveAfterCopyValue()) {
if (!ConfigHandler().saveAfterCopyPathValue().isEmpty()) {
saveToFilesystem(capture, ConfigHandler().saveAfterCopyPathValue());
}
} else {
// If we are able to properly save the file, save the file and copy to
// clipboard.
if ((ConfigHandler().saveAfterCopyValue()) &&
(!ConfigHandler().saveAfterCopyPathValue().isEmpty())) {
QApplication::clipboard()->setPixmap(capture);
saveToFilesystem(capture,
ConfigHandler().saveAfterCopyPathValue(),
QObject::tr("Capture saved to clipboard. "));
}
// Otherwise only save to clipboard
else {
QApplication::clipboard()->setPixmap(capture);
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard"));
}
QApplication::clipboard()->setPixmap(capture);
}
bool
ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path)
ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
const QString& path,
const QString& messagePrefix)
{
QString completePath = FileNameHandler().generateAbsolutePath(path);
completePath += QLatin1String(".png");
@@ -52,9 +60,11 @@ ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path)
if (ok) {
ConfigHandler().setSavePath(path);
saveMessage = QObject::tr("Capture saved as ") + completePath;
saveMessage =
messagePrefix + QObject::tr("Capture saved as ") + completePath;
} else {
saveMessage = QObject::tr("Error trying to save as ") + completePath;
saveMessage =
messagePrefix + QObject::tr("Error trying to save as ") + completePath;
notificationPath = "";
}

View File

@@ -26,6 +26,8 @@ public:
ScreenshotSaver();
void saveToClipboard(const QPixmap& capture);
bool saveToFilesystem(const QPixmap& capture, const QString& path);
bool saveToFilesystem(const QPixmap& capture,
const QString& path,
const QString& messagePrefix);
bool saveToFilesystemGUI(const QPixmap& capture);
};

View File

@@ -1011,7 +1011,7 @@ CaptureWidget::saveScreenshot()
if (m_context.savePath.isEmpty()) {
ScreenshotSaver().saveToFilesystemGUI(pixmap());
} else {
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath);
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath, "");
}
close();
}