SmartPanel.xaml.cpp 70.7 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"
atraczyk's avatar
atraczyk committed
20
21
#include <string>
#include <direct.h>
Nicolas Jager's avatar
Nicolas Jager committed
22
#include "SmartPanel.xaml.h"
23
24
#include "qrencode.h"
#include <MemoryBuffer.h>   // IMemoryBufferByteAccess
Nicolas Jager's avatar
Nicolas Jager committed
25
26
27
28

using namespace Platform;

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

46
47
48
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage;
using namespace Windows::UI::Core;
49
using namespace Windows::System::Threading;
50

Nicolas Jager's avatar
Nicolas Jager committed
51
52
53
54
SmartPanel::SmartPanel()
{
    InitializeComponent();

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

    /* populate the smartlist */
59
    _smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;
60

Nicolas Jager's avatar
Nicolas Jager committed
61
62
63
64

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

65
    /* connect delegates */
Nicolas Jager's avatar
Nicolas Jager committed
66
    Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
67
68
69
70
        if (_accountsList_) {
            auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size;
            if (accountsListSize > index)
                _accountsList_->SelectedIndex = index;
71
72
73
74
            else {
                if (accountsListSize > 0)
                    _accountsList_->SelectedIndex = 0;
            }
75
        }
Nicolas Jager's avatar
Nicolas Jager committed
76
    });
77
78
79
80
81
    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
82
    });
83
    ContactsViewModel::instance->contactDataModified += ref new ContactDataModified([this](Contact^ contact) {
84
    });
atraczyk's avatar
atraczyk committed
85
86
87
88
    AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() {
        _accountsListScrollView_->UpdateLayout();
        _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);
    });
89
90
91
    RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
    String^ accountId, String^ callId, String^ from) {
        ///auto from = call->from;
Nicolas Jager's avatar
Nicolas Jager committed
92
        auto contact = ContactsViewModel::instance->findContactByRingId(from);
93
94
95
96
97
98
99
100
101

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

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

102
103
        contact->_accountIdAssociated = accountId;

104
        auto item = SmartPanelItemsViewModel::instance->findItem(contact);
105
        item->_callId = callId;
Nicolas Jager's avatar
Nicolas Jager committed
106

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

110
        auto item = SmartPanelItemsViewModel::instance->findItem(callId);
111
112
113
114
115
116

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

117
        item->_callStatus = state;
118

119
120
        switch (state) {
        case CallStatus::NONE:
121
        case CallStatus::ENDED:
122
        {
atraczyk's avatar
atraczyk committed
123
124
125
126
127
128
129
130
131
132
133
            bool isInCall = false;
            for (auto item : SmartPanelItemsViewModel::instance->itemsList) {
                if (item->_callId && item->_callStatus == CallStatus::IN_PROGRESS) {
                    isInCall = true;
                    RingD::instance->currentCallId = item->_callId;
                    break;
                }
            }
            if (!isInCall)
                _settingsMenuButton_->Visibility = VIS::Visible;

134
135
136
137
138
139
140
141
142
            item->_callId = "";
            break;
        }
        case CallStatus::IN_PROGRESS:
        {
            _smartList_->SelectedItem = item;
            summonVideoPage();
            break;
        }
143
144
145
146
147
148
149
        case CallStatus::PEER_PAUSED:
        case CallStatus::PAUSED:
        {
            _smartList_->SelectedItem = item;
            summonVideoPage();
            break;
        }
150
151
152
        default:
            break;
        }
153
154

    });
155
    RingD::instance->devicesListRefreshed += ref new RingClientUWP::DevicesListRefreshed(this, &RingClientUWP::Views::SmartPanel::OndevicesListRefreshed);
156
157
158
159

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

163
    RingD::instance->exportOnRingEnded += ref new RingClientUWP::ExportOnRingEnded(this, &RingClientUWP::Views::SmartPanel::OnexportOnRingEnded);
164
    RingD::instance->accountUpdated += ref new RingClientUWP::AccountUpdated(this, &RingClientUWP::Views::SmartPanel::OnaccountUpdated);
Nicolas Jager's avatar
Nicolas Jager committed
165
    RingD::instance->registeredNameFound += ref new RingClientUWP::RegisteredNameFound(this, &RingClientUWP::Views::SmartPanel::OnregisteredNameFound);
Nicolas Jager's avatar
Nicolas Jager committed
166

167
168
169
    RingD::instance->finishCaptureDeviceEnumeration += ref new RingClientUWP::FinishCaptureDeviceEnumeration([this]() {
        populateVideoDeviceSettingsComboBox();
    });
170
171
    RingD::instance->registrationStateErrorGeneric += ref new RingClientUWP::RegistrationStateErrorGeneric(this, &RingClientUWP::Views::SmartPanel::OnregistrationStateErrorGeneric);
    RingD::instance->registrationStateRegistered += ref new RingClientUWP::RegistrationStateRegistered(this, &RingClientUWP::Views::SmartPanel::OnregistrationStateRegistered);
172
    RingD::instance->callPlaced += ref new RingClientUWP::CallPlaced(this, &RingClientUWP::Views::SmartPanel::OncallPlaced);
Nicolas Jager's avatar
Nicolas Jager committed
173
174
175
176
177
}

void
RingClientUWP::Views::SmartPanel::updatePageContent()
{
Nicolas Jager's avatar
Nicolas Jager committed
178
179
    auto accountListItem = AccountListItemsViewModel::instance->_selectedItem;
    if (!accountListItem)
Nicolas Jager's avatar
Nicolas Jager committed
180
181
        return;

182
183
184
    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
185

Nicolas Jager's avatar
Nicolas Jager committed
186
187
    Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
    Configuration::UserPreferences::instance->save();
Nicolas Jager's avatar
Nicolas Jager committed
188

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

Nicolas Jager's avatar
Nicolas Jager committed
194
    _devicesMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
195
196
                                      ? Windows::UI::Xaml::Visibility::Visible
                                      : Windows::UI::Xaml::Visibility::Collapsed;
197

Nicolas Jager's avatar
Nicolas Jager committed
198
    _shareMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
199
200
                                    ? Windows::UI::Xaml::Visibility::Visible
                                    : Windows::UI::Xaml::Visibility::Collapsed;
201
202

    _upnpState_->IsOn = accountListItem->_account->_upnpState;
Nicolas Jager's avatar
Nicolas Jager committed
203
204
205
206
207
208
209
210
211
212

    if (_upnpState_->IsOn) {
        _usernameTextBoxEdition_->IsEnabled = true;
        _usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;

    } else {
        _usernameTextBoxEdition_->IsEnabled = false;
        _usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    }

Nicolas Jager's avatar
Nicolas Jager committed
213
214
}

215
216
217
218
219
void RingClientUWP::Views::SmartPanel::unselectContact()
{
    _smartList_->SelectedItem = nullptr;
}

atraczyk's avatar
atraczyk committed
220
221
222
223
224
225
226
227
228
229
230
231
232
233
void RingClientUWP::Views::SmartPanel::_smartGridButton__Clicked(Object^ sender, RoutedEventArgs^ e)
{
    _accountsMenuButton__Unchecked(nullptr,nullptr);
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton__Unchecked(nullptr,nullptr);
    _shareMenuButton_->IsChecked = false;
    _devicesMenuButton__Unchecked(nullptr,nullptr);
    _devicesMenuButton_->IsChecked = false;
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _settingsMenuButton_->IsChecked = false;

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}

Nicolas Jager's avatar
Nicolas Jager committed
234
235
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
236
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
237
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
238
    _shareMenuButton_->IsChecked = false;
239
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
240
241
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
242
243
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk's avatar
atraczyk committed
244
245

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
246
247
248
249
250
251
}

void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e)
{
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
252
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
253
    _accountAddMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk's avatar
atraczyk committed
254
255

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
256
257
}

258
void RingClientUWP::Views::SmartPanel::_settingsMenu__Checked(Object^ sender, RoutedEventArgs^ e)
Nicolas Jager's avatar
Nicolas Jager committed
259
{
260
261
262
263
264
265
266
    _accountsMenuButton__Unchecked(nullptr,nullptr);
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton__Unchecked(nullptr,nullptr);
    _shareMenuButton_->IsChecked = false;
    _devicesMenuButton__Unchecked(nullptr,nullptr);
    _devicesMenuButton_->IsChecked = false;
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Visible;
atraczyk's avatar
atraczyk committed
267
268
269

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

270
    auto vcm = Video::VideoManager::instance->captureManager();
atraczyk's avatar
atraczyk committed
271
272
273
274
275
276
    if (vcm->deviceList->Size > 0) {
        if (!vcm->isInitialized)
            vcm->InitializeCameraAsync(true);
        else
            vcm->StartPreviewAsync(true);
    }
277
    summonPreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
278
279
}

280
void RingClientUWP::Views::SmartPanel::_settingsMenu__Unchecked(Object^ sender, RoutedEventArgs^ e)
Nicolas Jager's avatar
Nicolas Jager committed
281
{
282
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk's avatar
atraczyk committed
283

Nicolas Jager's avatar
Nicolas Jager committed
284
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
atraczyk's avatar
atraczyk committed
285

atraczyk's avatar
atraczyk committed
286
287
288
    auto vcm = Video::VideoManager::instance->captureManager();
    if (vcm->deviceList->Size > 0) {
        vcm->StopPreviewAsync()
289
        .then([](task<void> stopPreviewTask)
atraczyk's avatar
atraczyk committed
290
291
292
293
294
295
296
297
298
299
        {
            try {
                stopPreviewTask.get();
                Video::VideoManager::instance->captureManager()->isSettingsPreviewing = false;
            }
            catch (Exception^ e) {
                WriteException(e);
            }
        });
    }
300
    hidePreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
301
302
303
304
305
306
}

void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
{
    if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
        _rowRingTxtBx_->Height = 40;
307
        _selectedAccountAvatarContainer_->Height = 80;
308
        _shaderPhotoboothIcon_->Height = 80;
Nicolas Jager's avatar
Nicolas Jager committed
309
310
311
312
313
        _selectedAccountAvatarColumn_->Width = 90;
        _selectedAccountRow_->Height = 90;
    }
    else {
        _rowRingTxtBx_->Height = 0;
314
        _selectedAccountAvatarContainer_->Height = 50;
315
        _shaderPhotoboothIcon_->Height = 50;
Nicolas Jager's avatar
Nicolas Jager committed
316
317
318
319
        _selectedAccountAvatarColumn_->Width = 60;
        _selectedAccountRow_->Height = 60;
    }

320
    _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height;
321
    _shaderPhotoboothIcon_->Width = _shaderPhotoboothIcon_->Height;
322
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
323
324
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
325
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
326
327
328
329
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
330
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
331
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
332
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
333
334
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
335
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
336
337
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
338
    _accountsMenuButton_->IsChecked = false;
339
    _devicesMenuButton_->IsChecked = false;
340

atraczyk's avatar
atraczyk committed
341
342
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

343
    generateQRcode();
Nicolas Jager's avatar
Nicolas Jager committed
344
345
346
347
348
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
349
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
350
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
351
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk's avatar
atraczyk committed
352
353

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
354
355
356
357
358
359
}

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

361
    _createAccountYes_->IsEnabled = false;
362
363
364

    _accountTypeComboBox_->SelectedIndex = 0;
    _upnpStateAccountCreation_->IsOn = true;
Nicolas Jager's avatar
Nicolas Jager committed
365
366
367
    _RegisterStateEdition_->IsOn = true;
    _accountAliasTextBox_->Text = "";
    _usernameTextBox_->Text = "";
Nicolas Jager's avatar
Nicolas Jager committed
368
369

    checkStateAddAccountMenu();
Nicolas Jager's avatar
Nicolas Jager committed
370
371
372
373
}

void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
374
375
    switch (_accountTypeComboBox_->SelectedIndex) {
    case 0: /* RING account */
376
    {
Nicolas Jager's avatar
Nicolas Jager committed
377
378
379
380
381
        RingD::instance->createRINGAccount(_accountAliasTextBox_->Text
                                           , _ringPasswordBoxAccountCreation_->Password
                                           , _upnpStateAccountCreation_->IsOn
                                           , (_RegisterState_->IsOn) ? _usernameTextBox_->Text : "");

382
383
        _ringPasswordBoxAccountCreation_->Password = "";
        _ringPasswordBoxAccountCreationCheck_->Password = "";
Nicolas Jager's avatar
Nicolas Jager committed
384
        _usernameTextBox_->Text = "";
atraczyk's avatar
atraczyk committed
385
        break;
386
387
    }
    break;
388
    case 1: /* SIP account */
389
    {
Nicolas Jager's avatar
Nicolas Jager committed
390
        RingD::instance->createSIPAccount(_accountAliasTextBox_->Text, _sipPasswordBoxAccountCreation_->Password, _sipHostnameTextBox_->Text, _sipUsernameTextBox_->Text);
391
392
393
        _sipPasswordBoxAccountCreation_->Password = "";
        _sipUsernameTextBox_->Text = "";
        _sipHostnameTextBox_->Text = "";
394
395
396
397
        break;
    }
    default:
        break;
atraczyk's avatar
atraczyk committed
398
    }
