Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (70 loc) · 2.52 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (70 loc) · 2.52 KB
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
/*
* Copyright (C) 2024 Mikhail Medvedev <e-ink-reader@yandex.ru>
*
*
* 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 3
* of the License, or (at your option) any later version.
*
* 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.
*/
#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include <QTranslator>
static QString setUpTranslation(const QStringList &searchPaths)
{
QString localeName = QLocale::system().name();
QString translateName = "SFP-Master_" + localeName;
// skip user-specific dir for translations (first one); try the rest
foreach (const QString &path, searchPaths.mid(1))
{
QTranslator *translator = new QTranslator(qApp);
if (translator->load(translateName, path))
{
qApp->installTranslator(translator);
qDebug() << "Installed" << translateName << "from" << path;
return path;
} else {
delete translator;
}
}
return QString();
}
static void initPaths()
{
QStringList allPaths = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
if (allPaths.isEmpty()) {
// do not translate
qFatal("Critical error: QStandardPaths::standardLocations(QStandardPaths::AppDataLocation): empty list");
}
QDir binDir(QCoreApplication::applicationDirPath());
QString binRelPath = QDir::cleanPath(binDir.absoluteFilePath("../share/" + QCoreApplication::applicationName()));
allPaths.insert(1, binRelPath);
QDir userAppDataLocation(allPaths.value(0));
if (!userAppDataLocation.exists()) {
userAppDataLocation.mkpath(".");
// XXX some sort of error handling that befits the application
}
qApp->setProperty("app/translationDirectory", setUpTranslation(allPaths));
}
int main(int argc, char *argv[])
{
//If you need to change the system font - recomment this lines...
//QFont font("Monospace");
//font.setStyleHint(QFont::TypeWriter);
//font.setPointSize(12);
//QApplication::setFont(font);
QApplication a(argc, argv);
QCoreApplication::setApplicationName("sfp-master");
initPaths();
MainWindow w;
w.show();
return a.exec();
}