-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
110 lines (87 loc) · 3.98 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
/*
This file is part of Helium.
Helium 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.
Helium 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 Helium. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib-object.h>
#include <QtDBus/QDBusInterface>
#include <QtFeedback/QFeedbackHapticsEffect>
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "upnp/upnprenderer.h"
#include "upnp/upnpdevice.h"
#include "upnp/upnpdevicemodel.h"
#include "upnp/upnpmediaserver.h"
#include "upnp/upnpservermodel.h"
#include "upnp/upnprenderermodel.h"
#include "upnp/browsemodel.h"
#include "upnp/browsemodelstack.h"
#include "networkcontrol.h"
#include "settings.h"
#include "version.h"
#include <QtDeclarative>
QDeclarativeContext *rootContext;
Q_DECL_EXPORT int main(int argc, char *argv[])
{
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init ();
#endif
// Used in GUPnP User-Agent
g_set_application_name("Helium");
// QML glue
qmlRegisterType<UPnPRenderer>("org.jensge.UPnP", 1, 0, "UPnPRenderer");
qmlRegisterType<UPnPMediaServer>("org.jensge.UPnP", 1, 0, "UPnPMediaServer");
qmlRegisterType<BrowseModel>("org.jensge.UPnP", 1, 0, "BrowseModel");
QScopedPointer<QApplication> app(createApplication(argc, argv));
QString locale = QLocale::system().name();
QTranslator translator;
if (!(translator.load(QLatin1String("tr_") + locale, QLatin1String(":/")))) {
translator.load(QLatin1String("tr_en"), QLatin1String(":/"));
}
app->installTranslator(&translator);
UPnPServerModel serverModel;
UPnPRendererModel rendererModel;
Settings settings;
// only annoy the user on start-up by showing the connection dialog.
// GUPnP can handle appearing and disappearing network devices itself quite
// fine so there's no need to listen and pop-up that stupid connection
// dialog all the time
NetworkControl control;
QtMobility::QFeedbackHapticsEffect effect;
effect.setIntensity(1.0);
effect.setDuration(100);
auto version = QLatin1String (HELIUM_VERSION);
QmlApplicationViewer viewer;
rootContext = viewer.rootContext();
rootContext->setContextProperty(QLatin1String("serverModel"), &serverModel);
rootContext->setContextProperty(QLatin1String("rendererModel"), &rendererModel);
rootContext->setContextProperty(QLatin1String("browseModel"), &BrowseModel::empty());
rootContext->setContextProperty(QLatin1String("browseModelStack"), &BrowseModelStack::getDefault());
rootContext->setContextProperty(QLatin1String("networkControl"), &control);
rootContext->setContextProperty(QLatin1String("feedback"), &effect);
rootContext->setContextProperty(QLatin1String("settings"), &settings);
rootContext->setContextProperty(QLatin1String("VERSION"), version);
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setMainQmlFile(QLatin1String("qml/Helium/main.qml"));
viewer.showExpanded();
#ifdef HARMATTAN
if (settings.startMediaSharing()) {
QDBusInterface fdo(QLatin1String("org.freedesktop.DBus"), QLatin1String("/"), QLatin1String("org.freedesktop.DBus"));
bool isRunning = fdo.call(QLatin1String("NameHasOwner"), Settings::RYGEL_DBUS_IFACE).arguments().first().toBool();
if (settings.mediaSharingAvailable() && not isRunning) {
// Can't use D-Bus activation since we need to keep this particular port
QProcess::startDetached (QLatin1String("/usr/bin/rygel"),
QStringList() << QLatin1String("--port=57734"));
}
}
#endif
return app->exec();
}