Commit c395fdbd20002e180a923a7e4fcf6a5c3703450f
1 parent
ae79a4ed
cleaned up gallery/enrollment logic
Showing
3 changed files
with
11 additions
and
73 deletions
sdk/core/core.cpp
| ... | ... | @@ -112,7 +112,7 @@ struct AlgorithmCore |
| 112 | 112 | QScopedPointer<Gallery> g(Gallery::make(gallery)); |
| 113 | 113 | if (g.isNull()) return FileList(); |
| 114 | 114 | FileList fileList = g->files(); |
| 115 | - if (!fileList.isEmpty() && g->isUniversal() && !gallery.contains("append")) | |
| 115 | + if (!fileList.isEmpty() && gallery.contains("cache")) | |
| 116 | 116 | return fileList; // Already enrolled |
| 117 | 117 | |
| 118 | 118 | const TemplateList i(TemplateList::fromInput(input)); |
| ... | ... | @@ -166,7 +166,7 @@ struct AlgorithmCore |
| 166 | 166 | void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles) |
| 167 | 167 | { |
| 168 | 168 | gallery.reset(Gallery::make(file)); |
| 169 | - if (!gallery->isUniversal()) { | |
| 169 | + if ((file.suffix() != "gal") && (file.suffix() != "mem")) { | |
| 170 | 170 | enroll(file); |
| 171 | 171 | gallery.reset(Gallery::make(getMemoryGallery(file))); |
| 172 | 172 | galleryFiles = gallery->files(); | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -875,7 +875,6 @@ class BR_EXPORT Gallery : public Object |
| 875 | 875 | |
| 876 | 876 | public: |
| 877 | 877 | virtual ~Gallery() {} |
| 878 | - virtual bool isUniversal() const = 0; /*!< \c true if the gallery can read and write complete templates, \c false otherwise. */ | |
| 879 | 878 | TemplateList read(); /*!< \brief Retrieve all the stored templates. */ |
| 880 | 879 | FileList files(); /*!< \brief Retrieve all the stored template files. */ |
| 881 | 880 | virtual TemplateList readBlock(bool *done) = 0; /*!< \brief Retrieve a portion of the stored templates. */ | ... | ... |
sdk/plugins/gallery.cpp
| ... | ... | @@ -52,51 +52,30 @@ class galGallery : public Gallery |
| 52 | 52 | QFile gallery; |
| 53 | 53 | QDataStream stream; |
| 54 | 54 | |
| 55 | - ~galGallery() | |
| 56 | - { | |
| 57 | - gallery.close(); | |
| 58 | - } | |
| 59 | - | |
| 60 | 55 | void init() |
| 61 | 56 | { |
| 62 | 57 | gallery.setFileName(file); |
| 58 | + if (file.getBool("remove")) | |
| 59 | + gallery.remove(); | |
| 63 | 60 | QtUtils::touchDir(gallery); |
| 64 | - | |
| 65 | - if (file.contains("append")) { | |
| 66 | - if (!gallery.open(QFile::Append)) | |
| 67 | - qFatal("Can't open [%s] for appending.", qPrintable(gallery.fileName())); | |
| 68 | - } else if (gallery.exists()) { | |
| 69 | - if (!gallery.open(QFile::ReadOnly)) | |
| 70 | - qFatal("Can't open [%s] for reading.", qPrintable(gallery.fileName())); | |
| 71 | - } else { | |
| 72 | - if (!gallery.open(QFile::WriteOnly)) | |
| 73 | - qFatal("Can't open [%s] for writing.", qPrintable(gallery.fileName())); | |
| 74 | - } | |
| 75 | - | |
| 61 | + if (!gallery.open(QFile::ReadWrite | QFile::Append)) | |
| 62 | + qFatal("Can't open gallery: %s", qPrintable(gallery.fileName())); | |
| 76 | 63 | stream.setDevice(&gallery); |
| 77 | 64 | } |
| 78 | 65 | |
| 79 | - bool isUniversal() const | |
| 80 | - { | |
| 81 | - return true; | |
| 82 | - } | |
| 83 | - | |
| 84 | 66 | TemplateList readBlock(bool *done) |
| 85 | 67 | { |
| 86 | - *done = false; | |
| 68 | + if (stream.atEnd()) | |
| 69 | + gallery.seek(0); | |
| 87 | 70 | |
| 88 | 71 | TemplateList templates; |
| 89 | - while (templates.size() < Globals->blockSize) { | |
| 90 | - if (stream.atEnd()) { | |
| 91 | - *done = true; | |
| 92 | - gallery.seek(0); | |
| 93 | - break; | |
| 94 | - } | |
| 95 | - | |
| 72 | + while ((templates.size() < Globals->blockSize) && !stream.atEnd()) { | |
| 96 | 73 | Template m; |
| 97 | 74 | stream >> m; |
| 98 | 75 | templates.append(m); |
| 99 | 76 | } |
| 77 | + | |
| 78 | + *done = stream.atEnd(); | |
| 100 | 79 | return templates; |
| 101 | 80 | } |
| 102 | 81 | |
| ... | ... | @@ -126,11 +105,6 @@ class EmptyGallery : public Gallery |
| 126 | 105 | QtUtils::touchDir(QDir(file.name)); |
| 127 | 106 | } |
| 128 | 107 | |
| 129 | - bool isUniversal() const | |
| 130 | - { | |
| 131 | - return false; | |
| 132 | - } | |
| 133 | - | |
| 134 | 108 | TemplateList readBlock(bool *done) |
| 135 | 109 | { |
| 136 | 110 | *done = true; |
| ... | ... | @@ -180,11 +154,6 @@ class DefaultGallery : public Gallery |
| 180 | 154 | { |
| 181 | 155 | Q_OBJECT |
| 182 | 156 | |
| 183 | - bool isUniversal() const | |
| 184 | - { | |
| 185 | - return false; | |
| 186 | - } | |
| 187 | - | |
| 188 | 157 | TemplateList readBlock(bool *done) |
| 189 | 158 | { |
| 190 | 159 | *done = true; |
| ... | ... | @@ -248,11 +217,6 @@ class memGallery : public Gallery |
| 248 | 217 | } |
| 249 | 218 | } |
| 250 | 219 | |
| 251 | - bool isUniversal() const | |
| 252 | - { | |
| 253 | - return true; | |
| 254 | - } | |
| 255 | - | |
| 256 | 220 | TemplateList readBlock(bool *done) |
| 257 | 221 | { |
| 258 | 222 | if (!MemoryGalleries::aligned[file]) { |
| ... | ... | @@ -322,11 +286,6 @@ class csvGallery : public Gallery |
| 322 | 286 | |
| 323 | 287 | FileList files; |
| 324 | 288 | |
| 325 | - bool isUniversal() const | |
| 326 | - { | |
| 327 | - return false; | |
| 328 | - } | |
| 329 | - | |
| 330 | 289 | ~csvGallery() |
| 331 | 290 | { |
| 332 | 291 | if (files.isEmpty()) return; |
| ... | ... | @@ -393,11 +352,6 @@ class txtGallery : public Gallery |
| 393 | 352 | if (!lines.isEmpty()) QtUtils::writeFile(file.name, lines); |
| 394 | 353 | } |
| 395 | 354 | |
| 396 | - bool isUniversal() const | |
| 397 | - { | |
| 398 | - return false; | |
| 399 | - } | |
| 400 | - | |
| 401 | 355 | TemplateList readBlock(bool *done) |
| 402 | 356 | { |
| 403 | 357 | *done = true; |
| ... | ... | @@ -429,11 +383,6 @@ class xmlGallery : public Gallery |
| 429 | 383 | Q_PROPERTY(bool ignoreMetadata READ get_ignoreMetadata WRITE set_ignoreMetadata RESET reset_ignoreMetadata) |
| 430 | 384 | BR_PROPERTY(bool, ignoreMetadata, false) |
| 431 | 385 | |
| 432 | - bool isUniversal() const | |
| 433 | - { | |
| 434 | - return false; | |
| 435 | - } | |
| 436 | - | |
| 437 | 386 | TemplateList readBlock(bool *done) |
| 438 | 387 | { |
| 439 | 388 | TemplateList templates; |
| ... | ... | @@ -461,11 +410,6 @@ class dbGallery : public Gallery |
| 461 | 410 | { |
| 462 | 411 | Q_OBJECT |
| 463 | 412 | |
| 464 | - bool isUniversal() const | |
| 465 | - { | |
| 466 | - return false; | |
| 467 | - } | |
| 468 | - | |
| 469 | 413 | TemplateList readBlock(bool *done) |
| 470 | 414 | { |
| 471 | 415 | TemplateList templates; |
| ... | ... | @@ -617,11 +561,6 @@ class googleGallery : public Gallery |
| 617 | 561 | { |
| 618 | 562 | Q_OBJECT |
| 619 | 563 | |
| 620 | - bool isUniversal() const | |
| 621 | - { | |
| 622 | - return false; | |
| 623 | - } | |
| 624 | - | |
| 625 | 564 | TemplateList readBlock(bool *done) |
| 626 | 565 | { |
| 627 | 566 | TemplateList templates; | ... | ... |