mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merge pull request #714 from kiwix/uptodate_name_mapper
This commit is contained in:
commit
7c0a249493
@ -15,6 +15,51 @@
|
||||
#include <thread>
|
||||
#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::KiwixApp(int& argc, char *argv[])
|
||||
: QtSingleApplication("kiwix-desktop", argc, argv),
|
||||
m_profile(),
|
||||
@ -23,7 +68,7 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
|
||||
mp_downloader(nullptr),
|
||||
mp_manager(nullptr),
|
||||
mp_mainWindow(nullptr),
|
||||
m_nameMapper(m_library.getKiwixLibrary(), false),
|
||||
m_nameMapper(m_library.getKiwixLibrary()),
|
||||
m_server(&m_library.getKiwixLibrary(), &m_nameMapper)
|
||||
{
|
||||
try {
|
||||
@ -411,6 +456,7 @@ void KiwixApp::postInit() {
|
||||
[=](const QString& title) { emit currentTitleChanged(title); });
|
||||
connect(mp_tabWidget, &TabBar::libraryPageDisplayed, this, &KiwixApp::disableItemsOnLibraryPage);
|
||||
emit(m_library.booksChanged());
|
||||
connect(&m_library, &Library::booksChanged, this, &KiwixApp::updateNameMapper);
|
||||
disableItemsOnLibraryPage(true);
|
||||
}
|
||||
|
||||
@ -422,3 +468,8 @@ void KiwixApp::disableItemsOnLibraryPage(bool libraryDisplayed)
|
||||
KiwixApp::instance()->getAction(KiwixApp::ZoomOutAction)->setDisabled(libraryDisplayed);
|
||||
KiwixApp::instance()->getAction(KiwixApp::ZoomResetAction)->setDisabled(libraryDisplayed);
|
||||
}
|
||||
|
||||
void KiwixApp::updateNameMapper()
|
||||
{
|
||||
m_nameMapper.update();
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <QTranslator>
|
||||
#include <kiwix/name_mapper.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class KiwixApp : public QtSingleApplication
|
||||
{
|
||||
@ -99,11 +101,33 @@ public slots:
|
||||
void toggleSideBar(KiwixApp::SideBarType type);
|
||||
void printPage();
|
||||
void disableItemsOnLibraryPage(bool displayed);
|
||||
void updateNameMapper();
|
||||
|
||||
protected:
|
||||
void createAction();
|
||||
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:
|
||||
QTranslator m_qtTranslator, m_appTranslator;
|
||||
SettingsManager m_settingsManager;
|
||||
@ -116,7 +140,7 @@ private:
|
||||
TabBar* mp_tabWidget;
|
||||
SideBarType m_currentSideType;
|
||||
QErrorMessage* mp_errorDialog;
|
||||
kiwix::HumanReadableNameMapper m_nameMapper;
|
||||
NameMapperProxy m_nameMapper;
|
||||
kiwix::Server m_server;
|
||||
Translation m_translation;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user