annotate ui/main.cpp @ 1371:23df332b2a4c

(issue179) Read install signature timestamp from config This also changes the way the sigDt is propgated to the MainWindow. It no longer uses the settings but hands it over as a parameter directly.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 24 Nov 2014 15:48:49 +0100
parents 3d7ddf698480
children c64b6c56ce96
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 365
diff changeset
7 */
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include "mainwindow.h"
612
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
9 #include "processhelp.h"
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
10 #include "logging.h"
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents: 633
diff changeset
11 #include "selftest.h"
876
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
12 #include "util.h"
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
13 #ifdef WIN32
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
14 #include "taskscheduler.h"
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
15 #endif
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 #include <QApplication>
840
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
18 #include <QFile>
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 #include <QtPlugin>
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 #include <QMessageBox>
17
c12825a651ed Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents: 16
diff changeset
21 #include <QSettings>
423
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
22 #include <QDebug>
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
23 #include <QTranslator>
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
25 #include <QStyleFactory>
876
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
26 #include <QFontDatabase>
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
27
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
28 #ifndef VERSION
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
29 #define VERSION "0.0.1"
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
30 #endif
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
31
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
32 #ifndef APPNAME
407
af53c40e74b1 Rename m13ui to TrustBridge
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
33 #define APPNAME "TrustBridge"
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
34 #endif
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
35
840
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
36 #ifndef STARTUP_FILE_NAME
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
37 #define STARTUP_FILE_NAME "trustbridge-tray-starter.cfg"
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
38 #endif
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
39
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
40 #ifndef ORGANIZATION
409
09bb19e5e369 Remove m13 mentions and change test certificate to intevation.de
Andre Heinecke <aheinecke@intevation.de>
parents: 407
diff changeset
41 #define ORGANIZATION "BSI"
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
42 #endif
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43
829
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
44 #define COPYRIGHT "Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik \n" \
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
45 "Software engineering by Intevation GmbH \n\n" \
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
46 "This file is Free Software under the GNU GPL (v>=2)\n" \
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
47 "and comes with ABSOLUTELY NO WARRANTY!\n"
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
48
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 #ifdef Q_OS_WIN
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 #else
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 #endif
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54
1315
12ed0b72e9f5 (issue162) Change DO_RELEASE_BUILD to IS_TAG_BUILD to determine g_debug initializatation
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1079
diff changeset
55 #ifdef IS_TAG_BUILD
1058
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
56 bool g_debug = false;
1072
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
57 #else
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
58 bool g_debug = true;
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
59 #endif
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
60
1058
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
61 QtMessageHandler g_default_msg_handler = NULL;
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
62
1072
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
63 void filterDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
1058
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
64 {
1072
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
65 if (!g_debug && type == QtDebugMsg) {
1058
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
66 return;
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
67 }
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
68
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
69 if (g_default_msg_handler) {
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
70 (*g_default_msg_handler)(type, context, msg);
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
71 }
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
72 }
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
73
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
74
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 int main(int argc, char **argv)
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 {
1365
3d7ddf698480 (issue177) Only install updates with a newer signature on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1315
diff changeset
77 time_t signed_time = 0;
939
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
78 #ifdef WIN32
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
79 /* First verify integrity even before calling QApplication.
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
80 * We only do this on Windows as we have a PKCS#7 embedded
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
81 * signature there which we check with OS methods.
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
82 *
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
83 * On GNU/Linux platforms you should use an IDS system to
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
84 * monitor executable corruptions.
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
85 */
1365
3d7ddf698480 (issue177) Only install updates with a newer signature on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1315
diff changeset
86 if (!selftest(&signed_time)) {
1076
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
87 syslog_error_printf("Integrity check failed.");
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
88 MessageBoxW(NULL,
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
89 L"TrustBridge wurde nach der Installation modifizert.\n"
1078
5fad33497694 (isse116) Typo in message fixed.
Bernhard Reiter <bernhard@intevation.de>
parents: 1076
diff changeset
90 L"Um ihr System zu schützen wurde das Starten der Anwendung abgebrochen.\n"
1076
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
91 L"Bitte installieren Sie TrustBridge erneut.\n\n"
1079
6d5b305e9430 (isse116) Typo in message fixed.
Emanuel Schuetze <emanuel@intevation.de>
parents: 1078
diff changeset
92 L"TrustBridge has been modified after installation.\n"
1076
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
93 L"To protect your system the application launch has been aborted.\n"
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
94 L"Please reinstall TrustBridge.",
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
95 L"Integritätsprüfung fehlgeschlagen / Integrity check failed.",
96e448e1cc9f (issue116) Add error message when selftest failed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1074
diff changeset
96 MB_ICONERROR | MB_OK);
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
97 return -1;
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents: 633
diff changeset
98 }
939
574cd1fae1dc Only do selftest on Windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 879
diff changeset
99 #endif
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
100
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101 QApplication app (argc, argv);
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
103 QApplication::setQuitOnLastWindowClosed(false);
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
104 QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION));
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
105 QApplication::setApplicationName(QString::fromLatin1(APPNAME));
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
106 QApplication::setApplicationVersion(QString::fromLatin1(VERSION));
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
107 QSettings::setDefaultFormat(QSettings::IniFormat);
1058
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
108 QStringList arguments = QApplication::arguments();
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
109
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
110 if (arguments.contains("--debug")) {
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
111 g_debug = true;
fe2c6666b462 (issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents: 993
diff changeset
112 }
1072
1e429faf7c84 (issue46) Default to debug output on if RELEASE_BUILD is not defined
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1058
diff changeset
113 g_default_msg_handler = qInstallMessageHandler(filterDebugOutput);
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
114
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
115 qDebug() << "Application style is: " << app.style()->metaObject()->className();
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
116 qDebug() << "Available styles: " << QStyleFactory::keys().join(", ");
876
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
117 qDebug() << "Font is: " << app.font();
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
118
154
3349c9596043 Added commandline arguemnt '--tray' to hide or show the mainwindow.
Raimund Renkert <rrenkert@intevation.de>
parents: 73
diff changeset
119 bool trayMode = arguments.contains("--tray");
3349c9596043 Added commandline arguemnt '--tray' to hide or show the mainwindow.
Raimund Renkert <rrenkert@intevation.de>
parents: 73
diff changeset
120
829
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
121 if (arguments.contains("--version")) {
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
122 printf (APPNAME " Version: %s \n",
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
123 QApplication::applicationVersion().toLocal8Bit().constData());
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
124 printf (COPYRIGHT);
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
125 return 0;
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
126 }
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
127
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
128 QSettings settings;
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
129 settings.beginGroup("settings");
499
077b4342d69b Default autostart to true and change setting to bool
Andre Heinecke <aheinecke@intevation.de>
parents: 487
diff changeset
130 bool autoStart = settings.value("autostart", true).toBool();
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
131 settings.endGroup();
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
132
499
077b4342d69b Default autostart to true and change setting to bool
Andre Heinecke <aheinecke@intevation.de>
parents: 487
diff changeset
133 if (trayMode && !autoStart) {
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
134 return 0;
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
135 }
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
136
612
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
137 if (ProcessHelp::otherProcessesExist(APPNAME)) {
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
138 qDebug() << "Another " << APPNAME << " process is already running. Exiting.";
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
139 ProcessHelp::activateWindowForProcess(APPNAME);
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
140 return 0;
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
141 }
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
142
423
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
143 QTranslator translator;
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
144 if (QLocale::system().name() == "C") {
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
145 /* Useful for testing / development as the primary target is german */
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
146 translator.load(":/l10n/trustbridge_de_DE");
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
147 } else {
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
148 qDebug() << "Loading translations for: " << "trustbridge_" +
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
149 QLocale::system().name();
993
561cc777e0b6 Add failure indicator if translation load failed.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 939
diff changeset
150 if (!translator.load(":/l10n/trustbridge_" + QLocale::system().name())) {
561cc777e0b6 Add failure indicator if translation load failed.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 939
diff changeset
151 qDebug() << "Failed.";
561cc777e0b6 Add failure indicator if translation load failed.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 939
diff changeset
152 }
423
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
153 }
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
154 app.installTranslator(&translator);
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 840
diff changeset
155 /*
712
1e61903f61e2 Only exit when no tray is available and we are in tray mode.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 672
diff changeset
156 if ((!QSystemTrayIcon::isSystemTrayAvailable() ||
1e61903f61e2 Only exit when no tray is available and we are in tray mode.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 672
diff changeset
157 !QSystemTrayIcon::supportsMessages()) && trayMode) {
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
158 QMessageBox::critical(0, QString::fromLatin1(APPNAME),
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
159 QObject::tr("Couldn't detect any system tray "
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
160 "on this system. This software can only "
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
161 "be used in a desktop environment."));
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
162 return 1;
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
163 }
871
4efd6378c001 (issue51) Add fallback in case systemtray is unavailable.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 840
diff changeset
164 */
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
165 #ifdef Q_OS_WIN
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
166 {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
167 TaskScheduler taskSched;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
168 qDebug() << " task sched done: " << taskSched.createDailyTask(QCoreApplication::applicationFilePath(),
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
169 QString::fromLatin1("--tray"), QTime::currentTime());
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
170 }
840
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
171 #else
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
172 /* Save the display on start so that it might later be used by the cron startup script. */
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
173 QFile startup_file (settings.fileName().replace(APPNAME ".ini", STARTUP_FILE_NAME));
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
174 startup_file.open(QIODevice::WriteOnly);
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
175 startup_file.write(QString::fromLatin1("DISPLAY=%1\n").arg(qgetenv("DISPLAY").constData()).toUtf8());
c9a31544aaab (issue50) Write startup file with display variable
Andre Heinecke <andre.heinecke@intevation.de>
parents: 829
diff changeset
176 startup_file.close();
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
177 #endif
876
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
178
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
179 /* Install static fonts */
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
180
879
59fc7ececa5f Reference bug id for font database problem
Andre Heinecke <andre.heinecke@intevation.de>
parents: 876
diff changeset
181 /* The putenv here works around a bug in qt (#29192). Qt thinks it is a fatal
876
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
182 * error if the font directory does not exist. */
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
183 qputenv("QT_QPA_FONTDIR", get_install_dir());
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
184 int fontId = QFontDatabase::addApplicationFont(":/fonts/DejaVuSans.ttf");
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
185 if (fontId != -1)
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
186 {
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
187 QFont font("DejaVuSans");
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
188 font.setPointSize(9);
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
189 app.setFont(font);
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
190 }
0051cb07da28 Reduce libraries, document i386 build and statically link fonts.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 871
diff changeset
191
1371
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
192
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
193 QDateTime sigDt;
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
194 #ifndef Q_OS_WIN
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
195 /* Read it from the install config. */
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
196 sigDt = ProcessHelp::getSigDtFromInstSettings();
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
197 Q_UNUSED(signed_time);
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
198 #else
1365
3d7ddf698480 (issue177) Only install updates with a newer signature on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1315
diff changeset
199 if (signed_time != 0 && signed_time != -1) {
1371
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
200 /* Take it from the selftest result. */
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
201 sigDt = QDateTime::fromTime_t(signed_time);
1365
3d7ddf698480 (issue177) Only install updates with a newer signature on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1315
diff changeset
202 }
1371
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
203 #endif
1365
3d7ddf698480 (issue177) Only install updates with a newer signature on windows
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1315
diff changeset
204
1371
23df332b2a4c (issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1365
diff changeset
205 MainWindow mainWin(trayMode, sigDt);
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
206
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
207 return app.exec();
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
208 }

http://wald.intevation.org/projects/trustbridge/