From 8ce1dee519d786c62e7504a6d38e9f487d8036af Mon Sep 17 00:00:00 2001
From: atraczyk <andreastraczyk@gmail.com>
Date: Thu, 25 Aug 2016 18:15:07 -0400
Subject: [PATCH] account: add account type and ringID to accounts retrieval

- Adds account type and ringID to account retrieval from the daemon

Change-Id: I6184e5cb4c3f5f5f92ee6b6939ba69630e42eb4b
Tuleap: #963
---
 Account.cpp           | 41 ++++++++++++++++++++++-------------------
 Account.h             | 42 ++++++++++++++++++++++--------------------
 AccountsViewModel.cpp | 39 +++++++++++++++++++++------------------
 AccountsViewModel.h   | 38 ++++++++++++++++++++------------------
 RingD.cpp             | 24 ++++++++++++++----------
 SmartPanel.xaml       | 23 ++++++++++++++++++++++-
 6 files changed, 121 insertions(+), 86 deletions(-)

diff --git a/Account.cpp b/Account.cpp
index 57e7da1..e5e38b0 100644
--- a/Account.cpp
+++ b/Account.cpp
@@ -1,20 +1,22 @@
-/**************************************************************************
-* Copyright (C) 2016 by Savoir-faire Linux                                *
-* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
-*                                                                         *
-* This program is free software; you can redistribute it and/or modify    *
-* it under the terms of the GNU General Public License as published by    *
-* the Free Software Foundation; either version 3 of the License, or       *
-* (at your option) any later version.                                     *
-*                                                                         *
-* This program is distributed in the hope that it will be useful,         *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
-* GNU General Public License for more details.                            *
-*                                                                         *
-* You should have received a copy of the GNU General Public License       *
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
-**************************************************************************/
+/***************************************************************************
+ * Copyright (C) 2016 by Savoir-faire Linux                                *
+ * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
+ * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
 #include "pch.h"
 
 #include "Account.h"
@@ -26,10 +28,12 @@ using namespace Windows::UI::Core;
 using namespace RingClientUWP;
 
 Account::Account(String^ name,
-                 String^ ringID)
+                 String^ ringID,
+                 String^ accountType)
 {
     name_ = name;
     ringID_ = ringID;
+    accountType_ = accountType;
 }
 
 void
@@ -41,6 +45,5 @@ Account::NotifyPropertyChanged(String^ propertyName)
         ref new DispatchedHandler([this, propertyName]()
     {
         PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
-
     }));
 }
\ No newline at end of file
diff --git a/Account.h b/Account.h
index a3744d6..9ffc164 100644
--- a/Account.h
+++ b/Account.h
@@ -1,21 +1,24 @@
+/***************************************************************************
+ * Copyright (C) 2016 by Savoir-faire Linux                                *
+ * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
+ * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
 #pragma once
-/**************************************************************************
-* Copyright (C) 2016 by Savoir-faire Linux                                *
-* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
-*                                                                         *
-* This program is free software; you can redistribute it and/or modify    *
-* it under the terms of the GNU General Public License as published by    *
-* the Free Software Foundation; either version 3 of the License, or       *
-* (at your option) any later version.                                     *
-*                                                                         *
-* This program is distributed in the hope that it will be useful,         *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
-* GNU General Public License for more details.                            *
-*                                                                         *
-* You should have received a copy of the GNU General Public License       *
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
-**************************************************************************/
+
 using namespace Platform;
 using namespace Windows::UI::Xaml::Data;
 
@@ -24,18 +27,17 @@ namespace RingClientUWP
 public ref class Account sealed : public INotifyPropertyChanged
 {
 public:
-    Account(String^ name, String^ ringID);
-
+    Account(String^ name, String^ ringID, String^ accountType);
 
     virtual event PropertyChangedEventHandler^ PropertyChanged;
 
     property String^ name_;
     property String^ ringID_;
+    property String^ accountType_;
 
 protected:
     void NotifyPropertyChanged(String^ propertyName);
 
-
 };
 }
 
diff --git a/AccountsViewModel.cpp b/AccountsViewModel.cpp
index 229d58c..d6ba553 100644
--- a/AccountsViewModel.cpp
+++ b/AccountsViewModel.cpp
@@ -1,20 +1,22 @@
 /***************************************************************************
-* Copyright (C) 2016 by Savoir-faire Linux                                *
-* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
-*                                                                         *
-* This program is free software; you can redistribute it and/or modify    *
-* it under the terms of the GNU General Public License as published by    *
-* the Free Software Foundation; either version 3 of the License, or       *
-* (at your option) any later version.                                     *
-*                                                                         *
-* This program is distributed in the hope that it will be useful,         *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
-* GNU General Public License for more details.                            *
-*                                                                         *
-* You should have received a copy of the GNU General Public License       *
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
-**************************************************************************/
+ * Copyright (C) 2016 by Savoir-faire Linux                                *
+ * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
+ * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
 #include "pch.h"
 #include "AccountsViewModel.h"
 
