Ejemplo n.º 1
0
        public void ApplyConfig(UserConfig userConfig)
        {
            Trace.Call(userConfig);

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

            string modeStr = (string) userConfig["Interface/Notification/NotificationAreaIconMode"];
            f_NotificationAreaIconMode = (NotificationAreaIconMode) Enum.Parse(
                typeof(NotificationAreaIconMode),
                modeStr
            );

            // initialize status icon for the first time
            if (f_NotificationAreaIconMode != NotificationAreaIconMode.Never &&
                f_StatusIcon == null) {
                f_StatusIcon = new Gtk.StatusIcon();
                f_StatusIcon.Pixbuf = new Gdk.Pixbuf(null, "icon.svg");
                f_StatusIcon.Activate += OnStatusIconActivated;
                f_StatusIcon.PopupMenu += OnStatusIconPopupMenu;
                f_StatusIcon.Tooltip = "Smuxi";
            }
            if (f_NotificationAreaIconMode == NotificationAreaIconMode.Never &&
                !f_MainWindow.Visible) {
                // force window unhide as the user would not be able to bring
                // it back without a notification icon!
                f_MainWindow.Visible = true;
            }

            CheckMainWindowState();
        }
Ejemplo n.º 2
0
        public void ApplyConfig(UserConfig userConfig)
        {
            switch ((string) userConfig["Interface/Notebook/TabPosition"]) {
                case "top":
                    TabPos = Gtk.PositionType.Top;
                    ShowTabs = true;
                    break;
                case "bottom":
                    TabPos = Gtk.PositionType.Bottom;
                    ShowTabs = true;
                    break;
                case "left":
                    TabPos = Gtk.PositionType.Left;
                    ShowTabs = true;
                    break;
                case "right":
                    TabPos = Gtk.PositionType.Right;
                    ShowTabs = true;
                    break;
                case "none":
                    ShowTabs = false;
                    break;
            }

            // TODO: Homogeneous = true;
        }
Ejemplo n.º 3
0
        public override void Load(UserConfig config, string protocol, string id)
        {
            if (config == null) {
                throw new ArgumentNullException("config");
            }
            if (String.IsNullOrEmpty(protocol)) {
                throw new ArgumentNullException("protocol");
            }
            if (String.IsNullOrEmpty(id)) {
                throw new ArgumentNullException("id");
            }
            base.Load(config, protocol, id);

            var obj = config[ConfigKeyPrefix + "PriorityOnline"];
            if (obj != null) {
                Priorities[PresenceStatus.Online] = (int) obj;
            }
            obj = config[ConfigKeyPrefix + "PriorityAway"];
            if (obj != null) {
                Priorities[PresenceStatus.Away] = (int) obj;
            }
            obj = config[ConfigKeyPrefix + "Resource"];
            if (obj != null) {
                Resource = (string) obj;
            }
        }
Ejemplo n.º 4
0
 public override void ApplyConfig(UserConfig config)
 {
     base.ApplyConfig(config);
     if (BackgroundColor.HasValue) _PersonListBox.BackColor = _TopicTextView.BackColor = BackgroundColor.Value;
     if (BackgroundColor.HasValue) _PersonListBox.ForeColor = _TopicTextView.ForeColor = ForegroundColor.Value;
     _PersonListBox.Font = _TopicTextView.Font = Font;
     _PersonListBox.Width = TextRenderer.MeasureText("999999999", Font).Width;
 }
        public MessagePatternListController(UserConfig userConfig)
        {
            if (userConfig == null) {
                throw new ArgumentNullException("userConfig");
            }

            UserConfig = userConfig;
        }
Ejemplo n.º 6
0
        public ServerListController(UserConfig userConfig)
        {
            if (userConfig == null) {
                throw new ArgumentNullException("userConfig");
            }

            _UserConfig = userConfig;
        }
Ejemplo n.º 7
0
        public void ApplyConfig(UserConfig config)
        {
            if (config == null) {
                throw new ArgumentNullException("config");
            }

            var servers = new ServerListController(config);
            InitNetworks(servers.GetNetworks());
        }
Ejemplo n.º 8
0
 public virtual void Load(UserConfig config, string id)
 {
     if (config == null) {
         throw new ArgumentNullException("config");
     }
     if (String.IsNullOrEmpty(id)) {
         throw new ArgumentNullException("id");
     }
     Load(config, Protocol, id);
 }
Ejemplo n.º 9
0
        public void ApplyConfig(UserConfig config)
        {
            if (config == null) {
                throw new ArgumentNullException("config");
            }

            CommandCharacter = (string)
                config["Interface/Entry/CommandCharacter"];
            CompletionCharacter = (string)
                config["Interface/Entry/CompletionCharacter"];
            BashStyleCompletion = (bool)
                config["Interface/Entry/BashStyleCompletion"];
            CommandHistorySize = (int)
                config["Interface/Entry/CommandHistorySize"];
        }
Ejemplo n.º 10
0
        public FilterListWidget(Gtk.Window parent, UserConfig userConfig)
        {
            if (parent == null) {
                throw new ArgumentNullException("parent");
            }
            if (userConfig == null) {
                throw new ArgumentNullException("userConfig");
            }

            Build();
            Init();

            f_Parent = parent;
            f_Controller = new FilterListController(userConfig);
        }
Ejemplo n.º 11
0
        public virtual void Load(UserConfig config, int id)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // don't use ConfigKeyPrefix, so exception guarantees can be kept
            string prefix = "MessagePatterns/" + id + "/";

            if (config[prefix + "MessagePartPattern"] == null)
            {
                // SmartLink does not exist
                throw new ArgumentException("MessagePattern ID not found in config", "id");
            }

            ID = id;
            // now we have a valid ID, ConfigKeyPrefix works
            var messagePartPattern = (string)config[ConfigKeyPrefix + "MessagePartPattern"];

            if (messagePartPattern.StartsWith("/") && messagePartPattern.EndsWith("/i"))
            {
                var regexPattern = messagePartPattern.Substring(1, messagePartPattern.Length - 3);
                MessagePartPattern = new Regex(regexPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            }
            else
            {
                MessagePartPattern = new Regex(messagePartPattern, RegexOptions.Compiled);
            }
            var messagePartType = (string)config[ConfigKeyPrefix + "MessagePartType"];

            switch (messagePartType.ToLower())
            {
            case "url":
                MessagePartType = typeof(UrlMessagePartModel);
                break;

            case "image":
                MessagePartType = typeof(ImageMessagePartModel);
                break;
            }
            LinkFormat = (string)config[ConfigKeyPrefix + "LinkFormat"];
            TextFormat = (string)config[ConfigKeyPrefix + "TextFormat"];
        }
Ejemplo n.º 12
0
        public void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null)
            {
                throw new ArgumentNullException("userConfig");
            }

            NickColors       = (bool)userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors      = (bool)userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool)userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor   = TextColor.Parse(
                (string)userConfig["Interface/Notebook/Tab/HighlightColor"]
                );
            HighlightWords = new List <string>(
                (string[])userConfig["Interface/Chat/HighlightWords"]
                );
            Emojis = (bool)userConfig["Interface/Chat/Emojis"];

            var patternController = new MessagePatternListController(userConfig);
            var userPatterns      = patternController.GetList();
            var builtinPatterns   = BuiltinPatterns;
            var patterns          = new List <MessagePatternModel>(builtinPatterns.Count +
                                                                   userPatterns.Count);

            // No need to lock BuiltinPatterns as List<T> is thread-safe for
            // multiple readers as long as there is no writer at the same time.
            // BuiltinPatterns is only written once before the first instance
            // of MessageBuilderSettings is created via the static initializer.
            patterns.AddRange(builtinPatterns);
            patterns.AddRange(userPatterns);
            if (Emojis)
            {
                // Emoji
                var regex = new Regex(@":(\w+):", RegexOptions.Compiled);
                patterns.Add(new MessagePatternModel(regex)
                {
                    MessagePartType = typeof(ImageMessagePartModel),
                    LinkFormat      = "smuxi-emoji://{1}",
                });
            }
            Patterns     = patterns;
            UserPatterns = userPatterns;
        }
Ejemplo n.º 13
0
 public virtual void Save(UserConfig config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config[ConfigKeyPrefix + "Hostname"]                  = Hostname;
     config[ConfigKeyPrefix + "Port"]                      = Port;
     config[ConfigKeyPrefix + "Network"]                   = Network;
     config[ConfigKeyPrefix + "Nickname"]                  = Nickname;
     config[ConfigKeyPrefix + "Realname"]                  = Realname;
     config[ConfigKeyPrefix + "Username"]                  = Username;
     config[ConfigKeyPrefix + "Password"]                  = Password;
     config[ConfigKeyPrefix + "UseEncryption"]             = UseEncryption;
     config[ConfigKeyPrefix + "ValidateServerCertificate"] =
         ValidateServerCertificate;
     config[ConfigKeyPrefix + "OnStartupConnect"]  = OnStartupConnect;
     config[ConfigKeyPrefix + "OnConnectCommands"] = OnConnectCommands;
 }
Ejemplo n.º 14
0
        public virtual void Load(UserConfig config, string protocol, string id)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (String.IsNullOrEmpty(protocol))
            {
                throw new ArgumentNullException("protocol");
            }
            if (String.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            // don't use ConfigKeyPrefix, so exception guarantees can be kept
            string prefix = "Servers/" + protocol + "/" + id + "/";

            if (config[prefix + "Hostname"] == null)
            {
                // server does not exist
                throw new ArgumentException("ServerID not found in config", id);
            }
            ServerID = id;
            Protocol = protocol;
            // now we have a valid ServerID and Protocol, ConfigKeyPrefix works
            Hostname                  = (string)config[ConfigKeyPrefix + "Hostname"];
            Port                      = (int)config[ConfigKeyPrefix + "Port"];
            Network                   = (string)config[ConfigKeyPrefix + "Network"];
            Nickname                  = (string)config[ConfigKeyPrefix + "Nickname"];
            Realname                  = (string)config[ConfigKeyPrefix + "Realname"];
            Username                  = (string)config[ConfigKeyPrefix + "Username"];
            Password                  = (string)config[ConfigKeyPrefix + "Password"];
            UseEncryption             = (bool)config[ConfigKeyPrefix + "UseEncryption"];
            ValidateServerCertificate =
                (bool)config[ConfigKeyPrefix + "ValidateServerCertificate"];
            ClientCertificateFilename = (string)config[ConfigKeyPrefix + "ClientCertificateFilename"];
            if (config[ConfigKeyPrefix + "OnStartupConnect"] != null)
            {
                OnStartupConnect = (bool)config[ConfigKeyPrefix + "OnStartupConnect"];
            }
            OnConnectCommands = config[ConfigKeyPrefix + "OnConnectCommands"] as IList <string>;
        }
Ejemplo n.º 15
0
 public void ApplyConfig(UserConfig userConfig)
 {
     switch ((string) userConfig["Interface/Notebook/TabPosition"]) {
         case "top":
             Alignment = TabAlignment.Top;
             break;
         case "bottom":
             Alignment = TabAlignment.Bottom;
             break;
         case "left":
             Alignment = TabAlignment.Left;
             break;
         case "right":
             Alignment = TabAlignment.Right;
             break;
         case "none":
             //ShowTabs = false;
             break;
     }
 }
Ejemplo n.º 16
0
        public void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            MessagesSyncCount =
                (int)config["Interface/Notebook/EngineBufferLines"];

            var enumStr = (string)config["MessageBuffer/PersistencyType"];
            MessageBufferPersistencyType persistency;

            try {
                persistency = (MessageBufferPersistencyType)Enum.Parse(
                    typeof(MessageBufferPersistencyType), enumStr, true
                    );
            } catch (ArgumentException ex) {
#if LOG4NET
                _Logger.Error("ApplyConfig(): failed to parse " +
                              "PersistencyType: " + enumStr, ex);
#endif
                persistency = MessageBufferPersistencyType.Volatile;
            }
            InitMessageBuffer(persistency);

            string maxCapacityKey;
            if (persistency == MessageBufferPersistencyType.Volatile)
            {
                maxCapacityKey = "MessageBuffer/Volatile/MaxCapacity";
            }
            else
            {
                maxCapacityKey = "MessageBuffer/Persistent/MaxCapacity";
            }
            MessageBuffer.MaxCapacity = (int)config[maxCapacityKey];
        }
Ejemplo n.º 17
0
        private void ApplyConfig(UserConfig config, ServerModel server)
        {
            if (server.Username.Contains("@"))
            {
                var jid_user = server.Username.Split('@')[0];
                var jid_host = server.Username.Split('@')[1];
                _JabberClient.NetworkHost = server.Hostname;
                _JabberClient.User        = jid_user;
                _JabberClient.Server      = jid_host;
            }
            else
            {
                _JabberClient.Server = server.Hostname;
                _JabberClient.User   = server.Username;
            }
            _JabberClient.Port     = server.Port;
            _JabberClient.Password = server.Password;

            // XMPP specific settings
            if (server is XmppServerModel)
            {
                var xmppServer = (XmppServerModel)server;
                _JabberClient.Resource = xmppServer.Resource;
            }

            // fallback
            if (String.IsNullOrEmpty(_JabberClient.Resource))
            {
                _JabberClient.Resource = "smuxi";
            }

            _JabberClient.OnInvalidCertificate -= ValidateCertificate;

            _JabberClient.AutoStartTLS = server.UseEncryption;
            if (!server.ValidateServerCertificate)
            {
                _JabberClient.OnInvalidCertificate += ValidateCertificate;
            }
        }
Ejemplo n.º 18
0
        public void Remove(int key)
        {
            Trace.Call(key);

            string section = "MessagePatterns/" + key + "/";

            string[] keys = PatternIDs;
            if (keys == null)
            {
                keys = new string[] {};
            }
            var keyList = new List <string>(keys);
            int idx     = keyList.IndexOf(key.ToString());

            if (idx == -1)
            {
                // key not found
                return;
            }
            keyList.RemoveAt(idx);
            UserConfig.Remove(section);
            PatternIDs = keyList.ToArray();
        }
Ejemplo n.º 19
0
        public void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null)
            {
                throw new ArgumentNullException("userConfig");
            }

            NickColors       = (bool)userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors      = (bool)userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool)userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor   = TextColor.Parse(
                (string)userConfig["Interface/Notebook/Tab/HighlightColor"]
                );
            HighlightWords = new List <string>(
                (string[])userConfig["Interface/Chat/HighlightWords"]
                );

            var patternController = new MessagePatternListController(userConfig);
            var userPatterns      = patternController.GetList();
            var builtinPatterns   = BuiltinPatterns;
            var patterns          = new List <MessagePatternModel>(builtinPatterns.Count +
                                                                   userPatterns.Count);

            // No need to lock BuiltinPatterns as List<T> is thread-safe for
            // multiple readers as long as there is no writer at the same time.
            // BuiltinPatterns is only written once before the first instance
            // of MessageBuilderSettings is created via the static initializer.
            patterns.AddRange(builtinPatterns);
            patterns.AddRange(userPatterns);
            Patterns     = patterns;
            UserPatterns = userPatterns;

            // The Patterns property has to be initialized before we set the
            // Emojis property as it will modify the existing Patterns collection
            Emojis = (bool)userConfig["Interface/Chat/Emojis"];
        }
Ejemplo n.º 20
0
        public virtual void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            var theme = new ThemeSettings(config);
            if (theme.BackgroundColor == null) {
                ModifyBase(Gtk.StateType.Normal);
            } else {
                ModifyBase(Gtk.StateType.Normal, theme.BackgroundColor.Value);
            }
            if (theme.ForegroundColor == null) {
                ModifyText(Gtk.StateType.Normal);
            } else {
                ModifyText(Gtk.StateType.Normal, theme.ForegroundColor.Value);
            }
            ModifyFont(theme.FontDescription);

            Settings.ApplyConfig(config);

            // replace nick completer if needed
            if (Settings.BashStyleCompletion && !(NickCompleter is LongestPrefixNickCompleter)) {
                NickCompleter = new LongestPrefixNickCompleter();
            } else if (!Settings.BashStyleCompletion && !(NickCompleter is TabCycleNickCompleter)) {
                NickCompleter = new TabCycleNickCompleter();
            }

            // set the completion character
            NickCompleter.CompletionChar = Settings.CompletionCharacter;
        }
Ejemplo n.º 21
0
        public void ApplyConfig(UserConfig config)
        {
            _ThemeSettings = new ThemeSettings(config);
            if (_ThemeSettings.BackgroundColor == null) {
                ModifyBase(Gtk.StateType.Normal);
            } else {
                ModifyBase(Gtk.StateType.Normal, _ThemeSettings.BackgroundColor.Value);
            }
            if (_ThemeSettings.ForegroundColor == null) {
                ModifyText(Gtk.StateType.Normal);
            } else {
                ModifyText(Gtk.StateType.Normal, _ThemeSettings.ForegroundColor.Value);
            }
            ModifyFont(_ThemeSettings.FontDescription);

            string wrapModeStr = (string) config["Interface/Chat/WrapMode"];
            if (!String.IsNullOrEmpty(wrapModeStr)) {
                Gtk.WrapMode wrapMode = (Gtk.WrapMode) Enum.Parse(
                    typeof(Gtk.WrapMode),
                    wrapModeStr
                );
                if (wrapMode == Gtk.WrapMode.Word) {
                    wrapMode = Gtk.WrapMode.WordChar;
                }
                WrapMode = wrapMode;
            }

            _BufferLines = (int) config["Interface/Notebook/BufferLines"];
        }
