Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open zim location in file manager #970

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,12 @@
"download-storage-error": "Storage Error",
"download-storage-error-text": "The system doesn't have enough storage available.",
"download-unavailable": "Download Unavailable",
"download-unavailable-text": "This download is unavailable."
"download-unavailable-text": "This download is unavailable.",
"open-book": "Open book",
"download-book": "Download book",
"pause-download": "Pause download",
"resume-download": "Resume download",
"open-folder": "Open folder",
"couldnt-open-location": "Couldn't open location",
"couldnt-open-location-text": "Kiwix is not able to open folder {{FOLDER}}"
}
43 changes: 31 additions & 12 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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,16 +90,19 @@ QList<QMap<QString, QVariant>> ContentManager::getBooksList()
void ContentManager::onCustomContextMenu(const QPoint &point)
{
QModelIndex index = mp_view->getView()->indexAt(point);
if (!index.isValid())
return;
QMenu contextMenu("optionsMenu", mp_view->getView());
auto bookNode = static_cast<RowNode*>(index.internalPointer());
const auto id = bookNode->getBookId();

QAction menuDeleteBook("Delete book", this);
QAction menuOpenBook("Open book", this);
QAction menuDownloadBook("Download book", this);
QAction menuPauseBook("Pause download", this);
QAction menuResumeBook("Resume download", this);
QAction menuCancelBook("Cancel download", this);
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 @@ -108,12 +112,29 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
}
contextMenu.addAction(&menuCancelBook);
} else {
if (m_local) {
try {
const auto book = KiwixApp::instance()->getLibrary()->getBookById(id);
auto bookPath = QString::fromStdString(book.getPath());
contextMenu.addAction(&menuOpenBook);
contextMenu.addAction(&menuDeleteBook);
}
else
contextMenu.addAction(&menuOpenFolder);
connect(&menuOpenFolder, &QAction::triggered, [=]() {
QFileInfo fileInfo(bookPath);
QDir bookDir = fileInfo.absoluteDir();
bool dirOpen = bookDir.exists() && bookDir.isReadable() && QDesktopServices::openUrl(bookDir.absolutePath());
kelson42 marked this conversation as resolved.
Show resolved Hide resolved
if (!dirOpen) {
QString failedText = gt("couldnt-open-location-text");
failedText = failedText.replace("{{FOLDER}}", "<b>" + bookDir.absolutePath() + "</b>");
KiwixConfirmBox *dialog = new KiwixConfirmBox(gt("couldnt-open-location"), failedText, true, mp_view);
dialog->show();
connect(dialog, &KiwixConfirmBox::okClicked, [=]() {
dialog->deleteLater();
});
}
});
} catch (...) {
contextMenu.addAction(&menuDownloadBook);
}
}

connect(&menuDeleteBook, &QAction::triggered, [=]() {
Expand All @@ -135,9 +156,7 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
resumeBook(id, index);
});

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

void ContentManager::setLocal(bool local) {
Expand Down
Loading