mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merge pull request #760 from kiwix/fileHandle
This commit is contained in:
commit
fe588daf86
@ -15,6 +15,7 @@
|
|||||||
"home-page":"Home page",
|
"home-page":"Home page",
|
||||||
"main-menu":"Main menu",
|
"main-menu":"Main menu",
|
||||||
"print":"Print",
|
"print":"Print",
|
||||||
|
"print-page-error": "An error has occured while printing.",
|
||||||
"new-tab":"New tab",
|
"new-tab":"New tab",
|
||||||
"close-tab":"Close tab",
|
"close-tab":"Close tab",
|
||||||
"close":"Close",
|
"close":"Close",
|
||||||
@ -121,5 +122,7 @@
|
|||||||
"open-link-in-web-browser":"Open link in web browser",
|
"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-title":"Are you sure you want to change the download directory?",
|
||||||
"download-dir-dialog-msg":"The new download directory path will be:\n{{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 <QUrl>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStorageInfo>
|
#include <QStorageInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
|
ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@ -120,7 +121,20 @@ QStringList ContentManager::getBookInfos(QString id, const QStringList &keys)
|
|||||||
void ContentManager::openBook(const QString &id)
|
void ContentManager::openBook(const QString &id)
|
||||||
{
|
{
|
||||||
QUrl url("zim://"+id+".zim/");
|
QUrl url("zim://"+id+".zim/");
|
||||||
|
try {
|
||||||
KiwixApp::instance()->openUrl(url, true);
|
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;}}
|
#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 {
|
try {
|
||||||
zimId = m_library.openBookFromPath(validZimFile);
|
zimId = m_library.openBookFromPath(validZimFile);
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
openUrl(QUrl("zim://"+zimId+".zim/"));
|
openUrl(QUrl("zim://"+zimId+".zim/"));
|
||||||
@ -196,7 +198,7 @@ void KiwixApp::printPage()
|
|||||||
return;
|
return;
|
||||||
webview->page()->print(printer, [=](bool success) {
|
webview->page()->print(printer, [=](bool success) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
showMessage("An error has occured while printing.");
|
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
|
||||||
}
|
}
|
||||||
delete printer;
|
delete printer;
|
||||||
});
|
});
|
||||||
@ -227,13 +229,19 @@ void KiwixApp::openRandomUrl(bool newTab)
|
|||||||
url.setPath("/" + QString::fromStdString(entry.getPath()));
|
url.setPath("/" + QString::fromStdString(entry.getPath()));
|
||||||
openUrl(url, newTab);
|
openUrl(url, newTab);
|
||||||
} catch ( const kiwix::NoEntry& ) {
|
} 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)
|
QAction *KiwixApp::getAction(KiwixApp::Actions action)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <QtSingleApplication>
|
#include <QtSingleApplication>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QErrorMessage>
|
#include <QErrorMessage>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <kiwix/name_mapper.h>
|
#include <kiwix/name_mapper.h>
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public:
|
|||||||
|
|
||||||
void openRandomUrl(bool newTab=true);
|
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; }
|
KProfile* getProfile() { return &m_profile; }
|
||||||
Library* getLibrary() { return &m_library; }
|
Library* getLibrary() { return &m_library; }
|
||||||
|
@ -48,6 +48,9 @@ QString Library::openBookFromPath(const QString &zimPath)
|
|||||||
|
|
||||||
kiwix::Manager manager(&m_library);
|
kiwix::Manager manager(&m_library);
|
||||||
auto id = manager.addBookFromPathAndGetId(zimPath.toStdString());
|
auto id = manager.addBookFromPathAndGetId(zimPath.toStdString());
|
||||||
|
if (id == "") {
|
||||||
|
throw std::invalid_argument("invalid zim file");
|
||||||
|
}
|
||||||
save();
|
save();
|
||||||
emit(booksChanged());
|
emit(booksChanged());
|
||||||
return QString::fromStdString(id);
|
return QString::fromStdString(id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user