2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <QMainWindow>
23 #include <QtOpenGL/QGLWidget>
26 #include <QDeclarativeView>
27 #include <QDeclarativeContext>
28 #include <QDeclarativeError>
29 #include <QDeclarativeItem>
30 #include <QtDeclarative/QDeclarativeEngine>
31 #include <QtDeclarative/QDeclarativeContext>
33 // Gstreamer and QtGstQmlSink
35 #include <QtGstQmlSink/qmlvideosurfacegstsink.h>
36 #include <QtGstQmlSink/qmlgstvideoitem.h>
39 #include <TelepathyQt4/Types>
40 #include <TelepathyQt4/Account>
43 #include "../backend/telepathy-initializer.h"
44 #include "../backend/telepathy-client.h"
45 #include "../backend/session.h"
46 #include "../backend/voip/element-factory/defaultelementfactory.h"
47 #include "../backend/voip/element-factory/deviceelementfactory.h"
48 #include "../backend/accounts-model-item.h"
49 #include "../backend/accounts-model.h"
52 #include "main-window.h"
54 #include "telepathytypes.h"
55 #include "contacts-model-proxy.h"
56 #include "contacts-sort-filter-model-proxy.h"
57 #include "mobile-gst-element-factory.h"
58 #include "sound-notificator.h"
60 Makneto::Makneto(QApplication
*app
) : _app(app
),
66 _notificationsModel(0),
68 _ownDeviceFactory(0) {
70 // register data types to make its enums accessible from qml
71 qmlRegisterUncreatableType
<MaknetoBackend::AccountsModel
> ("org.makneto", 0, 1, "AccountsModel", QLatin1String("This type is only exported for its enums"));
72 qmlRegisterUncreatableType
<MaknetoBackend::Session
> ("org.makneto", 0, 1, "Session", QLatin1String("This type is only exported for its enums"));
73 qmlRegisterUncreatableType
<SessionModel
> ("org.makneto", 0, 1, "SessionModel", QLatin1String("This type is only exported for its enums"));
74 qmlRegisterUncreatableType
<NotificationsModel
> ("org.makneto", 0, 1, "NotificationsModel", QLatin1String("This type is only exported for its enums"));
75 qmlRegisterUncreatableType
<NotificationItem
> ("org.makneto", 0, 1, "NotificationItem", QLatin1String("This type is only exported for its enums"));
76 qmlRegisterUncreatableType
<TelepathyTypes
> ("org.makneto", 0, 1, "TelepathyTypes", QLatin1String("This type is only exported for its enums"));
78 /* register QtGstQmlSink items for playing videos */
79 qmlRegisterType
<QmlGstVideoItem
> ("Gst", 1, 0, "VideoItem");
80 qmlRegisterType
<QmlPainterVideoSurface
> ("Gst", 1, 0, "VideoSurface");
82 _qmlView
= new QDeclarativeView();
83 _window
= new MainWindow(_app
, this);
85 connect(_qmlView
, SIGNAL(statusChanged(QDeclarativeView::Status
)),
86 this, SLOT(onQmlStatusChanged(QDeclarativeView::Status
)));
88 _qmlView
->setResizeMode(QDeclarativeView::SizeRootObjectToView
);
89 _window
->setCentralWidget(_qmlView
);
94 MaknetoBackend::DeviceElementFactory::destroyAllFactories();
97 _qmlView
->deleteLater();
99 _window
->deleteLater();
100 if (_notificationsModel
)
101 _notificationsModel
->deleteLater();
103 _contactsProxy
->deleteLater();
105 _contactsModel
->deleteLater();
107 _sessionModel
->deleteLater();
108 if (_soundNotificator
)
109 _soundNotificator
->deleteLater();
110 if (_presenceManager
)
111 _presenceManager
->deleteLater();
114 bool Makneto::init() {
115 QDeclarativeContext
* rootContext
= _qmlView
->rootContext();
116 rootContext
->setContextProperty("makneto", this);
118 _qmlView
->setSource(QUrl("qrc:/declarative/mainview.qml"));
119 if (_qmlView
->status() == QDeclarativeView::Error
)
125 void Makneto::onQmlStatusChanged(QDeclarativeView::Status status
) {
127 case QDeclarativeView::Null
:
129 case QDeclarativeView::Ready
:
130 qDebug() << "Makneto: QML ready...";
133 case QDeclarativeView::Loading
:
134 qDebug() << "Makneto: Loading QML...";
136 case QDeclarativeView::Error
:
137 qWarning() << "Makneto: Error occurs while loading qml (ui) file. Exiting";
138 qWarning() << _qmlView
->errors();
142 qWarning() << "Makneto: udefind QML status" << status
;
146 void Makneto::onViewReady() {
149 _ownDeviceFactory
= new MobileGstElementFactory(_qmlView
);
150 MaknetoBackend::DeviceElementFactory::installFactory(_ownDeviceFactory
);
152 MaknetoBackend::TelepathyInitializer
*tpInit
= new MaknetoBackend::TelepathyInitializer();
155 SIGNAL(finished(MaknetoBackend::TelepathyClient
*)),
156 SLOT(onTelepathyInitializerFinished(MaknetoBackend::TelepathyClient
*)));
158 tpInit
->createClient(_app
->applicationName());
161 void Makneto::showWindow() {
163 qDebug() << "running on Symbian, show fullscreen";
164 _window
->showFullScreen();
165 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
166 qDebug() << "running on Maemo, show maximized";
167 _window
->showMaximized();
169 qDebug() << "Makneto: running environment is not Symbian nor Maemo - show in window";
174 void Makneto::onTelepathyInitializerFinished(MaknetoBackend::TelepathyClient
* client
) {
176 QDeclarativeContext
* rootContext
= _qmlView
->rootContext();
177 //QObject *rootObject = dynamic_cast<QObject*> (_qmlView->rootObject());
180 // - account model direct from backend
181 rootContext
->setContextProperty("accountsModel", client
->accountsModel());
183 _presenceManager
= new PresenceManager(client
->accountsModel(), this);
184 rootContext
->setContextProperty("presenceManager", _presenceManager
);
187 _contactsModel
= new ContactsModelProxy(this, client
->accountsModel());
188 _contactsProxy
= new ContactsSortFilterModelProxy(_contactsModel
, this);
189 rootContext
->setContextProperty("contactsModel", _contactsProxy
);
191 // - notifications model
192 _notificationsModel
= new NotificationsModel(client
, _window
, this);
193 rootContext
->setContextProperty("notificationsModel", _notificationsModel
);
196 _sessionModel
= new SessionModel(client
, _notificationsModel
, this);
197 rootContext
->setContextProperty("sessionsModel", _sessionModel
);
199 connect(_sessionModel
, SIGNAL(videoPreviewAvailable(const QString
&, QGst::ElementPtr
)), SLOT(onVideoPreviewAvailable(const QString
&, QGst::ElementPtr
)));
200 connect(_sessionModel
, SIGNAL(videoAvailable(const QString
&, QGst::ElementPtr
)), SLOT(onVideoAvailable(const QString
&, QGst::ElementPtr
)));
201 connect(_sessionModel
, SIGNAL(videoPreviewRemoved(const QString
&, QGst::ElementPtr
)), SLOT(onVideoPreviewRemoved(const QString
&, QGst::ElementPtr
)));
202 connect(_sessionModel
, SIGNAL(videoRemoved(const QString
&, QGst::ElementPtr
)), SLOT(onVideoRemoved(const QString
&, QGst::ElementPtr
)));
204 _soundNotificator
= new SoundNotificator(_app
, this);
205 connect(_sessionModel
, SIGNAL(startBeeping()), _soundNotificator
, SLOT(onStartBeeping()));
206 connect(_sessionModel
, SIGNAL(stopBeeping()), _soundNotificator
, SLOT(onStopBeeping()));
207 connect(_sessionModel
, SIGNAL(startRinging()), _soundNotificator
, SLOT(onStartRinging()));
208 connect(_sessionModel
, SIGNAL(stopRinging()), _soundNotificator
, SLOT(onStopRinging()));
211 qDebug() << "Makneto: Telepathy has been initialised";
214 void Makneto::onVideoPreviewAvailable(const QString
&sessionId
, QGst::ElementPtr videoOutElemPtr
) {
215 //QDeclarativeContext* rootContext = _qmlView->rootContext();
217 QmlPainterVideoSurface
*surface
= _ownDeviceFactory
->mapElementToSurface(videoOutElemPtr
);
219 qWarning() << "Makneto: element for id" << sessionId
<< " is not created by own factory";
222 //rootContext->setContextProperty(sessionId, surface);
223 qDebug() << "Makneto: videoSurfaceReady preview," << sessionId
<< "," << surface
;
224 emit
videoSurfaceReady("preview", sessionId
, surface
);
227 void Makneto::onVideoAvailable(const QString
&sessionId
, QGst::ElementPtr videoOutElemPtr
) {
228 //QDeclarativeContext* rootContext = _qmlView->rootContext();
230 QmlPainterVideoSurface
*surface
= _ownDeviceFactory
->mapElementToSurface(videoOutElemPtr
);
232 qWarning() << "Makneto: element for id" << sessionId
<< " is not created by own factory";
235 //rootContext->setContextProperty(sessionId, surface);
236 qDebug() << "Makneto: videoSurfaceReady video," << sessionId
<< "," << surface
;
237 emit
videoSurfaceReady("video", sessionId
, surface
);
240 void Makneto::onVideoPreviewRemoved(const QString
&sessionId
, QGst::ElementPtr videoOutElemPtr
) {
241 _ownDeviceFactory
->forgetElement(videoOutElemPtr
);
242 emit
videoSurfaceRemoved("preview", sessionId
);
245 void Makneto::onVideoRemoved(const QString
&sessionId
, QGst::ElementPtr videoOutElemPtr
) {
246 _ownDeviceFactory
->forgetElement(videoOutElemPtr
);
247 emit
videoSurfaceRemoved("video", sessionId
);
251 #include "makneto.moc"