forked from HandBrake/HandBrake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WinGui: Implement a Start Timer option for the queue. (HandBrake#586)
- Loading branch information
Showing
9 changed files
with
364 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<UserControl x:Class="HandBrakeWPF.Controls.SimpleTimeControl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:HandBrakeWPF.Controls" | ||
mc:Ignorable="d" | ||
d:DesignHeight="30" d:DesignWidth="90"> | ||
<Grid> | ||
<StackPanel Orientation="Horizontal"> | ||
<ComboBox x:Name="hour" Width="40" VerticalAlignment="Center" SelectionChanged="Hour_OnSelectionChanged" /> | ||
<TextBlock Text=":" Margin="3,0,3,0" VerticalAlignment="Center" FontSize="14" FontWeight="Bold" /> | ||
<ComboBox x:Name="minute" Width="40" VerticalAlignment="Center" SelectionChanged="Minute_OnSelectionChanged" /> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="SimpleTimeControl.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> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace HandBrakeWPF.Controls | ||
{ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
/// <summary> | ||
/// Interaction logic for SimpleTimeControl.xaml | ||
/// </summary> | ||
public partial class SimpleTimeControl : UserControl | ||
{ | ||
public static readonly DependencyProperty HourProperty = DependencyProperty.Register( | ||
"Hour", typeof(int), typeof(SimpleTimeControl), new PropertyMetadata(0, OnHourChanged)); | ||
|
||
public static readonly DependencyProperty MinuteProperty = DependencyProperty.Register( | ||
"Minute", typeof(int), typeof(SimpleTimeControl), new PropertyMetadata(0, OnMinuteChanged)); | ||
|
||
public SimpleTimeControl() | ||
{ | ||
InitializeComponent(); | ||
this.DataContext = this; | ||
this.hour.SelectedItem = 0; | ||
this.minute.SelectedItem = 1; | ||
|
||
for (int i = 0; i <= 23; i++) | ||
{ | ||
this.hour.Items.Add(i); | ||
} | ||
|
||
for (int i = 0; i <= 59; i++) | ||
{ | ||
this.minute.Items.Add(i); | ||
} | ||
} | ||
|
||
public int Hour | ||
{ | ||
get | ||
{ | ||
return (int)this.GetValue(HourProperty); | ||
} | ||
set | ||
{ | ||
this.SetValue(HourProperty, value); | ||
} | ||
} | ||
|
||
public int Minute | ||
{ | ||
get | ||
{ | ||
return (int)this.GetValue(MinuteProperty); | ||
} | ||
set | ||
{ | ||
this.SetValue(MinuteProperty, value); | ||
} | ||
} | ||
|
||
private static void OnHourChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (d is SimpleTimeControl) | ||
{ | ||
SimpleTimeControl ctlControl = (SimpleTimeControl)d; | ||
ctlControl.hour.SelectedItem = (int)e.NewValue; | ||
} | ||
} | ||
|
||
|
||
private static void OnMinuteChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (d is SimpleTimeControl) | ||
{ | ||
SimpleTimeControl ctlControl = (SimpleTimeControl)d; | ||
ctlControl.minute.SelectedItem = (int)e.NewValue; | ||
} | ||
} | ||
|
||
|
||
private void Hour_OnSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (this.hour.SelectedItem == null || this.minute.SelectedItem == null) | ||
{ | ||
return; | ||
} | ||
|
||
this.Hour = (int)this.hour.SelectedItem; | ||
} | ||
|
||
private void Minute_OnSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (this.hour.SelectedItem == null || this.minute.SelectedItem == null) | ||
{ | ||
return; | ||
} | ||
|
||
this.Minute = (int)this.minute.SelectedItem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="TaskScheduler.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> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
namespace HandBrakeWPF.Utilities | ||
{ | ||
using System; | ||
using System.Threading; | ||
|
||
public class TaskExecutor | ||
{ | ||
private Timer timer; | ||
|
||
private Action action; | ||
|
||
public void ScheduleTask(int hour, int min, Action task) | ||
{ | ||
if (timer != null) | ||
{ | ||
this.CancelTask(); | ||
} | ||
|
||
DateTime now = DateTime.Now; | ||
DateTime firstRun = new DateTime(now.Year, now.Month, now.Day, hour, min, 0, 0); | ||
if (now > firstRun) | ||
{ | ||
firstRun = firstRun.AddDays(1); | ||
} | ||
|
||
TimeSpan timeToGo = firstRun - now; | ||
if (timeToGo <= TimeSpan.Zero) | ||
{ | ||
timeToGo = TimeSpan.Zero; | ||
} | ||
|
||
action = task; | ||
|
||
timer = new Timer(x => | ||
{ | ||
action.Invoke(); | ||
}, null, timeToGo, TimeSpan.FromSeconds(60)); | ||
|
||
|
||
} | ||
|
||
public void CancelTask() | ||
{ | ||
if (this.timer != null) | ||
{ | ||
this.timer.Dispose(); | ||
this.timer = null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.