From 72e8dcbb5418e4414c5971693541761ed70cbc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 17 Jul 2017 16:59:50 +0200 Subject: [PATCH] Finished basic implementation of taskbar. --- .../BrowserApplicationController.cs | 4 +- .../BrowserApplicationInfo.cs | 2 +- .../BrowserIconResource.cs | 2 +- .../Behaviour/IApplicationController.cs | 2 +- .../Behaviour/INotificationController.cs | 20 ++++++++++ .../Configuration/IApplicationInfo.cs | 2 +- ...cationIconResource.cs => IIconResource.cs} | 4 +- .../Configuration/INotificationInfo.cs | 23 +++++++++++ SafeExamBrowser.Contracts/I18n/Key.cs | 1 + .../SafeExamBrowser.Contracts.csproj | 7 +++- .../UserInterface/ITaskbar.cs | 8 +++- ...ApplicationButton.cs => ITaskbarButton.cs} | 2 +- .../UserInterface/ITaskbarNotification.cs | 20 ++++++++++ .../UserInterface/IUiElementFactory.cs | 7 +++- .../Behaviour/StartupController.cs | 28 +++++++------ .../AboutNotificationIconResource.cs | 20 ++++++++++ .../Configuration/AboutNotificationInfo.cs | 26 ++++++++++++ SafeExamBrowser.Core/I18n/Text.xml | 1 + .../SafeExamBrowser.Core.csproj | 2 + .../Controls/ApplicationButton.xaml.cs | 9 ++--- .../ApplicationInstanceButton.xaml.cs | 2 +- .../Controls/DateTimeControl.xaml | 2 +- .../Controls/NotificationIcon.xaml | 28 +++++++++++++ .../Controls/NotificationIcon.xaml.cs | 37 ++++++++++++++++++ .../Controls/QuitButton.xaml | 28 +++++++++++++ .../Controls/QuitButton.xaml.cs | 26 ++++++++++++ .../Images/{Icon.ico => SafeExamBrowser.ico} | Bin .../SafeExamBrowser.UserInterface.csproj | 18 ++++++++- .../SplashScreen.xaml | 2 +- SafeExamBrowser.UserInterface/Taskbar.xaml | 13 ++++-- SafeExamBrowser.UserInterface/Taskbar.xaml.cs | 13 +++++- .../UiElementFactory.cs | 7 +++- ...esourceLoader.cs => IconResourceLoader.cs} | 18 +++------ SafeExamBrowser/CompositionRoot.cs | 8 ++-- SafeExamBrowser/SafeExamBrowser.csproj | 4 +- .../{Icon.ico => SafeExamBrowser.ico} | Bin 36 files changed, 337 insertions(+), 59 deletions(-) create mode 100644 SafeExamBrowser.Contracts/Behaviour/INotificationController.cs rename SafeExamBrowser.Contracts/Configuration/{IApplicationIconResource.cs => IIconResource.cs} (88%) create mode 100644 SafeExamBrowser.Contracts/Configuration/INotificationInfo.cs rename SafeExamBrowser.Contracts/UserInterface/{IApplicationButton.cs => ITaskbarButton.cs} (97%) create mode 100644 SafeExamBrowser.Contracts/UserInterface/ITaskbarNotification.cs create mode 100644 SafeExamBrowser.Core/Configuration/AboutNotificationIconResource.cs create mode 100644 SafeExamBrowser.Core/Configuration/AboutNotificationInfo.cs create mode 100644 SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml create mode 100644 SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml.cs create mode 100644 SafeExamBrowser.UserInterface/Controls/QuitButton.xaml create mode 100644 SafeExamBrowser.UserInterface/Controls/QuitButton.xaml.cs rename SafeExamBrowser.UserInterface/Images/{Icon.ico => SafeExamBrowser.ico} (100%) rename SafeExamBrowser.UserInterface/Utilities/{ApplicationIconResourceLoader.cs => IconResourceLoader.cs} (73%) rename SafeExamBrowser/{Icon.ico => SafeExamBrowser.ico} (100%) diff --git a/SafeExamBrowser.Browser/BrowserApplicationController.cs b/SafeExamBrowser.Browser/BrowserApplicationController.cs index 8556c8b9..f58eef63 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationController.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationController.cs @@ -14,9 +14,9 @@ namespace SafeExamBrowser.Browser { public class BrowserApplicationController : IApplicationController { - private IApplicationButton button; + private ITaskbarButton button; - public void RegisterApplicationButton(IApplicationButton button) + public void RegisterApplicationButton(ITaskbarButton button) { this.button = button; this.button.OnClick += ButtonClick; diff --git a/SafeExamBrowser.Browser/BrowserApplicationInfo.cs b/SafeExamBrowser.Browser/BrowserApplicationInfo.cs index 23661e5a..ea4562e0 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInfo.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInfo.cs @@ -14,6 +14,6 @@ namespace SafeExamBrowser.Browser { public string Name => "Chromium Browser"; public string Tooltip => Name; - public IApplicationIconResource IconResource { get; } = new BrowserIconResource(); + public IIconResource IconResource { get; } = new BrowserIconResource(); } } diff --git a/SafeExamBrowser.Browser/BrowserIconResource.cs b/SafeExamBrowser.Browser/BrowserIconResource.cs index f34ad241..5a12659b 100644 --- a/SafeExamBrowser.Browser/BrowserIconResource.cs +++ b/SafeExamBrowser.Browser/BrowserIconResource.cs @@ -11,7 +11,7 @@ using SafeExamBrowser.Contracts.Configuration; namespace SafeExamBrowser.Browser { - public class BrowserIconResource : IApplicationIconResource + public class BrowserIconResource : IIconResource { public Uri Uri => new Uri("pack://application:,,,/SafeExamBrowser.Browser;component/Images/ChromiumLogo.xaml"); public bool IsBitmapResource => false; diff --git a/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs b/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs index b57dd74a..a2324799 100644 --- a/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs @@ -15,6 +15,6 @@ namespace SafeExamBrowser.Contracts.Behaviour /// /// Registers the taskbar button for this application. /// - void RegisterApplicationButton(IApplicationButton button); + void RegisterApplicationButton(ITaskbarButton button); } } diff --git a/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs b/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs new file mode 100644 index 00000000..60a89427 --- /dev/null +++ b/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs @@ -0,0 +1,20 @@ +/* + * 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 SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Contracts.Behaviour +{ + public interface INotificationController + { + /// + /// Registers the taskbar notification. + /// + void RegisterNotification(ITaskbarNotification notification); + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs b/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs index d00de367..93d27f93 100644 --- a/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs +++ b/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs @@ -23,6 +23,6 @@ namespace SafeExamBrowser.Contracts.Configuration /// /// The resource providing the application icon. /// - IApplicationIconResource IconResource { get; } + IIconResource IconResource { get; } } } diff --git a/SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs b/SafeExamBrowser.Contracts/Configuration/IIconResource.cs similarity index 88% rename from SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs rename to SafeExamBrowser.Contracts/Configuration/IIconResource.cs index d5a26c82..4f24cff1 100644 --- a/SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs +++ b/SafeExamBrowser.Contracts/Configuration/IIconResource.cs @@ -10,10 +10,10 @@ using System; namespace SafeExamBrowser.Contracts.Configuration { - public interface IApplicationIconResource + public interface IIconResource { /// - /// The Uri pointing to the application icon. + /// The Uri pointing to the icon. /// Uri Uri { get; } diff --git a/SafeExamBrowser.Contracts/Configuration/INotificationInfo.cs b/SafeExamBrowser.Contracts/Configuration/INotificationInfo.cs new file mode 100644 index 00000000..8125449c --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/INotificationInfo.cs @@ -0,0 +1,23 @@ +/* + * 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/. + */ + +namespace SafeExamBrowser.Contracts.Configuration +{ + public interface INotificationInfo + { + /// + /// The tooltip for the notification. + /// + string Tooltip { get; } + + /// + /// The resource providing the notification icon. + /// + IIconResource IconResource { get; } + } +} diff --git a/SafeExamBrowser.Contracts/I18n/Key.cs b/SafeExamBrowser.Contracts/I18n/Key.cs index 3ef9f78c..832dfe5e 100644 --- a/SafeExamBrowser.Contracts/I18n/Key.cs +++ b/SafeExamBrowser.Contracts/I18n/Key.cs @@ -19,6 +19,7 @@ namespace SafeExamBrowser.Contracts.I18n MessageBox_SingleInstanceTitle, MessageBox_StartupError, MessageBox_StartupErrorTitle, + Notification_AboutTooltip, SplashScreen_InitializeBrowser, SplashScreen_StartupProcedure, Version diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index 61eeb7a4..bb6b714b 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -41,9 +41,11 @@ - + + + @@ -57,11 +59,12 @@ + - + diff --git a/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs b/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs index dc79083a..d9463764 100644 --- a/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs +++ b/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs @@ -13,7 +13,13 @@ namespace SafeExamBrowser.Contracts.UserInterface /// /// Adds the given application button to the taskbar. /// - void AddButton(IApplicationButton button); + void AddButton(ITaskbarButton button); + + /// + /// Adds the given notification button to the taskbar. + /// + /// + void AddNotification(ITaskbarNotification button); /// /// Moves the taskbar to the given location on the screen. diff --git a/SafeExamBrowser.Contracts/UserInterface/IApplicationButton.cs b/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs similarity index 97% rename from SafeExamBrowser.Contracts/UserInterface/IApplicationButton.cs rename to SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs index c79403b8..5e9da8a3 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IApplicationButton.cs +++ b/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs @@ -13,7 +13,7 @@ namespace SafeExamBrowser.Contracts.UserInterface { public delegate void TaskbarButtonClickHandler(Guid? instanceId = null); - public interface IApplicationButton + public interface ITaskbarButton { /// /// OnClick handler, executed when the user clicks on the application button. If multiple instances of diff --git a/SafeExamBrowser.Contracts/UserInterface/ITaskbarNotification.cs b/SafeExamBrowser.Contracts/UserInterface/ITaskbarNotification.cs new file mode 100644 index 00000000..7271ac96 --- /dev/null +++ b/SafeExamBrowser.Contracts/UserInterface/ITaskbarNotification.cs @@ -0,0 +1,20 @@ +/* + * 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/. + */ + +namespace SafeExamBrowser.Contracts.UserInterface +{ + public delegate void TaskbarNotificationClickHandler(); + + public interface ITaskbarNotification + { + /// + /// OnClick handler, executed when the user clicks on the notification icon. + /// + event TaskbarNotificationClickHandler OnClick; + } +} diff --git a/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs b/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs index 6931871f..a0b4177c 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs @@ -15,6 +15,11 @@ namespace SafeExamBrowser.Contracts.UserInterface /// /// Creates a taskbar button, initialized with the given application information. /// - IApplicationButton CreateApplicationButton(IApplicationInfo info); + ITaskbarButton CreateApplicationButton(IApplicationInfo info); + + /// + /// Creates a taskbar notification, initialized with the given notification information. + /// + ITaskbarNotification CreateNotification(INotificationInfo info); } } diff --git a/SafeExamBrowser.Core/Behaviour/StartupController.cs b/SafeExamBrowser.Core/Behaviour/StartupController.cs index 1efbf712..3c7b3535 100644 --- a/SafeExamBrowser.Core/Behaviour/StartupController.cs +++ b/SafeExamBrowser.Core/Behaviour/StartupController.cs @@ -24,6 +24,7 @@ namespace SafeExamBrowser.Core.Behaviour private IApplicationInfo browserInfo; private ILogger logger; private IMessageBox messageBox; + private INotificationInfo aboutInfo; private ISettings settings; private ISplashScreen splashScreen; private ITaskbar taskbar; @@ -51,21 +52,23 @@ namespace SafeExamBrowser.Core.Behaviour IApplicationInfo browserInfo, ILogger logger, IMessageBox messageBox, + INotificationInfo aboutInfo, ISettings settings, ISplashScreen splashScreen, ITaskbar taskbar, IText text, IUiElementFactory uiFactory) { - this.browserController = browserController ?? throw new ArgumentNullException(nameof(browserController)); - this.browserInfo = browserInfo ?? throw new ArgumentNullException(nameof(browserInfo)); - this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); ; - this.messageBox = messageBox ?? throw new ArgumentNullException(nameof(messageBox)); ; - this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); ; - this.splashScreen = splashScreen ?? throw new ArgumentNullException(nameof(splashScreen)); ; - this.taskbar = taskbar ?? throw new ArgumentNullException(nameof(taskbar)); ; - this.text = text ?? throw new ArgumentNullException(nameof(text)); ; - this.uiFactory = uiFactory ?? throw new ArgumentNullException(nameof(uiFactory)); ; + this.browserController = browserController; + this.browserInfo = browserInfo; + this.logger = logger; + this.messageBox = messageBox; + this.aboutInfo = aboutInfo; + this.settings = settings; + this.splashScreen = splashScreen; + this.taskbar = taskbar; + this.text = text; + this.uiFactory = uiFactory; } public bool TryInitializeApplication() @@ -166,7 +169,9 @@ namespace SafeExamBrowser.Core.Behaviour { logger.Info("Initializing taskbar."); - // TODO + var aboutNotification = uiFactory.CreateNotification(aboutInfo); + + taskbar.AddNotification(aboutNotification); } private void InitializeBrowser() @@ -177,9 +182,6 @@ namespace SafeExamBrowser.Core.Behaviour var browserButton = uiFactory.CreateApplicationButton(browserInfo); browserController.RegisterApplicationButton(browserButton); - - // TODO - taskbar.AddButton(browserButton); } diff --git a/SafeExamBrowser.Core/Configuration/AboutNotificationIconResource.cs b/SafeExamBrowser.Core/Configuration/AboutNotificationIconResource.cs new file mode 100644 index 00000000..c0eefc69 --- /dev/null +++ b/SafeExamBrowser.Core/Configuration/AboutNotificationIconResource.cs @@ -0,0 +1,20 @@ +/* + * 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 SafeExamBrowser.Contracts.Configuration; + +namespace SafeExamBrowser.Core.Configuration +{ + public class AboutNotificationIconResource : IIconResource + { + public Uri Uri => new Uri("pack://application:,,,/SafeExamBrowser;component/SafeExamBrowser.ico"); + public bool IsBitmapResource => true; + public bool IsXamlResource => false; + } +} diff --git a/SafeExamBrowser.Core/Configuration/AboutNotificationInfo.cs b/SafeExamBrowser.Core/Configuration/AboutNotificationInfo.cs new file mode 100644 index 00000000..2594fa57 --- /dev/null +++ b/SafeExamBrowser.Core/Configuration/AboutNotificationInfo.cs @@ -0,0 +1,26 @@ +/* + * 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 SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.I18n; + +namespace SafeExamBrowser.Core.Configuration +{ + public class AboutNotificationInfo : INotificationInfo + { + private IText text; + + public string Tooltip => text.Get(Key.Notification_AboutTooltip); + public IIconResource IconResource { get; } = new AboutNotificationIconResource(); + + public AboutNotificationInfo(IText text) + { + this.text = text; + } + } +} diff --git a/SafeExamBrowser.Core/I18n/Text.xml b/SafeExamBrowser.Core/I18n/Text.xml index ec535e8f..acc6147b 100644 --- a/SafeExamBrowser.Core/I18n/Text.xml +++ b/SafeExamBrowser.Core/I18n/Text.xml @@ -4,6 +4,7 @@ Shutdown Error An unexpected error occurred during the startup procedure! Please consult the application log for more information... Startup Error + About Safe Exam Browser Initializing browser. Initiating startup procedure. Version diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index 36b64c06..a33eced1 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -40,6 +40,8 @@ + + diff --git a/SafeExamBrowser.UserInterface/Controls/ApplicationButton.xaml.cs b/SafeExamBrowser.UserInterface/Controls/ApplicationButton.xaml.cs index 95aab8e5..f3dba797 100644 --- a/SafeExamBrowser.UserInterface/Controls/ApplicationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface/Controls/ApplicationButton.xaml.cs @@ -14,11 +14,10 @@ using System.Windows.Controls; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.UserInterface.Utilities; -using System.Windows.Media; namespace SafeExamBrowser.UserInterface.Controls { - public partial class ApplicationButton : UserControl, IApplicationButton + public partial class ApplicationButton : UserControl, ITaskbarButton { private IApplicationInfo info; private IList instances = new List(); @@ -57,10 +56,11 @@ namespace SafeExamBrowser.UserInterface.Controls private void InitializeApplicationButton() { Button.ToolTip = info.Tooltip; - Button.Content = ApplicationIconResourceLoader.Load(info.IconResource); + Button.Content = IconResourceLoader.Load(info.IconResource); - Button.MouseLeave += (o, args) => InstancePopup.IsOpen = InstancePopup.IsMouseOver; + Button.MouseLeave += (o, args) => InstancePopup.IsOpen &= InstancePopup.IsMouseOver || ActiveBar.IsMouseOver; InstancePopup.MouseLeave += (o, args) => InstancePopup.IsOpen = false; + InstancePopup.Opened += (o, args) => ActiveBar.Width = Double.NaN; InstancePopup.Closed += (o, args) => ActiveBar.Width = 40; InstanceStackPanel.SizeChanged += (o, args) => { @@ -80,7 +80,6 @@ namespace SafeExamBrowser.UserInterface.Controls else { InstancePopup.IsOpen = true; - ActiveBar.Width = Double.NaN; } } } diff --git a/SafeExamBrowser.UserInterface/Controls/ApplicationInstanceButton.xaml.cs b/SafeExamBrowser.UserInterface/Controls/ApplicationInstanceButton.xaml.cs index 3a82cfd5..17ae5dbc 100644 --- a/SafeExamBrowser.UserInterface/Controls/ApplicationInstanceButton.xaml.cs +++ b/SafeExamBrowser.UserInterface/Controls/ApplicationInstanceButton.xaml.cs @@ -33,7 +33,7 @@ namespace SafeExamBrowser.UserInterface.Controls private void InitializeApplicationInstanceButton() { - Icon.Content = ApplicationIconResourceLoader.Load(info.IconResource); + Icon.Content = IconResourceLoader.Load(info.IconResource); Text.Text = instance.Name; Button.ToolTip = $"{instance.Name} - {info.Tooltip}"; } diff --git a/SafeExamBrowser.UserInterface/Controls/DateTimeControl.xaml b/SafeExamBrowser.UserInterface/Controls/DateTimeControl.xaml index 11983e9c..e5d93b53 100644 --- a/SafeExamBrowser.UserInterface/Controls/DateTimeControl.xaml +++ b/SafeExamBrowser.UserInterface/Controls/DateTimeControl.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls" mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="75"> - + diff --git a/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml b/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml new file mode 100644 index 00000000..8d783f52 --- /dev/null +++ b/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml @@ -0,0 +1,28 @@ + + + + + diff --git a/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml.cs b/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml.cs new file mode 100644 index 00000000..8e81ca5f --- /dev/null +++ b/SafeExamBrowser.UserInterface/Controls/NotificationIcon.xaml.cs @@ -0,0 +1,37 @@ +/* + * 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.Windows.Controls; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.UserInterface.Utilities; + +namespace SafeExamBrowser.UserInterface.Controls +{ + public partial class NotificationIcon : UserControl, ITaskbarNotification + { + public event TaskbarNotificationClickHandler OnClick; + + public NotificationIcon(INotificationInfo info) + { + InitializeComponent(); + InitializeNotificationIcon(info); + } + + private void Icon_Click(object sender, System.Windows.RoutedEventArgs e) + { + OnClick?.Invoke(); + } + + private void InitializeNotificationIcon(INotificationInfo info) + { + IconButton.ToolTip = info.Tooltip; + IconButton.Content = IconResourceLoader.Load(info.IconResource); + } + } +} diff --git a/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml b/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml new file mode 100644 index 00000000..75d33930 --- /dev/null +++ b/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml @@ -0,0 +1,28 @@ + + + + + diff --git a/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml.cs b/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml.cs new file mode 100644 index 00000000..71315caa --- /dev/null +++ b/SafeExamBrowser.UserInterface/Controls/QuitButton.xaml.cs @@ -0,0 +1,26 @@ +/* + * 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.Windows; +using System.Windows.Controls; + +namespace SafeExamBrowser.UserInterface.Controls +{ + public partial class QuitButton : UserControl + { + public QuitButton() + { + InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + Application.Current.Shutdown(); + } + } +} diff --git a/SafeExamBrowser.UserInterface/Images/Icon.ico b/SafeExamBrowser.UserInterface/Images/SafeExamBrowser.ico similarity index 100% rename from SafeExamBrowser.UserInterface/Images/Icon.ico rename to SafeExamBrowser.UserInterface/Images/SafeExamBrowser.ico diff --git a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj index ce6291c1..618e18ba 100644 --- a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj +++ b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj @@ -56,6 +56,12 @@ ApplicationButton.xaml + + NotificationIcon.xaml + + + QuitButton.xaml + Code @@ -76,7 +82,7 @@ Taskbar.xaml - + @@ -102,6 +108,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -121,7 +135,7 @@ - + \ No newline at end of file diff --git a/SafeExamBrowser.UserInterface/SplashScreen.xaml b/SafeExamBrowser.UserInterface/SplashScreen.xaml index 27c2dbb4..51421177 100644 --- a/SafeExamBrowser.UserInterface/SplashScreen.xaml +++ b/SafeExamBrowser.UserInterface/SplashScreen.xaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="SplashScreen" Height="200" Width="350" WindowStyle="None" AllowsTransparency="True" WindowStartupLocation="CenterScreen" Cursor="Wait" Icon="./Images/Icon.ico"> + Title="SplashScreen" Height="200" Width="350" WindowStyle="None" AllowsTransparency="True" WindowStartupLocation="CenterScreen" Cursor="Wait" Icon="./Images/SafeExamBrowser.ico"> diff --git a/SafeExamBrowser.UserInterface/Taskbar.xaml b/SafeExamBrowser.UserInterface/Taskbar.xaml index 9026327a..3ae51816 100644 --- a/SafeExamBrowser.UserInterface/Taskbar.xaml +++ b/SafeExamBrowser.UserInterface/Taskbar.xaml @@ -6,15 +6,15 @@ xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls" xmlns:s="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" - Title="Taskbar" Height="40" Width="750" WindowStyle="None" AllowsTransparency="True" Topmost="True" Icon="./Images/Icon.ico"> + Title="Taskbar" Height="40" Width="750" WindowStyle="None" AllowsTransparency="True" Topmost="True" Icon="./Images/SafeExamBrowser.ico"> - - + + @@ -23,6 +23,13 @@ + + + 5 + + + + diff --git a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs index b0da237a..6ed2a950 100644 --- a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs @@ -7,6 +7,7 @@ */ using System.Windows; +using System.Windows.Input; using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.UserInterface @@ -18,7 +19,7 @@ namespace SafeExamBrowser.UserInterface InitializeComponent(); } - public void AddButton(IApplicationButton button) + public void AddButton(ITaskbarButton button) { if (button is UIElement) { @@ -26,6 +27,14 @@ namespace SafeExamBrowser.UserInterface } } + public void AddNotification(ITaskbarNotification button) + { + if (button is UIElement) + { + NotificationWrapPanel.Children.Add(button as UIElement); + } + } + public void SetPosition(int x, int y) { Left = x; @@ -38,7 +47,7 @@ namespace SafeExamBrowser.UserInterface Height = height; } - private void ApplicationScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) + private void ApplicationScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { var scrollAmount = 20; diff --git a/SafeExamBrowser.UserInterface/UiElementFactory.cs b/SafeExamBrowser.UserInterface/UiElementFactory.cs index 3f4c2b7b..a0f00f69 100644 --- a/SafeExamBrowser.UserInterface/UiElementFactory.cs +++ b/SafeExamBrowser.UserInterface/UiElementFactory.cs @@ -14,9 +14,14 @@ namespace SafeExamBrowser.UserInterface { public class UiElementFactory : IUiElementFactory { - public IApplicationButton CreateApplicationButton(IApplicationInfo info) + public ITaskbarButton CreateApplicationButton(IApplicationInfo info) { return new ApplicationButton(info); } + + public ITaskbarNotification CreateNotification(INotificationInfo info) + { + return new NotificationIcon(info); + } } } diff --git a/SafeExamBrowser.UserInterface/Utilities/ApplicationIconResourceLoader.cs b/SafeExamBrowser.UserInterface/Utilities/IconResourceLoader.cs similarity index 73% rename from SafeExamBrowser.UserInterface/Utilities/ApplicationIconResourceLoader.cs rename to SafeExamBrowser.UserInterface/Utilities/IconResourceLoader.cs index 88762ac5..cba02954 100644 --- a/SafeExamBrowser.UserInterface/Utilities/ApplicationIconResourceLoader.cs +++ b/SafeExamBrowser.UserInterface/Utilities/IconResourceLoader.cs @@ -15,22 +15,16 @@ using SafeExamBrowser.Contracts.Configuration; namespace SafeExamBrowser.UserInterface.Utilities { - internal static class ApplicationIconResourceLoader + internal static class IconResourceLoader { - internal static UIElement Load(IApplicationIconResource resource) + internal static UIElement Load(IIconResource resource) { if (resource.IsBitmapResource) { - var icon = new BitmapImage(); - var iconImage = new Image(); - - icon.BeginInit(); - icon.UriSource = resource.Uri; - icon.EndInit(); - - iconImage.Source = icon; - - return iconImage; + return new Image + { + Source = new BitmapImage(resource.Uri) + }; } else if (resource.IsXamlResource) { diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index de33cdd2..ce6f5c55 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -25,6 +25,7 @@ namespace SafeExamBrowser private IApplicationController browserController; private IApplicationInfo browserInfo; private IMessageBox messageBox; + private INotificationInfo aboutInfo; private ILogger logger; private IUiElementFactory uiFactory; @@ -45,15 +46,16 @@ namespace SafeExamBrowser { browserController = new BrowserApplicationController(); browserInfo = new BrowserApplicationInfo(); - messageBox = new WpfMessageBox(); logger = new Logger(); - uiFactory = new UiElementFactory(); + messageBox = new WpfMessageBox(); Taskbar = new Taskbar(); + uiFactory = new UiElementFactory(); logger.Subscribe(new LogFileWriter(Settings)); + aboutInfo = new AboutNotificationInfo(Text); ShutdownController = new ShutdownController(logger, messageBox, Text); - StartupController = new StartupController(browserController, browserInfo, logger, messageBox, Settings, SplashScreen, Taskbar, Text, uiFactory); + StartupController = new StartupController(browserController, browserInfo, logger, messageBox, aboutInfo, Settings, SplashScreen, Taskbar, Text, uiFactory); } } } diff --git a/SafeExamBrowser/SafeExamBrowser.csproj b/SafeExamBrowser/SafeExamBrowser.csproj index 75e35ec9..af8765a8 100644 --- a/SafeExamBrowser/SafeExamBrowser.csproj +++ b/SafeExamBrowser/SafeExamBrowser.csproj @@ -52,7 +52,7 @@ SafeExamBrowser.App - Icon.ico + SafeExamBrowser.ico @@ -129,7 +129,7 @@ - + \ No newline at end of file diff --git a/SafeExamBrowser/Icon.ico b/SafeExamBrowser/SafeExamBrowser.ico similarity index 100% rename from SafeExamBrowser/Icon.ico rename to SafeExamBrowser/SafeExamBrowser.ico