diff --git a/AccountsViewModel.cpp b/AccountsViewModel.cpp index 80dfbd5f511ac89d49ee1f2f24cde865a7bc6da4..229d58c9fa7b8984aadd1ca49387268a164d9be7 100644 --- a/AccountsViewModel.cpp +++ b/AccountsViewModel.cpp @@ -23,10 +23,20 @@ using namespace ViewModel; AccountsViewModel::AccountsViewModel() { - /* accountList_ should be filled with accounts saved on the disk */ accountsList_ = ref new Vector<Account^>(); +} - accountsList_->Append(ref new Account("Moi","jfdhfshfhsk")); - accountsList_->Append(ref new Account("SuperMan", "jfdhfshfhsk")); - accountsList_->Append(ref new Account("Travail", "jfdhfshfhsk")); +void +AccountsViewModel::add(std::string& name, std::string& ringid) +{ + accountsList_->Append(ref new Account( + Utils::toPlatformString(name), + Utils::toPlatformString(ringid) + )); +} + +void +AccountsViewModel::clearAccountList() +{ + accountsList_->Clear(); } \ No newline at end of file diff --git a/AccountsViewModel.h b/AccountsViewModel.h index 4f89a7180c45d7b2bb63eb710518ecb31b4175b9..cb39bc83995ad9ef97782e589d4bf172230ce276 100644 --- a/AccountsViewModel.h +++ b/AccountsViewModel.h @@ -16,6 +16,7 @@ * 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; namespace RingClientUWP @@ -36,6 +37,8 @@ internal: } /* functions */ + void add(std::string& name, std::string& ringid); + void clearAccountList(); /* properties */ property Vector<Account^>^ accountsList diff --git a/RingD.cpp b/RingD.cpp index c418f4b497161a387d1db4eb5263dcacda7b3613..5f542e60367fa2bb476093ba51dfdf9cea598740 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -1,161 +1,183 @@ -/*************************************************************************** -* Copyright (C) 2016 by Savoir-faire Linux * -* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com> * -* Author: Traczyk Andreas <traczyk.andreas@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" - -/* daemon */ -#include <dring.h> -#include "callmanager_interface.h" -#include "configurationmanager_interface.h" -#include "presencemanager_interface.h" -#include "fileutils.h" - -#include "account_schema.h" - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::Storage; -using namespace Windows::UI::Core; - -using namespace RingClientUWP; -using namespace RingClientUWP::Utils; - -void -DebugOutputWrapper(const std::string& str) -{ - MSG_(str); -} - -void -RingD::startDaemon() -{ - create_task([&]() - { - using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; - using namespace std::placeholders; - - std::map<std::string, SharedCallback> callHandlers = { - // 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]( - const std::string& accountId, - const std::string& callId, - const std::string& from) - { - MSG_("<IncomingCall>"); - MSG_("accountId = " + accountId); - MSG_("callId = " + callId); - MSG_("from = " + from); - - auto accountId2 = toPlatformString(accountId); - auto callId2 = toPlatformString(callId); - auto from2 = toPlatformString(from); - - incomingCall(accountId2, callId2, from2); - - }), - DRing::exportable_callback<DRing::CallSignal::StateChange>([this]( - const std::string& callId, - const std::string& state, - int code) - { - MSG_("<StateChange>"); - MSG_("callId = " + callId); - MSG_("state = " + state); - MSG_("code = " + std::to_string(code)); - - auto callId2 = toPlatformString(callId); - auto state2 = toPlatformString(state); - - stateChange(callId2, state2, code); - - }), - DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this]( - const std::string& accountId, - const std::string& from, - const std::map<std::string, std::string>& payloads) - { - MSG_("<IncomingAccountMessage>"); - MSG_("accountId = " + accountId); - MSG_("from = " + from); - - for (auto i : payloads) { - MSG_("payload = " + i.second); - auto payload = Utils::toPlatformString(i.second); - } - }) - }; - - registerCallHandlers(callHandlers); - - std::map<std::string, SharedCallback> dringDebugOutHandler; - dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend> - (std::bind(&DebugOutputWrapper, _1))); - registerCallHandlers(dringDebugOutHandler); - - std::map<std::string, SharedCallback> getAppPathHandler = - { - DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath> - ([this](std::vector<std::string>* paths) { - paths->emplace_back(localFolder_); - }) - }; - registerCallHandlers(getAppPathHandler); - - DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG | - DRing::DRING_FLAG_DEBUG | - DRing::DRING_FLAG_AUTOANSWER)); - - if (!DRing::start()) { - ERR_("\ndaemon didn't start.\n"); - return; - } - 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); - } - while (true) { - DRing::pollEvents(); - Sleep(1000); - 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(); - } -} +/*************************************************************************** +* Copyright (C) 2016 by Savoir-faire Linux * +* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * +* Author: Traczyk Andreas <traczyk.andreas@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" + +/* daemon */ +#include <dring.h> +#include "callmanager_interface.h" +#include "configurationmanager_interface.h" +#include "presencemanager_interface.h" +#include "fileutils.h" + +#include "account_schema.h" + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::Storage; +using namespace Windows::UI::Core; + +using namespace RingClientUWP; +using namespace RingClientUWP::Utils; + +void +debugOutputWrapper(const std::string& str) +{ + MSG_(str); +} + +void +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); + RingClientUWP::ViewModel::AccountsViewModel::instance->add( + accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second, + accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second); + } +} + +void +RingClientUWP::RingD::startDaemon() +{ + create_task([&]() + { + using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; + using namespace std::placeholders; + + std::map<std::string, SharedCallback> callHandlers = { + // 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]( + const std::string& accountId, + const std::string& callId, + const std::string& from) + { + MSG_("<IncomingCall>"); + MSG_("accountId = " + accountId); + MSG_("callId = " + callId); + MSG_("from = " + from); + + auto accountId2 = toPlatformString(accountId); + auto callId2 = toPlatformString(callId); + auto from2 = toPlatformString(from); + + incomingCall(accountId2, callId2, from2); + + }), + DRing::exportable_callback<DRing::CallSignal::StateChange>([this]( + const std::string& callId, + const std::string& state, + int code) + { + MSG_("<StateChange>"); + MSG_("callId = " + callId); + MSG_("state = " + state); + MSG_("code = " + std::to_string(code)); + + auto callId2 = toPlatformString(callId); + auto state2 = toPlatformString(state); + + stateChange(callId2, state2, code); + + }), + DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this]( + const std::string& accountId, + const std::string& from, + const std::map<std::string, std::string>& payloads) + { + MSG_("<IncomingAccountMessage>"); + MSG_("accountId = " + accountId); + MSG_("from = " + from); + + for (auto i : payloads) { + MSG_("payload = " + i.second); + auto payload = Utils::toPlatformString(i.second); + } + }), + DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]() + { + reloadAccountList(); + }) + }; + + registerCallHandlers(callHandlers); + + std::map<std::string, SharedCallback> dringDebugOutHandler; + dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend> + (std::bind(&debugOutputWrapper, _1))); + registerCallHandlers(dringDebugOutHandler); + + std::map<std::string, SharedCallback> getAppPathHandler = + { + DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath> + ([this](std::vector<std::string>* paths) { + paths->emplace_back(localFolder_); + }) + }; + registerCallHandlers(getAppPathHandler); + + DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG | + DRing::DRING_FLAG_DEBUG | + DRing::DRING_FLAG_AUTOANSWER)); + + if (!DRing::start()) { + ERR_("\ndaemon didn't start.\n"); + return; + } + 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); + } + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, + ref new DispatchedHandler([=]() { + reloadAccountList(); + })); + + while (true) { + DRing::pollEvents(); + Sleep(1000); + 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(); + } +} diff --git a/SmartPanel.xaml b/SmartPanel.xaml index 810edb5b9938678161048879dc5fc12c8c2b87cf..104eefdf1684b496026609707ea133b608676b71 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -338,6 +338,7 @@ Width="320" TextWrapping="Wrap" Style="{StaticResource TextBoxStyle1}" + KeyDown="_ringTxtBx__KeyDown" Text=""/> <ListBox x:Name="_smartList_" Grid.Row="1" diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index f2614f3a62e7e551ce4f8a4702d8c92411d3857d..99731d9cf053bb985023ac4640fe49c37378023f 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -1,157 +1,161 @@ -/*************************************************************************** - * 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/>. * - **************************************************************************/ -#include "pch.h" - -#include "SmartPanel.xaml.h" - -using namespace Platform; - -using namespace RingClientUWP; -using namespace RingClientUWP::Views; -using namespace RingClientUWP::ViewModel; -using namespace Windows::Media::Capture; -using namespace Windows::UI::Xaml; -using namespace Windows::Storage; -using namespace Windows::UI::Xaml::Media::Imaging; -using namespace Windows::UI::Xaml::Shapes; -using namespace Windows::UI::Xaml::Media; -using namespace Concurrency; -using namespace Windows::Foundation; - -SmartPanel::SmartPanel() -{ - InitializeComponent(); - - _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; - _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _shareMenuButton_->IsChecked = false; - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) -{ - if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { - _rowRingTxtBx_->Height = 40; - _selectedAccountAvatar_->Height = 80; - _selectedAccountAvatarColumn_->Width = 90; - _selectedAccountRow_->Height = 90; - } - else { - _rowRingTxtBx_->Height = 0; - _selectedAccountAvatar_->Height = 50; - _selectedAccountAvatarColumn_->Width = 60; - _selectedAccountRow_->Height = 60; - } - - _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; - _settingsTBtn_->IsChecked = false; - _accountsMenuButton_->IsChecked = false; - _shareMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountsMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - - -void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _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::_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; - cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); - - - create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) - { - if (photo != nullptr) { - // maybe it would be possible to move some logics to the style sheet - auto brush = ref new ImageBrush(); - - auto circle = ref new Ellipse(); - circle->Height = 80; // TODO : use some global constant when ready - circle->Width = 80; - auto path = photo->Path; - auto uri = ref new Windows::Foundation::Uri(path); - auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); - bitmapImage->UriSource = uri; - - brush->ImageSource = bitmapImage; - circle->Fill = brush; - _avatarWebcamCaptureBtn_->Content = circle; - } - }); - -} - - -void -SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) -{ - auto listbox = safe_cast<ListBox^>(sender); - auto contact = safe_cast<Contact^>(listbox->SelectedItem); - ContactsViewModel::instance->selectedContact = contact; -} +/*************************************************************************** + * 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/>. * + **************************************************************************/ +#include "pch.h" + +#include "SmartPanel.xaml.h" + +using namespace Platform; + +using namespace RingClientUWP; +using namespace RingClientUWP::Views; +using namespace RingClientUWP::ViewModel; +using namespace Windows::Media::Capture; +using namespace Windows::UI::Xaml; +using namespace Windows::Storage; +using namespace Windows::UI::Xaml::Media::Imaging; +using namespace Windows::UI::Xaml::Shapes; +using namespace Windows::UI::Xaml::Media; +using namespace Concurrency; +using namespace Windows::Foundation; + +SmartPanel::SmartPanel() +{ + InitializeComponent(); + + _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; + _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _shareMenuButton_->IsChecked = false; + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) +{ + if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { + _rowRingTxtBx_->Height = 40; + _selectedAccountAvatar_->Height = 80; + _selectedAccountAvatarColumn_->Width = 90; + _selectedAccountRow_->Height = 90; + } + else { + _rowRingTxtBx_->Height = 0; + _selectedAccountAvatar_->Height = 50; + _selectedAccountAvatarColumn_->Width = 60; + _selectedAccountRow_->Height = 60; + } + + _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; + _settingsTBtn_->IsChecked = false; + _accountsMenuButton_->IsChecked = false; + _shareMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountsMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _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::_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; + cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); + + + create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) + { + if (photo != nullptr) { + // maybe it would be possible to move some logics to the style sheet + auto brush = ref new ImageBrush(); + + auto circle = ref new Ellipse(); + circle->Height = 80; // TODO : use some global constant when ready + circle->Width = 80; + auto path = photo->Path; + auto uri = ref new Windows::Foundation::Uri(path); + auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); + bitmapImage->UriSource = uri; + + brush->ImageSource = bitmapImage; + circle->Fill = brush; + _avatarWebcamCaptureBtn_->Content = circle; + } + }); + +} + +void +SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) +{ + auto listbox = safe_cast<ListBox^>(sender); + auto contact = safe_cast<Contact^>(listbox->SelectedItem); + ContactsViewModel::instance->selectedContact = contact; +} + +void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) +{ + /* add contact, test purpose but will be reused later in some way */ + if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") { + ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text); + _ringTxtBx_->Text = ""; + } +} diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 168f3407683419ac91ea40440448bad81a040278..e5d36011021cf68c9943a013f1fe44ce92ffaa49 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -51,6 +51,7 @@ private: void _createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); + void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); }; } } \ No newline at end of file diff --git a/Utils.h b/Utils.h index 1498faa33565e007b21adf9385a1636691323571..f75f30fa383dcf130b283fdf19e74c5db9c5b246 100644 --- a/Utils.h +++ b/Utils.h @@ -6,7 +6,8 @@ using namespace Windows::Storage; namespace RingClientUWP { -namespace Utils { +namespace Utils +{ task<bool> fileExists(StorageFolder^ folder, String^ fileName) @@ -72,5 +73,6 @@ Platform::String^ toPlatformString(const std::string& str) std::wstring wsstr = makeWString(str); return ref new Platform::String(wsstr.c_str(), wsstr.length()); } + } } \ No newline at end of file