OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / GrowlCommunicator.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using Growl.Connector;\r
5 using Growl.CoreLibrary;\r
6 \r
7 namespace Handbrake.Functions\r
8 {\r
9     /// <summary>\r
10     /// Provides all functionality for communicating with Growl for Windows.\r
11     /// </summary>\r
12     /// <remarks>\r
13     /// This class is implemented as a static class because:\r
14     ///     1. It allows nearly all of the Growl-related code to be in one place\r
15     ///     2. It prevents the main form, queue handler, and any other part of Handbrake from having to declare\r
16     ///        or track any new instance variables\r
17     /// </remarks>\r
18     public static class GrowlCommunicator\r
19     {\r
20         /// <summary>\r
21         /// The <see cref="GrowlConnector"/> that actually talks to Growl\r
22         /// </summary>\r
23         private static GrowlConnector growl;\r
24 \r
25         /// <summary>\r
26         /// The Handbrake application instance that is registered with Growl\r
27         /// </summary>\r
28         private static Application application;\r
29 \r
30         /// <summary>\r
31         /// Notification shown upon completion of encoding\r
32         /// </summary>\r
33         public static NotificationType EncodingComplete;\r
34 \r
35 \r
36         /// <summary>\r
37         /// Checks to see if Growl is currently running on the local machine.\r
38         /// </summary>\r
39         /// <returns>\r
40         /// <c>true</c> if Growl is running;\r
41         /// <c>false</c> otherwise\r
42         /// </returns>\r
43         public static bool IsRunning()\r
44         {\r
45             Initialize();\r
46 \r
47             return growl.IsGrowlRunning();\r
48         }\r
49 \r
50         /// <summary>\r
51         /// Registers Handbrake with the local Growl instance\r
52         /// </summary>\r
53         /// <remarks>\r
54         /// This should usually be called at application start-up\r
55         /// </remarks>\r
56         public static void Register()\r
57         {\r
58             Initialize();\r
59 \r
60             growl.Register(application, new NotificationType[] { EncodingComplete });\r
61         }\r
62 \r
63         /// <summary>\r
64         /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with\r
65         /// static text, this is a shortcut method).\r
66         /// </summary>\r
67         public static void Notify()\r
68         {\r
69             string title = "Encoding Complete";\r
70             string text = "Put down that cocktail...\nyour Handbrake encode is done.";\r
71             Notification notification = new Notification(application.Name, EncodingComplete.Name, String.Empty, title, text);\r
72 \r
73             growl.Notify(notification);\r
74         }\r
75 \r
76         /// <summary>\r
77         /// Sends a notification to Growl. (This is the more generic version that could be used in the future if \r
78         /// more notification types are implemented)\r
79         /// </summary>\r
80         /// <param name="notificationType">The <see cref="NotificationType">type</see> of notification to send</param>\r
81         /// <param name="title">The notification title</param>\r
82         /// <param name="text">The notification text</param>\r
83         /// <param name="imageUrl">The notification image as a url</param>\r
84         public static void Notify(NotificationType notificationType, string title, string text, string imageUrl)\r
85         {\r
86             Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title, text);\r
87             notification.Icon = imageUrl;\r
88 \r
89             growl.Notify(notification);\r
90         }\r
91 \r
92         /// <summary>\r
93         /// Initializes the GrowlCommunicator\r
94         /// </summary>\r
95         private static void Initialize()\r
96         {\r
97             if (growl == null)\r
98             {\r
99                 growl = new GrowlConnector();\r
100                 growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;\r
101 \r
102                 application = new Application("Handbrake");\r
103                 application.Icon = global::Handbrake.Properties.Resources.logo64;\r
104 \r
105                 EncodingComplete = new NotificationType("Encoding Complete");\r
106             }\r
107         }\r
108     }\r
109 }\r