Initialize Papers, Categories and Vendors in Db.

This commit is contained in:
Jim Evins
2013-11-03 14:45:31 -05:00
parent 6ebc6a3177
commit 21c6b82b04
37 changed files with 10202 additions and 48 deletions
+3
View File
@@ -2,6 +2,8 @@ cmake_minimum_required (VERSION 2.8)
project (libglabels CXX)
configure_file (Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h @ONLY)
set (libglabels_sources
Category.cpp
Paper.cpp
@@ -37,6 +39,7 @@ include (${QT_USE_FILE})
include_directories (
${CMAKE_CURRENT_BINARY_DIR}
)
link_directories (
+36
View File
@@ -0,0 +1,36 @@
/* Config.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_Config_h
#define libglabels_Config_h
namespace libglabels
{
namespace Config
{
const QString PROJECT_SOURCE_DIR = "@glabels_qt_SOURCE_DIR@";
}
}
#endif // libglabels_Config_h
+72 -17
View File
@@ -20,8 +20,14 @@
#include "Db.h"
#include <QApplication>
#include <iostream>
#include "Config.h"
#include "XmlPaperParser.h"
#include "XmlCategoryParser.h"
#include "XmlVendorParser.h"
namespace libglabels
{
@@ -40,7 +46,10 @@ namespace libglabels
Db::Db()
{
// TODO
readPapers();
readCategories();
readVendors();
readTemplates();
}
@@ -499,52 +508,98 @@ namespace libglabels
}
void Db::read_papers()
QDir Db::systemTemplatesDir()
{
// TODO
QDir dir(QApplication::applicationDirPath());
if ( dir.dirName() == "bin" )
{
dir.cdUp();
dir.cd( "share" );
dir.cd( "libglabels-3.0" ); // TODO: install qt version
}
else
{
// Working out of build directory
dir.cd( Config::PROJECT_SOURCE_DIR );
}
dir.cd( "templates" );
return dir;
}
void Db::read_papers_from_dir( const QString &dirName )
void Db::readPapers()
{
// TODO
readPapersFromDir( systemTemplatesDir() );
}
void Db::read_categories()
void Db::readPapersFromDir( const QDir &dir )
{
// TODO
XmlPaperParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
{
if ( fileName == "paper-sizes.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
}
}
}
void Db::read_categories_from_dir( const QString &dirName )
void Db::readCategories()
{
// TODO
readCategoriesFromDir( systemTemplatesDir() );
}
void Db::read_vendors()
void Db::readCategoriesFromDir( const QDir &dir )
{
// TODO
XmlCategoryParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
{
if ( fileName == "categories.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
}
}
}
void Db::read_vendors_from_dir( const QString &dirName )
void Db::readVendors()
{
// TODO
readVendorsFromDir( systemTemplatesDir() );
}
void Db::read_templates()
void Db::readVendorsFromDir( const QDir &dir )
{
// TODO
XmlVendorParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
{
if ( fileName == "vendors.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
}
}
}
void Db::read_templates_from_dir( const QString &dirName )
void Db::readTemplates()
{
readTemplatesFromDir( systemTemplatesDir() );
// TODO: Read user directories
}
void Db::readTemplatesFromDir( const QDir &dir )
{
// TODO
}
}
+11 -8
View File
@@ -24,6 +24,7 @@
#include <QCoreApplication>
#include <QString>
#include <QDir>
#include "Paper.h"
#include "Category.h"
@@ -82,17 +83,19 @@ namespace libglabels
private:
static void read_papers();
static void read_papers_from_dir( const QString &dirName );
static QDir systemTemplatesDir();
static void read_categories();
static void read_categories_from_dir( const QString &dirName );
static void readPapers();
static void readPapersFromDir( const QDir &dir );
static void read_vendors();
static void read_vendors_from_dir( const QString &dirName );
static void readCategories();
static void readCategoriesFromDir( const QDir &dir );
static void read_templates();
static void read_templates_from_dir( const QString &dirName );
static void readVendors();
static void readVendorsFromDir( const QDir &dir );
static void readTemplates();
static void readTemplatesFromDir( const QDir &dir );
private: