OSDN Git Service

WinGui:
[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 System.Collections.Generic;\r
10     using System.Text;\r
11     using Growl.Connector;\r
12     using Growl.CoreLibrary;\r
13 \r
14     /// <summary>\r
15     /// Provides all functionality for communicating with Growl for Windows.\r
16     /// </summary>\r
17     /// <remarks>\r
18     /// This class is implemented as a static class because:\r
19     ///     1. It allows nearly all of the Growl-related code to be in one place\r
20     ///     2. It prevents the main form, queue handler, and any other part of Handbrake from having to declare\r
21     ///        or track any new instance variables\r
22     /// </remarks>\r
23     public static class GrowlCommunicator\r
24     {\r
25         /// <summary>\r
26         /// The <see cref="GrowlConnector"/> that actually talks to Growl\r
27         /// </summary>\r
28         private static GrowlConnector growl;\r
29 \r
30         /// <summary>\r
31         /// The Handbrake application instance that is registered with Growl\r
32         /// </summary>\r
33         private static Application application;\r
34 \r
35         /// <summary>\r
36         /// Notification shown upon completion of encoding\r
37         /// </summary>\r
38         private static NotificationType encodeOrQueueCompleted = new NotificationType("EncodeOrQueue", "HandBrake Status");\r
39 \r
40         /// <summary>\r
41         /// Checks to see if Growl is currently running on the local machine.\r
42         /// </summary>\r
43         /// <returns>\r
44         /// <c>true</c> if Growl is running;\r
45         /// <c>false</c> otherwise\r
46         /// </returns>\r
47         public static bool IsRunning()\r
48         {\r
49             Initialize();\r
50 \r
51             return growl.IsGrowlRunning();\r
52         }\r
53 \r
54         /// <summary>\r
55         /// Registers Handbrake with the local Growl instance\r
56         /// </summary>\r
57         /// <remarks>\r
58         /// This should usually be called at application start-up\r
59         /// </remarks>\r
60         public static void Register()\r
61         {\r
62             Initialize();\r
63             growl.Register(application, new NotificationType[] { encodeOrQueueCompleted });\r
64         }\r
65 \r
66         /// <summary>\r
67         /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with\r
68         /// static text, this is a shortcut method).\r
69         /// </summary>\r
70         /// <param name="title">\r
71         /// The title.\r
72         /// </param>\r
73         /// <param name="text">\r
74         /// The text to display.\r
75         /// </param>\r
76         public static void Notify(string title, string text)\r
77         {\r
78             Notification notification = new Notification(application.Name, encodeOrQueueCompleted.Name, String.Empty, title, text);\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                                             {\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 }\r