-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (111 loc) · 4.31 KB
/
main.cpp
File metadata and controls
127 lines (111 loc) · 4.31 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* This file is part of TTRss, a Tiny Tiny RSS Reader App
* for MeeGo Harmattan and Sailfish OS.
* Copyright (C) 2012–2016 Hauke Schade
*
* TTRss 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.
*
* TTRss 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 TTRss; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
* http://www.gnu.org/licenses/.
*/
#include <QtCore/QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#ifdef QT_QML_DEBUG
#include <QtQuick>
#endif
#if defined(Q_OS_SAILFISH)
#include <sailfishapp.h>
#endif
#else
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeContext>
#include "qmlapplicationviewer.h"
#include <QDeclarativeEngine>
#endif
#include <QtCore/QTranslator>
#include <QtCore/QLocale>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include "settings.hh"
#include "qmlutils.hh"
#include "mynetworkmanager.hh"
#if defined(Q_OS_HARMATTAN)
#define USE_THEME
#endif
#if defined(USE_THEME)
#include "theme.hh"
#endif
Q_DECL_EXPORT int main(int argc, char *argv[])
{
#if defined(Q_OS_SAILFISH)
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QScopedPointer<QGuiApplication> app(new QGuiApplication(argc, argv));
#else
QScopedPointer<QApplication> app(createApplication(argc, argv));
#endif
app->setApplicationVersion(APP_VERSION);
app->setApplicationName(QStringLiteral("ttrss"));
app->setOrganizationName(QStringLiteral("de.cnlpete"));
app->setOrganizationDomain(QStringLiteral("de.cnlpete"));
// check for old settings files, try to migrate to new location
Settings::migrateSettings_v1();
Settings::migrateSettings_v2();
QString locale = QLocale::system().name();
QTranslator translator;
/* the ":/" is a special directory Qt uses to
* distinguish resources;
* NB this will look for a filename matching locale + ".qm";
* if that's not found, it will truncate the locale to
* the first two characters (e.g. "en_GB" to "en") and look
* for that + ".qm"; if not found, it will look for a
* qml-translations.qm file; if not found, no translation is done
*/
if (translator.load("qml-translation." + locale, ":/i18n"))
app->installTranslator(&translator);
#if defined(Q_OS_SAILFISH)
QQuickView* viewer = SailfishApp::createView();
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QScopedPointer<QQuickView> viewer(new QQuickView);
viewer->setResizeMode(QQuickView::SizeRootObjectToView);
#else
QmlApplicationViewer *viewer = new QmlApplicationViewer();
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
//QObject::connect(viewer.engine(), SIGNAL(quit()), viewer.data, SLOT(close()));
#endif
viewer->engine()->setNetworkAccessManagerFactory(MyNetworkManager::instance());
viewer->rootContext()->setContextProperty("network", MyNetworkManager::instance());
viewer->rootContext()->setContextProperty("APP_VERSION", APP_VERSION);
viewer->rootContext()->setContextProperty("QMLUtils", QMLUtils::instance());
viewer->rootContext()->setContextProperty("settings", Settings::instance());
#ifdef USE_THEME
viewer->rootContext()->setContextProperty("MyTheme", Theme::instance());
#endif
#if defined(Q_OS_SAILFISH)
viewer->setSource(SailfishApp::pathTo("qml/sailfish/harbour-ttrss.qml"));
#elif defined(Q_OS_UBUNTU_TOUCH)
viewer->setSource(QStringLiteral("qml/ubuntu-touch/main.qml"));
#else
viewer->setMainQmlFile(QLatin1String("qml/harmattan/main.qml"));
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
viewer->show();
#else
viewer->showExpanded();
#endif
return app->exec();
}