Open book from the contentManager.

This commit is contained in:
Matthieu Gautier 2018-10-15 17:44:11 +02:00
parent a6f8bbd6e5
commit 9ce41c06af
5 changed files with 21 additions and 3 deletions

View File

@ -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 }}
</span>
<span>
<button v-if="book.path">Open</button>
<button v-if="book.path" v-on:click="openBook(book)">Open</button>
<button v-else>Download</button>
</span>
</div>

View File

@ -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);
}

View File

@ -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:

View File

@ -64,6 +64,13 @@ std::shared_ptr<kiwix::Reader> 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;
}

View File

@ -26,11 +26,11 @@ class Library : public QObject
public:
Library();
QString openBookFromPath(const QString& zimPath);
QString openBookById(const QString& _id);
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
QStringList getBookIds();
public slots:
QStringList getBookInfos(QString id, const QStringList &keys);
QString openBookById(const QString& _id);
signals:
void booksChanged();