Signed-off-by: Kevron Rees <[email protected]>
---
 src/dialerkeypad.cpp |   76 ++++++++++++++++++++++++++++++++++++++++++++------
 src/dialerkeypad.h   |    7 ++++
 2 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/src/dialerkeypad.cpp b/src/dialerkeypad.cpp
index 1e37c1c..2f71b33 100644
--- a/src/dialerkeypad.cpp
+++ b/src/dialerkeypad.cpp
@@ -19,6 +19,9 @@
 #include <MWidgetView>
 #include <MSceneManager>
 #include <MAction>
+#include <bluedevice.h>
+#include <btprofiles.h>
+#include <headset.h>
 
 #include <MWidgetCreator>
 M_REGISTER_WIDGET(DialerKeyPad)
@@ -112,7 +115,7 @@ DialerKeyPad::DialerKeyPad(DialerKeypadType keypadType,
                            MWidget *parent)
     : MOverlay(parent),
       m_type(keypadType),
-      m_box(new MStylableWidget()),
+      m_box(new MStylableWidget(this)),
       m_layout(new MLayout(m_box)),
       m_policyDefault(new MLinearLayoutPolicy(m_layout, Qt::Vertical)),
       m_policyShowKeypad(new MLinearLayoutPolicy(m_layout, Qt::Vertical)),
@@ -121,16 +124,18 @@ DialerKeyPad::DialerKeyPad(DialerKeypadType keypadType,
       m_keypadVisible(true),
       m_optionsVisible(true),
       m_incall(false),
+      m_headsetConnected(false),
       m_optionBox(new MStylableWidget()),
-      m_mute(new MButton("Mute")),
-      m_hold(new MButton("Hold")),
-      m_audiosink(new MButton("Speaker")),
-      m_nway(new MButton("Merge Calls")),
+      m_mute(new MButton("Mute",this)),
+      m_hold(new MButton("Hold",this)),
+      m_audiosink(new MButton("Speaker",this)),
+      m_nway(new MButton("Merge Calls",this)),
       m_buttonBox(new MStylableWidget()),
       m_controlBox(new MStylableWidget()),
-      m_add(new MButton()),
-      m_call(new MButton()),
-      m_hide(new MButton())
+      m_add(new MButton(this)),
+      m_call(new MButton(this)),
+      m_hide(new MButton(this)),
+      bluetoothDevices(new DeviceModel(this))
 {
     TRACE
     m_box->setParent(this);
@@ -190,12 +195,18 @@ DialerKeyPad::DialerKeyPad(DialerKeypadType keypadType,
     }
 
     connect(this, SIGNAL(appeared()), SLOT(updateLayoutPolicy()));
+
+    foreach(QDBusObjectPath path, bluetoothDevices->devices()) {
+        bluetoothDeviceCreated(path);
+    }
+
+    connect(bluetoothDevices, SIGNAL(deviceCreated(QDBusObjectPath)), this, 
SLOT(bluetoothDeviceCreated(QDBusObjectPath)));
+    connect(bluetoothDevices, SIGNAL(deviceRemoved(QDBusObjectPath)), this, 
SLOT(bluetoothDeviceRemoved(QDBusObjectPath)));
 }
 
 DialerKeyPad::~DialerKeyPad()
 {
     TRACE
-    delete m_layout;
 }
 
 void DialerKeyPad::updateButtonStates()
@@ -245,6 +256,13 @@ void DialerKeyPad::updateButtonStates()
         else
             m_nway->setText("Merge Calls");
     }
+
+    if (m_headsetConnected) {
+        m_audiosink->setText("Headset");
+    }
+    else {
+        m_audiosink->setText("Speaker");
+    }
 }
 
 void DialerKeyPad::updateLayoutPolicy()
@@ -496,6 +514,46 @@ void DialerKeyPad::setSpeedDial()
     SHOW_TBD
 }
 
+void DialerKeyPad::bluetoothDeviceCreated(QDBusObjectPath path)
+{
+    OrgBluezDeviceInterface 
device("org.bluez",path.path(),QDBusConnection::systemBus());
+    QVariantMap properties = device.GetProperties();
+
+    QStringList uuidlist = properties["UUIDs"].toStringList();
+
+    foreach(QString uuid, uuidlist) {
+        if(uuid.toLower() == BluetoothProfiles::hs || uuid.toLower() == 
BluetoothProfiles::hf) {
+            OrgBluezHeadsetInterface *headset = new 
OrgBluezHeadsetInterface("org.bluez",
+                                                                             
path.path(),
+                                                                             
QDBusConnection::systemBus(),
+                                                                             
this);
+            if(headset->IsConnected()) {
+                headsetConnected();
+            }
+            connect(headset,SIGNAL(Connected()),this,SLOT(headsetConnected()));
+            
connect(headset,SIGNAL(Disconnected()),this,SLOT(headsetDisconnected()));
+            break;
+        }
+    }
+}
+
+void DialerKeyPad::bluetoothDeviceRemoved(QDBusObjectPath)
+{
+
+}
+
+void DialerKeyPad::headsetConnected()
+{
+    m_headsetConnected=true;
+    updateButtonStates();
+}
+
+void DialerKeyPad::headsetDisconnected()
+{
+    m_headsetConnected=false;
+    updateButtonStates();
+}
+
 void DialerKeyPad::constructNumericKeypad(MGridLayoutPolicy *policy)
 {
     TRACE
diff --git a/src/dialerkeypad.h b/src/dialerkeypad.h
index 0271e4c..5887676 100644
--- a/src/dialerkeypad.h
+++ b/src/dialerkeypad.h
@@ -20,6 +20,7 @@
 #include <MButton>
 #include <MContainer>
 #include <MStylableWidget>
+#include <devicelistwidget.h>
 
 typedef enum _DialerKeypadType {
     DialerKeypadNumeric,
@@ -60,6 +61,7 @@ private:
     bool                   m_keypadVisible;
     bool                   m_optionsVisible;
     bool                   m_incall;
+    bool                   m_headsetConnected;
 
     MStylableWidget     *m_optionBox;
     MButton             *m_mute, *m_hold, *m_audiosink, *m_nway;
@@ -67,6 +69,7 @@ private:
     QList<MButton*>      m_buttons;
     MStylableWidget     *m_controlBox;
     MButton             *m_add, *m_call, *m_hide;
+    DeviceModel* bluetoothDevices;
 
     void constructNumericKeypad(MGridLayoutPolicy*);
     void constructQwertyKeypad();
@@ -90,6 +93,10 @@ private Q_SLOTS:
     void callsChanged();
     void callSpeedDial();
     void setSpeedDial();
+    void bluetoothDeviceCreated(QDBusObjectPath);
+    void bluetoothDeviceRemoved(QDBusObjectPath);
+    void headsetConnected();
+    void headsetDisconnected();
 };
 
 #endif // DIALERKEYPAD_H
-- 
1.7.1

_______________________________________________
MeeGo-dev mailing list
[email protected]
http://lists.meego.com/listinfo/meego-dev

Reply via email to