mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Open book from the contentManager.
This commit is contained in:
parent
a6f8bbd6e5
commit
9ce41c06af
@ -25,14 +25,19 @@ function init() {
|
|||||||
new QWebChannel(qt.webChannelTransport, function(channel) {
|
new QWebChannel(qt.webChannelTransport, function(channel) {
|
||||||
contentManager = channel.objects.contentManager;
|
contentManager = channel.objects.contentManager;
|
||||||
library = channel.objects.library;
|
library = channel.objects.library;
|
||||||
|
kiwix = channel.objects.kiwix;
|
||||||
app = new Vue({
|
app = new Vue({
|
||||||
el: "#app",
|
el: "#app",
|
||||||
data: {
|
data: {
|
||||||
contentManager: contentManager,
|
contentManager: contentManager,
|
||||||
library: library,
|
library: library,
|
||||||
|
kiwix: kiwix,
|
||||||
books: []
|
books: []
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
openBook : function(book) {
|
||||||
|
kiwix.openUrl("zim://"+book.id+".zim/", true, function() {});
|
||||||
|
},
|
||||||
changePage : function(delta) {
|
changePage : function(delta) {
|
||||||
var newPage = contentManager.currentPage+delta;
|
var newPage = contentManager.currentPage+delta;
|
||||||
if (newPage < 0) newPage = 0;
|
if (newPage < 0) newPage = 0;
|
||||||
@ -90,7 +95,7 @@ function init() {
|
|||||||
{{ book.tags }}
|
{{ book.tags }}
|
||||||
</span>
|
</span>
|
||||||
<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>
|
<button v-else>Download</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,6 +72,7 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
|
|||||||
mp_mainWindow = new MainWindow;
|
mp_mainWindow = new MainWindow;
|
||||||
mp_tabWidget = mp_mainWindow->getTabWidget();
|
mp_tabWidget = mp_mainWindow->getTabWidget();
|
||||||
mp_tabWidget->setContentManagerView(m_manager.getView());
|
mp_tabWidget->setContentManagerView(m_manager.getView());
|
||||||
|
m_manager.getView()->registerObject("kiwix", this);
|
||||||
postInit();
|
postInit();
|
||||||
|
|
||||||
mp_errorDialog = new QErrorMessage(mp_mainWindow);
|
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) {
|
void KiwixApp::openUrl(const QUrl &url, bool newTab) {
|
||||||
mp_tabWidget->openUrl(url, newTab);
|
mp_tabWidget->openUrl(url, newTab);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
virtual ~KiwixApp();
|
virtual ~KiwixApp();
|
||||||
static KiwixApp* instance();
|
static KiwixApp* instance();
|
||||||
|
|
||||||
void openUrl(const QUrl& url, bool newTab=true);
|
|
||||||
void openRandomUrl(bool newTab=true);
|
void openRandomUrl(bool newTab=true);
|
||||||
|
|
||||||
void showMessage(const QString& message);
|
void showMessage(const QString& message);
|
||||||
@ -67,6 +66,8 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void openZimFile(const QString& zimfile="");
|
void openZimFile(const QString& zimfile="");
|
||||||
|
void openUrl(const QString& url, bool newTab=true);
|
||||||
|
void openUrl(const QUrl& url, bool newTab=true);
|
||||||
void printPage();
|
void printPage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -64,6 +64,13 @@ std::shared_ptr<kiwix::Reader> Library::getReader(const QString &zimId)
|
|||||||
auto it = m_readersMap.find(zimId);
|
auto it = m_readersMap.find(zimId);
|
||||||
if (it != m_readersMap.end())
|
if (it != m_readersMap.end())
|
||||||
return it.value();
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ class Library : public QObject
|
|||||||
public:
|
public:
|
||||||
Library();
|
Library();
|
||||||
QString openBookFromPath(const QString& zimPath);
|
QString openBookFromPath(const QString& zimPath);
|
||||||
QString openBookById(const QString& _id);
|
|
||||||
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
|
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
|
||||||
QStringList getBookIds();
|
QStringList getBookIds();
|
||||||
public slots:
|
public slots:
|
||||||
QStringList getBookInfos(QString id, const QStringList &keys);
|
QStringList getBookInfos(QString id, const QStringList &keys);
|
||||||
|
QString openBookById(const QString& _id);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void booksChanged();
|
void booksChanged();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user