Commit a92f1311 authored by Nicolas Jager's avatar Nicolas Jager

call object and model view

Change-Id: I7d3024577ee3d6b74c6ced1721886cf968e931f5
parent 61b28428
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "pch.h"
#include "Call.h"
using namespace Windows::ApplicationModel::Core;
using namespace Platform;
using namespace Windows::UI::Core;
using namespace RingClientUWP;
Call::Call(String^ accountId, String^ callId, String^ from)
{
this->accountId = accountId;
this->callId = callId;
this->from = from;
this->state = "";
this->code = -1;
}
void RingClientUWP::Call::stateChange(String ^ state, int code)
{
this->state = state;
this->code = code;
}
void
Call::NotifyPropertyChanged(String^ propertyName)
{
CoreApplicationView^ view = CoreApplication::MainView;
view->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::Normal,
ref new DispatchedHandler([this, propertyName]()
{
PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
}));
}
\ No newline at end of file
#pragma once
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
using namespace Platform;
using namespace Windows::UI::Xaml::Data;
namespace RingClientUWP
{
public ref class Call sealed : public INotifyPropertyChanged
{
public:
/* functions */
Call(String^ accountId, String^ callId, String^ from);
void stateChange(String^ state, int code);
/* properties */
virtual event PropertyChangedEventHandler^ PropertyChanged;
property String^ accountId;
property String^ callId;
property String^ from;
property String^ state;
property int code;
/* events */
protected:
/* properties */
void NotifyPropertyChanged(String^ propertyName);
};
}
/***************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "pch.h"
#include "CallsViewModel.h"
using namespace RingClientUWP;
using namespace ViewModel;
using namespace Windows::UI::Core;
using namespace Windows::ApplicationModel::Core;
CallsViewModel::CallsViewModel()
{
CallsList_ = ref new Vector<Call^>();
/* connect to delegates. */
RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
String^ accountId, String^ callId, String^ from) {
addNewCall(accountId, callId, from);
});
RingD::instance->stateChange += ref new RingClientUWP::StateChange([&](
String^ callId, String^ state, int code) {
for each (auto call in CallsList_) {
if (call->callId == callId) {
call->stateChange(state, code);
return;
}
}
WNG_("Call not found");
});
}
Call^
RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ from)
{
auto call = ref new Call(accountId, callId, from);
CallsList_->Append(call);
return nullptr;
}
#pragma once
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
using namespace Platform::Collections;
namespace RingClientUWP
{
namespace ViewModel {
public ref class CallsViewModel sealed
{
internal:
/* singleton */
static property CallsViewModel^ instance
{
CallsViewModel^ get()
{
static CallsViewModel^ instance_ = ref new CallsViewModel();
return instance_;
}
}
/* functions */
Call^ addNewCall(String^ accountId, String^ callId, String^ from);
/* properties */
property Vector<Call^>^ CallsList
{
Vector<Call^>^ get()
{
return CallsList_;
}
}
/* events */
private:
CallsViewModel(); // singleton
Vector<Call^>^ CallsList_;
};
}
}
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="00000000-0000-0000-0000-000000000000" Publisher="CN=user" Version="1.0.0.0" />
<Identity Name="PackageNameXXXXX" Publisher="CN=user" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="2385953f-9019-423d-aa82-d1bbacfa258b" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>ring-client-uwp</DisplayName>
......
......@@ -32,6 +32,7 @@ using namespace Windows::Storage;
using namespace Windows::UI::Core;
using namespace RingClientUWP;
using namespace RingClientUWP::Utils;
void
DebugOutputWrapper(const std::string& str)
......@@ -58,6 +59,13 @@ RingClientUWP::RingD::startDaemon()
MSG_("accountId = " + accountId);
MSG_("callId = " + callId);
MSG_("from = " + from);
auto accountId2 = toPlatformString(accountId);
auto callId2 = toPlatformString(callId);
auto from2 = toPlatformString(from);
incomingCall(accountId2, callId2, from2);
}),
DRing::exportable_callback<DRing::CallSignal::StateChange>([this](
const std::string& callId,
......@@ -68,6 +76,12 @@ RingClientUWP::RingD::startDaemon()
MSG_("callId = " + callId);
MSG_("state = " + state);
MSG_("code = " + std::to_string(code));
auto callId2 = toPlatformString(callId);
auto state2 = toPlatformString(state);
stateChange(callId2, state2, code);
}),
DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this](
const std::string& accountId,
......@@ -89,21 +103,21 @@ RingClientUWP::RingD::startDaemon()
std::map<std::string, SharedCallback> dringDebugOutHandler;
dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend>
(std::bind(&DebugOutputWrapper, _1)));
(std::bind(&DebugOutputWrapper, _1)));
registerCallHandlers(dringDebugOutHandler);
std::map<std::string, SharedCallback> getAppPathHandler =
{
DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath>
([this](std::vector<std::string>* paths){
([this](std::vector<std::string>* paths) {
paths->emplace_back(localFolder_);
})
};
registerCallHandlers(getAppPathHandler);
DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG |
DRing::DRING_FLAG_DEBUG |
DRing::DRING_FLAG_AUTOANSWER));
DRing::DRING_FLAG_DEBUG |
DRing::DRING_FLAG_AUTOANSWER));
if (!DRing::start()) {
ERR_("\ndaemon didn't start.\n");
......
......@@ -22,9 +22,16 @@ using namespace concurrency;
namespace RingClientUWP
{
/* delegate */
delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
delegate void StateChange(String^ callId, String^ state, int code);
public ref class RingD sealed
{
public:
/* functions */
/* properties */
static property RingD^ instance
{
RingD^ get()
......@@ -42,17 +49,18 @@ public:
}
}
/* properties */
/* functions */
internal:
/* functions */
void startDaemon();
/* TODO : move members */
bool hasConfig;
std::string accountName;
/* events */
event IncomingCall^ incomingCall;
event StateChange^ stateChange;
private:
RingD(); // singleton
std::string localFolder_;
......
......@@ -25,6 +25,7 @@
#include "App.xaml.h"
#include "Account.h"
#include "AccountsViewModel.h"
#include "Call.h"
#include "Contact.h"
#include "ContactsViewModel.h"
......
......@@ -160,6 +160,8 @@
<ItemGroup>
<ClInclude Include="Account.h" />
<ClInclude Include="AccountsViewModel.h" />
<ClInclude Include="Call.h" />
<ClInclude Include="CallsViewModel.h" />
<ClInclude Include="Contact.h" />
<ClInclude Include="ContactsViewModel.h" />
<ClInclude Include="LoadingPage.xaml.h">
......@@ -255,6 +257,8 @@
<DependentUpon>App.xaml</DependentUpon>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\ring-daemon\MSVC;..\ring-daemon\src\media;..\ring-daemon\src;..\ring-daemon\src\dring;..\ring-daemon\contrib\include;..\ring-daemon\contrib\include\pjlib;..\ring-daemon\contrib\pjproject\third_party\speex\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ClCompile Include="Call.cpp" />
<ClCompile Include="CallsViewModel.cpp" />
<ClCompile Include="Contact.cpp" />
<ClCompile Include="ContactsViewModel.cpp" />
<ClCompile Include="LoadingPage.xaml.cpp">
......
......@@ -64,6 +64,16 @@
<ClCompile Include="RingD.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="LoadingPage.xaml.cpp" />
<ClCompile Include="MessageTextPage.xaml.cpp" />
<ClCompile Include="VideoPage.xaml.cpp" />
<ClCompile Include="Wizard.xaml.cpp" />
<ClCompile Include="Call.cpp">
<Filter>Model</Filter>
</ClCompile>
<ClCompile Include="CallsViewModel.cpp">
<Filter>ModelViews</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
......@@ -93,6 +103,16 @@
<ClInclude Include="RingD.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="LoadingPage.xaml.h" />
<ClInclude Include="MessageTextPage.xaml.h" />
<ClInclude Include="VideoPage.xaml.h" />
<ClInclude Include="Wizard.xaml.h" />
<ClInclude Include="Call.h">
<Filter>Model</Filter>
</ClInclude>
<ClInclude Include="CallsViewModel.h">
<Filter>ModelViews</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="Assets\LockScreenLogo.scale-200.png">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment