2
Copyright (C) 2010 UFO Coders <info@ufocoders.com>
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.
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, see <http://www.gnu.org/licenses/>.
19
#include "servicespage.h"
20
#include "ui_services.h"
21
#include "serviceoption.h"
22
#include "../bluewizard.h"
24
#include <QButtonGroup>
26
#include <bluedevil/bluedevil.h>
27
#include <KNotification>
30
ServicesPage::ServicesPage(QWidget* parent): QWizardPage(parent)
32
setTitle("Service selection");
36
void ServicesPage::initializePage()
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());
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());
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());
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()));
72
KNotification::Notification,
74
KIcon(device->icon()).pixmap(48,48)
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);
85
void ServicesPage::cleanupPage()
87
QList <QAbstractButton *> buttonList = m_buttonGroup.buttons();
88
Q_FOREACH(QAbstractButton *btn, buttonList) {
89
m_buttonGroup.removeButton(btn);
93
while ((child = d_layout->takeAt(0)) != 0) {
94
delete child->widget();
99
void ServicesPage::addService(const KService* service)
101
ServiceOption *widget = new ServiceOption(service, m_buttonGroup, this);
102
connect(widget, SIGNAL(selected(const KService*)), this, SLOT(selected(const KService*)));
104
if (d_layout->count() == 0) {
105
m_wizard->setService(service);
106
widget->setChecked(true);
109
d_layout->addWidget(widget);
112
void ServicesPage::selected(const KService* service)
114
kDebug() << "Service selected: " << (service ? service->name() : "none");
115
m_wizard->setService(service);