2017-08-22 10:29:00 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-08-22 10:29:00 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Documents;
|
2018-01-17 14:08:39 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Classic.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.UserInterface.Classic
|
|
|
|
|
{
|
|
|
|
|
public partial class SplashScreen : Window, ISplashScreen
|
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private bool allowClose;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
private SplashScreenViewModel model = new SplashScreenViewModel();
|
2018-01-17 14:08:39 +01:00
|
|
|
|
private IRuntimeInfo runtimeInfo;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
private IText text;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private WindowClosingEventHandler closing;
|
|
|
|
|
|
|
|
|
|
event WindowClosingEventHandler IWindow.Closing
|
|
|
|
|
{
|
|
|
|
|
add { closing += value; }
|
|
|
|
|
remove { closing -= value; }
|
|
|
|
|
}
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
public SplashScreen(IRuntimeInfo runtimeInfo, IText text)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
this.runtimeInfo = runtimeInfo;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
this.text = text;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeSplashScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public void BringToForeground()
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
Dispatcher.Invoke(Activate);
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public new void Close()
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
allowClose = true;
|
|
|
|
|
base.Close();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Hide()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Hide);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Show()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Show);
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Progress(int amount = 1)
|
|
|
|
|
{
|
|
|
|
|
model.CurrentProgress += amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Regress(int amount = 1)
|
|
|
|
|
{
|
|
|
|
|
model.CurrentProgress -= amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetIndeterminate()
|
|
|
|
|
{
|
|
|
|
|
model.IsIndeterminate = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMaxProgress(int max)
|
|
|
|
|
{
|
|
|
|
|
model.MaxProgress = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateText(TextKey key, bool showBusyIndication = false)
|
|
|
|
|
{
|
|
|
|
|
model.StopBusyIndication();
|
|
|
|
|
model.Status = text.Get(key);
|
|
|
|
|
|
|
|
|
|
if (showBusyIndication)
|
|
|
|
|
{
|
|
|
|
|
model.StartBusyIndication();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeSplashScreen()
|
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
InfoTextBlock.Inlines.Add(new Run($"Version {runtimeInfo.ProgramVersion}") { FontStyle = FontStyles.Italic });
|
2017-08-22 10:29:00 +02:00
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
2018-01-17 14:08:39 +01:00
|
|
|
|
InfoTextBlock.Inlines.Add(new Run(runtimeInfo.ProgramCopyright) { FontSize = 10 });
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
|
|
|
|
StatusTextBlock.DataContext = model;
|
|
|
|
|
ProgressBar.DataContext = model;
|
|
|
|
|
|
|
|
|
|
// To prevent the progress bar going from max to min value at startup...
|
|
|
|
|
model.MaxProgress = 1;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
|
|
|
|
Closing += (o, args) => args.Cancel = !allowClose;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|