コード例 #1
0
        private void UpdateActions()
        {
            if (!ActionsSupported || current_nf == null || current_track == null)
            {
                return;
            }

            if (!current_track.IsLive && interface_action_service.PlaybackActions["NextAction"].Sensitive)
            {
                current_nf.ClearActions();

                if (ActionIconsSupported)
                {
                    current_nf.AddHint("action-icons", true);

                    // We need to use an icon name as the action id, so that the notification uses that icon
                    current_nf.AddAction("media-skip-backward",
                                         Catalog.GetString("Previous"), OnPreviousTrack);

                    bool is_playing = ServiceManager.PlayerEngine.IsPlaying() && ServiceManager.PlayerEngine.CurrentState != PlayerState.Paused;
                    current_nf.AddAction(is_playing ? "media-playback-pause" : "media-playback-start",
                                         interface_action_service.PlaybackActions["PlayPauseAction"].Label, OnPlayPause);
                }

                current_nf.AddAction("media-skip-forward",
                                     Catalog.GetString("Skip this item"), OnNextTrack);
            }
        }
コード例 #2
0
ファイル: RequestWork.cs プロジェクト: dmulder/Task-Tracker
        static internal void SuggestTask()
        {
            SetPidginStatus("Available", "");
            Notification notify;
            Tasks        tasks = new Tasks();

            tasks.Load();
            Task task = tasks.GetPriority();

            if (task != null)
            {
                notify = new Notification("Tasks", "This is the next priority task:\n" + task.Summary);
                notify.AddAction("select", "Select", HandleSelectTask);
                notify.AddAction("postpone", "Delay", HandlePostponeTask);
                notify.AddAction("AddTask", "Add Task", HandleAddTask);
                notify.Timeout = 0;
                notify.Urgency = Urgency.Critical;
                notify.Show();
            }
            else
            {
                notify = new Notification("Tasks", "What are you working on?");
                notify.AddAction("AddTask", "Add Task", HandleAddTask);
                notify.Timeout = 0;
                notify.Urgency = Urgency.Critical;
                notify.Show();
            }
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: dmulder/Task-Tracker
        static void MenuViewTaskActivated(object sender, EventArgs e)
        {
            Tasks tasks = new Tasks();

            tasks.Load();
            Task         current = tasks.CurrentTask();
            Notification notify  = new Notification(current.Summary, current.Description.Substring(0, (current.Description.Length > 1000 ? 1000 : current.Description.Length)));

            notify.AddAction("edit", "Edit", HandleEditTaskActivated);
            notify.AddAction("finish", "Mark Finished", MenuFinishTaskActivated);
            notify.AddAction("list", "Tasks", HandleViewTaskListActivated);
            notify.Urgency = Urgency.Critical;
            notify.Show();
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: dmulder/Task-Tracker
        static void HandleDailyReportActivated(object sender, EventArgs e)
        {
            Reports dailyreport = new Reports();

            dailyreportmessage = dailyreport.CompileDailyReport();
            Notification notify = new Notification();

            notify.Summary = "Daily Report";
            notify.Body    = dailyreportmessage;
            notify.AddAction("send", "Send", HandleSendDaily);
            notify.AddAction("select", "Select Date", HandleSelectedReportActivated);
            notify.Urgency = Urgency.Critical;
            notify.Show();
        }
コード例 #5
0
        public override void AskYesNoQuestion(string title, string message, Gdk.Pixbuf icon,
                                              string ok_string, string cancel_string,
                                              EventHandler ok_handler, EventHandler cancel_handler)
        {
            Notification notify = new Notification(title, message, icon);

            notify.Timeout = 60000;

            notify.AddAction(cancel_string, cancel_string, delegate {
                if (cancel_handler != null)
                {
                    cancel_handler(null, null);
                }
                currentNotification = null;
            });

            notify.AddAction(ok_string, ok_string, delegate {
                if (ok_handler != null)
                {
                    ok_handler(null, null);
                }
                currentNotification = null;
            });

            notify.Closed += delegate {
                if (cancel_handler != null)
                {
                    cancel_handler(null, null);
                }
                currentNotification = null;
            };

            if (currentNotification != null)
            {
                Logger.Debug("RECEIVE: HandleSendRequest: Found a notification... closing it");
                currentNotification.Close();
                currentNotification = null;
            }

            currentNotification = notify;
            currentNotification.Show();
        }
コード例 #6
0
ファイル: Select_Date.cs プロジェクト: dmulder/Task-Tracker
        static void Daily()
        {
            Reports dailyreport = new Reports();

            dailyreportmessage = dailyreport.CompileDailyReport(selected);
            Notification notify = new Notification();

            notify.Summary = "Daily Report " + selected.ToShortDateString();
            notify.Body    = dailyreportmessage;
            notify.AddAction("send", "Send", HandleSendReport);
            notify.Urgency = Urgency.Critical;
            notify.Show();
        }
コード例 #7
0
ファイル: RequestWork.cs プロジェクト: dmulder/Task-Tracker
        static internal void DisplayMessage()
        {
            Tasks tasks = new Tasks();

            tasks.Load();
            Task         current = tasks.CurrentTask();
            Notification notify;

            if (current != null)
            {
                notify = new Notification("Tasks", "Are you still working on this task?\n" + current.Summary);
                notify.AddAction("yes", "Yes", HandleDoNothing);
                notify.AddAction("view", "View", HandleEditTask);
                notify.AddAction("finish", "Finish", HandleFinishedTask);
                notify.Timeout = 0;
                notify.Urgency = Urgency.Critical;
                notify.Show();
            }
            else
            {
                SuggestTask();
            }
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: xlizzard/synapse
 public override void DesktopNotify(ActivityFeedItemTemplate template, IActivityFeedItem item, string text)
 {
     // FIXME: This will need to be different on windows/osx...
     QApplication.Invoke(delegate {
         Notification notif = new Notification(text, item.Content);
         foreach (var action in template.Actions)
         {
             notif.AddAction(action.Name, action.Label, delegate {
                 item.TriggerAction(action.Name);
             });
         }
         notif.Show();
     });
 }
コード例 #9
0
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            foreach (var window in elements_service.ContentWindows)
            {
                if (window.HasToplevelFocus)
                {
                    return;
                }
            }

            bool is_notification_daemon = false;

            try {
                var name = Notifications.Global.ServerInformation.Name;
                is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon";
            } catch {
                // This will be reached if no notification daemon is running
                return;
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            string image = null;

            image = is_notification_daemon
                ? CoverArtSpec.GetPathForSize(current_track.ArtworkId, icon_size)
                : CoverArtSpec.GetPath(current_track.ArtworkId);

            if (!File.Exists(new SafeUri(image)))
            {
                if (artwork_manager_service != null)
                {
                    // artwork does not exist, try looking up the pixbuf to trigger scaling or conversion
                    Gdk.Pixbuf tmp_pixbuf = is_notification_daemon
                        ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, icon_size)
                        : artwork_manager_service.LookupPixbuf(current_track.ArtworkId);

                    if (tmp_pixbuf == null)
                    {
                        image = "audio-x-generic";
                    }
                    else
                    {
                        tmp_pixbuf.Dispose();
                    }
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, image, notif_area.Widget);
                }
                else
                {
                    current_nf.Summary  = current_track.DisplayTrackTitle;
                    current_nf.Body     = message;
                    current_nf.IconName = image;
                    current_nf.AttachToWidget(notif_area.Widget);
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;
                if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive)
                {
                    current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped);
                }
                current_nf.Show();
            } catch (Exception e) {
                Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false);
            }
        }
