Skip to content

Commit 2ffc785

Browse files
author
RandomEngy
committed
Editing a queue item now brings back the encoding profile as well.
1 parent f271973 commit 2ffc785

6 files changed

Lines changed: 101 additions & 25 deletions

File tree

VidCoder/Model/Preset.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Preset
1111
public string Name { get; set; }
1212
public bool IsBuiltIn { get; set; }
1313
public bool IsModified { get; set; }
14+
public bool IsQueue { get; set; }
1415
public EncodingProfile EncodingProfile { get; set; }
1516
}
1617
}

VidCoder/Utilities/Utilities.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,15 @@ public static void DeleteDirectory(string path)
187187
Directory.Delete(path);
188188
}
189189

190-
public static string CleanFileName(string fileName)
190+
public static string CleanFileName(string fileName, bool allowBackslashes = false)
191191
{
192192
string cleanName = fileName;
193193
foreach (string disallowedChar in disallowedCharacters)
194194
{
195-
cleanName = cleanName.Replace(disallowedChar, "_");
195+
if (disallowedChar != @"\" || !allowBackslashes)
196+
{
197+
cleanName = cleanName.Replace(disallowedChar, "_");
198+
}
196199
}
197200

198201
return cleanName;

VidCoder/View/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@
759759
<Setter Property="Foreground" Value="#0B4BC2" />
760760
<Setter Property="FontWeight" Value="Bold" />
761761
</DataTrigger>
762+
<DataTrigger Binding="{Binding IsQueue}" Value="True">
763+
<Setter Property="Foreground" Value="#222222" />
764+
<Setter Property="FontWeight" Value="Normal" />
765+
</DataTrigger>
762766
</Style.Triggers>
763767
</Style>
764768
</TextBlock.Style>

VidCoder/ViewModel/DataModels/PresetViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public bool IsModified
3434
}
3535
}
3636

37+
public bool IsQueue
38+
{
39+
get
40+
{
41+
return this.preset.IsQueue;
42+
}
43+
}
44+
3745
public string PresetName
3846
{
3947
get

VidCoder/ViewModel/EncodingViewModel.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ public string ProfileName
133133
}
134134
}
135135

136+
public bool SaveRenameButtonsVisible
137+
{
138+
get
139+
{
140+
return !this.IsBuiltIn && !this.originalPreset.IsQueue;
141+
}
142+
}
143+
136144
public bool IsBuiltIn
137145
{
138146
get
@@ -152,7 +160,7 @@ public bool DeleteButtonVisible
152160
{
153161
get
154162
{
155-
return !this.IsBuiltIn && !this.IsModified;
163+
return !this.IsBuiltIn && !this.IsModified && !this.originalPreset.IsQueue;
156164
}
157165
}
158166

@@ -167,8 +175,8 @@ public bool IsModified
167175

168176
set
169177
{
170-
// Don't mark as modified if this is an automatic change.
171-
if (!this.AutomaticChange)
178+
// Don't mark as modified if this is an automatic change or if it's a temporary queue preset.
179+
if (!this.AutomaticChange && !this.originalPreset.IsQueue)
172180
{
173181
if (this.originalPreset.IsModified != value)
174182
{
@@ -181,12 +189,12 @@ public bool IsModified
181189
this.NotifyPropertyChanged("IsModified");
182190
this.NotifyPropertyChanged("WindowTitle");
183191
this.NotifyPropertyChanged("DeleteButtonVisible");
192+
}
184193

185-
// If we've made a modification, we need to save the user presets.
186-
if (value)
187-
{
188-
this.mainViewModel.SaveUserPresets();
189-
}
194+
// If we've made a modification, we need to save the user presets.
195+
if (value)
196+
{
197+
this.mainViewModel.SaveUserPresets();
190198
}
191199
}
192200
}
@@ -515,6 +523,7 @@ private void NotifyAllChanged()
515523
this.NotifyPropertyChanged("WindowTitle");
516524
this.NotifyPropertyChanged("ProfileName");
517525
this.NotifyPropertyChanged("IsBuiltIn");
526+
this.NotifyPropertyChanged("SaveRenameButtonsVisible");
518527
this.NotifyPropertyChanged("DeleteButtonVisible");
519528
this.NotifyPropertyChanged("IsModified");
520529
this.NotifyPropertyChanged("OutputFormat");

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,26 +1501,37 @@ public PresetViewModel SelectedPreset
15011501

15021502
if (changeSelectedPreset)
15031503
{
1504-
this.GenerateOutputFileName();
1504+
NotifySelectedPresetChanged();
15051505

1506-
var encodingWindow = WindowManager.FindWindow(typeof(EncodingViewModel)) as EncodingViewModel;
1507-
if (encodingWindow != null)
1506+
// If we're switching away from a temporary queue preset, remove it.
1507+
if (previouslySelectedPreset != null && previouslySelectedPreset.IsQueue && previouslySelectedPreset != value)
15081508
{
1509-
encodingWindow.EditingPreset = this.selectedPreset.Preset;
1509+
this.AllPresets.Remove(previouslySelectedPreset);
15101510
}
1511+
}
1512+
}
1513+
}
15111514

