blob: b71479020dd6f5659d43f6f25461721631a3f932 [file] [log] [blame]
atraczyke9919eb2016-09-15 15:58:18 -04001/**************************************************************************
Nicolas Jagera92f1312016-08-25 08:01:22 -04002* Copyright (C) 2016 by Savoir-faire Linux *
3* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
atraczyke9919eb2016-09-15 15:58:18 -04004* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
Nicolas Jagera92f1312016-08-25 08:01:22 -04005* *
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
23using namespace RingClientUWP;
24using namespace ViewModel;
25using namespace Windows::UI::Core;
26using namespace Windows::ApplicationModel::Core;
27
28CallsViewModel::CallsViewModel()
29{
30 CallsList_ = ref new Vector<Call^>();
31
32 /* connect to delegates. */
Nicolas Jagerd76940f2016-08-31 14:44:04 -040033
Nicolas Jagera92f1312016-08-25 08:01:22 -040034 RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
35 String^ accountId, String^ callId, String^ from) {
Nicolas Jagerd76940f2016-08-31 14:44:04 -040036 auto call = addNewCall(accountId, callId, from);
Nicolas Jager5750df02016-09-13 11:20:33 -040037 // REFACTO : add if call == nullptr
Nicolas Jagerd76940f2016-08-31 14:44:04 -040038 callRecieved(call);
Nicolas Jagera92f1312016-08-25 08:01:22 -040039 });
Nicolas Jagerd76940f2016-08-31 14:44:04 -040040
Nicolas Jagera92f1312016-08-25 08:01:22 -040041 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 Jagerd76940f2016-08-31 14:44:04 -040045 if (state == "OVER") {
46 delete call;
47 call->stateChange("", code);
atraczyke9919eb2016-09-15 15:58:18 -040048 callEnded();
Nicolas Jagerf6a10322016-09-06 08:17:49 -040049 callStatusUpdated(call); // used ?
Nicolas Jager121bdf32016-09-13 12:12:15 -040050 RingD::instance->hangUpCall(call);
Nicolas Jagerd76940f2016-08-31 14:44:04 -040051 return;
52 }
atraczyke9919eb2016-09-15 15:58:18 -040053 else if (state == "CURRENT") {
54 callStarted();
55 }
Nicolas Jagera92f1312016-08-25 08:01:22 -040056 call->stateChange(state, code);
Nicolas Jagerf6a10322016-09-06 08:17:49 -040057 callStatusUpdated(call); // same...
Nicolas Jagera92f1312016-08-25 08:01:22 -040058 return;
59 }
60 }
61 WNG_("Call not found");
62 });
Nicolas Jagera92f1312016-08-25 08:01:22 -040063}
64
65Call^
Nicolas Jager5750df02016-09-13 11:20:33 -040066RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ peer)
Nicolas Jagera92f1312016-08-25 08:01:22 -040067{
Nicolas Jager5750df02016-09-13 11:20:33 -040068 if (accountId == "" | callId == "" | peer == "") {
69 WNG_("call can't be created");
70 }
71 auto call = ref new Call(accountId, callId, peer);
Nicolas Jagera92f1312016-08-25 08:01:22 -040072 CallsList_->Append(call);
Nicolas Jagerd76940f2016-08-31 14:44:04 -040073 return call;
Nicolas Jagera92f1312016-08-25 08:01:22 -040074}
Nicolas Jagerd76940f2016-08-31 14:44:04 -040075
76void RingClientUWP::ViewModel::CallsViewModel::clearCallsList()
77{
78 CallsList_->Clear();
Nicolas Jager7c409f32016-09-08 09:35:16 -040079}
80
81Call^
82CallsViewModel::findCall(String^ callId)
83{
84 for each (Call^ call in CallsList_)
85 if (call->callId == callId)
86 return call;
87
88 return nullptr;
89}