src/main.cpp

Mon, 07 Feb 2022 21:28:26 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 07 Feb 2022 21:28:26 +0100
changeset 2
a1e435907f3a
parent 1
d38df7b58026
child 6
f8474f2c5db9
permissions
-rw-r--r--

Added commandline parameters. Added initial app functions. Added user configuration read/write/create.

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
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 //#include <QLocale>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 //#include <QTranslator>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
26 #include "bmsapp.h"
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "config.h"
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
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 int main(int argc, char *argv[])
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 {
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 QApplication app(argc, argv);
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 app.setApplicationName(
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 #ifdef QT_DEBUG
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 "bmsapp-debug"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #else
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 "bmsapp"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #endif
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 );
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 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
41 app.setOrganizationName("mbse");
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
43 /* 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
44 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
45
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
46 /* 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
47 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
48 parser.setApplicationDescription("Brewery Management System Application.");
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
49 parser.addOptions({
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
50 // A boolean option with multiple names (-f, --force)
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
51 {{"c", "config"},
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
52 QCoreApplication::translate("main", "Start the configuration editor.")},
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
53 {{"d", "develop"},
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
54 QCoreApplication::translate("main", "Use the development database.")},
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
55 });
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
56 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
57 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
58 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
59
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
60 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
61
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
62 try {
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
63 auto mainAppReturnValue = Bmsapp::run();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
64 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
65 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
66 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
67 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
68 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
69 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
70 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
71 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
72 return EXIT_FAILURE;
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }

mercurial