internal: better copy
This commit is contained in:
parent
800b5e6515
commit
b5d8125867
4 changed files with 29 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ import qs.components
|
||||||
import qs.components.filedialog
|
import qs.components.filedialog
|
||||||
import qs.config
|
import qs.config
|
||||||
import qs.utils
|
import qs.utils
|
||||||
|
import Caelestia
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
import QtQuick
|
import QtQuick
|
||||||
|
|
@ -20,8 +21,10 @@ Item {
|
||||||
filterLabel: qsTr("Image files")
|
filterLabel: qsTr("Image files")
|
||||||
filters: Images.validImageExtensions
|
filters: Images.validImageExtensions
|
||||||
onAccepted: path => {
|
onAccepted: path => {
|
||||||
Paths.copy(path, `${Paths.home}/.face`);
|
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)}`]);
|
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)}`]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, 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) const;
|
||||||
Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, QJSValue onSaved, QJSValue onFailed) 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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,4 @@ Singleton {
|
||||||
function strip(path: url): string {
|
function strip(path: url): string {
|
||||||
return stringify(path).replace("file://", "");
|
return stringify(path).replace("file://", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy(from: url, to: url): void {
|
|
||||||
Quickshell.execDetached(["cp", strip(from), strip(to)]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue