1 /* GrowlCommunicator.cs $
\r
3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
10 using Growl.Connector;
\r
11 using Growl.CoreLibrary;
\r
13 namespace Handbrake.Functions
\r
16 /// Provides all functionality for communicating with Growl for Windows.
\r
19 /// This class is implemented as a static class because:
\r
20 /// 1. It allows nearly all of the Growl-related code to be in one place
\r
21 /// 2. It prevents the main form, queue handler, and any other part of Handbrake from having to declare
\r
22 /// or track any new instance variables
\r
24 public static class GrowlCommunicator
\r
27 /// The <see cref="GrowlConnector"/> that actually talks to Growl
\r
29 private static GrowlConnector growl;
\r
32 /// The Handbrake application instance that is registered with Growl
\r
34 private static Application application;
\r
37 /// Notification shown upon completion of encoding
\r
39 public static NotificationType EncodingComplete;
\r
43 /// Checks to see if Growl is currently running on the local machine.
\r
46 /// <c>true</c> if Growl is running;
\r
47 /// <c>false</c> otherwise
\r
49 public static bool IsRunning()
\r
53 return growl.IsGrowlRunning();
\r
57 /// Registers Handbrake with the local Growl instance
\r
60 /// This should usually be called at application start-up
\r
62 public static void Register()
\r
66 growl.Register(application, new NotificationType[] { EncodingComplete });
\r
70 /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with
\r
71 /// static text, this is a shortcut method).
\r
73 public static void Notify()
\r
75 string title = "Encoding Complete";
\r
76 string text = "Put down that cocktail...\nyour Handbrake encode is done.";
\r
77 Notification notification = new Notification(application.Name, EncodingComplete.Name, String.Empty, title, text);
\r
79 growl.Notify(notification);
\r
83 /// Sends a notification to Growl. (This is the more generic version that could be used in the future if
\r
84 /// more notification types are implemented)
\r
86 /// <param name="notificationType">The <see cref="NotificationType">type</see> of notification to send</param>
\r
87 /// <param name="title">The notification title</param>
\r
88 /// <param name="text">The notification text</param>
\r
89 /// <param name="imageUrl">The notification image as a url</param>
\r
90 public static void Notify(NotificationType notificationType, string title, string text, string imageUrl)
\r
92 Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title, text);
\r
93 notification.Icon = imageUrl;
\r
95 growl.Notify(notification);
\r
99 /// Initializes the GrowlCommunicator
\r
101 private static void Initialize()
\r
105 growl = new GrowlConnector();
\r
106 growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;
\r
108 application = new Application("Handbrake");
\r
109 application.Icon = global::Handbrake.Properties.Resources.logo64;
\r
111 EncodingComplete = new NotificationType("Encoding Complete");
\r