/* GrowlCommunicator.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ using System; using System.Collections.Generic; using System.Text; using Growl.Connector; using Growl.CoreLibrary; namespace Handbrake.Functions { /// /// Provides all functionality for communicating with Growl for Windows. /// /// /// 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 /// public static class GrowlCommunicator { /// /// The that actually talks to Growl /// private static GrowlConnector growl; /// /// The Handbrake application instance that is registered with Growl /// private static Application application; /// /// Notification shown upon completion of encoding /// public static NotificationType EncodeOrQueueCompleted = new NotificationType("EncodeOrQueue", "HandBrake Status"); /// /// Checks to see if Growl is currently running on the local machine. /// /// /// true if Growl is running; /// false otherwise /// public static bool IsRunning() { Initialize(); return growl.IsGrowlRunning(); } /// /// Registers Handbrake with the local Growl instance /// /// /// This should usually be called at application start-up /// public static void Register() { Initialize(); growl.Register(application, new NotificationType[] { EncodeOrQueueCompleted }); } /// /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with /// static text, this is a shortcut method). /// public static void Notify(string title, string text) { Notification notification = new Notification(application.Name, EncodeOrQueueCompleted.Name, String.Empty, title, text); growl.Notify(notification); } /// /// Sends a notification to Growl. (This is the more generic version that could be used in the future if /// more notification types are implemented) /// /// The type of notification to send /// The notification title /// The notification text /// The notification image as a url public static void Notify(NotificationType notificationType, string title, string text, string imageUrl) { Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title, text); notification.Icon = imageUrl; growl.Notify(notification); } /// /// Initializes the GrowlCommunicator /// private static void Initialize() { if (growl == null) { growl = new GrowlConnector(); growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; application = new Application("Handbrake"); application.Icon = global::Handbrake.Properties.Resources.logo64; } } } }