mirror of https://github.com/kiwix/libkiwix.git
Do not make the `Manager` responsible to create the `Library`.
The `Manager` manage a library already existing. This avoid the Library clone stuff.
This commit is contained in:
parent
bba3c252e4
commit
efae3e0d2f
|
@ -48,7 +48,7 @@ enum supportedListSortBy { TITLE, SIZE, DATE, CREATOR, PUBLISHER };
|
||||||
class Manager
|
class Manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager(Library* library);
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,7 +214,7 @@ class Manager
|
||||||
vector<std::string> bookIdList;
|
vector<std::string> bookIdList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library* library;
|
||||||
|
|
||||||
bool readBookFromPath(const string path, Book* book = NULL);
|
bool readBookFromPath(const string path, Book* book = NULL);
|
||||||
bool parseXmlDom(const pugi::xml_document& doc,
|
bool parseXmlDom(const pugi::xml_document& doc,
|
||||||
|
|
|
@ -45,7 +45,7 @@ class OPDSDumper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OPDSDumper() = default;
|
OPDSDumper() = default;
|
||||||
OPDSDumper(Library library);
|
OPDSDumper(Library* library);
|
||||||
~OPDSDumper();
|
~OPDSDumper();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,10 +89,10 @@ class OPDSDumper
|
||||||
*
|
*
|
||||||
* @param library The library to dump.
|
* @param library The library to dump.
|
||||||
*/
|
*/
|
||||||
void setLibrary(Library library) { this->library = library; }
|
void setLibrary(Library* library) { this->library = library; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library* library;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string date;
|
std::string date;
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
{
|
{
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Manager::Manager() : writableLibraryPath("")
|
Manager::Manager(Library* library):
|
||||||
|
writableLibraryPath(""),
|
||||||
|
library(library)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
|
@ -87,7 +89,7 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
library.addBook(book);
|
library->addBook(book);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +150,7 @@ bool Manager::parseOpdsDom(const pugi::xml_document& doc, const std::string& url
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the book properties with the new importer */
|
/* Update the book properties with the new importer */
|
||||||
library.addBook(book);
|
library->addBook(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -302,7 +304,7 @@ bool Manager::setBookIndex(const string id,
|
||||||
const string path,
|
const string path,
|
||||||
const supportedIndexType type)
|
const supportedIndexType type)
|
||||||
try {
|
try {
|
||||||
auto book = library.getBookById(id);
|
auto book = library->getBookById(id);
|
||||||
book.setIndexPath(isRelativePath(path)
|
book.setIndexPath(isRelativePath(path)
|
||||||
? computeAbsolutePath(
|
? computeAbsolutePath(
|
||||||
removeLastPathElement(writableLibraryPath, true, false),
|
removeLastPathElement(writableLibraryPath, true, false),
|
||||||
|
@ -316,7 +318,7 @@ try {
|
||||||
|
|
||||||
bool Manager::setBookPath(const string id, const string path)
|
bool Manager::setBookPath(const string id, const string path)
|
||||||
try {
|
try {
|
||||||
auto book = library.getBookById(id);
|
auto book = library->getBookById(id);
|
||||||
book.setPath(isRelativePath(path)
|
book.setPath(isRelativePath(path)
|
||||||
? computeAbsolutePath(
|
? computeAbsolutePath(
|
||||||
removeLastPathElement(writableLibraryPath, true, false),
|
removeLastPathElement(writableLibraryPath, true, false),
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
{
|
{
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
OPDSDumper::OPDSDumper(Library library)
|
OPDSDumper::OPDSDumper(Library* library)
|
||||||
: library(library)
|
: library(library)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,10 @@ string OPDSDumper::dumpOPDSFeed()
|
||||||
search_link.append_attribute("href") = searchDescriptionUrl.c_str();
|
search_link.append_attribute("href") = searchDescriptionUrl.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& pair: library.books) {
|
if (library) {
|
||||||
handleBook(pair.second, root_node);
|
for (auto& pair: library->books) {
|
||||||
|
handleBook(pair.second, root_node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeToString(root_node);
|
return nodeToString(root_node);
|
||||||
|
|
Loading…
Reference in New Issue