~ubuntu-branches/ubuntu/maverick/bluedevil/maverick-proposed

« back to all changes in this revision

Viewing changes to src/daemon/helpers/confirmmodechange/confirmmodechange.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2010-08-07 09:04:19 UTC
  • Revision ID: james.westby@ubuntu.com-20100807090419-68k54ucso2htcf5z
Tags: upstream-1.0~rc2
ImportĀ upstreamĀ versionĀ 1.0~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 Alejandro Fiestas Olivares <alex@eyeos.org>        *
 
3
 *   Copyright (C) 2010 Eduardo Robles Elvira <edulix@gmail.com>           *
 
4
 *   Copyright (C) 2010 UFO Coders <info@ufocoders.com>                    *
 
5
 *                                                                         *
 
6
 *   This program is free software; you can redistribute it and/or modify  *
 
7
 *   it under the terms of the GNU General Public License as published by  *
 
8
 *   the Free Software Foundation; either version 2 of the License, or     *
 
9
 *   (at your option) any later version.                                   *
 
10
 *                                                                         *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 
20
 ***************************************************************************/
 
21
 
 
22
#include "confirmmodechange.h"
 
23
 
 
24
#include <QtCore/QDebug>
 
25
#include <QtCore/QCoreApplication>
 
26
#include <QtCore/QTimer>
 
27
 
 
28
#include <KIcon>
 
29
#include <kiconloader.h>
 
30
#include <knotification.h>
 
31
#include <klocale.h>
 
32
 
 
33
ConfirmModeChange::ConfirmModeChange()
 
34
    : QObject()
 
35
{
 
36
    KNotification *notification = new KNotification("bluedevilConfirmModechange",
 
37
                                                    KNotification::Persistent, this);
 
38
 
 
39
    notification->setText(i18nc(
 
40
        "Showed in a notification when the Bluetooth mode is going to be changed (for example to flight mode), the %1 is the name of the mode",
 
41
        "Change bluetooth mode to %1 ?", qApp->arguments()[1])
 
42
    );
 
43
 
 
44
    QStringList actions;
 
45
    actions.append(i18nc("Confirm the bluetooth mode change, showed in a notification button", "Confirm"));
 
46
    actions.append(i18nc("Deny the bluetooth mdoe change, showed in a notification", "Deny"));
 
47
 
 
48
    notification->setActions(actions);
 
49
 
 
50
    connect(notification, SIGNAL(action1Activated()),this, SLOT(confirm()));
 
51
    connect(notification, SIGNAL(action2Activated()),this, SLOT(deny()));
 
52
    connect(notification, SIGNAL(closed()), this, SLOT(deny()));
 
53
    connect(notification, SIGNAL(ignored()), this, SLOT(deny()));
 
54
 
 
55
    // We're using persistent notifications so we have to use our own timeout (10s)
 
56
    QTimer::singleShot(10000, notification, SLOT(close()));
 
57
    notification->setPixmap(KIcon("preferences-system-bluetooth").pixmap(42, 42));
 
58
    notification->sendEvent();
 
59
}
 
60
 
 
61
void ConfirmModeChange::confirm()
 
62
{
 
63
    qDebug() << "confirmed";
 
64
    qApp->exit(0);
 
65
}
 
66
 
 
67
void ConfirmModeChange::deny()
 
68
{
 
69
    qDebug() << "Denied";
 
70
    qApp->exit(1);
 
71
}
 
72