diff --git a/Account.cpp b/Account.cpp index adbecb6e0af6e073fb7e28da31ad002efa4c6c17..43cd68fa5c7f56beb928fc9e45ec2ec35dcf9f45 100644 --- a/Account.cpp +++ b/Account.cpp @@ -30,12 +30,14 @@ using namespace RingClientUWP; 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 f9ee44843a55f4822221b872620e85c228673397..ac6b70ba62422a224c0baede3a34e114e2c8fed3 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 @@ public: 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 57f890578dc4b9a7afa75297c243196fc98d8f02..d07f543c01f1477aa70bad1b328b770c47f2a973 100644 --- a/AccountsViewModel.cpp +++ b/AccountsViewModel.cpp @@ -29,13 +29,14 @@ AccountsViewModel::AccountsViewModel() } 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 9f766c0ade2e810b0ffed5dbe9840e13ac7296b7..b4a3e9219716cd7375f8f2ebbedcb90147a6b754 100644 --- a/AccountsViewModel.h +++ b/AccountsViewModel.h @@ -43,7 +43,7 @@ internal: } /* 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 cf6c52955c856e7eb416a6d1de67c8e52e0594ba..73e96c714f5245ed9af2370d6e7123ffea46b5a8 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -45,19 +45,26 @@ void 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 @@ void RingClientUWP::RingD::hangUpCall2(String ^ callId) 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 @@ RingClientUWP::RingD::startDaemon() 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 @@ RingClientUWP::RingD::startDaemon() 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 @@ RingD::dequeueTasks() 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 @@ RingD::dequeueTasks() } } -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 @@ RingClientUWP::CallStatus RingClientUWP::RingD::getCallStatus(String^ state) 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 d2e62cdbb0f694f1921692d6ed2e921a4e6d6191..ec32c9156b92a7ea21d743582567e59d3da549db 100644 --- a/RingD.h +++ b/RingD.h @@ -32,6 +32,7 @@ delegate void StateChange(String^ callId, CallStatus state, int code); 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 @@ internal: 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 @@ private: AcceptIncommingCall, CancelOutGoingCall, HangUpCall, - RegisterDevice + RegisterDevice, + GetKnownDevices }; @@ -135,12 +139,13 @@ private: 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 f62e36d2ce65331c3d8b5b7486f1ec93362a01fb..d4dd0c96b63f688696ef78d762cb01a64efe3082 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -536,14 +536,22 @@ </Grid.RowDefinitions> <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 f596aa25c1d40ac14c0470deaab12122d13d15d8..1e34ae6a08cf57cb667b9d2a6359e8876237a746 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -48,6 +48,10 @@ SmartPanel::SmartPanel() /* 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 @@ RingClientUWP::Views::SmartPanel::updatePageContent() 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)