Debian Codegraph @

src/main.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "knowthelist.h"
19
20 #include <QApplication>
21 #include <QMessageBox>
22 #include <QTextCodec>
23 #include <QTranslator>
24 #include <QtSql>
25
26 int main(int argc, char* argv[])
27 {
28 QApplication a(argc, argv);
29
30 // init rand
31 qsrand(QDateTime::currentMSecsSinceEpoch() / 1000);
32
33 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
34 a.setQuitOnLastWindowClosed(true);
35
36 QCoreApplication::setOrganizationName("knowthelist-org");
37 QCoreApplication::setOrganizationDomain("");
38 QCoreApplication::setApplicationName("knowthelist");
39 QCoreApplication::setApplicationVersion("2.3.1");
40
41 QSettings settings;
42 QStringList languages;
43 languages << ""
44 << "en"
45 << "de"
46 << "cs"
47 << "hu"
48 << "fr";
49 QString lang = languages[settings.value("language", 0).toInt()];
50 if (lang.isEmpty())
51 lang = QLocale::system().name();
52
53 QTranslator qtTranslator;
54 qtTranslator.load("qt_" + lang,
55 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
56 a.installTranslator(&qtTranslator);
57
58 QTranslator localization;
59 bool result = localization.load(":knowthelist_" + lang + ".qm");
60 qDebug() << "localization load "
61 << ":knowthelist_" + lang + ".qm result:" << result;
62 a.installTranslator(&localization);
63
64 if (!QSqlDatabase::drivers().contains("QSQLITE")) {
65 #if QT_VERSION >= 0x050000
66 QMessageBox::critical(nullptr, QObject::tr("Unable to load database"),
67 QObject::tr("This application needs the QT5 SQLITE "
68 "driver (libqt5-sql-sqlite)"));
69 #else
70 QMessageBox::critical(0, QObject::tr("Unable to load database"),
71 QObject::tr("This application needs the QT4 SQLITE "
72 "driver (libqt4-sql-sqlite)"));
73 #endif
74
75 return 1;
76 }
77
78 #if QT_VERSION >= 0x050000
79 QString pathName = QStandardPaths::standardLocations(QStandardPaths::DataLocation).at(0);
80 #else
81 QString pathName = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
82 #endif
83 QDir path(pathName);
84
85 if (!path.exists())
86 path.mkpath(pathName);
87
88 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
89 db.setDatabaseName(path.absolutePath() + "/collection.db");
90
91 if (!db.open()) {
92 QMessageBox::critical(nullptr, "fatal database error",
93 db.lastError().text());
94 return 1;
95 }
96 qDebug() << "load database: " << db.databaseName();
97 Knowthelist w;
98 w.show();
99
100 return a.exec();
101 }