Example #1
0
 public MainWindow(bool preview)
 {
     InitializeComponent();
     this.preview              = preview;
     FullScreenMedia.Volume    = PreferenceManager.ReadVolumeSetting();
     imageTimer                = new DispatcherTimer();
     imageTimer.Tick          += ImageTimerEnded;
     imageTimer.Interval       = TimeSpan.FromMilliseconds(PreferenceManager.ReadIntervalSetting());
     infoShowingTimer          = new DispatcherTimer();
     infoShowingTimer.Tick    += (sender, args) => HideError();
     infoShowingTimer.Interval = TimeSpan.FromSeconds(5);
     if (preview)
     {
         ShowError("When fullscreen, control volume with up/down arrows or mouse wheel.");
     }
     // setting overlay text when media is opened. if you will try to set it in LoadMedia you will get nothing because media is not loaded yet
     FullScreenMedia.MediaOpened += (sender, args) =>
     {
         if (FullScreenMedia.Source != null)
         {
             Overlay.Text = FullScreenMedia.Source.AbsolutePath + "\n" +
                            FullScreenMedia.NaturalVideoWidth + "x" + FullScreenMedia.NaturalVideoHeight + "\n" +
                            (FullScreenMedia.NaturalDuration.HasTimeSpan
                            ? FullScreenMedia.NaturalDuration.TimeSpan.ToString()
                            : "");
         }
     };
 }
        public SettingsViewModel()
        {
            // command that show folder selection dialog and add selected folder to list
            _addCommand = new CommandHandler(
                o =>
            {
                var dial = new FolderBrowserDialog();
                if (
                    dial.ShowDialog(null) == DialogResult.OK)
                {
                    _mediaPaths.Add(dial.SelectedPath);
                }
            },
                o => true);
            // command that delete selected folder from list
            _delCommand = new CommandHandler(o =>
            {
                if (!String.IsNullOrWhiteSpace(_selectedRow) && _mediaPaths.Contains(_selectedRow))
                {
                    _mediaPaths.Remove(_selectedRow);
                }
            }, o => !String.IsNullOrWhiteSpace(_selectedRow));

            // command that will remove all registry keys
            _removeSettingsCommand = new CommandHandler(o =>
            {
                if (System.Windows.MessageBox.Show("Are you sure you want to remove all settings from registry?", "Remove all settings", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    PreferenceManager.RemoveRegistryKeys();
                    Application.Current.Shutdown();
                }
            }, o => true);

            // command that will save setting to registry
            _saveCommand = new CommandHandler(o =>
            {
                PreferenceManager.WriteVideoSettings(_mediaPaths.ToList());
                PreferenceManager.WriteVolumeSetting((float)Volume / 100F);
                PreferenceManager.WriteAlgorithmSetting(NextMediaAlgorithm);
                PreferenceManager.WriteIntervalSetting(Interval);
                PreferenceManager.WriteVolumeTimeoutSetting(VolumeTimeout);
                Application.Current.Shutdown();
            }, o => true);

            // command that will remove all registry keys
            _cancelCommand = new CommandHandler(o =>
            {
                if (System.Windows.MessageBox.Show("Are you sure you want to close settings and discard changes?", "Exit and discard", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    Application.Current.Shutdown();
                }
            }, o => true);

            // list of folders
            var list = PreferenceManager.ReadVideoSettings();

            foreach (var item in list)
            {
                _mediaPaths.Add(item);
            }

            Volume             = (int)(PreferenceManager.ReadVolumeSetting() * 100);
            NextMediaAlgorithm = PreferenceManager.ReadAlgorithmSetting();
            Interval           = PreferenceManager.ReadIntervalSetting();
            VolumeTimeout      = PreferenceManager.ReadVolumeTimeoutSetting();
        }