2017-08-22 10:29:00 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 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;
|
2018-07-06 15:57:38 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Taskbar.Events;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Windows;
|
2019-01-11 15:32:47 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Desktop.ViewModels;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2019-01-11 15:32:47 +01:00
|
|
|
|
namespace SafeExamBrowser.UserInterface.Desktop
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
public partial class SplashScreen : Window, ISplashScreen
|
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private bool allowClose;
|
2018-02-02 09:18:35 +01:00
|
|
|
|
private ProgressIndicatorViewModel model = new ProgressIndicatorViewModel();
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
private IText text;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private WindowClosingEventHandler closing;
|
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
public AppConfig AppConfig
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig = value;
|
|
|
|
|
UpdateAppInfo();
|
2018-02-21 14:01:21 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
event WindowClosingEventHandler IWindow.Closing
|
|
|
|
|
{
|
|
|
|
|
add { closing += value; }
|
|
|
|
|
remove { closing -= value; }
|
|
|
|
|
}
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
public SplashScreen(IText text, AppConfig appConfig = null)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
this.appConfig = appConfig;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
this.text = text;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeSplashScreen();
|
2018-09-21 14:40:48 +02:00
|
|
|
|
|
|
|
|
|
Loaded += SplashScreen_Loaded;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2018-10-04 11:24:16 +02:00
|
|
|
|
model.BusyIndication = false;
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
public void Progress()
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-10-03 14:35:27 +02:00
|
|
|
|
model.CurrentProgress += 1;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
public void Regress()
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-10-03 14:35:27 +02:00
|
|
|
|
model.CurrentProgress -= 1;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetIndeterminate()
|
|
|
|
|
{
|
|
|
|
|
model.IsIndeterminate = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public void SetMaxValue(int max)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
model.MaxProgress = max;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public void SetValue(int value)
|
|
|
|
|
{
|
|
|
|
|
model.CurrentProgress = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 11:24:16 +02:00
|
|
|
|
public void UpdateStatus(TextKey key, bool busyIndication = false)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
model.Status = text.Get(key);
|
2018-10-04 11:24:16 +02:00
|
|
|
|
model.BusyIndication = busyIndication;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeSplashScreen()
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
UpdateAppInfo();
|
2017-08-22 10:29:00 +02:00
|
|
|
|
|
|
|
|
|
StatusTextBlock.DataContext = model;
|
|
|
|
|
ProgressBar.DataContext = model;
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
Closing += (o, args) => args.Cancel = !allowClose;
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
2018-02-21 14:01:21 +01:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private void UpdateAppInfo()
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
if (appConfig != null)
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
InfoTextBlock.Inlines.Add(new Run($"Version {appConfig.ProgramVersion}") { FontStyle = FontStyles.Italic });
|
2018-02-21 14:01:21 +01:00
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
|
|
|
|
InfoTextBlock.Inlines.Add(new LineBreak());
|
2018-06-29 09:50:20 +02:00
|
|
|
|
InfoTextBlock.Inlines.Add(new Run(appConfig.ProgramCopyright) { FontSize = 10 });
|
2018-02-21 14:01:21 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-21 14:40:48 +02:00
|
|
|
|
|
|
|
|
|
private void SplashScreen_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Left = (SystemParameters.WorkArea.Right / 2) - (Width / 2);
|
|
|
|
|
Top = (SystemParameters.WorkArea.Bottom / 2) - (Height / 2);
|
|
|
|
|
}
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|