Commit 980b6d04fc988098d4dd60722554b03d0f1bdbde

Authored by Josh Klontz
1 parent a29b78a7

added support to preserve file paths when enrolling to a folder

sdk/core/qtutils.cpp
@@ -121,6 +121,15 @@ void QtUtils::writeFile(const QString &file, const QByteArray &data, int compres @@ -121,6 +121,15 @@ void QtUtils::writeFile(const QString &file, const QByteArray &data, int compres
121 } 121 }
122 } 122 }
123 123
  124 +void QtUtils::copyFile(const QString &src, const QString &dst)
  125 +{
  126 + touchDir(QFileInfo(dst));
  127 + if (!QFile::copy(src, dst)) {
  128 + if (QFileInfo(src).exists()) qFatal("Unable to copy %s to %s. Check file permissions.", qPrintable(src), qPrintable(dst));
  129 + else qFatal("Unable to copy %s to %s. File does not exist.", qPrintable(src), qPrintable(dst));
  130 + }
  131 +}
  132 +
124 void QtUtils::touchDir(const QDir &dir) 133 void QtUtils::touchDir(const QDir &dir)
125 { 134 {
126 if (dir.exists(".")) return; 135 if (dir.exists(".")) return;
sdk/core/qtutils.h
@@ -39,6 +39,7 @@ namespace QtUtils @@ -39,6 +39,7 @@ namespace QtUtils
39 void writeFile(const QString &file, const QStringList &lines); 39 void writeFile(const QString &file, const QStringList &lines);
40 void writeFile(const QString &file, const QString &data); 40 void writeFile(const QString &file, const QString &data);
41 void writeFile(const QString &file, const QByteArray &data, int compression = 0); 41 void writeFile(const QString &file, const QByteArray &data, int compression = 0);
  42 + void copyFile(const QString &src, const QString &dst);
42 43
43 /**** Directory Utilities ****/ 44 /**** Directory Utilities ****/
44 void touchDir(const QDir &dir); 45 void touchDir(const QDir &dir);
sdk/openbr_plugin.cpp
@@ -148,6 +148,14 @@ void File::set(const QString &key, const QVariant &value) @@ -148,6 +148,14 @@ void File::set(const QString &key, const QVariant &value)
148 m_metadata.insert(key, value); 148 m_metadata.insert(key, value);
149 } 149 }
150 150
  151 +bool File::getBool(const QString &key) const
  152 +{
  153 + if (!contains(key)) return false;
  154 + QVariant variant = value(key);
  155 + if (variant.isNull() || !variant.canConvert<bool>()) return true;
  156 + return variant.value<bool>();
  157 +}
  158 +
151 QString File::subject(int label) 159 QString File::subject(int label)
152 { 160 {
153 return Globals->classes.key(label, QString::number(label)); 161 return Globals->classes.key(label, QString::number(label));
sdk/openbr_plugin.h
@@ -206,6 +206,9 @@ struct BR_EXPORT File @@ -206,6 +206,9 @@ struct BR_EXPORT File
206 return variant.value<T>(); 206 return variant.value<T>();
207 } 207 }
208 208
  209 + /*!< \brief Specialization for boolean type. */
  210 + bool getBool(const QString &key) const;
  211 +
209 /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ 212 /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */
210 template <typename T> 213 template <typename T>
211 T get(const QString &key, const T &defaultValue) const 214 T get(const QString &key, const T &defaultValue) const
sdk/plugins/gallery.cpp
@@ -127,10 +127,10 @@ class EmptyGallery : public Gallery @@ -127,10 +127,10 @@ class EmptyGallery : public Gallery
127 // Enrolling a null file is used as an idiom to initialize an algorithm 127 // Enrolling a null file is used as an idiom to initialize an algorithm
128 if (file.name.isEmpty()) return; 128 if (file.name.isEmpty()) return;
129 129
130 - const QString destination = file.name + "/" + t.file.fileName(); 130 + const QString destination = file.name + "/" + (file.getBool("preservePath") ? t.file.name : t.file.fileName());
131 QMutexLocker diskLocker(&diskLock); // Windows prefers to crash when writing to disk in parallel 131 QMutexLocker diskLocker(&diskLock); // Windows prefers to crash when writing to disk in parallel
132 if (t.isNull()) { 132 if (t.isNull()) {
133 - QFile::copy(t.file.resolved(), destination); 133 + QtUtils::copyFile(t.file.resolved(), destination);
134 } else { 134 } else {
135 QScopedPointer<Format> format(Factory<Format>::make(destination)); 135 QScopedPointer<Format> format(Factory<Format>::make(destination));
136 format->write(t); 136 format->write(t);