1 /***************************************************************************
2 * Copyright (C) 2005-2012 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "clientsettings.h"
22 #include "osxnotificationbackend.h"
25 #include <QHBoxLayout>
27 #import <Foundation/NSUserNotification.h>
31 void SendNotificationCenterMessage(NSString* title, NSString* subtitle) {
32 NSUserNotificationCenter* center =
33 [NSUserNotificationCenter defaultUserNotificationCenter];
34 NSUserNotification* notification =
35 [[NSUserNotification alloc] init];
37 [notification setTitle: title];
38 [notification setSubtitle: subtitle];
40 [center deliverNotification: notification];
42 [notification release];
47 OSXNotificationBackend::OSXNotificationBackend(QObject *parent)
48 : AbstractNotificationBackend(parent),
51 NotificationSettings notificationSettings;
52 notificationSettings.initAndNotify("OSXNotification/Enabled", this, SLOT(enabledChanged(QVariant)), true);
55 void OSXNotificationBackend::enabledChanged(const QVariant &value)
57 _enabled = value.toBool();
60 void OSXNotificationBackend::notify(const Notification ¬ification)
67 NSString* message = [[NSString alloc] initWithUTF8String:notification.sender.toUtf8().constData()];
68 NSString* summary = [[NSString alloc] initWithUTF8String:notification.message.toUtf8().constData()];
70 SendNotificationCenterMessage(message, summary);
76 void OSXNotificationBackend::close(uint notificationId)
80 SettingsPage *OSXNotificationBackend::createConfigWidget() const
82 return new ConfigWidget();
85 OSXNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent)
86 : SettingsPage("Internal", "OSXNotification", parent)
88 _enabledBox = new QCheckBox(tr("Show OS X notifications"));
89 connect(_enabledBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
90 QHBoxLayout *layout = new QHBoxLayout(this);
91 layout->addWidget(_enabledBox);
94 void OSXNotificationBackend::ConfigWidget::widgetChanged()
96 bool changed = (_enabled != _enabledBox->isChecked());
97 if (changed != hasChanged())
98 setChangedState(changed);
101 bool OSXNotificationBackend::ConfigWidget::hasDefaults() const
106 void OSXNotificationBackend::ConfigWidget::defaults()
108 _enabledBox->setChecked(true);
112 void OSXNotificationBackend::ConfigWidget::load()
114 NotificationSettings s;
115 _enabled = s.value("OSXNotification/Enabled", false).toBool();
116 _enabledBox->setChecked(_enabled);
117 setChangedState(false);
121 void OSXNotificationBackend::ConfigWidget::save()
123 NotificationSettings s;
124 s.setValue("OSXNotification/Enabled", _enabledBox->isChecked());