summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Views
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-02-02 20:01:41 +0000
committersr55 <[email protected]>2013-02-02 20:01:41 +0000
commit81cf237836e97f9a0e23796da98f6411db783227 (patch)
tree1f0d9b8f21188ba2ebe9c5bd2dd26ae2175c5833 /win/CS/HandBrakeWPF/Views
parent2837d87bf7ac9255546976213e217d213dd10c1a (diff)
WinGui: Add support for the tray icon.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5235 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Views')
-rw-r--r--win/CS/HandBrakeWPF/Views/OptionsView.xaml2
-rw-r--r--win/CS/HandBrakeWPF/Views/ShellView.xaml.cs80
2 files changed, 80 insertions, 2 deletions
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
index 99d857bdc..389a80791 100644
--- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml
+++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
@@ -290,7 +290,7 @@
<StackPanel Orientation="Vertical" Grid.Column="1" Margin="20,0,0,0">
<CheckBox Content="Prevent the system from sleeping while encoding" IsChecked="{Binding PreventSleep}" />
- <CheckBox Content="Minimize to system tray (Requires Restart)" Visibility="Collapsed" IsChecked="{Binding MinimiseToTray}" />
+ <CheckBox Content="Minimize to system tray (Requires Restart)" IsChecked="{Binding MinimiseToTray}" />
<CheckBox Content="Display status messages from tray icon (balloon popups)" Visibility="Collapsed" IsChecked="{Binding DisplayStatusMessagesTrayIcon}" />
<CheckBox Content="Disable built-in preset update notification" IsChecked="{Binding DisablePresetUpdateCheckNotification}" />
<CheckBox Content="Always clear completed queue items after an encode completes" IsChecked="{Binding ClearQueueOnEncodeCompleted}" />
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
index 8a086ea09..b1eff7ddd 100644
--- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
+++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
@@ -9,26 +9,58 @@
namespace HandBrakeWPF.Views
{
+ using System;
+ using System.IO;
using System.Windows;
+ using System.Windows.Forms;
using System.Windows.Input;
+ using System.Windows.Resources;
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Commands;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Application = System.Windows.Application;
+
/// <summary>
/// Interaction logic for ShellView.xaml
/// </summary>
- public partial class ShellView : Window
+ public partial class ShellView
{
/// <summary>
+ /// The my notify icon.
+ /// </summary>
+ private readonly System.Windows.Forms.NotifyIcon notifyIcon;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="ShellView"/> class.
/// </summary>
public ShellView()
{
this.InitializeComponent();
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ bool minimiseToTray = userSettingService.GetUserSetting<bool>(UserSettingConstants.MainWindowMinimize);
+
+ if (minimiseToTray)
+ {
+ this.notifyIcon = new System.Windows.Forms.NotifyIcon();
+ this.notifyIcon.ContextMenu = new ContextMenu(new[] { new MenuItem("Restore", NotifyIconClick) });
+
+ StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/handbrakepineapple.ico"));
+ if (streamResourceInfo != null)
+ {
+ Stream iconStream = streamResourceInfo.Stream;
+ this.notifyIcon.Icon = new System.Drawing.Icon(iconStream);
+ }
+ this.notifyIcon.DoubleClick += this.NotifyIconClick;
+ this.StateChanged += this.ShellViewStateChanged;
+ }
+
// Start Encode (Ctrl+S)
// Stop Encode (Ctrl+K)
// Open Log Window (Ctrl+L)
@@ -53,6 +85,47 @@ namespace HandBrakeWPF.Views
}
/// <summary>
+ /// The notify icon_ click.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void NotifyIconClick(object sender, EventArgs e)
+ {
+ this.WindowState = WindowState.Normal;
+ }
+
+ /// <summary>
+ /// The shell view state changed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void ShellViewStateChanged(object sender, EventArgs e)
+ {
+ if (this.notifyIcon != null)
+ {
+ if (this.WindowState == WindowState.Minimized)
+ {
+ this.ShowInTaskbar = false;
+ notifyIcon.Visible = true;
+ // notifyIcon.ShowBalloonTip(5000, "HandBrake", "Application Minimised", ToolTipIcon.Info);
+ }
+ else if (this.WindowState == WindowState.Normal)
+ {
+ notifyIcon.Visible = false;
+ this.ShowInTaskbar = true;
+ }
+ }
+ }
+
+ /// <summary>
/// Check with the user before closing.
/// </summary>
/// <param name="e">
@@ -71,6 +144,11 @@ namespace HandBrakeWPF.Views
}
}
+ if (this.notifyIcon != null)
+ {
+ this.notifyIcon.Visible = false;
+ }
+
base.OnClosing(e);
}
}