summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/main.cpp')
-rw-r--r--utils/rbutilqt/main.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/utils/rbutilqt/main.cpp b/utils/rbutilqt/main.cpp
new file mode 100644
index 0000000000..47c625b54d
--- /dev/null
+++ b/utils/rbutilqt/main.cpp
@@ -0,0 +1,112 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Riebeling
10 *
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19
20#include <QCoreApplication>
21#include <QSettings>
22#include <QStyleFactory>
23#include "rbutilqt.h"
24#include "systrace.h"
25#include "Logger.h"
26#include "ConsoleAppender.h"
27#include "FileAppender.h"
28
29#ifdef STATIC
30#if QT_VERSION < 0x050400
31/*
32 * accessibility is no longer a plugin after 5.4.0:
33 * <https://bugreports.qt.io/browse/QTBUG-37957#comment-239189>
34 */
35#include <QtPlugin>
36Q_IMPORT_PLUGIN(AccessibleFactory)
37#endif
38#endif
39
40
41int main( int argc, char ** argv ) {
42#if QT_VERSION >= 0x050600
43 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
44 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
45#endif
46 QApplication app( argc, argv );
47#ifdef Q_OS_WIN
48 qApp->setStyle(QStyleFactory::create("Fusion"));
49#endif
50 ConsoleAppender* consoleAppender = new ConsoleAppender();
51 consoleAppender->setFormat("[%{file}:%{line} %{type}] %{message}\n");
52 cuteLoggerInstance()->registerAppender(consoleAppender);
53 SysTrace::rotateTrace();
54 QString tracefile = QDir::tempPath() + "/rbutil-trace.log";
55 FileAppender* fileAppender = new FileAppender();
56 fileAppender->setFormat("[%{file}:%{line} %{type}] %{message}\n");
57 fileAppender->setFileName(tracefile);
58 cuteLoggerInstance()->registerAppender(fileAppender);
59 LOG_INFO() << "Starting trace at" << QDateTime::currentDateTime().toString(Qt::ISODate);
60
61#if defined(Q_OS_MAC)
62 QDir dir(QApplication::applicationDirPath());
63 dir.cdUp();
64 dir.cd("plugins");
65 QApplication::addLibraryPath(dir.absolutePath());
66#endif
67 QString absolutePath = QCoreApplication::instance()->applicationDirPath();
68 // portable installation:
69 // check for a configuration file in the program folder.
70 QSettings *user;
71 if(QFileInfo(absolutePath + "/RockboxUtility.ini").isFile())
72 user = new QSettings(absolutePath + "/RockboxUtility.ini", QSettings::IniFormat, nullptr);
73 else user = new QSettings(QSettings::IniFormat, QSettings::UserScope, "rockbox.org", "RockboxUtility");
74
75 QString applang = QLocale::system().name();
76 QTranslator translator;
77 QTranslator qttrans;
78 // install translator
79 if(!user->value("lang", "").toString().isEmpty()) {
80 applang = user->value("lang", "").toString();
81 }
82 if(!applang.isEmpty()) {
83 if(!translator.load("rbutil_" + applang, absolutePath))
84 translator.load("rbutil_" + applang, ":/lang");
85 if(!qttrans.load("qt_" + applang,
86 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
87 qttrans.load("qt_" + applang, ":/lang");
88
89 QLocale::setDefault(QLocale(applang));
90 }
91 delete user;
92 app.installTranslator(&translator);
93 app.installTranslator(&qttrans);
94 //: This string is used to indicate the writing direction. Translate it
95 //: to "RTL" (without quotes) for RTL languages. Anything else will get
96 //: treated as LTR language.
97 if(QObject::tr("LTR") == "RTL")
98 app.setLayoutDirection(Qt::RightToLeft);
99
100 // keep a list of installed translators. Needed to be able uninstalling them
101 // later again (in case of translation changes)
102 QList<QTranslator*> translators;
103 translators.append(&translator);
104 translators.append(&qttrans);
105 RbUtilQt window(nullptr);
106 RbUtilQt::translators = translators;
107 window.show();
108
109// app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
110 return app.exec();
111
112}