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

« back to all changes in this revision

Viewing changes to src/wizard/pages/servicespage.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 UFO Coders <info@ufocoders.com>
 
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 3 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.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
 
 
19
#include "servicespage.h"
 
20
#include "ui_services.h"
 
21
#include "serviceoption.h"
 
22
#include "../bluewizard.h"
 
23
 
 
24
#include <QButtonGroup>
 
25
#include <kservice.h>
 
26
#include <bluedevil/bluedevil.h>
 
27
#include <KNotification>
 
28
#include <kdebug.h>
 
29
 
 
30
ServicesPage::ServicesPage(QWidget* parent): QWizardPage(parent)
 
31
{
 
32
    setTitle("Service selection");
 
33
    setupUi(this);
 
34
}
 
35
 
 
36
void ServicesPage::initializePage()
 
37
{
 
38
   kDebug() << "Initializing page";
 
39
    m_wizard = static_cast<BlueWizard*>(wizard());
 
40
    KService::List services = m_wizard->services();
 
41
    Device *device = Manager::self()->defaultAdapter()->deviceForAddress(m_wizard->deviceAddress());
 
42
 
 
43
    QStringList uuids = device->UUIDs();
 
44
    QByteArray preselectedUuid = m_wizard->preselectedUuid();
 
45
    Q_FOREACH(QString uuid, uuids) {
 
46
        uuid = uuid.toUpper();
 
47
        kDebug() << "Checking uuid: " << uuid;
 
48
        Q_FOREACH(const KSharedPtr<KService> service, services) {
 
49
            if (preselectedUuid.isEmpty()) {
 
50
                if (service.data()->property("X-BlueDevil-UUIDS").toStringList().contains(uuid)) {
 
51
                    kDebug() << "uuid: " << uuid << " " << service->name();
 
52
                    services.removeOne(service);
 
53
                    addService(service.data());
 
54
                }
 
55
            } else {
 
56
                kDebug() << "Checkign direct access: " << preselectedUuid;
 
57
                if (service.data()->property("X-BlueDevil-UUIDS").toStringList().contains(preselectedUuid)) {
 
58
                    kDebug() << "Service found: " << service->name();
 
59
                    m_wizard->setService(service.data());
 
60
                    m_wizard->done(1);
 
61
                }
 
62
            }
 
63
        }
 
64
    }
 
65
 
 
66
    //If no service has been added (no compatible services)
 
67
    if (d_layout->count() == 0) {
 
68
        kDebug() << "Any service has been found, launching the notification";
 
69
        QString desc(i18n("%1 has been paired successfully").arg(device->friendlyName()));
 
70
 
 
71
        KNotification::event(
 
72
            KNotification::Notification,
 
73
            desc,
 
74
            KIcon(device->icon()).pixmap(48,48)
 
75
        )->sendEvent();
 
76
        m_wizard->done(0);
 
77
        return;
 
78
    }
 
79
 
 
80
    ServiceOption *noneOption = new ServiceOption(i18n("None"), i18n("Do not initialize any service"), m_buttonGroup);
 
81
    connect(noneOption, SIGNAL(selected(const KService*)), this, SLOT(selected(const KService*)));
 
82
    d_layout->addWidget(noneOption);
 
83
}
 
84
 
 
85
void ServicesPage::cleanupPage()
 
86
{
 
87
    QList <QAbstractButton *>  buttonList =  m_buttonGroup.buttons();
 
88
    Q_FOREACH(QAbstractButton *btn, buttonList) {
 
89
         m_buttonGroup.removeButton(btn);
 
90
    }
 
91
 
 
92
    QLayoutItem *child;
 
93
    while ((child = d_layout->takeAt(0)) != 0) {
 
94
        delete child->widget();
 
95
        delete child;
 
96
    }
 
97
}
 
98
 
 
99
void ServicesPage::addService(const KService* service)
 
100
{
 
101
    ServiceOption *widget = new ServiceOption(service, m_buttonGroup, this);
 
102
    connect(widget, SIGNAL(selected(const KService*)), this, SLOT(selected(const KService*)));
 
103
 
 
104
    if (d_layout->count() == 0) {
 
105
        m_wizard->setService(service);
 
106
        widget->setChecked(true);
 
107
    }
 
108
 
 
109
    d_layout->addWidget(widget);
 
110
}
 
111
 
 
112
void ServicesPage::selected(const KService* service)
 
113
{
 
114
    kDebug() << "Service selected: " << (service ? service->name() : "none");
 
115
    m_wizard->setService(service);
 
116
}