SmartPanel.xaml.cpp 44.8 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/***************************************************************************
 * 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"
20
#include <string> // move it
Nicolas Jager's avatar
Nicolas Jager committed
21
#include "SmartPanel.xaml.h"
22
23
#include "qrencode.h"
#include <MemoryBuffer.h>   // IMemoryBufferByteAccess
Nicolas Jager's avatar
Nicolas Jager committed
24
25
26
27

using namespace Platform;

using namespace RingClientUWP;
28
using namespace RingClientUWP::Controls;
Nicolas Jager's avatar
Nicolas Jager committed
29
30
31
using namespace RingClientUWP::Views;
using namespace RingClientUWP::ViewModel;
using namespace Windows::Media::Capture;
32
using namespace Windows::Media::MediaProperties;
Nicolas Jager's avatar
Nicolas Jager committed
33
34
35
36
37
38
39
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;
40
41
42
using namespace Windows::Graphics::Imaging;
using namespace Windows::Foundation;
using namespace Concurrency;
Nicolas Jager's avatar
Nicolas Jager committed
43
44
using namespace Platform::Collections;

45
46
47
48
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage;
using namespace Windows::UI::Core;

Nicolas Jager's avatar
Nicolas Jager committed
49
50
51
52
SmartPanel::SmartPanel()
{
    InitializeComponent();

Nicolas Jager's avatar
Nicolas Jager committed
53
54
    /* populate accounts listBox*/
    _accountsList_->ItemsSource = AccountListItemsViewModel::instance->itemsList;
55
56

    /* populate the smartlist */
57
    _smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;
58

Nicolas Jager's avatar
Nicolas Jager committed
59
60
61
62

    /* populate the device list*/
///	_devicesIdList_ // not used so far

63
    /* connect delegates */
Nicolas Jager's avatar
Nicolas Jager committed
64
    Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
65
66
67
68
69
70
71
        if (_accountsList_) {
            auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size;
            if (accountsListSize > index)
                _accountsList_->SelectedIndex = index;
            else
                _accountsList_->SelectedIndex = 0;
        }
Nicolas Jager's avatar
Nicolas Jager committed
72
    });
73
74
75
76
77
78
    Configuration::UserPreferences::instance->loadProfileImage += ref new LoadProfileImage([this]() {
        StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
        String^ image_path = localfolder->Path + "\\.profile\\profile_image.png";
        auto uri = ref new Windows::Foundation::Uri(image_path);
        _selectedAccountAvatar_->ImageSource = ref new BitmapImage(uri);
    });
atraczyk's avatar
atraczyk committed
79
80
81
82
    AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() {
        _accountsListScrollView_->UpdateLayout();
        _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);
    });
83
84
85
    RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
    String^ accountId, String^ callId, String^ from) {
        ///auto from = call->from;
86
87
88
89
90
91
92
93
94
95
        auto contact = ContactsViewModel::instance->findContactByName(from);

        if (contact == nullptr)
            contact = ContactsViewModel::instance->addNewContact(from, from); // contact checked inside addNewContact.

        if (contact == nullptr) {
            ERR_("contact not handled!");
            return;
        }

96
97
        contact->_accountIdAssociated = accountId;

98
        auto item = SmartPanelItemsViewModel::instance->findItem(contact);
99
        item->_callId = callId;
Nicolas Jager's avatar
Nicolas Jager committed
100

101
    });
Nicolas Jager's avatar
Nicolas Jager committed
102
    RingD::instance->stateChange += ref new StateChange([this](String^ callId, CallStatus state, int code) {
103

104
        auto item = SmartPanelItemsViewModel::instance->findItem(callId);
105
106
107
108
109
110

        if (!item) {
            WNG_("item not found");
            return;
        }

111
        item->_callStatus = state;
112

113
114
        switch (state) {
        case CallStatus::NONE:
115
        case CallStatus::ENDED:
116
117
118
119
120
121
122
123
124
125
126
127
128
        {
            item->_callId = "";
            break;
        }
        case CallStatus::IN_PROGRESS:
        {
            _smartList_->SelectedItem = item;
            summonVideoPage();
            break;
        }
        default:
            break;
        }
129
130

    });
131
    RingD::instance->devicesListRefreshed += ref new RingClientUWP::DevicesListRefreshed(this, &RingClientUWP::Views::SmartPanel::OndevicesListRefreshed);
132
133
134
135
136


    ContactsViewModel::instance->contactAdded += ref new ContactAdded([this](Contact^ contact) {
        auto smartPanelItem = ref new SmartPanelItem();
        smartPanelItem->_contact = contact;
137
        SmartPanelItemsViewModel::instance->itemsList->Append(smartPanelItem);
138
    });
Nicolas Jager's avatar
Nicolas Jager committed
139

140
    RingD::instance->exportOnRingEnded += ref new RingClientUWP::ExportOnRingEnded(this, &RingClientUWP::Views::SmartPanel::OnexportOnRingEnded);
141
    RingD::instance->accountUpdated += ref new RingClientUWP::AccountUpdated(this, &RingClientUWP::Views::SmartPanel::OnaccountUpdated);
Nicolas Jager's avatar
Nicolas Jager committed
142

143
144
145
    RingD::instance->finishCaptureDeviceEnumeration += ref new RingClientUWP::FinishCaptureDeviceEnumeration([this]() {
        populateVideoDeviceSettingsComboBox();
    });
Nicolas Jager's avatar
Nicolas Jager committed
146
147
148
149
150
}

void
RingClientUWP::Views::SmartPanel::updatePageContent()
{
Nicolas Jager's avatar
Nicolas Jager committed
151
152
    auto accountListItem = AccountListItemsViewModel::instance->_selectedItem;
    if (!accountListItem)
Nicolas Jager's avatar
Nicolas Jager committed
153
154
        return;

155
156
157
    auto name = accountListItem->_account->name_; // refacto remove name variable and use the link directly on the next line... like _upnpnState..._

    accountListItem->_isSelected = true;
Nicolas Jager's avatar
Nicolas Jager committed
158

Nicolas Jager's avatar
Nicolas Jager committed
159
160
    Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
    Configuration::UserPreferences::instance->save();
Nicolas Jager's avatar
Nicolas Jager committed
161

Nicolas Jager's avatar
Nicolas Jager committed
162
    _selectedAccountName_->Text = name; // refacto : bind this in xaml directly
163
///    _devicesIdList_->ItemsSource = account->_devicesIdList;
Nicolas Jager's avatar
Nicolas Jager committed
164
    _deviceId_->Text = accountListItem->_account->_deviceId; /* this is the current device ...
Nicolas Jager's avatar
Nicolas Jager committed
165
    ... in the way to get all associated devices, we have to querry the daemon : */
166

Nicolas Jager's avatar
Nicolas Jager committed
167
    _devicesMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
168
169
                                      ? Windows::UI::Xaml::Visibility::Visible
                                      : Windows::UI::Xaml::Visibility::Collapsed;
170

Nicolas Jager's avatar
Nicolas Jager committed
171
    _shareMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
172
173
                                    ? Windows::UI::Xaml::Visibility::Visible
                                    : Windows::UI::Xaml::Visibility::Collapsed;
174
175

    _upnpState_->IsOn = accountListItem->_account->_upnpState;
Nicolas Jager's avatar
Nicolas Jager committed
176
177
}

178
179
180
181
182
void RingClientUWP::Views::SmartPanel::unselectContact()
{
    _smartList_->SelectedItem = nullptr;
}

Nicolas Jager's avatar
Nicolas Jager committed
183
184
185
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
    _shareMenuButton_->IsChecked = false;
186
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
187
188
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
189
190
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
191
192
193
194
195
196
}

void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e)
{
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
197
    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
198
199
200
201
202
203
}

void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e)
{
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible;
204
205
206
207
208
209
    auto vcm = Video::VideoManager::instance->captureManager();
    if (!vcm->isInitialized)
        vcm->InitializeCameraAsync(true);
    else
        vcm->StartPreviewAsync(true);
    summonPreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
210
211
212
213
214
215
}