Ejemplo n.º 22
0
        public ThemeSettings(UserConfig config)
        {
            if (config == null) {
                throw new ArgumentNullException("config");
            }

            string bgStr = (string) config["Interface/Chat/BackgroundColor"];
            if (!String.IsNullOrEmpty(bgStr)) {
                Gdk.Color bgColor = Gdk.Color.Zero;
                if (Gdk.Color.Parse(bgStr, ref bgColor)) {
                    f_BackgroundColor = bgColor;
                }
            } else {
                f_BackgroundColor = null;
            }

            string fgStr = (string) config["Interface/Chat/ForegroundColor"];
            if (!String.IsNullOrEmpty(fgStr)) {
                Gdk.Color fgColor = Gdk.Color.Zero;
                if (Gdk.Color.Parse(fgStr, ref fgColor)) {
                    f_ForegroundColor = fgColor;
                }
            } else {
                f_ForegroundColor = null;
            }

            string colorStr;
            Gdk.Color color;
            colorStr = (string) config["Interface/Notebook/Tab/HighlightColor"];
            color = Gdk.Color.Zero;
            if (Gdk.Color.Parse(colorStr, ref color)) {
                f_HighlightColor = color;
            }

            colorStr = (string) config["Interface/Notebook/Tab/ActivityColor"];
            color = Gdk.Color.Zero;
            if (Gdk.Color.Parse(colorStr, ref color)) {
                f_ActivityColor = color;
            }

            colorStr = (string) config["Interface/Notebook/Tab/NoActivityColor"];
            color = Gdk.Color.Zero;
            if (Gdk.Color.Parse(colorStr, ref color)) {
                f_NoActivityColor = color;
            }

            colorStr = (string) config["Interface/Notebook/Tab/EventColor"];
            color = Gdk.Color.Zero;
            if (Gdk.Color.Parse(colorStr, ref color)) {
                f_EventColor = color;
            }

            string fontFamily = (string) config["Interface/Chat/FontFamily"];
            string fontStyle = (string) config["Interface/Chat/FontStyle"];
            int fontSize = 0;
            if (config["Interface/Chat/FontSize"] != null) {
                fontSize = (int) config["Interface/Chat/FontSize"];
            }
            Pango.FontDescription fontDescription = new Pango.FontDescription();
            if (String.IsNullOrEmpty(fontFamily)) {
                // HACK: use fixed-sys by default if present
                if (File.Exists("Fixedsys500c.ttf")) {
                    fontDescription.Family = "FixedsysTTF, monospace";
                    // fixed-sys only looks good in size 11
                    fontDescription.Size = 11 * 1024;
                    fontDescription.Weight = Pango.Weight.Bold;
                    fontDescription.Style = Pango.Style.Normal;
                } else {
                    // use Monospace and Bold by default
                    fontDescription.Family = "monospace";
                    // black bold font on white background looks odd
                    //fontDescription.Weight = Pango.Weight.Bold;
                }
            } else {
                fontDescription.Family = fontFamily;
                string frontWeigth = null;
                if (fontStyle.Contains(" ")) {
                    int pos = fontStyle.IndexOf(" ");
                    frontWeigth = fontStyle.Substring(0, pos);
                    fontStyle = fontStyle.Substring(pos + 1);
                }
                fontDescription.Style = (Pango.Style) Enum.Parse(typeof(Pango.Style), fontStyle);
                if (frontWeigth != null) {
                    fontDescription.Weight = (Pango.Weight) Enum.Parse(typeof(Pango.Weight), frontWeigth);
                }
                fontDescription.Size = fontSize * 1024;
            }
            f_FontDescription = fontDescription;
        }
Ejemplo n.º 23
0
        public void Save()
        {
            Trace.Call();

            UserConfig.Save();
        }
Ejemplo n.º 24
0
        public virtual void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null) {
                throw new ArgumentNullException("userConfig");
            }

            NickColors = (bool) userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors = (bool) userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool) userConfig["Interface/Notebook/StripFormattings"];
        }
Ejemplo n.º 25
0
        public static void ApplyConfig(UserConfig userConfig)
        {
            Trace.Call(userConfig);

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

            _MainWindow.ApplyConfig(userConfig);
        }
Ejemplo n.º 26
0
        public virtual void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            _ThemeSettings = new ThemeSettings(config);

            _OutputMessageTextView.ApplyConfig(config);
        }
Ejemplo n.º 27
0
        private void ApplyConfig(UserConfig config, XmppServerModel server)
        {
            if (server.Username.Contains("@")) {
                var jid_user = server.Username.Split('@')[0];
                var jid_host = server.Username.Split('@')[1];
                JabberClient.NetworkHost = server.Hostname;
                JabberClient.User = jid_user;
                JabberClient.Server = jid_host;
            } else {
                JabberClient.Server = server.Hostname;
                JabberClient.User = server.Username;
            }
            JabberClient.Port = server.Port;
            JabberClient.Password = server.Password;

            Me = CreatePerson(
                String.Format("{0}@{1}",
                    JabberClient.User,
                    JabberClient.Server
                ),
                JabberClient.User
            );
            Me.IdentityNameColored.ForegroundColor = new TextColor(0, 0, 255);
            Me.IdentityNameColored.BackgroundColor = TextColor.None;
            Me.IdentityNameColored.Bold = true;

            // XMPP specific settings
            JabberClient.Resource = server.Resource;

            JabberClient.OnInvalidCertificate -= ValidateCertificate;

            JabberClient.AutoStartTLS = server.UseEncryption;
            if (!server.ValidateServerCertificate) {
                JabberClient.OnInvalidCertificate += ValidateCertificate;
            }

            var proxySettings = new ProxySettings();
            proxySettings.ApplyConfig(Session.UserConfig);
            var protocol = server.UseEncryption ? "xmpps" : "xmpp";
            var serverUri = String.Format("{0}://{1}:{2}", protocol,
                                          server.Hostname, server.Port);
            var proxy = proxySettings.GetWebProxy(serverUri);
            if (proxy == null) {
                JabberClient.Proxy = XmppProxyType.None;
            } else {
                var proxyScheme = proxy.Address.Scheme;
                var xmppProxyType = XmppProxyType.None;
                try {
                    // HACK: map proxy scheme to SmartIrc4net's ProxyType
                    xmppProxyType = (XmppProxyType) Enum.Parse(
                        typeof(XmppProxyType), proxyScheme, true
                    );
                } catch (ArgumentException ex) {
            #if LOG4NET
                    _Logger.Error("ApplyConfig(): Couldn't parse proxy type: " +
                                  proxyScheme, ex);
            #endif
                }
                JabberClient.Proxy = xmppProxyType;
                JabberClient.ProxyHost = proxy.Address.Host;
                JabberClient.ProxyPort = proxy.Address.Port;
                JabberClient.ProxyUsername = proxySettings.ProxyUsername;
                JabberClient.ProxyPassword = proxySettings.ProxyPassword;
            }
        }
Ejemplo n.º 28
0
        public void ApplyConfig(UserConfig config)
        {
            _ThemeSettings = new ThemeSettings(config);
            if (_ThemeSettings.BackgroundColor == null) {
                ModifyBase(Gtk.StateType.Normal);
            } else {
                ModifyBase(Gtk.StateType.Normal, _ThemeSettings.BackgroundColor.Value);
            }
            if (_ThemeSettings.ForegroundColor == null) {
                ModifyText(Gtk.StateType.Normal);
            } else {
                ModifyText(Gtk.StateType.Normal, _ThemeSettings.ForegroundColor.Value);
            }
            ModifyFont(_ThemeSettings.FontDescription);

            string wrapModeStr = (string) config["Interface/Chat/WrapMode"];
            if (!String.IsNullOrEmpty(wrapModeStr)) {
                Gtk.WrapMode wrapMode = (Gtk.WrapMode) Enum.Parse(
                    typeof(Gtk.WrapMode),
                    wrapModeStr
                );
                if (wrapMode == Gtk.WrapMode.Word) {
                    wrapMode = Gtk.WrapMode.WordChar;
                }
                WrapMode = wrapMode;
            }

            _BufferLines = (int) config["Interface/Notebook/BufferLines"];

            #if LOG4NET
            DateTime start = DateTime.UtcNow;
            #endif

            ResizeEmoji();

            #if LOG4NET
            DateTime stop = DateTime.UtcNow;
            double duration = stop.Subtract(start).TotalMilliseconds;
            _Logger.Debug("ApplyConfig(): ResizeEmoji()" +
                " done, took: " + Math.Round(duration) + " ms");
            #endif
        }
Ejemplo n.º 29
0
        public void Clear()
        {
            Trace.Call();

            f_Config = null;
            f_Chats.Clear();
            f_Notebook.RemoveAllPages();
            SyncedChats.Clear();
            SyncManager.Clear();
        }
Ejemplo n.º 30
0
        public virtual void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            var prefix = "Interface/Notebook/";
            AutoSwitchPersonChats =
                config[prefix + "AutoSwitchPersonChats"] as bool? ?? false;
            AutoSwitchGroupChats =
                config[prefix + "AutoSwitchGroupChats"] as bool? ?? true;

            f_Config = config;
            foreach (ChatView chat in f_Chats) {
                chat.ApplyConfig(f_Config);
            }
        }
Ejemplo n.º 31
0
        public static void Init()
        {
            if (_IsInitialized)
            {
                return;
            }
            _IsInitialized = true;

            var asm = Assembly.GetEntryAssembly();

            if (asm == null)
            {
                asm = Assembly.GetAssembly(typeof(Engine));
            }
            var asm_name = asm.GetName(false);

            var distVersion = Defines.DistVersion;

            if (!String.IsNullOrEmpty(distVersion))
            {
                distVersion = String.Format(" ({0})", distVersion);
            }
            _VersionString = String.Format(
                "{0} {1}{2} - running on {3} {4}",
                Path.GetFileNameWithoutExtension(asm_name.Name),
                AssemblyVersion,
                distVersion,
                Platform.OperatingSystem,
                Platform.Architecture
                );

            _Config = new Config();
            _Config.Load();

            // migration config settins from 1.0 or earlier to 1.1
            if (_Config.PreviousVersion == null ||
                _Config.PreviousVersion < new Version(1, 1))
            {
                // migrate all existing IRC connections for Slack to the
                // SlackProtocolManager
                var users = (string[])_Config["Engine/Users/Users"];
                if (users != null)
                {
                    foreach (var user in users)
                    {
                        var userConfig       = new UserConfig(_Config, user);
                        var serverController = new ServerListController(userConfig);
                        var servers          = serverController.GetServerList();
                        foreach (var server in servers)
                        {
                            if (server.Protocol != "IRC")
                            {
                                continue;
                            }
                            if (!server.Hostname.EndsWith(".irc.slack.com"))
                            {
                                continue;
                            }
#if LOG4NET
                            f_Logger.InfoFormat(
                                "Migrating Slack server '{0}' of user '{1}' " +
                                "from IRC to Slack protocol manager",
                                server,
                                user
                                );
#endif
                            // this is Slack IRC bridge connection
                            var migratedServer = new ServerModel(server);
                            migratedServer.ServerID = null;
                            migratedServer.Protocol = "Slack";
                            serverController.AddServer(migratedServer);
                            // remove old Slack server with IRC as protocol
                            serverController.RemoveServer(server.Protocol,
                                                          server.ServerID);
                        }
                    }
                }
                _Config["Engine/ConfigVersion"] = _Config.CurrentVersion.ToString();
            }

            _Config.Save();

            string location = Path.GetDirectoryName(asm.Location);
            if (String.IsNullOrEmpty(location) &&
                Environment.OSVersion.Platform == PlatformID.Unix)
            {
                // we are mkbundled
                var locationBuilder = new StringBuilder(8192);
                if (Mono.Unix.Native.Syscall.readlink("/proc/self/exe", locationBuilder) >= 0)
                {
                    location = Path.GetDirectoryName(locationBuilder.ToString());
                }
            }
            _ProtocolManagerFactory = new ProtocolManagerFactory();
            _ProtocolManagerFactory.LoadAllProtocolManagers(location);
        }
Ejemplo n.º 32
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;
                }
            });
        }
Ejemplo n.º 33
0
 public virtual void Load(UserConfig config, string protocol, string id)
 {
     if (config == null) {
         throw new ArgumentNullException("config");
     }
     if (String.IsNullOrEmpty(protocol)) {
         throw new ArgumentNullException("protocol");
     }
     if (String.IsNullOrEmpty(id)) {
         throw new ArgumentNullException("id");
     }
     // don't use ConfigKeyPrefix, so exception guarantees can be kept
     string prefix = "Servers/" + protocol + "/" + id + "/";
     if (config[prefix + "Hostname"] == null) {
         // server does not exist
         throw new ArgumentException("ServerID not found in config", id);
     }
     ServerID    = id;
     Protocol    = protocol;
     // now we have a valid ServerID and Protocol, ConfigKeyPrefix works
     Hostname    = (string) config[ConfigKeyPrefix + "Hostname"];
     Port        = (int)    config[ConfigKeyPrefix + "Port"];
     Network     = (string) config[ConfigKeyPrefix + "Network"];
     Username    = (string) config[ConfigKeyPrefix + "Username"];
     Password    = (string) config[ConfigKeyPrefix + "Password"];
     UseEncryption = (bool) config[ConfigKeyPrefix + "UseEncryption"];
     ValidateServerCertificate =
         (bool) config[ConfigKeyPrefix + "ValidateServerCertificate"];
     if (config[ConfigKeyPrefix + "OnStartupConnect"] != null) {
         OnStartupConnect = (bool) config[ConfigKeyPrefix + "OnStartupConnect"];
     }
     OnConnectCommands  = config[ConfigKeyPrefix + "OnConnectCommands"] as IList<string>;
 }
