mirror of https://github.com/kiwix/libkiwix.git
+ next dev. of kiwix-manage
This commit is contained in:
parent
2fae9e3b71
commit
93d5daeb94
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* 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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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 <kiwix::Book> books;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -34,7 +34,27 @@ namespace kiwix {
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kiwix::Library Manager::cloneLibrary() {
|
||||||
|
return this->library;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
#include <zim/article.h>
|
#include <zim/article.h>
|
||||||
#include <zim/fileiterator.h>
|
#include <zim/fileiterator.h>
|
||||||
|
#include <kiwix/library.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
@ -39,8 +40,10 @@ namespace kiwix {
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
bool readFile(const string path);
|
bool readFile(const string path);
|
||||||
|
kiwix::Library cloneLibrary();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
kiwix::Library library;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue