diff --git a/resources/texts/_contentManager.html b/resources/texts/_contentManager.html
index a7fbefa..e025104 100644
--- a/resources/texts/_contentManager.html
+++ b/resources/texts/_contentManager.html
@@ -25,14 +25,19 @@ function init() {
new QWebChannel(qt.webChannelTransport, function(channel) {
contentManager = channel.objects.contentManager;
library = channel.objects.library;
+ kiwix = channel.objects.kiwix;
app = new Vue({
el: "#app",
data: {
contentManager: contentManager,
library: library,
+ kiwix: kiwix,
books: []
},
methods: {
+ openBook : function(book) {
+ kiwix.openUrl("zim://"+book.id+".zim/", true, function() {});
+ },
changePage : function(delta) {
var newPage = contentManager.currentPage+delta;
if (newPage < 0) newPage = 0;
@@ -90,7 +95,7 @@ function init() {
{{ book.tags }}
-
+
diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp
index 3b5cd53..87f6080 100644
--- a/src/kiwixapp.cpp
+++ b/src/kiwixapp.cpp
@@ -72,6 +72,7 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
mp_mainWindow = new MainWindow;
mp_tabWidget = mp_mainWindow->getTabWidget();
mp_tabWidget->setContentManagerView(m_manager.getView());
+ m_manager.getView()->registerObject("kiwix", this);
postInit();
mp_errorDialog = new QErrorMessage(mp_mainWindow);
@@ -133,6 +134,10 @@ void KiwixApp::printPage()
}
}
+void KiwixApp::openUrl(const QString &url, bool newTab) {
+ openUrl(QUrl(url), newTab);
+}
+
void KiwixApp::openUrl(const QUrl &url, bool newTab) {
mp_tabWidget->openUrl(url, newTab);
}
diff --git a/src/kiwixapp.h b/src/kiwixapp.h
index 331a329..d3b640c 100644
--- a/src/kiwixapp.h
+++ b/src/kiwixapp.h
@@ -53,7 +53,6 @@ public:
virtual ~KiwixApp();
static KiwixApp* instance();
- void openUrl(const QUrl& url, bool newTab=true);
void openRandomUrl(bool newTab=true);
void showMessage(const QString& message);
@@ -67,6 +66,8 @@ public:
public slots:
void openZimFile(const QString& zimfile="");
+ void openUrl(const QString& url, bool newTab=true);
+ void openUrl(const QUrl& url, bool newTab=true);
void printPage();
protected:
diff --git a/src/library.cpp b/src/library.cpp
index 48dae22..b2f81cd 100644
--- a/src/library.cpp
+++ b/src/library.cpp
@@ -64,6 +64,13 @@ std::shared_ptr Library::getReader(const QString &zimId)
auto it = m_readersMap.find(zimId);
if (it != m_readersMap.end())
return it.value();
+ // No reader, try to open the file
+ try {
+ QString _id = zimId;
+ if (_id.endsWith(".zim")) _id.resize(_id.size()-4);
+ openBookById(_id);
+ return m_readersMap.find(zimId).value();
+ } catch(...) {}
return nullptr;
}
diff --git a/src/library.h b/src/library.h
index ad1b6b9..1be5b74 100644
--- a/src/library.h
+++ b/src/library.h
@@ -26,11 +26,11 @@ class Library : public QObject
public:
Library();
QString openBookFromPath(const QString& zimPath);
- QString openBookById(const QString& _id);
std::shared_ptr getReader(const QString& zimId);
QStringList getBookIds();
public slots:
QStringList getBookInfos(QString id, const QStringList &keys);
+ QString openBookById(const QString& _id);
signals:
void booksChanged();