void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e)
{
    _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
216
217
218
219
220
221
222
223
224
225
226
227
    Video::VideoManager::instance->captureManager()->StopPreviewAsync()
        .then([](task<void> stopPreviewTask)
    {
        try {
            stopPreviewTask.get();
            Video::VideoManager::instance->captureManager()->isSettingsPreviewing = false;
        }
        catch (Exception^ e) {
            WriteException(e);
        }
    });
    hidePreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
228
229
230
231
232
233
}

void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
{
    if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
        _rowRingTxtBx_->Height = 40;
234
        _selectedAccountAvatarContainer_->Height = 80;
235
        _shaderPhotoboothIcon_->Height = 80;
Nicolas Jager's avatar
Nicolas Jager committed
236
237
238
239
240
        _selectedAccountAvatarColumn_->Width = 90;
        _selectedAccountRow_->Height = 90;
    }
    else {
        _rowRingTxtBx_->Height = 0;
241
        _selectedAccountAvatarContainer_->Height = 50;
242
        _shaderPhotoboothIcon_->Height = 50;
Nicolas Jager's avatar
Nicolas Jager committed
243
244
245
246
        _selectedAccountAvatarColumn_->Width = 60;
        _selectedAccountRow_->Height = 60;
    }

247
    _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height;
248
    _shaderPhotoboothIcon_->Width = _shaderPhotoboothIcon_->Height;
Nicolas Jager's avatar
Nicolas Jager committed
249
250
251
252
253
254
255
256
    _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;
257
258
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
259
    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
260
261
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
262
    _accountsMenuButton_->IsChecked = false;
263
    _devicesMenuButton_->IsChecked = false;
264
265

    generateQRcode();
Nicolas Jager's avatar
Nicolas Jager committed
266
267
268
269
270
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
271
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
272
    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
273
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
274
275
276
277
278
279
}

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;
280

281
    _createAccountYes_->IsEnabled = false;
282
283
284
285

    _accountTypeComboBox_->SelectedIndex = 0;
    _upnpStateAccountCreation_->IsOn = true;
    _ringAliasTextBox_->Text = "";
Nicolas Jager's avatar
Nicolas Jager committed
286
287
288
289
}

void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
290
291
    switch (_accountTypeComboBox_->SelectedIndex) {
    case 0: /* RING account */
292
    {
293
294
295
        RingD::instance->createRINGAccount(_ringAliasTextBox_->Text, _ringPasswordBoxAccountCreation_->Password, _upnpStateAccountCreation_->IsOn);
        _ringPasswordBoxAccountCreation_->Password = "";
        _ringPasswordBoxAccountCreationCheck_->Password = "";
atraczyk's avatar
atraczyk committed
296
        break;
297
298
    }
    break;
299
    case 1: /* SIP account */
300
    {
301
302
303
304
        RingD::instance->createSIPAccount(_ringAliasTextBox_->Text, _sipPasswordBoxAccountCreation_->Password, _sipHostnameTextBox_->Text, _sipUsernameTextBox_->Text);
        _sipPasswordBoxAccountCreation_->Password = "";
        _sipUsernameTextBox_->Text = "";
        _sipHostnameTextBox_->Text = "";
305
306
307
308
        break;
    }
    default:
        break;
atraczyk's avatar
atraczyk committed
309
    }
310
311
312
313
314
315

    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton__Checked(nullptr, nullptr);


Nicolas Jager's avatar
Nicolas Jager committed
316
317
318
319
320
}


void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
321
322
    _accountsMenuButton_->IsChecked = false;
    _accountsMenuButton__Unchecked(nullptr,nullptr);
Nicolas Jager's avatar
Nicolas Jager committed
323
324
325
326
327
}

void
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
328
329
330
331
332
333
334
335
    auto listbox = dynamic_cast<ListBox^>(sender);
    auto item = dynamic_cast<SmartPanelItem^>(listbox->SelectedItem);
    SmartPanelItemsViewModel::instance->_selectedItem = item;

    if (!item) {
        summonWelcomePage();
        return;
    }
Nicolas Jager's avatar
Nicolas Jager committed
336

