blob: d9e0dd541f4e4f3e51468330ffe36346139cdfe0 [file] [log] [blame]
Nicolas Jager38f15642016-09-01 09:45:58 -04001/***************************************************************************
2 * Copyright (C) 2016 by Savoir-faire Linux *
3 * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4 * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 **************************************************************************/
19#include "pch.h"
20
21#include "SmartPanel.xaml.h"
22
23using namespace Platform;
24
25using namespace RingClientUWP;
26using namespace RingClientUWP::Views;
27using namespace RingClientUWP::ViewModel;
28using namespace Windows::Media::Capture;
29using namespace Windows::UI::Xaml;
30using namespace Windows::Storage;
31using namespace Windows::UI::Xaml::Media::Imaging;
32using namespace Windows::UI::Xaml::Shapes;
33using namespace Windows::UI::Xaml::Media;
34using namespace Concurrency;
35using namespace Windows::Foundation;
36
37SmartPanel::SmartPanel()
38{
39 InitializeComponent();
40
41 Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
42 _accountsList_->SelectedIndex = index;
43 });
44
45 _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
46 _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
47}
48
49void
50RingClientUWP::Views::SmartPanel::updatePageContent()
51{
52 auto account = AccountsViewModel::instance->selectedAccount;
53 if (!account)
54 return;
55
56 Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
57 Configuration::UserPreferences::instance->save();
58 _selectedAccountName_->Text = account->name_;
59}
60
61void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
62{
63 _shareMenuButton_->IsChecked = false;
64 _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
65 _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
66}
67
68void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e)
69{
70 _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
71 _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
72}
73
74void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e)
75{
76 _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
77 _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible;
78}
79
80void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e)
81{
82 _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
83 _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
84}
85
86void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
87{
88 if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
89 _rowRingTxtBx_->Height = 40;
90 _selectedAccountAvatar_->Height = 80;
91 _selectedAccountAvatarColumn_->Width = 90;
92 _selectedAccountRow_->Height = 90;
93 }
94 else {
95 _rowRingTxtBx_->Height = 0;
96 _selectedAccountAvatar_->Height = 50;
97 _selectedAccountAvatarColumn_->Width = 60;
98 _selectedAccountRow_->Height = 60;
99 }
100
101 _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height;
102 _settingsTBtn_->IsChecked = false;
103 _accountsMenuButton_->IsChecked = false;
104 _shareMenuButton_->IsChecked = false;
105}
106
107void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
108{
109 _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
110 _accountsMenuButton_->IsChecked = false;
111}
112
113void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
114{
115 _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
116}
117
118
119void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
120{
121 _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
122 _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
123}
124
125
126void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
127{
128
129}
130
131
132void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
133{
134
135}
136
137
138void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
139{
140 CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI();
141 cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png;
142 cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100);
143
144
145 create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo)
146 {
147 if (photo != nullptr) {
148 // maybe it would be possible to move some logics to the style sheet
149 auto brush = ref new ImageBrush();
150
151 auto circle = ref new Ellipse();
152 circle->Height = 80; // TODO : use some global constant when ready
153 circle->Width = 80;
154 auto path = photo->Path;
155 auto uri = ref new Windows::Foundation::Uri(path);
156 auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
157 bitmapImage->UriSource = uri;
158
159 brush->ImageSource = bitmapImage;
160 circle->Fill = brush;
161 _avatarWebcamCaptureBtn_->Content = circle;
162 }
163 });
164
165}
166
167
168void
169SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
170{
171 auto listbox = safe_cast<ListBox^>(sender);
172 auto contact = safe_cast<Contact^>(listbox->SelectedItem);
173 ContactsViewModel::instance->selectedContact = contact;
174}
175
176void
177SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
178{
179 auto listbox = safe_cast<ListBox^>(sender);
180 auto account = safe_cast<Account^>(listbox->SelectedItem);
181 AccountsViewModel::instance->selectedAccount = account;
182 updatePageContent();
183}
184
185void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
186{
187 /* add contact, test purpose but will be reused later in some way */
188 if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") {
189 ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
190 _ringTxtBx_->Text = "";
191 }
192}