Added initial implementation of Db.
This commit is contained in:
+121
@@ -0,0 +1,121 @@
|
||||
/* Db.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef libglabels_Db_h
|
||||
#define libglabels_Db_h
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "Paper.h"
|
||||
#include "Category.h"
|
||||
#include "Vendor.h"
|
||||
#include "Template.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
class Db : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
signals:
|
||||
static void changed();
|
||||
|
||||
|
||||
private:
|
||||
Db();
|
||||
|
||||
|
||||
public:
|
||||
static Db *instance() { return new Db; }
|
||||
|
||||
static void registerPaper( Paper *paper );
|
||||
static const Paper *lookupPaperFromName( const QString &name );
|
||||
static const Paper *lookupPaperFromId( const QString &id );
|
||||
static const QString &lookupPaperIdFromName( const QString &name );
|
||||
static const QString &lookupPaperNameFromId( const QString &id );
|
||||
static bool isPaperIdKnown( const QString &id );
|
||||
static bool isPaperIdOther( const QString &id );
|
||||
|
||||
static void registerCategory( Category *category );
|
||||
static const Category *lookupCategoryFromName( const QString &name );
|
||||
static const Category *lookupCategoryFromId( const QString &id );
|
||||
static const QString &lookupCategoryIdFromName( const QString &name );
|
||||
static const QString &lookupCategoryNameFromId( const QString &id );
|
||||
static bool isCategoryIdKnown( const QString &id );
|
||||
|
||||
static void registerVendor( Vendor *vendor );
|
||||
static const Vendor *lookupVendorFromName( const QString &name );
|
||||
static const QString &lookupVendorUrlFromName( const QString &name );
|
||||
static bool isVendorNameKnown( const QString &id );
|
||||
|
||||
static void registerTemplate( Template *tmplate );
|
||||
static const Template *lookupTemplateFromName( const QString &name );
|
||||
static const Template *lookupTemplateFromBrandPart( const QString &brand, const QString &part );
|
||||
static bool isTemplateKnown( const QString &brand, const QString &part );
|
||||
|
||||
static void registerUserTemplate( Template *tmplate );
|
||||
static void deleteUserTemplateByName( const QString &name );
|
||||
static void deleteUserTemplateByBrandPart( const QString &brand, const QString &part );
|
||||
|
||||
static void printKnownPapers();
|
||||
static void printKnownCategories();
|
||||
static void printKnownVendors();
|
||||
static void printKnownTemplates();
|
||||
|
||||
|
||||
private:
|
||||
static void read_papers();
|
||||
static void read_papers_from_dir( const QString &dirName );
|
||||
|
||||
static void read_categories();
|
||||
static void read_categories_from_dir( const QString &dirName );
|
||||
|
||||
static void read_vendors();
|
||||
static void read_vendors_from_dir( const QString &dirName );
|
||||
|
||||
static void read_templates();
|
||||
static void read_templates_from_dir( const QString &dirName );
|
||||
|
||||
|
||||
private:
|
||||
static std::list<Paper *> mPapers;
|
||||
static std::list<QString> mPaperIds;
|
||||
static std::list<QString> mPaperNames;
|
||||
|
||||
static std::list<Category *> mCategories;
|
||||
static std::list<QString> mCategoryIds;
|
||||
static std::list<QString> mCategoryNames;
|
||||
|
||||
static std::list<Vendor *> mVendors;
|
||||
static std::list<QString> mVendorNames;
|
||||
|
||||
static std::list<Template *> mTemplates;
|
||||
|
||||
static QString mEmpty;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // libglabels_Db_h
|
||||
Reference in New Issue
Block a user