/
main.cpp
executable file
·178 lines (152 loc) · 4.76 KB
/
main.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#
/*
* Copyright (C) 2018
* Jan van Katwijk (J.vanKatwijk@gmail.com)
* Lazy Chair Computing
*
* This file is part of qt-1090
*
* qt-1090 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* qt-1090 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qt-1090; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* qt-1090 is based on the dump1090 program
* Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.com>
* all rights acknowledged.
*/
#include <QApplication>
#include <QSettings>
#include <QTranslator>
#include <QDir>
#include <QDebug>
#include <unistd.h>
#include <getopt.h>
#include "adsb-constants.h"
#include "qt-1090.h"
#define DEFAULT_INI ".qt-1090.ini"
#ifndef GITHASH
#define GITHASH " "
#endif
static const QString styleSheet_1 =
// #include "./stylesheets/Adaptic.qss"
#include "./stylesheets/Combinear.qss"
;
static const QString styleSheet_2 =
#include "./stylesheets/Adaptic.qss"
// #include "./stylesheets/Combinear.qss"
;
QString fullPathfor (QString v, QString aa) {
QString fileName;
if (v == QString (""))
return QString ("/tmp/xxx");
if (v. at (0) == QChar ('/')) // full path specified
return v;
fileName = QDir::homePath ();
fileName. append ("/");
fileName. append (v);
fileName = QDir::toNativeSeparators (fileName);
if (!fileName. endsWith (aa))
fileName. append (aa);
return fileName;
}
void setTranslator (QString Language);
int main (int argc, char **argv) {
QString initFileName = fullPathfor (QString (DEFAULT_INI), ".ini");
qt1090 *MyRadioInterface;
QSettings *dumpSettings; // ini file
int j;
char *fileName = nullptr;
int deviceIndex = 0;
int freq = 1090000000;
int opt;
bool network = false;
QCoreApplication::setOrganizationName ("Lazy Chair Computing");
QCoreApplication::setOrganizationDomain ("Lazy Chair Computing");
QCoreApplication::setApplicationName ("qt-1090");
QCoreApplication::setApplicationVersion (QString (CURRENT_VERSION) + " Git: " + GITHASH);
// Parse the command line options
int sheet = 0;
while ((opt = getopt (argc, argv, "f:F:nABC")) != -1) {
switch (opt) { // there aren't many
case 'f':
case 'F':
freq = atoi (optarg);
break;
case 'n':
network = true;
break;
case 'A':
sheet = 1;
break;
case 'B':
sheet = 2;
break;
case 'C':
sheet = 3;
break;
default:
break;
}
}
dumpSettings = new QSettings (initFileName, QSettings::IniFormat);
/*
* Before we connect control to the gui, we have to
* instantiate
*/
#if QT_VERSION >= 0x050600
QGuiApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
#endif
QApplication a (argc, argv);
if (sheet != 0)
dumpSettings -> setValue ("style-sheet", sheet);
else
sheet = dumpSettings -> value ("style-sheet", 1). toInt ();
if ((sheet == 1) || (sheet == 2))
a.setStyleSheet (sheet == 1 ? styleSheet_1 : styleSheet_2);
// setting the language
// QString locale = QLocale::system (). name ();
// qDebug() << "main:" << "Detected system language" << locale;
// setTranslator (locale);
// a. setWindowIcon (QIcon (":/dab-radio.ico"));
MyRadioInterface = new qt1090 (dumpSettings, freq, network);
MyRadioInterface -> show ();
a. exec ();
/*
* done:
*/
dumpSettings -> sync ();
fprintf (stderr, "back in main program\n");
fflush (stdout);
fflush (stderr);
qDebug ("It is done\n");
// delete MyRadioInterface;
delete dumpSettings;
}
void setTranslator (QString Language) {
QTranslator *Translator = new QTranslator;
// German is special (as always)
if ((Language == "de_AT") || (Language == "de_CH"))
Language = "de_DE";
//
// what about Dutch?
bool TranslatorLoaded =
Translator -> load (QString(":/i18n/") + Language);
qDebug() << "main:" << "Set language" << Language;
QCoreApplication::installTranslator (Translator);
if (!TranslatorLoaded) {
qDebug() << "main:" << "Error while loading language specifics" << Language << "use English \"en_GB\" instead";
Language = "en_GB";
}
QLocale curLocale (QLocale ((const QString&)Language));
QLocale::setDefault (curLocale);
}