Commit b753cbec authored by Jan Paul Batrina's avatar Jan Paul Batrina Committed by Méven Car
Browse files

Copy the correct file path to clipboard

Previously, the path copied was always the temporary
save file path unless the image was autosaved.
Now, ExportManager keeps track of whether the image has
been saved, and that is used for choosing the correct path.

BUG: 441047
parent 138f9c26
......@@ -36,10 +36,12 @@
ExportManager::ExportManager(QObject *parent) :
QObject(parent),
mImageSavedNotInTemp(false),
mSavePixmap(QPixmap()),
mTempFile(QUrl())
{
connect(this, &ExportManager::imageSaved, &Settings::setLastSaveLocation);
connect(this, &ExportManager::imageSavedAndCopied, &Settings::setLastSaveLocation);
}
ExportManager::~ExportManager()
......@@ -91,6 +93,9 @@ void ExportManager::setPixmap(const QPixmap &pixmap)
file.remove();
mTempFile = QUrl();
}
// since the pixmap was modified, we now consider the image unsaved
mImageSavedNotInTemp = false;
}
void ExportManager::updatePixmapTimestamp()
......@@ -429,6 +434,7 @@ bool ExportManager::save(const QUrl &url)
saveSucceded = remoteSave(url, mimetype);
}
if (saveSucceded) {
mImageSavedNotInTemp = true;
KRecentDocument::add(url, QGuiApplication::desktopFileName());
}
return saveSucceded;
......@@ -446,6 +452,10 @@ bool ExportManager::isFileExists(const QUrl &url) const
return (existsJob->error() == KJob::NoError);
}
bool ExportManager::isImageSavedNotInTemp() const {
return mImageSavedNotInTemp;
}
bool ExportManager::isTempFileAlreadyUsed(const QUrl &url) const
{
return mUsedTempFileNames.contains(url);
......@@ -523,7 +533,6 @@ void ExportManager::doSaveAndCopy(const QUrl &url)
if (save(savePath)) {
QDir dir(savePath.path());
dir.cdUp();
Settings::setLastSaveLocation(savePath);
doCopyToClipboard(false);
emit imageSavedAndCopied(savePath);
......@@ -563,8 +572,8 @@ void ExportManager::doCopyToClipboard(bool notify)
void ExportManager::doCopyLocationToClipboard(bool notify)
{
QString localFile;
if (Settings::self()->autoSaveImage()) {
// The auto save has been enabled, we need to choose that file path
if (mImageSavedNotInTemp) {
// The image has been saved (manually or automatically), we need to choose that file path
localFile = Settings::self()->lastSaveLocation().toLocalFile();
} else {
// use a temporary save path, and copy that to clipboard instead
......
......@@ -42,6 +42,7 @@ class ExportManager: public QObject
QString defaultSaveLocation() const;
bool isFileExists(const QUrl &url) const;
bool isImageSavedNotInTemp() const;
void setPixmap(const QPixmap &pixmap);
QPixmap pixmap() const;
void updatePixmapTimestamp();
......@@ -89,6 +90,7 @@ class ExportManager: public QObject
bool remoteSave(const QUrl &url, const QString &mimetype);
bool isTempFileAlreadyUsed(const QUrl &url) const;
bool mImageSavedNotInTemp;
QPixmap mSavePixmap;
QDateTime mPixmapTimestamp;
QUrl mTempFile;
......
......@@ -260,7 +260,16 @@ void KSMainWindow::init()
// message: open containing folder
mOpenContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget);
connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({Settings::lastSaveLocation()});});
connect(mOpenContaining, &QAction::triggered, [=] {
QUrl imageUrl;
if (ExportManager::instance()->isImageSavedNotInTemp()) {
imageUrl = Settings::lastSaveLocation();
} else {
imageUrl = ExportManager::instance()->tempSave();
}
KIO::highlightInFileManager({imageUrl});
});
mHideMessageWidgetTimer = new QTimer(this);
// connect(mHideMessageWidgetTimer, &QTimer::timeout,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment