Skip to content
Snippets Groups Projects
Select Git revision
  • 8ce1dee519d786c62e7504a6d38e9f487d8036af
  • master default protected
  • release/201811
  • release/201812
  • release/201901
  • release/201902
  • release/201903
  • release/201904
  • release/201905
  • release/201906
  • release/201908
  • release/201912
  • release/202001
  • release/202005
  • release/windows-test/201910
  • release/201808
  • wip/smartlist_refacto
  • wip/patches_poly_2017/JimmyHamel/MathieuGirouxHuppe
18 results

SmartPanel.xaml.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    SmartPanel.xaml.cpp 6.61 KiB
    /***************************************************************************
     * 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 = "";
        }
    }