From f2ec6e1d4c8d0882fbd0b39b516f062ba5d5a11d Mon Sep 17 00:00:00 2001 From: Akseli Lahtinen Date: Wed, 11 Jan 2023 12:58:23 +0000 Subject: [PATCH] Write inside .cache folder in home, instead of just home Back when testing !745, i was using `kdesrc-run` and this bug slipped through my fingers: It began to create folder named after the file inside the home (or in this case, kdesrc-run home) folder. This fixes that. Now the clipboard image files go correctly to `~/.cache/KDE/screenshots/` folder. Anyhow, my bad, should've done more print debugging.. :sweat: --- src/clipboard.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/clipboard.cpp b/src/clipboard.cpp index 8fde7143b..b35222299 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -33,13 +33,14 @@ QImage Clipboard::image() const QString Clipboard::saveImage(QString localPath) const { - if (!QDir().exists(QStringLiteral("%1/screenshots").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)))) { - QDir().mkdir(QStringLiteral("%1/screenshots").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))); + QString imageDir(QStringLiteral("%1/screenshots").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))); + + if (!QDir().exists(imageDir)) { + QDir().mkdir(imageDir); } + if (localPath.isEmpty()) { - localPath = QStringLiteral("file://%1/screenshots/%2.png") - .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), - QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd-hh-mm-ss"))); + localPath = QStringLiteral("file://%1/%2.png").arg(imageDir, QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd-hh-mm-ss"))); } QUrl url(localPath); if (!url.isLocalFile()) { @@ -51,14 +52,11 @@ QString Clipboard::saveImage(QString localPath) const return {}; } - QDir dir; - if (!dir.exists(QFileInfo(url.fileName()).absoluteFilePath())) { - dir.mkpath(QFileInfo(url.fileName()).absoluteFilePath()); + if (image.save(url.toLocalFile())) { + return localPath; + } else { + return {}; } - - image.save(url.toLocalFile()); - - return localPath; } void Clipboard::saveText(QString message)