Blob Blame History Raw
From a967936a34b2f17e002f9d69dae3e74b0ef20799 Mon Sep 17 00:00:00 2001
From: David Rosca <nowrep@gmail.com>
Date: Mon, 12 Jan 2015 14:19:42 +0100
Subject: [PATCH 17/20] filereceiver: Fix crash when sending device is null

BUG: 342581
---
 src/daemon/kded/filereceiver/receivefilejob.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/daemon/kded/filereceiver/receivefilejob.cpp b/src/daemon/kded/filereceiver/receivefilejob.cpp
index daf6c57..1de755a 100644
--- a/src/daemon/kded/filereceiver/receivefilejob.cpp
+++ b/src/daemon/kded/filereceiver/receivefilejob.cpp
@@ -85,20 +85,31 @@ void ReceiveFileJob::init()
             SLOT(transferPropertiesChanged(QString,QVariantMap,QStringList)));
 
     m_session = new org::bluez::obex::Session1("org.bluez.obex", m_transfer->session().path(), QDBusConnection::sessionBus(), this);
-    kDebug(dblue()) << m_session->destination();
 
-    Device* device = Manager::self()->usableAdapter()->deviceForAddress(m_session->destination());
-    kDebug(dblue()) << device;
+    kDebug(dblue()) << "Source:" << m_session->source();
+    kDebug(dblue()) << "Destination:" << m_session->destination();
+
+    Device *device = 0;
+    bool isDeviceTrusted = false;
+
+    Q_FOREACH (Adapter *adapter, Manager::self()->adapters()) {
+        if (adapter->address() == m_session->source()) {
+            device = adapter->deviceForAddress(m_session->destination());
+            break;
+        }
+    }
 
     m_deviceName = m_session->destination();
+
     if (device) {
         kDebug(dblue()) << device->name();
         m_deviceName = device->name();
+        isDeviceTrusted = device->isTrusted();
     }
 
     FileReceiverSettings::self()->readConfig();
     kDebug(dblue()) << "Auto Accept: " << FileReceiverSettings::self()->autoAccept();
-    if (FileReceiverSettings::self()->autoAccept() == 1 && device->isTrusted()) {
+    if (FileReceiverSettings::self()->autoAccept() == 1 && isDeviceTrusted) {
         slotAccept();
         return;
     } else if (FileReceiverSettings::self()->autoAccept() == 2) {
-- 
2.1.0