blob: af9f832f1bed13a64d19609f1f62e41d8f77cc86 [file] [log] [blame]
Nicolas Jagera92f1312016-08-25 08:01:22 -04001/***************************************************************************
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
22using namespace RingClientUWP;
23using namespace ViewModel;
24using namespace Windows::UI::Core;
25using namespace Windows::ApplicationModel::Core;
26
27CallsViewModel::CallsViewModel()
28{
29 CallsList_ = ref new Vector<Call^>();
30
31 /* connect to delegates. */
Nicolas Jagerd76940f2016-08-31 14:44:04 -040032
Nicolas Jagera92f1312016-08-25 08:01:22 -040033 RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
34 String^ accountId, String^ callId, String^ from) {
Nicolas Jagerd76940f2016-08-31 14:44:04 -040035 auto call = addNewCall(accountId, callId, from);
Nicolas Jager5750df02016-09-13 11:20:33 -040036 // REFACTO : add if call == nullptr
Nicolas Jagerd76940f2016-08-31 14:44:04 -040037 callRecieved(call);
Nicolas Jagera92f1312016-08-25 08:01:22 -040038 });
Nicolas Jagerd76940f2016-08-31 14:44:04 -040039
Nicolas Jagera92f1312016-08-25 08:01:22 -040040 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 Jagerd76940f2016-08-31 14:44:04 -040044 if (state == "OVER") {
45 delete call;
46 call->stateChange("", code);
Nicolas Jagerf6a10322016-09-06 08:17:49 -040047 callStatusUpdated(call); // used ?
Nicolas Jager121bdf32016-09-13 12:12:15 -040048 RingD::instance->hangUpCall(call);
Nicolas Jagerd76940f2016-08-31 14:44:04 -040049 return;
50 }
Nicolas Jagera92f1312016-08-25 08:01:22 -040051 call->stateChange(state, code);
Nicolas Jagerf6a10322016-09-06 08:17:49 -040052 callStatusUpdated(call); // same...
Nicolas Jagera92f1312016-08-25 08:01:22 -040053 return;
54 }
55 }
56 WNG_("Call not found");
57 });
Nicolas Jagera92f1312016-08-25 08:01:22 -040058}
59
60Call^
Nicolas Jager5750df02016-09-13 11:20:33 -040061RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ peer)
Nicolas Jagera92f1312016-08-25 08:01:22 -040062{
Nicolas Jager5750df02016-09-13 11:20:33 -040063 if (accountId == "" | callId == "" | peer == "") {
64 WNG_("call can't be created");
65 }
66 auto call = ref new Call(accountId, callId, peer);
Nicolas Jagera92f1312016-08-25 08:01:22 -040067 CallsList_->Append(call);
Nicolas Jagerd76940f2016-08-31 14:44:04 -040068 return call;
Nicolas Jagera92f1312016-08-25 08:01:22 -040069}
Nicolas Jagerd76940f2016-08-31 14:44:04 -040070
71void RingClientUWP::ViewModel::CallsViewModel::clearCallsList()
72{
73 CallsList_->Clear();
Nicolas Jager7c409f32016-09-08 09:35:16 -040074}
75
76Call^
77CallsViewModel::findCall(String^ callId)
78{
79 for each (Call^ call in CallsList_)
80 if (call->callId == callId)
81 return call;
82
83 return nullptr;
84}