Inheritance: Gtk.EventBox, IChatView, IDisposable, ITraceable
Example #1
0
        public int GetPageNumber(ChatView chatView)
        {
            for (int i = 0; i < NPages; i++) {
                ChatView page = (ChatView) GetNthPage(i);
                if (page == chatView) {
                    return i;
                }
            }

            return -1;
        }
Example #2
0
        int GetSortedChatPosition(ChatView chatView)
        {
            // starting with > 0.8 the Engine supplies ChatModel.Position for us
            if (Frontend.EngineVersion > new Version("0.8")) {
                return chatView.Position;
            }

            // COMPAT: Engine <= 0.8 doesn't populate ChatModel.Position thus
            // _we_ have to find a good position
            var chat = chatView.ChatModel;
            // REMOTING CALL 1
            int idx = chat.Position;
            // REMOTING CALL 2
            ChatType type = chat.ChatType;
            // new group person and group chats behind their protocol chat
            if (idx == -1 &&
                (type == ChatType.Person ||
                 type == ChatType.Group)) {
                // REMOTING CALL 3
                IProtocolManager pm = chat.ProtocolManager;
                for (int i = 0; i < f_Notebook.NPages; i++) {
                    ChatView page = (ChatView) f_Notebook.GetNthPage(i);
                    ChatModel pageChat = page.ChatModel;
                    // REMOTING CALL 4 and 5
                    if (pageChat.ChatType == ChatType.Protocol &&
                        pageChat.ProtocolManager == pm) {
                        idx = i + 1;
                        break;
                    }
                }

                if (idx != -1) {
                    // now find the first chat with a different protocol manager
                    bool found = false;
                    for (int i = idx; i < f_Notebook.NPages; i++) {
                        ChatView page = (ChatView) f_Notebook.GetNthPage(i);
                        ChatModel pageChat = page.ChatModel;
                        // REMOTING CALL 6
                        if (pageChat.ProtocolManager != pm) {
                            found = true;
                            idx = i;
                            break;
                        }
                    }
                    if (!found) {
                        // if there was no next protocol manager, simply append
                        // the chat way to the end
                        idx = -1;
                    }
                }
            }

            return idx;
        }
Example #3
0
 public ChatViewManagerChatRemovedEventArgs(ChatView chatView)
 {
     f_ChatView = chatView;
 }
Example #4
0
        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);
            }
        }
Example #5
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.PresentWithServerTime();
                        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);
            }
        }
Example #6
0
        void DisposeIndicator(ChatView chatView)
        {
            Trace.Call(chatView);

            Indicator indicator;
            if (!Indicators.TryGetValue(chatView, out indicator)) {
                return;
            }

            indicator.Hide();
            Indicators.Remove(chatView);
        }
Example #7
0
 public ProtocolChatView FindProtocolChatViewParent(ChatView child)
 {
     foreach (var candidate in Chats) {
         if (!(candidate is ProtocolChatView) ||
             candidate.ProtocolManager == null) {
             continue;
         }
         if (child.ProtocolManager != candidate.ProtocolManager) {
             continue;
         }
         return (ProtocolChatView) candidate;
     }
     return null;
 }
Example #8
0
        public virtual void Remove(ChatView chatView)
        {
            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            var iter = FindChatIter(chatView);
            if (!TreeStore.IterIsValid(iter)) {
                return;
            }
            TreeStore.Remove(ref iter);
        }
Example #9
0
        public virtual void Render(ChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            var iter = FindChatIter(chatView);
            var path = TreeStore.GetPath(iter);
            TreeStore.EmitRowChanged(path, iter);
        }
Example #10
0
        public virtual void Append(ChatView chatView)
        {
            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            if (chatView is SessionChatView ||
                chatView is ProtocolChatView) {
                // top level chats
                TreeStore.AppendValues(chatView);
                ReparentOrphans();
                if (TreeStore.IterNChildren() == 1) {
                    // first node, usualy Smuxi chat
                    CurrentChatView = chatView;
                }
            } else {
                // childs with parents, hopefully
                var parentIter = FindProtocolChatIter(chatView);
                if (TreeStore.IterIsValid(parentIter)) {
                    TreeStore.AppendValues(parentIter, chatView);
                    var path = TreeStore.GetPath(parentIter);
                    ExpandRow(path, true);
                } else {
                    // parent chat doesn't exist yet, thus it has to become
                    // a top level chat for now and re-parent later
                    TreeStore.AppendValues(chatView);
                }
            }
        }
Example #11
0
        public virtual bool IsVisible(ChatView chatView)
        {
            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            Gtk.TreePath visibleStart, visibleEnd;
            GetVisibleRange(out visibleStart, out visibleEnd);
            var chatIter = FindChatIter(chatView);
            var chatPath = TreeStore.GetPath(chatIter);
            // we ignore 0 on purpose, say if a few pixels of a row are returned
            // as visible by GetVisibleRange() that is not good enough for us
            return visibleStart.Compare(chatPath) <= 0 &&
                   visibleEnd.Compare(chatPath) >= 0;
        }
Example #12
0
        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 {
                notification.Close();
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("DisposeNotification(): " +
                             "notification.Close() thew exception", ex);
            #endif
            } finally {
                Notifications.Remove(chatView);
            }
        }
Example #13
0
        public virtual void Render(ChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            var iter = FindChatIter(chatView);
            //var path = TreeStore.GetPath(iter);
            //TreeStore.EmitRowChanged(path, iter);
            // HACK: this emits row_changed _and_ sort_iter_changed and there is
            // no other public API in GTK+ to trigger a resort of a modified
            // value in the tree view :/
            TreeStore.SetValue(iter, 0, chatView);
        }
Example #14
0
        void OnChatViewMessageHighlighted(object sender,
                                          MessageTextViewMessageHighlightedEventArgs e,
                                          ChatView chatView)
        {
            Trace.Call(sender, e, chatView);

            if (!IsEnabled ||
                e.Message.TimeStamp <= chatView.SyncedLastSeenHighlight ||
                MainWindow.HasToplevelFocus) {
                return;
            }

            try {
                ShowNotification(chatView, e.Message);
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("OnChatViewMessageHighlighted(): " +
                             "ShowNotification() threw exception", ex);
            #endif
            }
        }
Example #15
0
        void ShowSource(ChatView chatView, MessageModel msg)
        {
            Trace.Call(chatView, msg);

            string sourceId;
            var    time = (Int64)((msg.TimeStamp - UnixEpoch).TotalMilliseconds * 1000L);

            if (Sources.TryGetValue(chatView, out sourceId))
            {
                // update time of existing source
                App.SetSourceTime(sourceId, time);
                return;
            }

            // TODO: TEST ME!
            sourceId = chatView.ID;
            string iconName = null;
            string label    = null;

            if (chatView is PersonChatView)
            {
                iconName = "smuxi-person-chat";
                label    = chatView.Name;
            }
            else if (chatView is GroupChatView)
            {
                iconName = "smuxi-group-chat";
                var nick = GetNick(msg);
                if (nick == null)
                {
                    label = chatView.Name;
                }
                else
                {
                    label = String.Format("{0} ({1})", chatView.Name, nick);
                }
            }

            var theme = Gtk.IconTheme.Default;

            GLib.Icon icon = null;
            if (Frontend.HasSystemIconTheme &&
                iconName != null && theme.HasIcon(iconName))
            {
                icon = new GLib.ThemedIcon(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))
                {
                    icon = new GLib.FileIcon(
                        GLib.FileFactory.NewForPath(iconInfo.Filename)
                        );
                }
            }
            App.AppendSource(sourceId, icon, label);
            App.SetSourceTime(sourceId, time);
            App.DrawAttention(sourceId);
            Sources.Add(chatView, sourceId);
        }
Example #16
0
 Gtk.TreeIter FindChatIter(ChatView view)
 {
     Gtk.TreeIter chatIter = Gtk.TreeIter.Zero;
     TreeStore.Foreach((model, path, iter) => {
         var candidate = (ChatView) model.GetValue(iter, 0);
         if (candidate == view) {
             chatIter = iter;
             return true;
         }
         return false;
     });
     return chatIter;
 }
Example #17
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);
            }
        }
Example #18
0
 Gtk.TreeIter FindProtocolChatIter(ChatView child)
 {
     Gtk.TreeIter iter;
     Gtk.TreeIter parentIter = Gtk.TreeIter.Zero;
     TreeStore.GetIterFirst(out iter);
     do {
         var candidate = (ChatView) TreeStore.GetValue(iter, 0);
         if (!(candidate is ProtocolChatView) ||
             candidate.ProtocolManager == null) {
             continue;
         }
         if (child.ProtocolManager != candidate.ProtocolManager) {
             continue;
         }
         parentIter = iter;
         break;
     } while (TreeStore.IterNext(ref iter));
     return parentIter;
 }
Example #19
0
        void OnChatViewMessageHighlighted(object sender,
                                          MessageTextViewMessageHighlightedEventArgs e,
                                          ChatView chatView)
        {
            Trace.Call(sender, e, chatView);

            if (MainWindow.HasToplevelFocus || !IsEnabled) {
                return;
            }

            Indicator indicator;
            if (Indicators.TryGetValue(chatView, out indicator)) {
                // update time of existing indicator
                indicator.SetProperty(
                    "time",
                    e.Message.TimeStamp.ToLocalTime().ToString("s")
                );
                return;
            }

            indicator = new Indicator();
            indicator.SetProperty("subtype", "im");
            if (chatView is PersonChatView) {
                indicator.SetProperty("icon", PersonChatIconBase64);
                indicator.SetProperty("sender", chatView.Name);
            }
            if (chatView is GroupChatView) {
                indicator.SetProperty("icon", GroupChatIconBase64);
                var nick = GetNick(e.Message);
                if (nick == null) {
                    indicator.SetProperty("sender", chatView.Name);
                } else {
                    indicator.SetProperty("sender",
                        String.Format(
                            "{0} ({1})",
                            chatView.Name, nick
                        )
                    );
                }
            }
            indicator.SetProperty(
                "time",
                e.Message.TimeStamp.ToLocalTime().ToString("s")
            );
            indicator.SetPropertyBool("draw-attention", true);
            indicator.UserDisplay += delegate {
                try {
                    MainWindow.PresentWithTime(
                        (uint) (DateTime.UtcNow - UnixEpoch).TotalSeconds
                    );
                    MainWindow.Notebook.CurrentChatView = chatView;
                    DisposeIndicator(chatView);
                } catch (Exception ex) {
            #if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted() " +
                                 "indicator.UserDisplay threw exception", ex);
            #endif
                }
            };
            try {
                indicator.Show();
            } catch (Exception ex) {
            #if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted() " +
                                 "indicator.Show() thew exception", ex);
            #endif
            }

            Indicators.Add(chatView, indicator);
        }
Example #20
0
        void OnChatViewMessageHighlighted(object sender,
                                          MessageTextViewMessageHighlightedEventArgs e,
                                          ChatView chatView)
        {
            if (!IsEnabled ||
                e.Message.TimeStamp <= chatView.SyncedLastSeenHighlight ||
                MainWindow.HasToplevelFocus) {
                return;
            }

            #if INDICATE_SHARP
            ShowIndicator(chatView, e.Message);
            #elif MESSAGING_MENU_SHARP
            ShowSource(chatView, e.Message);
            #endif
        }
Example #21
0
        public void UpdateTitle(ChatView chatView, string protocolStatus)
        {
            Trace.Call(chatView, protocolStatus);

            if (chatView == null) {
                chatView = Notebook.CurrentChatView;
            }
            if (chatView == null) {
                return;
            }

            string title;
            if (chatView is SessionChatView) {
                title = String.Empty;
            } else if (chatView is ProtocolChatView) {
                title = protocolStatus;
            } else {
                title = String.Format("{0} @ {1}",
                                      chatView.Name,
                                      protocolStatus);
            }
            if (!String.IsNullOrEmpty(title)) {
                title += " - ";
            }
            title += "Smuxi";

            Title = title;
        }
Example #22
0
        void DisposeIndicator(ChatView chatView)
        {
            Indicator indicator;
            if (!Indicators.TryGetValue(chatView, out indicator)) {
                return;
            }
            #if LOG4NET
            Logger.Debug("DisposeIndicator(): disposing indicator for: " +
                         chatView.Name);
            #endif

            try {
                indicator.Hide();
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("DisposeIndicator(): " +
                             "indicator.Hide() thew exception", ex);
            #endif
            } finally {
                Indicators.Remove(chatView);
            }
        }
Example #23
0
        void OnChatViewMessageHighlighted(object sender,
                                          MessageTextViewMessageHighlightedEventArgs e,
                                          ChatView chatView)
        {
            #if MSG_DEBUG
            Trace.Call(sender, e, chatView);
            #endif

            if (!IsEnabled ||
                e.Message.TimeStamp <= chatView.SyncedLastSeenHighlight ||
                (MainWindow.HasToplevelFocus &&
                 chatView.LabelWidget.IsDrawable)) {
                // no need to show a notification for:
                // - disabled chats
                // - seen highlights
                // - main window has focus and the chat tab is visible
                return;
            }

            try {
                ShowNotification(chatView, e.Message);
            } catch (Exception ex) {
            #if LOG4NET
                Logger.Error("OnChatViewMessageHighlighted(): " +
                             "ShowNotification() threw exception", ex);
            #endif
            }
        }
Example #24
0
        void ShowIndicator(ChatView chatView, MessageModel msg)
        {
            Indicator indicator;
            if (Indicators.TryGetValue(chatView, out indicator)) {
                // update time of existing indicator
                indicator.SetProperty(
                    "time",
                    msg.TimeStamp.ToLocalTime().ToString("s")
                );
                return;
            }

            indicator = new Indicator();
            indicator.SetProperty("subtype", "im");
            if (chatView is PersonChatView) {
                indicator.SetProperty("icon", PersonChatIconBase64);
                indicator.SetProperty("sender", chatView.Name);
            }
            if (chatView is GroupChatView) {
                indicator.SetProperty("icon", GroupChatIconBase64);
                var nick = GetNick(msg);
                if (nick == null) {
                    indicator.SetProperty("sender", chatView.Name);
                } else {
                    indicator.SetProperty("sender",
                        String.Format(
                            "{0} ({1})",
                            chatView.Name, nick
                        )
                    );
                }
            }
            indicator.SetProperty(
                "time",
                msg.TimeStamp.ToLocalTime().ToString("s")
            );
            indicator.SetPropertyBool("draw-attention", true);
            indicator.UserDisplay += delegate {
                try {
                    MainWindow.PresentWithServerTime();
                    MainWindow.Notebook.CurrentChatView = chatView;
                    DisposeIndicator(chatView);
                } catch (Exception ex) {
            #if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted() " +
                                 "indicator.UserDisplay threw exception", ex);
            #endif
                }
            };
            try {
                indicator.Show();
            } catch (Exception ex) {
            #if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted() " +
                                 "indicator.Show() thew exception", ex);
            #endif
            }

            Indicators.Add(chatView, indicator);
        }
Example #25
0
        void OnItemActivated(ChatView chat)
        {
            Trace.Call(chat);

            foreach (var invitee in Invitees) {
                var inviteeId = invitee.ID;
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        ProtocolManager.CommandInvite(
                            new CommandModel(
                                Frontend.FrontendManager,
                                ChatViewManager.ActiveChat.ChatModel,
                                String.Format("{0} {1}", inviteeId, chat.ID)
                            )
                        );
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
        }
Example #26
0
        void DisposeSource(ChatView chatView)
        {
            Trace.Call(chatView);

            try {
                string sourceId;
                if (!Sources.TryGetValue(chatView, out sourceId)) {
                    return;
                }

                App.RemoveSource(sourceId);
            } finally {
                Sources.Remove(chatView);
            }
        }
Example #27
0
 public ChatViewManagerChatAddedEventArgs(ChatView chatView)
 {
     f_ChatView = chatView;
 }
Example #28
0
        void ShowSource(ChatView chatView, MessageModel msg)
        {
            Trace.Call(chatView, msg);

            string sourceId;
            var time = (Int64) ((msg.TimeStamp - UnixEpoch).TotalMilliseconds * 1000L);
            if (Sources.TryGetValue(chatView, out sourceId)) {
                // update time of existing source
                App.SetSourceTime(sourceId, time);
                return;
            }

            // TODO: TEST ME!
            sourceId = chatView.ID;
            string iconName = null;
            string label = null;
            if (chatView is PersonChatView) {
                iconName = "smuxi-person-chat";
                label = chatView.Name;
            } else if (chatView is GroupChatView) {
                iconName = "smuxi-group-chat";
                var nick = GetNick(msg);
                if (nick == null) {
                    label = chatView.Name;
                } else {
                    label = String.Format("{0} ({1})", chatView.Name, nick);
                }
            }

            var theme = Gtk.IconTheme.Default;
            GLib.Icon icon = null;
            if (Frontend.HasSystemIconTheme &&
                iconName != null && theme.HasIcon(iconName)) {
                icon = new GLib.ThemedIcon(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)) {
                    icon = new GLib.FileIcon(
                        GLib.FileFactory.NewForPath(iconInfo.Filename)
                    );
                }
            }
            App.AppendSource(sourceId, icon, label);
            App.SetSourceTime(sourceId, time);
            App.DrawAttention(sourceId);
            Sources.Add(chatView, sourceId);
        }
Example #29
0
 public ChatViewManagerChatSyncedEventArgs(ChatView chatView)
 {
     ChatView = chatView;
 }
Example #30
0
        public void UpdateTitle(ChatView chatView, string protocolStatus)
        {
            Trace.Call(chatView, protocolStatus);

            if (chatView == null) {
                chatView = ChatViewManager.CurrentChatView;
            }
            if (protocolStatus == null) {
                protocolStatus = f_NetworkStatus;
            }
            if (chatView == null) {
                return;
            }

            string title;
            if (chatView is SessionChatView) {
                title = String.Empty;
            } else if (chatView is ProtocolChatView) {
                title = protocolStatus;
            } else if (chatView is GroupChatView) {
                var groupChatView = (GroupChatView) chatView;
                var users = String.Format(_("{0} Users"),
                                          groupChatView.Participants.Count);
                title = String.Format("{0} ({1}) @ {2}",
                                      chatView.Name,
                                      users,
                                      protocolStatus);
            } else {
                title = String.Format("{0} @ {1}",
                                      chatView.Name,
                                      protocolStatus);
            }
            if (!String.IsNullOrEmpty(title)) {
                title += " - ";
            }
            title += "Smuxi";

            Title = title;
        }
Example #31
0
 int GetChatSortValue(ChatView chat)
 {
     int status = 0;
     if (chat is SessionChatView) {
         status += 100;
     }
     if (chat is ProtocolChatView) {
         status += 50;
     }
     if (chat is GroupChatView) {
         status += 10;
     }
     return status;
 }
Example #32
0
        void ShowIndicator(ChatView chatView, MessageModel msg)
        {
            Indicator indicator;

            if (Indicators.TryGetValue(chatView, out indicator))
            {
                // update time of existing indicator
                indicator.SetProperty(
                    "time",
                    msg.TimeStamp.ToLocalTime().ToString("s")
                    );
                return;
            }

            indicator = new Indicator();
            indicator.SetProperty("subtype", "im");
            if (chatView is PersonChatView)
            {
                indicator.SetProperty("icon", PersonChatIconBase64);
                indicator.SetProperty("sender", chatView.Name);
            }
            if (chatView is GroupChatView)
            {
                indicator.SetProperty("icon", GroupChatIconBase64);
                var nick = GetNick(msg);
                if (nick == null)
                {
                    indicator.SetProperty("sender", chatView.Name);
                }
                else
                {
                    indicator.SetProperty("sender",
                                          String.Format(
                                              "{0} ({1})",
                                              chatView.Name, nick
                                              )
                                          );
                }
            }
            indicator.SetProperty(
                "time",
                msg.TimeStamp.ToLocalTime().ToString("s")
                );
            indicator.SetPropertyBool("draw-attention", true);
            indicator.UserDisplay += delegate {
                try {
                    MainWindow.PresentWithServerTime();
                    ChatViewManager.CurrentChatView = chatView;
                    DisposeIndicator(chatView);
                } catch (Exception ex) {
#if LOG4NET
                    Logger.Error("OnChatViewMessageHighlighted() " +
                                 "indicator.UserDisplay threw exception", ex);
#endif
                }
            };
            try {
                indicator.Show();
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("OnChatViewMessageHighlighted() " +
                             "indicator.Show() thew exception", ex);
#endif
            }

            Indicators.Add(chatView, indicator);
        }