Commit 82f8dda3 authored by atraczyk's avatar atraczyk Committed by Andreas Traczyk

Internal: populate account list from daemon

- Fills the account list after retrieving account list
  details form the daemon

Change-Id: I654fb554704049a942979de07a1b6b01ec513051
Tuleap: #962
parent ebec625c
...@@ -23,10 +23,20 @@ using namespace ViewModel; ...@@ -23,10 +23,20 @@ using namespace ViewModel;
AccountsViewModel::AccountsViewModel() AccountsViewModel::AccountsViewModel()
{ {
/* accountList_ should be filled with accounts saved on the disk */
accountsList_ = ref new Vector<Account^>(); accountsList_ = ref new Vector<Account^>();
}
accountsList_->Append(ref new Account("Moi","jfdhfshfhsk")); void
accountsList_->Append(ref new Account("SuperMan", "jfdhfshfhsk")); AccountsViewModel::add(std::string& name, std::string& ringid)
accountsList_->Append(ref new Account("Travail", "jfdhfshfhsk")); {
accountsList_->Append(ref new Account(
Utils::toPlatformString(name),
Utils::toPlatformString(ringid)
));
}
void
AccountsViewModel::clearAccountList()
{
accountsList_->Clear();
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/ **************************************************************************/
using namespace Platform::Collections; using namespace Platform::Collections;
namespace RingClientUWP namespace RingClientUWP
...@@ -36,6 +37,8 @@ internal: ...@@ -36,6 +37,8 @@ internal:
} }
/* functions */ /* functions */
void add(std::string& name, std::string& ringid);
void clearAccountList();
/* properties */ /* properties */
property Vector<Account^>^ accountsList property Vector<Account^>^ accountsList
......
/*************************************************************************** /***************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux * * Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> * * Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or * * the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/ **************************************************************************/
#include "pch.h" #include "pch.h"
/* daemon */ /* daemon */
#include <dring.h> #include <dring.h>
#include "callmanager_interface.h" #include "callmanager_interface.h"
#include "configurationmanager_interface.h" #include "configurationmanager_interface.h"
#include "presencemanager_interface.h" #include "presencemanager_interface.h"
#include "fileutils.h" #include "fileutils.h"
#include "account_schema.h" #include "account_schema.h"
using namespace Windows::ApplicationModel::Core; using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage; using namespace Windows::Storage;
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using namespace RingClientUWP; using namespace RingClientUWP;
using namespace RingClientUWP::Utils; using namespace RingClientUWP::Utils;
void void
DebugOutputWrapper(const std::string& str) debugOutputWrapper(const std::string& str)
{ {
MSG_(str); MSG_(str);
} }
void void
RingD::startDaemon() reloadAccountList()
{ {
create_task([&]() RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList();
{ std::vector<std::string> accountList = DRing::getAccountList();
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; for (std::string i : accountList) {
using namespace std::placeholders; std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(i);
RingClientUWP::ViewModel::AccountsViewModel::instance->add(
std::map<std::string, SharedCallback> callHandlers = { accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second,
// use IncomingCall only to register the call client sided, use StateChange to determine the impact on the UI accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second);
DRing::exportable_callback<DRing::CallSignal::IncomingCall>([this]( }
const std::string& accountId, }
const std::string& callId,
const std::string& from) void
{ RingClientUWP::RingD::startDaemon()
MSG_("<IncomingCall>"); {
MSG_("accountId = " + accountId); create_task([&]()
MSG_("callId = " + callId); {
MSG_("from = " + from); using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
using namespace std::placeholders;
auto accountId2 = toPlatformString(accountId);
auto callId2 = toPlatformString(callId); std::map<std::string, SharedCallback> callHandlers = {
auto from2 = toPlatformString(from); // use IncomingCall only to register the call client sided, use StateChange to determine the impact on the UI
DRing::exportable_callback<DRing::CallSignal::IncomingCall>([this](
incomingCall(accountId2, callId2, from2); const std::string& accountId,
const std::string& callId,
}), const std::string& from)
DRing::exportable_callback<DRing::CallSignal::StateChange>([this]( {
const std::string& callId, MSG_("<IncomingCall>");
const std::string& state, MSG_("accountId = " + accountId);
int code) MSG_("callId = " + callId);
{ MSG_("from = " + from);
MSG_("<StateChange>");
MSG_("callId = " + callId); auto accountId2 = toPlatformString(accountId);
MSG_("state = " + state); auto callId2 = toPlatformString(callId);
MSG_("code = " + std::to_string(code)); auto from2 = toPlatformString(from);
auto callId2 = toPlatformString(callId); incomingCall(accountId2, callId2, from2);
auto state2 = toPlatformString(state);
}),
stateChange(callId2, state2, code); DRing::exportable_callback<DRing::CallSignal::StateChange>([this](
const std::string& callId,
}), const std::string& state,
DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this]( int code)
const std::string& accountId, {
const std::string& from, MSG_("<StateChange>");
const std::map<std::string, std::string>& payloads) MSG_("callId = " + callId);
{ MSG_("state = " + state);
MSG_("<IncomingAccountMessage>"); MSG_("code = " + std::to_string(code));
MSG_("accountId = " + accountId);
MSG_("from = " + from); auto callId2 = toPlatformString(callId);
auto state2 = toPlatformString(state);
for (auto i : payloads) {
MSG_("payload = " + i.second); stateChange(callId2, state2, code);
auto payload = Utils::toPlatformString(i.second);
} }),
}) DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this](
}; const std::string& accountId,
const std::string& from,
registerCallHandlers(callHandlers); const std::map<std::string, std::string>& payloads)
{
std::map<std::string, SharedCallback> dringDebugOutHandler; MSG_("<IncomingAccountMessage>");
dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend> MSG_("accountId = " + accountId);
(std::bind(&DebugOutputWrapper, _1))); MSG_("from = " + from);
registerCallHandlers(dringDebugOutHandler);
for (auto i : payloads) {
std::map<std::string, SharedCallback> getAppPathHandler = MSG_("payload = " + i.second);
{ auto payload = Utils::toPlatformString(i.second);
DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath> }
([this](std::vector<std::string>* paths) { }),
paths->emplace_back(localFolder_); DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]()
}) {
}; reloadAccountList();
registerCallHandlers(getAppPathHandler); })
};
DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG |
DRing::DRING_FLAG_DEBUG | registerCallHandlers(callHandlers);
DRing::DRING_FLAG_AUTOANSWER));
std::map<std::string, SharedCallback> dringDebugOutHandler;
if (!DRing::start()) { dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend>
ERR_("\ndaemon didn't start.\n"); (std::bind(&debugOutputWrapper, _1)));
return; registerCallHandlers(dringDebugOutHandler);
}
else { std::map<std::string, SharedCallback> getAppPathHandler =
if (!hasConfig) {
{ DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath>
std::map<std::string, std::string> test_details; ([this](std::vector<std::string>* paths) {
test_details.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_ALIAS, accountName)); paths->emplace_back(localFolder_);
test_details.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_TYPE,"RING")); })
DRing::addAccount(test_details); };
} registerCallHandlers(getAppPathHandler);
while (true) {
DRing::pollEvents(); DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG |
Sleep(1000); DRing::DRING_FLAG_DEBUG |
dequeueTasks(); DRing::DRING_FLAG_AUTOANSWER));
}
DRing::fini(); if (!DRing::start()) {
} ERR_("\ndaemon didn't start.\n");
}); return;
} }
else {
RingD::RingD() if (!hasConfig)
{ {
localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path); 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"));
void DRing::addAccount(test_details);
RingD::dequeueTasks() }
{ CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
for (int i = 0; i < tasksList_.size(); i++) { ref new DispatchedHandler([=]() {
auto task = tasksList_.front(); reloadAccountList();
switch (task->request) { }));
case Request::None:
default: while (true) {
break; DRing::pollEvents();
} Sleep(1000);
tasksList_.pop(); dequeueTasks();
} }
} DRing::fini();
}
});
}
RingD::RingD()
{
localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path);
}
void
RingD::dequeueTasks()
{
for (int i = 0; i < tasksList_.size(); i++) {
auto task = tasksList_.front();
switch (task->request) {
case Request::None:
default:
break;
}
tasksList_.pop();
}
}
...@@ -338,6 +338,7 @@ ...@@ -338,6 +338,7 @@
Width="320" Width="320"
TextWrapping="Wrap" TextWrapping="Wrap"
Style="{StaticResource TextBoxStyle1}" Style="{StaticResource TextBoxStyle1}"
KeyDown="_ringTxtBx__KeyDown"
Text=""/> Text=""/>
<ListBox x:Name="_smartList_" <ListBox x:Name="_smartList_"
Grid.Row="1" Grid.Row="1"
......
/*************************************************************************** /***************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux * * Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or * * the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/ **************************************************************************/
#include "pch.h" #include "pch.h"
#include "SmartPanel.xaml.h" #include "SmartPanel.xaml.h"
using namespace Platform; using namespace Platform;
using namespace RingClientUWP; using namespace RingClientUWP;
using namespace RingClientUWP::Views; using namespace RingClientUWP::Views;
using namespace RingClientUWP::ViewModel; using namespace RingClientUWP::ViewModel;
using namespace Windows::Media::Capture; using namespace Windows::Media::Capture;
using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml;
using namespace Windows::Storage; using namespace Windows::Storage;
using namespace Windows::UI::Xaml::Media::Imaging; using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Shapes; using namespace Windows::UI::Xaml::Shapes;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
using namespace Concurrency; using namespace Concurrency;
using namespace Windows::Foundation; using namespace Windows::Foundation;
SmartPanel::SmartPanel() SmartPanel::SmartPanel()
{ {
InitializeComponent(); InitializeComponent();
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
_smartList_->ItemsSource = ContactsViewModel::instance->contactsList; _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
} }
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{ {
_shareMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
} }
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e)
{ {
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
} }
void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e)
{ {
_smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible;
} }
void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e)
{ {
_settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
} }
void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
{ {
if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
_rowRingTxtBx_->Height = 40; _rowRingTxtBx_->Height = 40;
_selectedAccountAvatar_->Height = 80; _selectedAccountAvatar_->Height = 80;
_selectedAccountAvatarColumn_->Width = 90; _selectedAccountAvatarColumn_->Width = 90;
_selectedAccountRow_->Height = 90; _selectedAccountRow_->Height = 90;
} }
else { else {
_rowRingTxtBx_->Height = 0; _rowRingTxtBx_->Height = 0;
_selectedAccountAvatar_->Height = 50; _selectedAccountAvatar_->Height = 50;
_selectedAccountAvatarColumn_->Width = 60; _selectedAccountAvatarColumn_->Width = 60;
_selectedAccountRow_->Height = 60; _selectedAccountRow_->Height = 60;
} }
_selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height;
_settingsTBtn_->IsChecked = false; _settingsTBtn_->IsChecked = false;
_accountsMenuButton_->IsChecked = false; _accountsMenuButton_->IsChecked = false;
_shareMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false;
} }
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{ {
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountsMenuButton_->IsChecked = false; _accountsMenuButton_->IsChecked = false;
} }
void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{ {
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
} }
void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) {
{ _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; }
}
void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{ }
} void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) }
{
void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
} {
CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI();
cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png;
void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100);
{
CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI();
cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo)
cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); {
if (photo != nullptr) {
// maybe it would be possible to move some logics to the style sheet
create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) auto brush = ref new ImageBrush();
{
if (photo != nullptr) { auto circle = ref new Ellipse();
// maybe it would be possible to move some logics to the style sheet circle->Height = 80; // TODO : use some global constant when ready
auto brush = ref new ImageBrush(); circle->Width = 80;
auto path = photo->Path;
auto circle = ref new Ellipse(); auto uri = ref new Windows::Foundation::Uri(path);
circle->Height = 80; // TODO : use some global constant when ready auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
circle->Width = 80; bitmapImage->UriSource = uri;
auto path = photo->Path;
auto uri = ref new Windows::Foundation::Uri(path); brush->ImageSource = bitmapImage;
auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); circle->Fill = brush;
bitmapImage->UriSource = uri; _avatarWebcamCaptureBtn_->Content = circle;