Skip to content

Commit 3de2e54

Browse files
author
RandomEngy
committed
Moved DVD player preference to options dialog, added "Play source" button
to preview window.
1 parent a2222cb commit 3de2e54

12 files changed

Lines changed: 170 additions & 95 deletions

VidCoder/Properties/Resources.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Properties/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ You should set this if you know your playback device only supports a certain pro
326326
<value>Duration</value>
327327
</data>
328328
<data name="AutoAudioDisabledToolTip" xml:space="preserve">
329-
<value>When automatic audio selection is disabled, the last picked track is re-selected.</value>
329+
<value>When automatic audio selection is disabled, the last picked track is persisted.</value>
330330
</data>
331331
<data name="AutoSubtitleDisabledToolTip" xml:space="preserve">
332-
<value>When automatic subtitle selection is disabled, the last picked subtitles are re-selected.</value>
332+
<value>When automatic subtitle selection is disabled, the last picked subtitles are persisted.</value>
333333
</data>
334334
<data name="ForeignAudioSearchToolTip" xml:space="preserve">
335335
<value>Searches for subtitle track that is likely to contain bits of foreign dialogue. Good for movies that are mainly in your native language.</value>

VidCoder/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,8 @@
194194
<Setting Name="AutoSubtitleBurnIn" Type="System.Boolean" Scope="User">
195195
<Value Profile="(Default)">True</Value>
196196
</Setting>
197+
<Setting Name="PreferredPlayer" Type="System.String" Scope="User">
198+
<Value Profile="(Default)">vlc</Value>
199+
</Setting>
197200
</Settings>
198201
</SettingsFile>

VidCoder/Utilities/Utilities.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -365,29 +365,6 @@ private static string GetFormatForFilesize(double size)
365365
return "F" + decimalPlaces;
366366
}
367367

368-
//public static string FormatFileSize(long size)
369-
//{
370-
// if (size < 1000)
371-
// {
372-
// return size.ToString(CultureInfo.InvariantCulture) + " bytes";
373-
// }
374-
375-
// double kilobytes = (double)size / 1024;
376-
// if (kilobytes < 1000)
377-
// {
378-
// return kilobytes.ToString("F2", CultureInfo.InvariantCulture) + " KB";
379-
// }
380-
381-
// double megabytes = kilobytes / 1024;
382-
// if (megabytes < 1000)
383-
// {
384-
// return megabytes.ToString("F2", CultureInfo.InvariantCulture) + " MB";
385-
// }
386-
387-
// double gigabytes = kilobytes / 1024;
388-
// return gigabytes.ToString("F2", CultureInfo.InvariantCulture) + " GB";
389-
//}
390-
391368
public static IMessageBoxService MessageBox
392369
{
393370
get
@@ -494,6 +471,11 @@ public static string GetSourceNameFolder(string videoFolder)
494471
}
495472
}
496473

474+
public static bool IsDvdFolder(string directory)
475+
{
476+
return Path.GetFileName(directory) == "VIDEO_TS" || Directory.Exists(Path.Combine(directory, "VIDEO_TS"));
477+
}
478+
497479
public static bool IsDiscFolder(string directory)
498480
{
499481
try

VidCoder/View/OptionsDialog.xaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@
2626
<CheckBox
2727
Height="16" Margin="10,69,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="230"
2828
IsChecked="{Binding PlaySoundOnCompletion}">Play sound on queue completion</CheckBox>
29-
29+
30+
<TextBlock
31+
Height="23" HorizontalAlignment="Left" Margin="10,100,0,0" Text="Preferred DVD player:" VerticalAlignment="Top" />
32+
<ComboBox
33+
Height="23" HorizontalAlignment="Left" Margin="133,97,0,0" VerticalAlignment="Top"
34+
ItemsSource="{Binding PlayerChoices}"
35+
DisplayMemberPath="Display"
36+
SelectedItem="{Binding SelectedPlayer}" />
37+
3038
<CheckBox
31-
Height="16" Margin="10,103,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="182"
39+
Height="16" Margin="10,135,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="182"
3240
IsChecked="{Binding UpdatesEnabled}">Enable automatic updates</CheckBox>
3341
<Grid
34-
Height="31" Margin="27,125,11,0" VerticalAlignment="Top"
42+
Height="31" Margin="27,157,11,0" VerticalAlignment="Top"
3543
Visibility="{Binding UpdatesEnabled, Converter={StaticResource VisibilityConverter}}">
3644
<Grid.ColumnDefinitions>
3745
<ColumnDefinition Width="Auto" />

VidCoder/View/PreviewWindow.xaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:controls="clr-namespace:VidCoder.Controls"
55
Title="{Binding Title}"
66
Width="864" Height="514"
7-
MinWidth="300" MinHeight="200"
7+
MinWidth="405" MinHeight="200"
88
Closing="Window_Closing"
99
AllowDrop="True"
1010
PreviewDrop="Window_PreviewDrop"
@@ -72,14 +72,24 @@
7272
Visibility="{Binding GeneratingPreview, Converter={StaticResource VisibilityConverter}, ConverterParameter=True}">
7373
<Button
7474
Height="23"
75-
Command="{Binding GeneratePreviewCommand}" ToolTip="Encodes and plays a small preview clip from the selected screen. Uses current encoding settings.">
75+
Command="{Binding PlaySourceCommand}" ToolTip="Plays the source video."
76+
Margin="0,0,0,0">
77+
<StackPanel Orientation="Horizontal" Margin="4,0">
78+
<Image Source="/Icons/blue_play_80.png" VerticalAlignment="Center" Height="15" />
79+
<TextBlock Text="Play Source" Margin="5,0,0,0" VerticalAlignment="Center" />
80+
</StackPanel>
81+
</Button>
82+
<Button
83+
Height="23"
84+
Command="{Binding GeneratePreviewCommand}" ToolTip="Encodes and plays a small preview clip from the selected screen. Uses current encoding settings."
85+
Margin="20,0,0,0">
7686
<StackPanel Orientation="Horizontal" Margin="4,0">
7787
<Image Source="/Icons/play_clip.png" VerticalAlignment="Center" Height="15" />
7888
<TextBlock Text="Encode Preview Clip" Margin="5,0,0,0" VerticalAlignment="Center" />
7989
</StackPanel>
8090
</Button>
8191
<ComboBox
82-
Height="22" Width="45" Margin="20,0,0,0"
92+
Height="22" Width="45" Margin="10,0,0,0"
8393
SelectedValue="{Binding PreviewSeconds}"
8494
SelectedValuePath="Content">
8595
<ComboBoxItem>5</ComboBoxItem>

VidCoder/View/QueueTitlesDialog.xaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
<TextBlock Text="Play Source" Margin="5,0,0,0" VerticalAlignment="Center" />
5050
</StackPanel>
5151
</Button>
52-
<ComboBox
53-
Margin="7,0,0,0"
54-
ItemsSource="{Binding PlayerChoices}"
55-
DisplayMemberPath="Display"
56-
SelectedItem="{Binding SelectedPlayer}"
57-
Visibility="{Binding PlayersAvailable, Converter={StaticResource VisibilityConverter}}"/>
5852
</StackPanel>
5953
</Grid>
6054
<CheckBox Name="checkBox1" Margin="23,0,0,106" HorizontalAlignment="Left" VerticalAlignment="Bottom" IsChecked="{Binding SelectRange}">

VidCoder/ViewModel/OptionsDialogViewModel.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class OptionsDialogViewModel : OkCancelDialogViewModel
3434
private int previewCount;
3535
private bool showAudioTrackNameField;
3636

37+
private List<IVideoPlayer> playerChoices;
38+
3739
private int initialLogVerbosity;
3840

3941
private IUpdater updateService;
@@ -81,6 +83,21 @@ public OptionsDialogViewModel(IUpdater updateService)
8183
}
8284
}
8385

86+
this.playerChoices = Players.All;
87+
if (this.playerChoices.Count > 0)
88+
{
89+
this.selectedPlayer = this.playerChoices[0];
90+
91+
foreach (IVideoPlayer player in this.playerChoices)
92+
{
93+
if (player.Id == Settings.Default.PreferredPlayer)
94+
{
95+
this.selectedPlayer = player;
96+
break;
97+
}
98+
}
99+
}
100+
84101
this.initialLogVerbosity = this.LogVerbosity;
85102
}
86103

@@ -157,6 +174,29 @@ public double UpdateProgress
157174
}
158175
}
159176

177+
public List<IVideoPlayer> PlayerChoices
178+
{
179+
get
180+
{
181+
return this.playerChoices;
182+
}
183+
}
184+
185+
private IVideoPlayer selectedPlayer;
186+
public IVideoPlayer SelectedPlayer
187+
{
188+
get
189+
{
190+
return this.selectedPlayer;
191+
}
192+
193+
set
194+
{
195+
this.selectedPlayer = value;
196+
this.RaisePropertyChanged(() => this.SelectedPlayer);
197+
}
198+
}
199+
160200
public string DefaultPath
161201
{
162202
get
@@ -656,6 +696,9 @@ public RelayCommand SaveSettingsCommand
656696
Settings.Default.DeleteSourceFilesOnClearingCompleted = this.DeleteSourceFilesOnClearingCompleted;
657697
Settings.Default.MinimumTitleLengthSeconds = this.MinimumTitleLengthSeconds;
658698
Settings.Default.VideoFileExtensions = this.VideoFileExtensions;
699+
700+
Settings.Default.PreferredPlayer = this.selectedPlayer.Id;
701+
659702
Settings.Default.Save();
660703

661704
Messenger.Default.Send(new OptionsChangedMessage());

VidCoder/ViewModel/PreviewViewModel.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ public bool HasPreview
202202
{
203203
this.hasPreview = value;
204204
this.GeneratePreviewCommand.RaiseCanExecuteChanged();
205+
this.PlaySourceCommand.RaiseCanExecuteChanged();
205206
this.RaisePropertyChanged(() => this.SeekBarEnabled);
206207
this.RaisePropertyChanged(() => this.HasPreview);
208+
this.RaisePropertyChanged(() => this.PlayAvailable);
207209
}
208210
}
209211

@@ -264,6 +266,33 @@ public int PreviewCount
264266
}
265267
}
266268

269+
public bool PlayAvailable
270+
{
271+
get
272+
{
273+
if (!this.HasPreview || this.mainViewModel.SourcePath == null)
274+
{
275+
return false;
276+
}
277+
278+
string sourcePath = this.mainViewModel.SourcePath;
279+
var fileAttributes = File.GetAttributes(sourcePath);
280+
if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
281+
{
282+
// Path is a directory. Can only preview when it's a DVD and we have a supported player installed.
283+
bool isDvd = Utilities.IsDvdFolder(this.mainViewModel.SourcePath);
284+
bool playerInstalled = Players.Installed.Count > 0;
285+
286+
return isDvd && playerInstalled;
287+
}
288+
else
289+
{
290+
// Path is a file
291+
return true;
292+
}
293+
}
294+
}
295+
267296
public HandBrakeInstance ScanInstance
268297
{
269298
get
@@ -299,6 +328,38 @@ public RelayCommand GeneratePreviewCommand
299328
}
300329
}
301330

331+
private RelayCommand playSourceCommand;
332+
public RelayCommand PlaySourceCommand
333+
{
334+
get
335+
{
336+
return this.playSourceCommand ?? (this.playSourceCommand = new RelayCommand(() =>
337+
{
338+
string sourcePath = this.mainViewModel.SourcePath;
339+
var fileAttributes = File.GetAttributes(sourcePath);
340+
if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
341+
{
342+
// Path is a directory
343+
IVideoPlayer player = Players.Installed.FirstOrDefault(p => p.Id == Settings.Default.PreferredPlayer);
344+
if (player == null)
345+
{
346+
player = Players.Installed[0];
347+
}
348+
349+
player.PlayTitle(sourcePath, this.mainViewModel.SelectedTitle.TitleNumber);
350+
}
351+
else
352+
{
353+
// Path is a file
354+
FileService.Instance.LaunchFile(sourcePath);
355+
}
356+
}, () =>
357+
{
358+
return this.PlayAvailable;
359+
}));
360+
}
361+
}
362+
302363
private RelayCommand cancelPreviewCommand;
303364
public RelayCommand CancelPreviewCommand
304365
{

0 commit comments

Comments
 (0)