Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }