예제 #1
0
파일: Form1.cs 프로젝트: yeka/WPanel
        public void growlNotify(string title, string message, ToolTipIcon bicon)
        {
            string basedir = Application.StartupPath + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar;
            string icon    = "";

            if (bicon == ToolTipIcon.Info)
            {
                icon = basedir + "Accept.png";
            }
            else if (bicon == ToolTipIcon.Warning)
            {
                icon = basedir + "Warning.png";
            }
            else if (bicon == ToolTipIcon.Error)
            {
                icon = basedir + "Delete.png";
            }
            Growl.Connector.Notification notification = new Growl.Connector.Notification(
                growlapp.Name,                   //application name
                notificationType.Name,           // notification name
                DateTime.Now.Ticks.ToString(),   // id
                title,                           // title
                message,                         // message
                icon,                            // icon, image location
                false,                           // stricky
                Growl.Connector.Priority.Normal, // priority
                ""                               // coalescingID
                );
            growl.Notify(notification);
        }
예제 #2
0
        void Notify(object iTrack)
        {
            if (!Properties.Settings.Default.DisableNotifications)
            {
                IITTrack song = (IITTrack)iTrack;
                string title = Escape(song.Name);
                string text = String.Format("{0}\n{1}", Escape(song.Artist), Escape(song.Album));
                // this handles streaming radio stations
                if (this.CurrentStreamTitle != null)
                {
                    title = Escape(this.CurrentStreamTitle);
                    text = String.Format("Station: {0}", Escape(song.Name));
                }

                // TODO:
                string artworkFilePath = null;
                byte[] artworkData = null;
                if (song.Artwork != null && song.Artwork.Count > 0)
                {
                    string safeAlbumName = GetSafeFileName(song.Album);
                    string filename = String.Format("{0}.jpg", safeAlbumName);
                    artworkFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), filename);
                    if (!System.IO.File.Exists(artworkFilePath))
                        song.Artwork[1].SaveArtworkToFile(artworkFilePath);
                    artworkData = System.IO.File.ReadAllBytes(artworkFilePath);
                }

                // old
                if (Properties.Settings.Default.SendUDPNotifications)
                {
                    udpGrowl.Notify(udpNotificationType, title, text, Growl.Connector.Priority.Normal, false);
                }

                // new
                if (Properties.Settings.Default.SendGNTPNotifications)
                {
                    int sourceID;
                    int playlistID;
                    int trackID;
                    int databaseID;
                    song.GetITObjectIDs(out sourceID, out playlistID, out trackID, out databaseID);

                    Growl.Connector.CallbackContext callback = new Growl.Connector.CallbackContext("song", String.Format("{0}|{1}|{2}|{3}", sourceID, playlistID, trackID, databaseID));

                    //Growl.CoreLibrary.Resource albumIcon = artworkFilePath;
                    Growl.CoreLibrary.Resource albumIcon = (artworkData != null ? new Growl.CoreLibrary.BinaryData(artworkData) : null);
                    Growl.Connector.Notification notification = new Growl.Connector.Notification(application.Name, nt1.Name, id, title, text, albumIcon, false, Growl.Connector.Priority.Normal, id);

                    notification.CustomTextAttributes.Add("iTunes-Artist", song.Artist);
                    notification.CustomTextAttributes.Add("iTunes-Album", song.Album);
                    notification.CustomTextAttributes.Add("iTunes-Duration", song.Duration.ToString());
                    notification.CustomTextAttributes.Add("iTunes-PlayedCount", song.PlayedCount.ToString());
                    notification.CustomTextAttributes.Add("iTunes-Genre", song.Genre);
                    notification.CustomTextAttributes.Add("iTunes-Rating", song.Rating.ToString());

                    growl.Notify(notification, callback);
                }
            }
        }
예제 #3
0
        void ThisApplication_NewMailEx(string EntryIDCollection)

        {
            if (Properties.Settings.Default.EnableNewMailNotifications)

            {
                if (EntryIDCollection != null)

                {
                    string title = null;

                    string text = null;



                    string[] ids = EntryIDCollection.Split(',');

                    if (ids.Length > 4)

                    {
                        title = "New Mail";

                        text = String.Format("You have {0} new messages", ids.Length);



                        Growl.Connector.Notification notification = new Growl.Connector.Notification(this.application.Name, newmail.Name, String.Empty, title, text);

                        Growl.Connector.CallbackContext callbackContext = new Growl.Connector.CallbackContext("null", "multimessage");

                        growl.Notify(notification, callbackContext);
                    }

                    else

                    {
                        foreach (string id in ids)

                        {
                            object obj = this.Session.GetItemFromID(id.Trim(), Type.Missing);

                            if (obj is Outlook.MailItem)

                            {
                                Outlook.MailItem message = (Outlook.MailItem)obj;

                                string body = message.Body;

                                if (!String.IsNullOrEmpty(body))

                                {
                                    body = body.Replace("\r\n", "\n");

                                    body = (body.Length > 50 ? body.Substring(0, 50) + "..." : body);
                                }



                                // just saving this for future reference

                                //Outlook.MAPIFolder folder = message.Parent as Outlook.MAPIFolder;

                                //Outlook.NameSpace outlookNameSpace = this.GetNamespace("MAPI");

                                //Outlook.MAPIFolder junkFolder = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders..olFolderJunk);



                                title = message.Subject;

                                if (!String.IsNullOrEmpty(title))
                                {
                                    title = title.Trim();
                                }

                                title = (String.IsNullOrEmpty(title) ? "[No Subject]" : message.Subject);

                                text = String.Format("From: {0}\n{1}", message.SenderName, body);



                                Growl.Connector.Priority priority = Growl.Connector.Priority.Normal;

                                if (message.Importance == Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh)
                                {
                                    priority = Growl.Connector.Priority.High;
                                }

                                else if (message.Importance == Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow)
                                {
                                    priority = Growl.Connector.Priority.Moderate;
                                }



                                Growl.Connector.Notification notification = new Growl.Connector.Notification(this.application.Name, newmail.Name, String.Empty, title, text);

                                notification.Priority = priority;

                                Growl.Connector.CallbackContext callbackContext = new Growl.Connector.CallbackContext(id, "mailmessage");

                                growl.Notify(notification, callbackContext);
                            }

                            else if (obj is Outlook.MeetingItem)

                            {
                                Outlook.MeetingItem message = (Outlook.MeetingItem)obj;

                                string body = message.Body;

                                if (!String.IsNullOrEmpty(body))

                                {
                                    body = body.Replace("\r\n", "\n");

                                    body = (body.Length > 50 ? body.Substring(0, 50) + "..." : body);
                                }



                                title = message.Subject;

                                if (!String.IsNullOrEmpty(title))
                                {
                                    title = title.Trim();
                                }

                                title = (String.IsNullOrEmpty(title) ? "[No Subject]" : message.Subject);

                                text = String.Format("From: {0}\n{1}", message.SenderName, body);



                                Growl.Connector.Priority priority = Growl.Connector.Priority.Normal;

                                if (message.Importance == Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh)
                                {
                                    priority = Growl.Connector.Priority.High;
                                }

                                else if (message.Importance == Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow)
                                {
                                    priority = Growl.Connector.Priority.Moderate;
                                }



                                Growl.Connector.Notification notification = new Growl.Connector.Notification(this.application.Name, newmail.Name, String.Empty, title, text);

                                notification.Priority = priority;

                                Growl.Connector.CallbackContext callbackContext = new Growl.Connector.CallbackContext(id, "mailmessage");

                                growl.Notify(notification, callbackContext);
                            }
                        }
                    }
                }
            }
        }