mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
commit
4fb9e917b6
@ -251,6 +251,9 @@ void ContentManager::eraseBook(const QString& id)
|
|||||||
|
|
||||||
void ContentManager::pauseBook(const QString& id)
|
void ContentManager::pauseBook(const QString& id)
|
||||||
{
|
{
|
||||||
|
if (!mp_downloader) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto& b = mp_library->getBookById(id);
|
auto& b = mp_library->getBookById(id);
|
||||||
auto download = mp_downloader->getDownload(b.getDownloadId());
|
auto download = mp_downloader->getDownload(b.getDownloadId());
|
||||||
if (download->getStatus() == kiwix::Download::K_ACTIVE)
|
if (download->getStatus() == kiwix::Download::K_ACTIVE)
|
||||||
@ -259,6 +262,9 @@ void ContentManager::pauseBook(const QString& id)
|
|||||||
|
|
||||||
void ContentManager::resumeBook(const QString& id)
|
void ContentManager::resumeBook(const QString& id)
|
||||||
{
|
{
|
||||||
|
if (!mp_downloader) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto& b = mp_library->getBookById(id);
|
auto& b = mp_library->getBookById(id);
|
||||||
auto download = mp_downloader->getDownload(b.getDownloadId());
|
auto download = mp_downloader->getDownload(b.getDownloadId());
|
||||||
if (download->getStatus() == kiwix::Download::K_PAUSED)
|
if (download->getStatus() == kiwix::Download::K_PAUSED)
|
||||||
@ -267,6 +273,9 @@ void ContentManager::resumeBook(const QString& id)
|
|||||||
|
|
||||||
void ContentManager::cancelBook(const QString& id)
|
void ContentManager::cancelBook(const QString& id)
|
||||||
{
|
{
|
||||||
|
if (!mp_downloader) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto& b = mp_library->getBookById(id);
|
auto& b = mp_library->getBookById(id);
|
||||||
auto download = mp_downloader->getDownload(b.getDownloadId());
|
auto download = mp_downloader->getDownload(b.getDownloadId());
|
||||||
if (download->getStatus() != kiwix::Download::K_COMPLETE) {
|
if (download->getStatus() != kiwix::Download::K_COMPLETE) {
|
||||||
|
@ -11,27 +11,14 @@
|
|||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <QMessageBox>
|
||||||
kiwix::Downloader* createDownloader() {
|
|
||||||
int attempt = 5;
|
|
||||||
while(attempt--) {
|
|
||||||
try {
|
|
||||||
return new kiwix::Downloader();
|
|
||||||
} catch (exception& e) {
|
|
||||||
qInfo() << "Cannot create downloader" << e.what();
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
KiwixApp::KiwixApp(int& argc, char *argv[])
|
KiwixApp::KiwixApp(int& argc, char *argv[])
|
||||||
: QApplication(argc, argv),
|
: QApplication(argc, argv),
|
||||||
m_settingsManager(),
|
m_settingsManager(),
|
||||||
m_libraryDirectory(findLibraryDirectory()),
|
m_libraryDirectory(findLibraryDirectory()),
|
||||||
m_library(),
|
m_library(),
|
||||||
mp_downloader(createDownloader()),
|
mp_downloader(nullptr),
|
||||||
m_manager(&m_library, mp_downloader),
|
|
||||||
mp_server(new kiwix::KiwixServe(
|
mp_server(new kiwix::KiwixServe(
|
||||||
appendToDirectory(m_libraryDirectory.toStdString(),"library.xml"),
|
appendToDirectory(m_libraryDirectory.toStdString(),"library.xml"),
|
||||||
m_settingsManager.getKiwixServerPort()))
|
m_settingsManager.getKiwixServerPort()))
|
||||||
@ -42,6 +29,14 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
|
|||||||
|
|
||||||
m_appTranslator.load(QLocale(), "kiwix-desktop", "_", ":/i18n/");
|
m_appTranslator.load(QLocale(), "kiwix-desktop", "_", ":/i18n/");
|
||||||
installTranslator(&m_appTranslator);
|
installTranslator(&m_appTranslator);
|
||||||
|
|
||||||
|
try {
|
||||||
|
mp_downloader = new kiwix::Downloader();
|
||||||
|
} catch (exception& e) {
|
||||||
|
QMessageBox::critical(nullptr, tr("Cannot create downloader"),
|
||||||
|
tr("Impossible to launch downloader, Kiwix-desktop will start but all download functions will not working !<br><br>") + e.what());
|
||||||
|
}
|
||||||
|
mp_manager = new ContentManager(&m_library, mp_downloader);
|
||||||
|
|
||||||
auto icon = QIcon();
|
auto icon = QIcon();
|
||||||
icon.addFile(":/icons/kiwix-app-icons-square.svg");
|
icon.addFile(":/icons/kiwix-app-icons-square.svg");
|
||||||
@ -90,18 +85,14 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
|
|||||||
createAction();
|
createAction();
|
||||||
mp_mainWindow = new MainWindow;
|
mp_mainWindow = new MainWindow;
|
||||||
mp_tabWidget = mp_mainWindow->getTabBar();
|
mp_tabWidget = mp_mainWindow->getTabBar();
|
||||||
mp_tabWidget->setContentManagerView(m_manager.getView());
|
mp_tabWidget->setContentManagerView(mp_manager->getView());
|
||||||
mp_tabWidget->setNewTabButton();
|
mp_tabWidget->setNewTabButton();
|
||||||
mp_mainWindow->getSideContentManager()->setContentManager(&m_manager);
|
mp_mainWindow->getSideContentManager()->setContentManager(mp_manager);
|
||||||
setSideBar(CONTENTMANAGER_BAR);
|
setSideBar(CONTENTMANAGER_BAR);
|
||||||
postInit();
|
postInit();
|
||||||
|
|
||||||
mp_errorDialog = new QErrorMessage(mp_mainWindow);
|
mp_errorDialog = new QErrorMessage(mp_mainWindow);
|
||||||
mp_mainWindow->show();
|
mp_mainWindow->show();
|
||||||
if (!mp_downloader) {
|
|
||||||
showMessage("Impossible to launch downloader.");
|
|
||||||
mpa_actions[ExitAction]->trigger();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KiwixApp::~KiwixApp()
|
KiwixApp::~KiwixApp()
|
||||||
@ -114,6 +105,7 @@ KiwixApp::~KiwixApp()
|
|||||||
mp_downloader->close();
|
mp_downloader->close();
|
||||||
delete mp_downloader;
|
delete mp_downloader;
|
||||||
}
|
}
|
||||||
|
delete mp_manager;
|
||||||
delete mp_errorDialog;
|
delete mp_errorDialog;
|
||||||
delete mp_mainWindow;
|
delete mp_mainWindow;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ private:
|
|||||||
QString m_libraryDirectory;
|
QString m_libraryDirectory;
|
||||||
Library m_library;
|
Library m_library;
|
||||||
kiwix::Downloader* mp_downloader;
|
kiwix::Downloader* mp_downloader;
|
||||||
ContentManager m_manager;
|
ContentManager* mp_manager;
|
||||||
MainWindow* mp_mainWindow;
|
MainWindow* mp_mainWindow;
|
||||||
TabBar* mp_tabWidget;
|
TabBar* mp_tabWidget;
|
||||||
SideBarType m_currentSideType;
|
SideBarType m_currentSideType;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user