Ejemplo n.º 34
0
 public virtual void Save(UserConfig config)
 {
     if (config == null) {
         throw new ArgumentNullException("config");
     }
     config[ConfigKeyPrefix + "Hostname"] = Hostname;
     config[ConfigKeyPrefix + "Port"]     = Port;
     config[ConfigKeyPrefix + "Network"]  = Network;
     config[ConfigKeyPrefix + "Username"] = Username;
     config[ConfigKeyPrefix + "Password"] = Password;
     config[ConfigKeyPrefix + "UseEncryption"] = UseEncryption;
     config[ConfigKeyPrefix + "ValidateServerCertificate"] =
         ValidateServerCertificate;
     config[ConfigKeyPrefix + "OnStartupConnect"] = OnStartupConnect;
     config[ConfigKeyPrefix + "OnConnectCommands"] = OnConnectCommands;
 }
Ejemplo n.º 35
0
        public void ApplyConfig(UserConfig userConfig)
        {
            if (userConfig == null) {
                throw new ArgumentNullException("userConfig");
            }

            NickColors = (bool) userConfig["Interface/Notebook/Channel/NickColors"];
            StripColors = (bool) userConfig["Interface/Notebook/StripColors"];
            StripFormattings = (bool) userConfig["Interface/Notebook/StripFormattings"];
            HighlightColor = TextColor.Parse(
                (string) userConfig["Interface/Notebook/Tab/HighlightColor"]
            );
            HighlightWords = new List<string>(
                (string[]) userConfig["Interface/Chat/HighlightWords"]
            );

            var patternController = new MessagePatternListController(userConfig);
            var userPatterns = patternController.GetList();
            var builtinPatterns = BuiltinPatterns;
            var patterns = new List<MessagePatternModel>(builtinPatterns.Count +
                                                         userPatterns.Count);
            // No need to lock BuiltinPatterns as List<T> is thread-safe for
            // multiple readers as long as there is no writer at the same time.
            // BuiltinPatterns is only written once before the first instance
            // of MessageBuilderSettings is created via the static initializer.
            patterns.AddRange(builtinPatterns);
            patterns.AddRange(userPatterns);
            Patterns = patterns;
            UserPatterns = userPatterns;
        }
Ejemplo n.º 36
0
 public static void InitLocalEngine()
 {
     Engine.Engine.Init();
     _EngineVersion = Engine.Engine.Version;
     _Session = new Engine.Session(Engine.Engine.Config,
                                   Engine.Engine.ProtocolManagerFactory,
                                   "local");
     _Session.RegisterFrontendUI(_MainWindow.UI);
     _UserConfig = _Session.UserConfig;
     ConnectEngineToGUI();
 }
Ejemplo n.º 37
0
        public override void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            base.ApplyConfig(config);

            // topic
            _TopicTextView.ApplyConfig(config);
            string topic_pos = (string) config["Interface/Notebook/Channel/TopicPosition"];
            if (_TopicScrolledWindow.IsAncestor(_OutputVBox)) {
                _OutputVBox.Remove(_TopicScrolledWindow);
            }
            if (OutputScrolledWindow.IsAncestor(_OutputVBox)) {
                _OutputVBox.Remove(OutputScrolledWindow);
            }
            if (topic_pos == "top") {
                _OutputVBox.PackStart(_TopicScrolledWindow, false, false, 0);
                _OutputVBox.PackStart(OutputScrolledWindow, true, true, 0);
            } else if  (topic_pos == "bottom") {
                _OutputVBox.PackStart(OutputScrolledWindow, true, true, 0);
                _OutputVBox.PackStart(_TopicScrolledWindow, false, false, 0);
            } else if (topic_pos == "none") {
                _OutputVBox.PackStart(OutputScrolledWindow, true, true, 0);
            } else {
            #if LOG4NET
                _Logger.Error("ApplyConfig(): unsupported value in Interface/Notebook/Channel/TopicPosition: " + topic_pos);
            #endif
            }
            _OutputVBox.ShowAll();

            // person list
            if (ThemeSettings.BackgroundColor == null) {
                _PersonTreeView.ModifyBase(Gtk.StateType.Normal);
            } else {
                _PersonTreeView.ModifyBase(Gtk.StateType.Normal, ThemeSettings.BackgroundColor.Value);
            }
            if (ThemeSettings.ForegroundColor == null) {
                _PersonTreeView.ModifyText(Gtk.StateType.Normal);
            } else {
                _PersonTreeView.ModifyText(Gtk.StateType.Normal, ThemeSettings.ForegroundColor.Value);
            }
            _PersonTreeView.ModifyFont(ThemeSettings.FontDescription);

            string userlist_pos = (string) config["Interface/Notebook/Channel/UserListPosition"];
            if (userlist_pos == "left") {
                userlist_pos = "right";
            }
            if (_PersonTreeViewFrame.IsAncestor(_OutputHPaned)) {
                _OutputHPaned.Remove(_PersonTreeViewFrame);
            }
            if (_OutputVBox.IsAncestor(_OutputHPaned)) {
                _OutputHPaned.Remove(_OutputVBox);
            }
            if (userlist_pos == "left") {
                _OutputHPaned.Pack1(_PersonTreeViewFrame, false, true);
                _OutputHPaned.Pack2(_OutputVBox, true, true);
            } else if (userlist_pos == "right") {
                _OutputHPaned.Pack1(_OutputVBox, true, false);
                _OutputHPaned.Pack2(_PersonTreeViewFrame, false, false);
            } else if (userlist_pos == "none") {
                _OutputHPaned.Pack1(_OutputVBox, true, true);
            } else {
            #if LOG4NET
                _Logger.Error("ApplyConfig(): unsupported value in Interface/Notebook/Channel/UserListPosition: " + userlist_pos);
            #endif
            }
            _OutputHPaned.ShowAll();

            NickColors = (bool) config["Interface/Notebook/Channel/NickColors"];
        }
Ejemplo n.º 38
0
 public static void InitLocalEngine()
 {
     if (!Engine.Engine.IsInitialized) {
         // only initialize a local engine once
         Engine.Engine.Init();
         _LocalSession = new Engine.Session(Engine.Engine.Config,
                                            Engine.Engine.ProtocolManagerFactory,
                                            "local");
         _LocalSession.ExecuteOnStartupCommands();
         _LocalSession.ProcessAutoConnect();
     }
     EngineAssemblyVersion = Engine.Engine.AssemblyVersion;
     EngineProtocolVersion = Engine.Engine.ProtocolVersion;
     Session = _LocalSession;
     _UserConfig = _Session.UserConfig;
 }
Ejemplo n.º 39
0
        public void ApplyConfig(UserConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            var proxyType = (string)config["Connection/ProxyType"];

            ProxyType     = (ProxyType)Enum.Parse(typeof(ProxyType), proxyType, true);
            ProxyHostname = (string)config["Connection/ProxyHostname"];
            ProxyPort     = (int)config["Connection/ProxyPort"];
            ProxyUsername = (string)config["Connection/ProxyUsername"];
            ProxyPassword = (string)config["Connection/ProxyPassword"];

            switch (ProxyType)
            {
            case ProxyType.None:
                DefaultWebProxy = null;
                SystemWebProxy  = null;
                break;

            case ProxyType.System:
                // TODO: add GNOME (gconf) support
                var no_proxy = Environment.GetEnvironmentVariable("no_proxy");
                var proxy    = WebRequest.GetSystemWebProxy();
                if (!String.IsNullOrEmpty(no_proxy) && proxy is WebProxy)
                {
                    var webProxy = (WebProxy)proxy;
                    // BypassArrayList expects regexes while no_proxy
                    // contains domains
                    var bypassUriRegexes = new List <string>();
                    foreach (var domain in no_proxy.Split(','))
                    {
                        string domainRegex = null;
                        if (domain.StartsWith("."))
                        {
                            domainRegex = String.Format(
                                @"^[a-z]+://(.+\.)?{0}",
                                Regex.Escape(domain.Substring(1))
                                );
                        }
                        else if (!Regex.IsMatch(domain, @"^[a-z]+://"))
                        {
                            domainRegex = String.Format(
                                @"^[a-z]+://{0}",
                                Regex.Escape(domain)
                                );
                        }
                        else
                        {
                            domainRegex = Regex.Escape(domain);
                        }
                        bypassUriRegexes.Add(domainRegex);
                    }
                    webProxy.BypassArrayList.AddRange(bypassUriRegexes);
                }
                DefaultWebProxy = null;
                SystemWebProxy  = proxy;
                break;

            default:
                var uriBuilder = new UriBuilder();
                uriBuilder.Scheme   = ProxyType.ToString().ToLower();
                uriBuilder.Host     = ProxyHostname;
                uriBuilder.Port     = ProxyPort;
                uriBuilder.UserName = ProxyUsername;
                uriBuilder.Password = ProxyPassword;
                var proxyUri = uriBuilder.ToString();
                DefaultWebProxy = new WebProxy(proxyUri);
                SystemWebProxy  = null;
                break;
            }
        }
Ejemplo n.º 40
0
        public override void ApplyConfig(UserConfig config)
        {
            Trace.Call(config);

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

            base.ApplyConfig(config);

            ProxySettings.ApplyConfig(config);
        }
