2
* Copyright (C) 2014 Canonical Ltd.
4
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
6
* This file is part of online-accounts-ui
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "notification.h"
25
#include <QCoreApplication>
27
#include <libnotify/notification.h>
28
#include <libnotify/notify.h>
30
using namespace OnlineAccountsUi;
32
namespace OnlineAccountsUi {
34
class NotificationPrivate: public QObject
37
Q_DECLARE_PUBLIC(Notification)
40
NotificationPrivate(const QString &summary,
42
Notification *notification);
43
~NotificationPrivate();
45
static void actionCallback(NotifyNotification *, char *action,
49
NotifyNotification *m_notification;
50
mutable Notification *q_ptr;
55
NotificationPrivate::NotificationPrivate(const QString &summary,
57
Notification *notification):
58
QObject(notification),
62
if (!notify_is_initted()) {
63
QByteArray name = QCoreApplication::applicationName().toUtf8();
64
notify_init(name.constData());
67
QByteArray summaryUtf8 = summary.toUtf8();
68
QByteArray bodyUtf8 = body.toUtf8();
69
m_notification = notify_notification_new(summaryUtf8.constData(),
72
g_signal_connect_swapped(m_notification, "closed",
73
G_CALLBACK(&Notification::closed), notification);
76
NotificationPrivate::~NotificationPrivate()
78
g_object_unref(m_notification);
81
void NotificationPrivate::actionCallback(NotifyNotification *, char *action,
84
Q_EMIT q->actionInvoked(QString::fromUtf8(action));
87
Notification::Notification(const QString &summary,
91
d_ptr(new NotificationPrivate(summary, body, this))
95
Notification::~Notification()
99
void Notification::addAction(const QString &action, const QString &label)
102
QByteArray actionUtf8 = action.toUtf8();
103
QByteArray labelUtf8 = label.toUtf8();
104
notify_notification_add_action(d->m_notification,
105
actionUtf8, labelUtf8,
106
NotifyActionCallback(
107
&NotificationPrivate::actionCallback),
111
void Notification::show()
114
GError *error = NULL;
115
if (!notify_notification_show(d->m_notification, &error)) {
116
qWarning() << "Couldn't show notification:" << error->message;
117
g_clear_error(&error);
121
#include "notification.moc"