Commit 813cf4d0 authored by Nicolas Jager's avatar Nicolas Jager

smartpanel : add devices menu

Change-Id: I709b54c285ca67299e7bfa15651bca9a45707978
Tuleap: #1213
parent 7611b9d7
......@@ -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
......
......@@ -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_;
};
}
......@@ -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();
}
......
......@@ -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 */
......
......@@ -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;
}
......@@ -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_;
......
......@@ -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"
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment