diff --git a/src/wizard/pages/discoverpage.cpp b/src/wizard/pages/discoverpage.cpp index dfdb1653..2c8b1700 100644 --- a/src/wizard/pages/discoverpage.cpp +++ b/src/wizard/pages/discoverpage.cpp @@ -1,172 +1,173 @@ /* Copyright (C) 2010 Alex Fiestas Copyright (C) 2010 UFO Coders This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "discoverpage.h" #include "ui_discover.h" #include "../bluewizard.h" #include #include #include #include #include #include using namespace BlueDevil; DiscoverPage::DiscoverPage(QWidget* parent): QWizardPage(parent), m_wizard(0) { setTitle("Discover Devices"); setupUi(this); connect(deviceList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*))); } DiscoverPage::~DiscoverPage() { } void DiscoverPage::initializePage() { kDebug() << "Initialize Page"; if (!m_wizard) { kDebug() << "First time in the page"; m_wizard = static_cast(wizard()); - connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(Device*)), this, - SLOT(deviceFound(Device*))); + connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(QVariantMap)), this, + SLOT(deviceFound(QVariantMap))); } connect(m_wizard, SIGNAL(currentIdChanged(int)), this, SLOT(leavePage(int))); startScan(); } void DiscoverPage::leavePage(int id) { if (id == 2) { cleanupPage(); } } -void DiscoverPage::nameChanged(const QString& name) -{ - kDebug() << name; - Device *device = static_cast(sender()); - m_itemRelation.value(device->address())->setText(name); - if (!device->name().isEmpty()) { - m_itemRelation[device->address()]->setText(device->friendlyName()); - if (m_itemRelation[device->address()]->isSelected()) { - m_wizard->setDeviceAddress(device->address().toAscii()); - emit completeChanged(); - } - return; - } -} - void DiscoverPage::cleanupPage() { stopScan(); deviceList->clear(); m_itemRelation.clear(); } bool DiscoverPage::isComplete() const { if (m_wizard->deviceAddress().isEmpty()) { return false; } return true; } void DiscoverPage::startScan() { deviceList->clear(); stopScan(); Manager::self()->defaultAdapter()->startDiscovery(); } void DiscoverPage::stopScan() { if (Manager::self()->defaultAdapter()) { Manager::self()->defaultAdapter()->stopDiscovery(); } } -void DiscoverPage::deviceFound(Device* device) +void DiscoverPage::deviceFound(const QVariantMap &deviceInfo) { - kDebug() << m_itemRelation.keys(); - kDebug() << device->address(); - if (m_itemRelation.contains(device->address()) && !device->name().isEmpty()) { - m_itemRelation[device->address()]->setText(device->friendlyName()); - if (m_itemRelation[device->address()]->isSelected()) { - m_wizard->setDeviceAddress(device->address().toAscii()); - emit completeChanged(); - } - return; + QString address = deviceInfo["Address"].toString(); + QString name = deviceInfo["Name"].toString(); + QString icon = deviceInfo["Icon"].toString(); + QString alias = deviceInfo["Alias"].toString(); + + kDebug() << "========================"; + kDebug() << "Address: " << address; + kDebug() << "Name: " << name; + kDebug() << "Alias: " << alias; + kDebug() << "Icon: " << icon; + kDebug() << "\n"; + + bool origName = false; + if (!name.isEmpty()) { + origName = true; } - QString name = device->alias(); - if (device->alias() != device->name() && !device->name().isEmpty()) { - name.append(" ("+device->name()+")"); + if (!alias.isEmpty() && alias != name && !name.isEmpty()) { + name = QString("%1 (%2)").arg(alias).arg(name); + } + + if (name.isEmpty()) { + name = address; } - QString icon = device->icon(); if (icon.isEmpty()) { icon.append("preferences-system-bluetooth"); } - QListWidgetItem *item = new QListWidgetItem(KIcon(icon), name, deviceList); - bool a = connect(device, SIGNAL(nameChanged(QString)), this, SLOT(nameChanged(QString))); - if (!a) { - kDebug() << "CONNECT FAILED HOYGAN"; + if (m_itemRelation.contains(address)) { + m_itemRelation[address]->setText(name); + m_itemRelation[address]->setIcon(KIcon(icon)); + m_itemRelation[address]->setData(Qt::UserRole+1, origName); + + if (deviceList->currentItem() == m_itemRelation[address]) { + itemSelected(m_itemRelation[address]); + } + return; } - item->setData(Qt::UserRole, device->address()); - deviceList->addItem(item); + QListWidgetItem *item = new QListWidgetItem(KIcon(icon), name, deviceList); + + item->setData(Qt::UserRole, address); + item->setData(Qt::UserRole+1, origName); - m_itemRelation.insert(device->address(), item); + m_itemRelation.insert(address, item); } void DiscoverPage::itemSelected(QListWidgetItem* item) { - Device *device = Manager::self()->defaultAdapter()->deviceForAddress(item->data(Qt::UserRole).toString()); - if (!device->name().isEmpty()) { - m_wizard->setDeviceAddress(device->address().toAscii()); + bool origName = item->data(Qt::UserRole+1).toBool(); + if (origName) { + QString address = item->data(Qt::UserRole).toString(); + m_wizard->setDeviceAddress(address.toAscii()); } else { m_wizard->setDeviceAddress(QByteArray()); } emit completeChanged(); } int DiscoverPage::nextId() const { if (m_wizard) { if (!m_wizard->deviceAddress().isEmpty()) { Device *device = Manager::self()->defaultAdapter()->deviceForAddress(m_wizard->deviceAddress()); if (device->isPaired()) { kDebug() << "Device is paired, jumping"; return BlueWizard::Services; } } } return BlueWizard::Pin; } diff --git a/src/wizard/pages/discoverpage.h b/src/wizard/pages/discoverpage.h index 56039bd7..902f2815 100644 --- a/src/wizard/pages/discoverpage.h +++ b/src/wizard/pages/discoverpage.h @@ -1,59 +1,58 @@ /* Copyright (C) 2010 UFO Coders This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DISCOVERPAGE_H #define DISCOVERPAGE_H #include "ui_discover.h" #include class BlueWizard; namespace BlueDevil { class Device; } using namespace BlueDevil; class DiscoverPage : public QWizardPage , public Ui::Discover { Q_OBJECT public: DiscoverPage(QWidget* parent = 0); virtual ~DiscoverPage(); virtual void initializePage(); virtual void cleanupPage(); virtual bool isComplete() const; virtual int nextId() const; private Q_SLOTS: void startScan(); - void deviceFound(Device * device); + void deviceFound(const QVariantMap &deviceInfo); void itemSelected(QListWidgetItem* item); void leavePage(int id); - void nameChanged(const QString& name); private: void stopScan(); private: QMap m_itemRelation; BlueWizard *m_wizard; }; #endif // DISCOVERPAGE_H