SmartPanel.xaml.cpp 58.5 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
#include "qrencode.h"
atraczyk's avatar
atraczyk committed
24
#include "lodepng.h"
25
#include <MemoryBuffer.h>   // IMemoryBufferByteAccess
Nicolas Jager's avatar
Nicolas Jager committed
26
27
28
29

using namespace Platform;

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

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

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
71
72
73
        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
74
    });
75
76
77
78
79
80
    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
81
82
83
84
    AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() {
        _accountsListScrollView_->UpdateLayout();
        _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);
    });
85
86
87
    RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
    String^ accountId, String^ callId, String^ from) {
        ///auto from = call->from;
88
89
90
91
92
93
94
95
96
97
        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;
        }

98
99
        contact->_accountIdAssociated = accountId;

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

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

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

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

113
        item->_callStatus = state;
114

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

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


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

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

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

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

158
159
160
    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
161

Nicolas Jager's avatar
Nicolas Jager committed
162
163
    Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
    Configuration::UserPreferences::instance->save();
Nicolas Jager's avatar
Nicolas Jager committed
164

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

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

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

    _upnpState_->IsOn = accountListItem->_account->_upnpState;
Nicolas Jager's avatar
Nicolas Jager committed
179
180
181
182
183
184
185
186
187
188

    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
189
190
}

191
192
193
194
195
void RingClientUWP::Views::SmartPanel::unselectContact()
{
    _smartList_->SelectedItem = nullptr;
}

Nicolas Jager's avatar
Nicolas Jager committed
196
197
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
198
199
    _settingsMenu__Unchecked(nullptr,nullptr);
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
200
    _shareMenuButton_->IsChecked = false;
201
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
202
203
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
204
205
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
206
207
208
209
210
211
}

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
212
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
213
214
}

215
void RingClientUWP::Views::SmartPanel::_settingsMenu__Checked(Object^ sender, RoutedEventArgs^ e)
Nicolas Jager's avatar
Nicolas Jager committed
216
{
217
218
219
220
221
222
    _accountsMenuButton__Unchecked(nullptr,nullptr);
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton__Unchecked(nullptr,nullptr);
    _shareMenuButton_->IsChecked = false;
    _devicesMenuButton__Unchecked(nullptr,nullptr);
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
223
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
224
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Visible;
225
    auto vcm = Video::VideoManager::instance->captureManager();
atraczyk's avatar
atraczyk committed
226
227
228
229
230
231
    if (vcm->deviceList->Size > 0) {
        if (!vcm->isInitialized)
            vcm->InitializeCameraAsync(true);
        else
            vcm->StartPreviewAsync(true);
    }
232
    summonPreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
233
234
}

235
void RingClientUWP::Views::SmartPanel::_settingsMenu__Unchecked(Object^ sender, RoutedEventArgs^ e)
Nicolas Jager's avatar
Nicolas Jager committed
236
{
237
    _settingsMenu_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
238
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
atraczyk's avatar
atraczyk committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
    auto vcm = Video::VideoManager::instance->captureManager();
    if (vcm->deviceList->Size > 0) {
        vcm->StopPreviewAsync()
            .then([](task<void> stopPreviewTask)
        {
            try {
                stopPreviewTask.get();
                Video::VideoManager::instance->captureManager()->isSettingsPreviewing = false;
            }
            catch (Exception^ e) {
                WriteException(e);
            }
        });
    }
253
    hidePreviewPage();
Nicolas Jager's avatar
Nicolas Jager committed
254
255
256
257
258
259
}

void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
{
    if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
        _rowRingTxtBx_->Height = 40;
260
        _selectedAccountAvatarContainer_->Height = 80;
261
        _shaderPhotoboothIcon_->Height = 80;
Nicolas Jager's avatar
Nicolas Jager committed
262
263
264
265
266
        _selectedAccountAvatarColumn_->Width = 90;
        _selectedAccountRow_->Height = 90;
    }
    else {
        _rowRingTxtBx_->Height = 0;
267
        _selectedAccountAvatarContainer_->Height = 50;
268
        _shaderPhotoboothIcon_->Height = 50;
Nicolas Jager's avatar
Nicolas Jager committed
269
270
271
272
        _selectedAccountAvatarColumn_->Width = 60;
        _selectedAccountRow_->Height = 60;
    }

273
    _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height;
274
    _shaderPhotoboothIcon_->Width = _shaderPhotoboothIcon_->Height;
275
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
276
277
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
278
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
279
280
281
282
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
283
284
    _settingsMenu__Unchecked(nullptr,nullptr);
    _settingsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
285
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
286
287
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
288
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
289
290
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
291
    _accountsMenuButton_->IsChecked = false;
292
    _devicesMenuButton_->IsChecked = false;
293
294

    generateQRcode();
Nicolas Jager's avatar
Nicolas Jager committed
295
296
297
298
299
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
300
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
301
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
302
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
303
304
305
306
307
308
}

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

310
    _createAccountYes_->IsEnabled = false;
311
312
313

    _accountTypeComboBox_->SelectedIndex = 0;
    _upnpStateAccountCreation_->IsOn = true;
Nicolas Jager's avatar
Nicolas Jager committed
314
315
316
    _RegisterStateEdition_->IsOn = true;
    _accountAliasTextBox_->Text = "";
    _usernameTextBox_->Text = "";
Nicolas Jager's avatar
Nicolas Jager committed
317
318
319
320
}

void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
321
322
    switch (_accountTypeComboBox_->SelectedIndex) {
    case 0: /* RING account */
323
    {
Nicolas Jager's avatar
Nicolas Jager committed
324
325
326
327
328
        RingD::instance->createRINGAccount(_accountAliasTextBox_->Text
                                           , _ringPasswordBoxAccountCreation_->Password
                                           , _upnpStateAccountCreation_->IsOn
                                           , (_RegisterState_->IsOn) ? _usernameTextBox_->Text : "");

329
330
        _ringPasswordBoxAccountCreation_->Password = "";
        _ringPasswordBoxAccountCreationCheck_->Password = "";
Nicolas Jager's avatar
Nicolas Jager committed
331
        _usernameTextBox_->Text = "";
atraczyk's avatar
atraczyk committed
332
        break;
333
334
    }
    break;
335
    case 1: /* SIP account */
336
    {
Nicolas Jager's avatar
Nicolas Jager committed
337
        RingD::instance->createSIPAccount(_accountAliasTextBox_->Text, _sipPasswordBoxAccountCreation_->Password, _sipHostnameTextBox_->Text, _sipUsernameTextBox_->Text);
338
339
340
        _sipPasswordBoxAccountCreation_->Password = "";
        _sipUsernameTextBox_->Text = "";
        _sipHostnameTextBox_->Text = "";
341
342
343
344
        break;
    }
    default:
        break;
atraczyk's avatar
atraczyk committed
345
    }
346
347
348
349

    _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
350
351
352
353
354
}


void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
355
356
    _accountsMenuButton_->IsChecked = false;
    _accountsMenuButton__Unchecked(nullptr,nullptr);
Nicolas Jager's avatar
Nicolas Jager committed
357
358
359
360
361
}

void
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
362
363
364
365
366
367
368
369
    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
370

371
372
    auto contact = item->_contact;

373
374
375
376
    if (item->_callStatus == CallStatus::IN_PROGRESS) {
        if (contact) {
            contact->_unreadMessages = 0;
            ContactsViewModel::instance->saveContactsToFile();
Nicolas Jager's avatar
Nicolas Jager committed
377
        }
378
379
380

        summonVideoPage();
        return;
Nicolas Jager's avatar
Nicolas Jager committed
381
    }
Nicolas Jager's avatar
Nicolas Jager committed
382

Nicolas Jager's avatar
Nicolas Jager committed
383
384
385
386
387
388
    if (contact) {
        summonMessageTextPage();
        contact->_unreadMessages = 0;
        ContactsViewModel::instance->saveContactsToFile();
        return;
    }
Nicolas Jager's avatar
Nicolas Jager committed
389
390
391
392
393
394
}

void
SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
    auto listbox = safe_cast<ListBox^>(sender);
395
396
397
398
399
400
401
402
403
404
405
406
407
408
    // 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
409
410
    auto account = safe_cast<AccountListItem^>(listbox->SelectedItem);
    AccountListItemsViewModel::instance->_selectedItem = account;
411

Nicolas Jager's avatar
Nicolas Jager committed
412
413
414
415
416
417
    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 */
418
    if (e->Key == Windows::System::VirtualKey::Enter && !_ringTxtBx_->Text->IsEmpty()) {
Nicolas Jager's avatar
Nicolas Jager committed
419
420
421
422
        ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
        _ringTxtBx_->Text = "";
    }
}
423

424
425
426
427
428
429
void RingClientUWP::Views::SmartPanel::_ringTxtBx__Click(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
    _ringTxtBx_->Text = "";
}

430
431
void
RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
432
433
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
434
435
436
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
437
438
            auto callId = item->_callId;
            RingD::instance->refuseIncommingCall(callId);
439
440
        }
    }
441
442
}

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

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

464
465
466
467
468
469
470
        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
471
472
473
474
475
}

void RingClientUWP::Views::SmartPanel::_cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
476
477
478
479
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            RingD::instance->cancelOutGoingCall2(item->_callId);
480
            item->_callStatus = CallStatus::TERMINATING;
481
482
483
            return;
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
484
485
486
487
488
489
490
}

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

491
492
493
494
    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
495
496
497
498
499
500
501
502
}


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

503
504
    for each (auto it in SmartPanelItemsViewModel::instance->itemsList)
        item->_hovered = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
505
506
507
508
509
510
511
512
513
514
515
516
517
}


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
518
519
}

520
521
void RingClientUWP::Views::SmartPanel::generateQRcode()
{
Nicolas Jager's avatar
Nicolas Jager committed
522
    auto ringId = AccountListItemsViewModel::instance->_selectedItem->_account->ringID_;
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
555
556
557
558
559
560
561
562
563
564
565
    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++) {
566
567
                int x = static_cast<int>((float)u / (float)widthBitmap * (float)widthQrCode);
                int y = static_cast<int>((float)v / (float)widthBitmap * (float)widthQrCode);
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

                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
589
590
591
592
593
594
595
596
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
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
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;

        bool isUsernameValid = (_usernameValid_->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 (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;
        }


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

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

710
    if (state == CallStatus::INCOMING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
        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);

729
    if (state == CallStatus::SEARCHING || state == CallStatus::OUTGOING_RINGING)
Nicolas Jager's avatar
Nicolas Jager committed
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
        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);

747
    if (state == CallStatus::NONE || state == CallStatus::ENDED)
Nicolas Jager's avatar
Nicolas Jager committed
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
        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()
{}
778
779
780
781

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

788
789
790
791
792
}


void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
793
794
795
    _settingsMenu__Unchecked(nullptr,nullptr);
    _settingsMenuButton_->IsChecked = false;

Nicolas Jager's avatar
Nicolas Jager committed
796
797
798
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

Nicolas Jager's avatar
Nicolas Jager committed
799
    auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
Nicolas Jager's avatar
Nicolas Jager committed
800
801
    RingD::instance->askToRefreshKnownDevices(accountId);

802
803
804
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
805
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
806
807
808
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
809
810
811
812
813
}


void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
814
815
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
816
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
817
818
819
820
821
}


void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
Nicolas Jager's avatar
Nicolas Jager committed
822
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
823
    AccountListItemsViewModel::instance->_selectedItem->_account->_devicesIdList = devicesList;
824
    _devicesIdList_->ItemsSource = devicesList;
Nicolas Jager's avatar
Nicolas Jager committed
825
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
826
827
828
829
830
831
832
833
}


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
834
    auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
835
    auto password = _passwordForPinGenerator_->Password;
Nicolas Jager's avatar
Nicolas Jager committed
836
837
838
839
    _passwordForPinGenerator_->Password = "";

    /* hide the button while we are waiting... */
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
840
841
842
843
844
845
846
847
848

    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
849
    _passwordForPinGenerator_->Password = "";
850
}
851

852
853
854
855

