Пример #1
0
        /// <summary>
        /// Change Apsim's default font, and apply the new font to all existing
        /// widgets.
        /// </summary>
        /// <param name="font">The new default font.</param>
        private void ChangeFont(Pango.FontDescription font)
        {
            SetWidgetFont(mainWidget, font);
#if NETFRAMEWORK
            Settings.Default.SetStringProperty($"gtk-font-name", font.ToString(), "");
#endif
            //Rc.ParseString($"gtk-font-name = \"{font}\"");
        }
Пример #2
0
 /// <summary>
 /// Invoked when the user clicks OK or Apply in the font selection
 /// dialog. Changes the font on all widgets and saves the new font
 /// in the config file.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void OnChangeFont(object sender, EventArgs args)
 {
     try
     {
         Pango.FontDescription newFont = Pango.FontDescription.FromString(fontDialog.FontName);
         Utility.Configuration.Settings.FontName = newFont.ToString();
         ChangeFont(newFont);
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
Пример #3
0
 /// <summary>
 /// Invoked when the user clicks OK or Apply in the font selection
 /// dialog. Changes the font on all widgets and saves the new font
 /// in the config file.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event arguments.</param>
 private void OnFontSelected(object sender, EventArgs args)
 {
     try
     {
         if (fontDialog != null)
         {
             Pango.FontDescription newFont = Pango.FontDescription.FromString(fontDialog.FontName);
             Utility.Configuration.Settings.EditorFontName = newFont.ToString();
             textEditor.Options.FontName = Utility.Configuration.Settings.EditorFontName;
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
Пример #4
0
        /// <summary>
        /// Invoked when the user clicks OK or Apply in the font selection
        /// dialog. Changes the font on all widgets and saves the new font
        /// in the config file.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="args">Event arguments.</param>
        private void OnChangeFont(object sender, ResponseArgs args)
        {
            try
            {
                string fontName = fontDialog.Font;

                Pango.FontDescription newFont = Pango.FontDescription.FromString(fontName);
                Utility.Configuration.Settings.FontName = newFont.ToString();
                ChangeFont(newFont);
                if (args.ResponseId != ResponseType.Apply)
                {
                    fontDialog.Dispose();
                }
            }
            catch (Exception err)
            {
                ShowError(err);
            }
        }
Пример #5
0
        private void _Load()
        {
            Trace.Call();

            // root
            string startup_commands = String.Join("\n", (string[])Frontend.UserConfig["OnStartupCommands"]);
            ((Gtk.TextView)_Glade["OnStartupCommandsTextView"]).Buffer.Text  = startup_commands;

            // Connection
            string nicknames = String.Join(" ", (string[])Frontend.UserConfig["Connection/Nicknames"]);
            ((Gtk.Entry)_Glade["ConnectionNicknamesEntry"]).Text  = nicknames;
            ((Gtk.Entry)_Glade["ConnectionUsernameEntry"]).Text  = (string)Frontend.UserConfig["Connection/Username"];
            ((Gtk.Entry)_Glade["ConnectionRealnameEntry"]).Text  = (string)Frontend.UserConfig["Connection/Realname"];
            string connect_commands = String.Join("\n", (string[])Frontend.UserConfig["Connection/OnConnectCommands"]);
            ((Gtk.TextView)_Glade["OnConnectCommandsTextView"]).Buffer.Text = connect_commands;

            string encoding = (string)Frontend.UserConfig["Connection/Encoding"];
            encoding = encoding.ToUpper();

            Gtk.ComboBox cb = (Gtk.ComboBox)_Glade["EncodingComboBox"];
            // glade might initialize it already!
            cb.Clear();
            Gtk.CellRendererText cell = new Gtk.CellRendererText();
            cb.PackStart(cell, false);
            cb.AddAttribute(cell, "text", 0);
            Gtk.ListStore store = new Gtk.ListStore(typeof(string), typeof(string));
            store.AppendValues(String.Format("<{0}>", _("System Default")), String.Empty);
            ArrayList encodingList = new ArrayList();
            ArrayList bodyNameList = new ArrayList();
            foreach (EncodingInfo encInfo in Encoding.GetEncodings()) {
                try {
                    Encoding enc = Encoding.GetEncoding(encInfo.CodePage);
                    string encodingName = enc.EncodingName.ToUpper();

                    // filter noise and duplicates
                    if (encodingName.IndexOf("DOS") != -1 ||
                        encodingName.IndexOf("MAC") != -1 ||
                        encodingName.IndexOf("EBCDIC") != -1 ||
                        encodingName.IndexOf("ISCII") != -1 ||
                        encodingList.Contains(encodingName) ||
                        bodyNameList.Contains(enc.BodyName)) {
                        continue;
                    }
            #if LOG4NET
                    _Logger.Debug("_Load(): adding encoding: " + enc.BodyName);
            #endif
                    encodingList.Add(encodingName);
                    bodyNameList.Add(enc.BodyName);

                    encodingName = enc.EncodingName;
                    // remove all (DOS)  / (Windows) / (Mac) crap from the encoding name
                    if (enc.EncodingName.Contains(" (")) {
                        encodingName = encodingName.Substring(0, enc.EncodingName.IndexOf(" ("));
                    }
                    store.AppendValues(enc.BodyName.ToUpper() + " - " + encodingName, enc.BodyName.ToUpper());
                } catch (NotSupportedException) {
                }
            }
            cb.Model = store;
            cb.Active = 0;
            store.SetSortColumnId(0, Gtk.SortType.Ascending);
            int j = 0;
            foreach (object[] row in store) {
                string encodingName = (string) row[1];
                if (encodingName == encoding) {
                    cb.Active = j;
                    break;
                }
                j++;
            }

            // Interface
            ((Gtk.Entry)_Glade["TimestampFormatEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];

            // Interface/Notebook
            ((Gtk.SpinButton)_Glade["BufferLinesSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Notebook/BufferLines"];
            ((Gtk.SpinButton)_Glade["EngineBufferLinesSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Notebook/EngineBufferLines"];
            ((Gtk.CheckButton)_Glade["StripColorsCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Notebook/StripColors"];
            ((Gtk.CheckButton)_Glade["StripFormattingsCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Notebook/StripFormattings"];
            switch ((string)Frontend.UserConfig["Interface/Notebook/TabPosition"]) {
                case "top":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonTop"]).Active = true;
                break;
                case "bottom":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonBottom"]).Active = true;
                break;
                case "left":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonLeft"]).Active = true;
                break;
                case "right":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonRight"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonNone"]).Active = true;
                break;
            }

            // Interface/Notebook/Channel
            switch ((string)Frontend.UserConfig["Interface/Notebook/Channel/UserListPosition"]) {
                case "left":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonLeft"]).Active = true;
                break;
                case "right":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonRight"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonNone"]).Active = true;
                break;
            }
            switch ((string)Frontend.UserConfig["Interface/Notebook/Channel/TopicPosition"]) {
                case "top":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonTop"]).Active = true;
                break;
                case "bottom":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonBottom"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonNone"]).Active = true;
                break;
            }
            ((Gtk.CheckButton) _Glade["NickColorsCheckButton"]).Active =
                (bool) Frontend.UserConfig["Interface/Notebook/Channel/NickColors"];

            // Interface/Notebook/Tab
            Gtk.ColorButton colorButton;
            string colorHexCode;

            colorButton = (Gtk.ColorButton)_Glade["NoActivityColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/NoActivityColor"];
            colorButton.Color = ColorTools.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["ActivityColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/ActivityColor"];
            colorButton.Color = ColorTools.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["ModeColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/EventColor"];
            colorButton.Color = ColorTools.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["HighlightColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/HighlightColor"];
            colorButton.Color = ColorTools.GetGdkColor(colorHexCode);

            // Interface/Chat
            colorButton = (Gtk.ColorButton)_Glade["ForegroundColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Chat/ForegroundColor"];
            if (String.IsNullOrEmpty(colorHexCode)) {
                ((Gtk.CheckButton)_Glade["OverrideForegroundColorCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideForegroundColorCheckButton"]).Active = true;
                colorButton.Color = ColorTools.GetGdkColor(colorHexCode);
            }

            colorButton = (Gtk.ColorButton)_Glade["BackgroundColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Chat/BackgroundColor"];
            if (String.IsNullOrEmpty(colorHexCode)) {
                ((Gtk.CheckButton)_Glade["OverrideBackgroundColorCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideBackgroundColorCheckButton"]).Active = true;
                colorButton.Color = ColorTools.GetGdkColor(colorHexCode);
            }

            Gtk.FontButton fontButton = (Gtk.FontButton)_Glade["FontButton"];
            string fontFamily = (string)Frontend.UserConfig["Interface/Chat/FontFamily"];
            string fontStyle = (string)Frontend.UserConfig["Interface/Chat/FontStyle"];
            int fontSize = 0;
            if (Frontend.UserConfig["Interface/Chat/FontSize"] != null) {
                fontSize = (int) Frontend.UserConfig["Interface/Chat/FontSize"];
            }
            if (String.IsNullOrEmpty(fontFamily) &&
                String.IsNullOrEmpty(fontStyle) &&
                fontSize == 0) {
                ((Gtk.CheckButton)_Glade["OverrideFontCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideFontCheckButton"]).Active = true;
                Pango.FontDescription fontDescription = new Pango.FontDescription();
                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;
                fontButton.FontName = fontDescription.ToString();
            }

            Gtk.ComboBox wrapModeComboBox = ((Gtk.ComboBox)_Glade["WrapModeComboBox"]);
            Gtk.WrapMode wrapMode = (Gtk.WrapMode) Enum.Parse(
                typeof(Gtk.WrapMode),
                (string) Frontend.UserConfig["Interface/Chat/WrapMode"]
            );
            int i = 0;
            foreach (object[] row in  (Gtk.ListStore) wrapModeComboBox.Model) {
                if (((Gtk.WrapMode) row[0]) == wrapMode) {
                    wrapModeComboBox.Active = i;
                    break;
                }
                i++;
            }

            // Interface/Entry
            ((Gtk.Entry)_Glade["CompletionCharacterEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"];
            ((Gtk.Entry)_Glade["CommandCharacterEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Entry/CommandCharacter"];
            ((Gtk.CheckButton)_Glade["BashStyleCompletionCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Entry/BashStyleCompletion"];
            ((Gtk.SpinButton)_Glade["CommandHistorySizeSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Entry/CommandHistorySize"];

            ((Gtk.CheckButton)_Glade["BeepOnHighlightCheckButton"]).Active =
                (bool)Frontend.UserConfig["Sound/BeepOnHighlight"];

            // Interface/Notification
            string modeStr = (string) Frontend.UserConfig["Interface/Notification/NotificationAreaIconMode"];
            NotificationAreaIconMode mode = (NotificationAreaIconMode) Enum.Parse(
                typeof(NotificationAreaIconMode),
                modeStr
            );
            switch (mode) {
                case NotificationAreaIconMode.Never:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = false;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonMinimized"]).Active = true;
                    break;
                case NotificationAreaIconMode.Always:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonAlways"]).Active = true;
                    break;
                case NotificationAreaIconMode.Minimized:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonMinimized"]).Active = true;
                    break;
                case NotificationAreaIconMode.Closed:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonClosed"]).Active = true;
                    break;
            }

            // Filters
            _ChannelFilterListView.Load();

            // Servers
            _ServerListView.Load();

            ((Gtk.Button)_Glade["ApplyButton"]).Sensitive = false;
        }
Пример #6
0
        private void _Load()
        {
            Trace.Call();

            // root
            string startup_commands = String.Join("\n", (string[])Frontend.UserConfig["OnStartupCommands"]);
            ((Gtk.TextView)_Glade["OnStartupCommandsTextView"]).Buffer.Text  = startup_commands;

            // Connection
            string nicknames = String.Join(" ", (string[])Frontend.UserConfig["Connection/Nicknames"]);
            ((Gtk.Entry)_Glade["ConnectionNicknamesEntry"]).Text  = nicknames;
            ((Gtk.Entry)_Glade["ConnectionUsernameEntry"]).Text  = (string)Frontend.UserConfig["Connection/Username"];
            ((Gtk.Entry)_Glade["ConnectionRealnameEntry"]).Text  = (string)Frontend.UserConfig["Connection/Realname"];
            string connect_commands = String.Join("\n", (string[])Frontend.UserConfig["Connection/OnConnectCommands"]);
            ((Gtk.TextView)_Glade["OnConnectCommandsTextView"]).Buffer.Text = connect_commands;

            string encoding = (string)Frontend.UserConfig["Connection/Encoding"];
            encoding = encoding.ToUpper();

            Gtk.ComboBox cb = (Gtk.ComboBox)_Glade["EncodingComboBox"];
            // glade might initialize it already!
            cb.Clear();
            Gtk.CellRendererText cell = new Gtk.CellRendererText();
            cb.PackStart(cell, false);
            cb.AddAttribute(cell, "text", 0);
            Gtk.ListStore store = new Gtk.ListStore(typeof(string), typeof(string));
            store.AppendValues(String.Format("<{0}>", _("System Default")), String.Empty);
            ArrayList encodingList = new ArrayList();
            ArrayList bodyNameList = new ArrayList();
            foreach (EncodingInfo encInfo in Encoding.GetEncodings()) {
                try {
                    Encoding enc = Encoding.GetEncoding(encInfo.CodePage);
                    string encodingName = enc.EncodingName.ToUpper();

                    if (!enc.IsSingleByte && enc != Encoding.UTF8) {
                        // ignore multi byte encodings except UTF-8
                        continue;
                    }

                    // filter noise and duplicates
                    if (encodingName.IndexOf("DOS") != -1 ||
                        encodingName.IndexOf("MAC") != -1 ||
                        encodingName.IndexOf("EBCDIC") != -1 ||
                        encodingName.IndexOf("ISCII") != -1 ||
                        encodingList.Contains(encodingName) ||
                        bodyNameList.Contains(enc.BodyName)) {
                        continue;
                    }
            #if LOG4NET
                    _Logger.Debug("_Load(): adding encoding: " + enc.BodyName);
            #endif
                    encodingList.Add(encodingName);
                    bodyNameList.Add(enc.BodyName);

                    encodingName = enc.EncodingName;
                    // remove all (DOS)  / (Windows) / (Mac) crap from the encoding name
                    if (enc.EncodingName.Contains(" (")) {
                        encodingName = encodingName.Substring(0, enc.EncodingName.IndexOf(" ("));
                    }
                    store.AppendValues(enc.BodyName.ToUpper() + " - " + encodingName, enc.BodyName.ToUpper());
                } catch (NotSupportedException) {
                }
            }
            cb.Model = store;
            cb.Active = 0;
            store.SetSortColumnId(0, Gtk.SortType.Ascending);
            int j = 0;
            foreach (object[] row in store) {
                string encodingName = (string) row[1];
                if (encodingName == encoding) {
                    cb.Active = j;
                    break;
                }
                j++;
            }

            // Connection - Proxy
            Gtk.ComboBox proxyTypeComboBox = ((Gtk.ComboBox)_Glade["ProxyTypeComboBox"]);
            ProxyType proxyType = (ProxyType) Enum.Parse(
                typeof(ProxyType),
                (string) Frontend.UserConfig["Connection/ProxyType"]
            );
            int i = 0;
            foreach (object[] row in  (Gtk.ListStore) proxyTypeComboBox.Model) {
                if (((ProxyType) row[0]) == proxyType) {
                    proxyTypeComboBox.Active = i;
                    break;
                }
                i++;
            }
            ((Gtk.Entry) _Glade["ProxyHostEntry"]).Text =
                (string) Frontend.UserConfig["Connection/ProxyHostname"];
            int proxyPort = (int) Frontend.UserConfig["Connection/ProxyPort"];
            if (proxyPort == -1) {
                proxyPort = 0;
            }
            ((Gtk.SpinButton) _Glade["ProxyPortSpinButton"]).Value = proxyPort;
            ((Gtk.Entry) _Glade["ProxyUsernameEntry"]).Text =
                (string) Frontend.UserConfig["Connection/ProxyUsername"];
            ((Gtk.Entry) _Glade["ProxyPasswordEntry"]).Text =
                (string) Frontend.UserConfig["Connection/ProxyPassword"];
            CheckProxyShowPasswordCheckButton();

            // MessageBuffer
            if (Frontend.EngineVersion >= new Version("0.8.1")) {
                // feature introduced in >= 0.8.1
                Gtk.ComboBox persistencyTypeComboBox =
                    ((Gtk.ComboBox)_Glade["PersistencyTypeComboBox"]);
                try {
                    var persistencyType = (MessageBufferPersistencyType) Enum.Parse(
                        typeof(MessageBufferPersistencyType),
                        (string) Frontend.UserConfig["MessageBuffer/PersistencyType"]
                    );
                    i = 0;
                    foreach (object[] row in (Gtk.ListStore) persistencyTypeComboBox.Model) {
                        if (((MessageBufferPersistencyType) row[0]) == persistencyType) {
                            persistencyTypeComboBox.Active = i;
                            break;
                        }
                        i++;
                    }
                } catch (ArgumentException) {
                    // for forward compatibility with newer engines
                    persistencyTypeComboBox.Active = -1;
                }
                ((Gtk.SpinButton)_Glade["VolatileMaxCapacitySpinButton"]).Value =
                    (double)(int)Frontend.UserConfig["MessageBuffer/Volatile/MaxCapacity"];
                ((Gtk.SpinButton)_Glade["PersistentMaxCapacitySpinButton"]).Value =
                    (double)(int)Frontend.UserConfig["MessageBuffer/Persistent/MaxCapacity"];
            }

            // Interface
            ((Gtk.CheckButton) _Glade["ShowAdvancedSettingsCheckButton"]).Active =
                (bool) Frontend.UserConfig["Interface/ShowAdvancedSettings"];
            CheckShowAdvancedSettingsCheckButton();

            // Interface/Notebook
            ((Gtk.Entry)_Glade["TimestampFormatEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
            ((Gtk.SpinButton)_Glade["BufferLinesSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Notebook/BufferLines"];
            ((Gtk.SpinButton)_Glade["EngineBufferLinesSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Notebook/EngineBufferLines"];
            ((Gtk.CheckButton)_Glade["StripColorsCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Notebook/StripColors"];
            ((Gtk.CheckButton)_Glade["StripFormattingsCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Notebook/StripFormattings"];
            switch ((string)Frontend.UserConfig["Interface/Notebook/TabPosition"]) {
                case "top":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonTop"]).Active = true;
                break;
                case "bottom":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonBottom"]).Active = true;
                break;
                case "left":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonLeft"]).Active = true;
                break;
                case "right":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonRight"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["TabPositionRadioButtonNone"]).Active = true;
                break;
            }
            if (Frontend.UserConfig["Interface/Notebook/AutoSwitchPersonChats"] != null) {
                ((Gtk.CheckButton) _Glade["AutoSwitchPersonChatsCheckButton"]).Active =
                    (bool) Frontend.UserConfig["Interface/Notebook/AutoSwitchPersonChats"];
            }
            if (Frontend.UserConfig["Interface/Notebook/AutoSwitchGroupChats"] != null) {
                ((Gtk.CheckButton) _Glade["AutoSwitchGroupChatsCheckButton"]).Active =
                    (bool) Frontend.UserConfig["Interface/Notebook/AutoSwitchGroupChats"];
            }

            // Interface/Notebook/Channel
            switch ((string)Frontend.UserConfig["Interface/Notebook/Channel/UserListPosition"]) {
                case "left":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonLeft"]).Active = true;
                break;
                case "right":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonRight"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["UserListPositionRadioButtonNone"]).Active = true;
                break;
            }
            switch ((string)Frontend.UserConfig["Interface/Notebook/Channel/TopicPosition"]) {
                case "top":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonTop"]).Active = true;
                break;
                case "bottom":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonBottom"]).Active = true;
                break;
                case "none":
                    ((Gtk.RadioButton)_Glade["TopicPositionRadioButtonNone"]).Active = true;
                break;
            }
            ((Gtk.CheckButton) _Glade["NickColorsCheckButton"]).Active =
                (bool) Frontend.UserConfig["Interface/Notebook/Channel/NickColors"];

            // Interface/Notebook/Tab
            Gtk.ColorButton colorButton;
            string colorHexCode;

            colorButton = (Gtk.ColorButton)_Glade["NoActivityColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/NoActivityColor"];
            colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["ActivityColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/ActivityColor"];
            colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["ModeColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/EventColor"];
            colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);

            colorButton = (Gtk.ColorButton)_Glade["HighlightColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Notebook/Tab/HighlightColor"];
            colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);

            // Interface/Chat
            colorButton = (Gtk.ColorButton)_Glade["ForegroundColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Chat/ForegroundColor"];
            if (String.IsNullOrEmpty(colorHexCode)) {
                ((Gtk.CheckButton)_Glade["OverrideForegroundColorCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideForegroundColorCheckButton"]).Active = true;
                colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);
            }

            colorButton = (Gtk.ColorButton)_Glade["BackgroundColorButton"];
            colorHexCode = (string)Frontend.UserConfig["Interface/Chat/BackgroundColor"];
            if (String.IsNullOrEmpty(colorHexCode)) {
                ((Gtk.CheckButton)_Glade["OverrideBackgroundColorCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideBackgroundColorCheckButton"]).Active = true;
                colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);
            }

            Gtk.FontButton fontButton = (Gtk.FontButton)_Glade["FontButton"];
            string fontFamily = (string)Frontend.UserConfig["Interface/Chat/FontFamily"];
            string fontStyle = (string)Frontend.UserConfig["Interface/Chat/FontStyle"];
            int fontSize = 0;
            if (Frontend.UserConfig["Interface/Chat/FontSize"] != null) {
                fontSize = (int) Frontend.UserConfig["Interface/Chat/FontSize"];
            }
            if (String.IsNullOrEmpty(fontFamily) &&
                String.IsNullOrEmpty(fontStyle) &&
                fontSize == 0) {
                ((Gtk.CheckButton)_Glade["OverrideFontCheckButton"]).Active = false;
            } else {
                ((Gtk.CheckButton)_Glade["OverrideFontCheckButton"]).Active = true;
                Pango.FontDescription fontDescription = new Pango.FontDescription();
                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;
                fontButton.FontName = fontDescription.ToString();
            }

            Gtk.ComboBox wrapModeComboBox = ((Gtk.ComboBox)_Glade["WrapModeComboBox"]);
            Gtk.WrapMode wrapMode = (Gtk.WrapMode) Enum.Parse(
                typeof(Gtk.WrapMode),
                (string) Frontend.UserConfig["Interface/Chat/WrapMode"]
            );
            if (wrapMode == Gtk.WrapMode.Word) {
                wrapMode = Gtk.WrapMode.WordChar;
            }
            i = 0;
            foreach (object[] row in  (Gtk.ListStore) wrapModeComboBox.Model) {
                if (((Gtk.WrapMode) row[0]) == wrapMode) {
                    wrapModeComboBox.Active = i;
                    break;
                }
                i++;
            }

            // Interface/Entry
            ((Gtk.Entry)_Glade["CompletionCharacterEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"];
            ((Gtk.Entry)_Glade["CommandCharacterEntry"]).Text =
                (string)Frontend.UserConfig["Interface/Entry/CommandCharacter"];
            ((Gtk.CheckButton)_Glade["BashStyleCompletionCheckButton"]).Active =
                (bool)Frontend.UserConfig["Interface/Entry/BashStyleCompletion"];
            ((Gtk.SpinButton)_Glade["CommandHistorySizeSpinButton"]).Value =
                (double)(int)Frontend.UserConfig["Interface/Entry/CommandHistorySize"];

            var highlight_words =
                (string[]) Frontend.UserConfig["Interface/Chat/HighlightWords"];
            // backwards compatibility with 0.7.x servers
            if (highlight_words == null) {
                highlight_words = new string[] {};
            }
            ((Gtk.TextView)_Glade["HighlightWordsTextView"]).Buffer.Text  =
                    String.Join("\n", highlight_words);

            ((Gtk.CheckButton)_Glade["BeepOnHighlightCheckButton"]).Active =
                (bool)Frontend.UserConfig["Sound/BeepOnHighlight"];

            // Interface/Notification
            string modeStr = (string) Frontend.UserConfig["Interface/Notification/NotificationAreaIconMode"];
            NotificationAreaIconMode mode = (NotificationAreaIconMode) Enum.Parse(
                typeof(NotificationAreaIconMode),
                modeStr
            );
            switch (mode) {
                case NotificationAreaIconMode.Never:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = false;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonClosed"]).Active = true;

                    // the toggle event is not raised as the checkbox is already unchecked by default
                    // thus we have to disable the radio buttons by hand
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonAlways"]).Sensitive = false;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonMinimized"]).Sensitive = false;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonClosed"]).Sensitive = false;
                    break;
                case NotificationAreaIconMode.Always:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonAlways"]).Active = true;
                    break;
                case NotificationAreaIconMode.Minimized:
                    // can't support this for now, see: http://projects.qnetp.net/issues/show/158
                    goto case NotificationAreaIconMode.Never;
                    /*
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonMinimized"]).Active = true;
                    break;
                    */
                case NotificationAreaIconMode.Closed:
                    ((Gtk.CheckButton) _Glade["NotificationAreaIconCheckButton"]).Active = true;
                    ((Gtk.RadioButton) _Glade["NotificationAreaIconRadioButtonClosed"]).Active = true;
                    break;
            }
            ((Gtk.CheckButton) _Glade["MessagingMenuCheckButton"]).Active =
                (bool) Frontend.UserConfig["Interface/Notification/MessagingMenuEnabled"];
            ((Gtk.CheckButton) _Glade["NotificationPopupsCheckButton"]).Active =
                (bool) Frontend.UserConfig["Interface/Notification/PopupsEnabled"];

            // Filters
            _FilterListWidget.InitProtocols(Frontend.Session.GetSupportedProtocols());
            _FilterListWidget.Load();

            // Servers
            _ServerListView.Load();

            // Logging
            ((Gtk.Button) _Glade["LoggingOpenButton"]).Visible = false;
            if (Frontend.UserConfig["Logging/Enabled"] != null) {
                ((Gtk.CheckButton) _Glade["LoggingEnabledCheckButton"]).Active =
                    (bool) Frontend.UserConfig["Logging/Enabled"];
                if (Frontend.IsLocalEngine) {
                    ((Gtk.Button) _Glade["LoggingOpenButton"]).Visible = true;
                }
            }
            if (Frontend.UserConfig["Logging/LogFilteredMessages"] != null) {
                ((Gtk.CheckButton) _Glade["LoggingLogFilteredMessagesCheckButton"]).Active =
                    (bool) Frontend.UserConfig["Logging/LogFilteredMessages"];
            }

            ((Gtk.Button)_Glade["ApplyButton"]).Sensitive = false;
        }
Пример #7
0
        void ReadFromConfig()
        {
            Trace.Call();

            var conf = Frontend.UserConfig;

            // manually handled widgets
            ProxyType proxyType = (ProxyType)Enum.Parse(
                typeof(ProxyType),
                (string)conf["Connection/ProxyType"]
                );
            int i = 0;

            foreach (object[] row in  (Gtk.ListStore)f_ProxyTypeComboBox.Model)
            {
                if (((ProxyType)row[0]) == proxyType)
                {
                    f_ProxyTypeComboBox.Active = i;
                    break;
                }
                i++;
            }
            f_ProxySwitch.Active = proxyType != ProxyType.None;
            CheckProxySwitch();

            f_ShowColorsCheckButton.Active      = !(bool)conf["Interface/Notebook/StripColors"];
            f_ShowFormattingsCheckButton.Active = !(bool)conf["Interface/Notebook/StripFormattings"];

            var fontButton = (Gtk.FontButton)Builder.GetObject("FontButton");
            var fontFamily = (string)conf["Interface/Chat/FontFamily"];
            var fontStyle  = (string)conf["Interface/Chat/FontStyle"];
            int fontSize   = 0;

            if (conf["Interface/Chat/FontSize"] != null)
            {
                fontSize = (int)conf["Interface/Chat/FontSize"];
            }
            if (String.IsNullOrEmpty(fontFamily) &&
                String.IsNullOrEmpty(fontStyle) &&
                fontSize == 0)
            {
                f_SystemWideFontRadioButton.Active = true;
            }
            else
            {
                f_CustomFontRadioButton.Active = true;
                Pango.FontDescription fontDescription = new Pango.FontDescription();
                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;
                fontButton.FontName  = fontDescription.ToString();
            }
            var bgColorHexCode = (string)conf["Interface/Chat/BackgroundColor"];
            var fgColorHexCode = (string)conf["Interface/Chat/ForegroundColor"];

            if (String.IsNullOrEmpty(bgColorHexCode) &&
                String.IsNullOrEmpty(fgColorHexCode))
            {
                f_SystemWideFontRadioButton.Active = true;
            }
            else
            {
                f_CustomFontColorRadioButton.Active = true;
            }

            // mapped widgets
            foreach (var confEntry in ConfigKeyToWidgetNameMap)
            {
                var confKey   = confEntry.Key;
                var confValue = conf[confKey];
                var widgetId  = confEntry.Value;
                var widget    = Builder.GetObject(widgetId);
                if (widget is Gtk.SpinButton)
                {
                    var spinButton = (Gtk.SpinButton)widget;
                    if (confValue is Int32)
                    {
                        spinButton.Value = (Int32)confValue;
                    }
                    else
                    {
                        spinButton.Value = Int32.Parse((string)confValue);
                    }
                }
                else if (widget is Gtk.ColorButton)
                {
                    var colorButton  = (Gtk.ColorButton)widget;
                    var colorHexCode = (string)confValue;
                    if (String.IsNullOrEmpty(colorHexCode))
                    {
                        colorButton.Color = Gdk.Color.Zero;
                    }
                    else
                    {
                        colorButton.Color = ColorConverter.GetGdkColor(colorHexCode);
                    }
                }
                else if (widget is Gtk.CheckButton)
                {
                    var checkButton = (Gtk.CheckButton)widget;
                    checkButton.Active = (bool)confValue;
#if GTK_SHARP_3
                }
                else if (widget is Gtk.Switch)
                {
                    var @switch = (Gtk.Switch)widget;
                    @switch.Active = (bool)confValue;
#endif
                }
                else if (widget is Gtk.TextView)
                {
                    var textView = (Gtk.TextView)widget;
                    if (confValue is string[])
                    {
                        textView.Buffer.Text = String.Join("\n", (string[])confValue);
                    }
                    else
                    {
                        textView.Buffer.Text = (string)confValue;
                    }
                }
                else if (widget is Gtk.Entry)
                {
                    var entry = (Gtk.Entry)widget;
                    if (confValue is string[])
                    {
                        entry.Text = String.Join(" ", (string[])confValue);
                    }
                    else
                    {
                        entry.Text = (string)confValue;
                    }
                }
            }
        }