diff options
Diffstat (limited to 'plugin/src')
| -rw-r--r-- | plugin/src/Caelestia/cutils.cpp | 21 | ||||
| -rw-r--r-- | plugin/src/Caelestia/cutils.hpp | 3 |
2 files changed, 24 insertions, 0 deletions
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; }; |