mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Connect RandomArticleAction.
This commit is contained in:
parent
15f1492d96
commit
f8c6f18c0a
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user