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.
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
) :
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
);
63 if (action
== DECLINE_KEY
) {
64 emit
declineNotification(id
);
67 qWarning() << "NotificationItem: udefined notification action" << action
;
70 void NotificationItem::onNotificationClosed(quint32
) {
74 NotificationItem::~NotificationItem() {
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
) {
90 case NotificationsModel::IdRole
:
92 case NotificationsModel::TitleRole
:
94 case NotificationsModel::SessionIdRole
:
95 return _session
->getUniqueName();
96 case NotificationsModel::SessionNameRole
:
97 return _session
->getName();
98 case NotificationsModel::MessageRole
:
100 case NotificationsModel::TypeRole
:
102 case NotificationsModel::IconRole
:
103 return _session
->getIcon();
109 QString
NotificationItem::getTitle() {
112 return "Incoming Video Call";
114 return "Incoming Audio Call";
117 case SendMessageErrorType
:
118 return "Sending error";
121 return "New Message";
125 int NotificationItem::getId() {
129 NotificationItem::NotificationType
NotificationItem::getType() {
133 MaknetoBackend::Session
*NotificationItem::getSession() {
137 #include "notification-item.moc"