Implemented draft of the about window.

This commit is contained in:
dbuechel 2017-08-02 10:13:23 +02:00
parent 75f104f136
commit 6861353b64
13 changed files with 193 additions and 12 deletions

View file

@ -60,8 +60,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AboutNotificationIconResource.cs" />
<Compile Include="AboutNotificationInfo.cs" />
<Compile Include="Settings\BrowserSettings.cs" />
<Compile Include="Settings\SettingsImpl.cs" />
<Compile Include="WorkingArea.cs" />

View file

@ -16,5 +16,10 @@ namespace SafeExamBrowser.Contracts.Behaviour
/// Registers the taskbar notification.
/// </summary>
void RegisterNotification(ITaskbarNotification notification);
/// <summary>
/// Instructs the controller to shut down and release all used resources.
/// </summary>
void Terminate();
}
}

View file

@ -14,6 +14,11 @@ namespace SafeExamBrowser.Contracts.UserInterface
{
public interface IUserInterfaceFactory : IMessageBox
{
/// <summary>
/// Creates a new about window displaying information about the currently running application version.
/// </summary>
IWindow CreateAboutWindow(ISettings settings, IText text);
/// <summary>
/// Creates a taskbar button, initialized with the given application information.
/// </summary>

View file

@ -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();
}
}
}

View file

@ -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();
}
}
}
}

View file

@ -9,7 +9,7 @@
using System;
using SafeExamBrowser.Contracts.Configuration;
namespace SafeExamBrowser.Configuration
namespace SafeExamBrowser.Core.Notifications
{
public class AboutNotificationIconResource : IIconResource
{

View file

@ -9,7 +9,7 @@
using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.I18n;
namespace SafeExamBrowser.Configuration
namespace SafeExamBrowser.Core.Notifications
{
public class AboutNotificationInfo : INotificationInfo
{

View file

@ -75,6 +75,9 @@
<Compile Include="Logging\LogText.cs" />
<Compile Include="Logging\ModuleLogger.cs" />
<Compile Include="Logging\ThreadInfo.cs" />
<Compile Include="Notifications\AboutNotificationController.cs" />
<Compile Include="Notifications\AboutNotificationIconResource.cs" />
<Compile Include="Notifications\AboutNotificationInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,41 @@
<Window x:Class="SafeExamBrowser.UserInterface.AboutWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface"
mc:Ignorable="d"
Title="About" Height="350" Width="450" ResizeMode="NoResize" Icon="./Images/SafeExamBrowser.ico"
ShowInTaskbar="False" WindowStartupLocation="CenterScreen">
<Window.Background>
<SolidColorBrush Color="Black" Opacity="0.8" />
</Window.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.ColumnSpan="2" Source="pack://application:,,,/SafeExamBrowser.UserInterface;component/Images/SplashScreen.png" />
<TextBlock x:Name="VersionInfo" Grid.Row="0" Grid.Column="1" Foreground="White" Margin="50,75,35,10" TextWrapping="Wrap" FontSize="10" />
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="MainText" Foreground="White" Margin="10" FontSize="10" TextWrapping="Wrap">
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/.
<LineBreak />
<LineBreak />
<Bold><Underline>CefSharp (.NET bindings for the Chromium Embedded Framework)</Underline></Bold>
<LineBreak />
Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
<LineBreak />
<LineBreak />
<Bold><Underline>CEF (Chromium Embedded Framework)</Underline></Bold>
<LineBreak />
Copyright © 2008-2014 Marshall A. Greenblatt. Portions Copyright © 2006-2009 Google Inc. All rights reserved.
</TextBlock>
</ScrollViewer>
</Grid>
</Window>

View file

@ -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));
}
}
}

View file

@ -67,6 +67,9 @@
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
</Compile>
<Compile Include="BrowserWindow.xaml.cs">
<DependentUpon>BrowserWindow.xaml</DependentUpon>
</Compile>
@ -118,6 +121,10 @@
</None>
</ItemGroup>
<ItemGroup>
<Page Include="AboutWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="BrowserWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View file

@ -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);

View file

@ -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));
}