コード例 #10
0
        void ShowNotification(ChatView chatView, MessageModel msg)
        {
            Notification notification;

            if (!Capabilites.Contains("append") &&
                Notifications.TryGetValue(chatView, out notification))
            {
                // no support for append, update the existing notification
                notification.Body = GLib.Markup.EscapeText(
                    msg.ToString()
                    );
                return;
            }

            notification = new Notification()
            {
                Summary  = chatView.Name,
                Category = "im.received"
            };
            notification.AddHint("desktop-entry", "smuxi-frontend-gnome");
            if (Capabilites.Contains("body"))
            {
                // notify-osd doesn't like unknown tags when appending
                notification.Body = GLib.Markup.EscapeText(
                    msg.ToString()
                    );
            }
            if (Capabilites.Contains("icon-static"))
            {
                Gdk.Pixbuf iconData = null;
                string     iconName = null;
                if (chatView is PersonChatView)
                {
                    iconData = PersonChatIconPixbuf;
                    iconName = "smuxi-person-chat";
                }
                else if (chatView is GroupChatView)
                {
                    iconData = GroupChatIconPixbuf;
                    iconName = "smuxi-group-chat";
                }
                var theme = Gtk.IconTheme.Default;
#if DISABLED
                // OPT: use icon path/name if we can, so the image (26K) is not
                // send over D-Bus. Especially with the gnome-shell this is a
                // serious performance issue, see:
                // https://bugzilla.gnome.org/show_bug.cgi?id=683829
                if (iconName != null && theme.HasIcon(iconName))
                {
                    // HACK: use icon path instead of name as gnome-shell does
                    // not support icon names correctly, see:
                    // https://bugzilla.gnome.org/show_bug.cgi?id=665957
                    var iconInfo = theme.LookupIcon(iconName, 256, Gtk.IconLookupFlags.UseBuiltin);
                    if (!String.IsNullOrEmpty(iconInfo.Filename) &&
                        File.Exists(iconInfo.Filename) &&
                        ServerVendor == "GNOME" &&
                        (ServerName == "Notification Daemon" ||
                         ServerName == "gnome-shell"))
                    {
                        // HACK: notification-daemon 0.7.5 seems to ignore
                        // the image_path hint for some reason, thus we have to
                        // rely on app_icon instead, see:
                        // https://bugzilla.gnome.org/show_bug.cgi?id=684653
                        // HACK: gnome-shell 3.4.2 shows no notification at all
                        // with image_path and stops responding to further
                        // notifications which freezes Smuxi completely!
                        notification.IconName = "file://" + iconInfo.Filename;
                    }
                    else if (!String.IsNullOrEmpty(iconInfo.Filename) &&
                             File.Exists(iconInfo.Filename) &&
                             SpecificationVersion >= new Version("1.1"))
                    {
                        // starting with DNS >= 1.1 we can use the image-path
                        // hint instead of icon_data or app_icon
                        var hintName = "image_path";
                        if (SpecificationVersion >= new Version("1.2"))
                        {
                            hintName = "image-path";
                        }
                        notification.AddHint(hintName,
                                             "file://" + iconInfo.Filename);
                    }
                    else
                    {
                        // fallback to icon_data as defined in DNS 0.9
                        notification.Icon = iconData;
                    }
#endif
                if (Frontend.HasSystemIconTheme &&
                    iconName != null && theme.HasIcon(iconName))
                {
                    notification.IconName = iconName;
                }
                else if (iconName != null && theme.HasIcon(iconName))
                {
                    // icon wasn't in the system icon theme
                    var iconInfo = theme.LookupIcon(iconName, 256, Gtk.IconLookupFlags.UseBuiltin);
                    if (!String.IsNullOrEmpty(iconInfo.Filename) &&
                        File.Exists(iconInfo.Filename))
                    {
                        notification.IconName = "file://" + iconInfo.Filename;
                    }
                }
                else if (iconData != null)
                {
                    // fallback to icon_data as the icon is not available in
                    // the theme
                    notification.Icon = iconData;
                }
                else
                {
                    // fallback for non-group/person messages
                    notification.IconName = "notification-message-im";
                }
            }
            else
            {
                // fallback to generic icon
                notification.IconName = "notification-message-im";
            }
            if (Capabilites.Contains("actions"))
            {
                notification.AddAction("show", _("Show"), delegate {
                    try {
                        MainWindow.PresentWithServerTime();
                        ChatViewManager.CurrentChatView = chatView;
                        notification.Close();
                    } catch (Exception ex) {
#if LOG4NET
                        Logger.Error("OnChatViewMessageHighlighted() " +
                                     "notification.Show threw exception", ex);
#endif
                    }
                });
            }
            if (Capabilites.Contains("append"))
            {
                notification.AddHint("append", String.Empty);
            }
            if (Capabilites.Contains("sound"))
            {
                // DNS 0.9 only supports sound-file which is a file path
                // http://www.galago-project.org/specs/notification/0.9/x344.html
                // DNS 1.1 supports sound-name which is an id, see:
                // http://people.canonical.com/~agateau/notifications-1.1/spec/ar01s08.html
                // http://0pointer.de/public/sound-naming-spec.html
                // LAMESPEC: We can't tell which of those are actually
                // supported by this version as hint are totally optional :/
                // HACK: always pass both hints when possible
                notification.AddHint("sound-name", "message-new-instant");
                if (SoundFile != null)
                {
                    notification.AddHint("sound-file", SoundFile);
                }
            }
            notification.Closed += delegate {
                try {
#if LOG4NET
                    Logger.Debug("OnChatViewMessageHighlighted(): received " +
                                 "notification.Closed signal for: " +
                                 chatView.Name);
#endif
                    Notifications.Remove(chatView);
                } catch (Exception ex) {
#if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted(): " +
                                 "Exception in notification.Closed handler",
                                 ex);
#endif
                }
            };
            notification.Show();

            if (!Notifications.ContainsKey(chatView))
            {
                Notifications.Add(chatView, notification);
            }
        }

        void OnMainWindowFocusInEvent(object sender, Gtk.FocusInEventArgs e)
        {
            Trace.Call(sender, e);

            if (MainWindow.Notebook.IsBrowseModeEnabled)
            {
                return;
            }

            var currentChatView = ChatViewManager.CurrentChatView;

            if (currentChatView == null)
            {
                return;
            }
            DisposeNotification(currentChatView);
        }

        void OnMainWindowNotebookSwitchPage(object sender, Gtk.SwitchPageArgs e)
        {
            Trace.Call(sender, e);

            if (MainWindow.Notebook.IsBrowseModeEnabled)
            {
                return;
            }

            var currentChatView = ChatViewManager.CurrentChatView;

            if (currentChatView == null)
            {
                return;
            }
            DisposeNotification(currentChatView);
        }

        void DisposeNotification(ChatView chatView)
        {
            Notification notification;

            if (!Notifications.TryGetValue(chatView, out notification))
            {
                return;
            }
#if LOG4NET
            Logger.Debug("DisposeNotification(): disposing notification for: " +
                         chatView.Name);
#endif

            try {
                // don't try to close already closed notifications (timeout)
                if (notification.Id == 0)
                {
#if LOG4NET
                    Logger.Debug("DisposeNotification(): notification already " +
                                 "closed for: " + chatView.Name);
#endif
                    return;
                }

                notification.Close();
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("DisposeNotification(): " +
                             "notification.Close() thew exception", ex);
#endif
            } finally {
                Notifications.Remove(chatView);
            }
        }