399
400
401
402

    _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
403
404
405
406
407
}


void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
408
409
    _accountsMenuButton_->IsChecked = false;
    _accountsMenuButton__Unchecked(nullptr,nullptr);
Nicolas Jager's avatar
Nicolas Jager committed
410
411
412
413
414
}

void
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
415
416
417
418
419
420
421
422
    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
423

424
425
    auto contact = item->_contact;

426
427
428
    if (item->_callStatus == CallStatus::IN_PROGRESS
            || item->_callStatus == CallStatus::PAUSED
            || item->_callStatus == CallStatus::PEER_PAUSED) {
429
430
431
        if (contact) {
            contact->_unreadMessages = 0;
            ContactsViewModel::instance->saveContactsToFile();
Nicolas Jager's avatar
Nicolas Jager committed
432
        }
433
434
435

        summonVideoPage();
        return;
Nicolas Jager's avatar
Nicolas Jager committed
436
    }
Nicolas Jager's avatar
Nicolas Jager committed
437

Nicolas Jager's avatar
Nicolas Jager committed
438
439
440
441
442
443
    if (contact) {
        summonMessageTextPage();
        contact->_unreadMessages = 0;
        ContactsViewModel::instance->saveContactsToFile();
        return;
    }
Nicolas Jager's avatar
Nicolas Jager committed
444
445
446
447
448
449
}

void
SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
    auto listbox = safe_cast<ListBox^>(sender);
450
451
452
453
454
455
456
457
458
459
460
461
462
463
    // 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
464
465
    auto account = safe_cast<AccountListItem^>(listbox->SelectedItem);
    AccountListItemsViewModel::instance->_selectedItem = account;
466

Nicolas Jager's avatar
Nicolas Jager committed
467
468
469
470
471
472
    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 */
473
    if (e->Key == Windows::System::VirtualKey::Enter && !_ringTxtBx_->Text->IsEmpty()) {
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
        for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
            if (it->_contact->name_ == _ringTxtBx_->Text) {
                _smartList_->SelectedItem = it;
                _ringTxtBx_->Text = "";
                return;
            }
        }

        /* if the string has 40 chars, we simply consider it as a ring id. It has to be improved */
        if (_ringTxtBx_->Text->Length() == 40) {
            ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
            _ringTxtBx_->Text = "";
        }


        RingD::instance->lookUpName(_ringTxtBx_->Text);
Nicolas Jager's avatar
Nicolas Jager committed
490
491
    }
}
492

493
494
void RingClientUWP::Views::SmartPanel::_ringTxtBx__Click(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
495
    RingD::instance->lookUpName(_ringTxtBx_->Text);
496
497
}

498
499
void
RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
500
501
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
502
503
504
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
505
506
            auto callId = item->_callId;
            RingD::instance->refuseIncommingCall(callId);
507
508
        }
    }
509
510
}

511
512
void
RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
513
514
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
515
516
517
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
518
            auto callId = item->_callId;
519
520
521
522
523

            for (auto it : SmartPanelItemsViewModel::instance->itemsList)
                if (it->_callStatus != CallStatus::IN_PROGRESS)
                    RingD::instance->pauseCall(Utils::toString(it->_callId));

524
            RingD::instance->acceptIncommingCall(callId);
525
526
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
527
528
529
530
531
532
}

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

atraczyk's avatar
atraczyk committed
537
538
        _settingsMenuButton_->Visibility = VIS::Collapsed;

539
540
541
542
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            auto contact = item->_contact;
            if (contact)
543
544
545
546
547
            {
                for (auto it : SmartPanelItemsViewModel::instance->itemsList)
                    if (it->_callStatus == CallStatus::IN_PROGRESS)
                        RingD::instance->pauseCall(Utils::toString(it->_callId));

548
                RingD::instance->placeCall(contact);
549
            }
550
551
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
552
553
554
555
556
}

void RingClientUWP::Views::SmartPanel::_cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
557
558
559
560
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            RingD::instance->cancelOutGoingCall2(item->_callId);
561
            item->_callStatus = CallStatus::TERMINATING;
562
563
564
            return;
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
565
566
567
568
569
570
571
}

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

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

Nicolas Jager's avatar
Nicolas Jager committed
575
576
577
578
579
    /// to keep for future use, when we will be able to do several calls.
    ///if (item->_callStatus == CallStatus::NONE || item->_callStatus == CallStatus::ENDED)
    ///    item->_hovered = Windows::UI::Xaml::Visibility::Visible;

    /// for now use this, do not merge with the for loop above, to make easier to remove that part later
