Exemple #1
0
        public static PastNotification Save(Growl.DisplayStyle.Notification notification, string requestID, DateTime timestamp)
        {
            Growl.DisplayStyle.NotificationLite notificationLite = Growl.DisplayStyle.NotificationLite.Clone(notification);
            string path = Growl.CoreLibrary.PathUtility.Combine(historyFolder, Growl.CoreLibrary.PathUtility.GetSafeFolderName(notificationLite.ApplicationName));

            Growl.CoreLibrary.PathUtility.EnsureDirectoryExists(path);

            // save image data
            string imageFile = null;

            if (notification.Image != null && notification.Image.IsSet)
            {
                System.Drawing.Image image = (System.Drawing.Image)notification.Image;
                using (image)
                {
                    System.Drawing.Image thumbnail = GenerateThumbnail(image, 48, 48);
                    if (thumbnail != null)
                    {
                        using (thumbnail)
                        {
                            string imagefilename = String.Format(@"{0}.img", requestID);
                            imageFile = Growl.CoreLibrary.PathUtility.Combine(path, imagefilename);

                            thumbnail.Save(imageFile);
                        }
                    }
                }
            }

            PastNotification pn = new PastNotification(notificationLite, timestamp, imageFile);

            // save text data
            string filename = String.Format(@"{0}.notification", requestID);
            string filepath = Growl.CoreLibrary.PathUtility.Combine(path, filename);

            System.IO.StreamWriter w = System.IO.File.CreateText(filepath);
            using (w)
            {
                string data = Serialization.SerializeObject(pn);
                w.Write(data);
                data = null;
            }

            return(pn);
        }
 public override void ProcessNotification(Growl.DisplayStyle.Notification notification, Growl.Daemon.CallbackInfo cbInfo, Growl.Connector.RequestInfo requestInfo)
 {
     this.realDisplay.ProcessNotification(notification, cbInfo, requestInfo);
 }
Exemple #3
0
        public NotificationReceivedEventArgs(Growl.DisplayStyle.Notification n)

        {
            this.n = n;
        }
Exemple #4
0
 public NotificationReceivedEventArgs(Growl.DisplayStyle.Notification n)
 {
     this.n = n;
 }
        internal void SendSystemNotification(string title, string text, Display display)
        {
            Growl.Connector.RequestInfo requestInfo = new Growl.Connector.RequestInfo();  // this is not used, but needed as a placeholder

            DisplayStyle.Notification n = new Growl.DisplayStyle.Notification();
            n.UUID = requestInfo.RequestID;
            n.ApplicationName = Properties.Resources.SystemNotification_ApplicationName;
            n.Description = text;
            n.Name = "Growl System Message";
            n.Priority = (int)Growl.Connector.Priority.Normal;
            n.Sticky = false;   // system notifications are never sticky
            n.Title = title;
            n.Image = Growl.FormResources.growl;

            ShowNotification(n, display, null, false, requestInfo);
        }
        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;
        }