Commit baa5927d9a06830ce420ecc5adb7ab5dfb07b0b0

Authored by Scott Klum
1 parent a2c6d47d

Updated empty gallery to use deepest folder as subject label

openbr/core/utility.cpp
... ... @@ -19,6 +19,25 @@ QStringList br::getFiles(QDir dir, bool recursive)
19 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 41 QStringList br::getFiles(const QString &regexp)
23 42 {
24 43 QFileInfo fileInfo(regexp);
... ...
openbr/core/utility.h
... ... @@ -11,6 +11,7 @@ namespace br
11 11 {
12 12  
13 13 BR_EXPORT QStringList getFiles(QDir dir, bool recursive);
  14 +BR_EXPORT QList<QPair<QString,QStringList> > getFilesWithLabels(QDir dir);
14 15 BR_EXPORT QStringList getFiles(const QString &regexp);
15 16  
16 17 } // namespace br
... ...
openbr/plugins/gallery/empty.cpp
... ... @@ -20,6 +20,8 @@
20 20 #include <openbr/core/qtutils.h>
21 21 #include <openbr/core/utility.h>
22 22  
  23 +typedef QPair<QString,QStringList> FilesWithLabel;
  24 +
23 25 namespace br
24 26 {
25 27  
... ... @@ -113,10 +115,11 @@ class EmptyGallery : public Gallery
113 115  
114 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 123 return templates;
121 124 }
122 125 };
... ...