Don't use gt function in the constructor of kiwixApp.

The `gt` function get the instance of the kiwixApp.

So we cannot call this function in the constructor of kiwixApp itself.
Move all the (complex) initialization step in another method call after
the kiwixApp is created.
This commit is contained in:
Matthieu Gautier 2020-04-07 16:09:31 +02:00
parent c8ed41dea5
commit 9f346f5f75
3 changed files with 29 additions and 24 deletions

View File

@ -37,30 +37,6 @@ 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, gt("error-downloader-window-title"),
gt("error-downloader-launch-message") + "<br><br>" + e.what());
}
mp_manager = new ContentManager(&m_library, mp_downloader);
auto icon = QIcon();
icon.addFile(":/icons/kiwix-app-icons-square.svg");
setWindowIcon(icon);
setApplicationName("Kiwix");
setDesktopFileName("kiwix.desktop");
setStyle(QStyleFactory::create("Windows"));
QFile styleFile(":/css/style.css");
styleFile.open(QIODevice::ReadOnly);
auto byteContent = styleFile.readAll();
styleFile.close();
QString style(byteContent);
setStyleSheet(style);
QString fontName; QString fontName;
if (platformName() == "windows") { if (platformName() == "windows") {
QFontDatabase::addApplicationFont(":/fonts/SegoeUI/segoeuib.ttf"); QFontDatabase::addApplicationFont(":/fonts/SegoeUI/segoeuib.ttf");
@ -88,6 +64,33 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
auto font = QFont(fontName); auto font = QFont(fontName);
setFont(font); setFont(font);
}
void KiwixApp::init()
{
try {
mp_downloader = new kiwix::Downloader();
} catch (exception& e) {
QMessageBox::critical(nullptr, gt("error-downloader-window-title"),
gt("error-downloader-launch-message") + "<br><br>" + e.what());
}
mp_manager = new ContentManager(&m_library, mp_downloader);
auto icon = QIcon();
icon.addFile(":/icons/kiwix-app-icons-square.svg");
setWindowIcon(icon);
setApplicationName("Kiwix");
setDesktopFileName("kiwix.desktop");
setStyle(QStyleFactory::create("Windows"));
QFile styleFile(":/css/style.css");
styleFile.open(QIODevice::ReadOnly);
auto byteContent = styleFile.readAll();
styleFile.close();
QString style(byteContent);
setStyleSheet(style);
createAction(); createAction();
mp_mainWindow = new MainWindow; mp_mainWindow = new MainWindow;

View File

@ -63,6 +63,7 @@ public:
KiwixApp(int& argc, char *argv[]); KiwixApp(int& argc, char *argv[]);
virtual ~KiwixApp(); virtual ~KiwixApp();
static KiwixApp* instance(); static KiwixApp* instance();
void init();
void openRandomUrl(bool newTab=true); void openRandomUrl(bool newTab=true);

View File

@ -16,6 +16,7 @@ int main(int argc, char *argv[])
QWebEngineUrlScheme::registerScheme(scheme); QWebEngineUrlScheme::registerScheme(scheme);
#endif #endif
KiwixApp a(argc, argv); KiwixApp a(argc, argv);
a.init();
QCommandLineParser parser; QCommandLineParser parser;
parser.addPositionalArgument("zimfile", "The zim file"); parser.addPositionalArgument("zimfile", "The zim file");