Ejemplo n.º 41
0
        public void Connect(string engine)
        {
            Trace.Call(engine);

            if (engine == null) {
                throw new ArgumentNullException("engine");
            }
            if (engine.Length == 0) {
                throw new ArgumentException(_("Engine must not be empty."), "engine");
            }

            bool engineFound = false;
            foreach (var entry in (string[]) f_FrontendConfig["Engines/Engines"]) {
                if (entry == engine) {
                    engineFound = true;
                    break;
                }
            }
            if (!engineFound) {
                throw new ArgumentException(_("Engine does not exist."), "engine");
            }

            f_Engine = engine;
            string username = (string) f_FrontendConfig["Engines/"+engine+"/Username"];
            string password = (string) f_FrontendConfig["Engines/"+engine+"/Password"];
            string hostname = (string) f_FrontendConfig["Engines/"+engine+"/Hostname"];
            string bindAddress = (string) f_FrontendConfig["Engines/"+engine+"/BindAddress"];
            int port = (int) f_FrontendConfig["Engines/"+engine+"/Port"];
            //string formatter = (string) _FrontendConfig["Engines/"+engine+"/Formatter"];
            string channel = (string) f_FrontendConfig["Engines/"+engine+"/Channel"];

            // SSH tunnel support
            bool useSshTunnel = false;
            if (f_FrontendConfig["Engines/"+engine+"/UseSshTunnel"] != null) {
                useSshTunnel = (bool) f_FrontendConfig["Engines/"+engine+"/UseSshTunnel"];
            }
            string sshProgram = (string) f_FrontendConfig["Engines/"+engine+"/SshProgram"];
            string sshParameters = (string) f_FrontendConfig["Engines/"+engine+"/SshParameters"];
            string sshHostname = (string) f_FrontendConfig["Engines/"+engine+"/SshHostname"];
            int sshPort = -1;
            if (f_FrontendConfig["Engines/"+engine+"/SshPort"] != null) {
                sshPort = (int) f_FrontendConfig["Engines/"+engine+"/SshPort"];
            }
            string sshUsername = (string) f_FrontendConfig["Engines/"+engine+"/SshUsername"];
            string sshPassword = (string) f_FrontendConfig["Engines/"+engine+"/SshPassword"];
            var sshKeyfile = (string) f_FrontendConfig["Engines/"+engine+"/SshKeyfile"];

            // OPT: always use SSH compression (both openssh and plink support it)
            // this reduces the .NET remoting traffic by about 75%
            if (String.IsNullOrEmpty(sshParameters) ||
                !sshParameters.Contains(" -C")) {
                sshParameters += " -C";
            }

            int remotingPort = 0;
            if (useSshTunnel) {
                // find free remoting back-channel port
                TcpListener remotingPortListener = new TcpListener(IPAddress.Loopback, 0);
                remotingPortListener.Start();
                remotingPort = ((IPEndPoint)remotingPortListener.LocalEndpoint).Port;

                // find free local forward port
                TcpListener localForwardListener = new TcpListener(IPAddress.Loopback, 0);
                localForwardListener.Start();
                int localForwardPort = ((IPEndPoint)localForwardListener.LocalEndpoint).Port;

                // only stop the listeners after we got all ports we need
                // else it might re-use a port!
                remotingPortListener.Stop();
                localForwardListener.Stop();
            #if LOG4NET
                f_Logger.Debug("Connect(): found free local backward port (for remoting back-channel): " + remotingPort);
                f_Logger.Debug("Connect(): found free local forward port: " + localForwardPort);
            #endif

                // HACK: we can't use localForwardPort here as .NET remoting
                // will announce the server port in the server Session object
                // thus the client will try to reach it using the original
                // server port :(
                f_SshTunnelManager = new SshTunnelManager(
                    sshProgram, sshParameters, sshUsername, sshPassword,
                    sshKeyfile, sshHostname, sshPort,
                    //"127.0.0.1", localForwardPort, "127.0.0.1", port,
                    "127.0.0.1", port, "127.0.0.1", port,
                    "127.0.0.1", remotingPort, "127.0.0.1", remotingPort
                );
                f_SshTunnelManager.Setup();
                f_SshTunnelManager.Connect();

                // so we want to connect via the SSH tunnel now
                hostname = "127.0.0.1";
                // HACK: see above
                //port = localForwardPort;

                // the smuxi-server has to connect to us via the SSH tunnel too
                bindAddress = "127.0.0.1";
            }

            IDictionary props = new Hashtable();
            // ugly remoting expects the port as string ;)
            props["port"] = remotingPort.ToString();
            string connection_url = null;
            SessionManager sessm = null;
            switch (channel) {
                case "TCP":
                    // Make sure the channel is really using our random
                    // remotingPort. Already registered channel will for sure
                    // not to that and thus the back-connection fails!
                    if (f_ChannelName != null) {
                        IChannel oldChannel = ChannelServices.GetChannel(f_ChannelName);
                        if (oldChannel != null) {
            #if LOG4NET
                            f_Logger.Debug("Connect(): found old remoting channel, unregistering...");
            #endif
                            ChannelServices.UnregisterChannel(oldChannel);
                        }
                    }

                    // frontend -> engine
                    BinaryClientFormatterSinkProvider cprovider =
                        new BinaryClientFormatterSinkProvider();

                    // engine -> frontend (back-connection)
                    BinaryServerFormatterSinkProvider sprovider =
                        new BinaryServerFormatterSinkProvider();
                    // required for MS .NET 1.1
                    sprovider.TypeFilterLevel = TypeFilterLevel.Full;

                    if (bindAddress != null) {
                        props["machineName"] = bindAddress;
                    }
                    var tcpChannel = new TcpChannel(props, cprovider, sprovider);
                    f_ChannelName = tcpChannel.ChannelName;
                    ChannelServices.RegisterChannel(tcpChannel, false);

                    // make sure the listen port of channel is ready before we
                    // connect to the engine, as it will make a call back!
                    while (true) {
                        using (TcpClient tcpClient = new TcpClient()) {
                            try {
                                tcpClient.Connect(hostname, port);
            #if LOG4NET
                                f_Logger.Debug("Connect(): listen port of remoting channel is ready");
            #endif
                                break;
                            } catch (SocketException ex) {
            #if LOG4NET
                                f_Logger.Debug("Connect(): listen port of remoting channel is not reading yet, retrying...", ex);
            #endif
                            }
                            System.Threading.Thread.Sleep(1000);
                        }
                    }

                    connection_url = "tcp://"+hostname+":"+port+"/SessionManager";
            #if LOG4NET
                    f_Logger.Info("Connecting to: "+connection_url);
            #endif
                    sessm = (SessionManager)Activator.GetObject(typeof(SessionManager),
                        connection_url);
                    break;
            #if CHANNEL_TCPEX
                case "TcpEx":
                    //props.Remove("port");
                    //props["name"] = "tcpex";
                    connection_url = "tcpex://"+hostname+":"+port+"/SessionManager";
                    if (ChannelServices.GetChannel("ExtendedTcp") == null) {
                        ChannelServices.RegisterChannel(new TcpExChannel(props, null, null));
                    }
            #if LOG4NET
                    _Logger.Info("Connecting to: "+connection_url);
            #endif
                    sessm = (SessionManager)Activator.GetObject(typeof(SessionManager),
                        connection_url);
                    break;
            #endif
            #if CHANNEL_BIRDIRTCP
                case "BirDirTcp":
                    string ip = System.Net.Dns.Resolve(hostname).AddressList[0].ToString();
                    connection_url = "birdirtcp://"+ip+":"+port+"/SessionManager";
                    if (ChannelServices.GetChannel("birdirtcp") == null) {
                        ChannelServices.RegisterChannel(new BidirTcpClientChannel());
                    }
            #if LOG4NET
                    _Logger.Info("Connecting to: "+connection_url);
            #endif
                    sessm = (SessionManager)Activator.GetObject(typeof(SessionManager),
                        connection_url);
                    break;
            #endif
                case "HTTP":
                    connection_url = "http://"+hostname+":"+port+"/SessionManager";
                    if (ChannelServices.GetChannel("http") == null) {
                        ChannelServices.RegisterChannel(new HttpChannel(), false);
                    }
            #if LOG4NET
                    f_Logger.Info("Connecting to: "+connection_url);
            #endif
                    sessm = (SessionManager)Activator.GetObject(typeof(SessionManager),
                        connection_url);
                    break;
                default:
                    throw new ApplicationException(String.Format(
                                    _("Unknown channel ({0}) - "+
                                      "only the following channel types are supported:"),
                                    channel) + " HTTP TCP");
            }
            f_SessionManager = sessm;
            f_EngineUrl = connection_url;

            f_Session = sessm.Register(username, MD5.FromString(password), f_FrontendUI);
            if (f_Session == null) {
                throw new ApplicationException(_("Registration with engine failed!  "+
                               "The username and/or password were wrong - please verify them."));
            }

            f_EngineVersion = sessm.EngineVersion;
            f_UserConfig = new UserConfig(f_Session.Config,
                                         username);
            f_UserConfig.IsCaching = true;
            f_UserConfig.FrontendConfig = f_FrontendConfig;
        }