2
Copyright (C) 2010 Alex Fiestas <alex@eyeos.org>
3
Copyright (C) 2010 UFO Coders <info@ufocoders.com>
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 3 of the License, or
8
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
20
#include "discoverpage.h"
21
#include "ui_discover.h"
22
#include "../bluewizard.h"
24
#include <QListWidgetItem>
31
#include <bluedevil/bluedevil.h>
33
using namespace BlueDevil;
35
DiscoverPage::DiscoverPage(QWidget* parent): QWizardPage(parent), m_counter(0), m_wizard(0)
37
setTitle("Discover Devices");
40
m_timer = new QTimer();
41
m_timer->setInterval(100);
43
connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
44
connect(scanBtn, SIGNAL(clicked()), this, SLOT(startScan()));
46
connect(deviceList, SIGNAL(itemActivated(QListWidgetItem*)), this,
47
SLOT(itemSelected(QListWidgetItem*)));
50
DiscoverPage::~DiscoverPage()
55
void DiscoverPage::initializePage()
57
kDebug() << "Initialize Page";
59
kDebug() << "First time in the page";
60
m_wizard = static_cast<BlueWizard* >(wizard());
61
connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(Device*)), this,
62
SLOT(deviceFound(Device*)));
65
connect(m_wizard, SIGNAL(currentIdChanged(int)), this, SLOT(leavePage(int)));
69
void DiscoverPage::leavePage(int id)
72
progressBar->setValue(0);
77
void DiscoverPage::cleanupPage()
82
bool DiscoverPage::isComplete() const
84
if (m_wizard->deviceAddress().isEmpty()) {
90
void DiscoverPage::startScan()
93
progressBar->setValue(0);
97
Manager::self()->defaultAdapter()->startDiscovery();
101
void DiscoverPage::stopScan()
105
Manager::self()->defaultAdapter()->stopDiscovery();
108
void DiscoverPage::deviceFound(Device* device)
110
QString name = device->alias();
111
if (device->alias() != device->name() && !device->name().isEmpty()) {
112
name.append(" ("+device->name()+")");
115
QString icon = device->icon();
116
if (icon.isEmpty()) {
117
icon.append("preferences-system-bluetooth");
120
QListWidgetItem *item = new QListWidgetItem(KIcon(icon), name, deviceList);
122
item->setData(Qt::UserRole, device->address());
123
deviceList->addItem(item);
126
void DiscoverPage::timeout()
129
progressBar->setValue(m_counter);
131
if (m_counter == 100) {
136
void DiscoverPage::itemSelected(QListWidgetItem* item)
138
m_wizard->setDeviceAddress(item->data(Qt::UserRole).toByteArray());
139
emit completeChanged();
142
int DiscoverPage::nextId() const
145
if (!m_wizard->deviceAddress().isEmpty()) {
146
Device *device = Manager::self()->defaultAdapter()->deviceForAddress(m_wizard->deviceAddress());
147
if (device->isPaired()) {
148
kDebug() << "Device is paired, jumping";
149
return BlueWizard::Services;
153
return BlueWizard::Pin;