account: add RING/SIP accounts

- adds the ability to add accounts from within the accounts menu

Change-Id: Ic2bd21f8c08e0e159c1006409eaaf815b7748bc8
Tuleap: #996
diff --git a/AccountsViewModel.cpp b/AccountsViewModel.cpp
index 36e891f..57f8905 100644
--- a/AccountsViewModel.cpp
+++ b/AccountsViewModel.cpp
@@ -37,6 +37,7 @@
                               Utils::toPlatformString(accountType),

                               Utils::toPlatformString(accountID)

                           ));

+    updateScrollView();

 }

 

 void

diff --git a/AccountsViewModel.h b/AccountsViewModel.h
index fcbd4b7..9f766c0 100644
--- a/AccountsViewModel.h
+++ b/AccountsViewModel.h
@@ -26,6 +26,7 @@
 

 delegate void NewAccountSelected();

 delegate void NoAccountSelected();

+delegate void UpdateScrollView();

 

 namespace ViewModel {

 public ref class AccountsViewModel sealed

@@ -74,6 +75,7 @@
     /* events */

     event NewAccountSelected^ newAccountSelected;

     event NoAccountSelected^ noAccountSelected;

+    event UpdateScrollView^ updateScrollView;

 

 private:

     AccountsViewModel(); // singleton

diff --git a/RingD.cpp b/RingD.cpp
index 365274b..ea6db14 100644
--- a/RingD.cpp
+++ b/RingD.cpp
@@ -24,8 +24,8 @@
 #include "configurationmanager_interface.h"

 #include "presencemanager_interface.h"

 #include "fileutils.h"

-

 #include "account_schema.h"

+#include "account_const.h"

 

 #include "SmartPanel.xaml.h"

 

@@ -100,6 +100,20 @@
 }

 

 void

+RingD::createRINGAccount(String^ alias)

+{

+    accountName = Utils::toString(alias);

+    tasksList_.push(ref new RingD::Task(Request::AddRingAccount));

+}

+

+void

+RingD::createSIPAccount(String^ alias)

+{

+    accountName = Utils::toString(alias);

+    tasksList_.push(ref new RingD::Task(Request::AddSIPAccount));

+}

+

+void

 RingClientUWP::RingD::startDaemon()

 {

     // TODO (during refactoring) : use namespace

@@ -176,6 +190,18 @@
                     }));

                 }

             }),

