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
|
||||
{
|
||||
public:
|
||||
Manager();
|
||||
Manager(Library* library);
|
||||
~Manager();
|
||||
|
||||
/**
|
||||
|
@ -214,7 +214,7 @@ class Manager
|
|||
vector<std::string> bookIdList;
|
||||
|
||||
protected:
|
||||
kiwix::Library library;
|
||||
kiwix::Library* library;
|
||||
|
||||
bool readBookFromPath(const string path, Book* book = NULL);
|
||||
bool parseXmlDom(const pugi::xml_document& doc,
|
||||
|
|
|
@ -45,7 +45,7 @@ class OPDSDumper
|
|||
{
|
||||
public:
|
||||
OPDSDumper() = default;
|
||||
OPDSDumper(Library library);
|
||||
OPDSDumper(Library* library);
|
||||
~OPDSDumper();
|
||||
|
||||
/**
|
||||
|
@ -89,10 +89,10 @@ class OPDSDumper
|
|||
*
|
||||
* @param library The library to dump.
|
||||
*/
|
||||
void setLibrary(Library library) { this->library = library; }
|
||||
void setLibrary(Library* library) { this->library = library; }
|
||||
|
||||
protected:
|
||||
kiwix::Library library;
|
||||
kiwix::Library* library;
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string date;
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
namespace kiwix
|
||||
{
|
||||
/* Constructor */
|
||||
Manager::Manager() : writableLibraryPath("")
|
||||
Manager::Manager(Library* library):
|
||||
writableLibraryPath(""),
|
||||
library(library)
|
||||
{
|
||||
}
|
||||
/* Destructor */
|
||||
|
@ -87,7 +89,7 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
|
|||
}
|
||||
|
||||
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 */
|
||||
library.addBook(book);
|
||||
library->addBook(book);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -302,7 +304,7 @@ bool Manager::setBookIndex(const string id,
|
|||
const string path,
|
||||
const supportedIndexType type)
|
||||
try {
|
||||
auto book = library.getBookById(id);
|
||||
auto book = library->getBookById(id);
|
||||
book.setIndexPath(isRelativePath(path)
|
||||
? computeAbsolutePath(
|
||||
removeLastPathElement(writableLibraryPath, true, false),
|
||||
|
@ -316,7 +318,7 @@ try {
|
|||
|
||||
bool Manager::setBookPath(const string id, const string path)
|
||||
try {
|
||||
auto book = library.getBookById(id);
|
||||
auto book = library->getBookById(id);
|
||||
book.setPath(isRelativePath(path)
|
||||
? computeAbsolutePath(
|
||||
removeLastPathElement(writableLibraryPath, true, false),
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
namespace kiwix
|
||||
{
|
||||
/* Constructor */
|
||||
OPDSDumper::OPDSDumper(Library library)
|
||||
OPDSDumper::OPDSDumper(Library* library)
|
||||
: library(library)
|
||||
{
|
||||
}
|
||||
|
@ -110,8 +110,10 @@ string OPDSDumper::dumpOPDSFeed()
|
|||
search_link.append_attribute("href") = searchDescriptionUrl.c_str();
|
||||
}
|
||||
|
||||
for (auto& pair: library.books) {
|
||||
handleBook(pair.second, root_node);
|
||||
if (library) {
|
||||
for (auto& pair: library->books) {
|
||||
handleBook(pair.second, root_node);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeToString(root_node);
|
||||
|
|
Loading…
Reference in New Issue