From 93d5daeb94cc51df8e502ce5c6d192081ea45b27 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 17 Apr 2011 17:12:49 +0000 Subject: [PATCH] + next dev. of kiwix-manage --- src/common/kiwix/library.cpp | 50 ++++++++++++++++++++++++++++++ src/common/kiwix/library.h | 60 ++++++++++++++++++++++++++++++++++++ src/common/kiwix/manager.cpp | 20 ++++++++++++ src/common/kiwix/manager.h | 3 ++ 4 files changed, 133 insertions(+) create mode 100644 src/common/kiwix/library.cpp create mode 100644 src/common/kiwix/library.h diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp new file mode 100644 index 000000000..de30f6366 --- /dev/null +++ b/src/common/kiwix/library.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2011 Emmanuel Engelhart + * + * This program 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 + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "library.h" + +namespace kiwix { + + /* Constructor */ + Book::Book(): + id(""), + path(""), + last(""), + indexPath(""), + indexType(XAPIAN) { + } + + /* Destructor */ + Book::~Book() { + } + + /* Constructor */ + Library::Library() { + } + + /* Destructor */ + Library::~Library() { + } + + bool Library::addBook(const Book &book) { + this->books.push_back(book); + return true; + } + +} diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h new file mode 100644 index 000000000..f738aab0c --- /dev/null +++ b/src/common/kiwix/library.h @@ -0,0 +1,60 @@ +/* + * Copyright 2011 Emmanuel Engelhart + * + * This program 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 + * any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_LIBRARY_H +#define KIWIX_LIBRARY_H + +#include +#include + +using namespace std; + +namespace kiwix { + + enum supportedIndexType { XAPIAN, CLUCENE }; + + class Book { + + public: + Book(); + ~Book(); + + string id; + string path; + string last; + string indexPath; + supportedIndexType indexType; + + }; + + class Library { + + public: + Library(); + ~Library(); + + string current; + bool addBook(const Book &book); + vector books; + + }; + +} + +#endif diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index 0f2a128c4..c4bd809c1 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -34,7 +34,27 @@ namespace kiwix { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(path.c_str()); + if (result) { + pugi::xml_node libraryNode = doc.child("library"); + library.current = libraryNode.attribute("current").value(); + + for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) { + kiwix::Book book; + book.id = bookNode.attribute("id").value(); + book.path = bookNode.attribute("path").value(); + book.last = bookNode.attribute("last").value(); + book.indexPath = bookNode.attribute("indexPath").value(); + book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN: CLUCENE; + library.addBook(book); + } + + } + return result; } + kiwix::Library Manager::cloneLibrary() { + return this->library; + } + } diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index 9a4c1f35d..1fc1b3b24 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include "time.h" @@ -39,8 +40,10 @@ namespace kiwix { ~Manager(); bool readFile(const string path); + kiwix::Library cloneLibrary(); protected: + kiwix::Library library; }; }