From 6861353b64550bd186c14868aac742a66c372211 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 2 Aug 2017 10:13:23 +0200 Subject: [PATCH] Implemented draft of the about window. --- .../SafeExamBrowser.Configuration.csproj | 2 - .../Behaviour/INotificationController.cs | 5 ++ .../UserInterface/IUserInterfaceFactory.cs | 5 ++ .../Behaviour/Operations/TaskbarOperation.cs | 18 ++++-- .../AboutNotificationController.cs | 59 +++++++++++++++++++ .../AboutNotificationIconResource.cs | 2 +- .../Notifications}/AboutNotificationInfo.cs | 2 +- .../SafeExamBrowser.Core.csproj | 3 + .../AboutWindow.xaml | 41 +++++++++++++ .../AboutWindow.xaml.cs | 52 ++++++++++++++++ .../SafeExamBrowser.UserInterface.csproj | 7 +++ .../UserInterfaceFactory.cs | 5 ++ SafeExamBrowser/CompositionRoot.cs | 4 +- 13 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 SafeExamBrowser.Core/Notifications/AboutNotificationController.cs rename {SafeExamBrowser.Configuration => SafeExamBrowser.Core/Notifications}/AboutNotificationIconResource.cs (93%) rename {SafeExamBrowser.Configuration => SafeExamBrowser.Core/Notifications}/AboutNotificationInfo.cs (93%) create mode 100644 SafeExamBrowser.UserInterface/AboutWindow.xaml create mode 100644 SafeExamBrowser.UserInterface/AboutWindow.xaml.cs diff --git a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj index 7511636f..ef19d3db 100644 --- a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj +++ b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj @@ -60,8 +60,6 @@ - - diff --git a/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs b/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs index 60a89427..08e343a7 100644 --- a/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/INotificationController.cs @@ -16,5 +16,10 @@ namespace SafeExamBrowser.Contracts.Behaviour /// Registers the taskbar notification. /// void RegisterNotification(ITaskbarNotification notification); + + /// + /// Instructs the controller to shut down and release all used resources. + /// + void Terminate(); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs index e40bac2d..1fad76ab 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs @@ -14,6 +14,11 @@ namespace SafeExamBrowser.Contracts.UserInterface { public interface IUserInterfaceFactory : IMessageBox { + /// + /// Creates a new about window displaying information about the currently running application version. + /// + IWindow CreateAboutWindow(ISettings settings, IText text); + /// /// Creates a taskbar button, initialized with the given application information. /// diff --git a/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs index 591eb4e7..56eaf358 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/TaskbarOperation.cs @@ -7,27 +7,31 @@ */ using SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Notifications; namespace SafeExamBrowser.Core.Behaviour.Operations { public class TaskbarOperation : IOperation { private ILogger logger; + private INotificationController aboutController; private ITaskbar taskbar; private IUserInterfaceFactory uiFactory; - private INotificationInfo aboutInfo; + private IText text; + private ISettings settings; public ISplashScreen SplashScreen { private get; set; } - public TaskbarOperation(ILogger logger, INotificationInfo aboutInfo, ITaskbar taskbar, IUserInterfaceFactory uiFactory) + public TaskbarOperation(ILogger logger, ISettings settings, ITaskbar taskbar, IText text, IUserInterfaceFactory uiFactory) { this.logger = logger; - this.aboutInfo = aboutInfo; + this.settings = settings; this.taskbar = taskbar; + this.text = text; this.uiFactory = uiFactory; } @@ -36,14 +40,18 @@ namespace SafeExamBrowser.Core.Behaviour.Operations logger.Info("Initializing taskbar..."); SplashScreen.UpdateText(Key.SplashScreen_InitializeTaskbar); + var aboutInfo = new AboutNotificationInfo(text); var aboutNotification = uiFactory.CreateNotification(aboutInfo); + aboutController = new AboutNotificationController(settings, text, uiFactory); + aboutController.RegisterNotification(aboutNotification); + taskbar.AddNotification(aboutNotification); } public void Revert() { - // Nothing to do here so far... + aboutController.Terminate(); } } } diff --git a/SafeExamBrowser.Core/Notifications/AboutNotificationController.cs b/SafeExamBrowser.Core/Notifications/AboutNotificationController.cs new file mode 100644 index 00000000..6a12b470 --- /dev/null +++ b/SafeExamBrowser.Core/Notifications/AboutNotificationController.cs @@ -0,0 +1,59 @@ +/* + * 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.Behaviour; +using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Core.Notifications +{ + public class AboutNotificationController : INotificationController + { + private ITaskbarNotification notification; + private ISettings settings; + private IText text; + private IUserInterfaceFactory uiFactory; + private IWindow window; + + public AboutNotificationController(ISettings settings, IText text, IUserInterfaceFactory uiFactory) + { + this.settings = settings; + this.text = text; + this.uiFactory = uiFactory; + } + + public void RegisterNotification(ITaskbarNotification notification) + { + this.notification = notification; + + notification.Clicked += Notification_Clicked; + } + + public void Terminate() + { + window?.Close(); + } + + private void Notification_Clicked() + { + if (window == null) + { + window = uiFactory.CreateAboutWindow(settings, text); + + window.Closing += () => window = null; + window.Show(); + } + else + { + window.BringToForeground(); + } + } + } +} diff --git a/SafeExamBrowser.Configuration/AboutNotificationIconResource.cs b/SafeExamBrowser.Core/Notifications/AboutNotificationIconResource.cs similarity index 93% rename from SafeExamBrowser.Configuration/AboutNotificationIconResource.cs rename to SafeExamBrowser.Core/Notifications/AboutNotificationIconResource.cs index 43a52f3d..058f3286 100644 --- a/SafeExamBrowser.Configuration/AboutNotificationIconResource.cs +++ b/SafeExamBrowser.Core/Notifications/AboutNotificationIconResource.cs @@ -9,7 +9,7 @@ using System; using SafeExamBrowser.Contracts.Configuration; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Core.Notifications { public class AboutNotificationIconResource : IIconResource { diff --git a/SafeExamBrowser.Configuration/AboutNotificationInfo.cs b/SafeExamBrowser.Core/Notifications/AboutNotificationInfo.cs similarity index 93% rename from SafeExamBrowser.Configuration/AboutNotificationInfo.cs rename to SafeExamBrowser.Core/Notifications/AboutNotificationInfo.cs index e1f7dc11..88aeeadb 100644 --- a/SafeExamBrowser.Configuration/AboutNotificationInfo.cs +++ b/SafeExamBrowser.Core/Notifications/AboutNotificationInfo.cs @@ -9,7 +9,7 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Core.Notifications { public class AboutNotificationInfo : INotificationInfo { diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index 7aa9f8fc..bd8c6692 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -75,6 +75,9 @@ + + + diff --git a/SafeExamBrowser.UserInterface/AboutWindow.xaml b/SafeExamBrowser.UserInterface/AboutWindow.xaml new file mode 100644 index 00000000..55d9c2e4 --- /dev/null +++ b/SafeExamBrowser.UserInterface/AboutWindow.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + This application is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed + with this application, You can obtain one at http://mozilla.org/MPL/2.0/. + + + CefSharp (.NET bindings for the Chromium Embedded Framework) + + Copyright © 2010-2017 The CefSharp Authors. All rights reserved. + + + CEF (Chromium Embedded Framework) + + Copyright © 2008-2014 Marshall A. Greenblatt. Portions Copyright © 2006-2009 Google Inc. All rights reserved. + + + + diff --git a/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs b/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs new file mode 100644 index 00000000..4db14eff --- /dev/null +++ b/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs @@ -0,0 +1,52 @@ +/* + * 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.Documents; +using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.UserInterface +{ + public partial class AboutWindow : Window, IWindow + { + private ISettings settings; + private IText text; + private WindowClosingEventHandler closing; + + event WindowClosingEventHandler IWindow.Closing + { + add { closing += value; } + remove { closing -= value; } + } + + public AboutWindow(ISettings settings, IText text) + { + this.settings = settings; + this.text = text; + + InitializeComponent(); + InitializeAboutWindow(); + } + + public void BringToForeground() + { + Activate(); + } + + private void InitializeAboutWindow() + { + Closing += (o, args) => closing?.Invoke(); + VersionInfo.Inlines.Add(new Run($"{text.Get(Key.Version)} {settings.ProgramVersion}") { FontStyle = FontStyles.Italic }); + VersionInfo.Inlines.Add(new LineBreak()); + VersionInfo.Inlines.Add(new LineBreak()); + VersionInfo.Inlines.Add(new Run(settings.ProgramCopyright)); + } + } +} diff --git a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj index 74f6cc2d..6af6c63b 100644 --- a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj +++ b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj @@ -67,6 +67,9 @@ + + AboutWindow.xaml + BrowserWindow.xaml @@ -118,6 +121,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/SafeExamBrowser.UserInterface/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface/UserInterfaceFactory.cs index 0cde8fab..fd9d3d47 100644 --- a/SafeExamBrowser.UserInterface/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface/UserInterfaceFactory.cs @@ -18,6 +18,11 @@ namespace SafeExamBrowser.UserInterface { public class UserInterfaceFactory : IUserInterfaceFactory { + public IWindow CreateAboutWindow(ISettings settings, IText text) + { + return new AboutWindow(settings, text); + } + public ITaskbarButton CreateApplicationButton(IApplicationInfo info) { return new ApplicationButton(info); diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index 841bcb97..fc19a8dd 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -35,7 +35,6 @@ namespace SafeExamBrowser private IEventController eventController; private ILogger logger; private INativeMethods nativeMethods; - private INotificationInfo aboutInfo; private IProcessMonitor processMonitor; private ISettings settings; private IText text; @@ -62,7 +61,6 @@ namespace SafeExamBrowser logger.Subscribe(new LogFileWriter(settings)); text = new Text(textResource); - aboutInfo = new AboutNotificationInfo(text); browserController = new BrowserApplicationController(settings, text, uiFactory); processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods); windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); @@ -76,7 +74,7 @@ namespace SafeExamBrowser StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); StartupOperations.Enqueue(new WorkingAreaOperation(logger, Taskbar, workingArea)); - StartupOperations.Enqueue(new TaskbarOperation(logger, aboutInfo, Taskbar, uiFactory)); + StartupOperations.Enqueue(new TaskbarOperation(logger, settings, Taskbar, text, uiFactory)); StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); StartupOperations.Enqueue(new EventControllerOperation(eventController, logger)); }