[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bbluedevil=5D_src/actionplugins/sendfile/helper=3A_P?=
From:       Alex Fiestas <afiestas () kde ! org>
Date:       2011-04-02 15:44:16
Message-ID: 20110402154416.9ABF8A60AE () git ! kde ! org
[Download RAW message or body]

Git commit f28d9aff7c22f4fa062a2b70894059c9ac5770bc by Alex Fiestas.
Committed on 21/03/2011 at 18:20.
Pushed by afiestas into branch 'master'.

Port the device selection to Adapter::deviceFound(QVariantMap)

Just as we did with bluedevil-wizard, port the send file wizard
so we don't get devices with empty names.

M  +41   -17   src/actionplugins/sendfile/helper/discoverwidget.cpp     
M  +1    -1    src/actionplugins/sendfile/helper/discoverwidget.h     

http://commits.kde.org/bluedevil/f28d9aff7c22f4fa062a2b70894059c9ac5770bc

diff --git a/src/actionplugins/sendfile/helper/discoverwidget.cpp \
b/src/actionplugins/sendfile/helper/discoverwidget.cpp index 9494997..37f0128 100644
--- a/src/actionplugins/sendfile/helper/discoverwidget.cpp
+++ b/src/actionplugins/sendfile/helper/discoverwidget.cpp
@@ -40,8 +40,8 @@ DiscoverWidget::DiscoverWidget(QWidget* parent)
 
     connect(deviceList, SIGNAL(itemActivated(QListWidgetItem*)), this,
             SLOT(itemSelected(QListWidgetItem*)));
-    connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(Device*)), this,
-            SLOT(deviceFound(Device*)));
+    connect(Manager::self()->defaultAdapter(), SIGNAL(deviceFound(QVariantMap)), \
this, +            SLOT(deviceFound(QVariantMap)));
 
     startScan();
 }
@@ -71,34 +71,58 @@ void DiscoverWidget::stopScan()
     }
 }
 
-void DiscoverWidget::deviceFound(Device* device)
+void DiscoverWidget::deviceFound(const QVariantMap& deviceInfo)
 {
-    if (m_itemRelation.contains(device->address()) && !device->name().isEmpty()) {
-        m_itemRelation[device->address()]->setText(device->friendlyName());
-        if (m_itemRelation[device->address()]->isSelected()) {
-            emit deviceSelected(device);
-        }
-        return;
+    QString address = deviceInfo["Address"].toString();
+    QString name = deviceInfo["Name"].toString();
+    QString icon = deviceInfo["Icon"].toString();
+    QString alias = deviceInfo["Alias"].toString();
+
+    qDebug() << "========================";
+    qDebug() << "Address: " << address;
+    qDebug() << "Name: " << name;
+    qDebug() << "Alias: " << alias;
+    qDebug() << "Icon: " << icon;
+    qDebug() << "\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");
     }
 
+    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]) {
+            emit deviceSelected(Manager::self()->defaultAdapter()->deviceForAddress(address));
 +        }
+        return;
+    }
+
     QListWidgetItem *item = new QListWidgetItem(KIcon(icon), name, deviceList);
 
-    item->setData(Qt::UserRole, qVariantFromValue<QObject*>(device));
-    m_itemRelation.insert(device->address(), item);
+    item->setData(Qt::UserRole, address);
+    item->setData(Qt::UserRole+1, origName);
+
+    m_itemRelation.insert(address, item);
 }
 
 void DiscoverWidget::itemSelected(QListWidgetItem* item)
 {
-    Device *device = \
                qobject_cast<Device*>(item->data(Qt::UserRole).value<QObject*>());
-    emit deviceSelected(device);
+    emit deviceSelected(Manager::self()->defaultAdapter()->deviceForAddress(item->data(Qt::UserRole).toString()));
  }
\ No newline at end of file
diff --git a/src/actionplugins/sendfile/helper/discoverwidget.h \
b/src/actionplugins/sendfile/helper/discoverwidget.h index be0934d..cd37fdb 100644
--- a/src/actionplugins/sendfile/helper/discoverwidget.h
+++ b/src/actionplugins/sendfile/helper/discoverwidget.h
@@ -50,7 +50,7 @@ public Q_SLOTS:
     void startScan();
 
 private Q_SLOTS:
-    void deviceFound(Device *device);
+    void deviceFound(const QVariantMap &deviceInfo);
     void itemSelected(QListWidgetItem* item);
 
 private:


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic