// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// HandBrakes Main Window
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using HandBrake.App.Core.Model;
using HandBrake.App.Core.Utilities;
using HandBrake.Interop.Interop;
using HandBrake.Interop.Utilities;
using HandBrakeWPF.Commands;
using HandBrakeWPF.Commands.DebugTools;
using HandBrakeWPF.Commands.Menu;
using HandBrakeWPF.Commands.Presets;
using HandBrakeWPF.EventArgs;
using HandBrakeWPF.Helpers;
using HandBrakeWPF.Model;
using HandBrakeWPF.Model.Audio;
using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Model.Queue;
using HandBrakeWPF.Model.Subtitles;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Encode.Model;
using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Queue.Interfaces;
using HandBrakeWPF.Services.Queue.Model;
using HandBrakeWPF.Services.Scan.EventArgs;
using HandBrakeWPF.Services.Scan.Interfaces;
using HandBrakeWPF.Services.Scan.Model;
using HandBrakeWPF.Startup;
using HandBrakeWPF.Utilities;
using HandBrakeWPF.Utilities.FileDialogs;
using HandBrakeWPF.ViewModels.Interfaces;
using HandBrakeWPF.Views;
using Action = System.Action;
using Application = System.Windows.Application;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using ILog = Services.Logging.Interfaces.ILog;
public class MainViewModel : ViewModelBase, IMainViewModel
{
private readonly IQueueService queueProcessor;
private readonly IPresetService presetService;
private readonly IErrorService errorService;
private readonly IUpdateService updateService;
private readonly IWindowManager windowManager;
private readonly INotifyIconService notifyIconService;
private readonly ILog logService;
private readonly INotificationService notificationService;
private readonly IUserSettingService userSettingService;
private readonly IScan scanService;
private readonly WindowsTaskbar windowsTaskbar = new WindowsTaskbar();
private readonly DelayedActionProcessor delayedPreviewprocessor = new DelayedActionProcessor();
private string windowName;
private string sourceLabel;
private string statusLabel;
private string programStatusLabel;
private Source scannedSource;
private Title selectedTitle;
private string duration;
private bool showStatusWindow;
private Preset selectedPreset;
private QueueTask queueEditTask;
private int lastEncodePercentage;
private bool showSourceSelection;
private BindingList drives;
private bool showAlertWindow;
private string alertWindowHeader;
private string alertWindowText;
private bool hasSource;
private bool isSettingPreset;
private bool isModifiedPreset;
private bool updateAvailable;
private bool isNavigationEnabled;
private double progressAmount;
public MainViewModel(
IUserSettingService userSettingService,
IScan scanService,
IPresetService presetService,
IErrorService errorService,
IUpdateService updateService,
IPrePostActionService whenDoneService,
IWindowManager windowManager,
IPictureSettingsViewModel pictureSettingsViewModel,
IVideoViewModel videoViewModel,
ISummaryViewModel summaryViewModel,
IFiltersViewModel filtersViewModel,
IAudioViewModel audioViewModel,
ISubtitlesViewModel subtitlesViewModel,
IChaptersViewModel chaptersViewModel,
IStaticPreviewViewModel staticPreviewViewModel,
IQueueViewModel queueViewModel,
IMetaDataViewModel metaDataViewModel,
INotifyIconService notifyIconService,
ISystemService systemService,
ILog logService,
INotificationService notificationService)
: base(userSettingService)
{
this.scanService = scanService;
this.presetService = presetService;
this.errorService = errorService;
this.updateService = updateService;
this.windowManager = windowManager;
this.notifyIconService = notifyIconService;
this.logService = logService;
this.notificationService = notificationService;
this.QueueViewModel = queueViewModel;
this.userSettingService = userSettingService;
this.queueProcessor = IoCHelper.Get();
this.SummaryViewModel = summaryViewModel;
this.PictureSettingsViewModel = pictureSettingsViewModel;
this.VideoViewModel = videoViewModel;
this.MetaDataViewModel = metaDataViewModel;
this.FiltersViewModel = filtersViewModel;
this.AudioViewModel = audioViewModel;
this.SubtitleViewModel = subtitlesViewModel;
this.ChaptersViewModel = chaptersViewModel;
this.StaticPreviewViewModel = staticPreviewViewModel;
// Setup Properties
this.WindowTitle = Resources.HandBrake_Title;
this.CurrentTask = new EncodeTask();
this.ScannedSource = new Source();
this.HasSource = false;
this.IsNavigationEnabled = true;
// Setup Events
this.scanService.ScanStarted += this.ScanStared;
this.scanService.ScanCompleted += this.ScanCompleted;
this.scanService.ScanStatusChanged += this.ScanStatusChanged;
this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;
this.queueProcessor.QueueCompleted += this.QueueCompleted;
this.queueProcessor.QueueChanged += this.QueueChanged;
this.queueProcessor.QueuePaused += this.QueueProcessor_QueuePaused;
this.queueProcessor.QueueJobStatusChanged += this.QueueProcessor_QueueJobStatusChanged;
this.userSettingService.SettingChanged += this.UserSettingServiceSettingChanged;
this.PresetsCategories = new BindingList();
this.Drives = new BindingList();
// Set Process Priority. Only when using in-process encoding.
// When process isolation is enabled, we'll stick to "Normal".
if (!this.userSettingService.GetUserSetting(UserSettingConstants.ProcessIsolationEnabled))
{
switch ((ProcessPriority)this.userSettingService.GetUserSetting(UserSettingConstants.ProcessPriorityInt))
{
case ProcessPriority.High:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
break;
case ProcessPriority.AboveNormal:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case ProcessPriority.Normal:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
break;
case ProcessPriority.Low:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
break;
default:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
}
// Setup Commands
this.QueueCommand = new QueueCommands(this.QueueViewModel);
this.ProcessDriveCommand = new SimpleRelayCommand