2017-08-22 09:37:17 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-08-22 09:37:17 +02:00
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2017-08-22 09:37:17 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Classic.Controls;
|
2018-01-19 09:23:09 +01:00
|
|
|
|
using MessageBoxResult = SafeExamBrowser.Contracts.UserInterface.MessageBoxResult;
|
2017-08-22 09:37:17 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.UserInterface.Classic
|
|
|
|
|
{
|
|
|
|
|
public class UserInterfaceFactory : IUserInterfaceFactory
|
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text)
|
2017-08-22 09:37:17 +02:00
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
return new AboutWindow(runtimeInfo, text);
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IApplicationButton CreateApplicationButton(IApplicationInfo info)
|
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
return new ApplicationButton(info);
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, IBrowserSettings settings)
|
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
return new BrowserWindow(control, settings);
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWindow CreateLogWindow(ILogger logger, IText text)
|
|
|
|
|
{
|
2017-08-22 10:58:36 +02:00
|
|
|
|
LogWindow logWindow = null;
|
|
|
|
|
var logWindowReadyEvent = new AutoResetEvent(false);
|
|
|
|
|
var logWindowThread = new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
logWindow = new LogWindow(logger, text);
|
|
|
|
|
logWindow.Closed += (o, args) => logWindow.Dispatcher.InvokeShutdown();
|
|
|
|
|
logWindow.Show();
|
|
|
|
|
|
|
|
|
|
logWindowReadyEvent.Set();
|
|
|
|
|
|
|
|
|
|
System.Windows.Threading.Dispatcher.Run();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
logWindowThread.SetApartmentState(ApartmentState.STA);
|
|
|
|
|
logWindowThread.Name = nameof(LogWindow);
|
|
|
|
|
logWindowThread.IsBackground = true;
|
|
|
|
|
logWindowThread.Start();
|
|
|
|
|
|
|
|
|
|
logWindowReadyEvent.WaitOne();
|
|
|
|
|
|
|
|
|
|
return logWindow;
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public INotificationButton CreateNotification(INotificationInfo info)
|
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
return new NotificationButton(info);
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-13 08:33:12 +02:00
|
|
|
|
public ISystemKeyboardLayoutControl CreateKeyboardLayoutControl()
|
|
|
|
|
{
|
|
|
|
|
return new KeyboardLayoutControl();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 09:37:17 +02:00
|
|
|
|
public ISystemPowerSupplyControl CreatePowerSupplyControl()
|
|
|
|
|
{
|
2017-08-23 10:30:27 +02:00
|
|
|
|
return new PowerSupplyControl();
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text)
|
2017-08-22 09:37:17 +02:00
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
SplashScreen splashScreen = null;
|
|
|
|
|
var splashReadyEvent = new AutoResetEvent(false);
|
|
|
|
|
var splashScreenThread = new Thread(() =>
|
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
splashScreen = new SplashScreen(runtimeInfo, text);
|
2017-08-22 10:29:00 +02:00
|
|
|
|
splashScreen.Closed += (o, args) => splashScreen.Dispatcher.InvokeShutdown();
|
|
|
|
|
splashScreen.Show();
|
|
|
|
|
|
|
|
|
|
splashReadyEvent.Set();
|
|
|
|
|
|
|
|
|
|
System.Windows.Threading.Dispatcher.Run();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
splashScreenThread.SetApartmentState(ApartmentState.STA);
|
|
|
|
|
splashScreenThread.Name = nameof(SplashScreen);
|
|
|
|
|
splashScreenThread.IsBackground = true;
|
|
|
|
|
splashScreenThread.Start();
|
|
|
|
|
|
|
|
|
|
splashReadyEvent.WaitOne();
|
|
|
|
|
|
|
|
|
|
return splashScreen;
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 10:26:30 +01:00
|
|
|
|
public ISystemWirelessNetworkControl CreateWirelessNetworkControl()
|
|
|
|
|
{
|
|
|
|
|
return new WirelessNetworkControl();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 09:23:09 +01:00
|
|
|
|
public MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information)
|
2017-08-22 09:37:17 +02:00
|
|
|
|
{
|
2018-01-19 09:23:09 +01:00
|
|
|
|
// The last two parameters are an unfortunate necessity, since e.g. splash screens are displayed topmost while running in their
|
|
|
|
|
// own thread / dispatcher, and would thus conceal the message box...
|
|
|
|
|
var result = MessageBox.Show(message, title, ToButton(action), ToImage(icon), System.Windows.MessageBoxResult.None, MessageBoxOptions.ServiceNotification);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MessageBoxButton ToButton(MessageBoxAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
2018-01-19 09:23:09 +01:00
|
|
|
|
case MessageBoxAction.YesNo:
|
|
|
|
|
return MessageBoxButton.YesNo;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
default:
|
|
|
|
|
return MessageBoxButton.OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MessageBoxImage ToImage(MessageBoxIcon icon)
|
|
|
|
|
{
|
|
|
|
|
switch (icon)
|
|
|
|
|
{
|
|
|
|
|
case MessageBoxIcon.Error:
|
|
|
|
|
return MessageBoxImage.Error;
|
2018-01-19 09:23:09 +01:00
|
|
|
|
case MessageBoxIcon.Question:
|
|
|
|
|
return MessageBoxImage.Question;
|
|
|
|
|
case MessageBoxIcon.Warning:
|
|
|
|
|
return MessageBoxImage.Warning;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
default:
|
|
|
|
|
return MessageBoxImage.Information;
|
|
|
|
|
}
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
2018-01-19 09:23:09 +01:00
|
|
|
|
|
|
|
|
|
private MessageBoxResult ToResult(System.Windows.MessageBoxResult result)
|
|
|
|
|
{
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case System.Windows.MessageBoxResult.Cancel:
|
|
|
|
|
return MessageBoxResult.Cancel;
|
|
|
|
|
case System.Windows.MessageBoxResult.No:
|
|
|
|
|
return MessageBoxResult.No;
|
|
|
|
|
case System.Windows.MessageBoxResult.OK:
|
|
|
|
|
return MessageBoxResult.Ok;
|
|
|
|
|
case System.Windows.MessageBoxResult.Yes:
|
|
|
|
|
return MessageBoxResult.Yes;
|
|
|
|
|
default:
|
|
|
|
|
return MessageBoxResult.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-22 09:37:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|