blob: 02a493344ea34e7b9cff5fcf07c609bff3a35f44 [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);
36 callRecieved(call);
Nicolas Jagera92f1312016-08-25 08:01:22 -040037 });
Nicolas Jagerd76940f2016-08-31 14:44:04 -040038
Nicolas Jagera92f1312016-08-25 08:01:22 -040039 RingD::instance->stateChange += ref new RingClientUWP::StateChange([&](
40 String^ callId, String^ state, int code) {
41 for each (auto call in CallsList_) {
42 if (call->callId == callId) {
Nicolas Jagerd76940f2016-08-31 14:44:04 -040043 if (state == "OVER") {
44 delete call;
45 call->stateChange("", code);
Nicolas Jagerf6a10322016-09-06 08:17:49 -040046 callStatusUpdated(call); // used ?
Nicolas Jagerd76940f2016-08-31 14:44:04 -040047 return;
48 }
Nicolas Jagera92f1312016-08-25 08:01:22 -040049 call->stateChange(state, code);
Nicolas Jagerf6a10322016-09-06 08:17:49 -040050 callStatusUpdated(call); // same...
Nicolas Jagera92f1312016-08-25 08:01:22 -040051 return;
52 }
53 }
54 WNG_("Call not found");
55 });
Nicolas Jagera92f1312016-08-25 08:01:22 -040056}
57
58Call^
59RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ from)
60{
61 auto call = ref new Call(accountId, callId, from);
62 CallsList_->Append(call);
Nicolas Jagerd76940f2016-08-31 14:44:04 -040063 return call;
Nicolas Jagera92f1312016-08-25 08:01:22 -040064}
Nicolas Jagerd76940f2016-08-31 14:44:04 -040065
66void RingClientUWP::ViewModel::CallsViewModel::clearCallsList()
67{
68 CallsList_->Clear();
69}