annotate ui/main.cpp @ 829:294d76174102

(issue5) Add --version to trustbridge and trustbridge-admin
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 24 Jul 2014 11:41:52 +0200
parents 8de162b91a22
children c9a31544aaab
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"
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
12 #ifdef WIN32
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
13 #include "taskscheduler.h"
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
14 #endif
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 #include <QApplication>
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 #include <QSystemTrayIcon>
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 #include <QtPlugin>
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 #include <QMessageBox>
17
c12825a651ed Read out content-length and use this to skip existing files
Andre Heinecke <aheinecke@intevation.de>
parents: 16
diff changeset
20 #include <QSettings>
423
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
21 #include <QDebug>
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
22 #include <QTranslator>
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
24 #include <QStyleFactory>
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
25
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
26 #ifndef VERSION
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
27 #define VERSION "0.0.1"
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
28 #endif
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
29
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
30 #ifndef APPNAME
407
af53c40e74b1 Rename m13ui to TrustBridge
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
31 #define APPNAME "TrustBridge"
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
32 #endif
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
33
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
34 #ifndef ORGANIZATION
409
09bb19e5e369 Remove m13 mentions and change test certificate to intevation.de
Andre Heinecke <aheinecke@intevation.de>
parents: 407
diff changeset
35 #define ORGANIZATION "BSI"
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
36 #endif
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37
829
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
38 #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
39 "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
40 "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
41 "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
42
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 #ifdef Q_OS_WIN
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 #else
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 #endif
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 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
50 {
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
51 /* First verify integrity even before calling QApplication*/
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents: 633
diff changeset
52 if (!selftest()) {
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
53 syslog_error_printf ("Integrity check failed.");
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
54 #ifdef RELEASE_BUILD
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
55 return -1;
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
56 #endif
634
80d1a80b3e8d Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents: 633
diff changeset
57 }
631
edf269b6e499 Add self test as first opertation on start
Andre Heinecke <andre.heinecke@intevation.de>
parents: 612
diff changeset
58
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 QApplication app (argc, argv);
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
61 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
62 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
63 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
64 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
65 QSettings::setDefaultFormat(QSettings::IniFormat);
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
66
672
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
67 qDebug() << "Application style is: " << app.style()->metaObject()->className();
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
68 qDebug() << "Available styles: " << QStyleFactory::keys().join(", ");
376978e9cc61 Add debug output about style
Andre Heinecke <andre.heinecke@intevation.de>
parents: 634
diff changeset
69
154
3349c9596043 Added commandline arguemnt '--tray' to hide or show the mainwindow.
Raimund Renkert <rrenkert@intevation.de>
parents: 73
diff changeset
70 QStringList arguments = QApplication::arguments();
3349c9596043 Added commandline arguemnt '--tray' to hide or show the mainwindow.
Raimund Renkert <rrenkert@intevation.de>
parents: 73
diff changeset
71 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
72
829
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
73 if (arguments.contains("--version")) {
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
74 printf (APPNAME " Version: %s \n",
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
75 QApplication::applicationVersion().toLocal8Bit().constData());
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
76 printf (COPYRIGHT);
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
77 return 0;
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
78 }
294d76174102 (issue5) Add --version to trustbridge and trustbridge-admin
Andre Heinecke <andre.heinecke@intevation.de>
parents: 827
diff changeset
79
482
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
80 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
81 settings.beginGroup("settings");
499
077b4342d69b Default autostart to true and change setting to bool
Andre Heinecke <aheinecke@intevation.de>
parents: 487
diff changeset
82 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
83 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
84
499
077b4342d69b Default autostart to true and change setting to bool
Andre Heinecke <aheinecke@intevation.de>
parents: 487
diff changeset
85 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
86 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
87 }
0f4331ed4e83 Close the application if started in tray mode and autstart is not set.
Raimund Renkert <rrenkert@intevation.de>
parents: 423
diff changeset
88
612
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
89 if (ProcessHelp::otherProcessesExist(APPNAME)) {
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
90 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
91 ProcessHelp::activateWindowForProcess(APPNAME);
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
92 return 0;
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
93 }
2ea11a95aa4a Bail if the user is already running the application.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 499
diff changeset
94
423
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
95 QTranslator translator;
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
96 if (QLocale::system().name() == "C") {
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
97 /* Useful for testing / development as the primary target is german */
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
98 translator.load(":/l10n/trustbridge_de_DE");
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
99 } else {
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
100 translator.load(":/l10n/trustbridge_" + QLocale::system().name());
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
101 qDebug() << "Loading translations for: " << "trustbridge_" +
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
102 QLocale::system().name();
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
103 }
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
104 app.installTranslator(&translator);
3d1e9df24803 Add translation loading
Andre Heinecke <aheinecke@intevation.de>
parents: 409
diff changeset
105
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
106 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
107 !QSystemTrayIcon::supportsMessages()) && trayMode) {
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
108 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
109 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
110 "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
111 "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
112 return 1;
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113 }
16
225a5ec20dad Use QSettings and manage downloader from mainwindow.
Andre Heinecke <aheinecke@intevation.de>
parents: 0
diff changeset
114
827
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
115 #ifdef Q_OS_WIN
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
116 {
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
117 TaskScheduler taskSched;
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
118 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
119 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
120 }
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
121 #endif
8de162b91a22 (Issue49) Create a Scheduled daily task to run trustbridge
Andre Heinecke <andre.heinecke@intevation.de>
parents: 712
diff changeset
122
365
75f7288ad67b Switch from listupdatedialog to installwrapper. Minor UI improvements
Andre Heinecke <aheinecke@intevation.de>
parents: 154
diff changeset
123 MainWindow mainWin(trayMode);
0
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125 return app.exec();
cb0cde2c5eb9 Initial commit. Basically a Hello World with a Tray Icon.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
126 }

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