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