From f6a1032706e42290ae0c5f35e6f367a7eba9bc90 Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Tue, 6 Sep 2016 08:17:49 -0400 Subject: [PATCH] call : accept/reject incoming calls - adds buttons and logic to accept or reject a call. - removes the auto answer flag. Tuleap: #984 Change-Id: Ifbf5e5bbbff77b26badff6b180d4e0368f207910 --- Call.cpp | 12 +++++++++- Call.h | 3 +++ CallsViewModel.cpp | 4 ++-- Contact.h | 14 ++++++++++- ContactsViewModel.cpp | 2 ++ RingD.cpp | 38 +++++++++++++++++++++++++----- RingD.h | 15 ++++++++++-- SmartPanel.xaml | 4 +++- SmartPanel.xaml.cpp | 54 ++++++++++++++++++++++++++++++++----------- SmartPanel.xaml.h | 2 ++ 10 files changed, 121 insertions(+), 27 deletions(-) diff --git a/Call.cpp b/Call.cpp index 24e4353..6b02ec7 100644 --- a/Call.cpp +++ b/Call.cpp @@ -53,4 +53,14 @@ Call::NotifyPropertyChanged(String^ propertyName) PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName)); })); -} \ No newline at end of file +} + +void RingClientUWP::Call::refuse() +{ + RingD::instance->refuseIncommingCall(this); +} + +void RingClientUWP::Call::accept() +{ + RingD::instance->acceptIncommingCall(this); +} diff --git a/Call.h b/Call.h index aa96993..c0d4fa1 100644 --- a/Call.h +++ b/Call.h @@ -43,6 +43,9 @@ protected: /* properties */ void NotifyPropertyChanged(String^ propertyName); +internal: + void refuse(); + void accept(); }; } diff --git a/CallsViewModel.cpp b/CallsViewModel.cpp index cf6166f..02a4933 100644 --- a/CallsViewModel.cpp +++ b/CallsViewModel.cpp @@ -43,11 +43,11 @@ CallsViewModel::CallsViewModel() if (state == "OVER") { delete call; call->stateChange("", code); - callStatusUpdated(call); + callStatusUpdated(call); // used ? return; } call->stateChange(state, code); - callStatusUpdated(call); + callStatusUpdated(call); // same... return; } } diff --git a/Contact.h b/Contact.h index 517d35c..a88d648 100644 --- a/Contact.h +++ b/Contact.h @@ -83,6 +83,18 @@ public: PropertyChanged(this, ref new PropertyChangedEventArgs("_call")); } } + property Windows::UI::Xaml::GridLength _contactBarHeight + { + Windows::UI::Xaml::GridLength get() + { + return contactBarHeight_; + } + void set(Windows::UI::Xaml::GridLength value) + { + contactBarHeight_ = value; + PropertyChanged(this, ref new PropertyChangedEventArgs("_contactBarHeight")); + } + } internal: void saveConversationToFile(); @@ -97,7 +109,7 @@ private: Conversation^ conversation_; Visibility notificationNewMessage_; unsigned int unreadMessages_; - Windows::UI::Xaml::GridLength contactBarHeight_; + Windows::UI::Xaml::GridLength contactBarHeight_ = 0; Call^ call_; }; } diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 68141b5..7ac6dc8 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -79,6 +79,8 @@ ContactsViewModel::ContactsViewModel() return; } contact->_call = call; + contact->_contactBarHeight = 50; + }); } diff --git a/RingD.cpp b/RingD.cpp index ea6db14..3abac15 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -102,6 +102,7 @@ void RingClientUWP::RingD::sendAccountTextMessage(String^ message) void RingD::createRINGAccount(String^ alias) { + // refactoring : create a dedicated class constructor task and removes accountName from RingD accountName = Utils::toString(alias); tasksList_.push(ref new RingD::Task(Request::AddRingAccount)); } @@ -109,10 +110,21 @@ RingD::createRINGAccount(String^ alias) void RingD::createSIPAccount(String^ alias) { + // refactoring : create a dedicated class constructor task and removes accountName from RingD accountName = Utils::toString(alias); tasksList_.push(ref new RingD::Task(Request::AddSIPAccount)); } +void RingClientUWP::RingD::refuseIncommingCall(Call^ call) +{ + tasksList_.push(ref new RingD::Task(Request::RefuseIncommingCall, call)); +} + +void RingClientUWP::RingD::acceptIncommingCall(Call^ call) +{ + tasksList_.push(ref new RingD::Task(Request::AcceptIncommingCall, call)); +} + void RingClientUWP::RingD::startDaemon() { @@ -191,13 +203,13 @@ RingClientUWP::RingD::startDaemon() } }), DRing::exportable_callback<DRing::ConfigurationSignal::RegistrationStateChanged>([this]( - const std::string& account_id, const std::string& state, - int detailsCode, const std::string& detailsStr) + const std::string& account_id, const std::string& state, + int detailsCode, const std::string& detailsStr) { MSG_("<RegistrationStateChanged>: ID = " + account_id + "state = " + state); if (state == DRing::Account::States::UNREGISTERED) { CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, - ref new DispatchedHandler([=]() { + ref new DispatchedHandler([=]() { reloadAccountList(); })); } @@ -228,8 +240,7 @@ RingClientUWP::RingD::startDaemon() 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)); if (!DRing::start()) { ERR_("\ndaemon didn't start.\n"); @@ -267,7 +278,8 @@ RingD::dequeueTasks() { for (int i = 0; i < tasksList_.size(); i++) { auto task = tasksList_.front(); - switch (task->request) { + auto request = dynamic_cast<Task^>(task)->request; + switch (request) { case Request::None: break; case Request::AddRingAccount: @@ -286,6 +298,20 @@ RingD::dequeueTasks() DRing::addAccount(sipAccountDetails); } break; + case Request::RefuseIncommingCall: + { + auto callId = task->_call->callId; + auto callId2 = Utils::toString(callId); + DRing::refuse(callId2); + } + break; + case Request::AcceptIncommingCall: + { + auto callId = task->_call->callId; + auto callId2 = Utils::toString(callId); + DRing::accept(callId2); + } + break; default: break; } diff --git a/RingD.h b/RingD.h index 4026c54..ceff044 100644 --- a/RingD.h +++ b/RingD.h @@ -58,6 +58,8 @@ internal: void sendAccountTextMessage(String^ message); void createRINGAccount(String^ alias); void createSIPAccount(String^ alias); + void refuseIncommingCall(Call^ call); + void acceptIncommingCall(Call^ call); /* TODO : move members */ bool hasConfig; @@ -73,14 +75,23 @@ private: enum class Request { None, AddRingAccount, - AddSIPAccount + AddSIPAccount, + RefuseIncommingCall, + AcceptIncommingCall }; ref class Task { internal: - Task(Request r) { request = r; } + Task(Request r) { + request = r; + } + Task(Request r, Call^ c) { + request = r; + _call = c; + } public: property Request request; + property Call^ _call; }; /* functions */ diff --git a/SmartPanel.xaml b/SmartPanel.xaml index d113973..65d0543 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -32,7 +32,7 @@ <RowDefinition Height="60"/> <!-- use the height of _contactBar_ to make it visible or collapsed. --> <RowDefinition x:Name="_contactBar_" - Height="0"/> + Height="{x:Bind _contactBarHeight, Mode=OneWay}"/> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> @@ -100,10 +100,12 @@ Grid.Row="0" HorizontalAlignment="Center"> <Button x:Name="_acceptIncomingCallBtn_" + Click="_acceptIncomingCallBtn__Click" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Accept"/> <Button x:Name="_rejectIncomingCallBtn_" + Click="_rejectIncomingCallBtn__Click" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Reject"/> diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 2742708..8ee8d73 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -34,6 +34,10 @@ using namespace Windows::UI::Xaml::Media; using namespace Concurrency; using namespace Windows::Foundation; +using namespace Windows::ApplicationModel::Core; +using namespace Windows::Storage; +using namespace Windows::UI::Core; + SmartPanel::SmartPanel() { InitializeComponent(); @@ -138,22 +142,22 @@ void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object switch (_accountTypeComboBox_->SelectedIndex) { case 0: - { - RingD::instance->createRINGAccount(_aliasTextBox_->Text); - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountsMenuButton__Checked(nullptr, nullptr); - break; - } + { + RingD::instance->createRINGAccount(_aliasTextBox_->Text); + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountsMenuButton__Checked(nullptr, nullptr); break; + } + break; case 1: - { - RingD::instance->createSIPAccount(_aliasTextBox_->Text); - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountsMenuButton__Checked(nullptr, nullptr); - break; - } - default: - break; + { + RingD::instance->createSIPAccount(_aliasTextBox_->Text); + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountsMenuButton__Checked(nullptr, nullptr); + break; + } + default: + break; } } @@ -189,3 +193,25 @@ void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sen _ringTxtBx_->Text = ""; } } + + +void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast<Button^>(e->OriginalSource); + auto contact = dynamic_cast<Contact^>(button->DataContext); + auto call = contact->_call; + + call->refuse(); + contact->_contactBarHeight = 0; +} + + +void RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast<Button^>(e->OriginalSource); + auto contact = dynamic_cast<Contact^>(button->DataContext); + auto call = contact->_call; + + call->accept(); + contact->_contactBarHeight = 0; +} diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 29e6a56..1b2f63f 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -53,6 +53,8 @@ private: void _smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void _accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); + void _rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); }; } } \ No newline at end of file -- GitLab