580
    /*bool anyCall = false;
Nicolas Jager's avatar
Nicolas Jager committed
581
582
583
584
585
    for (auto it : SmartPanelItemsViewModel::instance->itemsList) {
        if (it->_callStatus != CallStatus::NONE && it->_callStatus != CallStatus::ENDED)
            anyCall = true;
    }

586
587
    if (anyCall == false)*/
    item->_hovered = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
588
589


Nicolas Jager's avatar
Nicolas Jager committed
590
591
592
593
594
595
596
597
}


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

598
599
    for each (auto it in SmartPanelItemsViewModel::instance->itemsList)
        item->_hovered = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
600
601
602
603
604
605
606
607
608
609
610
611
612
}


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
613
614
}

615
616
void RingClientUWP::Views::SmartPanel::generateQRcode()
{
Nicolas Jager's avatar
Nicolas Jager committed
617
    auto ringId = AccountListItemsViewModel::instance->_selectedItem->_account->ringID_;
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
    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++) {
661
662
                int x = static_cast<int>((float)u / (float)widthBitmap * (float)widthQrCode);
                int y = static_cast<int>((float)v / (float)widthBitmap * (float)widthQrCode);
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683

                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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
void RingClientUWP::Views::SmartPanel::checkStateAddAccountMenu()
{
    bool isRingAccountType = (_accountTypeComboBox_->SelectedIndex == 0) ? true : false;

    bool isAccountAlias = (_accountAliasTextBox_->Text->IsEmpty()) ? false : true;

    if (isAccountAlias) {
        _accountAliasValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _accountAliasInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    } else {
        _accountAliasValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _accountAliasInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    }

    if (isRingAccountType) {
        bool isPublic = _RegisterState_->IsOn;

Nicolas Jager's avatar
Nicolas Jager committed
701
702
        bool isUsernameValid = (_usernameValid_->Visibility == Windows::UI::Xaml::Visibility::Visible
                                && !_usernameTextBox_->Text->IsEmpty()) ? true : false;
Nicolas Jager's avatar
Nicolas Jager committed
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728

        bool isPasswordValid = (_ringPasswordBoxAccountCreation_->Password->IsEmpty()) ? false : true;

        bool isRingPasswordCheck = (_ringPasswordBoxAccountCreation_->Password
                                    == _ringPasswordBoxAccountCreationCheck_->Password
                                    && isPasswordValid)
                                   ? true : false;

        if (isPasswordValid) {
            _passwordValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
            _passwordInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        }
        else {
            _passwordValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
            _passwordInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        }

        if (isRingPasswordCheck) {
            _passwordCheckValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
            _passwordCheckInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        }
        else {
            _passwordCheckValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
            _passwordCheckInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        }

Nicolas Jager's avatar
Nicolas Jager committed
729
730
731
732
733
734
735
        if (isUsernameValid) {
            _usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
            _usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        } else {
            _usernameValid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
            _usernameInvalid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        }
Nicolas Jager's avatar
Nicolas Jager committed
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808

        if (isPublic)
            if (isUsernameValid && isAccountAlias && isRingPasswordCheck && isPasswordValid)
                _createAccountYes_->IsEnabled = true;
            else
                _createAccountYes_->IsEnabled = false;
        else if (isAccountAlias && isRingPasswordCheck && isPasswordValid)
            _createAccountYes_->IsEnabled = true;
        else
            _createAccountYes_->IsEnabled = false;

    } else {
        if (isAccountAlias)
            _createAccountYes_->IsEnabled = true;
        else
            _createAccountYes_->IsEnabled = false;
    }

}

void RingClientUWP::Views::SmartPanel::checkStateEditionMenu()
{
    if (AccountListItemsViewModel::instance->_selectedItem == nullptr)
        return;
    bool isRingAccountType = (AccountListItemsViewModel::instance->_selectedItem->_account->accountType_ == "RING")
                             ? true : false;

    bool isAccountAlias = (_accountAliasTextBoxEdition_->Text->IsEmpty()) ? false : true;

    bool isAlreadyRegistered = (_RegisterStateEdition_->IsEnabled) ? false : true;

    if (isAccountAlias) {
        _accountAliasValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
        _accountAliasInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    }
    else {
        _accountAliasValidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _accountAliasInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    }

    if (isRingAccountType) {
        bool isPublic = _RegisterStateEdition_->IsOn;

        bool isUsernameValid = (_usernameValidEdition_->Visibility == Windows::UI::Xaml::Visibility::Visible)
                               ? true : false;

        bool isPasswordValid = (_ringPasswordBoxAccountCreation_->Password->IsEmpty()) ? false : true;

        bool isRingPasswordCheck = (_ringPasswordBoxAccountCreation_->Password
                                    == _ringPasswordBoxAccountCreationCheck_->Password
                                    && isPasswordValid)
                                   ? true : false;
        if (isPublic)
            if (isUsernameValid && isAccountAlias || isAlreadyRegistered) {
                _acceptAccountModification_->IsEnabled = true;
                //_registerOnBlockchainEdition_->IsEnabled = true;
            } else {
                _acceptAccountModification_->IsEnabled = false;
                //_registerOnBlockchainEdition_->IsEnabled = false;
            }
        else if (isAccountAlias)
            _acceptAccountModification_->IsEnabled = true;
        else
            _acceptAccountModification_->IsEnabled = false;
    }
    else {
        if (isAccountAlias)
            _acceptAccountModification_->IsEnabled = true;
        else
            _acceptAccountModification_->IsEnabled = false;
    }
}

809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
void RingClientUWP::Views::SmartPanel::ringTxtBxPlaceHolderDelay(String^ placeHolderText, int delayInMilliSeconds)
{
    _ringTxtBx_->PlaceholderText = placeHolderText;
    TimeSpan delay;
    delay.Duration = 10000 * delayInMilliSeconds;
    ThreadPoolTimer^ delayTimer = ThreadPoolTimer::CreateTimer(
                                      ref new TimerElapsedHandler([this](ThreadPoolTimer^ source)
    {
        Dispatcher->RunAsync(CoreDispatcherPriority::High,
                             ref new DispatchedHandler([this]()
        {
            _ringTxtBx_->PlaceholderText = "";
        }));
    }), delay);
}

825
826
827
828
829
830
831
832
833
834
void RingClientUWP::Views::SmartPanel::showLinkThisDeviceStep1()
{
    _step1Menu_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _step2Menu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

    _nextstep_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _addAccountYes_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addAccountNo_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}

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

839
    if (state == CallStatus::INCOMING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
        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);

858
    if (state == CallStatus::SEARCHING || state == CallStatus::OUTGOING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
        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);

876
    if (state == CallStatus::NONE || state == CallStatus::ENDED)
Nicolas Jager's avatar
Nicolas Jager committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
        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()
{}
907
908
909
910

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

atraczyk's avatar
atraczyk committed
917
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
918
919
920
921
922
}