337
338
    auto contact = item->_contact;

339
340
341
342
    if (item->_callStatus == CallStatus::IN_PROGRESS) {
        if (contact) {
            contact->_unreadMessages = 0;
            ContactsViewModel::instance->saveContactsToFile();
Nicolas Jager's avatar
Nicolas Jager committed
343
        }
344
345
346

        summonVideoPage();
        return;
Nicolas Jager's avatar
Nicolas Jager committed
347
    }
Nicolas Jager's avatar
Nicolas Jager committed
348

Nicolas Jager's avatar
Nicolas Jager committed
349
350
351
352
353
354
    if (contact) {
        summonMessageTextPage();
        contact->_unreadMessages = 0;
        ContactsViewModel::instance->saveContactsToFile();
        return;
    }
Nicolas Jager's avatar
Nicolas Jager committed
355
356
357
358
359
360
}

void
SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
    auto listbox = safe_cast<ListBox^>(sender);
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    // disable deselction from listbox
    if (listbox->SelectedItem == nullptr)
    {
        if (e->RemovedItems->Size > 0)
        {
            Object^ itemToReselect = e->RemovedItems->GetAt(0);
            for each (auto item in listbox->Items) {
                if (item == itemToReselect) {
                    listbox->SelectedItem = itemToReselect;
                    continue;
                }
            }
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
375
376
    auto account = safe_cast<AccountListItem^>(listbox->SelectedItem);
    AccountListItemsViewModel::instance->_selectedItem = account;
377

Nicolas Jager's avatar
Nicolas Jager committed
378
379
380
381
382
383
    updatePageContent();
}

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 */
384
    if (e->Key == Windows::System::VirtualKey::Enter && !_ringTxtBx_->Text->IsEmpty()) {
Nicolas Jager's avatar
Nicolas Jager committed
385
386
387
388
        ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
        _ringTxtBx_->Text = "";
    }
}
389

390
391
392
393
394
395
void RingClientUWP::Views::SmartPanel::_ringTxtBx__Click(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
    _ringTxtBx_->Text = "";
}

396
397
void
RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
398
399
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
400
401
402
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
403
404
            auto callId = item->_callId;
            RingD::instance->refuseIncommingCall(callId);
405
406
        }
    }
407
408
}

409
410
void
RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
411
412
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
413
414
415
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
416
417
            auto callId = item->_callId;
            RingD::instance->acceptIncommingCall(callId);
418
419
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
420
421
422
423
424
425
}

void
SmartPanel::_callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
426
    if (button) {
427
428
429
        /* force to hide the button, avoid attempting to call several times... */
        button->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

430
431
432
433
434
435
436
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            auto contact = item->_contact;
            if (contact)
                RingD::instance->placeCall(contact);
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
437
438
439
440
441
}

void RingClientUWP::Views::SmartPanel::_cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
442
443
444
445
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            RingD::instance->cancelOutGoingCall2(item->_callId);
446
            item->_callStatus = CallStatus::TERMINATING;
447
448
449
            return;
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
450
451
452
453
454
455
456
}

void RingClientUWP::Views::SmartPanel::Grid_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    auto grid = dynamic_cast<Grid^>(sender);
    auto item = dynamic_cast<SmartPanelItem^>(grid->DataContext);

457
458
459
460
    for (auto it : SmartPanelItemsViewModel::instance->itemsList)
        it->_hovered = Windows::UI::Xaml::Visibility::Collapsed;

    item->_hovered = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
461
462
463
464
465
466
467
468
}


void RingClientUWP::Views::SmartPanel::Grid_PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    auto grid = dynamic_cast<Grid^>(sender);
    auto item = dynamic_cast<SmartPanelItem^>(grid->DataContext);

469
470
    for each (auto it in SmartPanelItemsViewModel::instance->itemsList)
        item->_hovered = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
471
472
473
474
475
476
477
478
479
480
481
482
483
}


void RingClientUWP::Views::SmartPanel::_contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    auto listBoxItem = dynamic_cast<ListBoxItem^>(sender);
    auto smartPanelItem = dynamic_cast<SmartPanelItem^>(listBoxItem->DataContext);

    if (_smartList_->SelectedItem != smartPanelItem)
        _smartList_->SelectedItem = smartPanelItem;
    else
        _smartList_->SelectedItem = nullptr;

