OSDN Git Service

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