void growl_NotificationCallback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData, object state) { if (callbackData != null) { if (callbackData.Result == Growl.CoreLibrary.CallbackResult.CLICK) { if (response.CustomTextAttributes.ContainsKey("Rating")) { string r = response.CustomTextAttributes["Rating"]; int rating = Convert.ToInt32(r); string[] parts = callbackData.Data.Split('|'); int sourceID = Convert.ToInt32(parts[0]); int playlistID = Convert.ToInt32(parts[1]); int trackID = Convert.ToInt32(parts[2]); int databaseID = Convert.ToInt32(parts[3]); IITTrack song = (IITTrack)this.GetITObjectByID(sourceID, playlistID, trackID, databaseID); if (song != null) { song.Rating = rating; } } } } }
/// <summary> /// Growlが通知を終えた際に呼び出されるコールバックを処理するイベントハンドラ /// </summary> /// <param name="response"></param> /// <param name="callbackData"></param> /// <param name="state"></param> private void ConnectorNotificationCallback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData, object state) { Debug.WriteLine("{0}:{1}", DateTime.Now.ToLongTimeString(), callbackData.Data); Trace.WriteLine(String.Format("{0}:{1}", DateTime.Now.ToLongTimeString(), callbackData.Data)); if (callbackData.Result == Growl.CoreLibrary.CallbackResult.CLICK) { if (callbackData.Data != "") { OpenChatWindow(callbackData.Data); } } }
Growl.Connector.Response gntpListener_RegisterReceived(Growl.Connector.Application application, List<Growl.Connector.NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo) { Growl.Connector.Response response = null; // get the icon Growl.CoreLibrary.Resource applicationIcon = null; if (application.Icon != null && application.Icon.IsSet) { try { applicationIcon = application.Icon; } catch { applicationIcon = null; } } // deal with notification list Dictionary<string, RegisteredNotification> rns = new Dictionary<string, RegisteredNotification>(notificationTypes.Count); foreach (Growl.Connector.NotificationType nt in notificationTypes) { Growl.CoreLibrary.Resource icon = null; try { if (nt.Icon != null && nt.Icon.IsSet) { icon = nt.Icon; } } catch { icon = null; } RegisteredNotification rn = new RegisteredNotification(nt.DisplayName, nt.Enabled, nt.CustomTextAttributes, nt.CustomBinaryAttributes); rn.SetIcon(icon, application.Name); rns.Add(nt.Name, rn); } // update/create the RegisteredApplication bool exisiting = false; RegisteredApplication ra = null; if (IsApplicationRegistered(application.Name)) { exisiting = true; ra = GetRegisteredApplication(application.Name); ra.SetIcon(applicationIcon); // the application is already registered, so we want to use the new notification list, but preserve any exisiting preferences foreach (RegisteredNotification raRn in ra.Notifications.Values) { foreach (RegisteredNotification rn in rns.Values) { if (raRn.Name == rn.Name) { // use the exisiting preferences rn.Preferences = raRn.Preferences; } } } ra.Notifications = rns; } else { ra = new RegisteredApplication(application.Name, rns, application.CustomTextAttributes, application.CustomBinaryAttributes); ra.SetIcon(applicationIcon); if (Properties.Settings.Default.ManuallyEnableNewApplications) ra.Preferences.PrefEnabled = false; this.applications.Add(ra.Name, ra); // fire ApplicationRegistered event this.OnApplicationRegistered(ra); } if (ra.Enabled && !exisiting) { DisplayStyle.Notification n = new Growl.DisplayStyle.Notification(); n.UUID = requestInfo.RequestID; n.NotificationID = requestInfo.RequestID; n.ApplicationName = ra.Name; n.Description = String.Format(Properties.Resources.SystemNotification_AppRegistered_Text, ra.Name); n.Name = ra.Name; n.Priority = (int)Growl.Connector.Priority.Normal; n.Sticky = false; // registration notifications are never sticky n.Title = Properties.Resources.SystemNotification_AppRegistered_Title; n.Image = ra.GetIcon(); if (requestInfo.WasForwarded()) n.OriginMachineName = application.MachineName; // handle custom attributes n.AddCustomTextAttributes(application.CustomTextAttributes); n.AddCustomBinaryAttributes(application.CustomBinaryAttributes); ShowNotification(n, this.growlDefaultDisplay, null, false, requestInfo); response = new Growl.Connector.Response(); } else { // application is disabled or already registered response = new Growl.Connector.Response(); } // handle any forwarding after we have handled it locally // (NOTE: as of 03.09.2010 (v2.0.2), notifications are NOT forwarded if // they are not enabled (unlike before). if (ra.Enabled) { List<string> limitToTheseComputers = null; if (ra.ShouldForward(Properties.Settings.Default.AllowForwarding, out limitToTheseComputers)) { // update icon urls to binary data for forwarding if (application.Icon != null && application.Icon.IsSet && application.Icon.IsUrl) { System.Drawing.Image icon = (Image)application.Icon; if (icon != null) application.Icon = icon; } foreach (Growl.Connector.NotificationType nt in notificationTypes) { if (nt.Icon != null && nt.Icon.IsSet && nt.Icon.IsUrl) { System.Drawing.Image icon = (Image)nt.Icon; if (icon != null) nt.Icon = icon; } } HandleForwarding(application, notificationTypes, requestInfo, limitToTheseComputers); } } return response; }
Growl.Connector.Response gntpListener_NotifyReceived(Growl.Connector.Notification notification, Growl.Daemon.CallbackInfo callbackInfo, Growl.Connector.RequestInfo requestInfo) { Growl.Connector.Response response = null; if (IsApplicationRegistered(notification.ApplicationName)) { RegisteredApplication ra = GetRegisteredApplication(notification.ApplicationName); if (ra.Notifications.ContainsKey(notification.Name)) { RegisteredNotification rn = ra.Notifications[notification.Name]; bool sticky = rn.ShouldStayOnScreen(false, this.activityMonitor.IsIdle, notification.Sticky); Growl.Connector.Priority priority = rn.Priority(notification.Priority); if (ra.Enabled && rn.Enabled) { DisplayStyle.Notification n = new Growl.DisplayStyle.Notification(); n.UUID = requestInfo.RequestID; n.NotificationID = requestInfo.RequestID; n.CoalescingID = notification.CoalescingID; n.ApplicationName = notification.ApplicationName; n.Description = notification.Text; n.Name = notification.Name; n.Priority = (int)priority; n.Sticky = sticky; n.Title = notification.Title; n.Duration = rn.Duration; if (requestInfo.WasForwarded()) n.OriginMachineName = notification.MachineName; if (notification.Icon != null && notification.Icon.IsSet) { n.Image = notification.Icon; } else { n.Image = rn.GetIcon(); } // handle custom attributes n.AddCustomTextAttributes(ra.CustomTextAttributes); n.AddCustomBinaryAttributes(ra.CustomBinaryAttributes); n.AddCustomTextAttributes(rn.CustomTextAttributes); n.AddCustomBinaryAttributes(rn.CustomBinaryAttributes); n.AddCustomTextAttributes(notification.CustomTextAttributes); n.AddCustomBinaryAttributes(notification.CustomBinaryAttributes); // play sound string soundFile; bool shouldPlaySound = rn.ShouldPlaySound(this.growlDefaultSound, out soundFile); if (shouldPlaySound) PlaySound(soundFile); ShowNotification(n, rn.Display, callbackInfo, true, requestInfo); this.OnNotificationReceived(n); PastNotification pn = SaveToHistory(n, requestInfo.RequestID); AddToMissedNotificationList(pn); this.OnNotificationPast(pn); // handle any forwarding after we have already handled it locally // (NOTE: as of 03.09.2010 (v2.0.2), notifications are NOT forwarded if // they are not enabled (unlike before). List<string> limitToTheseComputers = null; if (rn.ShouldForward(Properties.Settings.Default.AllowForwarding, out limitToTheseComputers)) { // update the icon (in case we used the app's icon or a registered icon, etc) notification.Icon = n.Image; notification.Priority = priority; // convert urls to binary data if (notification.Icon != null && notification.Icon.IsSet && notification.Icon.IsUrl) { System.Drawing.Image icon = (Image)notification.Icon; notification.Icon = icon; } HandleForwarding(notification, callbackInfo, requestInfo, limitToTheseComputers); } } else { // application or notification type is not enabled - but that is ok } // return OK response response = new Growl.Connector.Response(); } else { // notification type is not registered response = new Growl.Connector.Response(Growl.Connector.ErrorCode.UNKNOWN_NOTIFICATION, Growl.Connector.ErrorDescription.NOTIFICATION_TYPE_NOT_REGISTERED); } } else { response = new Growl.Connector.Response(Growl.Connector.ErrorCode.UNKNOWN_APPLICATION, Growl.Connector.ErrorDescription.APPLICATION_NOT_REGISTERED); } return response; }
void display_NotificationCallback(Growl.Daemon.CallbackInfo cbInfo, Growl.CoreLibrary.CallbackResult result) { if (this.gntpListener != null && cbInfo != null && cbInfo.Context != null) { cbInfo.RequestInfo.SaveHandlingInfo(String.Format("Was responded to on {0} - Action: {1}", Environment.MachineName, result)); Growl.Connector.Response response = new Growl.Connector.Response(); response.SetCallbackData(cbInfo.NotificationID, cbInfo.Context, result); if (cbInfo.ShouldKeepConnectionOpen()) { this.gntpListener.WriteResponse(cbInfo, response); } else { string url = cbInfo.Context.CallbackUrl; if (!String.IsNullOrEmpty(url)) { // this will only fire on CLICK since that is the more expected behavior // NOTE: there is probably a huge security risk by doing this (for now, I am relying on UriBuilder to protect us from from other types of commands) if (result == Growl.CoreLibrary.CallbackResult.CLICK) { try { System.UriBuilder ub = new UriBuilder(url); // do this in another thread so the Process.Start doesnt block ThreadPool.QueueUserWorkItem(new WaitCallback(OpenUrl), ub.Uri.AbsoluteUri); } catch { // TODO: this is temporary (and thus not localized either) // LOCALIZE: SendSystemNotification("Callback failure", String.Format("An application requested a callback via url, but the url was invalid. The url was: {0}", url)); } } } } } }
/// <summary> /// Growlにエラーがあった場合に発生するイベントを処理するイベントハンドラ /// </summary> /// <param name="response"></param> /// <param name="state"></param> private void connector_ErrorResponse(Growl.Connector.Response response, object state) { System.Windows.Forms.MessageBox.Show(response.ErrorDescription, response.ErrorCode.ToString(CultureInfo.InvariantCulture)); }
void growl_NotificationCallback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData) { if (callbackData != null && callbackData.Result == Growl.CoreLibrary.CallbackResult.CLICK) { string type = callbackData.Type; if (type != null && type != String.Empty) { string id = callbackData.Data; object obj = this.Session.GetItemFromID(id, Type.Missing); switch (type) { case "mailmessage": if (obj != null && obj is Outlook.MailItem) { Outlook.MailItem message = (Outlook.MailItem)obj; EnableFullActivation(); message.Display(false); DisableFullActivation(); } obj = null; break; case "multimessage": object aw = this.ActiveWindow(); if (aw is Microsoft.Office.Interop.Outlook.Explorer) { Microsoft.Office.Interop.Outlook.Explorer explorer = (Microsoft.Office.Interop.Outlook.Explorer)aw; EnableFullActivation(); explorer.Activate(); DisableFullActivation(); } else if (aw is Microsoft.Office.Interop.Outlook.Inspector) { Microsoft.Office.Interop.Outlook.Inspector inspector = (Microsoft.Office.Interop.Outlook.Inspector)aw; EnableFullActivation(); inspector.Activate(); DisableFullActivation(); } break; case "remindermail": if (obj != null && obj is Outlook.MailItem) { Outlook.MailItem item = (Outlook.MailItem)obj; EnableFullActivation(); item.Display(false); DisableFullActivation(); } obj = null; break; case "reminderappointment": if (obj != null && obj is Outlook.AppointmentItem) { Outlook.AppointmentItem item = (Outlook.AppointmentItem)obj; EnableFullActivation(); item.Display(false); DisableFullActivation(); } obj = null; break; case "remindertask": if (obj != null && obj is Outlook.TaskItem) { Outlook.TaskItem item = (Outlook.TaskItem)obj; EnableFullActivation(); item.Display(false); DisableFullActivation(); } obj = null; break; } } } }