void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
923
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
924
925
    _settingsMenuButton_->IsChecked = false;

Nicolas Jager's avatar
Nicolas Jager committed
926
927
928
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

929
930
931
932
933
934
935
936
937
    auto account = AccountListItemsViewModel::instance->_selectedItem->_account;

    _deviceId_->Text = account->_deviceId;
    if (_deviceId_->Text->IsEmpty()) {
        _deviceId_->Text = "No device id found!";
        ERR_("device Id not found for account " + Utils::toString(account->_deviceId));
    }

    RingD::instance->askToRefreshKnownDevices(account->accountID_);
Nicolas Jager's avatar
Nicolas Jager committed
938

939
940
941
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
942
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
943
944
945
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
atraczyk's avatar
atraczyk committed
946
947

    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
948
949
950
951
952
}


void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
953
954
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
955
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
956
957
958
959
960
}


void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
Nicolas Jager's avatar
Nicolas Jager committed
961
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
962
    AccountListItemsViewModel::instance->_selectedItem->_account->_devicesIdList = devicesList;
963
    _devicesIdList_->ItemsSource = devicesList;
Nicolas Jager's avatar
Nicolas Jager committed
964
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
965
966
967
968
969
970
971
972
}


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
973
    auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
974
    auto password = _passwordForPinGenerator_->Password;
Nicolas Jager's avatar
Nicolas Jager committed
975
976
977
978
    _passwordForPinGenerator_->Password = "";

    /* hide the button while we are waiting... */
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
979
980
981
982
983
984
985
986
987

    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
988
    _passwordForPinGenerator_->Password = "";
989
}
990

991
992
993
994

void RingClientUWP::Views::SmartPanel::OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin)
{
    _waitingAndResult_->Text = pin;
Nicolas Jager's avatar
Nicolas Jager committed
995
996
997
998
999
1000
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;

}


void RingClientUWP::Views::SmartPanel::_closePin__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)