summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-27 17:56:46 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-27 17:56:46 +1000
commitb5d812586733353000e741bd4448f217e8ec1224 (patch)
tree99e8966c374538ce71e941cdeeaf76893cb882e6
parentplugin: saveItem ensure parent dir (diff)
downloadcaelestia-shell-b5d812586733353000e741bd4448f217e8ec1224.tar.gz
caelestia-shell-b5d812586733353000e741bd4448f217e8ec1224.tar.bz2
caelestia-shell-b5d812586733353000e741bd4448f217e8ec1224.zip
internal: better copy
-rw-r--r--modules/dashboard/Wrapper.qml7
-rw-r--r--plugin/src/Caelestia/cutils.cpp21
-rw-r--r--plugin/src/Caelestia/cutils.hpp3
-rw-r--r--utils/Paths.qml4
4 files changed, 29 insertions, 6 deletions
diff --git a/modules/dashboard/Wrapper.qml b/modules/dashboard/Wrapper.qml
index befc859..ba5dad6 100644
--- a/modules/dashboard/Wrapper.qml
+++ b/modules/dashboard/Wrapper.qml
@@ -4,6 +4,7 @@ import qs.components
import qs.components.filedialog
import qs.config
import qs.utils
+import Caelestia
import Quickshell
import Quickshell.Hyprland
import QtQuick
@@ -20,8 +21,10 @@ Item {
filterLabel: qsTr("Image files")
filters: Images.validImageExtensions
onAccepted: path => {
- Paths.copy(path, `${Paths.home}/.face`);
- Quickshell.execDetached(["notify-send", "-a", "caelestia-shell", "-u", "low", "-h", `STRING:image-path:${path}`, "Profile picture changed", `Profile picture changed to ${Paths.shortenHome(path)}`]);
+ if (CUtils.copyFile(`file://${path}`, `${Paths.home}/.face`))
+ Quickshell.execDetached(["notify-send", "-a", "caelestia-shell", "-u", "low", "-h", `STRING:image-path:${path}`, "Profile picture changed", `Profile picture changed to ${Paths.shortenHome(path)}`]);
+ else
+ Quickshell.execDetached(["notify-send", "-a", "caelestia-shell", "-u", "critical", "Unable to change profile picture", `Failed to change profile picture to ${Paths.shortenHome(path)}`]);
}
}
}
diff --git a/plugin/src/Caelestia/cutils.cpp b/plugin/src/Caelestia/cutils.cpp
index fd7fcdd..2415f80 100644
--- a/plugin/src/Caelestia/cutils.cpp
+++ b/plugin/src/Caelestia/cutils.cpp
@@ -68,3 +68,24 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q
}
);
}
+
+bool CUtils::copyFile(const QUrl& source, const QUrl& target) const {
+ return this->copyFile(source, target, true);
+}
+
+bool CUtils::copyFile(const QUrl& source, const QUrl& target, bool overwrite) const {
+ if (!source.isLocalFile()) {
+ qWarning() << "CUtils::copyFile: source" << source << "is not a local file";
+ return false;
+ }
+ if (!target.isLocalFile()) {
+ qWarning() << "CUtils::copyFile: target" << target << "is not a local file";
+ return false;
+ }
+
+ if (overwrite) {
+ QFile::remove(target.toLocalFile());
+ }
+
+ return QFile::copy(source.toLocalFile(), target.toLocalFile());
+}
diff --git a/plugin/src/Caelestia/cutils.hpp b/plugin/src/Caelestia/cutils.hpp
index e50cab0..e1319a4 100644
--- a/plugin/src/Caelestia/cutils.hpp
+++ b/plugin/src/Caelestia/cutils.hpp
@@ -15,4 +15,7 @@ public:
Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, QJSValue onSaved, QJSValue onFailed) const;
Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, QJSValue onSaved) const;
Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, QJSValue onSaved, QJSValue onFailed) const;
+
+ Q_INVOKABLE bool copyFile(const QUrl& source, const QUrl& target) const;
+ Q_INVOKABLE bool copyFile(const QUrl& source, const QUrl& target, bool overwrite) const;
};
diff --git a/utils/Paths.qml b/utils/Paths.qml
index 71be877..0a00c9d 100644
--- a/utils/Paths.qml
+++ b/utils/Paths.qml
@@ -37,8 +37,4 @@ Singleton {
function strip(path: url): string {
return stringify(path).replace("file://", "");
}
-
- function copy(from: url, to: url): void {
- Quickshell.execDetached(["cp", strip(from), strip(to)]);
- }
}