Commit f3cd29513989ab245e5ef990dd1100eccbd2f0b8

Authored by Josh Klontz
1 parent 253d8f61

redesigned .txt gallery format

Showing 1 changed file with 27 additions and 10 deletions
openbr/plugins/gallery.cpp
@@ -506,38 +506,55 @@ BR_REGISTER(Gallery, csvGallery) @@ -506,38 +506,55 @@ BR_REGISTER(Gallery, csvGallery)
506 * \brief Treats each line as a file. 506 * \brief Treats each line as a file.
507 * \author Josh Klontz \cite jklontz 507 * \author Josh Klontz \cite jklontz
508 * 508 *
509 - * The entire line is treated as the file path. 509 + * The entire line is treated as the file path. An optional label may be specified using a space ' ' separator:
510 * 510 *
  511 +\verbatim
  512 +<FILE>
  513 +<FILE>
  514 +...
  515 +<FILE>
  516 +\endverbatim
  517 + * or
  518 +\verbatim
  519 +<FILE> <LABEL>
  520 +<FILE> <LABEL>
  521 +...
  522 +<FILE> <LABEL>
  523 +\endverbatim
511 * \see csvGallery 524 * \see csvGallery
512 */ 525 */
513 class txtGallery : public Gallery 526 class txtGallery : public Gallery
514 { 527 {
515 Q_OBJECT 528 Q_OBJECT
516 - Q_PROPERTY(QString metadataKey READ get_metadataKey WRITE set_metadataKey RESET reset_metadataKey STORED false)  
517 - BR_PROPERTY(QString, metadataKey, "") 529 + Q_PROPERTY(QString label READ get_label WRITE set_label RESET reset_label STORED false)
  530 + BR_PROPERTY(QString, label, "")
518 531
519 QStringList lines; 532 QStringList lines;
520 533
521 ~txtGallery() 534 ~txtGallery()
522 { 535 {
523 - if (!lines.isEmpty()) QtUtils::writeFile(file.name, lines); 536 + if (!lines.isEmpty())
  537 + QtUtils::writeFile(file.name, lines);
524 } 538 }
525 539
526 TemplateList readBlock(bool *done) 540 TemplateList readBlock(bool *done)
527 { 541 {
528 - *done = true;  
529 TemplateList templates; 542 TemplateList templates;
530 - if (!file.exists()) return templates;  
531 -  
532 - foreach (const QString &line, QtUtils::readLines(file))  
533 - templates.append(File(line)); 543 + foreach (const QString &line, QtUtils::readLines(file)) {
  544 + int splitIndex = line.lastIndexOf(' ');
  545 + if (splitIndex == -1) templates.append(File(line));
  546 + else templates.append(File(line.mid(0, splitIndex), line.mid(splitIndex+1)));
  547 + }
534 *done = true; 548 *done = true;
535 return templates; 549 return templates;
536 } 550 }
537 551
538 void write(const Template &t) 552 void write(const Template &t)
539 { 553 {
540 - lines.append(metadataKey.isEmpty() ? t.file.flat() : t.file.get<QString>(metadataKey)); 554 + QString line = t.file.name;
  555 + if (!label.isEmpty())
  556 + line += " " + t.file.get<QString>(label);
  557 + lines.append(line);
541 } 558 }
542 }; 559 };
543 560