+            DRing::exportable_callback<DRing::ConfigurationSignal::RegistrationStateChanged>([this](

+            const std::string& account_id, const std::string& state,

+            int detailsCode, const std::string& detailsStr)

+            {

+                MSG_("<RegistrationStateChanged>: ID = " + account_id + "state = " + state);

+                if (state == DRing::Account::States::UNREGISTERED) {

+                    CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,

+                        ref new DispatchedHandler([=]() {

+                        reloadAccountList();

+                    }));

+                }

+            }),

             DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]()

             {

                 CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,

diff --git a/RingD.h b/RingD.h
index 5aaaa30..4026c54 100644
--- a/RingD.h
+++ b/RingD.h
@@ -56,6 +56,8 @@
     void startDaemon();

     void reloadAccountList();

     void sendAccountTextMessage(String^ message);

+    void createRINGAccount(String^ alias);

+    void createSIPAccount(String^ alias);

 

     /* TODO : move members */

     bool hasConfig;

diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index 9736001..d113973 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -132,7 +132,7 @@
                            Grid.Column="1"

                            Grid.Row="0"

                            TextAlignment="Right"

-                           Margin="0,5,10,0"

+                           Margin="0,5,18,0"

                            Foreground="ForestGreen"

                            Text="{x:Bind accountType_}"/>

                 <TextBlock x:Name="_ringID_"

@@ -228,15 +228,17 @@
                     <RowDefinition Height="*"/>

                     <RowDefinition Height="30"/>

                 </Grid.RowDefinitions>

-                <ListBox x:Name="_accountsList_"

+                <ScrollViewer x:Name="_accountsListScrollView_"

+                              ScrollViewer.VerticalScrollBarVisibility="Auto"

+                              ScrollViewer.VerticalScrollMode="Enabled">

+                    <ListBox x:Name="_accountsList_"

                          Grid.Row="0"

                          SelectionChanged="_accountList__SelectionChanged"

-                         ScrollViewer.HorizontalScrollBarVisibility="Auto"

-                         ScrollViewer.HorizontalScrollMode="Enabled"

                          Width="320"

                          ItemContainerStyle="{StaticResource contactsListBoxStyle}"

                          Background="#FFE4F1F9"

                          ItemTemplate="{StaticResource AccountTemplate}"/>

+                </ScrollViewer>

                 <Button x:Name="_addAccountBtn_"

                         Grid.Row="1"

                         VerticalAlignment="Center"

@@ -261,7 +263,8 @@
                         <TextBlock VerticalAlignment="Center"

                                    Text="Account type : "

                                    Margin="10,10,0,10"/>

-                        <ComboBox SelectedIndex="0"

+                        <ComboBox x:Name="_accountTypeComboBox_"

+                                  SelectedIndex="0"

                                   Margin="10"

                                   VerticalAlignment="Center"

                                   Width="195">

@@ -272,25 +275,14 @@
                     <!-- RING account. -->

                     <StackPanel x:Name="_ringAccountCreationStack_"

                                 Visibility="Visible">

-                        <TextBox  Margin="10"

+                        <TextBox  x:Name="_aliasTextBox_"

+                                  Margin="10"

                                   PlaceholderText="Enter your username"/>

                         <PasswordBox Margin="10"

                                      PlaceholderText="Enter your password"/>

                         <PasswordBox  Margin="10"

                                       PlaceholderText="Repeat your Password"/>

                     </StackPanel>

-                    <!-- SIP account. -->

-                    <StackPanel x:Name="_sipAccountCreationStack_"

-                                Visibility="Collapsed">

-                        <TextBox Margin="10"

-                                 PlaceholderText="Enter hostname"/>

-                        <TextBox Margin="10"

-                                 PlaceholderText="Enter your username"/>

-                        <PasswordBox Margin="10"

-                                     PlaceholderText="Enter your password"/>

-                        <PasswordBox Margin="10"

-                                     PlaceholderText="Repeat your Password"/>

-                    </StackPanel>

                 </StackPanel>

                 <!-- buttons yes/no to create the new account. -->

                 <Grid Grid.Row="1">

@@ -302,14 +294,14 @@
                                 HorizontalAlignment="Center"

                                 Content="&#xE081;"

                                 Click="_createAccountYes__Click"

-                                Style="{StaticResource ButtonStyle2}"/>

+                                Style="{StaticResource ButtonStyle5}"/>

                         <Button x:Name="_createAccountNo_"

                                 Grid.Row="1"

                                 VerticalAlignment="Center"

                                 HorizontalAlignment="Center"

                                 Content="&#xE106;"

                                 Click="_createAccountNo__Click"

-                                Style="{StaticResource ButtonStyle2}"/>

+                                Style="{StaticResource ButtonStyle5}"/>

                     </StackPanel>

                 </Grid>

             </Grid>

diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index 85238c0..2742708 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -48,6 +48,10 @@
         auto uri = ref new Windows::Foundation::Uri(image_path);

         _selectedAccountAvatar_->ImageSource = ref new BitmapImage(uri);

     });

+    AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() {

+        _accountsListScrollView_->UpdateLayout();

+        _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);

+    });

 

     _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;

     _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;

@@ -129,16 +133,35 @@
     _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;

 }

 

-

 void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

 {

-

+    switch (_accountTypeComboBox_->SelectedIndex)

+    {

+    case 0:

+        {

+            RingD::instance->createRINGAccount(_aliasTextBox_->Text);

+            _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

+            _accountsMenuButton__Checked(nullptr, nullptr);

+            break;

+        }

+        break;

+    case 1:

+        {

+            RingD::instance->createSIPAccount(_aliasTextBox_->Text);

+            _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

+            _accountsMenuButton__Checked(nullptr, nullptr);

+            break;

+        }

+        default:

+            break;

+    }

 }

 

 

 void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

 {

-

+    _accountsMenuButton_->IsChecked = false;

+    _accountsMenuButton__Unchecked(nullptr,nullptr);

 }

 

 void

diff --git a/Styles.xaml b/Styles.xaml
index 9afeebe..3a87cd9 100644
--- a/Styles.xaml
+++ b/Styles.xaml
@@ -115,6 +115,19 @@
         <Setter Property="Background"

                 Value="LightBlue"/>

     </Style>

+    <Style x:Key="ButtonStyle5"

+        TargetType="Button">

+        <Setter Property="Width"

+            Value="160"/>

+        <Setter Property="Height"

+            Value="30"/>

+        <Setter Property="FontFamily"

+            Value="Segoe MDL2 Assets"/>

+        <Setter Property="Foreground"

+            Value="White"/>

+        <Setter Property="Background"

+            Value="Transparent"/>

+    </Style>

     <Style x:Key="ToggleButtonStyle1"

            TargetType="ToggleButton">

         <Setter Property="Width"