Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 1 | /***************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * *
|
| 5 | * This program is free software; you can redistribute it and/or modify *
|
| 6 | * it under the terms of the GNU General Public License as published by *
|
| 7 | * the Free Software Foundation; either version 3 of the License, or *
|
| 8 | * (at your option) any later version. *
|
| 9 | * *
|
| 10 | * This program is distributed in the hope that it will be useful, *
|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 13 | * GNU General Public License for more details. *
|
| 14 | * *
|
| 15 | * You should have received a copy of the GNU General Public License *
|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 17 | **************************************************************************/
|
| 18 | #include "pch.h"
|
| 19 |
|
| 20 | #include "CallsViewModel.h"
|
| 21 |
|
| 22 | using namespace RingClientUWP;
|
| 23 | using namespace ViewModel;
|
| 24 | using namespace Windows::UI::Core;
|
| 25 | using namespace Windows::ApplicationModel::Core;
|
| 26 |
|
| 27 | CallsViewModel::CallsViewModel()
|
| 28 | {
|
| 29 | CallsList_ = ref new Vector<Call^>();
|
| 30 |
|
| 31 | /* connect to delegates. */
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 32 |
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 33 | RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
|
| 34 | String^ accountId, String^ callId, String^ from) {
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 35 | auto call = addNewCall(accountId, callId, from);
|
Nicolas Jager | 5750df0 | 2016-09-13 11:20:33 -0400 | [diff] [blame^] | 36 | // REFACTO : add if call == nullptr
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 37 | callRecieved(call);
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 38 | });
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 39 |
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 40 | RingD::instance->stateChange += ref new RingClientUWP::StateChange([&](
|
| 41 | String^ callId, String^ state, int code) {
|
| 42 | for each (auto call in CallsList_) {
|
| 43 | if (call->callId == callId) {
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 44 | if (state == "OVER") {
|
| 45 | delete call;
|
| 46 | call->stateChange("", code);
|
Nicolas Jager | f6a1032 | 2016-09-06 08:17:49 -0400 | [diff] [blame] | 47 | callStatusUpdated(call); // used ?
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 48 | return;
|
| 49 | }
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 50 | call->stateChange(state, code);
|
Nicolas Jager | f6a1032 | 2016-09-06 08:17:49 -0400 | [diff] [blame] | 51 | callStatusUpdated(call); // same...
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 52 | return;
|
| 53 | }
|
| 54 | }
|
| 55 | WNG_("Call not found");
|
| 56 | });
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 57 | }
|
| 58 |
|
| 59 | Call^
|
Nicolas Jager | 5750df0 | 2016-09-13 11:20:33 -0400 | [diff] [blame^] | 60 | RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ peer)
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 61 | {
|
Nicolas Jager | 5750df0 | 2016-09-13 11:20:33 -0400 | [diff] [blame^] | 62 | if (accountId == "" | callId == "" | peer == "") {
|
| 63 | WNG_("call can't be created");
|
| 64 | }
|
| 65 | auto call = ref new Call(accountId, callId, peer);
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 66 | CallsList_->Append(call);
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 67 | return call;
|
Nicolas Jager | a92f131 | 2016-08-25 08:01:22 -0400 | [diff] [blame] | 68 | }
|
Nicolas Jager | d76940f | 2016-08-31 14:44:04 -0400 | [diff] [blame] | 69 |
|
| 70 | void RingClientUWP::ViewModel::CallsViewModel::clearCallsList()
|
| 71 | {
|
| 72 | CallsList_->Clear();
|
Nicolas Jager | 7c409f3 | 2016-09-08 09:35:16 -0400 | [diff] [blame] | 73 | }
|
| 74 |
|
| 75 | Call^
|
| 76 | CallsViewModel::findCall(String^ callId)
|
| 77 | {
|
| 78 | for each (Call^ call in CallsList_)
|
| 79 | if (call->callId == callId)
|
| 80 | return call;
|
| 81 |
|
| 82 | return nullptr;
|
| 83 | }
|