コード例 #11
0
        void ShowNotification(ChatView chatView, MessageModel msg)
        {
            Notification notification;

            if (!Capabilites.Contains("append") &&
                Notifications.TryGetValue(chatView, out notification))
            {
                // no support for append, update the existing notification
                notification.Body = GLib.Markup.EscapeText(
                    msg.ToString()
                    );
                return;
            }

            notification = new Notification()
            {
                Summary  = chatView.Name,
                Category = "im.received"
            };
            if (Capabilites.Contains("body"))
            {
                // notify-osd doesn't like unknown tags when appending
                notification.Body = GLib.Markup.EscapeText(
                    msg.ToString()
                    );
            }
            //notification.IconName = "notification-message-im";
            if (Capabilites.Contains("icon-static"))
            {
                if (chatView is PersonChatView)
                {
                    notification.Icon = PersonChatIconPixbuf;
                }
                if (chatView is GroupChatView)
                {
                    notification.Icon = GroupChatIconPixbuf;
                }
            }
            if (Capabilites.Contains("actions"))
            {
                notification.AddAction("show", _("Show"), delegate {
                    try {
                        MainWindow.Present();
                        MainWindow.Notebook.CurrentChatView = chatView;
                        notification.Close();
                    } catch (Exception ex) {
#if LOG4NET
                        Logger.Error("OnChatViewMessageHighlighted() " +
                                     "notification.Show threw exception", ex);
#endif
                    }
                });
            }
            if (Capabilites.Contains("append"))
            {
                notification.AddHint("append", String.Empty);
            }
            if (Capabilites.Contains("sound"))
            {
                // DNS 0.9 only supports sound-file which is a file path
                // http://www.galago-project.org/specs/notification/0.9/x344.html
                // DNS 1.1 supports sound-name which is an id, see:
                // http://people.canonical.com/~agateau/notifications-1.1/spec/ar01s08.html
                // http://0pointer.de/public/sound-naming-spec.html
                // LAMESPEC: We can't tell which of those are actually
                // supported by this version as hint are totally optional :/
                // HACK: always pass both hints when possible
                notification.AddHint("sound-name", "message-new-instant");
                if (SoundFile != null)
                {
                    notification.AddHint("sound-file", SoundFile);
                }
            }
            notification.Closed += delegate {
                try {
#if LOG4NET
                    Logger.Debug("OnChatViewMessageHighlighted(): received " +
                                 "notification.Closed signal for: " +
                                 chatView.Name);
#endif
                    Notifications.Remove(chatView);
                } catch (Exception ex) {
#if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted(): " +
                                 "Exception in notification.Closed handler",
                                 ex);
#endif
                }
            };
            notification.Show();

            if (!Notifications.ContainsKey(chatView))
            {
                Notifications.Add(chatView, notification);
            }
        }
