diff --git a/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs index 4ff4288e..f24e4a73 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs @@ -59,13 +59,10 @@ namespace SafeExamBrowser.Core.Behaviour.Operations CreateLogNotification(); } - // TODO: - //CreateAboutNotification(); - - //if (systemInfo.HasBattery) - //{ - // CreatePowerSupplyComponent(); - //} + if (systemInfo.HasBattery) + { + CreatePowerSupplyComponent(); + } } public void Revert() @@ -90,17 +87,6 @@ namespace SafeExamBrowser.Core.Behaviour.Operations taskbar.AddNotification(logNotification); } - private void CreateAboutNotification() - { - var aboutInfo = new AboutNotificationInfo(text); - var aboutNotification = uiFactory.CreateNotification(aboutInfo); - - aboutController = new AboutNotificationController(settings, text, uiFactory); - aboutController.RegisterNotification(aboutNotification); - - taskbar.AddNotification(aboutNotification); - } - private void CreatePowerSupplyComponent() { var control = uiFactory.CreatePowerSupplyControl(); diff --git a/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml b/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml new file mode 100644 index 00000000..727c1b26 --- /dev/null +++ b/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml.cs b/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml.cs new file mode 100644 index 00000000..35823ed0 --- /dev/null +++ b/SafeExamBrowser.UserInterface.Classic/Controls/PowerSupplyControl.xaml.cs @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Threading; +using SafeExamBrowser.Contracts.SystemComponents; +using SafeExamBrowser.Contracts.UserInterface.Taskbar; + +namespace SafeExamBrowser.UserInterface.Classic.Controls +{ + public partial class PowerSupplyControl : UserControl, ISystemPowerSupplyControl + { + private double BATTERY_CHARGE_MAX_WIDTH; + + public PowerSupplyControl() + { + InitializeComponent(); + BATTERY_CHARGE_MAX_WIDTH = BatteryCharge.Width; + } + + public void Close() + { + Popup.IsOpen = false; + } + + public void SetBatteryCharge(double charge, BatteryChargeStatus status) + { + Dispatcher.BeginInvoke(new Action(() => + { + var width = BATTERY_CHARGE_MAX_WIDTH * charge; + + width = width > BATTERY_CHARGE_MAX_WIDTH ? BATTERY_CHARGE_MAX_WIDTH : width; + width = width < 0 ? 0 : width; + + BatteryCharge.Width = width; + BatteryCharge.Fill = status == BatteryChargeStatus.Low ? Brushes.Orange : BatteryCharge.Fill; + BatteryCharge.Fill = status == BatteryChargeStatus.Critical ? Brushes.Red : BatteryCharge.Fill; + Warning.Visibility = status == BatteryChargeStatus.Critical ? Visibility.Visible : Visibility.Collapsed; + })); + } + + public void SetPowerGridConnection(bool connected) + { + Dispatcher.BeginInvoke(new Action(() => PowerPlug.Visibility = connected ? Visibility.Visible : Visibility.Collapsed)); + } + + public void SetTooltip(string text) + { + Dispatcher.BeginInvoke(new Action(() => Button.ToolTip = text)); + } + + public void ShowCriticalBatteryWarning(string warning) + { + Dispatcher.BeginInvoke(new Action(() => ShowPopup(warning))); + } + + public void ShowLowBatteryInfo(string info) + { + Dispatcher.BeginInvoke(new Action(() => ShowPopup(info))); + } + + private void ShowPopup(string text) + { + Popup.IsOpen = true; + PopupText.Text = text; + Background = Brushes.LightGray; + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + Popup.IsOpen = false; + Background = Brushes.Transparent; + } + } +} diff --git a/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj b/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj index d89dfd61..577c295d 100644 --- a/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj +++ b/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj @@ -81,6 +81,9 @@ NotificationButton.xaml + + PowerSupplyControl.xaml + QuitButton.xaml @@ -121,6 +124,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/SafeExamBrowser.UserInterface.Classic/Templates/Buttons.xaml b/SafeExamBrowser.UserInterface.Classic/Templates/Buttons.xaml index 223954fb..bd7d1ec7 100644 --- a/SafeExamBrowser.UserInterface.Classic/Templates/Buttons.xaml +++ b/SafeExamBrowser.UserInterface.Classic/Templates/Buttons.xaml @@ -1,12 +1,11 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + BorderThickness="1" Cursor="Hand" Padding="{TemplateBinding Padding}"> @@ -18,6 +17,7 @@ + diff --git a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs index 2a5f34fe..bbd1b9c2 100644 --- a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; using System.Threading; using System.Windows; using SafeExamBrowser.Contracts.Configuration; @@ -68,8 +67,7 @@ namespace SafeExamBrowser.UserInterface.Classic public ISystemPowerSupplyControl CreatePowerSupplyControl() { - // TODO: - throw new NotImplementedException(); + return new PowerSupplyControl(); } public ISplashScreen CreateSplashScreen(ISettings settings, IText text)