Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 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 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 20 | #include "ContactsViewModel.h"
|
| 21 | #include "MessageTextPage.xaml.h"
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 22 | #include "SmartPanel.xaml.h"
|
| 23 | #include "RingConsolePanel.xaml.h"
|
Nicolas Jager | e069c41 | 2016-08-15 15:00:17 -0400 | [diff] [blame] | 24 | #include "VideoPage.xaml.h"
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 25 | #include "PreviewPage.xaml.h"
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 26 | #include "WelcomePage.xaml.h"
|
| 27 |
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 28 | #include "gnutls\gnutls.h"
|
| 29 |
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 30 | #include "MainPage.xaml.h"
|
| 31 |
|
| 32 | using namespace RingClientUWP;
|
| 33 | using namespace RingClientUWP::Views;
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 34 | using namespace RingClientUWP::ViewModel;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 35 |
|
| 36 | using namespace Platform;
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 37 | using namespace Windows::ApplicationModel::Core;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 38 | using namespace Windows::Foundation;
|
| 39 | using namespace Windows::Foundation::Collections;
|
| 40 | using namespace Windows::UI::ViewManagement;
|
| 41 | using namespace Windows::UI::Xaml;
|
| 42 | using namespace Windows::UI::Xaml::Controls;
|
| 43 | using namespace Windows::UI::Xaml::Controls::Primitives;
|
| 44 | using namespace Windows::UI::Core;
|
| 45 | using namespace Windows::UI::Xaml::Data;
|
| 46 | using namespace Windows::UI::Xaml::Input;
|
| 47 | using namespace Windows::UI::Xaml::Interop;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 48 | using namespace Windows::UI::Xaml::Navigation;
|
| 49 | using namespace Windows::ApplicationModel::Activation;
|
| 50 | using namespace Windows::Graphics::Display;
|
| 51 | using namespace Windows::System;
|
atraczyk | 49f1b57 | 2016-10-27 12:33:28 -0400 | [diff] [blame] | 52 | using namespace Concurrency;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 53 |
|
| 54 | MainPage::MainPage()
|
| 55 | {
|
| 56 | InitializeComponent();
|
| 57 |
|
atraczyk | 49f1b57 | 2016-10-27 12:33:28 -0400 | [diff] [blame] | 58 | UserModel::instance->getUserData();
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 59 |
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 60 | Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::OnResize);
|
| 61 |
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 62 | _welcomeFrame_->Navigate(TypeName(RingClientUWP::Views::WelcomePage::typeid));
|
| 63 | _smartPanel_->Navigate(TypeName(RingClientUWP::Views::SmartPanel::typeid));
|
| 64 | _consolePanel_->Navigate(TypeName(RingClientUWP::Views::RingConsolePanel::typeid));
|
Nicolas Jager | e069c41 | 2016-08-15 15:00:17 -0400 | [diff] [blame] | 65 | _videoFrame_->Navigate(TypeName(RingClientUWP::Views::VideoPage::typeid));
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 66 | _previewFrame_->Navigate(TypeName(RingClientUWP::Views::PreviewPage::typeid));
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 67 | _messageTextFrame_->Navigate(TypeName(RingClientUWP::Views::MessageTextPage::typeid));
|
| 68 |
|
| 69 | /* connect to delegates */
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 70 | RingD::instance->stateChange += ref new RingClientUWP::StateChange(this, &RingClientUWP::MainPage::OnstateChange);
|
| 71 | auto smartPanel = dynamic_cast<SmartPanel^>(_smartPanel_->Content);
|
| 72 | smartPanel->summonMessageTextPage += ref new RingClientUWP::SummonMessageTextPage(this, &RingClientUWP::MainPage::OnsummonMessageTextPage);
|
| 73 | smartPanel->summonWelcomePage += ref new RingClientUWP::SummonWelcomePage(this, &RingClientUWP::MainPage::OnsummonWelcomePage);
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 74 | smartPanel->summonPreviewPage += ref new RingClientUWP::SummonPreviewPage(this, &RingClientUWP::MainPage::OnsummonPreviewPage);
|
| 75 | smartPanel->hidePreviewPage += ref new RingClientUWP::HidePreviewPage(this, &RingClientUWP::MainPage::OnhidePreviewPage);
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 76 | smartPanel->summonVideoPage += ref new RingClientUWP::SummonVideoPage(this, &RingClientUWP::MainPage::OnsummonVideoPage);
|
| 77 | auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
|
| 78 | videoPage->pressHangUpCall += ref new RingClientUWP::PressHangUpCall(this, &RingClientUWP::MainPage::OnpressHangUpCall);
|
Nicolas Jager | e72856b | 2016-10-30 15:06:17 -0400 | [diff] [blame] | 79 | auto messageTextFrame = dynamic_cast<MessageTextPage^>(_messageTextFrame_->Content);
|
| 80 | messageTextFrame->closeMessageTextPage += ref new RingClientUWP::CloseMessageTextPage(this, &RingClientUWP::MainPage::OncloseMessageTextPage);
|
| 81 |
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 82 |
|
| 83 | DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
|
| 84 | dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 85 | Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 86 |
|
| 87 | visibilityChangedEventToken = Window::Current->VisibilityChanged +=
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 88 | ref new WindowVisibilityChangedEventHandler(this, &MainPage::Application_VisibilityChanged);
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 89 | applicationSuspendingEventToken = Application::Current->Suspending +=
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 90 | ref new SuspendingEventHandler(this, &MainPage::Application_Suspending);
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 91 | applicationResumingEventToken = Application::Current->Resuming +=
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 92 | ref new EventHandler<Object^>(this, &MainPage::Application_Resuming);
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 93 | }
|
| 94 |
|
| 95 | void
|
| 96 | MainPage::OnKeyDown(KeyRoutedEventArgs^ e)
|
| 97 | {
|
| 98 | if (e->Key == VirtualKey::F5) {
|
| 99 | _outerSplitView_->OpenPaneLength = Window::Current->Bounds.Width;
|
| 100 | _outerSplitView_->IsPaneOpen = !_outerSplitView_->IsPaneOpen;
|
| 101 | }
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 102 | }
|
| 103 |
|
| 104 | void RingClientUWP::MainPage::_toggleSmartBoxButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 105 | {
|
| 106 | _innerSplitView_->IsPaneOpen = !_innerSplitView_->IsPaneOpen;
|
atraczyk | 0cf42d7 | 2016-09-06 11:16:37 -0400 | [diff] [blame] | 107 | if (_innerSplitView_->IsPaneOpen) {
|
| 108 | dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Normal);
|
| 109 | _hamburgerButtonBar_->Width = 320;
|
| 110 | }
|
| 111 | else {
|
| 112 | dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Minimized);
|
| 113 | _hamburgerButtonBar_->Width = 60;
|
| 114 | }
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 115 | }
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 116 |
|
| 117 | void
|
| 118 | RingClientUWP::MainPage::showFrame(Windows::UI::Xaml::Controls::Frame^ frame)
|
| 119 | {
|
| 120 | _navGrid_->SetRow(_welcomeFrame_, 0);
|
| 121 | _navGrid_->SetRow(_messageTextFrame_, 0);
|
| 122 | _navGrid_->SetRow(_videoFrame_, 0);
|
| 123 |
|
| 124 | if (frame == _welcomeFrame_) {
|
| 125 | _navGrid_->SetRow(_welcomeFrame_, 1);
|
| 126 | } else if (frame == _videoFrame_) {
|
| 127 | _navGrid_->SetRow(_videoFrame_, 1);
|
| 128 | } else if (frame == _messageTextFrame_) {
|
| 129 | _navGrid_->SetRow(_messageTextFrame_, 1);
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 130 | }
|
| 131 | }
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 132 |
|
| 133 | void
|
| 134 | RingClientUWP::MainPage::OnNavigatedTo(NavigationEventArgs ^ e)
|
| 135 | {
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 136 | gnutls_global_init();
|
| 137 | RingD::instance->registerCallbacks();
|
| 138 | RingD::instance->initDaemon( DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG );
|
| 139 | Video::VideoManager::instance->captureManager()->EnumerateWebcamsAsync();
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 140 | showLoadingOverlay(true, false);
|
| 141 | }
|
| 142 |
|
| 143 | void
|
| 144 | RingClientUWP::MainPage::showLoadingOverlay(bool load, bool modal)
|
| 145 | {
|
| 146 | if (!isLoading && load) {
|
| 147 | isLoading = true;
|
| 148 | _loadingOverlay_->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
| 149 | if (modal) {
|
| 150 | _fadeInModalStoryboard_->Begin();
|
| 151 | auto blackBrush = ref new Windows::UI::Xaml::Media::SolidColorBrush(Windows::UI::Colors::Black);
|
| 152 | _loadingOverlayRect_->Fill = blackBrush;
|
| 153 | }
|
| 154 | else {
|
| 155 | auto whiteBrush = ref new Windows::UI::Xaml::Media::SolidColorBrush(Windows::UI::Colors::White);
|
| 156 | _loadingOverlayRect_->Fill = whiteBrush;
|
| 157 | _loadingOverlayRect_->Opacity = 1.0;
|
| 158 | }
|
| 159 | OnResize(nullptr, nullptr);
|
| 160 | }
|
| 161 | else if (!load) {
|
| 162 | isLoading = false;
|
| 163 | _fadeOutStoryboard_->Begin();
|
| 164 | }
|
| 165 | }
|
| 166 |
|
| 167 | void
|
| 168 | RingClientUWP::MainPage::PositionImage()
|
| 169 | {
|
| 170 | bounds = ApplicationView::GetForCurrentView()->VisibleBounds;
|
| 171 |
|
| 172 | auto img = ref new Image();
|
| 173 | auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
|
| 174 | Windows::Foundation::Uri^ uri;
|
| 175 |
|
| 176 | if (bounds.Width < 1200)
|
| 177 | uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/TESTS/logo-ring.scale-200.png");
|
| 178 | else
|
| 179 | uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/TESTS/logo-ring.scale-150.png");
|
| 180 |
|
| 181 | bitmapImage->UriSource = uri;
|
| 182 | img->Source = bitmapImage;
|
| 183 | _loadingImage_->Source = img->Source;
|
| 184 |
|
| 185 | _loadingImage_->SetValue(Canvas::LeftProperty, bounds.Width * 0.5 - _loadingImage_->Width * 0.5);
|
| 186 | _loadingImage_->SetValue(Canvas::TopProperty, bounds.Height * 0.5 - _loadingImage_->Height * 0.5);
|
| 187 | }
|
| 188 |
|
| 189 | void
|
| 190 | RingClientUWP::MainPage::PositionRing()
|
| 191 | {
|
| 192 | double left;
|
| 193 | double top;
|
| 194 | if (bounds.Width < 1200) {
|
| 195 | _splashProgressRing_->Width = 118;
|
| 196 | _splashProgressRing_->Height = 118;
|
| 197 | left = bounds.Width * 0.5 - _loadingImage_->Width * 0.5 - 145;
|
| 198 | top = bounds.Height * 0.5 - _loadingImage_->Height * 0.5 - 60;
|
| 199 | }
|
| 200 | else {
|
| 201 | _splashProgressRing_->Width = 162;
|
| 202 | _splashProgressRing_->Height = 162;
|
| 203 | left = bounds.Width * 0.5 - _loadingImage_->Width * 0.5 - 195;
|
| 204 | top = bounds.Height * 0.5 - _loadingImage_->Height * 0.5 - 84;
|
| 205 | }
|
| 206 | _splashProgressRing_->SetValue(Canvas::LeftProperty, left + _loadingImage_->Width * 0.5);
|
| 207 | _splashProgressRing_->SetValue(Canvas::TopProperty, top + _loadingImage_->Height * 0.5);
|
| 208 | }
|
| 209 |
|
| 210 | void
|
| 211 | RingClientUWP::MainPage::OnResize(Platform::Object^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ e)
|
| 212 | {
|
| 213 | PositionImage();
|
| 214 | PositionRing();
|
| 215 | }
|
| 216 |
|
| 217 | void
|
| 218 | RingClientUWP::MainPage::DisplayProperties_DpiChanged(DisplayInformation^ sender, Platform::Object^ args)
|
| 219 | {
|
| 220 | OnResize(nullptr, nullptr);
|
| 221 | }
|
| 222 |
|
| 223 | void
|
| 224 | RingClientUWP::MainPage::hideLoadingOverlay()
|
| 225 | {
|
| 226 | _loadingOverlay_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 227 | }
|
| 228 |
|
| 229 | void RingClientUWP::MainPage::OnsummonMessageTextPage()
|
| 230 | {
|
| 231 | auto messageTextPage = dynamic_cast<MessageTextPage^>(_messageTextFrame_->Content);
|
| 232 | messageTextPage->updatePageContent();
|
| 233 | showFrame(_messageTextFrame_);
|
| 234 |
|
| 235 | }
|
| 236 |
|
| 237 |
|
| 238 | void RingClientUWP::MainPage::OnsummonWelcomePage()
|
| 239 | {
|
| 240 | showFrame(_welcomeFrame_);
|
| 241 | }
|
| 242 |
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 243 | void RingClientUWP::MainPage::OnsummonPreviewPage()
|
| 244 | {
|
| 245 | WriteLine("Show Settings Preview");
|
| 246 | _previewFrame_->Visibility = VIS::Visible;
|
| 247 | }
|
| 248 |
|
| 249 | void RingClientUWP::MainPage::OnhidePreviewPage()
|
| 250 | {
|
| 251 | WriteLine("Hide Settings Preview");
|
| 252 | _previewFrame_->Visibility = VIS::Collapsed;
|
| 253 | }
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 254 |
|
| 255 | void RingClientUWP::MainPage::OnsummonVideoPage()
|
| 256 | {
|
| 257 | auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
|
| 258 | videoPage->updatePageContent();
|
| 259 | showFrame(_videoFrame_);
|
| 260 | }
|
| 261 |
|
| 262 |
|
| 263 | void RingClientUWP::MainPage::OnpressHangUpCall()
|
| 264 | {
|
| 265 | OnsummonMessageTextPage();
|
| 266 | }
|
| 267 |
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 268 | void RingClientUWP::MainPage::OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code)
|
| 269 | {
|
| 270 | auto item = SmartPanelItemsViewModel::instance->_selectedItem;
|
| 271 |
|
| 272 | switch (state) {
|
| 273 | /* send the user to the peer's message text page */
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 274 | case CallStatus::ENDED:
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 275 | {
|
| 276 | if (item)
|
| 277 | OnsummonMessageTextPage();
|
| 278 | break;
|
| 279 | }
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 280 | default:
|
| 281 | break;
|
| 282 | }
|
| 283 |
|
| 284 | }
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 285 |
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 286 | void
|
| 287 | MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingEventArgs^ e)
|
| 288 | {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 289 | RingDebug::instance->WriteLine("Application_Suspending");
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 290 | if (Frame->CurrentSourcePageType.Name ==
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 291 | Interop::TypeName(MainPage::typeid).Name) {
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 292 | auto deferral = e->SuspendingOperation->GetDeferral();
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 293 | BeginExtendedExecution()
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 294 | .then([=](task<void> previousTask) {
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 295 | try {
|
| 296 | previousTask.get();
|
| 297 | }
|
| 298 | catch (Exception^ e) {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 299 | RingDebug::instance->WriteLine("Exception: Extended Execution Begin");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 300 | }
|
| 301 | })
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 302 | .then([this, deferral](task<void> previousTask) {
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 303 | try {
|
| 304 | previousTask.get();
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 305 | RingDebug::instance->WriteLine("deferral->Complete()");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 306 | deferral->Complete();
|
| 307 | }
|
| 308 | catch (Exception^ e) {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 309 | RingDebug::instance->WriteLine("Exception: Extended Execution");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 310 | deferral->Complete();
|
| 311 | }
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 312 | });
|
| 313 | }
|
| 314 | }
|
| 315 |
|
| 316 | void
|
| 317 | MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventArgs^ e)
|
| 318 | {
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 319 | auto vcm = Video::VideoManager::instance->captureManager();
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 320 | if (e->Visible) {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 321 | RingDebug::instance->WriteLine("->Visible");
|
atraczyk | c8f949a | 2016-10-07 11:34:03 -0400 | [diff] [blame] | 322 | bool isInCall = false;
|
| 323 | for (auto item : SmartPanelItemsViewModel::instance->itemsList) {
|
| 324 | if (item->_callId && item->_callStatus == CallStatus::IN_PROGRESS) {
|
| 325 | isInCall = true;
|
| 326 | break;
|
| 327 | }
|
| 328 | }
|
| 329 | if (isInCall) {
|
| 330 | /*if (RingD::instance->currentCallId)
|
| 331 | RingD::instance->unPauseCall(RingD::instance->currentCallId);*/
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 332 | vcm->InitializeCameraAsync(false);
|
| 333 | vcm->videoFrameCopyInvoker->Start();
|
| 334 | }
|
| 335 | else if (vcm->isSettingsPreviewing) {
|
| 336 | vcm->CleanupCameraAsync()
|
| 337 | .then([=](task<void> cleanupTask){
|
| 338 | cleanupTask.get();
|
| 339 | CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
|
| 340 | CoreDispatcherPriority::High, ref new DispatchedHandler([=]()
|
| 341 | {
|
| 342 | vcm->InitializeCameraAsync(true);
|
| 343 | }));
|
| 344 | });
|
atraczyk | c8f949a | 2016-10-07 11:34:03 -0400 | [diff] [blame] | 345 | }
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 346 | }
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 347 | else {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 348 | RingDebug::instance->WriteLine("->Invisible");
|
atraczyk | c8f949a | 2016-10-07 11:34:03 -0400 | [diff] [blame] | 349 | bool isInCall = false;
|
| 350 | for (auto item : SmartPanelItemsViewModel::instance->itemsList) {
|
| 351 | if (item->_callId && item->_callStatus == CallStatus::IN_PROGRESS) {
|
| 352 | isInCall = true;
|
| 353 | RingD::instance->currentCallId = item->_callId;
|
| 354 | break;
|
| 355 | }
|
| 356 | }
|
| 357 | if (isInCall) {
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 358 | // TODO
|
atraczyk | c8f949a | 2016-10-07 11:34:03 -0400 | [diff] [blame] | 359 | /*if (RingD::instance->currentCallId) {
|
| 360 | WriteLine("Pausing call: " + RingD::instance->currentCallId);
|
| 361 | RingD::instance->pauseCall(RingD::instance->currentCallId);
|
| 362 | }*/
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 363 | if (vcm->isPreviewing) {
|
| 364 | vcm->StopPreviewAsync();
|
| 365 | if (vcm->captureTaskTokenSource)
|
| 366 | vcm->captureTaskTokenSource->cancel();
|
| 367 | vcm->videoFrameCopyInvoker->Stop();
|
atraczyk | c8f949a | 2016-10-07 11:34:03 -0400 | [diff] [blame] | 368 | }
|
| 369 | }
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 370 | else if (vcm->isSettingsPreviewing) {
|
| 371 | vcm->StopPreviewAsync();
|
| 372 | }
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 373 | }
|
Nicolas Jager | 083b3ae | 2016-10-04 08:46:19 -0400 | [diff] [blame] | 374 | }
|
| 375 |
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 376 | void MainPage::Application_Resuming(Object^, Object^)
|
| 377 | {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 378 | RingDebug::instance->WriteLine("Application_Resuming");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 379 | }
|
| 380 |
|
| 381 | void
|
| 382 | MainPage::SessionRevoked(Object^ sender, ExtendedExecutionRevokedEventArgs^ args)
|
| 383 | {
|
| 384 | Dispatcher->RunAsync(CoreDispatcherPriority::High, ref new DispatchedHandler([=]() {
|
| 385 | ClearExtendedExecution();
|
| 386 | }));
|
| 387 | }
|
| 388 |
|
| 389 | void
|
| 390 | MainPage::ClearExtendedExecution()
|
| 391 | {
|
| 392 | if (session != nullptr) {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 393 | RingDebug::instance->WriteLine("End Extended Execution");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 394 | session->Revoked -= sessionRevokedToken;
|
| 395 | }
|
| 396 | }
|
| 397 |
|
| 398 | task<void>
|
| 399 | MainPage::BeginExtendedExecution()
|
| 400 | {
|
| 401 | ClearExtendedExecution();
|
| 402 |
|
| 403 | auto newSession = ref new ExtendedExecutionSession();
|
| 404 | newSession->Reason = ExtendedExecutionReason::SavingData;
|
| 405 | newSession->Description = "Extended Execution";
|
| 406 | sessionRevokedToken = (newSession->Revoked += ref new TypedEventHandler<Object^,
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 407 | ExtendedExecutionRevokedEventArgs^>(this, &MainPage::SessionRevoked));
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 408 | return create_task(newSession->RequestExtensionAsync())
|
atraczyk | 85e1231 | 2016-11-03 10:31:23 -0400 | [diff] [blame] | 409 | .then([=](ExtendedExecutionResult result){
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 410 | try {
|
| 411 | switch (result)
|
| 412 | {
|
| 413 | case ExtendedExecutionResult::Allowed:
|
| 414 | session = newSession;
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 415 | RingDebug::instance->WriteLine("Request Extended Execution Allowed");
|
| 416 | RingDebug::instance->WriteLine("Clean up camera...");
|
atraczyk | acc4c41 | 2016-11-10 22:56:52 -0500 | [diff] [blame^] | 417 | Video::VideoManager::instance->captureManager()->CleanupCameraAsync();
|
| 418 | RingDebug::instance->WriteLine("Hang up calls...");
|
| 419 | DRing::fini();
|
| 420 | gnutls_global_init();
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 421 | break;
|
| 422 |
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 423 | default:
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 424 | case ExtendedExecutionResult::Denied:
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 425 | RingDebug::instance->WriteLine("Request Extended Execution Denied");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 426 | break;
|
| 427 | }
|
| 428 | }
|
| 429 | catch (Exception^ e) {
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 430 | RingDebug::instance->WriteLine("Exception: Extended Execution Request");
|
atraczyk | 6290cc3 | 2016-10-07 08:47:15 -0400 | [diff] [blame] | 431 | }
|
| 432 | });
|
atraczyk | 49f1b57 | 2016-10-27 12:33:28 -0400 | [diff] [blame] | 433 | }
|
Nicolas Jager | e72856b | 2016-10-30 15:06:17 -0400 | [diff] [blame] | 434 |
|
| 435 |
|
| 436 | void RingClientUWP::MainPage::OncloseMessageTextPage()
|
| 437 | {
|
| 438 | auto smartPanel = dynamic_cast<SmartPanel^>(_smartPanel_->Content);
|
| 439 | smartPanel->unselectContact();
|
| 440 | }
|