Nicolas Jager's avatar
Nicolas Jager committed
484
485
}

486
487
void RingClientUWP::Views::SmartPanel::generateQRcode()
{
Nicolas Jager's avatar
Nicolas Jager committed
488
    auto ringId = AccountListItemsViewModel::instance->_selectedItem->_account->ringID_;
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
    auto ringId2 = Utils::toString(ringId);

    _ringId_->Text = ringId;

    auto qrcode = QRcode_encodeString(ringId2.c_str(),
                                      0, //Let the version be decided by libqrencode
                                      QR_ECLEVEL_L, // Lowest level of error correction
                                      QR_MODE_8, // 8-bit data mode
                                      1);

    if (!qrcode) {
        WNG_("Failed to generate QR code: ");
        return;
    }

    const int STRETCH_FACTOR = 4;
    const int widthQrCode = qrcode->width;
    const int widthBitmap = STRETCH_FACTOR * widthQrCode;

    unsigned char* qrdata = qrcode->data;

    auto frame = ref new SoftwareBitmap(BitmapPixelFormat::Bgra8, widthBitmap, widthBitmap, BitmapAlphaMode::Premultiplied);

    const int BYTES_PER_PIXEL = 4;


    BitmapBuffer^ buffer = frame->LockBuffer(BitmapBufferAccessMode::ReadWrite);
    IMemoryBufferReference^ reference = buffer->CreateReference();

    Microsoft::WRL::ComPtr<IMemoryBufferByteAccess> byteAccess;
    if (SUCCEEDED(reinterpret_cast<IUnknown*>(reference)->QueryInterface(IID_PPV_ARGS(&byteAccess))))
    {
        byte* data;
        unsigned capacity;
        byteAccess->GetBuffer(&data, &capacity);

        auto desc = buffer->GetPlaneDescription(0);

        unsigned char* row, * p;
        p = qrcode->data;

        for (int u = 0 ; u < widthBitmap ; u++) {
            for (int v = 0; v < widthBitmap; v++) {
                int x = (float)u / (float)widthBitmap * (float)widthQrCode;
                int y = (float)v / (float)widthBitmap * (float)widthQrCode;

                auto currPixelRow = desc.StartIndex + desc.Stride * u + BYTES_PER_PIXEL * v;
                row = (p + (y * widthQrCode));

                if (*(row + x) & 0x1) {
                    data[currPixelRow + 3] = 255;
                }
            }
        }

    }
    delete reference;
    delete buffer;

    auto sbSource = ref new Media::Imaging::SoftwareBitmapSource();

    sbSource->SetBitmapAsync(frame);

    _selectedAccountQrCode_->Source = sbSource;
}

Nicolas Jager's avatar
Nicolas Jager committed
555
556
557
Object ^ RingClientUWP::Views::IncomingVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto state = static_cast<CallStatus>(value);
558

559
    if (state == CallStatus::INCOMING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
        return  Windows::UI::Xaml::Visibility::Visible;
    else
        return  Windows::UI::Xaml::Visibility::Collapsed;
}

Object ^ RingClientUWP::Views::IncomingVisibility::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::IncomingVisibility::IncomingVisibility()
{}


Object ^ RingClientUWP::Views::OutGoingVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto state = static_cast<CallStatus>(value);

578
    if (state == CallStatus::SEARCHING || state == CallStatus::OUTGOING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
        return  Windows::UI::Xaml::Visibility::Visible;
    else
        return  Windows::UI::Xaml::Visibility::Collapsed;
}

Object ^ RingClientUWP::Views::OutGoingVisibility::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::OutGoingVisibility::OutGoingVisibility()
{}

Object ^ RingClientUWP::Views::HasAnActiveCall::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto state = static_cast<CallStatus>(value);

596
    if (state == CallStatus::NONE || state == CallStatus::ENDED)
Nicolas Jager's avatar
Nicolas Jager committed
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
        return Windows::UI::Xaml::Visibility::Collapsed;
    else
        return Windows::UI::Xaml::Visibility::Visible;
}

Object ^ RingClientUWP::Views::HasAnActiveCall::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::HasAnActiveCall::HasAnActiveCall()
{}

Object ^ RingClientUWP::Views::NewMessageBubleNotification::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto unreadMessages = static_cast<uint32>(value);

    if (unreadMessages > 0)
        return Windows::UI::Xaml::Visibility::Visible;

    return Windows::UI::Xaml::Visibility::Collapsed;
}

Object ^ RingClientUWP::Views::NewMessageBubleNotification::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::NewMessageBubleNotification::NewMessageBubleNotification()
{}
627
628
629
630

void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
631
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
632
633
634
635
636
    _waitingForPin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _passwordForPinGenerator_->Password = "";
    // refacto : do something better...
    _waitingAndResult_->Text = "Exporting account on the Ring...";

637
638
639
640
641
}


void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
642
643
644
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

Nicolas Jager's avatar
Nicolas Jager committed
645
    auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
Nicolas Jager's avatar
Nicolas Jager committed
646
647
    RingD::instance->askToRefreshKnownDevices(accountId);

648
649
650
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
651
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
652
653
654
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
655
656
657
658
659
}


void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
660
661
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
662
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
663
664
665
666
667
}


void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
Nicolas Jager's avatar
Nicolas Jager committed
668
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
669
    AccountListItemsViewModel::instance->_selectedItem->_account->_devicesIdList = devicesList;
670
    _devicesIdList_->ItemsSource = devicesList;
Nicolas Jager's avatar
Nicolas Jager committed
671
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
672
673
674
675
676
677
678
679
}


void RingClientUWP::Views::SmartPanel::_pinGeneratorYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _waitingForPin_->Visibility = Windows::UI::Xaml::Visibility::Visible;

Nicolas Jager's avatar
Nicolas Jager committed
680
    auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
681
    auto password = _passwordForPinGenerator_->Password;
Nicolas Jager's avatar
Nicolas Jager committed
682
683
684
685
    _passwordForPinGenerator_->Password = "";

    /* hide the button while we are waiting... */
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
686
687
688
689
690
691
692
693
694

    RingD::instance->askToExportOnRing(accountId, password);
}


void RingClientUWP::Views::SmartPanel::_pinGeneratorNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
695
    _passwordForPinGenerator_->Password = "";
696
}
697

698
699
700
701

void RingClientUWP::Views::SmartPanel::OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin)
{
    _waitingAndResult_->Text = pin;
Nicolas Jager's avatar
Nicolas Jager committed
702
703
704
705
706
707
708
709
710
711
712
713
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;

}


void RingClientUWP::Views::SmartPanel::_closePin__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _waitingForPin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _devicesMenuButton_->IsChecked = false;

    // refacto : do something better...
    _waitingAndResult_->Text = "Exporting account on the Ring...";
714
}
715
716
717
718
719
720
721
722


void RingClientUWP::Views::SmartPanel::_shareMenuDone__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuButton_->IsChecked = false;

    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745

Object ^ RingClientUWP::Views::AccountTypeToSourceImage::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto accountType = dynamic_cast<String^>(value);
    Uri^ uri = (accountType == "RING")
               ? ref new Uri("ms-appx:///Assets/AccountTypeRING.png")
               : ref new Uri("ms-appx:///Assets/AccountTypeSIP.png");

    return ref new BitmapImage(uri);
}

Object ^ RingClientUWP::Views::AccountTypeToSourceImage::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::AccountTypeToSourceImage::AccountTypeToSourceImage()
{}

Object ^ RingClientUWP::Views::AccountSelectedToVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    //auto accountId = static_cast<bool(value);

Nicolas Jager's avatar
Nicolas Jager committed
746
    if (/*AccountListItemsViewModel::instance->_selectedItem->_account->_isSelected ==*/ (bool)value == true)
747
748
749
750
751
752
753
754
755
756
757
758
        return Windows::UI::Xaml::Visibility::Visible;

    return Windows::UI::Xaml::Visibility::Collapsed;
}

