Skip to content

Commit

Permalink
Merge pull request #970 from kiwix/openFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr authored Aug 4, 2023
2 parents 7c4cd1d + 63b9de9 commit 8fa0634
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
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());
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

0 comments on commit 8fa0634

Please sign in to comment.