diff options
author | sr55 <[email protected]> | 2013-02-02 20:01:41 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-02-02 20:01:41 +0000 |
commit | 81cf237836e97f9a0e23796da98f6411db783227 (patch) | |
tree | 1f0d9b8f21188ba2ebe9c5bd2dd26ae2175c5833 /win/CS/HandBrakeWPF | |
parent | 2837d87bf7ac9255546976213e217d213dd10c1a (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')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/UserSettingConstants.cs | 10 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 48 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/ShellView.xaml.cs | 80 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/defaultsettings.xml | 18 |
6 files changed, 82 insertions, 77 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index c2214eee4..71bac458b 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -106,6 +106,7 @@ <Reference Include="System.Management" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
+ <Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\libraries\caliburn\System.Windows.Interactivity.dll</HintPath>
</Reference>
diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index f0414ef6b..030cdedac 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -132,16 +132,6 @@ namespace HandBrakeWPF public const string Skipversion = "skipversion";
/// <summary>
- /// Tooltip
- /// </summary>
- public const string TooltipEnable = "tooltipEnable";
-
- /// <summary>
- /// Tray Icon
- /// </summary>
- public const string TrayIconAlerts = "trayIconAlerts";
-
- /// <summary>
/// Update Status
/// </summary>
public const string UpdateStatus = "updateStatus";
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 36fa35985..8e771fb66 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -147,16 +147,6 @@ namespace HandBrakeWPF.ViewModels private bool disablePresetUpdateCheckNotification;
/// <summary>
- /// The display status messages tray icon.
- /// </summary>
- private bool displayStatusMessagesTrayIcon;
-
- /// <summary>
- /// The enable gui tooltips.
- /// </summary>
- private bool enableGuiTooltips;
-
- /// <summary>
/// The growl after encode.
/// </summary>
private bool growlAfterEncode;
@@ -570,23 +560,6 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Gets or sets a value indicating whether EnableGuiTooltips.
- /// </summary>
- public bool EnableGuiTooltips
- {
- get
- {
- return this.enableGuiTooltips;
- }
-
- set
- {
- this.enableGuiTooltips = value;
- this.NotifyOfPropertyChange("EnableGuiTooltips");
- }
- }
-
- /// <summary>
/// Gets or sets WhenDone.
/// </summary>
public string WhenDone
@@ -1172,23 +1145,6 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Gets or sets a value indicating whether DisplayStatusMessagesTrayIcon.
- /// </summary>
- public bool DisplayStatusMessagesTrayIcon
- {
- get
- {
- return this.displayStatusMessagesTrayIcon;
- }
-
- set
- {
- this.displayStatusMessagesTrayIcon = value;
- this.NotifyOfPropertyChange("DisplayStatusMessagesTrayIcon");
- }
- }
-
- /// <summary>
/// Gets or sets LogVerbosityOptions.
/// </summary>
public BindingList<int> LogVerbosityOptions
@@ -1478,7 +1434,6 @@ namespace HandBrakeWPF.ViewModels // General
// #############################
- this.EnableGuiTooltips = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.TooltipEnable);
this.CheckForUpdates = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.UpdateStatus);
// Days between update checks
@@ -1647,7 +1602,6 @@ namespace HandBrakeWPF.ViewModels // #############################
// Minimise to Tray
- this.DisplayStatusMessagesTrayIcon = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.TrayIconAlerts);
this.MinimiseToTray = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.MainWindowMinimize);
this.DisablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PresetNotification);
this.ClearQueueOnEncodeCompleted = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.ClearCompletedFromQueue);
@@ -1839,7 +1793,6 @@ namespace HandBrakeWPF.ViewModels /* General */
this.userSettingService.SetUserSetting(UserSettingConstants.UpdateStatus, this.CheckForUpdates);
this.userSettingService.SetUserSetting(UserSettingConstants.DaysBetweenUpdateCheck, this.CheckForUpdatesFrequency);
- this.userSettingService.SetUserSetting(UserSettingConstants.TooltipEnable, this.EnableGuiTooltips);
this.userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, this.WhenDone);
this.userSettingService.SetUserSetting(UserSettingConstants.GrowlQueue, this.GrowlAfterQueue);
this.userSettingService.SetUserSetting(UserSettingConstants.GrowlEncode, this.GrowlAfterEncode);
@@ -1881,7 +1834,6 @@ namespace HandBrakeWPF.ViewModels /* Advanced */
userSettingService.SetUserSetting(UserSettingConstants.MainWindowMinimize, this.MinimiseToTray);
- userSettingService.SetUserSetting(UserSettingConstants.TrayIconAlerts, this.DisplayStatusMessagesTrayIcon);
userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification);
userSettingService.SetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue, this.ClearQueueOnEncodeCompleted);
userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount);
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);
}
}
diff --git a/win/CS/HandBrakeWPF/defaultsettings.xml b/win/CS/HandBrakeWPF/defaultsettings.xml index c1a645647..48576180a 100644 --- a/win/CS/HandBrakeWPF/defaultsettings.xml +++ b/win/CS/HandBrakeWPF/defaultsettings.xml @@ -130,14 +130,6 @@ </item>
<item>
<key>
- <string>tooltipEnable</string>
- </key>
- <value>
- <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">true</anyType>
- </value>
- </item>
- <item>
- <key>
<string>defaultPreset</string>
</key>
<value>
@@ -205,7 +197,7 @@ <string>MainWindowMinimize</string>
</key>
<value>
- <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">true</anyType>
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>
</value>
</item>
<item>
@@ -226,14 +218,6 @@ </item>
<item>
<key>
- <string>trayIconAlerts</string>
- </key>
- <value>
- <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">true</anyType>
- </value>
- </item>
- <item>
- <key>
<string>lastUpdateCheckDate</string>
</key>
<value>
|