summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs
blob: e9d54d4ce59ebf804d15571b0081aff92a24145c (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
// --------------------------------------------------------------------------------------------------------------------
// <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 Caliburn.Micro;

    using HandBrake.ApplicationServices.Model;
    using HandBrake.ApplicationServices.Utilities;
    using HandBrake.Interop.Model.Encoding;

    using HandBrakeWPF.ViewModels;
    using HandBrakeWPF.ViewModels.Interfaces;

    /// <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();
        }


        private void qsv_preset_radiobutton(object sender, System.Windows.RoutedEventArgs e)
        {
            qsv_preset_ValueChanged(sender, null);
        }

        private void qsv_preset_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            VideoViewModel mvm = ((VideoViewModel)this.DataContext);
            EncodeTask task = mvm.Task;

            string full_string = "";

            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 = "";
            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);
        }
    }
}