Commit 142de7bb5f035bdd94e4c2a28ba0ca119b09d01a

Authored by Josh Klontz
1 parent dde90f19

Revert "cleaned up turkGallery implementation"

This reverts commit 2288768bcce0467cf410d1912d44e8f021242e99.
Showing 1 changed file with 24 additions and 28 deletions
openbr/plugins/turk.cpp
@@ -13,45 +13,41 @@ class turkGallery : public Gallery @@ -13,45 +13,41 @@ class turkGallery : public Gallery
13 { 13 {
14 Q_OBJECT 14 Q_OBJECT
15 15
16 - struct Attribute : public QStringList  
17 - {  
18 - QString name;  
19 - Attribute(const QString &str = QString())  
20 - {  
21 - const int i = str.indexOf('[');  
22 - name = str.mid(0, i);  
23 - if (i != -1)  
24 - append(str.mid(i+1, str.length()-i-2).split(","));  
25 - }  
26 - };  
27 -  
28 TemplateList readBlock(bool *done) 16 TemplateList readBlock(bool *done)
29 { 17 {
30 *done = true; 18 *done = true;
31 TemplateList templates; 19 TemplateList templates;
  20 + if (!file.exists()) return templates;
  21 +
32 QStringList lines = QtUtils::readLines(file); 22 QStringList lines = QtUtils::readLines(file);
33 - if (lines.empty())  
34 - qFatal(".turk Gallery missing header.");  
35 - QList<Attribute> types;  
36 - foreach (const QString &header, parse(lines.takeFirst()))  
37 - types.append(header); 23 + QRegExp regexp(",(?!(?:\\w+,?)+\\])");
  24 +
  25 + QStringList headers;
  26 +
  27 + if (!lines.isEmpty()) headers = lines.takeFirst().split(regexp);
38 28
39 foreach (const QString &line, lines) { 29 foreach (const QString &line, lines) {
40 - const QStringList words = parse(line);  
41 - if (words.size() != types.size())  
42 - qFatal(".turk Gallery incorrect column count."); 30 + QStringList words = line.split(regexp);
  31 + if (words.size() != headers.size()) continue;
  32 + File f;
  33 + f.name = words[0];
  34 + f.set("Label", words[0].mid(0,5));
43 35
44 - File f(words[0], words[0].mid(0,5));  
45 for (int i=1; i<words.size(); i++) { 36 for (int i=1; i<words.size(); i++) {
46 - Attribute &type = types[i];  
47 - Attribute rating(words[i]);  
48 - if (type.size() != rating.size())  
49 - qFatal(".turk Gallery incorrect ratings count."); 37 + QStringList categories = headers[i].split('[');
  38 + categories.last().chop(1); // Remove trailing bracket
  39 + QStringList types = categories.last().split(',');
  40 +
  41 + QStringList ratings = words[i].split(',');
  42 + ratings.first() = ratings.first().mid(1); // Remove first bracket
  43 + ratings.last().chop(1); // Remove trailing bracket
  44 +
  45 + if (types.size() != ratings.size()) continue;
50 46
51 QMap<QString,QVariant> categoryMap; 47 QMap<QString,QVariant> categoryMap;
52 - for (int j=0; j<type.size(); j++)  
53 - categoryMap.insert(type[j], rating[j]);  
54 - f.set(type.name, categoryMap); 48 + for (int j=0; j<types.size(); j++) categoryMap.insert(types[j],ratings[j]);
  49 +
  50 + f.set(categories[0], categoryMap);
55 } 51 }
56 templates.append(f); 52 templates.append(f);
57 } 53 }