OSDN Git Service

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