1 /* ColorCode, a free MasterMind clone with built in solver
2 * Copyright (C) 2009 Dirk Laebisch
3 * http://www.laebisch.com/
4 *
5 * ColorCode is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * ColorCode is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with ColorCode. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <iostream>
20 #include <QApplication>
21 #include <QLibraryInfo>
22 #include <QLocale>
23 #include <QTranslator>
24 #include "colorcode.h"
25
main(int argc,char * argv[])26 int main(int argc, char* argv[])
27 {
28 using namespace std;
29
30 string lang("");
31 if (argc > 1)
32 {
33 string str;
34 for (int i = 1; i < argc; ++i)
35 {
36 str = argv[i];
37 if (str == "-h" || str == "--help")
38 {
39 cout << "usage: ColorCode [options]" << endl;
40 cout << " options:" << endl;
41 cout << " -l cc, --lang=cc use country code cc instead of system locale, accepted values for cc: en|de|cs|fr|hu|es" << endl;
42 cout << " -h, --help prints this message ;-)" << endl;
43 return 0;
44 }
45 else if (str == "-l" && i < argc - 1)
46 {
47 if (std::string(argv[i + 1]) == "de"
48 || std::string(argv[i + 1]) == "en"
49 || std::string(argv[i + 1]) == "cs"
50 || std::string(argv[i + 1]) == "fr"
51 || std::string(argv[i + 1]) == "hu"
52 || std::string(argv[i + 1]) == "es" )
53 {
54 std::string test(argv[i]);
55 lang = argv[i + 1];
56 }
57 }
58 else if ( str.size() == 9
59 && str.find("--lang=") != string::npos
60 && (str.substr(7) == "en"
61 || str.substr(7) == "de"
62 || str.substr(7) == "cs"
63 || str.substr(7) == "fr"
64 || str.substr(7) == "hu"
65 || str.substr(7) == "es" ) )
66 {
67 lang = str.substr(7);
68 }
69 }
70 }
71
72 QApplication app(argc, argv);
73
74 QTranslator qtTranslator;
75 if (lang == "")
76 {
77 qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
78 }
79 else
80 {
81 qtTranslator.load("qt_" + QString::fromStdString(lang), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
82 }
83 app.installTranslator(&qtTranslator);
84
85 QTranslator appTranslator;
86 if (lang == "")
87 {
88 appTranslator.load(":/trans_" + QLocale::system().name());
89 }
90 else
91 {
92 appTranslator.load(":/trans_" + QString::fromStdString(lang));
93 }
94 app.installTranslator(&appTranslator);
95
96 ColorCode w;
97 w.show();
98 return app.exec();
99 }
100