From 980b6d04fc988098d4dd60722554b03d0f1bdbde Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Mon, 18 Mar 2013 12:10:47 -0400 Subject: [PATCH] added support to preserve file paths when enrolling to a folder --- sdk/core/qtutils.cpp | 9 +++++++++ sdk/core/qtutils.h | 1 + sdk/openbr_plugin.cpp | 8 ++++++++ sdk/openbr_plugin.h | 3 +++ sdk/plugins/gallery.cpp | 4 ++-- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sdk/core/qtutils.cpp b/sdk/core/qtutils.cpp index f3f083c..9d6d8f5 100644 --- a/sdk/core/qtutils.cpp +++ b/sdk/core/qtutils.cpp @@ -121,6 +121,15 @@ void QtUtils::writeFile(const QString &file, const QByteArray &data, int compres } } +void QtUtils::copyFile(const QString &src, const QString &dst) +{ + touchDir(QFileInfo(dst)); + if (!QFile::copy(src, dst)) { + if (QFileInfo(src).exists()) qFatal("Unable to copy %s to %s. Check file permissions.", qPrintable(src), qPrintable(dst)); + else qFatal("Unable to copy %s to %s. File does not exist.", qPrintable(src), qPrintable(dst)); + } +} + void QtUtils::touchDir(const QDir &dir) { if (dir.exists(".")) return; diff --git a/sdk/core/qtutils.h b/sdk/core/qtutils.h index 96d6316..cd150a1 100644 --- a/sdk/core/qtutils.h +++ b/sdk/core/qtutils.h @@ -39,6 +39,7 @@ namespace QtUtils void writeFile(const QString &file, const QStringList &lines); void writeFile(const QString &file, const QString &data); void writeFile(const QString &file, const QByteArray &data, int compression = 0); + void copyFile(const QString &src, const QString &dst); /**** Directory Utilities ****/ void touchDir(const QDir &dir); diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index f7cc14c..f7cbbda 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -148,6 +148,14 @@ void File::set(const QString &key, const QVariant &value) m_metadata.insert(key, value); } +bool File::getBool(const QString &key) const +{ + if (!contains(key)) return false; + QVariant variant = value(key); + if (variant.isNull() || !variant.canConvert()) return true; + return variant.value(); +} + QString File::subject(int label) { return Globals->classes.key(label, QString::number(label)); diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index 4e63952..66252bc 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -206,6 +206,9 @@ struct BR_EXPORT File return variant.value(); } + /*!< \brief Specialization for boolean type. */ + bool getBool(const QString &key) const; + /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ template T get(const QString &key, const T &defaultValue) const diff --git a/sdk/plugins/gallery.cpp b/sdk/plugins/gallery.cpp index e522d44..ea713ae 100644 --- a/sdk/plugins/gallery.cpp +++ b/sdk/plugins/gallery.cpp @@ -127,10 +127,10 @@ class EmptyGallery : public Gallery // Enrolling a null file is used as an idiom to initialize an algorithm if (file.name.isEmpty()) return; - const QString destination = file.name + "/" + t.file.fileName(); + const QString destination = file.name + "/" + (file.getBool("preservePath") ? t.file.name : t.file.fileName()); QMutexLocker diskLocker(&diskLock); // Windows prefers to crash when writing to disk in parallel if (t.isNull()) { - QFile::copy(t.file.resolved(), destination); + QtUtils::copyFile(t.file.resolved(), destination); } else { QScopedPointer format(Factory::make(destination)); format->write(t); -- libgit2 0.21.4