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