/
main.cpp
109 lines (93 loc) · 3.25 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
98
99
100
101
102
103
104
105
106
107
108
109
/*
PhotoFlare main program.
*/
//#include <QDebug>
#include <QApplication>
#include <QFileInfo>
#include <QTranslator>
#include <QtSingleApplication>
#include <QStandardPaths>
#include <QFileInfo>
#include <QDir>
#include "mainwindow.h"
#include "Settings.h"
int main(int argc, char *argv[])
{
QtSingleApplication app("PhotoFlare", argc, argv);
if(!app.isRunning())
{
app.setApplicationName(QObject::tr("PhotoFlare"));
app.setApplicationVersion(QObject::tr("1.5.3"));
app.setOrganizationDomain(QObject::tr("photoflare.io"));
app.setOrganizationName(QObject::tr("photoflare"));
// Setup Default settings
QString loc = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString(), QStandardPaths::LocateDirectory)+"photoflare";
if(QDir(loc).exists() == false)
{
SETTINGS->setDefaultSettings();
}
// Set language based on System locale
if(SETTINGS->getUserLanguage() == "notset")
{
QString sysLanguage = QLocale::languageToString(QLocale::system().language());
QString lang;
if(sysLanguage == "English")
{
lang = "en";
}
else if(sysLanguage == "French")
{
lang = "fr";
}
else if(sysLanguage == "German")
{
lang = "de";
}
else if(sysLanguage == "Dutch")
{
lang = "nl";
}
else if(sysLanguage == "Chinese")
{
lang = "zh_TW";
}
SETTINGS->setUserLanguage(lang);
}
QTranslator translator;
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
for(int i = 0;i < paths.length(); i++)
{
QFileInfo check_file(paths[i]+"/languages/"+SETTINGS->getUserLanguage()+".qm"); //for installers
//QFileInfo check_file("languages/"+SETTINGS->getUserLanguage()+".qm"); //local builds
if(check_file.exists() && check_file.isFile())
{
translator.load(SETTINGS->getUserLanguage()+".qm", paths[i]+"/languages/"); //for installers
//translator.load(SETTINGS->getUserLanguage()+".qm", "languages/") //local builds
}
}
app.installTranslator(&translator);
MainWindow w;
w.show();
if(argc > 1)
{
for (int i = 1; i < argc; ++i)
{
w.handleMessage(QString(argv[i]));
}
}
app.setActivationWindow(&w, true);
QObject::connect(&app, SIGNAL(messageReceived(QString)), &w, SLOT(handleMessage(QString)));
return app.exec();
}
else
{
if(argc > 1)
{
for (int i = 1; i < argc; ++i)
{
app.sendMessage(QString(argv[i]));
}
}
}
return 0;
}