Skip to content

Commit

Permalink
Add "Open Folder" context menu option
Browse files Browse the repository at this point in the history
Added an option to open the zim's location in the OS's file manager
  • Loading branch information
juuz0 committed Aug 2, 2023
1 parent 91e8661 commit c981c44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@
"open-book": "Open book",
"download-book": "Download book",
"pause-download": "Pause download",
"resume-download": "Resume download"
"resume-download": "Resume download",
"open-folder": "Open folder"
}
11 changes: 11 additions & 0 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "kiwixconfirmbox.h"
#include <QtConcurrent/QtConcurrentRun>
#include "contentmanagerheader.h"
#include <QDesktopServices>

ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
: QObject(parent),
Expand Down Expand Up @@ -89,13 +90,15 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
QMenu contextMenu("optionsMenu", mp_view->getView());
auto bookNode = static_cast<RowNode*>(index.internalPointer());
const auto id = bookNode->getBookId();
QString bookPath = "";

QAction menuDeleteBook(gt("delete-book"), this);
QAction menuOpenBook(gt("open-book"), this);
QAction menuDownloadBook(gt("download-book"), this);
QAction menuPauseBook(gt("pause-download"), this);
QAction menuResumeBook(gt("resume-download"), this);
QAction menuCancelBook(gt("cancel-download"), this);
QAction menuOpenFolder(gt("open-folder"), this);

if (bookNode->isDownloading()) {
if (bookNode->getDownloadInfo().paused) {
Expand All @@ -107,8 +110,10 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
} else {
try {
const auto book = KiwixApp::instance()->getLibrary()->getBookById(id);
bookPath = QString::fromStdString(book.getPath());
contextMenu.addAction(&menuOpenBook);
contextMenu.addAction(&menuDeleteBook);
contextMenu.addAction(&menuOpenFolder);
} catch (...) {
contextMenu.addAction(&menuDownloadBook);
}
Expand All @@ -132,6 +137,12 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
connect(&menuResumeBook, &QAction::triggered, [=]() {
resumeBook(id, index);
});
connect(&menuOpenFolder, &QAction::triggered, [=]() {
if (bookPath != "") {
QFileInfo fileInfo(bookPath);
QDesktopServices::openUrl(fileInfo.absoluteDir().absolutePath());
}
});

if (index.isValid()) {
contextMenu.exec(mp_view->getView()->viewport()->mapToGlobal(point));
Expand Down

0 comments on commit c981c44

Please sign in to comment.