diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 58205790a96c81ad87c681399542c186d7185ad6..40d98c0c2326f68f8c052159556d51bb42ae802d 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -1,142 +1,144 @@ -/*************************************************************************** -* 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 "ContactsViewModel.h" - -using namespace Windows::Data::Json; -using namespace Windows::Storage; - -using namespace RingClientUWP; -using namespace ViewModel; - -ContactsViewModel::ContactsViewModel() -{ - contactsList_ = ref new Vector<Contact^>(); - openContactsFromFile(); -} - -Contact^ -RingClientUWP::ViewModel::ContactsViewModel::findContactByName(String ^ name) -{ - for each (Contact^ contact in contactsList_) - if (contact->name_ == name) - return contact; - - return nullptr; -} - -Contact^ -RingClientUWP::ViewModel::ContactsViewModel::addNewContact(String^ name, String^ ringId) -{ - if (contactsList_ && !findContactByName(name)) { - Contact^ contact = ref new Contact(name, ringId); - contactsList_->Append(contact); - saveContactsToFile(); - return contact; - } - - return nullptr; -} - -void -ContactsViewModel::saveContactsToFile() -{ - StorageFolder^ localfolder = ApplicationData::Current->LocalFolder; - String^ contactsFile = ".profile\\contacts.json"; - - try { - create_task(localfolder->CreateFileAsync(contactsFile - , Windows::Storage::CreationCollisionOption::ReplaceExisting)) - .then([&](StorageFile^ newFile) { - try { - FileIO::WriteTextAsync(newFile, Stringify()); - } - catch (Exception^ e) { - RingDebug::instance->print("Exception while writing to contacts file"); - } - }); - } - catch (Exception^ e) { - RingDebug::instance->print("Exception while opening contacts file"); - } -} - -void -ContactsViewModel::openContactsFromFile() -{ - String^ contactsFile = ".profile\\contacts.json"; - - Utils::fileExists(ApplicationData::Current->LocalFolder, - contactsFile) - .then([this, contactsFile](bool contacts_file_exists) - { - if (contacts_file_exists) { - try { - create_task(ApplicationData::Current->LocalFolder->GetFileAsync(contactsFile)) - .then([this](StorageFile^ file) - { - create_task(FileIO::ReadTextAsync(file)) - .then([this](String^ fileContents) { - if (fileContents != nullptr) - Destringify(fileContents); - }); - }); - } - catch (Exception^ e) { - RingDebug::instance->print("Exception while opening contacts file"); - } - } - }); -} - -String^ -ContactsViewModel::Stringify() -{ - JsonArray^ jsonArray = ref new JsonArray(); - - for (unsigned int i = 0; i < contactsList_->Size; i++) { - jsonArray->Append(contactsList_->GetAt(i)->ToJsonObject()); - } - - JsonObject^ jsonObject = ref new JsonObject(); - jsonObject->SetNamedValue(contactListKey, jsonArray); - - return jsonObject->Stringify(); -} - -void -ContactsViewModel::Destringify(String^ data) -{ - JsonObject^ jsonObject = JsonObject::Parse(data); - String^ name; - String^ ringid; - - JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); - for (unsigned int i = 0; i < contactlist->Size; i++) { - IJsonValue^ contact = contactlist->GetAt(i); - if (contact->ValueType == JsonValueType::Object) { - JsonObject^ jsonContactObject = contact->GetObject(); - JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr); - if (contactObject != nullptr) { - name = contactObject->GetNamedString(nameKey, ""); - ringid = contactObject->GetNamedString(ringIDKey, ""); - } - contactsList_->Append(ref new Contact(name, ringid)); - } - } -} \ No newline at end of file +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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 "ContactsViewModel.h" + +using namespace Windows::Data::Json; +using namespace Windows::Storage; + +using namespace RingClientUWP; +using namespace ViewModel; + +ContactsViewModel::ContactsViewModel() +{ + contactsList_ = ref new Vector<Contact^>(); + openContactsFromFile(); +} + +Contact^ +ContactsViewModel::findContactByName(String ^ name) +{ + for each (Contact^ contact in contactsList_) + if (contact->name_ == name) + return contact; + + return nullptr; +} + +Contact^ +ContactsViewModel::addNewContact(String^ name, String^ ringId) +{ + if (contactsList_ && !findContactByName(name)) { + Contact^ contact = ref new Contact(name, ringId); + contactsList_->Append(contact); + saveContactsToFile(); + return contact; + } + + return nullptr; +} + +void +ContactsViewModel::saveContactsToFile() +{ + StorageFolder^ localfolder = ApplicationData::Current->LocalFolder; + String^ contactsFile = ".profile\\contacts.json"; + + try { + create_task(localfolder->CreateFileAsync(contactsFile + , Windows::Storage::CreationCollisionOption::ReplaceExisting)) + .then([&](StorageFile^ newFile) { + try { + FileIO::WriteTextAsync(newFile, Stringify()); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while writing to contacts file"); + } + }); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while opening contacts file"); + } +} + +void +ContactsViewModel::openContactsFromFile() +{ + String^ contactsFile = ".profile\\contacts.json"; + + Utils::fileExists(ApplicationData::Current->LocalFolder, + contactsFile) + .then([this,contactsFile](bool contacts_file_exists) + { + if (contacts_file_exists) { + try { + create_task(ApplicationData::Current->LocalFolder->GetFileAsync(contactsFile)) + .then([this](StorageFile^ file) + { + create_task(FileIO::ReadTextAsync(file)) + .then([this](String^ fileContents){ + if (fileContents != nullptr) + Destringify(fileContents); + }); + }); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while opening contacts file"); + } + } + }); +} + +String^ +ContactsViewModel::Stringify() +{ + JsonArray^ jsonArray = ref new JsonArray(); + + for (unsigned int i = 0; i < contactsList_->Size; i++) { + jsonArray->Append(contactsList_->GetAt(i)->ToJsonObject()); + } + + JsonObject^ jsonObject = ref new JsonObject(); + jsonObject->SetNamedValue(contactListKey, jsonArray); + + return jsonObject->Stringify(); +} + +void +ContactsViewModel::Destringify(String^ data) +{ + JsonObject^ jsonObject = JsonObject::Parse(data); + String^ name; + String^ ringid; + + JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); + for (unsigned int i = 0; i < contactlist->Size; i++) { + IJsonValue^ contact = contactlist->GetAt(i); + if (contact->ValueType == JsonValueType::Object) { + JsonObject^ jsonContactObject = contact->GetObject(); + JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr); + if (contactObject != nullptr) { + name = contactObject->GetNamedString(nameKey, ""); + ringid = contactObject->GetNamedString(ringIDKey, ""); + } + contactsList_->Append(ref new Contact(name, ringid)); + } + } +} diff --git a/ContactsViewModel.h b/ContactsViewModel.h index 31bf79e79b921a8bab6cd9bcb13ec69739f657d4..1bb057ebeb30473b479a816ac2a4e845aff40aea 100644 --- a/ContactsViewModel.h +++ b/ContactsViewModel.h @@ -1,88 +1,91 @@ -#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 Concurrency; -using namespace Platform::Collections; - -namespace RingClientUWP -{ - -delegate void NewContactSelected(); -delegate void NoContactSelected(); - -namespace ViewModel { -public ref class ContactsViewModel sealed -{ -internal: - /* singleton */ - static property ContactsViewModel^ instance - { - ContactsViewModel^ get() - { - static ContactsViewModel^ instance_ = ref new ContactsViewModel(); - return instance_; - } - } - - /* functions */ - Contact^ findContactByName(String^ name); - Contact^ addNewContact(String^ name, String^ ringId); - void saveContactsToFile(); - void openContactsFromFile(); - String^ Stringify(); - void Destringify(String^ data); - - /* properties */ - property Contact^ selectedContact - { - Contact^ get() - { - return currentItem_; - } - void set(Contact^ value) - { - oldItem_ = currentItem_; - currentItem_ = value; - if (value) - newContactSelected(); - else - noContactSelected(); - } - } - - property Vector<Contact^>^ contactsList - { - Vector<Contact^>^ get() - { - return contactsList_; - } - } - - /* events */ - event NewContactSelected^ newContactSelected; - event NoContactSelected^ noContactSelected; - -private: - ContactsViewModel(); // singleton - Vector<Contact^>^ contactsList_; - Contact^ currentItem_; - Contact^ oldItem_; - -}; -} -} +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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/>. * + **************************************************************************/ + +#pragma once + +using namespace Platform::Collections; +using namespace Concurrency; + +namespace RingClientUWP +{ + +delegate void NewContactSelected(); +delegate void NoContactSelected(); + +namespace ViewModel { +public ref class ContactsViewModel sealed +{ +internal: + /* singleton */ + static property ContactsViewModel^ instance + { + ContactsViewModel^ get() + { + static ContactsViewModel^ instance_ = ref new ContactsViewModel(); + return instance_; + } + } + + /* functions */ + Contact^ findContactByName(String^ name); + Contact^ addNewContact(String^ name, String^ ringId); + void saveContactsToFile(); + void openContactsFromFile(); + String^ Stringify(); + void Destringify(String^ data); + + /* properties */ + property Contact^ selectedContact + { + Contact^ get() + { + return currentItem_; + } + void set(Contact^ value) + { + oldItem_ = currentItem_; + currentItem_ = value; + if (value) + newContactSelected(); + else + noContactSelected(); + } + } + + property Vector<Contact^>^ contactsList + { + Vector<Contact^>^ get() + { + return contactsList_; + } + } + + /* events */ + event NewContactSelected^ newContactSelected; + event NoContactSelected^ noContactSelected; + +private: + ContactsViewModel(); // singleton + Vector<Contact^>^ contactsList_; + Contact^ currentItem_; + Contact^ oldItem_; + +}; +} +} diff --git a/RingD.cpp b/RingD.cpp index cacaad8bf22116dae83ae541537927414bd4634d..385084a9d9d8a7c783539431f994ef993f617395 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -1,189 +1,196 @@ -/*************************************************************************** -* Copyright (C) 2016 by Savoir-faire Linux * -* Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com> * -* Author: Traczyk Andreas <traczyk.andreas@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" - -/* daemon */ -#include <dring.h> -#include "callmanager_interface.h" -#include "configurationmanager_interface.h" -#include "presencemanager_interface.h" -#include "fileutils.h" - -#include "account_schema.h" - -#include "SmartPanel.xaml.h" - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::Storage; -using namespace Windows::UI::Core; - -using namespace RingClientUWP; -using namespace RingClientUWP::Utils; - -void -debugOutputWrapper(const std::string& str) -{ - MSG_(str); -} - -void -reloadAccountList() -{ - RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList(); - std::vector<std::string> accountList = DRing::getAccountList(); - std::vector<std::string>::reverse_iterator rit = accountList.rbegin(); - for (; rit != accountList.rend(); ++rit) { - std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(*rit); - std::string ringID(accountDetails.find(ring::Conf::CONFIG_ACCOUNT_USERNAME)->second); - if(!ringID.empty()) - ringID = ringID.substr(5); - RingClientUWP::ViewModel::AccountsViewModel::instance->add( - accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second, //name - ringID, //ringid - accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second); //type - } -} - -void -RingClientUWP::RingD::startDaemon() -{ - create_task([&]() - { - using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; - using namespace std::placeholders; - - std::map<std::string, SharedCallback> callHandlers = { - // use IncomingCall only to register the call client sided, use StateChange to determine the impact on the UI - DRing::exportable_callback<DRing::CallSignal::IncomingCall>([this]( - const std::string& accountId, - const std::string& callId, - const std::string& from) - { - MSG_("<IncomingCall>"); - 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, - const std::string& state, - int code) - { - MSG_("<StateChange>"); - 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, - const std::string& from, - const std::map<std::string, std::string>& payloads) - { - MSG_("<IncomingAccountMessage>"); - MSG_("accountId = " + accountId); - MSG_("from = " + from); - - for (auto i : payloads) { - MSG_("payload = " + i.second); - auto payload = Utils::toPlatformString(i.second); - } - }), - DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]() - { - reloadAccountList(); - }) - }; - - registerCallHandlers(callHandlers); - - std::map<std::string, SharedCallback> dringDebugOutHandler; - dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend> - (std::bind(&debugOutputWrapper, _1))); - registerCallHandlers(dringDebugOutHandler); - - std::map<std::string, SharedCallback> getAppPathHandler = - { - DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath> - ([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)); - - if (!DRing::start()) { - ERR_("\ndaemon didn't start.\n"); - return; - } - else { - if (!hasConfig) - { - std::map<std::string, std::string> ringAccountDetails; - ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_ALIAS, accountName)); - ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_TYPE,"RING")); - DRing::addAccount(ringAccountDetails); - } - CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, - ref new DispatchedHandler([=]() { - reloadAccountList(); - })); - while (true) { - DRing::pollEvents(); - Sleep(1000); - dequeueTasks(); - } - DRing::fini(); - } - }); -} - -RingD::RingD() -{ - localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path); -} - -void -RingD::dequeueTasks() -{ - for (int i = 0; i < tasksList_.size(); i++) { - auto task = tasksList_.front(); - switch (task->request) { - case Request::None: - default: - break; - } - tasksList_.pop(); - } -} +/*************************************************************************** +* Copyright (C) 2016 by Savoir-faire Linux * +* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * +* Author: Traczyk Andreas <traczyk.andreas@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" + +/* daemon */ +#include <dring.h> +#include "callmanager_interface.h" +#include "configurationmanager_interface.h" +#include "presencemanager_interface.h" +#include "fileutils.h" + +#include "account_schema.h" + +#include "SmartPanel.xaml.h" + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::Storage; +using namespace Windows::UI::Core; + +using namespace RingClientUWP; +using namespace RingClientUWP::Utils; + +void +debugOutputWrapper(const std::string& str) +{ + MSG_(str); +} + +void +RingClientUWP::RingD::reloadAccountList() +{ + RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList(); + std::vector<std::string> accountList = DRing::getAccountList(); + std::vector<std::string>::reverse_iterator rit = accountList.rbegin(); + for (; rit != accountList.rend(); ++rit) { + std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(*rit); + std::string ringID(accountDetails.find(ring::Conf::CONFIG_ACCOUNT_USERNAME)->second); + if(!ringID.empty()) + ringID = ringID.substr(5); + RingClientUWP::ViewModel::AccountsViewModel::instance->add( + accountDetails.find(ring::Conf::CONFIG_ACCOUNT_ALIAS)->second, //name + ringID, //ringid + accountDetails.find(ring::Conf::CONFIG_ACCOUNT_TYPE)->second); //type + } + // load user preferences + Configuration::UserPreferences::instance->load(); +} + +void +RingClientUWP::RingD::startDaemon() +{ + create_task([&]() + { + using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; + using namespace std::placeholders; + + std::map<std::string, SharedCallback> callHandlers = { + // use IncomingCall only to register the call client sided, use StateChange to determine the impact on the UI + DRing::exportable_callback<DRing::CallSignal::IncomingCall>([this]( + const std::string& accountId, + const std::string& callId, + const std::string& from) + { + MSG_("<IncomingCall>"); + 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, + const std::string& state, + int code) + { + MSG_("<StateChange>"); + 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, + const std::string& from, + const std::map<std::string, std::string>& payloads) + { + MSG_("<IncomingAccountMessage>"); + MSG_("accountId = " + accountId); + MSG_("from = " + from); + + for (auto i : payloads) { + MSG_("payload = " + i.second); + auto payload = Utils::toPlatformString(i.second); + } + }), + DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]() + { + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, + ref new DispatchedHandler([=]() { + reloadAccountList(); + })); + }) + }; + + registerCallHandlers(callHandlers); + + std::map<std::string, SharedCallback> dringDebugOutHandler; + dringDebugOutHandler.insert(DRing::exportable_callback<DRing::Debug::MessageSend> + (std::bind(&debugOutputWrapper, _1))); + registerCallHandlers(dringDebugOutHandler); + + std::map<std::string, SharedCallback> getAppPathHandler = + { + DRing::exportable_callback<DRing::ConfigurationSignal::GetAppDataPath> + ([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)); + + if (!DRing::start()) { + ERR_("\ndaemon didn't start.\n"); + return; + } + else { + if (!hasConfig) + { + std::map<std::string, std::string> ringAccountDetails; + ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_ALIAS, accountName)); + ringAccountDetails.insert(std::make_pair(ring::Conf::CONFIG_ACCOUNT_TYPE,"RING")); + DRing::addAccount(ringAccountDetails); + } + else { + CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, + ref new DispatchedHandler([=]() { + reloadAccountList(); + })); + } + while (true) { + DRing::pollEvents(); + Sleep(1000); + dequeueTasks(); + } + DRing::fini(); + } + }); +} + +RingD::RingD() +{ + localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path); +} + +void +RingD::dequeueTasks() +{ + for (int i = 0; i < tasksList_.size(); i++) { + auto task = tasksList_.front(); + switch (task->request) { + case Request::None: + default: + break; + } + tasksList_.pop(); + } +} diff --git a/RingD.h b/RingD.h index 80bb6f74348fa7e2d24bd6a003c0529a5caecac4..9758fbdfc83fcfa6f4445d52e07080864b062735 100644 --- a/RingD.h +++ b/RingD.h @@ -1,82 +1,83 @@ -/*************************************************************************** -* 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/>. * -**************************************************************************/ -#pragma once - -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() - { - static RingD^ instance_ = ref new RingD(); - return instance_; - } - } - - property bool daemonRunning - { - bool get() - { - return daemonRunning_; - } - } - -internal: - /* functions */ - void startDaemon(); - - /* TODO : move members */ - bool hasConfig; - std::string accountName; - - /* events */ - event IncomingCall^ incomingCall; - event StateChange^ stateChange; - -private: - /* sub classes */ - enum class Request { None }; - ref class Task - { - public: - property Request request; - }; - - /* functions */ - RingD(); // singleton - void dequeueTasks(); - - /* members */ - std::string localFolder_; - bool daemonRunning_ = false; - std::queue<Task^> tasksList_; -}; +/*************************************************************************** +* 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/>. * +**************************************************************************/ +#pragma once + +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() + { + static RingD^ instance_ = ref new RingD(); + return instance_; + } + } + + property bool daemonRunning + { + bool get() + { + return daemonRunning_; + } + } + +internal: + /* functions */ + void startDaemon(); + void reloadAccountList(); + + /* TODO : move members */ + bool hasConfig; + std::string accountName; + + /* events */ + event IncomingCall^ incomingCall; + event StateChange^ stateChange; + +private: + /* sub classes */ + enum class Request { None }; + ref class Task + { + public: + property Request request; + }; + + /* functions */ + RingD(); // singleton + void dequeueTasks(); + + /* members */ + std::string localFolder_; + bool daemonRunning_ = false; + std::queue<Task^> tasksList_; +}; } \ No newline at end of file diff --git a/RingDebug.cpp b/RingDebug.cpp index 7d14f87d639c5da8f3095f66e9340ab8c8daae99..6305d8fabc44d88a01fec0cfff3789da0c90d322 100644 --- a/RingDebug.cpp +++ b/RingDebug.cpp @@ -1,20 +1,21 @@ /*************************************************************************** -* 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/>. * -**************************************************************************/ + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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/>. * + **************************************************************************/ /* client */ #include "pch.h" diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index c68b9ac44faaa2e845e8d3c7139687b6e30b01ec..690183d10720e0ada9c74597d3c59701ade160ed 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -1,180 +1,192 @@ -/*************************************************************************** - * 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 "SmartPanel.xaml.h" - -using namespace Platform; - -using namespace RingClientUWP; -using namespace RingClientUWP::Views; -using namespace RingClientUWP::ViewModel; -using namespace Windows::Media::Capture; -using namespace Windows::UI::Xaml; -using namespace Windows::Storage; -using namespace Windows::UI::Xaml::Media::Imaging; -using namespace Windows::UI::Xaml::Shapes; -using namespace Windows::UI::Xaml::Media; -using namespace Concurrency; -using namespace Windows::Foundation; - -SmartPanel::SmartPanel() -{ - InitializeComponent(); - - _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; - _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; -} - -void -RingClientUWP::Views::SmartPanel::updatePageContent() -{ - auto account = AccountsViewModel::instance->selectedAccount; - if (!account) - return; - - _selectedAccountName_->Text = account->name_; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _shareMenuButton_->IsChecked = false; - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) -{ - if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { - _rowRingTxtBx_->Height = 40; - _selectedAccountAvatar_->Height = 80; - _selectedAccountAvatarColumn_->Width = 90; - _selectedAccountRow_->Height = 90; - } - else { - _rowRingTxtBx_->Height = 0; - _selectedAccountAvatar_->Height = 50; - _selectedAccountAvatarColumn_->Width = 60; - _selectedAccountRow_->Height = 60; - } - - _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; - _settingsTBtn_->IsChecked = false; - _accountsMenuButton_->IsChecked = false; - _shareMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountsMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - -} - -void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - -} - -void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); - cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; - cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); - - - create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) - { - if (photo != nullptr) { - // maybe it would be possible to move some logics to the style sheet - auto brush = ref new ImageBrush(); - - auto circle = ref new Ellipse(); - circle->Height = 80; // TODO : use some global constant when ready - circle->Width = 80; - auto path = photo->Path; - auto uri = ref new Windows::Foundation::Uri(path); - auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); - bitmapImage->UriSource = uri; - - brush->ImageSource = bitmapImage; - circle->Fill = brush; - _avatarWebcamCaptureBtn_->Content = circle; - } - }); - -} - -void -SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) -{ - auto listbox = safe_cast<ListBox^>(sender); - auto contact = safe_cast<Contact^>(listbox->SelectedItem); - ContactsViewModel::instance->selectedContact = contact; -} - -void -SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) -{ - auto listbox = safe_cast<ListBox^>(sender); - auto account = safe_cast<Account^>(listbox->SelectedItem); - AccountsViewModel::instance->selectedAccount = account; - updatePageContent(); -} - -void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) -{ - /* add contact, test purpose but will be reused later in some way */ - if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") { - ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text); - _ringTxtBx_->Text = ""; - } -} +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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 "SmartPanel.xaml.h" + +using namespace Platform; + +using namespace RingClientUWP; +using namespace RingClientUWP::Views; +using namespace RingClientUWP::ViewModel; +using namespace Windows::Media::Capture; +using namespace Windows::UI::Xaml; +using namespace Windows::Storage; +using namespace Windows::UI::Xaml::Media::Imaging; +using namespace Windows::UI::Xaml::Shapes; +using namespace Windows::UI::Xaml::Media; +using namespace Concurrency; +using namespace Windows::Foundation; + +SmartPanel::SmartPanel() +{ + InitializeComponent(); + + Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { + _accountsList_->SelectedIndex = index; + }); + + _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; + _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; +} + +void +RingClientUWP::Views::SmartPanel::updatePageContent() +{ + auto account = AccountsViewModel::instance->selectedAccount; + if (!account) + return; + + Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex; + Configuration::UserPreferences::instance->save(); + _selectedAccountName_->Text = account->name_; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _shareMenuButton_->IsChecked = false; + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) +{ + if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { + _rowRingTxtBx_->Height = 40; + _selectedAccountAvatar_->Height = 80; + _selectedAccountAvatarColumn_->Width = 90; + _selectedAccountRow_->Height = 90; + } + else { + _rowRingTxtBx_->Height = 0; + _selectedAccountAvatar_->Height = 50; + _selectedAccountAvatarColumn_->Width = 60; + _selectedAccountRow_->Height = 60; + } + + _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; + _settingsTBtn_->IsChecked = false; + _accountsMenuButton_->IsChecked = false; + _shareMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountsMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + + +void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + + +void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + +} + + +void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + +} + + +void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); + cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; + cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); + + + create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) + { + if (photo != nullptr) { + // maybe it would be possible to move some logics to the style sheet + auto brush = ref new ImageBrush(); + + auto circle = ref new Ellipse(); + circle->Height = 80; // TODO : use some global constant when ready + circle->Width = 80; + auto path = photo->Path; + auto uri = ref new Windows::Foundation::Uri(path); + auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); + bitmapImage->UriSource = uri; + + brush->ImageSource = bitmapImage; + circle->Fill = brush; + _avatarWebcamCaptureBtn_->Content = circle; + } + }); + +} + + +void +SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) +{ + auto listbox = safe_cast<ListBox^>(sender); + auto contact = safe_cast<Contact^>(listbox->SelectedItem); + ContactsViewModel::instance->selectedContact = contact; +} + +void +SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) +{ + auto listbox = safe_cast<ListBox^>(sender); + auto account = safe_cast<Account^>(listbox->SelectedItem); + AccountsViewModel::instance->selectedAccount = account; + updatePageContent(); +} + +void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) +{ + /* add contact, test purpose but will be reused later in some way */ + if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") { + ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text); + _ringTxtBx_->Text = ""; + } +} diff --git a/UserPreferences.cpp b/UserPreferences.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0b080de602bb1bcdf1760c4ab04adebbc2ba7ab --- /dev/null +++ b/UserPreferences.cpp @@ -0,0 +1,102 @@ +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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" + +using namespace Windows::Data::Json; +using namespace Windows::Storage; + +using namespace RingClientUWP; +using namespace Platform; +using namespace Configuration; + +void +UserPreferences::save() +{ + StorageFolder^ localfolder = ApplicationData::Current->LocalFolder; + String^ preferencesFile = "preferences.json"; + + try { + create_task(localfolder->CreateFileAsync(preferencesFile + ,Windows::Storage::CreationCollisionOption::ReplaceExisting)) + .then([&](StorageFile^ newFile){ + try { + FileIO::WriteTextAsync(newFile,Stringify()); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while writing to preferences file"); + } + }); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while opening preferences file"); + } +} + +void +UserPreferences::load() +{ + String^ preferencesFile = "preferences.json"; + + Utils::fileExists(ApplicationData::Current->LocalFolder, + preferencesFile) + .then([this,preferencesFile](bool contacts_file_exists) + { + if (contacts_file_exists) { + RingDebug::instance->print("opened preferences file"); + try { + create_task(ApplicationData::Current->LocalFolder->GetFileAsync(preferencesFile)) + .then([this](StorageFile^ file) + { + create_task(FileIO::ReadTextAsync(file)) + .then([this](String^ fileContents){ + RingDebug::instance->print("reading preferences file"); + if (fileContents != nullptr) { + Destringify(fileContents); + // select account index after loading preferences + selectIndex(PREF_ACCOUNT_INDEX); + } + }); + }); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while opening preferences file"); + } + } + else { + selectIndex(0); + } + }); +} + +String^ +UserPreferences::Stringify() +{ + JsonObject^ preferencesObject = ref new JsonObject(); + preferencesObject->SetNamedValue("PREF_ACCOUNT_INDEX", JsonValue::CreateNumberValue(PREF_ACCOUNT_INDEX)); + return preferencesObject->Stringify(); +} + +void +UserPreferences::Destringify(String^ data) +{ + JsonObject^ jsonObject = JsonObject::Parse(data); + PREF_ACCOUNT_INDEX = static_cast<int>(jsonObject->GetNamedNumber("PREF_ACCOUNT_INDEX")); + JsonArray^ preferencesList = jsonObject->GetNamedArray("Account.index", ref new JsonArray()); +} \ No newline at end of file diff --git a/UserPreferences.h b/UserPreferences.h new file mode 100644 index 0000000000000000000000000000000000000000..5c8ee752d3b51737a70b13826d440e0c4167c3ab --- /dev/null +++ b/UserPreferences.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: J�ger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@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/>. * + **************************************************************************/ + +#pragma once + +namespace RingClientUWP +{ + +delegate void SelectIndex(int index); + +namespace Configuration +{ + +/* delegates */ + +public ref class UserPreferences sealed +{ +public: + /* singleton */ + static property UserPreferences^ instance + { + UserPreferences^ get() + { + static UserPreferences^ instance_ = ref new UserPreferences(); + return instance_; + } + } + + /* properties */ + property int PREF_ACCOUNT_INDEX; + + /* functions */ + void save(); + void load(); + String^ Stringify(); + void Destringify(String^ data); + +internal: + + /* events */ + event SelectIndex^ selectIndex; + +private: + UserPreferences() { }; + +}; + +} +} \ No newline at end of file diff --git a/pch.h b/pch.h index 0ccf5895bdb43be456920b993a9a301c83aa75fa..c2af724174c616e2999b413c6d9214e4902ac60f 100644 --- a/pch.h +++ b/pch.h @@ -35,3 +35,4 @@ #include "RingD.h" #include "RingDebug.h" #include "Utils.h" +#include "UserPreferences.h" diff --git a/ring-client-uwp.vcxproj b/ring-client-uwp.vcxproj index 0c83f1bbc2b5607918f7cc4345e912a9ed038fe7..ce8fbe64cc5f771597de127af30035d9a49fff92 100644 --- a/ring-client-uwp.vcxproj +++ b/ring-client-uwp.vcxproj @@ -137,7 +137,7 @@ <DisableSpecificWarnings>4453;28204;4267;4129;4973;4018;</DisableSpecificWarnings> <AdditionalIncludeDirectories>..\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> <PreprocessorDefinitions>WIN32_NATIVE;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <WholeProgramOptimization>false</WholeProgramOptimization> + <WholeProgramOptimization>false</WholeProgramOptimization> </ClCompile> <Link> <AdditionalLibraryDirectories>$(SolutionDir)..\ring-daemon\contrib\lib\x64;$(SolutionDir)..\ring-daemon\MSVC\x64\ReleaseLib\bin;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> @@ -189,6 +189,7 @@ <ClInclude Include="SmartPanel.xaml.h"> <DependentUpon>SmartPanel.xaml</DependentUpon> </ClInclude> + <ClInclude Include="UserPreferences.h" /> <ClInclude Include="Utils.h" /> <ClInclude Include="VideoPage.xaml.h"> <DependentUpon>VideoPage.xaml</DependentUpon> @@ -293,6 +294,7 @@ <ClCompile Include="SmartPanel.xaml.cpp"> <DependentUpon>SmartPanel.xaml</DependentUpon> </ClCompile> + <ClCompile Include="UserPreferences.cpp" /> <ClCompile Include="VideoPage.xaml.cpp"> <DependentUpon>VideoPage.xaml</DependentUpon> </ClCompile> diff --git a/ring-client-uwp.vcxproj.filters b/ring-client-uwp.vcxproj.filters index 0ad361d5d58565e86a38ea910e0fe35482f82961..c34224b8c913d1821627a24a9c95578b1c7732e1 100644 --- a/ring-client-uwp.vcxproj.filters +++ b/ring-client-uwp.vcxproj.filters @@ -73,10 +73,13 @@ </ClCompile> <ClCompile Include="Conversation.cpp"> <Filter>Model</Filter> - </ClCompile> + </ClCompile> <ClCompile Include="CallsViewModel.cpp"> <Filter>ModelViews</Filter> </ClCompile> + <ClCompile Include="UserPreferences.cpp"> + <Filter>Common</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="pch.h" /> @@ -115,10 +118,13 @@ </ClInclude> <ClInclude Include="CallsViewModel.h"> <Filter>ModelViews</Filter> - </ClInclude> + </ClInclude> <ClInclude Include="Conversation.h"> <Filter>Model</Filter> </ClInclude> + <ClInclude Include="UserPreferences.h"> + <Filter>Common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Image Include="Assets\LockScreenLogo.scale-200.png">