SmartPanel.xaml.cpp 22.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"
20
#include <string> // move it
Nicolas Jager's avatar
Nicolas Jager committed
21
22
23
24
25
#include "SmartPanel.xaml.h"

using namespace Platform;

using namespace RingClientUWP;
26
using namespace RingClientUWP::Controls;
Nicolas Jager's avatar
Nicolas Jager committed
27
28
29
30
31
32
33
34
35
36
37
using namespace RingClientUWP::Views;
using namespace RingClientUWP::ViewModel;
using namespace Windows::Media::Capture;
using namespace Windows::UI::Xaml;
using namespace Windows::Storage;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Shapes;
using namespace Windows::UI::Xaml::Media;
using namespace Concurrency;
using namespace Windows::Foundation;

38
39
40
41
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Storage;
using namespace Windows::UI::Core;

Nicolas Jager's avatar
Nicolas Jager committed
42
43
44
45
SmartPanel::SmartPanel()
{
    InitializeComponent();

46
47
48
    _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;

    /* populate the smartlist */
49
    _smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;
50

Nicolas Jager's avatar
Nicolas Jager committed
51
52
53
54

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

55
    /* connect delegates */
Nicolas Jager's avatar
Nicolas Jager committed
56
57
58
    Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
        _accountsList_->SelectedIndex = index;
    });
59
60
61
62
63
64
    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
65
66
67
68
    AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() {
        _accountsListScrollView_->UpdateLayout();
        _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);
    });
69
70
71
    RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
    String^ accountId, String^ callId, String^ from) {
        ///auto from = call->from;
72
73
74
75
76
77
78
79
80
81
        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;
        }

82
        auto item = SmartPanelItemsViewModel::instance->findItem(contact);
83
        item->_callId = callId;
Nicolas Jager's avatar
Nicolas Jager committed
84

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

88
        auto item = SmartPanelItemsViewModel::instance->findItem(callId);
89
90
91
92
93
94

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

95
        item->_callStatus = state;
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
        switch (state) {
        case CallStatus::NONE:
        case CallStatus::ENDED:
        {
            item->_callId = "";
            break;
        }
        case CallStatus::IN_PROGRESS:
        {
            _smartList_->SelectedItem = item;
            summonVideoPage();
            break;
        }
        default:
            break;
        }
113
114

    });
115
    RingD::instance->devicesListRefreshed += ref new RingClientUWP::DevicesListRefreshed(this, &RingClientUWP::Views::SmartPanel::OndevicesListRefreshed);
116
117
118
119
120


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

124
125
    RingD::instance->exportOnRingEnded += ref new RingClientUWP::ExportOnRingEnded(this, &RingClientUWP::Views::SmartPanel::OnexportOnRingEnded);

Nicolas Jager's avatar
Nicolas Jager committed
126
127


Nicolas Jager's avatar
Nicolas Jager committed
128
129
130
131
132
133
134
135
136
}

void
RingClientUWP::Views::SmartPanel::updatePageContent()
{
    auto account = AccountsViewModel::instance->selectedAccount;
    if (!account)
        return;

137
    auto name = account->name_;
Nicolas Jager's avatar
Nicolas Jager committed
138

Nicolas Jager's avatar
Nicolas Jager committed
139
140
    Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
    Configuration::UserPreferences::instance->save();
Nicolas Jager's avatar
Nicolas Jager committed
141

142
    _selectedAccountName_->Text = name;
143
///    _devicesIdList_->ItemsSource = account->_devicesIdList;
Nicolas Jager's avatar
Nicolas Jager committed
144
145
    _deviceId_->Text = account->_deviceId; /* this is the current device ...
    ... in the way to get all associated devices, we have to querry the daemon : */
146
147
148
149

    _devicesMenuButton_->Visibility = (account->accountType_ == "RING")
                                      ? Windows::UI::Xaml::Visibility::Visible
                                      : Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
150
151
152
153
154
}

void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
    _shareMenuButton_->IsChecked = false;
155
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
156
157
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
158
159
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
}

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

void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e)
{
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}

void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e)
{
    _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}

void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode)
{
    if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) {
        _rowRingTxtBx_->Height = 40;
184
        _selectedAccountAvatarContainer_->Height = 80;
Nicolas Jager's avatar
Nicolas Jager committed
185
186
187
188
189
        _selectedAccountAvatarColumn_->Width = 90;
        _selectedAccountRow_->Height = 90;
    }
    else {
        _rowRingTxtBx_->Height = 0;
190
        _selectedAccountAvatarContainer_->Height = 50;
Nicolas Jager's avatar
Nicolas Jager committed
191
192
193
194
        _selectedAccountAvatarColumn_->Width = 60;
        _selectedAccountRow_->Height = 60;
    }

195
    _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height;
Nicolas Jager's avatar
Nicolas Jager committed
196
197
198
199
200
201
202
203
    _settingsTBtn_->IsChecked = false;
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
204
205
206
207
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
208
    _accountsMenuButton_->IsChecked = false;
209
    _devicesMenuButton_->IsChecked = false;
Nicolas Jager's avatar
Nicolas Jager committed
210
211
212
213
214
}

void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
215
216
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
217
218
219
220
221
222
223
224
225
226
}

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

void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
227
228
229
    switch (_accountTypeComboBox_->SelectedIndex)
    {
    case 0:
230
    {
231
232
233
234
235
        CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
        ref new DispatchedHandler([=]() {
            auto frame = dynamic_cast<Windows::UI::Xaml::Controls::Frame^>(Window::Current->Content);
            dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(true, true);
        }));
236
237
238
        RingD::instance->createRINGAccount(_aliasTextBox_->Text);
        _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _accountsMenuButton__Checked(nullptr, nullptr);
atraczyk's avatar
atraczyk committed
239
        break;
240
241
    }
    break;
atraczyk's avatar
atraczyk committed
242
    case 1:
243
244
245
246
247
248
249
250
    {
        RingD::instance->createSIPAccount(_aliasTextBox_->Text);
        _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        _accountsMenuButton__Checked(nullptr, nullptr);
        break;
    }
    default:
        break;
atraczyk's avatar
atraczyk committed
251
    }
252
    _aliasTextBox_->Text = "";
Nicolas Jager's avatar
Nicolas Jager committed
253
254
255
256
257
}


void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
atraczyk's avatar
atraczyk committed
258
259
    _accountsMenuButton_->IsChecked = false;
    _accountsMenuButton__Unchecked(nullptr,nullptr);
Nicolas Jager's avatar
Nicolas Jager committed
260
261
262
263
264
}

void
SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
265
266
267
268
269
270
271
272
    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
273

274
275
    auto contact = item->_contact;

276
277
278
279
    if (item->_callStatus == CallStatus::IN_PROGRESS) {
        if (contact) {
            contact->_unreadMessages = 0;
            ContactsViewModel::instance->saveContactsToFile();
Nicolas Jager's avatar
Nicolas Jager committed
280
        }
281
282
283

        summonVideoPage();
        return;
Nicolas Jager's avatar
Nicolas Jager committed
284
    }
Nicolas Jager's avatar
Nicolas Jager committed
285

Nicolas Jager's avatar
Nicolas Jager committed
286
287
288
289
290
291
    if (contact) {
        summonMessageTextPage();
        contact->_unreadMessages = 0;
        ContactsViewModel::instance->saveContactsToFile();
        return;
    }
Nicolas Jager's avatar
Nicolas Jager committed
292
293
294
295
296
297
}

void
SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
    auto listbox = safe_cast<ListBox^>(sender);
298
299
300
301
302
303
304
305
306
307
308
309
310
311
    // 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
312
313
314
315
316
317
318
319
    auto account = safe_cast<Account^>(listbox->SelectedItem);
    AccountsViewModel::instance->selectedAccount = account;
    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 */
320
    if (e->Key == Windows::System::VirtualKey::Enter && !_ringTxtBx_->Text->IsEmpty()) {
Nicolas Jager's avatar
Nicolas Jager committed
321
322
323
324
        ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
        _ringTxtBx_->Text = "";
    }
}
325

326
327
328
329
330
331
void RingClientUWP::Views::SmartPanel::_ringTxtBx__Click(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text);
    _ringTxtBx_->Text = "";
}

332
333
void
RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
334
335
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
336
337
338
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
339
340
            auto callId = item->_callId;
            RingD::instance->refuseIncommingCall(callId);
341
342
        }
    }
343
344
}

345
346
void
RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
347
348
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
349
350
351
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
352
353
            auto callId = item->_callId;
            RingD::instance->acceptIncommingCall(callId);
354
355
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
356
357
358
359
360
361
}

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

366
367
368
369
370
371
372
        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
373
374
375
376
377
}

void RingClientUWP::Views::SmartPanel::_cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    auto button = dynamic_cast<Button^>(e->OriginalSource);
378
379
380
381
    if (button) {
        auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
        if (item) {
            RingD::instance->cancelOutGoingCall2(item->_callId);
382
            item->_callStatus = CallStatus::TERMINATING;
383
384
385
            return;
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
386
387
388
389
390
391
392
393
}

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

394
395
    if (item->_callId->IsEmpty())
        item->_hovered = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
396
397
398
399
400
401
402
403
404
}


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

Nicolas Jager's avatar
Nicolas Jager committed
405
    item->_hovered = Windows::UI::Xaml::Visibility::Collapsed;
Nicolas Jager's avatar
Nicolas Jager committed
406
407
408
409
410
411
412
413
414
415
416
417
418
}


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
419
420
421
422
423
}

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

Nicolas Jager's avatar
Nicolas Jager committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
    if (state == CallStatus::INCOMING_RINGING)
        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);

    if (state == CallStatus::SEARCHING || state == CallStatus::OUTGOING_RINGING)
        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);

    if (state == CallStatus::NONE || state == CallStatus::ENDED)
        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()
{}
493
494
495
496

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

503
504
505
506
507
}


void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Nicolas Jager's avatar
Nicolas Jager committed
508
509
510
511
512
513
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;

    auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
    RingD::instance->askToRefreshKnownDevices(accountId);

514
515
516
    _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
517
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
518
519
520
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _accountsMenuButton_->IsChecked = false;
    _shareMenuButton_->IsChecked = false;
521
522
523
524
525
}


void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
526
527
    _devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    _addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
Nicolas Jager's avatar
Nicolas Jager committed
528
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
529
530
531
532
533
}


void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
Nicolas Jager's avatar
Nicolas Jager committed
534
    _waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
535
536
    AccountsViewModel::instance->selectedAccount->_devicesIdList = devicesList;
    _devicesIdList_->ItemsSource = devicesList;
Nicolas Jager's avatar
Nicolas Jager committed
537
    _devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
538
539
540
541
542
543
544
545
546
547
}


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;

    auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
    auto password = _passwordForPinGenerator_->Password;
Nicolas Jager's avatar
Nicolas Jager committed
548
549
550
551
    _passwordForPinGenerator_->Password = "";

    /* hide the button while we are waiting... */
    _closePin_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
552
553
554
555
556
557
558
559
560

    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
561
    _passwordForPinGenerator_->Password = "";
562
}
563

564
565
566
567

void RingClientUWP::Views::SmartPanel::OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin)
{
    _waitingAndResult_->Text = pin;
Nicolas Jager's avatar
Nicolas Jager committed
568
569
570
571
572
573
574
575
576
577
578
579
    _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...";
580
}