コード例 #12
0
        private void ShowTrackNotification()
        {
            // This has to happen before the next if, otherwise the last_* members aren't set correctly.
            if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle &&
                                          notify_last_artist == current_track.DisplayArtistName))
            {
                return;
            }

            notify_last_title  = current_track.DisplayTrackTitle;
            notify_last_artist = current_track.DisplayArtistName;

            if (!show_notifications)
            {
                return;
            }

            foreach (var window in elements_service.ContentWindows)
            {
                if (window.HasToplevelFocus)
                {
                    return;
                }
            }

            bool is_notification_daemon = false;

            try {
                var name = Notifications.Global.ServerInformation.Name;
                is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon";
            } catch {
                // This will be reached if no notification daemon is running
                return;
            }

            string message = GetByFrom(
                current_track.ArtistName, current_track.DisplayArtistName,
                current_track.AlbumTitle, current_track.DisplayAlbumTitle);

            if (artwork_manager_service == null)
            {
                artwork_manager_service = ServiceManager.Get <ArtworkManager> ();
            }

            Gdk.Pixbuf image = null;

            if (artwork_manager_service != null)
            {
                image = is_notification_daemon
                    ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, 42)
                    : artwork_manager_service.LookupPixbuf(current_track.ArtworkId);
            }

            if (image == null)
            {
                image = IconThemeUtils.LoadIcon(48, "audio-x-generic");
                if (image != null)
                {
                    image.ScaleSimple(42, 42, Gdk.InterpType.Bilinear);
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, image, notif_area.Widget);
                }
                else
                {
                    current_nf.Summary = current_track.DisplayTrackTitle;
                    current_nf.Body    = message;
                    current_nf.Icon    = image;
                    current_nf.AttachToWidget(notif_area.Widget);
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;
                if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive)
                {
                    current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped);
                }
                current_nf.Show();
            } catch (Exception e) {
                Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false);
            }
        }