File: main.cpp

package info (click to toggle)
tipp10 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,948 kB
  • sloc: cpp: 10,810; ansic: 143; makefile: 9
file content (256 lines) | stat: -rw-r--r-- 6,625 bytes parent folder | download
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
Copyright (c) 2006-2011, Tom Thielicke IT Solutions

This program 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.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

/****************************************************************
**
** File name: main.cpp
**
****************************************************************/

#include <QApplication>
#include <QString>
#include <QSettings>
#include <QCoreApplication>
#include <QTranslator>

#include "def/defines.h"
#include "sql/connection.h"
#include "widget/mainwindow.h"
#include "widget/illustrationdialog.h"

int main(int argc, char *argv[]) {

    QApplication app(argc, argv);

    // Set application name and domain
    // (this saves having to repeat the information
    // each time a QSettings object is created)
	app.setOrganizationName(APP_ORGANIZATION);
 	app.setOrganizationDomain(APP_URL);
    app.setApplicationName(APP_NAME_INTERN);

	// Settings to get and set general settings
	#if APP_PORTABLE
	/*QSettings settings(QSettings::IniFormat, QSettings::UserScope,
		"portable", "settings");
    settings.setPath(QSettings::IniFormat, QSettings::UserScope,
    	QCoreApplication::applicationDirPath());*/
    QSettings settings(QCoreApplication::applicationDirPath() +
    	"/portable/settings.ini", QSettings::IniFormat);
	#else
	QSettings settings;
	#endif

	// Read/write language and show illustration flag
	settings.beginGroup("general");
	QString languageGui = settings.value("language_gui",
		QLocale::system().name()).toString();

	QStringList languagesGui =
		QString(APP_EXISTING_LANGUAGES_GUI).split(";", QString::SkipEmptyParts);

	QString checkDelims = "_";
	bool checkSuccessful = true;

	for (;;) {

		if (languagesGui.contains(languageGui)) {
			break;
		}

		int rightmost = 0;
		for (int i = 0; i < (int)checkDelims.length(); i++) {
			int k = languageGui.lastIndexOf(checkDelims[i]);
			if (k > rightmost)
				rightmost = k;
		}

		// no truncations? fail
		if (rightmost == 0)  {
			checkSuccessful = false;
			break;
		}

		languageGui.truncate(rightmost);
    }
    if (!checkSuccessful) {
		languageGui = APP_STD_LANGUAGE_GUI;
	}

	QString languageLayout = settings.value("language_layout",
		"").toString();

	QString languageLesson = settings.value("language_lesson",
		"").toString();

	bool showIllustration = settings.value("check_illustration", true).toBool();
	bool useNativeStyle = settings.value("check_native_style", false).toBool();
	settings.endGroup();

	// Convert old keyboard layout settings to new (since v2.1.0)
	if (languageLayout == "") {
		if (languageGui != "de") {

			languageLayout = "us_qwerty";
			if (APP_MAC) {
				languageLayout.append("_mac");
			} else {
				languageLayout.append("_win");
			}
			// Enable when English lessons available!!!!!!!!
            languageLesson = "en_us_qwerty";

		} else {
			// Check user's keyboard layout (win or mac)
			settings.beginGroup("settings");

			//! Used operation system ("win" or "mac").
			QString opSystem;

			//! Used keyboard layout ("de", "ch", "neo", etc.).
			QString opLayout;

			//! Used swiss layout ("sg" or "sf").
			QString chLayout;

			//! Used neo layout ("1.0" or "2.0").
			QString neoLayout;

			opSystem = "win";
			opLayout = "";
			chLayout = "";
			neoLayout = "";
			switch (settings.value("combo_layout_ch", 0).toInt()) {
				case 0:
					chLayout = "_sg";
					break;
				case 1:
					chLayout = "_sf";
					break;
			}
			switch (settings.value("combo_layout",
				KEYBOARD_LAYOUT_STANDARD).toInt()) {
				case 0:
					opLayout = "de_qwertz";
					break;
				case 1:
					opLayout = "ch_qwertz";
					break;
				case 2:
					opLayout = "de_neo";
					break;
				case 3:
					opLayout = "de_dvorak_v1";
					break;
				case 4:
					opLayout = "de_ristome";
					break;
				case 5:
					opLayout = "us_qwerty";
					break;
			}
			switch (settings.value("combo_layout_neo",
				0).toInt()) {
				case 0:
					neoLayout = "_v1";
					break;
				case 1:
					neoLayout = "_v2";
					break;
			}
			switch (settings.value("combo_layout_os",
				KEYBOARD_LAYOUT_MAC).toInt()) {
				case 0:
					opSystem = "win";
					break;
				case 1:
					opSystem = "mac";
					break;
			}

			languageLayout = opLayout;

			if (opLayout == "ch_qwertz") {
				languageLayout.append(chLayout);
			}

			if (opLayout == "de_neo") {
				languageLayout.append(neoLayout);
				languageLesson = "de_de_qwertz"; //"de_de_neo_v2";
			} else {
				languageLesson = "de_de_qwertz";
			}

			languageLayout.append("_" + opSystem);
			settings.endGroup();

		}
	}

	settings.beginGroup("general");
	settings.setValue("language_gui", languageGui);
	settings.setValue("language_layout", languageLayout);
	settings.setValue("language_lesson", languageLesson);
	settings.endGroup();

    // Set windows style
	if (!useNativeStyle) {
	    app.setStyle("fusion");
    }

	// Translation
	// Common qt widgets
	QTranslator translatorQt;
	translatorQt.load("qt_" + languageGui, ":/languages/");
	app.installTranslator(&translatorQt);

	// Content (own translation files)
	QTranslator translatorContent;
	translatorContent.load("tipp10_" + languageGui, ":/languages/");
	app.installTranslator(&translatorContent);

	// Set path to the db if arg parameter is set
	if (argc > 1) {
		settings.beginGroup("database");
		settings.setValue("pathpro", QString::fromLatin1(argv[1]) + "/" +
			APP_USER_DB);
		settings.endGroup();
	}

	// Create database connection
    if (!createConnection()) {
		// Cannot find or open database
		// -> exit program
		return 1;
	}


	// Show illustration widget at the beginning if not disabled by the user
    if (showIllustration) {
        IllustrationDialog illustrationDialog(0);
		illustrationDialog.exec();
	}

	// Create main window object
    MainWindow window;
    window.show();

    // Start the event loop
    return app.exec();
}