summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs
blob: 9f12972beac6702fb9db1f680e59bff5bbd548c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VideoView.xaml.cs" company="HandBrake Project (http://handbrake.fr)">
//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
//   Interaction logic for VideoView.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.Views
{
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;

    using HandBrake.ApplicationServices.Model;

    using HandBrakeWPF.ViewModels;

    /// <summary>
    /// Interaction logic for VideoView.xaml
    /// </summary>
    public partial class VideoView : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="VideoView"/> class.
        /// </summary>
        public VideoView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The qsv_preset_radiobutton.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void qsv_preset_radiobutton(object sender, System.Windows.RoutedEventArgs e)
        {
            qsv_preset_ValueChanged(sender, null);
        }

        /// <summary>
        /// The qsv_preset_ value changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void qsv_preset_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            VideoViewModel mvm = ((VideoViewModel)this.DataContext);
            EncodeTask task = mvm.Task;

            string full_string = string.Empty;

            IDictionary<string, string> newOptions = new Dictionary<string, string>();
            string[] existingSegments = full_string.Split(':');
            foreach (string existingSegment in existingSegments)
            {
                string optionName = existingSegment;
                string optionValue = string.Empty;
                int equalsIndex = existingSegment.IndexOf('=');
                if (equalsIndex >= 0)
                {
                    optionName = existingSegment.Substring(
                        0, existingSegment.IndexOf("=", System.StringComparison.Ordinal));
                    optionValue = existingSegment.Substring(equalsIndex);
                }

                if (optionName != string.Empty)
                {
                    if (newOptions.ContainsKey(optionName))
                        newOptions.Remove(optionName);
                    newOptions.Add(optionName, optionValue);
                }
            }

            full_string = string.Empty;
            foreach (KeyValuePair<string, string> entry in newOptions)
            {
                full_string += entry.Key;
                if (entry.Value != string.Empty)
                    full_string += entry.Value;
                full_string += ":";
            }
            full_string = full_string.TrimEnd(':');

            task.AdvancedEncoderOptions = full_string;
            task.NotifyOfPropertyChange(() => task.AdvancedEncoderOptions);
        }
    }
}