Commit baa5927d9a06830ce420ecc5adb7ab5dfb07b0b0
1 parent
a2c6d47d
Updated empty gallery to use deepest folder as subject label
Showing
3 changed files
with
27 additions
and
4 deletions
openbr/core/utility.cpp
| @@ -19,6 +19,25 @@ QStringList br::getFiles(QDir dir, bool recursive) | @@ -19,6 +19,25 @@ QStringList br::getFiles(QDir dir, bool recursive) | ||
| 19 | return files; | 19 | return files; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | +QList<QPair<QString,QStringList> > br::getFilesWithLabels(QDir dir) | ||
| 23 | +{ | ||
| 24 | + dir = QDir(dir.canonicalPath()); | ||
| 25 | + | ||
| 26 | + QStringList files; | ||
| 27 | + foreach (const QString &file, QtUtils::naturalSort(dir.entryList(QDir::Files))) | ||
| 28 | + files.append(dir.absoluteFilePath(file)); | ||
| 29 | + | ||
| 30 | + QList<QPair<QString,QStringList> > filesWithLabels; | ||
| 31 | + filesWithLabels.append(QPair<QString,QStringList>(dir.dirName(),files)); | ||
| 32 | + | ||
| 33 | + foreach (const QString &folder, QtUtils::naturalSort(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))) { | ||
| 34 | + QDir subdir(dir); | ||
| 35 | + bool success = subdir.cd(folder); if (!success) qFatal("cd failure."); | ||
| 36 | + filesWithLabels.append(getFilesWithLabels(subdir)); | ||
| 37 | + } | ||
| 38 | + return filesWithLabels; | ||
| 39 | +} | ||
| 40 | + | ||
| 22 | QStringList br::getFiles(const QString ®exp) | 41 | QStringList br::getFiles(const QString ®exp) |
| 23 | { | 42 | { |
| 24 | QFileInfo fileInfo(regexp); | 43 | QFileInfo fileInfo(regexp); |
openbr/core/utility.h
| @@ -11,6 +11,7 @@ namespace br | @@ -11,6 +11,7 @@ namespace br | ||
| 11 | { | 11 | { |
| 12 | 12 | ||
| 13 | BR_EXPORT QStringList getFiles(QDir dir, bool recursive); | 13 | BR_EXPORT QStringList getFiles(QDir dir, bool recursive); |
| 14 | +BR_EXPORT QList<QPair<QString,QStringList> > getFilesWithLabels(QDir dir); | ||
| 14 | BR_EXPORT QStringList getFiles(const QString ®exp); | 15 | BR_EXPORT QStringList getFiles(const QString ®exp); |
| 15 | 16 | ||
| 16 | } // namespace br | 17 | } // namespace br |
openbr/plugins/gallery/empty.cpp
| @@ -20,6 +20,8 @@ | @@ -20,6 +20,8 @@ | ||
| 20 | #include <openbr/core/qtutils.h> | 20 | #include <openbr/core/qtutils.h> |
| 21 | #include <openbr/core/utility.h> | 21 | #include <openbr/core/utility.h> |
| 22 | 22 | ||
| 23 | +typedef QPair<QString,QStringList> FilesWithLabel; | ||
| 24 | + | ||
| 23 | namespace br | 25 | namespace br |
| 24 | { | 26 | { |
| 25 | 27 | ||
| @@ -113,10 +115,11 @@ class EmptyGallery : public Gallery | @@ -113,10 +115,11 @@ class EmptyGallery : public Gallery | ||
| 113 | 115 | ||
| 114 | static TemplateList getTemplates(const QDir &dir) | 116 | static TemplateList getTemplates(const QDir &dir) |
| 115 | { | 117 | { |
| 116 | - const QStringList files = getFiles(dir, true); | ||
| 117 | - TemplateList templates; templates.reserve(files.size()); | ||
| 118 | - foreach (const QString &file, files) | ||
| 119 | - templates.append(File(file, dir.dirName())); | 118 | + const QList<FilesWithLabel> filesWithLabels = getFilesWithLabels(dir); |
| 119 | + TemplateList templates; templates.reserve(filesWithLabels.size()); | ||
| 120 | + foreach (const FilesWithLabel &filesWithLabel, filesWithLabels) | ||
| 121 | + foreach (const QString &file, filesWithLabel.second) | ||
| 122 | + templates.append(File(file, filesWithLabel.first)); | ||
| 120 | return templates; | 123 | return templates; |
| 121 | } | 124 | } |
| 122 | }; | 125 | }; |