OSDN Git Service

WinGui: Fix subtitle forced for foreign scan. Set it to "scan" instead of "Forced"
[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 EncodeOrQueueCompleted = new NotificationType("EncodeOrQueue", "HandBrake Status");\r
40 \r
41         /// <summary>\r
42         /// Checks to see if Growl is currently running on the local machine.\r
43         /// </summary>\r
44         /// <returns>\r
45         /// <c>true</c> if Growl is running;\r
46         /// <c>false</c> otherwise\r
47         /// </returns>\r
48         public static bool IsRunning()\r
49         {\r
50             Initialize();\r
51 \r
52             return growl.IsGrowlRunning();\r
53         }\r
54 \r
55         /// <summary>\r
56         /// Registers Handbrake with the local Growl instance\r
57         /// </summary>\r
58         /// <remarks>\r
59         /// This should usually be called at application start-up\r
60         /// </remarks>\r
61         public static void Register()\r
62         {\r
63             Initialize();\r
64             growl.Register(application, new NotificationType[] { EncodeOrQueueCompleted });\r
65         }\r
66 \r
67         /// <summary>\r
68         /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with\r
69         /// static text, this is a shortcut method).\r
70         /// </summary>\r
71         public static void Notify(string title, string text)\r
72         {\r
73             Notification notification = new Notification(application.Name, EncodeOrQueueCompleted.Name, String.Empty, title, text);\r
74             growl.Notify(notification);\r
75         }\r
76 \r
77         /// <summary>\r
78         /// Sends a notification to Growl. (This is the more generic version that could be used in the future if \r
79         /// more notification types are implemented)\r
80         /// </summary>\r
81         /// <param name="notificationType">The <see cref="NotificationType">type</see> of notification to send</param>\r
82         /// <param name="title">The notification title</param>\r
83         /// <param name="text">The notification text</param>\r
84         /// <param name="imageUrl">The notification image as a url</param>\r
85         public static void Notify(NotificationType notificationType, string title, string text, string imageUrl)\r
86         {\r
87             Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title, text);\r
88             notification.Icon = imageUrl;\r
89 \r
90             growl.Notify(notification);\r
91         }\r
92 \r
93         /// <summary>\r
94         /// Initializes the GrowlCommunicator\r
95         /// </summary>\r
96         private static void Initialize()\r
97         {\r
98             if (growl == null)\r
99             {\r
100                 growl = new GrowlConnector();\r
101                 growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;\r
102 \r
103                 application = new Application("Handbrake");\r
104                 application.Icon = global::Handbrake.Properties.Resources.logo64;\r
105             }\r
106         }\r
107     }\r
108 }\r