public QueueTitlesWindowViewModel()
        {
            this.main           = Ioc.Get <MainViewModel>();
            this.PickersService = Ioc.Get <PickersService>();
            this.windowManager  = Ioc.Get <IWindowManager>();

            this.selectedTitles            = new ReactiveList <TitleSelectionViewModel>();
            this.titleStartOverrideEnabled = Config.QueueTitlesUseTitleOverride;
            this.titleStartOverride        = Config.QueueTitlesTitleOverride;
            this.nameOverrideEnabled       = Config.QueueTitlesUseNameOverride;
            this.nameOverride = Config.QueueTitlesNameOverride;

            this.titles = new ReactiveList <TitleSelectionViewModel>();
            this.RefreshTitles();

            this.Play = ReactiveCommand.Create(MvvmUtilities.CreateConstantObservable(Players.Installed.Count > 0));
            this.Play.Subscribe(_ => this.PlayImpl());

            this.AddToQueue = ReactiveCommand.Create();
            this.AddToQueue.Subscribe(_ => this.AddToQueueImpl());

            this.main.WhenAnyValue(x => x.SourceData)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.RefreshTitles();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectEnabled)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectStartMinutes)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.PickersService.WhenAnyValue(x => x.SelectedPicker.Picker.TitleRangeSelectEndMinutes)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.SetSelectedFromRange();
            });

            this.selectedTitles.CountChanged
            .Select(count => count == 1)
            .ToProperty(this, x => x.TitleDetailsVisible, out this.titleDetailsVisible, initialValue: false);

            this.selectedTitles.CollectionChanged +=
                (sender, args) =>
            {
                if (this.selectedTitles.Count == 1)
                {
                    SourceTitle title = this.selectedTitles[0].Title;

                    // Do preview
                    var previewProfile =
                        new VCProfile
                    {
                        CustomCropping = true,
                        Cropping       = new VCCropping(),
                        VideoEncoder   = "x264",
                        AudioEncodings = new List <AudioEncoding>()
                    };

                    var previewJob =
                        new VCJob
                    {
                        RangeType       = VideoRangeType.All,
                        Title           = title.Index,
                        EncodingProfile = previewProfile
                    };

                    this.PreviewImage = this.main.ScanInstance.GetPreview(previewProfile.CreatePreviewSettings(title), 2);
                    this.RaisePropertyChanged(nameof(this.TitleText));
                }
            };
        }
Exemplo n.º 2
0
        public OptionsDialogViewModel(IUpdater updateService)
        {
            this.updater = updateService;

            this.Tabs = new List <string>
            {
                OptionsRes.GeneralTab,                                  // 0
                OptionsRes.FileNamingTab,                               // 1
                OptionsRes.ProcessTab,                                  // 2
                OptionsRes.AdvancedTab,                                 // 3
            };

            if (Utilities.SupportsUpdates)
            {
                this.Tabs.Add(OptionsRes.UpdatesTab);                 // 4
            }

            // UpdateStatus
            this.updater
            .WhenAnyValue(x => x.State)
            .Select(state =>
            {
                switch (state)
                {
                case UpdateState.NotStarted:
                    return(string.Empty);

                case UpdateState.DownloadingInfo:
                    return(OptionsRes.DownloadingInfoStatus);

                case UpdateState.DownloadingInstaller:
                    return(string.Format(OptionsRes.DownloadingStatus, this.updater.LatestVersion));

                case UpdateState.UpToDate:
                    return(OptionsRes.UpToDateStatus);

                case UpdateState.InstallerReady:
                    return(string.Format(OptionsRes.UpdateReadyStatus, this.updater.LatestVersion));

                case UpdateState.Failed:
                    return(OptionsRes.UpdateFailedStatus);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            })
            .ToProperty(this, x => x.UpdateStatus, out this.updateStatus);

            // UpdateDownloading
            this.updater
            .WhenAnyValue(x => x.State)
            .Select(state => state == UpdateState.DownloadingInstaller)
            .ToProperty(this, x => x.UpdateDownloading, out this.updateDownloading);

            // UpdateProgressPercent
            this.updater
            .WhenAnyValue(x => x.UpdateDownloadProgressFraction)
            .Select(downloadFraction => downloadFraction * 100)
            .ToProperty(this, x => x.UpdateProgressPercent, out this.updateProgressPercent);

            // CpuThrottlingDisplay
            this.WhenAnyValue(x => x.CpuThrottlingCores, x => x.CpuThrottlingMaxCores, (cores, maxCores) =>
            {
                double currentFraction = (double)cores / maxCores;
                return(currentFraction.ToString("p0"));
            }).ToProperty(this, x => x.CpuThrottlingDisplay, out this.cpuThrottlingDisplay);

            this.SaveSettings = ReactiveCommand.Create();
            this.SaveSettings.Subscribe(_ => this.SaveSettingsImpl());

            this.BrowseVideoPlayer = ReactiveCommand.Create(this.WhenAnyValue(x => x.UseCustomVideoPlayer));
            this.BrowseVideoPlayer.Subscribe(_ => this.BrowseVideoPlayerImpl());

            this.BrowseCompletionSound = ReactiveCommand.Create(this.WhenAnyValue(x => x.UseCustomCompletionSound));
            this.BrowseCompletionSound.Subscribe(_ => this.BrowseCompletionSoundImpl());

            this.BrowsePath = ReactiveCommand.Create();
            this.BrowsePath.Subscribe(_ => this.BrowsePathImpl());

            this.BrowsePreviewFolder = ReactiveCommand.Create();
            this.BrowsePreviewFolder.Subscribe(_ => this.BrowsePreviewFolderImpl());

            this.OpenAddProcessDialog = ReactiveCommand.Create();
            this.OpenAddProcessDialog.Subscribe(_ => this.OpenAddProcessDialogImpl());

            this.RemoveProcess = ReactiveCommand.Create(this.WhenAnyValue(x => x.SelectedProcess).Select(selectedProcess => selectedProcess != null));
            this.RemoveProcess.Subscribe(_ => this.RemoveProcessImpl());

            bool logFolderExists = Directory.Exists(Utilities.LogsFolder);

            this.OpenLogFolder = ReactiveCommand.Create(MvvmUtilities.CreateConstantObservable(logFolderExists));
            this.OpenLogFolder.Subscribe(_ => this.OpenLogFolderImpl());

            this.CheckUpdate = ReactiveCommand.Create(this.updater.WhenAnyValue(x => x.State).Select(state =>
            {
                return(Config.UpdatesEnabled &&
                       (state == UpdateState.Failed ||
                        state == UpdateState.NotStarted ||
                        state == UpdateState.UpToDate));
            }));
            this.CheckUpdate.Subscribe(_ => this.CheckUpdateImpl());

            this.updatesEnabledConfig                 = Config.UpdatesEnabled;
            this.defaultPath                          = Config.AutoNameOutputFolder;
            this.customFormat                         = Config.AutoNameCustomFormat;
            this.customFormatString                   = Config.AutoNameCustomFormatString;
            this.outputToSourceDirectory              = Config.OutputToSourceDirectory;
            this.preserveFolderStructureInBatch       = Config.PreserveFolderStructureInBatch;
            this.useCustomPreviewFolder               = Config.UseCustomPreviewFolder;
            this.previewOutputFolder                  = Config.PreviewOutputFolder;
            this.whenFileExists                       = CustomConfig.WhenFileExists;
            this.whenFileExistsBatch                  = CustomConfig.WhenFileExistsBatch;
            this.minimizeToTray                       = Config.MinimizeToTray;
            this.useCustomVideoPlayer                 = Config.UseCustomVideoPlayer;
            this.customVideoPlayer                    = Config.CustomVideoPlayer;
            this.useBuiltInPlayerForPreviews          = Config.UseBuiltInPlayerForPreviews;
            this.playSoundOnCompletion                = Config.PlaySoundOnCompletion;
            this.useCustomCompletionSound             = Config.UseCustomCompletionSound;
            this.customCompletionSound                = Config.CustomCompletionSound;
            this.workerProcessPriority                = Config.WorkerProcessPriority;
            this.logVerbosity                         = Config.LogVerbosity;
            this.copyLogToOutputFolder                = Config.CopyLogToOutputFolder;
            this.previewCount                         = Config.PreviewCount;
            this.rememberPreviousFiles                = Config.RememberPreviousFiles;
            this.showAudioTrackNameField              = Config.ShowAudioTrackNameField;
            this.enableLibDvdNav                      = Config.EnableLibDvdNav;
            this.deleteSourceFilesOnClearingCompleted = Config.DeleteSourceFilesOnClearingCompleted;
            this.preserveModifyTimeFiles              = Config.PreserveModifyTimeFiles;
            this.resumeEncodingOnRestart              = Config.ResumeEncodingOnRestart;
            this.useWorkerProcess                     = Config.UseWorkerProcess;
            this.minimumTitleLengthSeconds            = Config.MinimumTitleLengthSeconds;
            this.autoPauseProcesses                   = new ObservableCollection <string>();
            this.videoFileExtensions                  = Config.VideoFileExtensions;
            this.cpuThrottlingCores                   = (int)Math.Round(this.CpuThrottlingMaxCores * Config.CpuThrottlingFraction);
            if (this.cpuThrottlingCores < 1)
            {
                this.cpuThrottlingCores = 1;
            }

            if (this.cpuThrottlingCores > this.CpuThrottlingMaxCores)
            {
                this.cpuThrottlingCores = this.CpuThrottlingMaxCores;
            }

            List <string> autoPauseList = CustomConfig.AutoPauseProcesses;

            if (autoPauseList != null)
            {
                foreach (string process in autoPauseList)
                {
                    this.autoPauseProcesses.Add(process);
                }
            }

            // List of language codes and names: http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx

            this.languageChoices =
                new List <InterfaceLanguage>
            {
                new InterfaceLanguage {
                    CultureCode = string.Empty, Display = OptionsRes.UseOSLanguage
                },
                new InterfaceLanguage {
                    CultureCode = "en-US", Display = "English"
                },
                new InterfaceLanguage {
                    CultureCode = "id-ID", Display = "Bahasa Indonesia / Indonesian"
                },
                new InterfaceLanguage {
                    CultureCode = "bs-Latn-BA", Display = "bosanski (Bosna i Hercegovina) / Bosnian (Latin)"
                },
                new InterfaceLanguage {
                    CultureCode = "cs-CZ", Display = "čeština / Czech"
                },
                new InterfaceLanguage {
                    CultureCode = "de-DE", Display = "Deutsch / German"
                },
                new InterfaceLanguage {
                    CultureCode = "es-ES", Display = "Español / Spanish"
                },
                new InterfaceLanguage {
                    CultureCode = "eu-ES", Display = "Euskara / Basque"
                },
                new InterfaceLanguage {
                    CultureCode = "fr-FR", Display = "Français / French"
                },
                new InterfaceLanguage {
                    CultureCode = "it-IT", Display = "italiano / Italian"
                },
                new InterfaceLanguage {
                    CultureCode = "hu-HU", Display = "Magyar / Hungarian"
                },
                new InterfaceLanguage {
                    CultureCode = "nl-BE", Display = "Nederlands / Dutch"
                },
                new InterfaceLanguage {
                    CultureCode = "pl-PL", Display = "polski / Polish"
                },
                new InterfaceLanguage {
                    CultureCode = "pt-PT", Display = "Português / Portuguese"
                },
                new InterfaceLanguage {
                    CultureCode = "pt-BR", Display = "Português (Brasil) / Portuguese (Brazil)"
                },
                new InterfaceLanguage {
                    CultureCode = "tr-TR", Display = "Türkçe / Turkish"
                },
                new InterfaceLanguage {
                    CultureCode = "ka-GE", Display = "ქართული / Georgian"
                },
                new InterfaceLanguage {
                    CultureCode = "ru-RU", Display = "русский / Russian"
                },
                new InterfaceLanguage {
                    CultureCode = "ko-KO", Display = "한국어 / Korean"
                },
                new InterfaceLanguage {
                    CultureCode = "zh-Hans", Display = "中文(简体) / Chinese (Simplified)"
                },
                new InterfaceLanguage {
                    CultureCode = "zh-Hant", Display = "中文(繁體) / Chinese (Traditional)"
                },
                new InterfaceLanguage {
                    CultureCode = "ja-JP", Display = "日本語 / Japanese"
                },
            };

            this.priorityChoices = new List <ComboChoice>
            {
                new ComboChoice("High", OptionsRes.Priority_High),
                new ComboChoice("AboveNormal", OptionsRes.Priority_AboveNormal),
                new ComboChoice("Normal", OptionsRes.Priority_Normal),
                new ComboChoice("BelowNormal", OptionsRes.Priority_BelowNormal),
                new ComboChoice("Idle", OptionsRes.Priority_Idle),
            };

            this.interfaceLanguage = this.languageChoices.FirstOrDefault(l => l.CultureCode == Config.InterfaceLanguageCode);
            if (this.interfaceLanguage == null)
            {
                this.interfaceLanguage = this.languageChoices[0];
            }

            this.playerChoices = Players.All;
            if (this.playerChoices.Count > 0)
            {
                this.selectedPlayer = this.playerChoices[0];

                foreach (IVideoPlayer player in this.playerChoices)
                {
                    if (player.Id == Config.PreferredPlayer)
                    {
                        this.selectedPlayer = player;
                        break;
                    }
                }
            }

            if (!CommonUtilities.Beta)
            {
                Task.Run(async() =>
                {
                    this.betaInfo = await Updater.GetUpdateInfoAsync(beta: true);

                    this.betaInfoAvailable = false;
                    if (this.betaInfo != null)
                    {
                        if (this.betaInfo.LatestVersion.FillInWithZeroes() > Utilities.CurrentVersion)
                        {
                            this.betaInfoAvailable = true;
                        }

                        await DispatchUtilities.InvokeAsync(() =>
                        {
                            this.RaisePropertyChanged(nameof(this.BetaChangelogUrl));
                            this.RaisePropertyChanged(nameof(this.BetaSectionVisible));
                        });
                    }
                });
            }

            int tabIndex = Config.OptionsDialogLastTab;

            if (tabIndex >= this.Tabs.Count)
            {
                tabIndex = 0;
            }

            this.SelectedTabIndex = tabIndex;
        }