some fixes, export hangup action to qml
[makneto-zunavac1.git] / src / ui-mobile / notification-item.cpp
blobefed3e8df2dfc71f3d3517c11b39ae4f81e3b6ca
1 /*
2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
3 *
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.
8 *
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.
21 #include "notification-item.h"
22 #include "notifications-model.h"
24 static const QString ACCEPT_KEY = "accept";
25 static const QString DECLINE_KEY = "decline";
27 NotificationItem::NotificationItem(int id, MaknetoBackend::Session *session, NotificationType type, QString msg) :
28 id(id),
29 type(type),
30 message(msg),
31 _session(session),
32 _notification(NULL),
33 _expireTimer(NULL) {
35 qDebug() << "NotificationItem: create notification " << getTitle() << " " << _session->getName();
37 if (Notification::isInitted()) {
38 _notification = new Notification(getTitle(), _session->getName(), _session->getIcon(), this);
40 connect(_notification, SIGNAL(actionInvoked(const QString &)), this, SLOT(onNotificationAction(const QString &)));
41 connect(_notification, SIGNAL(closed(quint32)), this, SLOT(onNotificationClosed(quint32)));
43 _notification->addAction(ACCEPT_KEY, "Accept");
44 _notification->addAction(DECLINE_KEY, "Decline");
45 _notification->setTimeout(10000); // 10s
46 _notification->show();
49 if (type == AudioCallType || type == VideoCallType) {
50 connect(session, SIGNAL(callEnded(QString)), SLOT(onCallEnded(QString)));
53 if (type == CallErrorType || type == SendMessageErrorType) {
54 QTimer::singleShot(5000, this, SLOT(onExpire()));
58 void NotificationItem::onNotificationAction(const QString &action) {
59 if (action == ACCEPT_KEY) {
60 emit acceptNotification(id);
61 return;
63 if (action == DECLINE_KEY) {
64 emit declineNotification(id);
65 return;
67 qWarning() << "NotificationItem: udefined notification action" << action;
70 void NotificationItem::onNotificationClosed(quint32) {
71 _notification = NULL;
74 NotificationItem::~NotificationItem() {
75 if (_notification)
76 _notification->close(); // _notification autodete is set to true...
79 void NotificationItem::onExpire() {
80 emit notificationExpired(getId());
83 void NotificationItem::onCallEnded(const QString &msg) {
84 qDebug() << "NotificationItem: call ended, decline notification";
85 emit declineNotification(id);
88 QVariant NotificationItem::data(int role) {
89 switch (role) {
90 case NotificationsModel::IdRole:
91 return id;
92 case NotificationsModel::TitleRole:
93 return getTitle();
94 case NotificationsModel::SessionIdRole:
95 return _session->getUniqueName();
96 case NotificationsModel::SessionNameRole:
97 return _session->getName();
98 case NotificationsModel::MessageRole:
99 return message;
100 case NotificationsModel::TypeRole:
101 return type;
102 case NotificationsModel::IconRole:
103 return _session->getIcon();
104 default:
105 return QVariant();
109 QString NotificationItem::getTitle() {
110 switch (type) {
111 case VideoCallType:
112 return "Incoming Video Call";
113 case AudioCallType:
114 return "Incoming Audio Call";
115 case CallErrorType:
116 return "Call Error";
117 case SendMessageErrorType:
118 return "Sending error";
119 case ChatType:
120 default:
121 return "New Message";
125 int NotificationItem::getId() {
126 return id;
129 NotificationItem::NotificationType NotificationItem::getType() {
130 return type;
133 MaknetoBackend::Session *NotificationItem::getSession() {
134 return _session;
137 #include "notification-item.moc"