OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / GrowlCommunicator.cs
1 /*  GrowlCommunicator.cs $\r
2         \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
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.Text;\r
10 using Growl.Connector;\r
11 using Growl.CoreLibrary;\r
12 \r
13 namespace Handbrake.Functions\r
14 {\r
15     /// <summary>\r
16     /// Provides all functionality for communicating with Growl for Windows.\r
17     /// </summary>\r
18     /// <remarks>\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
23     /// </remarks>\r
24     public static class GrowlCommunicator\r
25     {\r
26         /// <summary>\r
27         /// The <see cref="GrowlConnector"/> that actually talks to Growl\r
28         /// </summary>\r
29         private static GrowlConnector growl;\r
30 \r
31         /// <summary>\r
32         /// The Handbrake application instance that is registered with Growl\r
33         /// </summary>\r
34         private static Application application;\r
35 \r
36         /// <summary>\r
37         /// Notification shown upon completion of encoding\r
38         /// </summary>\r
39         public static NotificationType EncodingComplete;\r
40 \r
41 \r
42         /// <summary>\r
43         /// Checks to see if Growl is currently running on the local machine.\r
44         /// </summary>\r
45         /// <returns>\r
46         /// <c>true</c> if Growl is running;\r
47         /// <c>false</c> otherwise\r
48         /// </returns>\r
49         public static bool IsRunning()\r
50         {\r
51             Initialize();\r
52 \r
53             return growl.IsGrowlRunning();\r
54         }\r
55 \r
56         /// <summary>\r
57         /// Registers Handbrake with the local Growl instance\r
58         /// </summary>\r
59         /// <remarks>\r
60         /// This should usually be called at application start-up\r
61         /// </remarks>\r
62         public static void Register()\r
63         {\r
64             Initialize();\r
65 \r
66             growl.Register(application, new NotificationType[] { EncodingComplete });\r
67         }\r
68 \r
69         /// <summary>\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
72         /// </summary>\r
73         public static void Notify()\r
74         {\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
78 \r
79             growl.Notify(notification);\r
80         }\r
81 \r
82         /// <summary>\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
85         /// </summary>\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
91         {\r
92             Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title, text);\r
93             notification.Icon = imageUrl;\r
94 \r
95             growl.Notify(notification);\r
96         }\r
97 \r
98         /// <summary>\r
99         /// Initializes the GrowlCommunicator\r
100         /// </summary>\r
101         private static void Initialize()\r
102         {\r
103             if (growl == null)\r
104             {\r
105                 growl = new GrowlConnector();\r
106                 growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;\r
107 \r
108                 application = new Application("Handbrake");\r
109                 application.Icon = global::Handbrake.Properties.Resources.logo64;\r
110 \r
111                 EncodingComplete = new NotificationType("Encoding Complete");\r
112             }\r
113         }\r
114     }\r
115 }\r