示例#1
0
    public static void pushNotification(String icon,
                                        int val)
    {
        Notification n = new Notification("Brightness",          // for a11y-reasons supply something meaning full
                                          "",                    // this needs to be empty!
                                          icon);

        n.AddHint("value", val);
        n.AddHint("x-canonical-private-synchronous", "");
        n.Show();
        Mono.Unix.Native.Syscall.sleep(1);
    }
示例#2
0
        public Notifier()
        {
            _enabled = true;
            _exited  = new ManualResetEvent(false);
            _queue   = new Queue <NotificationMessage> ();
            _sync    = ((ICollection)_queue).SyncRoot;

            ThreadPool.QueueUserWorkItem(
                state => {
                while (_enabled || Count > 0)
                {
                    var msg = dequeue();
                    if (msg != null)
                    {
#if UBUNTU
                        var nf = new Notification(msg.Summary, msg.Body, msg.Icon);
                        nf.AddHint("append", "allowed");
                        nf.Show();
#else
                        Console.WriteLine(msg);
#endif
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }

                _exited.Set();
            }
                );
        }
    public static void pushNotification(String title,
                                        String body,
                                        String icon)
    {
        Notification n = new Notification(title, body, icon);

        n.AddHint("x-canonical-append", "");
        n.Show();
        Mono.Unix.Native.Syscall.sleep(3);          // simulate typing
    }
示例#4
0
    public static void Main()
    {
        // call this so we can savely use the m_capabilities array later
        ExampleUtil.InitCaps();

        // show what's supported
        ExampleUtil.PrintCaps();

        // try the icon-sonly case
        if (ExampleUtil.HasCap(ExampleUtil.Capability.CAP_LAYOUT_ICON_ONLY) &&
            ExampleUtil.HasCap(ExampleUtil.Capability.CAP_SYNCHRONOUS))
        {
            Notification n = new Notification("Eject",              // for a11y-reasons supply something meaning full
                                              "",                   // this needs to be empty!
                                              "notification-device-eject");
            n.AddHint("x-canonical-private-icon-only", "");
            n.AddHint("x-canonical-private-synchronous", "");
            n.Show();
        }
        else
        {
            Console.WriteLine("The daemon does not support sync. icon-only!");
        }
    }
示例#5
0
        public static void Main(string[] args)
        {
            var ts = new ThreadState();

            WaitCallback notifyMsg = state =>
            {
                while (ts.Enabled || _msgQ.Count > 0)
                {
                    Thread.Sleep(500);

                    if (_msgQ.Count > 0)
                    {
                        var msg = (NfMessage)_msgQ.Dequeue();
            #if NOTIFY
                        var nf = new Notification(msg.Summary, msg.Body, msg.Icon);
                        nf.AddHint("append", "allowed");
                        nf.Show();
            #else
                        Console.WriteLine("{0}: {1}", msg.Summary, msg.Body);
            #endif
                    }
                }

                ts.Notification.Set();
            };

            ThreadPool.QueueUserWorkItem(notifyMsg);

            using (var ws = new WebSocket("ws://echo.websocket.org"))
            //using (var ws = new WebSocket("wss://echo.websocket.org"))
            //using (var ws = new WebSocket("ws://localhost:4649"))
            //using (var ws = new WebSocket("ws://localhost:4649/Echo"))
            //using (var ws = new WebSocket("wss://localhost:4649/Echo"))
            //using (var ws = new WebSocket("ws://localhost:4649/Echo?name=nobita"))
            //using (var ws = new WebSocket("ws://localhost:4649/エコー?name=のび太"))
            //using (var ws = new WebSocket("ws://localhost:4649/Chat"))
            //using (var ws = new WebSocket("ws://localhost:4649/Chat?name=nobita"))
            //using (var ws = new WebSocket("ws://localhost:4649/チャット?name=のび太"))
            {
                ws.OnOpen += (sender, e) =>
                {
                    ws.Send("Hi, all!");
                };

                ws.OnMessage += (sender, e) =>
                {
                    if (!String.IsNullOrEmpty(e.Data))
                    {
                        enNfMessage("[WebSocket] Message", e.Data, "notification-message-im");
                    }
                };

                ws.OnError += (sender, e) =>
                {
                    enNfMessage("[WebSocket] Error", e.Message, "notification-message-im");
                };

                ws.OnClose += (sender, e) =>
                {
                    enNfMessage(
                        String.Format("[WebSocket] Close({0})", e.Code),
                        e.Reason,
                        "notification-message-im");
                };

        #if DEBUG
                ws.Log.Level = LogLevel.Trace;
        #endif
                //ws.Compression = CompressionMethod.Deflate;
                //ws.Origin = "http://echo.websocket.org";
                //ws.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
                //{
                //  ws.Log.Debug(String.Format("\n{0}\n{1}", certificate.Issuer, certificate.Subject));
                //  return true;
                //};
                //ws.SetCookie(new Cookie("nobita", "\"idiot, gunfighter\""));
                //ws.SetCookie(new Cookie("dora", "tanuki"));
                //ws.SetCredentials ("nobita", "password", false);
                ws.Connect();
                //ws.ConnectAsync();
                //Console.WriteLine("Compression: {0}", ws.Compression);

                Thread.Sleep(500);
                Console.WriteLine("\nType \"exit\" to exit.\n");

                string data;
                while (true)
                {
                    Thread.Sleep(500);

                    Console.Write("> ");
                    data = Console.ReadLine();
                    if (data == "exit")
                    //if (data == "exit" || !ws.IsAlive)
                    {
                        break;
                    }

                    ws.Send(data);
                }
            }

            ts.Enabled = false;
            ts.Notification.WaitOne();
        }
        private void configure()
        {
            _ws.OnOpen += (sender, e) =>
            {
                var msg = createTextMessage("connection", String.Empty);
                _ws.Send(msg);
            };

            _ws.OnMessage += (sender, e) =>
            {
                switch (e.Type)
                {
                case Opcode.TEXT:
                    var msg = parseTextMessage(e.Data);
                    _msgQ.Enqueue(msg);
                    break;

                case Opcode.BINARY:
                    var audioMsg = parseAudioMessage(e.RawData);
                    if (audioMsg.user_id == _user_id)
                    {
                        goto default;
                    }
                    if (_audioBox.ContainsKey(audioMsg.user_id))
                    {
                        _audioBox[audioMsg.user_id].Enqueue(audioMsg.buffer_array);
                    }
                    else
                    {
                        var q = Queue.Synchronized(new Queue());
                        q.Enqueue(audioMsg.buffer_array);
                        _audioBox.Add(audioMsg.user_id, q);
                    }
                    break;

                default:
                    break;
                }
            };

            _ws.OnError += (sender, e) =>
            {
                enNfMessage("[AudioStreamer] error", "WS: Error: " + e.Message, "notification-message-im");
            };

            _ws.OnClose += (sender, e) =>
            {
                enNfMessage
                (
                    "[AudioStreamer] disconnect",
                    String.Format("WS: Close({0}: {1})", e.Code, e.Reason),
                    "notification-message-im"
                );
            };

            //_ws.Compression = CompressionMethod.DEFLATE;

            _notifyMsgState = new ThreadState();
            _notifyMsg      = (state) =>
            {
                while (_notifyMsgState.Enabled || _msgQ.Count > 0)
                {
                    Thread.Sleep(500);

                    if (_msgQ.Count > 0)
                    {
                        NfMessage msg = (NfMessage)_msgQ.Dequeue();
            #if NOTIFY
                        Notification nf = new Notification(msg.Summary,
                                                           msg.Body,
                                                           msg.Icon);
                        nf.AddHint("append", "allowed");
                        nf.Show();
            #else
                        Console.WriteLine("{0}: {1}", msg.Summary, msg.Body);
            #endif
                    }
                }

                _notifyMsgState.Notification.Set();
            };

            _sendHeartbeat = (state) =>
            {
                var msg = createTextMessage("heartbeat", String.Empty);
                _ws.Send(msg);
            };
        }
示例#7
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);
            }
        }