Object ^ RingClientUWP::Views::AccountSelectedToVisibility::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::AccountSelectedToVisibility::AccountSelectedToVisibility()
{}
759
760
761
762
763
764
765


void RingClientUWP::Views::SmartPanel::_editAccountMenuButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
    _aliasTextBoxEditionMenu_->Text = account->name_;
    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
766
767
    _deleteAccountBtnEditionMenu_->IsChecked = false;
    _deleteAccountBtnEditionMenu_->IsEnabled = (AccountListItemsViewModel::instance->itemsList->Size > 1)? true : false;
768
    _createAccountYes_->IsEnabled = false;
769
770
771
772
773
774
775
776
777
778
    _sipAccountStackEditionMenu_->Visibility = (account->accountType_ == "SIP")
            ? Windows::UI::Xaml::Visibility::Visible
            :Windows::UI::Xaml::Visibility::Collapsed;
    _upnpStackEditionMenu_->Visibility = (account->accountType_ == "RING")
                                         ? Windows::UI::Xaml::Visibility::Visible
                                         : Windows::UI::Xaml::Visibility::Collapsed;
    _sipHostnameEditionMenu_->Text = account->_sipHostname;
    _sipUsernameEditionTextBox_->Text = account->_sipUsername;
    _sipPasswordEditionMenu_->Password = account->_sipPassword;

779
780
781
782
783
784
785
786
787
}


void RingClientUWP::Views::SmartPanel::_acceptAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
    auto accountId = account->accountID_;


788
789
790
    // mettre ca en visibility du bouton delete
    auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size;

791
    /* if the delete button is toggled, just delete the account */
792
    if ( _deleteAccountBtnEditionMenu_->IsChecked->Value == true && accountsListSize > 1) {
793
794
795
796
        AccountListItem^ item;
        for each (item in AccountListItemsViewModel::instance->itemsList)
            if (item->_account->accountID_ == accountId)
                break;
797

798
799
        if (item)
            AccountListItemsViewModel::instance->removeItem(item);
800

801
        RingD::instance->deleteAccount(accountId);
802

803
    } else { /* otherwise edit the account */
804
805
806
807
808
809

        account->name_ = _aliasTextBoxEditionMenu_->Text;
        account->_upnpState = _upnpState_->IsOn;

        RingD::instance->updateAccount(accountId);
    }
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825

    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
}


void RingClientUWP::Views::SmartPanel::_cancelAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}


void RingClientUWP::Views::SmartPanel::OnaccountUpdated(RingClientUWP::Account ^account)
{
    updatePageContent();
826
827
828
829
}

void RingClientUWP::Views::SmartPanel::_passwordBoxAccountCreationCheck__PasswordChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
830
831
832
    _createAccountYes_->IsEnabled = (_ringPasswordBoxAccountCreation_->Password
                                     == _ringPasswordBoxAccountCreationCheck_->Password
                                     && _ringPasswordBoxAccountCreation_->Password->Length() > 0)
833
834
                                    ? true : false;
}
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890


void RingClientUWP::Views::SmartPanel::_accountTypeComboBox__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
    auto accountTypeComboBox = dynamic_cast<ComboBox^>(sender);

    /* avoid exception at start */
    if (_ringAccountCreationStack_ == nullptr && _sipAccountCreationStack_ == nullptr)
        return;

    /* empty everything, avoid to keep credentials in memory... */
    _ringPasswordBoxAccountCreation_->Password = "";
    _ringPasswordBoxAccountCreationCheck_->Password = "";
    _sipPasswordBoxAccountCreation_->Password = "";
    _sipUsernameTextBox_->Text = "";
    _sipHostnameTextBox_->Text = "";

    if (accountTypeComboBox->SelectedIndex == 0 /* RING type is selected */) {
        _ringAccountCreationStack_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _sipAccountCreationStack_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _createAccountYes_->IsEnabled = false;
        _upnpStateAccountCreation_->IsOn = true;
    } else { /* SIP type is selected */
        _ringAccountCreationStack_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _sipAccountCreationStack_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _createAccountYes_->IsEnabled = (_ringAliasTextBox_->Text->IsEmpty()) ? false : true;
    }
}




