mirror of https://github.com/kiwix/libkiwix.git
+ imp. of kiwix-manage
This commit is contained in:
parent
08bcb43afb
commit
355ca7057e
|
@ -27,7 +27,12 @@ namespace kiwix {
|
||||||
path(""),
|
path(""),
|
||||||
last(""),
|
last(""),
|
||||||
indexPath(""),
|
indexPath(""),
|
||||||
indexType(XAPIAN) {
|
indexType(XAPIAN),
|
||||||
|
title(""),
|
||||||
|
description(""),
|
||||||
|
language(""),
|
||||||
|
date(""),
|
||||||
|
creator("") {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
|
|
|
@ -40,7 +40,11 @@ namespace kiwix {
|
||||||
string last;
|
string last;
|
||||||
string indexPath;
|
string indexPath;
|
||||||
supportedIndexType indexType;
|
supportedIndexType indexType;
|
||||||
|
string title;
|
||||||
|
string description;
|
||||||
|
string language;
|
||||||
|
string creator;
|
||||||
|
string date;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Library {
|
class Library {
|
||||||
|
|
|
@ -45,6 +45,11 @@ namespace kiwix {
|
||||||
book.last = bookNode.attribute("last").value();
|
book.last = bookNode.attribute("last").value();
|
||||||
book.indexPath = bookNode.attribute("indexPath").value();
|
book.indexPath = bookNode.attribute("indexPath").value();
|
||||||
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN: CLUCENE;
|
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN: CLUCENE;
|
||||||
|
book.title = bookNode.attribute("title").value();
|
||||||
|
book.description = bookNode.attribute("description").value();
|
||||||
|
book.language = bookNode.attribute("language").value();
|
||||||
|
book.date = bookNode.attribute("date").value();
|
||||||
|
book.creator = bookNode.attribute("creator").value();
|
||||||
library.addBook(book);
|
library.addBook(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +66,39 @@ namespace kiwix {
|
||||||
libraryNode.append_attribute("current") = library.current.c_str();
|
libraryNode.append_attribute("current") = library.current.c_str();
|
||||||
|
|
||||||
/* Add each book */
|
/* Add each book */
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
pugi::xml_node bookNode = libraryNode.append_child("book");
|
||||||
|
bookNode.append_attribute("id") = itr->id.c_str();
|
||||||
|
bookNode.append_attribute("path") = itr->path.c_str();
|
||||||
|
|
||||||
|
if (itr->last != "")
|
||||||
|
bookNode.append_attribute("last") = itr->last.c_str();
|
||||||
|
|
||||||
|
if (itr->indexPath != "") {
|
||||||
|
bookNode.append_attribute("indexPath") = itr->indexPath.c_str();
|
||||||
|
if (itr->indexType == XAPIAN)
|
||||||
|
bookNode.append_attribute("indexType") = "xapian";
|
||||||
|
else
|
||||||
|
bookNode.append_attribute("indexType") = "clucene";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itr->title != "")
|
||||||
|
bookNode.append_attribute("title") = itr->title.c_str();
|
||||||
|
|
||||||
|
if (itr->description != "")
|
||||||
|
bookNode.append_attribute("description") = itr->description.c_str();
|
||||||
|
|
||||||
|
if (itr->language != "")
|
||||||
|
bookNode.append_attribute("language") = itr->language.c_str();
|
||||||
|
|
||||||
|
if (itr->date != "")
|
||||||
|
bookNode.append_attribute("date") = itr->date.c_str();
|
||||||
|
|
||||||
|
if (itr->creator != "")
|
||||||
|
bookNode.append_attribute("creator") = itr->creator.c_str();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* saving file */
|
/* saving file */
|
||||||
doc.save_file(path.c_str());
|
doc.save_file(path.c_str());
|
||||||
|
@ -68,6 +106,22 @@ namespace kiwix {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Manager::addBookFromPath(const string path) {
|
||||||
|
kiwix::Book book;
|
||||||
|
|
||||||
|
/* Open the ZIM file */
|
||||||
|
kiwix::Reader reader = kiwix::Reader(path);
|
||||||
|
book.path = path;
|
||||||
|
book.id = reader.getId();
|
||||||
|
book.title = reader.getTitle();
|
||||||
|
book.description = reader.getDescription();
|
||||||
|
book.language = reader.getLanguage();
|
||||||
|
book.date = reader.getDate();
|
||||||
|
book.creator = reader.getCreator();
|
||||||
|
library.addBook(book);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Manager::removeBookByIndex(const unsigned int bookIndex) {
|
bool Manager::removeBookByIndex(const unsigned int bookIndex) {
|
||||||
return this->library.removeBookByIndex(bookIndex);
|
return this->library.removeBookByIndex(bookIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,8 @@
|
||||||
#ifndef KIWIX_MANAGER_H
|
#ifndef KIWIX_MANAGER_H
|
||||||
#define KIWIX_MANAGER_H
|
#define KIWIX_MANAGER_H
|
||||||
|
|
||||||
#include <zim/zim.h>
|
|
||||||
#include <zim/file.h>
|
|
||||||
#include <zim/article.h>
|
|
||||||
#include <zim/fileiterator.h>
|
|
||||||
#include <kiwix/library.h>
|
#include <kiwix/library.h>
|
||||||
|
#include <kiwix/reader.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
@ -42,6 +39,7 @@ namespace kiwix {
|
||||||
bool readFile(const string path);
|
bool readFile(const string path);
|
||||||
bool writeFile(const string path);
|
bool writeFile(const string path);
|
||||||
bool removeBookByIndex(const unsigned int bookIndex);
|
bool removeBookByIndex(const unsigned int bookIndex);
|
||||||
|
bool addBookFromPath(const string path);
|
||||||
kiwix::Library cloneLibrary();
|
kiwix::Library cloneLibrary();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -133,6 +133,36 @@ namespace kiwix {
|
||||||
contentLength, contentType);
|
contentLength, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Reader::getTitle() {
|
||||||
|
string value="";
|
||||||
|
this->getMetatag("Title", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Reader::getDescription() {
|
||||||
|
string value="";
|
||||||
|
this->getMetatag("Description", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Reader::getLanguage() {
|
||||||
|
string value="";
|
||||||
|
this->getMetatag("Language", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Reader::getDate() {
|
||||||
|
string value="";
|
||||||
|
this->getMetatag("Date", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Reader::getCreator() {
|
||||||
|
string value="";
|
||||||
|
this->getMetatag("Creator", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the first page URL */
|
/* Return the first page URL */
|
||||||
string Reader::getFirstPageUrl() {
|
string Reader::getFirstPageUrl() {
|
||||||
string url = "";
|
string url = "";
|
||||||
|
|
|
@ -45,6 +45,11 @@ namespace kiwix {
|
||||||
string getFirstPageUrl();
|
string getFirstPageUrl();
|
||||||
string getMainPageUrl();
|
string getMainPageUrl();
|
||||||
bool getMetatag(const string &url, string &content);
|
bool getMetatag(const string &url, string &content);
|
||||||
|
string getTitle();
|
||||||
|
string getDescription();
|
||||||
|
string getLanguage();
|
||||||
|
string getDate();
|
||||||
|
string getCreator();
|
||||||
bool getPageUrlFromTitle(const string &title, string &url);
|
bool getPageUrlFromTitle(const string &title, string &url);
|
||||||
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
||||||
bool searchSuggestions(const string &prefix, unsigned int suggestionsCount);
|
bool searchSuggestions(const string &prefix, unsigned int suggestionsCount);
|
||||||
|
|
Loading…
Reference in New Issue