src/main.cpp

Mon, 28 Feb 2022 21:21:33 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 28 Feb 2022 21:21:33 +0100
changeset 31
ab17a56a47dd
parent 18
d0ca50776b0b
child 85
34ca34ed81df
permissions
-rw-r--r--

Setup translation system and started the Dutch translation

1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * main.cpp is part of bmsapp.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include <QApplication>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include <QCommandLineParser>
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
19 #include <QDebug>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
20 #include <QDate>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
21 #include <QMessageBox>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
22
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
23 #include "bmsapp.h"
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "config.h"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 int main(int argc, char *argv[])
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 {
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 QApplication app(argc, argv);
31
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
30 QString locale = QLocale::system().name();
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
31
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 app.setApplicationName(
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 #ifdef QT_DEBUG
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 "bmsapp-debug"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 #else
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 "bmsapp"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #endif
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 );
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 app.setApplicationVersion(VERSIONSTRING);
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
40 app.setOrganizationName("mbse");
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
15
c58b82549713 Started adding the global setup screen.
Michiel Broek <mbroek@mbse.eu>
parents: 14
diff changeset
42 /* Stylesheet setup */
18
d0ca50776b0b Fixed missing arrows on combobox and spinboxes in the qdarkstyle theme. Changed suppliers editor icon in the menu.
Michiel Broek <mbroek@mbse.eu>
parents: 16
diff changeset
43 QFile f(":/qdarkstyle/theme/style.qss");
16
a5d8e783a7b0 Completed the global setup editor.
Michiel Broek <mbroek@mbse.eu>
parents: 15
diff changeset
44 //QFile f(":darkorange.qss");
a5d8e783a7b0 Completed the global setup editor.
Michiel Broek <mbroek@mbse.eu>
parents: 15
diff changeset
45 //QFile f(":dummy");
14
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
46 if (!f.exists()) {
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
47 printf("Unable to set stylesheet, file not found\n");
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
48 } else {
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
49 f.open(QFile::ReadOnly | QFile::Text);
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
50 QTextStream ts(&f);
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
51 qApp->setStyleSheet(ts.readAll());
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
52 }
8a304c898a75 Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
53
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
54 /* Setup user ini format */
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
55 QSettings::setDefaultFormat(QSettings::IniFormat);
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
56
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
57 /* Setup commandline parser */
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
58 QCommandLineParser parser;
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
59 parser.setApplicationDescription("Brewery Management System Application.");
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
60 QCommandLineOption const startConfigOption({"c", "config"}, "Start the configuration editor.");
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
61 parser.addOption(startConfigOption);
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
62 QCommandLineOption const useDevelopOption({"d", "develop"}, "Use the development database.");
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
63 parser.addOption(useDevelopOption);
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
64 parser.addHelpOption();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
65 parser.addVersionOption();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
66 parser.process(app);
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
67
31
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
68 QTranslator translator;
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
69 translator.load(QString("bmsapp_") + locale);
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
70 app.installTranslator(&translator);
ab17a56a47dd Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
71
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
72 qDebug().noquote() << "Starting" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
73
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
74 try {
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
75 auto mainAppReturnValue = Bmsapp::run(parser.isSet(useDevelopOption), parser.isSet(startConfigOption));
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
76 qDebug().noquote() << "Finished" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
77 return mainAppReturnValue;
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
78 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
79 catch (const QString &error) {
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
80 QMessageBox::critical(0,
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
81 QApplication::tr("Application terminates"),
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
82 QApplication::tr("The application encountered a fatal error.\nError message:\n%1").arg(error));
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
83 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
84 return EXIT_FAILURE;
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 }

mercurial