mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
Merge pull request #760 from kiwix/fileHandle
This commit is contained in:
commit
fe588daf86
@ -15,6 +15,7 @@
|
||||
"home-page":"Home page",
|
||||
"main-menu":"Main menu",
|
||||
"print":"Print",
|
||||
"print-page-error": "An error has occured while printing.",
|
||||
"new-tab":"New tab",
|
||||
"close-tab":"Close tab",
|
||||
"close":"Close",
|
||||
@ -121,5 +122,7 @@
|
||||
"open-link-in-web-browser":"Open link in web browser",
|
||||
"download-dir-dialog-title":"Are you sure you want to change the download directory?",
|
||||
"download-dir-dialog-msg":"The new download directory path will be:\n{{DIRECTORY}}",
|
||||
"invalid-port":"Invalid port"
|
||||
"invalid-port":"Invalid port",
|
||||
"zim-open-fail-title":"Invalid file",
|
||||
"zim-open-fail-text":"The ZIM file <b>{{ZIM}}</b> cannot be open properly. It will be removed from your library."
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
#include <QStorageInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
|
||||
: QObject(parent),
|
||||
@ -120,7 +121,20 @@ QStringList ContentManager::getBookInfos(QString id, const QStringList &keys)
|
||||
void ContentManager::openBook(const QString &id)
|
||||
{
|
||||
QUrl url("zim://"+id+".zim/");
|
||||
KiwixApp::instance()->openUrl(url, true);
|
||||
try {
|
||||
KiwixApp::instance()->openUrl(url, true);
|
||||
} catch (const std::exception& e) {
|
||||
auto tabBar = KiwixApp::instance()->getTabWidget();
|
||||
tabBar->closeTab(1);
|
||||
auto text = gt("zim-open-fail-text");
|
||||
text = text.replace("{{ZIM}}", QString::fromStdString(mp_library->getBookById(id).getPath()));
|
||||
auto title = gt("zim-open-fail-title");
|
||||
KiwixApp::instance()->showMessage(text, title, QMessageBox::Warning);
|
||||
mp_library->removeBookFromLibraryById(id);
|
||||
tabBar->setCurrentIndex(0);
|
||||
emit(booksChanged());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#define ADD_V(KEY, METH) {if(key==KEY) {values.append(QString::fromStdString((d->METH()))); continue;}}
|
||||
|
@ -176,7 +176,9 @@ void KiwixApp::openZimFile(const QString &zimfile)
|
||||
try {
|
||||
zimId = m_library.openBookFromPath(validZimFile);
|
||||
} catch (const std::exception& e) {
|
||||
showMessage("Cannot open " + validZimFile + ": \n" + e.what());
|
||||
auto text = gt("zim-open-fail-text");
|
||||
text = text.replace("{{ZIM}}", validZimFile);
|
||||
showMessage(text, gt("zim-open-fail-title"), QMessageBox::Warning);
|
||||
return;
|
||||
}
|
||||
openUrl(QUrl("zim://"+zimId+".zim/"));
|
||||
@ -196,7 +198,7 @@ void KiwixApp::printPage()
|
||||
return;
|
||||
webview->page()->print(printer, [=](bool success) {
|
||||
if (!success) {
|
||||
showMessage("An error has occured while printing.");
|
||||
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
|
||||
}
|
||||
delete printer;
|
||||
});
|
||||
@ -227,13 +229,19 @@ void KiwixApp::openRandomUrl(bool newTab)
|
||||
url.setPath("/" + QString::fromStdString(entry.getPath()));
|
||||
openUrl(url, newTab);
|
||||
} catch ( const kiwix::NoEntry& ) {
|
||||
showMessage(gt("random-article-error"));
|
||||
showMessage(gt("random-article-error"), gt("error-title"), QMessageBox::Information);
|
||||
}
|
||||
}
|
||||
|
||||
void KiwixApp::showMessage(const QString &message)
|
||||
void KiwixApp::showMessage(const QString &message, const QString &title, const enum QMessageBox::Icon &icon)
|
||||
{
|
||||
mp_errorDialog->showMessage(message);
|
||||
QMessageBox msgBox(
|
||||
icon, //Icon
|
||||
title, //Title
|
||||
message, //Text
|
||||
QMessageBox::Ok //Buttons
|
||||
);
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
QAction *KiwixApp::getAction(KiwixApp::Actions action)
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <QtSingleApplication>
|
||||
#include <QApplication>
|
||||
#include <QErrorMessage>
|
||||
#include <QMessageBox>
|
||||
#include <QTranslator>
|
||||
#include <kiwix/name_mapper.h>
|
||||
|
||||
@ -66,7 +67,7 @@ public:
|
||||
|
||||
void openRandomUrl(bool newTab=true);
|
||||
|
||||
void showMessage(const QString& message);
|
||||
void showMessage(const QString& message, const QString& title, const enum QMessageBox::Icon& icon);
|
||||
|
||||
KProfile* getProfile() { return &m_profile; }
|
||||
Library* getLibrary() { return &m_library; }
|
||||
|
@ -48,6 +48,9 @@ QString Library::openBookFromPath(const QString &zimPath)
|
||||
|
||||
kiwix::Manager manager(&m_library);
|
||||
auto id = manager.addBookFromPathAndGetId(zimPath.toStdString());
|
||||
if (id == "") {
|
||||
throw std::invalid_argument("invalid zim file");
|
||||
}
|
||||
save();
|
||||
emit(booksChanged());
|
||||
return QString::fromStdString(id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user