Commit d3047f8e74a770b8f6e8201ad60465cb36dfe71c

Authored by Scott Klum
Committed by GitHub
2 parents a2c6d47d 9b6e5c90

Merge pull request #502 from biometrics/empty

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,6 +19,25 @@ QStringList br::getFiles(QDir dir, bool recursive)
19 return files; 19 return files;
20 } 20 }
21 21
  22 +QList<br::FilesWithLabel> br::getFilesWithLabels(QDir dir)
  23 +{
  24 + dir = QDir(dir.canonicalPath());
  25 +
  26 + QStringList files;
  27 + foreach (const QString &file, dir.entryList(QDir::Files))
  28 + files.append(dir.absoluteFilePath(file));
  29 +
  30 + QList<br::FilesWithLabel> filesWithLabels;
  31 + filesWithLabels.append(br::FilesWithLabel(dir.dirName(),files));
  32 +
  33 + foreach (const QString &folder, 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 &regexp) 41 QStringList br::getFiles(const QString &regexp)
23 { 42 {
24 QFileInfo fileInfo(regexp); 43 QFileInfo fileInfo(regexp);
openbr/core/utility.h
@@ -10,7 +10,10 @@ @@ -10,7 +10,10 @@
10 namespace br 10 namespace br
11 { 11 {
12 12
  13 +typedef QPair<QString,QStringList> FilesWithLabel;
  14 +
13 BR_EXPORT QStringList getFiles(QDir dir, bool recursive); 15 BR_EXPORT QStringList getFiles(QDir dir, bool recursive);
  16 +BR_EXPORT QList<QPair<QString,QStringList> > getFilesWithLabels(QDir dir);
14 BR_EXPORT QStringList getFiles(const QString &regexp); 17 BR_EXPORT QStringList getFiles(const QString &regexp);
15 18
16 } // namespace br 19 } // namespace br
openbr/plugins/gallery/empty.cpp
@@ -113,10 +113,11 @@ class EmptyGallery : public Gallery @@ -113,10 +113,11 @@ class EmptyGallery : public Gallery
113 113
114 static TemplateList getTemplates(const QDir &dir) 114 static TemplateList getTemplates(const QDir &dir)
115 { 115 {
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())); 116 + const QList<FilesWithLabel> filesWithLabels = getFilesWithLabels(dir);
  117 + TemplateList templates;
  118 + foreach (const FilesWithLabel &filesWithLabel, filesWithLabels)
  119 + foreach (const QString &file, filesWithLabel.second)
  120 + templates.append(File(file, filesWithLabel.first));
120 return templates; 121 return templates;
121 } 122 }
122 }; 123 };