1512-
var previewWindow = WindowManager.FindWindow(typeof(PreviewViewModel)) as PreviewViewModel;
1513-
if (previewWindow != null)
1514-
{
1515-
previewWindow.RequestRefreshPreviews();
1516-
}
1515+
private void NotifySelectedPresetChanged()
1516+
{
1517+
this.GenerateOutputFileName();
15171518

1518-
this.NotifyPropertyChanged("SelectedPreset");
1519-
}
1519+
var encodingWindow = WindowManager.FindWindow(typeof (EncodingViewModel)) as EncodingViewModel;
1520+
if (encodingWindow != null)
1521+
{
1522+
encodingWindow.EditingPreset = this.selectedPreset.Preset;
1523+
}
15201524

1521-
this.NotifyPropertyChanged("ShowChapterMarkerUI");
1522-
Properties.Settings.Default.LastPresetIndex = this.AllPresets.IndexOf(this.selectedPreset);
1525+
var previewWindow = WindowManager.FindWindow(typeof (PreviewViewModel)) as PreviewViewModel;
1526+
if (previewWindow != null)
1527+
{
1528+
previewWindow.RequestRefreshPreviews();
15231529
}
1530+
1531+
this.NotifyPropertyChanged("SelectedPreset");
1532+
this.NotifyPropertyChanged("ShowChapterMarkerUI");
1533+
1534+
Settings.Default.LastPresetIndex = this.AllPresets.IndexOf(this.selectedPreset);
15241535
}
15251536

15261537
public int SelectedTabIndex
@@ -3165,6 +3176,23 @@ public void EditQueueJob(EncodeJobViewModel jobVM)
31653176
{
31663177
EncodeJob job = jobVM.Job;
31673178

3179+
if (this.SelectedPreset.IsModified)
3180+
{
3181+
MessageBoxResult dialogResult = Utilities.MessageBox.Show(this, "Do you want to save changes to your current preset?", "Save current preset?", MessageBoxButton.YesNoCancel);
3182+
if (dialogResult == MessageBoxResult.Yes)
3183+
{
3184+
this.SavePreset();
3185+
}
3186+
else if (dialogResult == MessageBoxResult.No)
3187+
{
3188+
this.RevertPreset(userInitiated: false);
3189+
}
3190+
else if (dialogResult == MessageBoxResult.Cancel)
3191+
{
3192+
return;
3193+
}
3194+
}
3195+
31683196
if (jobVM.HandBrakeInstance != null && jobVM.HandBrakeInstance == this.ScanInstance)
31693197
{
31703198
this.ApplyEncodeJobChoices(jobVM);
@@ -3218,8 +3246,31 @@ public void EditQueueJob(EncodeJobViewModel jobVM)
32183246
this.StartScan(job.SourcePath, jobVM);
32193247
}
32203248

3249+
// Bring in encoding profile and put in a placeholder preset.
3250+
if (this.AllPresets[0].IsQueue)
3251+
{
3252+
this.AllPresets.RemoveAt(0);
3253+
}
3254+
3255+
var queuePreset = new PresetViewModel(
3256+
new Preset
3257+
{
3258+
IsBuiltIn = false,
3259+
IsModified = false,
3260+
IsQueue = true,
3261+
Name = "Restored from Queue",
3262+
EncodingProfile = jobVM.Job.EncodingProfile
3263+
});
3264+
3265+
this.AllPresets.Insert(0, queuePreset);
3266+
3267+
this.selectedPreset = queuePreset;
3268+
this.NotifySelectedPresetChanged();
3269+
32213270
// Since it's been sent back for editing, remove the queue item
32223271
this.EncodeQueue.Remove(jobVM);
3272+
3273+
this.SaveUserPresets();
32233274
}
32243275

32253276
public void RemoveQueueJob(EncodeJobViewModel job)
@@ -3427,7 +3478,7 @@ public void SaveUserPresets()
34273478

34283479
foreach (PresetViewModel presetVM in this.AllPresets)
34293480
{
3430-
if (!presetVM.Preset.IsBuiltIn || presetVM.Preset.IsModified)
3481+
if ((!presetVM.Preset.IsBuiltIn || presetVM.Preset.IsModified) && !presetVM.IsQueue)
34313482
{
34323483
userPresets.Add(presetVM.Preset);
34333484
}
@@ -4246,7 +4297,7 @@ private string BuildOutputFileName(string sourcePath, string sourceName, int tit
42464297
fileName = sourceName + titleSection + rangeSection;
42474298
}
42484299

4249-
return Utilities.CleanFileName(fileName);
4300+
return Utilities.CleanFileName(fileName, allowBackslashes: true);
42504301
}
42514302

42524303
private static string ReplaceTitles(string inputString, int title)

0 commit comments

Comments
 (0)