diff options
author | sr55 <[email protected]> | 2012-10-10 20:13:19 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-10-10 20:13:19 +0000 |
commit | 1bbc7702f0d57f826ae359dfd519e2c1400f84da (patch) | |
tree | 714e36990eb8cac4f866c287dd93916374edc493 /win/CS | |
parent | 7602fc9323c7e2f73fde18363e1abc44f99dd392 (diff) |
WinGui: API Tidyup Part 2 of many. Growl Support.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5011 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 12 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/GrowlCommunicator.cs | 124 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.Designer.cs | 9 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.resx | 4 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Resources/logo64.png | bin | 0 -> 11967 bytes | |||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs | 6 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/NotificationService.cs | 84 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/UserSettingConstants.cs | 10 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 6 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 10 |
11 files changed, 259 insertions, 7 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 3597bb029..17eec09d0 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -87,6 +87,14 @@ <Reference Include="GongSolutions.Wpf.DragDrop">
<HintPath>..\libraries\WPFDragDrop\GongSolutions.Wpf.DragDrop.dll</HintPath>
</Reference>
+ <Reference Include="Growl.Connector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=980c2339411be384, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\libraries\Growl.Connector.dll</HintPath>
+ </Reference>
+ <Reference Include="Growl.CoreLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=13e59d82e007b064, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\libraries\Growl.CoreLibrary.dll</HintPath>
+ </Reference>
<Reference Include="Ookii.Dialogs.Wpf">
<HintPath>..\libraries\OokiiDialogs\Ookii.Dialogs.Wpf.dll</HintPath>
</Reference>
@@ -129,6 +137,7 @@ <Compile Include="Converters\Options\OptionsTabConverter.cs" />
<Compile Include="Converters\Subtitles\SubtitlesQueueDisplayConverter.cs" />
<Compile Include="Converters\Video\VideoEncoderConverter.cs" />
+ <Compile Include="Helpers\GrowlCommunicator.cs" />
<Compile Include="Services\DriveDetectService.cs" />
<Compile Include="Services\EncodeServiceWrapper.cs" />
<Compile Include="Services\Interfaces\IDriveDetectService.cs" />
@@ -136,7 +145,9 @@ <Compile Include="Model\SourceMenuItem.cs" />
<Compile Include="Model\UpdateCheckInformation.cs" />
<Compile Include="Model\DownloadStatus.cs" />
+ <Compile Include="Services\Interfaces\INotificationService.cs" />
<Compile Include="Services\Interfaces\IUpdateService.cs" />
+ <Compile Include="Services\NotificationService.cs" />
<Compile Include="Services\ScanServiceWrapper.cs" />
<Compile Include="Services\UpdateService.cs" />
<Compile Include="Views\ShellView.xaml.cs">
@@ -366,6 +377,7 @@ <Content Include="defaultsettings.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <None Include="Resources\logo64.png" />
<Resource Include="Views\Images\warningsmall.png" />
<Resource Include="Views\Images\Refresh.ico" />
<Resource Include="Views\Images\Complete.png" />
diff --git a/win/CS/HandBrakeWPF/Helpers/GrowlCommunicator.cs b/win/CS/HandBrakeWPF/Helpers/GrowlCommunicator.cs new file mode 100644 index 000000000..cd711b583 --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/GrowlCommunicator.cs @@ -0,0 +1,124 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="GrowlCommunicator.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>
+// <summary>
+// Provides all functionality for communicating with Growl for Windows.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+
+ using Growl.Connector;
+
+ /// <summary>
+ /// Provides all functionality for communicating with Growl for Windows.
+ /// </summary>
+ /// <remarks>
+ /// This class is implemented as a static class because:
+ /// 1. It allows nearly all of the Growl-related code to be in one place
+ /// 2. It prevents the main form, queue handler, and any other part of Handbrake from having to declare
+ /// or track any new instance variables
+ /// </remarks>
+ public static class GrowlCommunicator
+ {
+ /// <summary>
+ /// The <see cref="GrowlConnector"/> that actually talks to Growl
+ /// </summary>
+ private static GrowlConnector growl;
+
+ /// <summary>
+ /// The Handbrake application instance that is registered with Growl
+ /// </summary>
+ private static Application application;
+
+ /// <summary>
+ /// Notification shown upon completion of encoding
+ /// </summary>
+ private static NotificationType encodeOrQueueCompleted = new NotificationType("EncodeOrQueue", "HandBrake Status");
+
+ /// <summary>
+ /// Checks to see if Growl is currently running on the local machine.
+ /// </summary>
+ /// <returns>
+ /// <c>true</c> if Growl is running;
+ /// <c>false</c> otherwise
+ /// </returns>
+ public static bool IsRunning()
+ {
+ Initialize();
+
+ return GrowlConnector.IsGrowlRunningLocally();
+ }
+
+ /// <summary>
+ /// Registers Handbrake with the local Growl instance
+ /// </summary>
+ /// <remarks>
+ /// This should usually be called at application start-up
+ /// </remarks>
+ public static void Register()
+ {
+ Initialize();
+ growl.Register(application, new[] {encodeOrQueueCompleted});
+ }
+
+ /// <summary>
+ /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with
+ /// static text, this is a shortcut method).
+ /// </summary>
+ /// <param name="title">
+ /// The title.
+ /// </param>
+ /// <param name="text">
+ /// The text to display.
+ /// </param>
+ public static void Notify(string title, string text)
+ {
+ Notification notification = new Notification(application.Name, encodeOrQueueCompleted.Name, String.Empty,
+ title, text);
+ growl.Notify(notification);
+ }
+
+ /// <summary>
+ /// Sends a notification to Growl. (This is the more generic version that could be used in the future if
+ /// more notification types are implemented)
+ /// </summary>
+ /// <param name="notificationType">The <see cref="NotificationType">type</see> of notification to send</param>
+ /// <param name="title">The notification title</param>
+ /// <param name="text">The notification text</param>
+ /// <param name="imageUrl">The notification image as a url</param>
+ public static void Notify(NotificationType notificationType, string title, string text, string imageUrl)
+ {
+ Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title,
+ text)
+ {
+ Icon = imageUrl
+ };
+
+ growl.Notify(notification);
+ }
+
+ /// <summary>
+ /// Initializes the GrowlCommunicator
+ /// </summary>
+ private static void Initialize()
+ {
+ if (growl == null)
+ {
+ growl = new GrowlConnector
+ {
+ EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText,
+ KeyHashAlgorithm = Cryptography.HashAlgorithmType.SHA1
+ };
+
+ application = new Application("Handbrake")
+ {
+ Icon = Properties.Resources.logo64
+ };
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 10b0c5c43..0978c2fca 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.17020
+// Runtime Version:4.0.30319.269
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -278,5 +278,12 @@ namespace HandBrakeWPF.Properties { return ResourceManager.GetString("Advanced_WeightPToolTip", resourceCulture);
}
}
+
+ public static System.Drawing.Bitmap logo64 {
+ get {
+ object obj = ResourceManager.GetObject("logo64", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index a4b5f6259..9c92427cb 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -233,4 +233,8 @@ Baseline profile, as required for iPods and similar devices, requires weighted P Note that some devices and players, even those that support Main Profile,
may have problems with Weighted P-frame prediction: the Apple TV is completely incompatible with it, for example.</value>
</data>
+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <data name="logo64" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\logo64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Resources/logo64.png b/win/CS/HandBrakeWPF/Resources/logo64.png Binary files differnew file mode 100644 index 000000000..12808f636 --- /dev/null +++ b/win/CS/HandBrakeWPF/Resources/logo64.png diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs new file mode 100644 index 000000000..d955bb55c --- /dev/null +++ b/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs @@ -0,0 +1,6 @@ +namespace HandBrakeWPF.Services.Interfaces
+{
+ public interface INotificationService
+ {
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/NotificationService.cs b/win/CS/HandBrakeWPF/Services/NotificationService.cs new file mode 100644 index 000000000..234130b72 --- /dev/null +++ b/win/CS/HandBrakeWPF/Services/NotificationService.cs @@ -0,0 +1,84 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="NotificationService.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>
+// <summary>
+// The Notification Service (Growl Connector)
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services
+{
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
+ using HandBrakeWPF.Helpers;
+ using HandBrakeWPF.Services.Interfaces;
+
+ /// <summary>
+ /// The Notification Service (Growl Connector)
+ /// </summary>
+ public class NotificationService : INotificationService
+ {
+ /// <summary>
+ /// The user setting service.
+ /// </summary>
+ private readonly IUserSettingService userSettingService;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="NotificationService"/> class.
+ /// </summary>
+ /// <param name="encodeService">
+ /// The encode Service.
+ /// </param>
+ /// <param name="queueProcessor">
+ /// The queue Processor.
+ /// </param>
+ /// <param name="userSettingService">
+ /// The user Setting Service.
+ /// </param>
+ public NotificationService(IEncodeServiceWrapper encodeService, IQueueProcessor queueProcessor, IUserSettingService userSettingService)
+ {
+ this.userSettingService = userSettingService;
+ encodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted;
+ queueProcessor.QueueCompleted += this.QueueProcessorQueueCompleted;
+ GrowlCommunicator.Register();
+ }
+
+ /// <summary>
+ /// The queue processor_ queue completed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs.
+ /// </param>
+ private void QueueProcessorQueueCompleted(object sender, System.EventArgs e)
+ {
+ // Growl
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlQueue))
+ {
+ GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");
+ }
+ }
+
+ /// <summary>
+ /// The encode service_ encode completed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EncodeCompletedEventArgs.
+ /// </param>
+ private void EncodeServiceEncodeCompleted(object sender, HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs e)
+ {
+ // Growl
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlEncode))
+ {
+ GrowlCommunicator.Notify(
+ "Encode Completed", "Put down that cocktail...\nyour Handbrake encode is done.");
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index ed4796836..24666874c 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -57,6 +57,7 @@ namespace HandBrakeWPF.Startup this.windsorContainer.Register(Component.For<IDriveDetectService>().ImplementedBy<DriveDetectService>().LifeStyle.Is(LifestyleType.Singleton));
this.windsorContainer.Register(Component.For<IScanServiceWrapper>().ImplementedBy<ScanServiceWrapper>().LifeStyle.Is(LifestyleType.Singleton));
this.windsorContainer.Register(Component.For<IEncodeServiceWrapper>().ImplementedBy<EncodeServiceWrapper>().LifeStyle.Is(LifestyleType.Singleton));
+ this.windsorContainer.Register(Component.For<INotificationService>().ImplementedBy<NotificationService>().LifeStyle.Is(LifestyleType.Singleton));
// Shell
this.windsorContainer.Register(Component.For<IErrorService>().ImplementedBy<ErrorService>().LifeStyle.Is(LifestyleType.Singleton));
diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 440b65bf5..9371dc733 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -181,6 +181,16 @@ namespace HandBrakeWPF /// </summary>
public const string EnableLibHb = "EnableLibHb";
+ /// <summary>
+ /// Growl Encodes
+ /// </summary>
+ public const string GrowlEncode = "GrowlEncode";
+
+ /// <summary>
+ /// Growl Queues
+ /// </summary>
+ public const string GrowlQueue = "GrowlQueue";
+
#endregion
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 081272a4d..e7c737b09 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -189,8 +189,12 @@ namespace HandBrakeWPF.ViewModels /// <param name="driveDetectService">
/// The drive Detect Service.
/// </param>
+ /// <param name="notificationService">
+ /// The notification Service.
+ /// Leave in Constructor.
+ /// </param>
public MainViewModel(IUserSettingService userSettingService, IScanServiceWrapper scanService, IEncodeServiceWrapper encodeService, IPresetService presetService,
- IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService)
+ IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService, INotificationService notificationService)
{
GeneralUtilities.SetInstanceId();
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 343d6be7c..779e3e86a 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -781,7 +781,7 @@ namespace HandBrakeWPF.ViewModels set
{
this.preferredLanguages = value;
- this.NotifyOfPropertyChange("preferredLanguages");
+ this.NotifyOfPropertyChange("PreferredLanguages");
}
}
@@ -1499,8 +1499,8 @@ namespace HandBrakeWPF.ViewModels this.whenDoneOptions.Add("Quit HandBrake");
this.WhenDone = userSettingService.GetUserSetting<string>("WhenCompleteAction");
- this.GrowlAfterEncode = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.GrowlEncode);
- this.GrowlAfterQueue = userSettingService.GetUserSetting<bool>(ASUserSettingConstants.GrowlQueue);
+ this.GrowlAfterEncode = userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlEncode);
+ this.GrowlAfterQueue = userSettingService.GetUserSetting<bool>(UserSettingConstants.GrowlQueue);
this.SendFileAfterEncode = this.userSettingService.GetUserSetting<bool>(ASUserSettingConstants.SendFile);
this.SendFileTo = Path.GetFileNameWithoutExtension(this.userSettingService.GetUserSetting<string>(ASUserSettingConstants.SendFileTo)) ?? string.Empty;
this.SendFileToPath = this.userSettingService.GetUserSetting<string>(ASUserSettingConstants.SendFileTo) ?? string.Empty;
@@ -1828,8 +1828,8 @@ namespace HandBrakeWPF.ViewModels this.userSettingService.SetUserSetting(UserSettingConstants.DaysBetweenUpdateCheck, this.CheckForUpdatesFrequency);
this.userSettingService.SetUserSetting(UserSettingConstants.TooltipEnable, this.EnableGuiTooltips);
this.userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, this.WhenDone);
- this.userSettingService.SetUserSetting(ASUserSettingConstants.GrowlQueue, this.GrowlAfterQueue);
- this.userSettingService.SetUserSetting(ASUserSettingConstants.GrowlEncode, this.GrowlAfterEncode);
+ this.userSettingService.SetUserSetting(UserSettingConstants.GrowlQueue, this.GrowlAfterQueue);
+ this.userSettingService.SetUserSetting(UserSettingConstants.GrowlEncode, this.GrowlAfterEncode);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileTo, this.SendFileToPath);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFile, this.SendFileAfterEncode);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileToArgs, this.Arguments);
|