mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Addressed libkiwix API changes
Fixed the build failure caused by the libkiwix API changes done in kiwix/libkiwix#636.
This commit is contained in:
parent
643a35a996
commit
9c467d7d69
@ -50,7 +50,7 @@ QStringList ContentManager::getTranslations(const QStringList &keys)
|
|||||||
QStringList ContentManager::getBookInfos(QString id, const QStringList &keys)
|
QStringList ContentManager::getBookInfos(QString id, const QStringList &keys)
|
||||||
{
|
{
|
||||||
QStringList values;
|
QStringList values;
|
||||||
kiwix::Book* b = [=]()->kiwix::Book* {
|
const kiwix::Book* b = [=]()->const kiwix::Book* {
|
||||||
try {
|
try {
|
||||||
return &mp_library->getBookById(id);
|
return &mp_library->getBookById(id);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -137,7 +137,9 @@ QStringList ContentManager::updateDownloadInfos(QString id, const QStringList &k
|
|||||||
try {
|
try {
|
||||||
d = mp_downloader->getDownload(b.getDownloadId());
|
d = mp_downloader->getDownload(b.getDownloadId());
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
b.setDownloadId("");
|
kiwix::Book bCopy(b);
|
||||||
|
bCopy.setDownloadId("");
|
||||||
|
mp_library->getKiwixLibrary().addOrUpdateBook(bCopy);
|
||||||
mp_library->save();
|
mp_library->save();
|
||||||
emit(mp_library->booksChanged());
|
emit(mp_library->booksChanged());
|
||||||
return values;
|
return values;
|
||||||
@ -146,11 +148,13 @@ QStringList ContentManager::updateDownloadInfos(QString id, const QStringList &k
|
|||||||
d->updateStatus(true);
|
d->updateStatus(true);
|
||||||
if (d->getStatus() == kiwix::Download::K_COMPLETE) {
|
if (d->getStatus() == kiwix::Download::K_COMPLETE) {
|
||||||
QString tmp(QString::fromStdString(d->getPath()));
|
QString tmp(QString::fromStdString(d->getPath()));
|
||||||
b.setPath(QDir::toNativeSeparators(tmp).toStdString());
|
kiwix::Book bCopy(b);
|
||||||
b.setDownloadId("");
|
bCopy.setPath(QDir::toNativeSeparators(tmp).toStdString());
|
||||||
b.setPathValid(true);
|
bCopy.setDownloadId("");
|
||||||
|
bCopy.setPathValid(true);
|
||||||
// removing book url so that download link in kiwix-serve is not displayed.
|
// removing book url so that download link in kiwix-serve is not displayed.
|
||||||
b.setUrl("");
|
bCopy.setUrl("");
|
||||||
|
mp_library->getKiwixLibrary().addOrUpdateBook(bCopy);
|
||||||
mp_library->save();
|
mp_library->save();
|
||||||
mp_library->bookmarksChanged();
|
mp_library->bookmarksChanged();
|
||||||
if (!m_local) {
|
if (!m_local) {
|
||||||
@ -209,7 +213,7 @@ QString ContentManager::downloadBook(const QString &id)
|
|||||||
{
|
{
|
||||||
if (!mp_downloader)
|
if (!mp_downloader)
|
||||||
return "";
|
return "";
|
||||||
auto& book = [&]()->kiwix::Book& {
|
const auto& book = [&]()->const kiwix::Book& {
|
||||||
try {
|
try {
|
||||||
return m_remoteLibrary.getBookById(id.toStdString());
|
return m_remoteLibrary.getBookById(id.toStdString());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -233,8 +237,9 @@ QString ContentManager::downloadBook(const QString &id)
|
|||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
book.setDownloadId(download->getDid());
|
kiwix::Book bookCopy(book);
|
||||||
mp_library->addBookToLibrary(book);
|
bookCopy.setDownloadId(download->getDid());
|
||||||
|
mp_library->addBookToLibrary(bookCopy);
|
||||||
mp_library->save();
|
mp_library->save();
|
||||||
emit(oneBookChanged(id));
|
emit(oneBookChanged(id));
|
||||||
return QString::fromStdString(download->getDid());
|
return QString::fromStdString(download->getDid());
|
||||||
|
@ -15,47 +15,6 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// KiwixApp::NameMapperProxy
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
KiwixApp::NameMapperProxy::NameMapperProxy(kiwix::Library& lib)
|
|
||||||
: library(lib)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void KiwixApp::NameMapperProxy::update()
|
|
||||||
{
|
|
||||||
const auto newNameMapper = new kiwix::HumanReadableNameMapper(library, false);
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
|
||||||
nameMapper.reset(newNameMapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
KiwixApp::NameMapperProxy::NameMapperHandle
|
|
||||||
KiwixApp::NameMapperProxy::currentNameMapper() const
|
|
||||||
{
|
|
||||||
// Return a copy of the handle to the current NameMapper object. It will
|
|
||||||
// ensure that the object survives any call to NameMapperProxy::update()
|
|
||||||
// made before the completion of any pending operation on that object.
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
|
||||||
return nameMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string KiwixApp::NameMapperProxy::getNameForId(const std::string& id)
|
|
||||||
{
|
|
||||||
// Ensure that the current nameMapper object survives a concurrent call
|
|
||||||
// to NameMapperProxy::update()
|
|
||||||
return currentNameMapper()->getNameForId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string KiwixApp::NameMapperProxy::getIdForName(const std::string& name)
|
|
||||||
{
|
|
||||||
// Ensure that the current nameMapper object survives a concurrent call
|
|
||||||
// to NameMapperProxy::update()
|
|
||||||
return currentNameMapper()->getIdForName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// KiwixApp
|
// KiwixApp
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -68,7 +27,7 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
|
|||||||
mp_downloader(nullptr),
|
mp_downloader(nullptr),
|
||||||
mp_manager(nullptr),
|
mp_manager(nullptr),
|
||||||
mp_mainWindow(nullptr),
|
mp_mainWindow(nullptr),
|
||||||
m_nameMapper(m_library.getKiwixLibrary()),
|
m_nameMapper(m_library.getKiwixLibrary(), false),
|
||||||
m_server(&m_library.getKiwixLibrary(), &m_nameMapper)
|
m_server(&m_library.getKiwixLibrary(), &m_nameMapper)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -106,27 +106,6 @@ protected:
|
|||||||
void createAction();
|
void createAction();
|
||||||
void postInit();
|
void postInit();
|
||||||
|
|
||||||
private: // types
|
|
||||||
class NameMapperProxy : public kiwix::NameMapper {
|
|
||||||
typedef std::shared_ptr<kiwix::NameMapper> NameMapperHandle;
|
|
||||||
public:
|
|
||||||
explicit NameMapperProxy(kiwix::Library& library);
|
|
||||||
|
|
||||||
virtual std::string getNameForId(const std::string& id);
|
|
||||||
virtual std::string getIdForName(const std::string& name);
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
private:
|
|
||||||
NameMapperHandle currentNameMapper() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
mutable std::mutex mutex;
|
|
||||||
kiwix::Library& library;
|
|
||||||
NameMapperHandle nameMapper;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTranslator m_qtTranslator, m_appTranslator;
|
QTranslator m_qtTranslator, m_appTranslator;
|
||||||
SettingsManager m_settingsManager;
|
SettingsManager m_settingsManager;
|
||||||
@ -139,7 +118,7 @@ private:
|
|||||||
TabBar* mp_tabWidget;
|
TabBar* mp_tabWidget;
|
||||||
SideBarType m_currentSideType;
|
SideBarType m_currentSideType;
|
||||||
QErrorMessage* mp_errorDialog;
|
QErrorMessage* mp_errorDialog;
|
||||||
NameMapperProxy m_nameMapper;
|
kiwix::UpdatableNameMapper m_nameMapper;
|
||||||
kiwix::Server m_server;
|
kiwix::Server m_server;
|
||||||
Translation m_translation;
|
Translation m_translation;
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
class LibraryManipulator: public kiwix::LibraryManipulator {
|
class LibraryManipulator: public kiwix::LibraryManipulator {
|
||||||
public:
|
public:
|
||||||
LibraryManipulator(Library* p_library)
|
LibraryManipulator(Library* p_library)
|
||||||
: mp_library(p_library) {}
|
: kiwix::LibraryManipulator(&p_library->getKiwixLibrary())
|
||||||
|
, mp_library(p_library)
|
||||||
|
{}
|
||||||
virtual ~LibraryManipulator() {}
|
virtual ~LibraryManipulator() {}
|
||||||
bool addBookToLibrary(kiwix::Book book) {
|
bool addBookToLibrary(kiwix::Book book) {
|
||||||
auto ret = mp_library->m_library.addBook(book);
|
auto ret = mp_library->m_library.addBook(book);
|
||||||
@ -118,7 +120,7 @@ void Library::save()
|
|||||||
m_library.writeBookmarksToFile(kiwix::appendToDirectory(m_libraryDirectory.toStdString(), "library.bookmarks.xml"));
|
m_library.writeBookmarksToFile(kiwix::appendToDirectory(m_libraryDirectory.toStdString(), "library.bookmarks.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
kiwix::Book &Library::getBookById(QString id)
|
const kiwix::Book &Library::getBookById(QString id) const
|
||||||
{
|
{
|
||||||
return m_library.getBookById(id.toStdString());
|
return m_library.getBookById(id.toStdString());
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
void save();
|
void save();
|
||||||
kiwix::Library& getKiwixLibrary() { return m_library; }
|
kiwix::Library& getKiwixLibrary() { return m_library; }
|
||||||
public slots:
|
public slots:
|
||||||
kiwix::Book& getBookById(QString id);
|
const kiwix::Book& getBookById(QString id) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void booksChanged();
|
void booksChanged();
|
||||||
|
@ -78,8 +78,8 @@ UrlSchemeHandler::handleMetaRequest(QWebEngineUrlRequestJob* request)
|
|||||||
|
|
||||||
|
|
||||||
class IdNameMapper : public kiwix::NameMapper {
|
class IdNameMapper : public kiwix::NameMapper {
|
||||||
std::string getNameForId(const std::string& id) { return id + ".zim"; }
|
std::string getNameForId(const std::string& id) const { return id + ".zim"; }
|
||||||
std::string getIdForName(const std::string& id) { return id.substr(0, id.size()-4); }
|
std::string getIdForName(const std::string& id) const { return id.substr(0, id.size()-4); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user