@@ -27,11 +29,12 @@ AccountsViewModel::AccountsViewModel()
 }
 
 void
-AccountsViewModel::add(std::string& name, std::string& ringid)
+AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType)
 {
     accountsList_->Append(ref new Account(
         Utils::toPlatformString(name),
-        Utils::toPlatformString(ringid)
+        Utils::toPlatformString(ringID),
+        Utils::toPlatformString(accountType)
     ));
 }
 
diff --git a/AccountsViewModel.h b/AccountsViewModel.h
index cb39bc8..b9c8d64 100644
--- a/AccountsViewModel.h
+++ b/AccountsViewModel.h
@@ -1,21 +1,23 @@
+/***************************************************************************
+ * Copyright (C) 2016 by Savoir-faire Linux                                *
+ * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
+ * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
 #pragma once
-/**************************************************************************
-* Copyright (C) 2016 by Savoir-faire Linux                                *
-* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com>              *
-*                                                                         *
-* This program is free software; you can redistribute it and/or modify    *
-* it under the terms of the GNU General Public License as published by    *
-* the Free Software Foundation; either version 3 of the License, or       *
-* (at your option) any later version.                                     *
-*                                                                         *
-* This program is distributed in the hope that it will be useful,         *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
-* GNU General Public License for more details.                            *
-*                                                                         *
-* You should have received a copy of the GNU General Public License       *
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
-**************************************************************************/
 
 using namespace Platform::Collections;
 
@@ -37,7 +39,7 @@ internal:
     }
 
     /* functions */
-    void add(std::string& name, std::string& ringid);
+    void add(std::string& name, std::string& ringID, std::string& accountType);
     void clearAccountList();
 
     /* properties */
diff --git a/RingD.cpp b/RingD.cpp
index 5f542e6..2d4ef73 100644
--- a/RingD.cpp
+++ b/RingD.cpp
@@ -45,11 +45,16 @@ reloadAccountList()
 {
     RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList();
     std::vector<std::string> accountList = DRing::getAccountList();
-    for (std::string i : accountList) {
-        std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(i);
+    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(ring::Conf::CONFIG_ACCOUNT_USERNAME)->second);
+        if(!ringID.empty())
+            ringID = ringID.substr(5);
         RingClientUWP::ViewModel::AccountsViewModel::instance->add(
-            accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second,
-            accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second);
+            accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second,      //name
+            ringID,                                                             //ringid
+            accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second);      //type
     }
 }
 
@@ -143,16 +148,15 @@ RingClientUWP::RingD::startDaemon()
         else {
             if (!hasConfig)
             {
-                std::map<std::string, std::string> test_details;
-                test_details.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_ALIAS, accountName));
-                test_details.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_TYPE,"RING"));
-                DRing::addAccount(test_details);
+                std::map<std::string, std::string> ringAccountDetails;
+                ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_ALIAS, accountName));
+                ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_TYPE,"RING"));
+                DRing::addAccount(ringAccountDetails);
             }
             CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
                ref new DispatchedHandler([=]() {
                 reloadAccountList();
             }));
-
             while (true) {
                 DRing::pollEvents();
                 Sleep(1000);
@@ -180,4 +184,4 @@ RingD::dequeueTasks()
         }
         tasksList_.pop();
     }
-}
+}
\ No newline at end of file
diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index 104eefd..41d32d9 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -112,18 +112,39 @@
             <Grid>
                 <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="60"/>
-                    <ColumnDefinition Width="*"/>
+                    <ColumnDefinition Width="200"/>
+                    <ColumnDefinition Width="60"/>
                 </Grid.ColumnDefinitions>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="30"/>
+                    <RowDefinition Height="30"/>
+                </Grid.RowDefinitions>
                 <Image x:Name="_accountAvatar_"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        Grid.Column="0"
+                       Grid.RowSpan="2"
                        Width="55"
                        Height="55"
                        Source="Assets\TESTS\contactAvatar.png"/>
                 <TextBlock x:Name="_accountName_"
                            Grid.Column="1"
+                           Grid.Row="0"
                            Text="{x:Bind name_}"/>
+                <TextBlock x:Name="_accountType_"
+                           Grid.Column="2"
+                           Grid.Row="0"
+                           TextAlignment="Right"
+                           Margin="0,0,10,0"
+                           Foreground="ForestGreen"
+                           Text="{x:Bind accountType_}"/>
+                <TextBlock x:Name="_ringID_"
+                           Grid.Column="1"
+                           Grid.ColumnSpan="2"
+                           Grid.Row="1"
+                           Foreground="Crimson"
+                           TextTrimming="CharacterEllipsis"
+                           Text="{x:Bind ringID_}"/>
             </Grid>
         </DataTemplate>
     </Page.Resources>
-- 
GitLab