This repository has been archived by the owner on Mar 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmain.cpp
134 lines (109 loc) · 4.29 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Copyright (C) 2012 Dickson Leong
This file is part of Tweetian.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/qdeclarative.h>
#include <QtCore/QTranslator>
#include <QtCore/QLocale>
#include <QtCore/QFile>
#include "qmlapplicationviewer.h"
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
#include <QtGui/QSplashScreen>
#include <QtGui/QPixmap>
#endif
#include "src/qmlutils.h"
#include "src/imageuploader.h"
#include "src/thumbnailcacher.h"
#include "src/userstream.h"
#include "src/networkmonitor.h"
#if defined(Q_OS_HARMATTAN) || defined(Q_WS_SIMULATOR)
#include "src/harmattanutils.h"
#endif
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
#include "src/symbianutils.h"
#endif
#ifdef Q_OS_HARMATTAN
#include <QtDBus/QDBusConnection>
#include "src/tweetianif.h"
#endif
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QString lang = QLocale::system().name();
lang.truncate(2); // ignore the country code
const QStringList appArgs = app->arguments();
foreach (const QString &arg, appArgs) {
if (arg.startsWith(QLatin1String("--lang="))) {
lang = arg.mid(7);
break;
}
}
QTranslator translator;
if (QFile::exists(":/i18n/tweetian_" + lang + ".qm")) {
qDebug("Translation for \"%s\" exists", qPrintable(lang));
translator.load("tweetian_" + lang, ":/i18n");
}
else {
qDebug("Translation for \"%s\" not exists, using the default language (en)", qPrintable(lang));
translator.load("tweetian_en", ":/i18n");
}
app->installTranslator(&translator);
app->setApplicationName("Tweetian");
app->setOrganizationName("Tweetian");
app->setApplicationVersion(APP_VERSION);
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
QSplashScreen *splash = new QSplashScreen(QPixmap(":/splash/tweetian-splash-symbian.jpg"));
splash->show();
splash->showMessage(QSplashScreen::tr("Loading..."), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
#endif
QDeclarativeView view;
#ifdef Q_OS_HARMATTAN
new TweetianIf(app.data(), &view);
QDBusConnection bus = QDBusConnection::sessionBus();
bus.registerService("com.tweetian");
bus.registerObject("/com/tweetian", app.data());
#endif
QMLUtils qmlUtils(&view);
view.rootContext()->setContextProperty("QMLUtils", &qmlUtils);
ThumbnailCacher thumbnailCacher;
view.rootContext()->setContextProperty("thumbnailCacher", &thumbnailCacher);
NetworkMonitor networkMonitor;
view.rootContext()->setContextProperty("networkMonitor", &networkMonitor);
view.rootContext()->setContextProperty("APP_VERSION", APP_VERSION);
#if defined(Q_OS_HARMATTAN) || defined(Q_WS_SIMULATOR)
HarmattanUtils harmattanUtils;
view.rootContext()->setContextProperty("harmattanUtils", &harmattanUtils);
#endif
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
SymbianUtils symbianUtils(&view);
view.rootContext()->setContextProperty("symbianUtils", &symbianUtils);
#endif
qmlRegisterType<ImageUploader>("Uploader", 1, 0, "ImageUploader");
qmlRegisterType<UserStream>("UserStream", 1, 0, "UserStream");
#if defined(Q_OS_HARMATTAN)
view.setSource(QUrl("qrc:/qml/tweetian-harmattan/main.qml"));
#elif defined(Q_OS_SYMBIAN)
view.setSource(QUrl("qrc:/qml/tweetian-symbian/main.qml"));
#else
view.setSource(QUrl("qrc:/qml/tweetian-harmattan/main.qml"));
#endif
view.showFullScreen();
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
splash->finish(&view);
splash->deleteLater();
#endif
return app->exec();
}