smartpanel : add devices menu

Change-Id: I709b54c285ca67299e7bfa15651bca9a45707978
Tuleap: #1213
diff --git a/Account.cpp b/Account.cpp
index adbecb6..43cd68f 100644
--- a/Account.cpp
+++ b/Account.cpp
@@ -30,12 +30,14 @@
 Account::Account(String^ name,

                  String^ ringID,

                  String^ accountType,

-                 String^ accountID)

+                 String^ accountID,

+                 String^ deviceId)

 {

     name_ = name;

     ringID_ = ringID;

     accountType_ = accountType;

     accountID_ = accountID;

+    _deviceId = deviceId;

 }

 

 void

diff --git a/Account.h b/Account.h
index f9ee448..ac6b70b 100644
--- a/Account.h
+++ b/Account.h
@@ -21,13 +21,14 @@
 

 using namespace Platform;

 using namespace Windows::UI::Xaml::Data;

+using namespace Platform::Collections;

 

 namespace RingClientUWP

 {

 public ref class Account sealed : public INotifyPropertyChanged

 {

 public:

-    Account(String^ name, String^ ringID, String^ accountType, String^ accountID);

+    Account(String^ name, String^ ringID, String^ accountType, String^ accountID, String^ deviceId);

 

     virtual event PropertyChangedEventHandler^ PropertyChanged;

 

@@ -35,10 +36,22 @@
     property String^ ringID_;

     property String^ accountType_;

     property String^ accountID_;

+    property String^ _deviceId;

+    property Windows::Foundation::Collections::IVector<String^>^ _devicesIdList {

+        Windows::Foundation::Collections::IVector<String^>^ get() {

+            return devicesIdList_;

+        }

+        void set(Windows::Foundation::Collections::IVector<String^>^ value) {

+            devicesIdList_ = value;

+        }

+    }

 

 protected:

     void NotifyPropertyChanged(String^ propertyName);

 

+private:

+    Windows::Foundation::Collections::IVector<String^>^ devicesIdList_;

+

 };

 }

 

diff --git a/AccountsViewModel.cpp b/AccountsViewModel.cpp
index 57f8905..d07f543 100644
--- a/AccountsViewModel.cpp
+++ b/AccountsViewModel.cpp
@@ -29,13 +29,14 @@
 }

 

 void

-AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID)

+AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId)

 {

     accountsList_->Append(ref new Account(

                               Utils::toPlatformString(name),

                               Utils::toPlatformString(ringID),

                               Utils::toPlatformString(accountType),

-                              Utils::toPlatformString(accountID)

+                              Utils::toPlatformString(accountID),

+                              Utils::toPlatformString(deviceId)

                           ));

     updateScrollView();

 }

diff --git a/AccountsViewModel.h b/AccountsViewModel.h
index 9f766c0..b4a3e92 100644
--- a/AccountsViewModel.h
+++ b/AccountsViewModel.h
@@ -43,7 +43,7 @@
     }

 

     /* functions */

-    void add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID);

+    void add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId);

     void clearAccountList();

 

     /* properties */

diff --git a/RingD.cpp b/RingD.cpp
index cf6c529..73e96c7 100644
--- a/RingD.cpp
+++ b/RingD.cpp
@@ -45,19 +45,26 @@
 RingClientUWP::RingD::reloadAccountList()

 {

     RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList();

+

     std::vector<std::string> accountList = DRing::getAccountList();

     std::vector<std::string>::reverse_iterator rit = accountList.rbegin();

+

     for (; rit != accountList.rend(); ++rit) {

+

         std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(*rit);

         std::string ringID(accountDetails.find(DRing::Account::ConfProperties::USERNAME)->second);

+

         if(!ringID.empty())

             ringID = ringID.substr(5);

+

         RingClientUWP::ViewModel::AccountsViewModel::instance->add(

-            accountDetails.find(DRing::Account::ConfProperties::ALIAS)->second,      //name

-            ringID,                                                             //ringid

-            accountDetails.find(DRing::Account::ConfProperties::TYPE)->second,       //type

-            *rit);

+            accountDetails.find(DRing::Account::ConfProperties::ALIAS)->second,             // alias

+            ringID,                                                                         // ringid

+            accountDetails.find(DRing::Account::ConfProperties::TYPE)->second,              // account type

+            *rit,                                                                           // account id

+            accountDetails.find(DRing::Account::ConfProperties::RING_DEVICE_ID)->second);   // device id

     }

+

     // load user preferences

     Configuration::UserPreferences::instance->load();

 }

@@ -197,6 +204,14 @@
     tasksList_.push(ref new RingD::Task(Request::HangUpCall, callId));

 }

 

+void RingClientUWP::RingD::askToRefreshKnownDevices(String^ accountId)

+{

+    auto task = ref new RingD::Task(Request::GetKnownDevices);

+    task->_accountId = accountId;

+

+    tasksList_.push(task);

+}

+

 void

 RingClientUWP::RingD::startDaemon()

 {

@@ -250,7 +265,7 @@
                 auto callId2 = toPlatformString(callId);

                 auto state2 = toPlatformString(state);

 

-                auto state3 = getCallStatus(state2);

+                auto state3 = translateCallStatus(state2);

 

                 if (state3 == CallStatus::ENDED)

                     DRing::hangUp(callId); // solve a bug in the daemon API.

@@ -347,7 +362,18 @@
                 ref new DispatchedHandler([=]() {

                     RingDebug::instance->print(toto);

                 }));

