-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
59 lines (51 loc) · 2.5 KB
/
Main.cpp
File metadata and controls
59 lines (51 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/** @file Main.cpp
* Program entry point and main loop.
* @author Adrien RICCIARDI
*/
#include <MainWindow.hpp>
#include <RemoteControl.hpp>
#include <QApplication>
#include <QLibraryInfo>
#include <QMessageBox>
#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
// Load Qt-provided translations (used for instance in default dialogs)
QTranslator qtTranslator;
bool isLocaleLoaded = qtTranslator.load(QLocale::system(), "qt", "_", QLibraryInfo::path(QLibraryInfo::TranslationsPath));
if (isLocaleLoaded) application.installTranslator(&qtTranslator);
// Select the right application translation according to system language
QTranslator translator;
// Retrieve the current language code of the system
const QString languageCode = QLocale::languageToCode(QLocale::system().language());
// Load the corresponding translation
isLocaleLoaded = translator.load(":/Translations/" + languageCode + ".qm");
if (isLocaleLoaded) application.installTranslator(&translator);
// Check arguments
if (argc < 4)
{
// This error string is displayed only for debugging purpose, so no need to translate it
QMessageBox::critical(nullptr, "Bad command line arguments",
"One or more command line arguments are missing.\n\n"
"The first argument must be the base path of the documents to display (this is the relative path for the document internal hyperlinks). This path starts from the root of the content resource file.\n\n"
"The second argument is the name of the document to consider as \"home\", its path is relative to the base path.\n\n"
"The third argument is the name of the document to display, its path is relative to the base path.",
QMessageBox::Ok);
// The preceding QMessageBox runs its own event loop, so there is no need to call application.exec()
return 0;
}
// Create and configure application main window
MainWindow mainWindow;
mainWindow.setContentSettings(argv[1], argv[2], argv[3]);
mainWindow.showMaximized();
// Set task bar icon on Linux
#ifdef Q_OS_LINUX
mainWindow.setWindowIcon(QIcon(":/Icon/Icon.svg"));
#endif
// Create a thread that will listen to commands on process stdin
RemoteControl remoteControlThread;
remoteControlThread.start();
QObject::connect(&remoteControlThread, &RemoteControl::commandReceived, &mainWindow, &MainWindow::displayDocument);
return application.exec();
}