void RingClientUWP::Views::SmartPanel::_ringAliasTextBox__TextChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::TextChangedEventArgs^ e)
{
    _createAccountYes_->IsEnabled = (_ringAliasTextBox_->Text->IsEmpty()
                                     || (_accountTypeComboBox_->SelectedIndex == 0 /* RING type is selected */
                                         && _ringPasswordBoxAccountCreation_->Password->Length() < 1))
                                    ? false : true;
}

Object ^ RingClientUWP::Views::CollapseEmptyString::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    auto stringValue = dynamic_cast<String^>(value);

    return (stringValue->IsEmpty())
           ? Windows::UI::Xaml::Visibility::Collapsed
           : Windows::UI::Xaml::Visibility::Visible;
}

Object ^ RingClientUWP::Views::CollapseEmptyString::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
    throw ref new Platform::NotImplementedException();
}

RingClientUWP::Views::CollapseEmptyString::CollapseEmptyString()
{}
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912


void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    _photoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _shaderPhotoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}


void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ 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^ photoFile)
    {
        if (photoFile != nullptr) {
            auto brush = ref new ImageBrush();

            auto circle = ref new Ellipse();
913
            circle->Height = 80;
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
            circle->Width = 80;
            auto path = photoFile->Path;
            auto uri = ref new Windows::Foundation::Uri(path);
            auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
            bitmapImage->UriSource = uri;

            StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
            String^ profilefolder = ".profile";
            create_task(localfolder->CreateFolderAsync(profilefolder,
                        Windows::Storage::CreationCollisionOption::OpenIfExists))
            .then([=](StorageFolder^ copytofolder) {
                try {
                    create_task(photoFile->CopyAsync(copytofolder))
                    .then([=](StorageFile^ copiedfile) {
                        copiedfile->RenameAsync("profile_image.png",
                                                Windows::Storage::NameCollisionOption::ReplaceExisting);
                    });
                }
                catch (Exception^ e) {
                    RingDebug::instance->print("Exception while saving profile image");
                }
            });

            Configuration::UserPreferences::instance->PREF_PROFILE_PHOTO = true;

            Configuration::UserPreferences::instance->save();

            brush->ImageSource = bitmapImage;
            _selectedAccountAvatar_->ImageSource = bitmapImage;
        }
    });
}


void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    _photoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _shaderPhotoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970


void RingClientUWP::Views::SmartPanel::_smartList__PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{

}


void RingClientUWP::Views::SmartPanel::Grid_PointerMoved(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    auto grid = dynamic_cast<Grid^>(sender);
    auto item = dynamic_cast<SmartPanelItem^>(grid->DataContext);

    for (auto it : SmartPanelItemsViewModel::instance->itemsList)
        it->_hovered = Windows::UI::Xaml::Visibility::Collapsed;

    item->_hovered = Windows::UI::Xaml::Visibility::Visible;
}
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000

// VIDEO

void
SmartPanel::_videoDeviceComboBox__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^)
{
    if (_videoDeviceComboBox_->Items->Size) {
        Video::VideoCaptureManager^ vcm = Video::VideoManager::instance->captureManager();
        auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);
        auto deviceId = static_cast<String^>(selectedItem->Tag);
        std::vector<int>::size_type index;
        for(index = 0; index != vcm->deviceList->Size; index++) {
            auto dev =  vcm->deviceList->GetAt(index);
            if (dev->id() == deviceId) {
                break;
            }
        }
        vcm->activeDevice = vcm->deviceList->GetAt(index);

        populateVideoResolutionSettingsComboBox();
    }
}

void
SmartPanel::_videoResolutionComboBox__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^)
{
    if (_videoResolutionComboBox_->Items->Size) {
        Video::VideoCaptureManager^ vcm = Video::VideoManager::instance->captureManager();
        auto device = vcm->activeDevice;
        auto selectedItem = static_cast<ComboBoxItem^>(static_cast<ComboBox^>(sender)->SelectedItem);