+            }),

+

+

+            DRing::exportable_callback<DRing::ConfigurationSignal::KnownDevicesChanged>([&](const std::string& accountId, const std::map<std::string, std::string>& devices)

+            {

+                dispatcher->RunAsync(CoreDispatcherPriority::High,

+                ref new DispatchedHandler([=]() {

+                    RingDebug::instance->print("toto");

+                }));

             })

+

+

         };

         registerCallHandlers(callHandlers);

 

@@ -552,6 +578,15 @@
             deviceDetails.insert(std::make_pair(DRing::Account::ConfProperties::ARCHIVE_PASSWORD, password));

             DRing::addAccount(deviceDetails);

         }

+        case Request::GetKnownDevices:

+        {

+            auto accountId = task->_accountId;

+            auto accountId2 = Utils::toString(accountId);

+

+            auto devicesList = DRing::getKnownRingDevices(accountId2);

+            auto devicesList2 = translateKnownRingDevices(devicesList);

+

+        }

         default:

             break;

         }

@@ -559,7 +594,7 @@
     }

 }

 

-RingClientUWP::CallStatus RingClientUWP::RingD::getCallStatus(String^ state)

+RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ state)

 {

     if (state == "INCOMING")

         return CallStatus::INCOMING_RINGING;

@@ -578,3 +613,16 @@
 

     return CallStatus::NONE;

 }

+

+Vector<String^>^ RingClientUWP::RingD::translateKnownRingDevices(const std::map<std::string, std::string> devices)

+{

+    auto devicesList = ref new Vector<String^>();

+

+    for (auto i : devices) {

+        MSG_("devices.first = " + i.first);

+        MSG_("devices.second = " + i.second);

+    }

+

+

+    return devicesList;

+}

diff --git a/RingD.h b/RingD.h
index d2e62cd..ec32c91 100644
--- a/RingD.h
+++ b/RingD.h
@@ -32,6 +32,7 @@
 delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);

 delegate void CallPlaced(String^ callId);

 delegate void IncomingMessage(String^ callId, String^ payload);

+//delegate void DevicesListRefreshed()

 

 

 public ref class RingD sealed

@@ -84,9 +85,11 @@
     void acceptIncommingCall(String^ call);

     void placeCall(Contact^ contact);

     /*void cancelOutGoingCall2(String^ callId);*/ // marche pas

-    CallStatus getCallStatus(String^ state);

+    CallStatus translateCallStatus(String^ state);

+    Vector<String^>^ translateKnownRingDevices(const std::map<std::string, std::string> devices);

 

     void hangUpCall2(String^ callId);

+    void askToRefreshKnownDevices(String^ accountId);

 

     /* TODO : move members */

     ///bool hasConfig; // replaced by startingStatus

@@ -109,7 +112,8 @@
         AcceptIncommingCall,

         CancelOutGoingCall,

         HangUpCall,

-        RegisterDevice

+        RegisterDevice,

+        GetKnownDevices

     };

 

 

@@ -135,12 +139,13 @@
         property String^ _callId;

         property String^ _pin;

         property String^ _password;

+        property String^ _accountId;

     };

 

     /* functions */

     RingD(); // singleton

     void dequeueTasks();

-//    CallStatus getCallStatus(String^ state);

+//    CallStatus translateCallStatus(String^ state);

 

     /* members */

     std::string localFolder_;

diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index f62e36d..d4dd0c9 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -537,13 +537,21 @@
                 <Grid Background="#FFE4F1F9">

                     <Grid.RowDefinitions>

                         <RowDefinition Height="auto"/>

+                        <RowDefinition Height="auto"/>

                         <RowDefinition Height="*"/>

                         <RowDefinition Height="auto"/>

                         <RowDefinition Height="auto"/>

                     </Grid.RowDefinitions>

-                    <TextBlock Text="devices:"

+                    <TextBlock Text="Device ID:"

                                Grid.Row="0"

                                HorizontalAlignment="Center"/>

+                    <TextBlock x:Name="_deviceId_"

+                               Text="[TEXT_MISSING]"

+                               Grid.Row="1"

+                               IsTextSelectionEnabled="True"

+                               HorizontalAlignment="Center"/>

+                    <ListBox x:Name="_devicesIdList_"

+                         Grid.Row="2"/>

                 </Grid>

                 <Button x:Name="_addDevice_"

                         Grid.Row="1"

diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index f596aa2..1e34ae6 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -48,6 +48,10 @@
     /* populate the smartlist */

     _smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;

 

+

+    /* populate the device list*/

+///	_devicesIdList_ // not used so far

+

     /* connect delegates */

     Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {

         _accountsList_->SelectedIndex = index;

@@ -127,9 +131,17 @@
     if (!account)

         return;

 

+    auto accountId = account->accountID_;

+

     Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;

     Configuration::UserPreferences::instance->save();

-    _selectedAccountName_->Text = account->name_;

+

+    _selectedAccountName_->Text = accountId;

+    _devicesIdList_->ItemsSource = account->_devicesIdList;

+    _deviceId_->Text = account->_deviceId; /* this is the current device ...

+    ... in the way to get all associated devices, we have to querry the daemon : */

+    RingD::instance->askToRefreshKnownDevices(accountId);

+

 }

 

 void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)