Connect RandomArticleAction.

This commit is contained in:
Matthieu Gautier 2018-07-26 14:49:33 +02:00
parent 15f1492d96
commit f8c6f18c0a
2 changed files with 19 additions and 1 deletions

View File

@ -120,6 +120,22 @@ void KiwixApp::openUrl(const QUrl &url, bool newTab) {
mp_tabWidget->openUrl(url, newTab);
}
void KiwixApp::openRandomUrl(bool newTab)
{
auto zimId = mp_tabWidget->currentZimId();
if (zimId.isEmpty()) {
return;
}
auto reader = m_library.getReader(zimId);
auto entry = reader->getRandomPage();
QUrl url;
url.setScheme("zim");
url.setHost(zimId);
url.setPath("/" + QString::fromStdString(entry.getPath()));
openUrl(url, newTab);
}
void KiwixApp::showMessage(const QString &message)
{
mp_errorDialog->showMessage(message);
@ -146,7 +162,8 @@ void KiwixApp::createAction()
CREATE_ACTION_ICON(RandomArticleAction, "random", "Random Article");
SET_SHORTCUT(RandomArticleAction, QKeySequence(Qt::CTRL+Qt::Key_R));
DISABLE_ACTION(RandomArticleAction);
connect(mpa_actions[RandomArticleAction], &QAction::triggered,
this, [=]() { this->openRandomUrl(); });
CREATE_ACTION_ICON(PrintAction, "print", "Print");
SET_SHORTCUT(PrintAction, QKeySequence::Print);

View File

@ -53,6 +53,7 @@ public:
static KiwixApp* instance();
void openUrl(const QUrl& url, bool newTab=true);
void openRandomUrl(bool newTab=true);
void showMessage(const QString& message);