From c395fdbd20002e180a923a7e4fcf6a5c3703450f Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Thu, 17 Jan 2013 15:46:32 -0500 Subject: [PATCH] cleaned up gallery/enrollment logic --- sdk/core/core.cpp | 4 ++-- sdk/openbr_plugin.h | 1 - sdk/plugins/gallery.cpp | 79 +++++++++---------------------------------------------------------------------- 3 files changed, 11 insertions(+), 73 deletions(-) diff --git a/sdk/core/core.cpp b/sdk/core/core.cpp index e09176a..e0bcb8b 100644 --- a/sdk/core/core.cpp +++ b/sdk/core/core.cpp @@ -112,7 +112,7 @@ struct AlgorithmCore QScopedPointer g(Gallery::make(gallery)); if (g.isNull()) return FileList(); FileList fileList = g->files(); - if (!fileList.isEmpty() && g->isUniversal() && !gallery.contains("append")) + if (!fileList.isEmpty() && gallery.contains("cache")) return fileList; // Already enrolled const TemplateList i(TemplateList::fromInput(input)); @@ -166,7 +166,7 @@ struct AlgorithmCore void retrieveOrEnroll(const File &file, QScopedPointer &gallery, FileList &galleryFiles) { gallery.reset(Gallery::make(file)); - if (!gallery->isUniversal()) { + if ((file.suffix() != "gal") && (file.suffix() != "mem")) { enroll(file); gallery.reset(Gallery::make(getMemoryGallery(file))); galleryFiles = gallery->files(); diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index 470bef2..9c10a54 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -875,7 +875,6 @@ class BR_EXPORT Gallery : public Object public: virtual ~Gallery() {} - virtual bool isUniversal() const = 0; /*!< \c true if the gallery can read and write complete templates, \c false otherwise. */ TemplateList read(); /*!< \brief Retrieve all the stored templates. */ FileList files(); /*!< \brief Retrieve all the stored template files. */ virtual TemplateList readBlock(bool *done) = 0; /*!< \brief Retrieve a portion of the stored templates. */ diff --git a/sdk/plugins/gallery.cpp b/sdk/plugins/gallery.cpp index d0f954b..9362b2f 100644 --- a/sdk/plugins/gallery.cpp +++ b/sdk/plugins/gallery.cpp @@ -52,51 +52,30 @@ class galGallery : public Gallery QFile gallery; QDataStream stream; - ~galGallery() - { - gallery.close(); - } - void init() { gallery.setFileName(file); + if (file.getBool("remove")) + gallery.remove(); QtUtils::touchDir(gallery); - - if (file.contains("append")) { - if (!gallery.open(QFile::Append)) - qFatal("Can't open [%s] for appending.", qPrintable(gallery.fileName())); - } else if (gallery.exists()) { - if (!gallery.open(QFile::ReadOnly)) - qFatal("Can't open [%s] for reading.", qPrintable(gallery.fileName())); - } else { - if (!gallery.open(QFile::WriteOnly)) - qFatal("Can't open [%s] for writing.", qPrintable(gallery.fileName())); - } - + if (!gallery.open(QFile::ReadWrite | QFile::Append)) + qFatal("Can't open gallery: %s", qPrintable(gallery.fileName())); stream.setDevice(&gallery); } - bool isUniversal() const - { - return true; - } - TemplateList readBlock(bool *done) { - *done = false; + if (stream.atEnd()) + gallery.seek(0); TemplateList templates; - while (templates.size() < Globals->blockSize) { - if (stream.atEnd()) { - *done = true; - gallery.seek(0); - break; - } - + while ((templates.size() < Globals->blockSize) && !stream.atEnd()) { Template m; stream >> m; templates.append(m); } + + *done = stream.atEnd(); return templates; } @@ -126,11 +105,6 @@ class EmptyGallery : public Gallery QtUtils::touchDir(QDir(file.name)); } - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { *done = true; @@ -180,11 +154,6 @@ class DefaultGallery : public Gallery { Q_OBJECT - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { *done = true; @@ -248,11 +217,6 @@ class memGallery : public Gallery } } - bool isUniversal() const - { - return true; - } - TemplateList readBlock(bool *done) { if (!MemoryGalleries::aligned[file]) { @@ -322,11 +286,6 @@ class csvGallery : public Gallery FileList files; - bool isUniversal() const - { - return false; - } - ~csvGallery() { if (files.isEmpty()) return; @@ -393,11 +352,6 @@ class txtGallery : public Gallery if (!lines.isEmpty()) QtUtils::writeFile(file.name, lines); } - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { *done = true; @@ -429,11 +383,6 @@ class xmlGallery : public Gallery Q_PROPERTY(bool ignoreMetadata READ get_ignoreMetadata WRITE set_ignoreMetadata RESET reset_ignoreMetadata) BR_PROPERTY(bool, ignoreMetadata, false) - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { TemplateList templates; @@ -461,11 +410,6 @@ class dbGallery : public Gallery { Q_OBJECT - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { TemplateList templates; @@ -617,11 +561,6 @@ class googleGallery : public Gallery { Q_OBJECT - bool isUniversal() const - { - return false; - } - TemplateList readBlock(bool *done) { TemplateList templates; -- libgit2 0.21.4