diff --git a/app/glabels_main.cpp b/app/glabels_main.cpp index 7764ce3..868a6f5 100644 --- a/app/glabels_main.cpp +++ b/app/glabels_main.cpp @@ -24,12 +24,6 @@ #include "MainWindow.h" #include "libglabels/Db.h" -////// TEMPORARY TESTING //////// -#include "libglabels/XmlPaperParser.h" -#include "libglabels/XmlCategoryParser.h" -#include "libglabels/XmlVendorParser.h" -///////////////////////////////// - using namespace gLabels; using namespace libglabels; @@ -44,23 +38,10 @@ int main( int argc, char **argv ) Db::init(); ////// TEMPORARY TESTING //////// - { - XmlPaperParser parser; - parser.readFile( "/usr/local/share/libglabels-3.0/templates/paper-sizes.xml" ); - Db::printKnownPapers(); - } - - { - XmlCategoryParser parser; - parser.readFile( "/usr/local/share/libglabels-3.0/templates/categories.xml" ); - Db::printKnownCategories(); - } - - { - XmlVendorParser parser; - parser.readFile( "/usr/local/share/libglabels-3.0/templates/vendors.xml" ); - Db::printKnownVendors(); - } + Db::printKnownPapers(); + Db::printKnownCategories(); + Db::printKnownVendors(); + Db::printKnownTemplates(); ///////////////////////////////// MainWindow mainWin; diff --git a/libglabels/CMakeLists.txt b/libglabels/CMakeLists.txt index 9d2fbed..adb8519 100644 --- a/libglabels/CMakeLists.txt +++ b/libglabels/CMakeLists.txt @@ -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 ( diff --git a/libglabels/Config.h.in b/libglabels/Config.h.in new file mode 100644 index 0000000..71af495 --- /dev/null +++ b/libglabels/Config.h.in @@ -0,0 +1,36 @@ +/* Config.h + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#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 diff --git a/libglabels/Db.cpp b/libglabels/Db.cpp index fa3ea18..cadb2c8 100644 --- a/libglabels/Db.cpp +++ b/libglabels/Db.cpp @@ -20,8 +20,14 @@ #include "Db.h" +#include #include +#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 } - } diff --git a/libglabels/Db.h b/libglabels/Db.h index 96200a0..1bcccff 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -24,6 +24,7 @@ #include #include +#include #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: diff --git a/templates/ascom-iso-templates.xml b/templates/ascom-iso-templates.xml new file mode 100644 index 0000000..57534cf --- /dev/null +++ b/templates/ascom-iso-templates.xml @@ -0,0 +1,353 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +