Beispiel #1
0
        protected void OnSwitchRemoteEngineActionActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                var dialog = new Gtk.MessageDialog(
                    Parent, Gtk.DialogFlags.Modal,
                    Gtk.MessageType.Warning, Gtk.ButtonsType.YesNo,
                    _("Switching the remote engine will disconnect you from the current engine!\n" +
                      "Are you sure you want to do this?")
                    );
                int result = dialog.Run();
                dialog.Destroy();
                if ((Gtk.ResponseType)result == Gtk.ResponseType.Yes)
                {
                    Frontend.DisconnectEngineFromGUI();
                    Frontend.ShowEngineManagerDialog();
                }
            } catch (Exception ex) {
                Frontend.ShowException(Parent, ex);
            }
        }
Beispiel #2
0
        protected virtual void OnPopulatePopup(object sender, Gtk.PopulatePopupArgs e)
        {
            Trace.Call(sender, e);

            if (!_AtLinkTag)
            {
                return;
            }

            Gtk.Menu popup = e.Menu;
            // remove all items
            foreach (Gtk.Widget children in popup.Children)
            {
                popup.Remove(children);
            }

            Gtk.ImageMenuItem open_item = new Gtk.ImageMenuItem(Gtk.Stock.Open, null);
            open_item.Activated += delegate {
                if (_ActiveLink != null)
                {
                    Frontend.OpenLink(_ActiveLink);
                }
            };
            popup.Append(open_item);

            Gtk.ImageMenuItem copy_item = new Gtk.ImageMenuItem(Gtk.Stock.Copy, null);
            copy_item.Activated += delegate {
                if (_ActiveLink == null)
                {
                    return;
                }
                Gdk.Atom      clipboardAtom = Gdk.Atom.Intern("CLIPBOARD", false);
                Gtk.Clipboard clipboard     = Gtk.Clipboard.Get(clipboardAtom);
                clipboard.Text = _ActiveLink.ToString();
            };
            popup.Append(copy_item);

            popup.ShowAll();
        }
Beispiel #3
0
        private void InitCommandManager()
        {
            if (_CommandManager != null)
            {
                _CommandManager.Dispose();
            }

            if (Frontend.Session == null)
            {
                _CommandManager = null;
            }
            else
            {
                _CommandManager = new CommandManager(Frontend.Session);
                _CommandManager.ExceptionEvent +=
                    delegate(object sender, CommandExceptionEventArgs e) {
                    Gtk.Application.Invoke(delegate {
                        Frontend.ShowException(e.Exception);
                    });
                };
            }
        }
Beispiel #4
0
        public override void Close()
        {
            Trace.Call();

            // show warning if there are open chats (besides protocol chat)
            // FIXME: REMOTING CALL 1 + 2 + 3
            if (ChatModel.ProtocolManager.Chats.Count > 1)
            {
                Gtk.MessageDialog md = new Gtk.MessageDialog(
                    Frontend.MainWindow,
                    Gtk.DialogFlags.Modal,
                    Gtk.MessageType.Warning,
                    Gtk.ButtonsType.YesNo,
                    _("Closing the protocol chat will also close all open chats connected to it!\n" +
                      "Are you sure you want to do this?"));
                int result = md.Run();
                md.Destroy();
                if ((Gtk.ResponseType)result != Gtk.ResponseType.Yes)
                {
                    return;
                }
            }

            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    // no need to call base.Close() as CommandNetwork() will
                    // deal with it
                    Frontend.Session.CommandNetwork(
                        new CommandModel(
                            Frontend.FrontendManager,
                            ChatModel,
                            "close"
                            )
                        );
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            });
        }
Beispiel #5
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);
                    }
                });
            }
        }
Beispiel #6
0
        protected virtual void OnTabMenuReconnectActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                var pm = ProtocolManager;
                if (pm == null)
                {
                    return;
                }

                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        pm.Reconnect(Frontend.FrontendManager);
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            } catch (Exception ex) {
                Frontend.ShowException(ex);
            }
        }
Beispiel #7
0
        private static bool CheckFrontendManagerStatus()
        {
            Trace.Call();

            if (_FrontendManager == null)
            {
                // we lost the frontend manager, nothing to check
                return(false);
            }

            if (_FrontendManager.IsAlive)
            {
                // everything is fine
                return(true);
            }

#if LOG4NET
            _Logger.Error("CheckFrontendManagerStatus(): frontend manager is not alive anymore!");
#endif
            Gtk.Application.Invoke(delegate {
                Gtk.MessageDialog md = new Gtk.MessageDialog(_MainWindow,
                                                             Gtk.DialogFlags.Modal, Gtk.MessageType.Error,
                                                             Gtk.ButtonsType.OkCancel, _("The server has lost the connection to the frontend.\nDo you want to reconnect now?"));
                Gtk.ResponseType res = (Gtk.ResponseType)md.Run();
                md.Destroy();

                if (res != Gtk.ResponseType.Ok)
                {
                    // the frontend is unusable in this state -> say good bye
                    Frontend.Quit();
                    return;
                }

                Frontend.ReconnectEngineToGUI();
            });

            return(false);
        }
Beispiel #8
0
        private void OnStatusIconPopupMenu(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            Gtk.Menu menu = new Gtk.Menu();

            Gtk.ImageMenuItem preferencesItem = new Gtk.ImageMenuItem(
                Gtk.Stock.Preferences, null
                );
            preferencesItem.Activated += delegate {
                try {
                    var builder = new Gtk.Builder(null, "PreferencesDialog2.ui", null);
                    var widget  = (Gtk.Widget)builder.GetObject("PreferencesDialog");
                    var dialog  = new PreferencesDialog(f_MainWindow, builder, widget.Handle);
                    dialog.Show();
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            };
            menu.Add(preferencesItem);

            menu.Add(new Gtk.SeparatorMenuItem());

            Gtk.ImageMenuItem quitItem = new Gtk.ImageMenuItem(
                Gtk.Stock.Quit, null
                );
            quitItem.Activated += delegate {
                try {
                    Frontend.Quit();
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            };
            menu.Add(quitItem);

            menu.ShowAll();
            menu.Popup();
        }
Beispiel #9
0
        protected virtual void OnFocusInEvent(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                UrgencyHint = false;
                if (_Notebook.IsBrowseModeEnabled)
                {
                    return;
                }

                ChatView chatView = _Notebook.CurrentChatView;
                if (chatView != null)
                {
                    // clear activity and highlight
                    chatView.HasHighlight = false;
                    chatView.HasActivity  = false;
                    var lastMsg = chatView.OutputMessageTextView.LastMessage;
                    if (lastMsg == null || Frontend.UseLowBandwidthMode)
                    {
                        return;
                    }
                    // update last seen highlight
                    ThreadPool.QueueUserWorkItem(delegate {
                        try {
                            // REMOTING CALL 1
                            chatView.ChatModel.LastSeenHighlight = lastMsg.TimeStamp;
                        } catch (Exception ex) {
#if LOG4NET
                            f_Logger.Error("OnFocusInEvent(): Exception", ex);
#endif
                        }
                    });
                }
            } catch (Exception ex) {
                Frontend.ShowException(this, ex);
            }
        }
Beispiel #10
0
        private void OnStatusIconPopupMenu(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            Gtk.Menu menu = new Gtk.Menu();

            Gtk.ImageMenuItem preferencesItem = new Gtk.ImageMenuItem(
                Gtk.Stock.Preferences, null
                );
            preferencesItem.Activated += delegate {
                try {
                    PreferencesDialog dialog = new PreferencesDialog(f_MainWindow);
                    dialog.CurrentPage          = PreferencesDialog.Page.Interface;
                    dialog.CurrentInterfacePage = PreferencesDialog.InterfacePage.Notification;
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            };
            menu.Add(preferencesItem);

            menu.Add(new Gtk.SeparatorMenuItem());

            Gtk.ImageMenuItem quitItem = new Gtk.ImageMenuItem(
                Gtk.Stock.Quit, null
                );
            quitItem.Activated += delegate {
                try {
                    Frontend.Quit();
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            };
            menu.Add(quitItem);

            menu.ShowAll();
            menu.Popup();
        }
Beispiel #11
0
        void _OnMenuAddToContactsItemActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            IList <PersonModel> persons = GetSelectedPersons();

            if (persons == null)
            {
                return;
            }

            foreach (PersonModel person in persons)
            {
                var per = person;

                // is this a groupchat contact whose real id is unknown
                if (person.ID.StartsWith(ID))
                {
                    continue;
                }

                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        XmppProtocolManager.CommandContact(
                            new CommandModel(
                                Frontend.FrontendManager,
                                ChatModel,
                                "add " + per.ID
                                )
                            );
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
        }
Beispiel #12
0
        void OnUserinfoItemActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            var sourceChatModel = ChatViewManager.ActiveChat.ChatModel;

            foreach (PersonModel target in Targets)
            {
                var targetId = target.ID;
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        ProtocolManager.CommandCtcp(
                            new CommandModel(
                                Frontend.FrontendManager,
                                sourceChatModel,
                                String.Format("{0} {1}", targetId, "USERINFO")
                                )
                            );
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
        }
Beispiel #13
0
        protected void OnCaretModeActionToggled(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                var caretMode = f_CaretModeAction.Active;

                foreach (var chatView in ChatViewManager.Chats)
                {
                    chatView.OutputMessageTextView.CursorVisible = caretMode;
                }

                if (caretMode)
                {
                    ChatViewManager.CurrentChatView.OutputMessageTextView.HasFocus = true;
                }
                else
                {
                    MainWindow.Entry.HasFocus = true;
                }
            } catch (Exception ex) {
                Frontend.ShowException(Parent, ex);
            }
        }
Beispiel #14
0
        void OnTimeItemActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            var sourceChatModel = ChatViewManager.ActiveChat.ChatModel;

            foreach (PersonModel target in Targets)
            {
                var targetId = target.ID;
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        ProtocolManager.CommandTime(
                            new CommandModel(
                                Frontend.FrontendManager,
                                sourceChatModel,
                                targetId
                                )
                            );
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
        }
Beispiel #15
0
        public static bool TryOpenChatLink(Uri link)
        {
            Trace.Call(link);

            if (Session == null)
            {
                return(false);
            }

            // supported:
            // smuxi://freenode/#smuxi
            // smuxi://freenode/#%23csharp (##csharp)
            // irc://#smuxi
            // irc://irc.oftc.net/
            // irc://irc.oftc.net/#smuxi
            // irc://irc.oftc.net:6667/#smuxi
            // not supported (yet):
            // smuxi:///meebey

            IProtocolManager manager = null;
            var linkPort             = link.Port;

            if (linkPort == -1)
            {
                switch (link.Scheme)
                {
                case "irc":
                    linkPort = 6667;
                    break;

                case "ircs":
                    linkPort = 6697;
                    break;
                }
            }
            // decode #%23csharp to ##csharp
            var linkChat = HttpUtility.UrlDecode(link.Fragment);

            if (String.IsNullOrEmpty(linkChat) && link.AbsolutePath.Length > 0)
            {
                linkChat = link.AbsolutePath.Substring(1);
            }

            var    linkProtocol = link.Scheme;
            var    linkHost     = link.Host;
            string linkNetwork  = null;

            if (!linkHost.Contains("."))
            {
                // this seems to be a network name
                linkNetwork = linkHost;
            }

            // find existing protocol chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats)
            {
                if (!(chatView is ProtocolChatView))
                {
                    continue;
                }
                var protocolChat = (ProtocolChatView)chatView;
                var host         = protocolChat.Host;
                var port         = protocolChat.Port;
                var network      = protocolChat.NetworkID;
                // Check first by network name with fallback to host+port.
                // The network name has to be checked against the NetworkID and
                // also ChatModel.ID as the user might have entered a different
                // network name in settings than the server does
                if (!String.IsNullOrEmpty(network) &&
                    (String.Compare(network, linkNetwork, true) == 0 ||
                     String.Compare(chatView.ID, linkNetwork, true) == 0))
                {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
                if (String.Compare(host, linkHost, true) == 0 &&
                    port == linkPort)
                {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
            }

            if (manager == null)
            {
                // only irc may autoconnect to a server
                switch (linkProtocol)
                {
                case "irc":
                case "ircs":
                case "smuxi":
                    break;

                default:
                    return(false);
                }
                ServerModel server = null;
                if (!String.IsNullOrEmpty(linkNetwork))
                {
                    // try to find a server with this network name and connect to it
                    var serverSettings = new ServerListController(UserConfig);
                    server = serverSettings.GetServerByNetwork(linkNetwork);
                    if (server == null)
                    {
                        // in case someone tried an unknown network
                        return(false);
                    }
                    // ignore OnConnectCommands
                    server.OnConnectCommands = null;
                }
                else if (!String.IsNullOrEmpty(linkHost))
                {
                    server = new ServerModel()
                    {
                        Protocol = linkProtocol,
                        Hostname = linkHost,
                        Port     = linkPort
                    };
                }
                if (server != null)
                {
                    manager = Session.Connect(server, FrontendManager);
                }
            }

            if (String.IsNullOrEmpty(linkChat))
            {
                return(true);
            }

            // switch to existing chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats)
            {
                if (manager != null && chatView.ProtocolManager != manager)
                {
                    continue;
                }
                if (String.Compare(chatView.ID, linkChat, true) == 0)
                {
                    MainWindow.ChatViewManager.CurrentChatView = chatView;
                    return(true);
                }
            }

            // join chat
            if (manager != null)
            {
                var chat = new GroupChatModel(linkChat, linkChat, null);
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        manager.OpenChat(FrontendManager, chat);
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
            return(true);
        }
Beispiel #16
0
        public static void ShowException(Gtk.Window parent, Exception ex)
        {
            Trace.Call(parent, ex != null ? ex.GetType() : null);

            if (parent == null)
            {
                parent = _MainWindow;
            }

            if (!IsGuiThread())
            {
                Gtk.Application.Invoke(delegate {
                    ShowException(parent, ex);
                });
                return;
            }

            if (ex is NotImplementedException)
            {
                // don't quit on NotImplementedException
                ShowError(parent, ex);
                return;
            }

#if LOG4NET
            _Logger.Error("ShowException(): Exception:", ex);
#endif

            // HACK: ugly MS .NET throws underlaying SocketException instead of
            // wrapping those into a nice RemotingException, see:
            // http://projects.qnetp.net/issues/show/232
            if (ex is System.Runtime.Remoting.RemotingException ||
                ex is System.Net.Sockets.SocketException)
            {
                if (_InReconnectHandler || _InCrashHandler)
                {
                    // one reconnect is good enough and a crash we won't survive
                    return;
                }

                Frontend.ReconnectEngineToGUI();
                return;
            }

            if (_InCrashHandler)
            {
                // only show not more than one crash dialog, else the user
                // will not be able to copy/paste the stack trace and stuff
                return;
            }
            _InCrashHandler = true;

            CrashDialog cd = new CrashDialog(parent, ex);
            cd.Run();
            cd.Destroy();

            if (SysDiag.Debugger.IsAttached)
            {
                // allow the debugger to examine the situation
                //SysDiag.Debugger.Break();
                // HACK: Break() would be nicer but crashes the runtime
                throw ex;
            }

            Quit();
        }
Beispiel #17
0
        public static void ReconnectEngineToGUI(bool cleanly)
        {
            Trace.Call(cleanly);

            if (_InReconnectHandler)
            {
#if LOG4NET
                _Logger.Debug("ReconnectEngineToGUI(): already in reconnect " +
                              "handler, ignoring reconnect...");
#endif
                return;
            }

            _InReconnectHandler = true;
            var disconnectedEvent = new AutoResetEvent(false);
            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    // delay the disconnect to give the reconnect some extra
                    // time as NetworkManager is not accurate about when the
                    // network is really ready
                    GLib.Timeout.Add(5 * 1000, delegate {
                        Frontend.DisconnectEngineFromGUI(cleanly);
                        disconnectedEvent.Set();
                        return(false);
                    });

                    var successful = false;
                    var attempt    = 1;
                    while (!successful)
                    {
                        Gtk.Application.Invoke(delegate {
                            MainWindow.NetworkStatus = null;
                            MainWindow.Status        = String.Format(
                                _("Reconnecting to engine... (attempt {0})"),
                                attempt++
                                );
                        });
                        try {
                            disconnectedEvent.WaitOne();
                            _MainWindow.EngineManager.Reconnect();
                            successful = true;
                        } catch (Exception ex) {
#if LOG4NET
                            _Logger.Debug("ReconnectEngineToGUI(): Exception", ex);
#endif
                            disconnectedEvent.Set();
                            Thread.Sleep(30 * 1000);
                        }
                    }
                    _UserConfig           = _MainWindow.EngineManager.UserConfig;
                    EngineAssemblyVersion = _MainWindow.EngineManager.EngineAssemblyVersion;
                    EngineProtocolVersion = _MainWindow.EngineManager.EngineProtocolVersion;
                    Session = _MainWindow.EngineManager.Session;

                    Gtk.Application.Invoke(delegate {
                        Frontend.ConnectEngineToGUI();
                    });
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                } finally {
                    _InReconnectHandler = false;
                }
            });
        }
Beispiel #18
0
        public static void ConnectEngineToGUI()
        {
            if (IsLocalEngine)
            {
                // HACK: SessionManager.Register() is not used for local engines
                _LocalSession.RegisterFrontendUI(_MainWindow.UI);
            }

            SyncConfig();

            _FrontendManager = _Session.GetFrontendManager(_MainWindow.UI);
            _FrontendManager.Sync();

            // MS .NET doesn't like this with Remoting?
            if (Type.GetType("Mono.Runtime") != null)
            {
                // when are running on Mono, all should be good
                if (_UserConfig.IsCaching)
                {
                    // when our UserConfig is cached, we need to invalidate the cache
                    // DISABLED: see FrontendManager._OnConfigChanged
                    //_FrontendManager.ConfigChangedDelegate = SyncConfig;
                }
            }

            _MainWindow.ShowAll();
            // make sure entry got attention :-P
            _MainWindow.Entry.HasFocus = true;

            // local sessions can't have network issues :)
            if (_Session != _LocalSession)
            {
                _FrontendManagerCheckerQueue = new TaskQueue("FrontendManagerCheckerQueue");
                _FrontendManagerCheckerQueue.AbortedEvent += delegate {
#if LOG4NET
                    _Logger.Debug("_FrontendManagerCheckerQueue.AbortedEvent(): task queue aborted!");
#endif
                };

                _FrontendManagerCheckerQueue.ExceptionEvent +=
                    delegate(object sender, TaskQueueExceptionEventArgs e) {
#if LOG4NET
                    _Logger.Error("Exception in TaskQueue: ", e.Exception);
                    _Logger.Error("Inner-Exception: ", e.Exception.InnerException);
#endif
                    Frontend.ShowException(e.Exception);
                };

                _FrontendManagerCheckerQueue.Queue(delegate {
                    // keep looping as long as the checker returns true
                    while (CheckFrontendManagerStatus())
                    {
                        // FIXME: bail out somehow when we lost the connection
                        // without an exception in the meantime

                        // only check once per minute
                        Thread.Sleep(60 * 1000);
                    }
#if LOG4NET
                    _Logger.Debug("_FrontendManagerCheckerQueue(): " +
                                  "CheckFrontendManagerStatus() returned false, " +
                                  "time to say good bye!");
#endif
                });
            }
            MainWindow.ChatViewManager.IsSensitive = true;
        }
Beispiel #19
0
        private static void InitGtk(string[] args)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                InitGtkPathWin();
            }

#if GTK_SHARP_2_8 || GTK_SHARP_2_10
            if (!GLib.Thread.Supported)
            {
                GLib.Thread.Init();
            }
#else
            // with GTK# 2.8 we can do this better, see above
            // GTK# 2.7.1 for MS .NET doesn't support that though.
            if (Type.GetType("Mono.Runtime") == null)
            {
                // when we don't run on Mono, we need to initialize glib ourself
                GLib.Thread.Init();
            }
#endif
            _UIThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;

            string appDir    = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string localeDir = Path.Combine(appDir, "locale");
            if (!Directory.Exists(localeDir))
            {
                localeDir = Path.Combine(Defines.InstallPrefix, "share");
                localeDir = Path.Combine(localeDir, "locale");
            }

            LibraryCatalog.Init("smuxi-frontend-gnome", localeDir);
#if LOG4NET
            _Logger.Debug("InitGtk(): Using locale data from: " + localeDir);
#endif
            Gtk.Application.Init(Name, ref args);
            IsGtkInitialized = true;
#if GTK_SHARP_2_10
            GLib.ExceptionManager.UnhandledException += _OnUnhandledException;
#endif

            IconName = "smuxi-frontend-gnome";
            var iconPath = Path.Combine(Defines.InstallPrefix, "share");
            iconPath = Path.Combine(iconPath, "icons");
            var theme    = Gtk.IconTheme.Default;
            var settings = Gtk.Settings.Default;
            var iconInfo = theme.LookupIcon(IconName, -1, 0);
            HasSystemIconTheme = iconInfo != null &&
                                 iconInfo.Filename != null &&
                                 iconInfo.Filename.StartsWith(iconPath);
#if LOG4NET
            _Logger.DebugFormat("InitGtk(): Using {0} icon theme",
                                HasSystemIconTheme ? "system" : "built-in");
#endif

            var unityWithLightIcons = false;
            if (Frontend.IsUnity)
            {
                var sysGtkTheme  = settings.ThemeName ?? String.Empty;
                var sysIconTheme = GetGtkIconThemeName() ?? String.Empty;
#if LOG4NET
                _Logger.DebugFormat("InitGtk(): Detected GTK+ theme: {0} " +
                                    "icon theme: {1}", sysGtkTheme,
                                    sysIconTheme);
#endif
                if (sysGtkTheme.StartsWith("Ambiance") &&
                    sysIconTheme != "ubuntu-mono-dark")
                {
#if LOG4NET
                    _Logger.Debug("InitGtk(): Detected Ambiance theme with " +
                                  "light icons");
#endif
                    unityWithLightIcons = true;
                }
            }
            var appIconDir = Path.Combine(appDir, "icons");
            if (Directory.Exists(appIconDir))
            {
                var iconTheme = "Smuxi-Symbolic";
#if LOG4NET
                _Logger.InfoFormat("InitGtk(): Setting icon theme to: {0}",
                                   iconTheme);
#endif
                var origin = Assembly.GetExecutingAssembly().FullName;
                settings.SetStringProperty(
                    "gtk-icon-theme-name", iconTheme, origin
                    );
                settings.SetLongProperty(
                    "gtk-menu-images", 0, origin
                    );
                settings.SetLongProperty(
                    "gtk-button-images", 0, origin
                    );
#if LOG4NET
                _Logger.InfoFormat("InitGtk(): Prepending {0} to icon search path",
                                   appIconDir);
#endif
                theme.PrependSearchPath(appIconDir);
            }

            if (HasSystemIconTheme)
            {
                Gtk.Window.DefaultIconName = "smuxi-frontend-gnome";
            }
            else
            {
                Gtk.Window.DefaultIcon = Frontend.LoadIcon(
                    "smuxi-frontend-gnome", 256, "icon_256x256.png"
                    );
            }
        }
Beispiel #20
0
 static SessionChatView()
 {
     IconPixbuf = Frontend.LoadIcon(
         "smuxi-session-chat", 16, "session-chat_256x256.png"
         );
 }
Beispiel #21
0
 private void _CommandDetach(CommandModel cd)
 {
     Frontend.Quit();
 }
Beispiel #22
0
 private void _CommandList(CommandModel cd)
 {
     Frontend.OpenFindGroupChatWindow(cd.Parameter);
 }
Beispiel #23
0
        private void _OnActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                if (!(Text.Length > 0))
                {
                    return;
                }
                if (ChatViewManager.CurrentChatView == null)
                {
                    return;
                }

                if (Text.IndexOf("\n") != -1)
                {
                    var text = Text.TrimEnd('\n');
                    // seems to be a paste, so let's break it apart
                    string[] msgParts = text.Split(new char[] { '\n' });
                    if (msgParts.Length > 3)
                    {
                        string msg = String.Format(_("You are going to paste {0} lines. Do you want to continue?"),
                                                   msgParts.Length);
                        Gtk.MessageDialog md = new Gtk.MessageDialog(
                            Frontend.MainWindow,
                            Gtk.DialogFlags.Modal,
                            Gtk.MessageType.Warning,
                            Gtk.ButtonsType.YesNo,
                            msg);
                        Gtk.ResponseType res = (Gtk.ResponseType)md.Run();
                        md.Destroy();
                        if (res != Gtk.ResponseType.Yes)
                        {
                            Text = String.Empty;
                            return;
                        }
                    }
                    if (Frontend.EngineVersion < new Version(0, 8, 11))
                    {
                        foreach (string msg in msgParts)
                        {
                            ExecuteCommand(msg);
                        }
                    }
                    else
                    {
                        // new engines know how to handle messages containing \n
                        ExecuteCommand(text);
                    }
                }
                else
                {
                    ExecuteCommand(Text);
                    AddToHistory(Text, _History.Count - _HistoryPosition);
                    // reset history position to last entry
                    _HistoryPosition = _History.Count - 1;
                }
                Text = String.Empty;
            } catch (Exception ex) {
#if LOG4NET
                _Logger.Error(ex);
#endif
                Frontend.ShowException(null, ex);
            }
        }
Beispiel #24
0
        protected virtual void OnSwitchPage(object sender, Gtk.SwitchPageArgs e)
        {
            Trace.Call(sender, e);

            if (f_IsBrowseModeEnabled)
            {
                return;
            }

            // synchronize FrontManager.CurrenPage
            ChatView chatView = GetChat((int)e.PageNum);

            if (chatView == null)
            {
                return;
            }

            ChatModel chatModel = chatView.ChatModel;

            // clear activity and highlight
            chatView.HasHighlight = false;
            chatView.HasActivity  = false;
            chatView.HasEvent     = false;
            var lastMsg = chatView.OutputMessageTextView.LastMessage;

            var method = Trace.GetMethodBase();

            f_SwitchPageQueue.Queue(delegate {
                // HACK: don't pass the real parameters are it's unsafe from
                // a non-main (GUI) thread!
                Trace.Call(method, null, null);

                try {
                    DateTime start = DateTime.UtcNow, stop;
                    var fm         = Frontend.FrontendManager;
                    if (fm == null)
                    {
                        // in case we are currently reconnecting to a remote engine
                        return;
                    }

                    // OPT-TODO: we could use here a TaskStack instead which
                    // would make sure only the newest task gets executed
                    // instead of every task in the FIFO sequence!
                    var nmanager = chatView.ProtocolManager;

                    // TODO: only set the protocol manager and update network
                    // status if the protocol manager differs from the old one

                    // REMOTING CALL 2
                    fm.CurrentChat = chatModel;
                    if (nmanager != null)
                    {
                        // REMOTING CALL 3
                        fm.CurrentProtocolManager = nmanager;
                    }

                    // even when we have no network manager, we still want to update
                    // the network status and title
                    // REMOTING CALL 4
                    fm.UpdateNetworkStatus();

                    // update last seen highlight
                    // REMOTING CALL 5
                    if (lastMsg != null && !Frontend.UseLowBandwidthMode)
                    {
                        chatModel.LastSeenHighlight = lastMsg.TimeStamp;
                    }

                    stop = DateTime.UtcNow;
#if LOG4NET
                    f_Logger.Debug("OnSwitchPage(): task took: " + (stop - start).Milliseconds + " ms");
#endif
                } catch (Exception ex) {
#if LOG4NET
                    f_Logger.Error("OnSwitchPage(): Exception", ex);
#endif
                    Frontend.ShowException(ex);
                }
            });
        }
Beispiel #25
0
        public AboutDialog(Gtk.Window parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            TransientFor = parent;
            ProgramName  = Frontend.Name;
            var version     = Frontend.Version.ToString();
            var distVersion = Defines.DistVersion;

            if (!String.IsNullOrEmpty(distVersion))
            {
                Version = String.Format("\n Vendor: {0}", distVersion);
            }
            Version += "\n Frontend: " + Frontend.UIName + " " + version +
                       "\n Engine: " + Frontend.EngineAssemblyVersion;
            if (!Frontend.IsLocalEngine)
            {
                Version += "\n Protocol: " + Frontend.EngineProtocolVersion;
            }
            Copyright = "Copyright © 2005-2017 Mirco Bauer <*****@*****.**> and other contributors";
            Authors   = new string[] {
                "Mirco Bauer <*****@*****.**>",
                "David Paleino <*****@*****.**>",
                "Clément Bourgeois <*****@*****.**>",
                "Chris Le Sueur <*****@*****.**>",
                "Tuukka Hastrup <*****@*****.**>",
                "Bianca Mix <*****@*****.**>",
                "Oliver Schneider <*****@*****.**>",
                "Carlos Martín Nieto <*****@*****.**>"
            };
            Artists = new string[] {
                "Jakub Steiner <*****@*****.**>",
                "Rodney Dawes <*****@*****.**>",
                "Lapo Calamandrei <*****@*****.**>",
                "Ahmed Abdellah <*****@*****.**>",
                "George Karavasilev <*****@*****.**>",
                "Joern Konopka <*****@*****.**>",
                "Nuno F. Pinheiro <*****@*****.**>"
            };
            TranslatorCredits = _("translator-credits");
            Logo = Frontend.LoadIcon(
                Frontend.IconName, 256, "icon_256x256.png"
                );
            // HACK: shows "not implemented" error on OS X and
            // "No application is registered as handling this file" on Windows.
            // This probably relies on gvfs or similar which isn't available in
            // the GTK{+,#} ports/installers for OS X and Windows. Thus we only
            // show the website URL as label instead.
            if (Frontend.IsMacOSX || Frontend.IsWindows)
            {
                WebsiteLabel = "https://smuxi.im/";
            }
            else
            {
                Website      = "https://smuxi.im/";
                WebsiteLabel = _("Smuxi Website");
            }
        }
Beispiel #26
0
 static PersonChatView()
 {
     IconPixbuf = Frontend.LoadIcon(
         "smuxi-person-chat", 16, "person-chat_256x256.png"
         );
 }
Beispiel #27
0
        protected virtual void OnFindButtonClicked(object sender, System.EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                string nameFilter = f_NameEntry.Text.Trim();
                if (!(Frontend.EngineVersion >= new Version("0.8.1")) &&
                    String.IsNullOrEmpty(nameFilter))
                {
                    Gtk.MessageDialog md = new Gtk.MessageDialog(
                        this,
                        Gtk.DialogFlags.Modal,
                        Gtk.MessageType.Warning,
                        Gtk.ButtonsType.YesNo,
                        _("Searching for group chats without a filter is not " +
                          "recommended.  This may take a while, or may not " +
                          "work at all.\n" +
                          "Do you wish to continue?")
                        );
                    int result = md.Run();
                    md.Destroy();
                    if (result != (int)Gtk.ResponseType.Yes)
                    {
                        return;
                    }
                }

                f_ListStore.Clear();
                CancelFindThread();

                GroupChatModel filter = new GroupChatModel(null, nameFilter, null);
                f_FindThread = new Thread(new ThreadStart(delegate {
                    try {
                        Gtk.Application.Invoke(delegate {
                            GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
                        });

                        IList <GroupChatModel> chats = f_ProtocolManager.FindGroupChats(filter);

                        Gtk.Application.Invoke(delegate {
                            Gdk.Color bgColor = f_TreeView.Style.Background(Gtk.StateType.Normal);
                            foreach (GroupChatModel chat in chats)
                            {
                                f_ListStore.AppendValues(
                                    chat,
                                    chat.PersonCount,
                                    chat.Name,
                                    PangoTools.ToMarkup(chat.Topic, bgColor)
                                    );
                            }
                        });
                    } catch (ThreadAbortException) {
#if LOG4NET
                        f_Logger.Debug("FindThread aborted");
#endif
                        Thread.ResetAbort();
                    } catch (Exception ex) {
                        Frontend.ShowError(this, _("Error while fetching the list of group chats from the server."), ex);
                    } finally {
                        Gtk.Application.Invoke(delegate {
                            // if the dialog is gone the GdkWindow might be destroyed already
                            if (GdkWindow != null)
                            {
                                GdkWindow.Cursor = null;
                            }
                        });
                    }
                }));
                f_FindThread.IsBackground = true;
                f_FindThread.Start();
            } catch (Exception ex) {
                Frontend.ShowException(ex);
            }
        }
Beispiel #28
0
        void OnWorkerException(object sender, WorkerExceptionEventArgs e)
        {
            Trace.Call(sender, e);

            Frontend.ShowException(e.Exception);
        }
Beispiel #29
0
        static ProtocolChatView()
        {
            IconPixbuf = Frontend.LoadIcon(
                "smuxi-protocol-chat", 16, "protocol-chat_256x256.png"
                );
            NetworkWebsiteUrls = new Dictionary <string, string>(
                StringComparer.InvariantCultureIgnoreCase
                );

            // IRC
            NetworkWebsiteUrls.Add("OFTC", "http://www.oftc.net/");
            NetworkWebsiteUrls.Add("freenode", "http://freenode.net/");
            NetworkWebsiteUrls.Add("QuakeNet", "http://www.quakenet.org/");
            NetworkWebsiteUrls.Add("IRCnet", "http://www.ircnet.org/");
            NetworkWebsiteUrls.Add("DALnet", "http://www.dal.net/");
            NetworkWebsiteUrls.Add("GameSurge", "https://gamesurge.net/");
            NetworkWebsiteUrls.Add("EFnet", "http://www.efnet.org/");
            NetworkWebsiteUrls.Add("GIMPnet", "http://www.gimp.org/");
            NetworkWebsiteUrls.Add("GSDnet", "http://www.gsd-software.net/");
            NetworkWebsiteUrls.Add("ustream", "http://www.ustream.tv/");
            NetworkWebsiteUrls.Add("Infinity-IRC", "http://www.infinityirc.com/");
            NetworkWebsiteUrls.Add("GeekShed", "http://www.geekshed.net/");

            // Twitter
            NetworkWebsiteUrls.Add("Twitter", "http://www.twitter.com/");

            // XMPP - with federation
            NetworkWebsiteUrls.Add("XMPP", "http://xmpp.org/");
            NetworkWebsiteUrls.Add("jabber.org", "http://planet.jabber.org/");
            NetworkWebsiteUrls.Add("jabber.de", "http://www.jabber.de/");
            NetworkWebsiteUrls.Add("jabber.at", "http://planet.jabber.org/");
            NetworkWebsiteUrls.Add("jabber.ccc.de", "http://web.jabber.ccc.de/");
            NetworkWebsiteUrls.Add("xmpp-gmx.gmx.net", "http://planet.jabber.org/");
            NetworkWebsiteUrls.Add("xmpp-webde.gmx.net", "http://planet.jabber.org/");
            NetworkWebsiteUrls.Add("jabber.gmx.net", "http://planet.jabber.org/");
            // XMPP - without federation
            NetworkWebsiteUrls.Add("talk.google.com", "http://www.google.com/talk/");
            NetworkWebsiteUrls.Add("chat.facebook.com", "http://www.facebook.com/");

            // JabbR
            NetworkWebsiteUrls.Add("jabbr.net", "http://jabbr.net/");

            // Campfire
            NetworkWebsiteUrls.Add("Campfire", "http://campfirenow.com");

            // support downloading favicons via https
            var whitelist = Session.CertificateValidator.HostnameWhitelist;

            lock (whitelist) {
                foreach (var url in NetworkWebsiteUrls.Values)
                {
                    var uri      = new Uri(url);
                    var hostname = uri.Host;
                    if (whitelist.Contains(hostname))
                    {
                        continue;
                    }
                    whitelist.Add(hostname);
                }
            }
        }
Beispiel #30
0
        public static void ShowException(Gtk.Window parent, Exception ex)
        {
            Trace.Call(parent, ex != null ? ex.GetType() : null);

            if (parent == null)
            {
                parent = _MainWindow;
            }

            if (!IsGuiThread())
            {
                Gtk.Application.Invoke(delegate {
                    ShowException(parent, ex);
                });
                return;
            }

            if (ex is NotImplementedException)
            {
                // don't quit on NotImplementedException
                ShowError(parent, ex);
                return;
            }

#if LOG4NET
            _Logger.Error("ShowException(): Exception:", ex);
#endif

            // HACK: ugly MS .NET throws underlaying SocketException instead of
            // wrapping those into a nice RemotingException, see:
            // http://projects.qnetp.net/issues/show/232
            if (ex is System.Runtime.Remoting.RemotingException ||
                ex is System.Net.Sockets.SocketException)
            {
                if (_InReconnectHandler || _InCrashHandler)
                {
                    // one reconnect is good enough and a crash we won't survive
                    return;
                }

                Frontend.ReconnectEngineToGUI();
                return;
            }

            if (_InCrashHandler)
            {
                // only show not more than one crash dialog, else the user
                // will not be able to copy/paste the stack trace and stuff
                return;
            }
            _InCrashHandler = true;

            // we are using a remote engine, we are not running on Mono and an
            // IConvertible issue happened
            if (!Frontend.IsLocalEngine &&
                Type.GetType("Mono.Runtime") == null &&
                ex is InvalidCastException &&
                ex.Message.Contains("IConvertible"))
            {
                var msg = _(
                    "A fatal error has been detected because of a protocol incompatibility with the smuxi-server!\n\n" +
                    "Please install Mono on the frontend side so it matches the smuxi-server.\n\n" +
                    "More details about this issue can be found here:\n" +
                    "https://smuxi.im/issues/show/589"
                    );
                var dialog = new Gtk.MessageDialog(
                    parent,
                    Gtk.DialogFlags.Modal,
                    Gtk.MessageType.Error,
                    Gtk.ButtonsType.Close,
                    true,
                    msg
                    );
                dialog.Run();
                dialog.Destroy();
                Quit();
                return;
            }

            CrashDialog cd = new CrashDialog(parent, ex);
            cd.Run();
            cd.Destroy();

            if (SysDiag.Debugger.IsAttached)
            {
                // allow the debugger to examine the situation
                //SysDiag.Debugger.Break();
                // HACK: Break() would be nicer but crashes the runtime
                throw ex;
            }

            Quit();
        }