示例#8
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;
            }

            // If we have persistent notifications, we show a notification even if the main window has focus
            // so that the information displayed (track title, etc.) gets updated.
            if (!PersistenceSupported)
            {
                foreach (var window in elements_service.ContentWindows)
                {
                    if (window.HasToplevelFocus)
                    {
                        return;
                    }
                }
            }

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

            string image = null;

            image = 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 = artwork_manager_service.LookupPixbuf(current_track.ArtworkId);

                    if (tmp_pixbuf == null)
                    {
                        // TODO: image should be set to "audio-x-generic", but icon names are not supported by the
                        // notification daemon in GNOME Shell. See https://bugzilla.gnome.org/show_bug.cgi?id=665957
                        image = null;
                    }
                    else
                    {
                        tmp_pixbuf.Dispose();
                    }
                }
            }

            try {
                if (current_nf == null)
                {
                    current_nf = new Notification(current_track.DisplayTrackTitle,
                                                  message, Banshee.ServiceStack.Application.IconName);
                }
                else
                {
                    current_nf.Summary  = current_track.DisplayTrackTitle;
                    current_nf.Body     = message;
                    current_nf.IconName = Banshee.ServiceStack.Application.IconName;
                    if (notif_area != null && notif_area.Widget != null)
                    {
                        current_nf.AttachToWidget(notif_area.Widget);
                    }
                }
                current_nf.Urgency = Urgency.Low;
                current_nf.Timeout = 4500;

                if (image == null)
                {
                    current_nf.RemoveHint("image-path");
                }
                else
                {
                    current_nf.AddHint("image-path", image);
                }

                if (ServiceManager.PlayerEngine.IsPlaying())
                {
                    current_nf.Category = "x-gnome.music";
                }

                if (PersistenceSupported)
                {
                    current_nf.AddHint("resident", true);
                }

                current_nf.Show();
            } catch (Exception e) {
                Log.Error(Catalog.GetString("Cannot show notification"), e);
            }
        }
示例#9
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);
            }
        }
示例#10
0
        public static void Main(string[] args)
        {
            ThreadState ts = new ThreadState();

            WaitCallback notifyMsg = state =>
            {
                while (ts.Enabled || _msgQ.Count > 0)
                {
                    Thread.Sleep(500);

                    if (_msgQ.Count > 0)
                    {
                        NfMessage msg = (NfMessage)_msgQ.Dequeue();
            #if NOTIFY
                        Notification nf = new Notification(msg.Summary,
                                                           msg.Body,
                                                           msg.Icon);
                        nf.AddHint("append", "allowed");
                        nf.Show();
            #else
                        Console.WriteLine("{0}: {1}", msg.Summary, msg.Body);
            #endif
                    }
                }

                ts.Notification.Set();
            };

            ThreadPool.QueueUserWorkItem(notifyMsg);

            using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo"))
            //using (WebSocket ws = new WebSocket("wss://echo.websocket.org", "echo"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/Echo"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/Echo?name=nobita"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/エコー?name=のび太"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/Chat"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/Chat?name=nobita"))
            //using (WebSocket ws = new WebSocket("ws://localhost:4649/チャット?name=のび太"))
            {
                ws.OnOpen += (sender, e) =>
                {
                    ws.Send("Hi, all!");
                };

                ws.OnMessage += (sender, e) =>
                {
                    if (!String.IsNullOrEmpty(e.Data))
                    {
                        enNfMessage("[WebSocket] Message", e.Data, "notification-message-im");
                    }
                };

                ws.OnError += (sender, e) =>
                {
                    enNfMessage("[WebSocket] Error", e.Message, "notification-message-im");
                };

                ws.OnClose += (sender, e) =>
                {
                    enNfMessage(
                        String.Format("[WebSocket] Close({0})", e.Code),
                        e.Reason,
                        "notification-message-im");
                };

                //ws.SetCookie(new Cookie("nobita", "\"idiot, gunfighter\""));
                //ws.SetCookie(new Cookie("dora", "tanuki"));
                ws.Connect();

                Thread.Sleep(500);
                Console.WriteLine("\nType \"exit\" to exit.\n");

                string data;
                while (true)
                {
                    Thread.Sleep(500);

                    Console.Write("> ");
                    data = Console.ReadLine();
                    if (data == "exit")
                    //if (data == "exit" || !ws.IsAlive)
                    {
                        break;
                    }

                    ws.Send(data);
                }
            }

            ts.Enabled = false;
            ts.Notification.WaitOne();
        }