void RingClientUWP::Views::SmartPanel::OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin)
{
    _waitingAndResult_->Text = pin;
Nicolas Jager's avatar
Nicolas Jager committed
856
857
858
859
860
861
862
863
864
865
866
867
    _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...";
868
}
869
870
871
872
873
874
875
876


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

    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899

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
900
    if (/*AccountListItemsViewModel::instance->_selectedItem->_account->_isSelected ==*/ (bool)value == true)
901
902
903
904
905
906
907
908
909
910
911
912
        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()
{}
913
914
915
916
917


void RingClientUWP::Views::SmartPanel::_editAccountMenuButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
Nicolas Jager's avatar
Nicolas Jager committed
918
919
920
921
922
923
924

    auto volatileAccountDetails = RingD::instance->getVolatileAccountDetails(account);

    _accountAliasTextBoxEdition_->Text = account->name_;
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _deleteAccountEdition_->IsOn = false;
    _deleteAccountEdition_->IsEnabled = (AccountListItemsViewModel::instance->itemsList->Size > 1)? true : false;
925
    _createAccountYes_->IsEnabled = false;
Nicolas Jager's avatar
Nicolas Jager committed
926
927
928
929
930
931
932
933
934
935
936

    _whatWilHappendeleteRingAccountEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _whatWilHappendeleteSipAccountEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

    _sipAccountStackEdition_->Visibility = (account->accountType_ == "SIP")
                                           ? Windows::UI::Xaml::Visibility::Visible
                                           :Windows::UI::Xaml::Visibility::Collapsed;
    _ringStackEdition_->Visibility = (account->accountType_ == "RING")
                                     ? Windows::UI::Xaml::Visibility::Visible
                                     : Windows::UI::Xaml::Visibility::Collapsed;
    _sipHostnameEdition_->Text = account->_sipHostname;
937
    _sipUsernameEditionTextBox_->Text = account->_sipUsername;
Nicolas Jager's avatar
Nicolas Jager committed
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
    _sipPasswordEdition_->Password = account->_sipPassword;

    auto registeredName = Utils::toPlatformString(RingD::instance->registeredName(account));

    if (registeredName) {
        _RegisterStateEdition_->IsOn = true; // keep this before _usernameTextBoxEdition_

        _usernameTextBoxEdition_->IsEnabled = false;
        _usernameTextBoxEdition_->Text = registeredName;
        _RegisterStateEdition_->IsEnabled = false;

        //_registerOnBlockchainEdition_->IsEnabled = false;
        _whatWilHappenEdition_->Text = "You are already registered.";
        _usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    } else {
        _RegisterStateEdition_->IsOn = false;

        _usernameTextBoxEdition_->IsEnabled = false;
        _usernameTextBoxEdition_->Text = "";
        _RegisterStateEdition_->IsEnabled = true;

        //_registerOnBlockchainEdition_->IsEnabled = false;
        _whatWilHappenEdition_->Text = "You are not yet registered.";
        _usernameInvalidEdition_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    }
963

Nicolas Jager's avatar
Nicolas Jager committed
964
    checkStateEditionMenu();
965
966
967
968
969
970
971
972
973
}


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


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

977
    /* if the delete button is toggled, just delete the account */
Nicolas Jager's avatar
Nicolas Jager committed
978
    if (_deleteAccountEdition_->IsOn == true && accountsListSize > 1) {
979
980
981
982
        AccountListItem^ item;
        for each (item in AccountListItemsViewModel::instance->itemsList)
            if (item->_account->accountID_ == accountId)
                break;
983

984
985
        if (item)
            AccountListItemsViewModel::instance->removeItem(item);
986

987
        RingD::instance->deleteAccount(accountId);
988

989
    } else { /* otherwise edit the account */
990

Nicolas Jager's avatar
Nicolas Jager committed
991
        account->name_ = _accountAliasTextBox_->Text;
992
993
994
995
        account->_upnpState = _upnpState_->IsOn;

        RingD::instance->updateAccount(accountId);
    }
996

Nicolas Jager's avatar
Nicolas Jager committed
997
    _accountEditionGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
998
999
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
1000