Commit d0830772 authored by Nicolas Jager's avatar Nicolas Jager

smartpanel : add pin number generator

Change-Id: I3e4d4e37c6481abb9ed98f4a19ea0d6b09fe4f08
Tuleap: #1215
parent 813cf4d0
......@@ -34,7 +34,7 @@ public:
property String^ name_;
property String^ ringID_;
property String^ accountType_;
property String^ accountType_; // refacto : create a enum accountType
property String^ accountID_;
property String^ _deviceId;
property Windows::Foundation::Collections::IVector<String^>^ _devicesIdList {
......
......@@ -31,6 +31,7 @@ AccountsViewModel::AccountsViewModel()
void
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),
......
......@@ -57,12 +57,12 @@ RingClientUWP::RingD::reloadAccountList()
if(!ringID.empty())
ringID = ringID.substr(5);
RingClientUWP::ViewModel::AccountsViewModel::instance->add(
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
auto alias = accountDetails.find(DRing::Account::ConfProperties::ALIAS)->second;
auto type = accountDetails.find(DRing::Account::ConfProperties::TYPE)->second;
auto deviceId = (type == "SIP")? std::string() : accountDetails.find(DRing::Account::ConfProperties::RING_DEVICE_ID)->second;
RingClientUWP::ViewModel::AccountsViewModel::instance->add(alias, ringID, type, *rit /*account id*/, deviceId);
}
// load user preferences
......@@ -212,6 +212,15 @@ void RingClientUWP::RingD::askToRefreshKnownDevices(String^ accountId)
tasksList_.push(task);
}
void RingClientUWP::RingD::askToExportOnRing(String ^ accountId, String ^ password)
{
auto task = ref new RingD::Task(Request::ExportOnRing);
task->_accountId = accountId;
task->_password = password;
tasksList_.push(task);
}
void
RingClientUWP::RingD::startDaemon()
{
......@@ -369,7 +378,16 @@ RingClientUWP::RingD::startDaemon()
{
dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
RingDebug::instance->print("toto");
RingDebug::instance->print("KnownDevicesChanged ---> C PAS FINI");
}));
}),
DRing::exportable_callback<DRing::ConfigurationSignal::ExportOnRingEnded>([&](const std::string& accountId, int status, const std::string& pin)
{
auto accountId2 = Utils::toPlatformString(accountId);
auto pin2 = (pin.empty()) ? "Error Bad Password" : "Your generated pin :" + Utils::toPlatformString(pin);
dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
exportOnRingEnded(accountId2, pin2);
}));
})
......@@ -584,8 +602,25 @@ RingD::dequeueTasks()
auto accountId2 = Utils::toString(accountId);
auto devicesList = DRing::getKnownRingDevices(accountId2);
if (devicesList.empty())
break;
auto devicesList2 = translateKnownRingDevices(devicesList);
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
ref new DispatchedHandler([=]() {
devicesListRefreshed(devicesList2);
}));
}
case Request::ExportOnRing:
{
auto accountId = task->_accountId;
auto password = task->_password;
auto accountId2 = Utils::toString(accountId);
auto password2 = Utils::toString(password);
DRing::exportOnRing(accountId2, password2);
}
default:
break;
......@@ -621,8 +656,11 @@ Vector<String^>^ RingClientUWP::RingD::translateKnownRingDevices(const std::map<
for (auto i : devices) {
MSG_("devices.first = " + i.first);
MSG_("devices.second = " + i.second);
auto deviceName = Utils::toPlatformString(i.second);
devicesList->Append(deviceName);
}
return devicesList;
}
......@@ -32,7 +32,8 @@ 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()
delegate void DevicesListRefreshed(Vector<String^>^ devicesList);
delegate void ExportOnRingEnded(String^ accountId, String^ pin);
public ref class RingD sealed
......@@ -90,6 +91,7 @@ internal:
void hangUpCall2(String^ callId);
void askToRefreshKnownDevices(String^ accountId);
void askToExportOnRing(String^ accountId, String^ password);
/* TODO : move members */
///bool hasConfig; // replaced by startingStatus
......@@ -101,6 +103,8 @@ internal:
event IncomingAccountMessage^ incomingAccountMessage;
event IncomingMessage^ incomingMessage;
event CallPlaced^ callPlaced;
event DevicesListRefreshed^ devicesListRefreshed;
event ExportOnRingEnded^ exportOnRingEnded;
private:
/* sub classes */
......@@ -113,7 +117,8 @@ private:
CancelOutGoingCall,
HangUpCall,
RegisterDevice,
GetKnownDevices
GetKnownDevices,
ExportOnRing
};
......
......@@ -383,17 +383,20 @@
Checked="_accountsMenuButton__Checked"
Unchecked="_accountsMenuButton__Unchecked"
Style="{StaticResource ToggleButtonStyle1}"/>
<!-- _shareMenuButton_ collapsed on purpose -->
<ToggleButton x:Name="_shareMenuButton_"
VerticalAlignment="Bottom"
Visibility="Collapsed"
Content="&#xE72D;"
Checked="_shareMenuButton__Checked"
Unchecked="_shareMenuButton__Unchecked"
Style="{StaticResource ToggleButtonStyle1}"/>
<ToggleButton x:Name="_devicesMenuButton_"
VerticalAlignment="Bottom"
Content="devices;"
Content="&#xE836;"
Checked="_devicesMenuButton__Checked"
Unchecked="_devicesMenuButton__Unchecked"/>
Unchecked="_devicesMenuButton__Unchecked"
Style="{StaticResource ToggleButtonStyle1}"/>
</StackPanel>
</StackPanel>
<ToggleButton x:Name="_settingsTBtn_"
......@@ -561,6 +564,75 @@
Click="_addDevice__Click"
Style="{StaticResource ButtonStyle6}"/>
</Grid>
<!-- add device (pin generator) menu. -->
<Grid x:Name="_addingDeviceGrid_"
Grid.Row="2"
Visibility="Collapsed"
Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid Background="#FFE4F1F9">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center"
Text="PIN generator"
HorizontalAlignment="Center"
Grid.Row="0"
Margin="10,10,0,10"/>
<PasswordBox x:Name="_passwordForPinGenerator_"
Margin="10"
Grid.Row="1"
PlaceholderText="Enter your password"/>
</Grid>
<!-- buttons yes/no to generate a PIN. -->
<Grid Grid.Row="1">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Button x:Name="_pinGeneratorYes_"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="&#xE081;"
Click="_pinGeneratorYes__Click"
Style="{StaticResource ButtonStyle5}"/>
<Button x:Name="_pinGeneratorNo_"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="&#xE106;"
Click="_pinGeneratorNo__Click"
Style="{StaticResource ButtonStyle5}"/>
</StackPanel>
</Grid>
</Grid>
<!-- waiting for a PIN. -->
<Grid x:Name="_waitingForPin_"
Grid.Row="2"
Visibility="Collapsed"
Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid Background="#FFE4F1F9">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="_waitingAndResult_"
VerticalAlignment="Center"
Text="Exporting account on the Ring..."
HorizontalAlignment="Center"
Grid.Row="0"
Margin="10,10,0,10"/>
</Grid>
</Grid>
</Grid>
<!-- smartList and settings. -->
<Grid Grid.Row="1">
......
......@@ -112,6 +112,7 @@ SmartPanel::SmartPanel()
}
});
RingD::instance->devicesListRefreshed += ref new RingClientUWP::DevicesListRefreshed(this, &RingClientUWP::Views::SmartPanel::OndevicesListRefreshed);
ContactsViewModel::instance->contactAdded += ref new ContactAdded([this](Contact^ contact) {
......@@ -120,6 +121,8 @@ SmartPanel::SmartPanel()
SmartPanelItemsViewModel::instance->itemsList->Append(smartPanelItem);
});
RingD::instance->exportOnRingEnded += ref new RingClientUWP::ExportOnRingEnded(this, &RingClientUWP::Views::SmartPanel::OnexportOnRingEnded);
}
......@@ -137,9 +140,14 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
Configuration::UserPreferences::instance->save();
_selectedAccountName_->Text = accountId;
_devicesIdList_->ItemsSource = account->_devicesIdList;
/// _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 : */
_devicesMenuButton_->Visibility = (account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
RingD::instance->askToRefreshKnownDevices(accountId);
}
......@@ -147,8 +155,11 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
_shareMenuButton_->IsChecked = false;
_devicesMenuButton_->IsChecked = false;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e)
......@@ -193,12 +204,19 @@ void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel:
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuButton_->IsChecked = false;
_devicesMenuButton_->IsChecked = false;
}
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
......@@ -479,16 +497,57 @@ RingClientUWP::Views::NewMessageBubleNotification::NewMessageBubleNotification()
void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuButton_->IsChecked = false;
_shareMenuButton_->IsChecked = false;
}
void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
AccountsViewModel::instance->selectedAccount->_devicesIdList = devicesList;
_devicesIdList_->ItemsSource = devicesList;
}
void RingClientUWP::Views::SmartPanel::_pinGeneratorYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_waitingForPin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto password = _passwordForPinGenerator_->Password;
RingD::instance->askToExportOnRing(accountId, password);
}
void RingClientUWP::Views::SmartPanel::_pinGeneratorNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_devicesMenuButton_->IsChecked = false;
}
void RingClientUWP::Views::SmartPanel::OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin)
{
MSG_("XXXX");
_waitingAndResult_->Text = pin;
}
......@@ -98,6 +98,10 @@ private:
void _devicesMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList);
void _pinGeneratorYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _pinGeneratorNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin);
};
}
}
\ No newline at end of file
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