forked from dddaisuke/Caesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·97 lines (86 loc) · 3.06 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
/*******************************************************************************
#
# Copyright (C) 2010-2011 Matteo Paonessa <matteo.paonessa@gmail.com>
#
# This file is part of the Caesium distribution.
#
# Caesium 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.
#
# Caesium 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 Caesium; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
#
# Author: Matteo Paonessa <matteo.paonessa@gmail.com>
#
# ******************************************************************************/
#include <QtGui/QApplication>
#include <QString>
#include "caesium.h"
#include "global.h"
#include <QDebug>
#include <QTextStream>
QString findLocaleN(int n, QString dir)
{
QDir langDir(dir + "/language");
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
for (int i = list.length() - 1; i >= 0; i--)
{
QString file = list.at(i);
QStringList name = file.split(".");
if (name[0] == QString::number(n))
{
return QString::number(n) + "." + name[1];
}
}
return QString("31.English");
}
QString findLocaleS(QString string, QString dir)
{
QDir langDir(dir + "/language");
QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
for (int i = list.length() - 1; i >= 0; i--)
{
QString file = list.at(i);
QStringList name = file.split(".");
if (name[1] == string)
{
return name[0] + "." + string;
}
}
return QString("31.English");
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
settings.setIniCodec("UTF-8");
a.addLibraryPath(a.applicationDirPath() + "/lib/");
int loc = QLocale::system().language();
QString locale = settings.value("Preferences/lang").value<QString>();
QTranslator translator;
if(locale.isEmpty())
{
translator.load(a.applicationDirPath() + "/language/" + findLocaleN(loc, a.applicationDirPath()));
a.installTranslator(&translator);
}
else
{
translator.load(a.applicationDirPath() + "/language/" + findLocaleS(locale, a.applicationDirPath()));
a.installTranslator(&translator);
}
QPixmap pixmap(":icons/splash.png");
QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
splash.setMask(pixmap.mask());
splash.show();
Caesium w;
QTimer::singleShot(400, &splash, SLOT(close()));
QTimer::singleShot(400, &w, SLOT(show()));
return a.exec();
}