Changeset a2a811e2605275a015a5c8d402ea98b2947afb86

Show
Ignore:
Timestamp:
09/19/08 00:01:22 (5 years ago)
Author:
Armin Burgmeier <armin@…>
Parents:
04fe422de37ab2581560c02d9fbb84e47b49f86e
Children:
823255b93401a002c0156230dbcbd5a508dd0baf
git-committer:
Armin Burgmeier <armin@arbur.net> / 2008-09-19T00:01:22Z+0200
Message:

Added security page to preferences dialog

2008-09-18 Armin Burgmeier <armin@…>

  • inc/dialogs/preferencesdialogs.hpp:
  • src/dialogs/preferencesdialogs.cpp: Added a security page.
  • inc/core/browser.hpp:
  • src/core/browser.cpp: Set discovery's security policy and certificate manager's trust file from preferences.
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r04fe422 ra2a811e  
     12008-09-18  Armin Burgmeier  <armin@arbur.net> 
     2 
     3        * inc/dialogs/preferencesdialogs.hpp: 
     4        * src/dialogs/preferencesdialogs.cpp: Added a security page. 
     5 
     6        * inc/core/browser.hpp: 
     7        * src/core/browser.cpp: Set discovery's security policy and 
     8        certificate manager's trust file from preferences. 
     9 
    1102008-09-18  Armin Burgmeier  <armin@arbur.net> 
    211 
  • inc/core/browser.hpp

    r8667620 ra2a811e  
    2929#include <libinfgtk/inf-gtk-certificate-manager.h> 
    3030#include <libinfinity/client/infc-browser.h> 
     31#include <libinfinity/common/inf-discovery-avahi.h> 
    3132#include <libinfinity/common/inf-xmpp-manager.h> 
     33#include <libinfinity/inf-config.h> 
    3234 
    3335#include <gtkmm/window.h> 
     
    106108                             const std::runtime_error& error); 
    107109 
     110        void on_security_policy_changed(); 
     111        void on_trust_file_changed(); 
     112 
    108113        Gtk::Window& m_parent; 
    109114        const InfcNotePlugin* m_text_plugin; 
     
    112117 
    113118        InfXmppManager* m_xmpp_manager; 
     119#ifdef INFINOTE_HAVE_AVAHI 
     120        InfDiscoveryAvahi* m_discovery; 
     121#endif 
    114122        InfGtkIo* m_io; 
    115123        InfGtkCertificateManager* m_cert_manager; 
  • inc/dialogs/preferencesdialog.hpp

    r04fe422 ra2a811e  
    2929#include <gtkmm/spinbutton.h> 
    3030#include <gtkmm/checkbutton.h> 
    31 #include <gtkmm/comboboxtext.h> 
     31#include <gtkmm/combobox.h> 
    3232#include <gtkmm/notebook.h> 
    3333#include <gtkmm/alignment.h> 
    3434#include <gtkmm/filechooserbutton.h> 
    3535#include <gtkmm/fontbutton.h> 
    36 //#include <gtkmm/colorbutton.h> 
    3736#include <gtkmm/sizegroup.h> 
     37#include <gtkmm/liststore.h> 
    3838 
    3939namespace Gobby 
    4040{ 
     41 
     42template<typename OptionType> 
     43class PreferencesComboBox: public Gtk::ComboBox 
     44{ 
     45public: 
     46        PreferencesComboBox(Preferences::Option<OptionType>& option): 
     47                m_option(option), m_store(Gtk::ListStore::create(m_columns)) 
     48        { 
     49                set_model(m_store); 
     50 
     51                Gtk::CellRendererText* renderer = 
     52                        Gtk::manage(new Gtk::CellRendererText); 
     53                pack_start(*renderer, true); 
     54                add_attribute(renderer->property_text(), m_columns.text); 
     55        } 
     56 
     57        void add(const Glib::ustring& text, const OptionType& value) 
     58        { 
     59                Gtk::TreeIter iter = m_store->append(); 
     60                (*iter)[m_columns.text] = text; 
     61                (*iter)[m_columns.value] = value; 
     62 
     63                if(m_option == value) 
     64                        set_active(iter); 
     65        } 
     66 
     67private: 
     68        class Columns: public Gtk::TreeModelColumnRecord 
     69        { 
     70        public: 
     71                Gtk::TreeModelColumn<Glib::ustring> text; 
     72                Gtk::TreeModelColumn<OptionType> value; 
     73 
     74                Columns() { add(text); add(value); } 
     75        }; 
     76 
     77        virtual void on_changed() 
     78        { 
     79                Gtk::ComboBox::on_changed(); 
     80                m_option = (*get_active())[m_columns.value]; 
     81        } 
     82 
     83        Preferences::Option<OptionType>& m_option; 
     84 
     85        Columns m_columns; 
     86        Glib::RefPtr<Gtk::ListStore> m_store; 
     87}; 
    4188 
    4289class PreferencesDialog : public Gtk::Dialog 
    4390{ 
    4491public: 
     92        template<typename OptionType> 
     93        class ComboColumns: public Gtk::TreeModelColumnRecord 
     94        { 
     95        }; 
     96 
    4597        class Group: public Gtk::Frame 
    4698        { 
     
    148200                Group m_group_font; 
    149201 
    150                 Gtk::ComboBoxText m_cmb_toolbar_style; 
    151  
     202                PreferencesComboBox<Gtk::ToolbarStyle> m_cmb_toolbar_style; 
    152203                Gtk::FontButton m_btn_font; 
     204        }; 
     205 
     206        class Security: public Page 
     207        { 
     208        public: 
     209                Security(Preferences& preferences); 
     210         
     211        protected: 
     212                Group m_group_trust_file; 
     213                Group m_group_connection_policy; 
     214 
     215                Gtk::FileChooserButton m_btn_path_trust_file; 
     216                PreferencesComboBox<InfXmppConnectionSecurityPolicy> 
     217                        m_cmb_connection_policy; 
    153218        }; 
    154219 
     
    167232        View m_page_view; 
    168233        Appearance m_page_appearance; 
     234        Security m_page_security; 
    169235}; 
    170236 
  • src/core/browser.cpp

    rcd0ff9f ra2a811e  
    2121 
    2222#include <libinfinity/inf-config.h> 
    23 #include <libinfinity/common/inf-discovery-avahi.h> 
    2423 
    2524#include <gtkmm/stock.h> 
     
    6362        m_xmpp_manager = inf_xmpp_manager_new(); 
    6463#ifdef INFINOTE_HAVE_AVAHI 
    65         InfDiscoveryAvahi* discovery = 
    66                 inf_discovery_avahi_new(INF_IO(m_io), m_xmpp_manager, 
    67                                         NULL, NULL); 
     64        m_discovery = inf_discovery_avahi_new(INF_IO(m_io), m_xmpp_manager, 
     65                                              NULL, NULL); 
     66        inf_discovery_avahi_set_security_policy( 
     67                m_discovery, m_preferences.security.policy); 
    6868        inf_gtk_browser_store_add_discovery(m_browser_store, 
    69                                             INF_DISCOVERY(discovery)); 
    70         g_object_unref(discovery); 
     69                                            INF_DISCOVERY(m_discovery)); 
    7170#endif 
    7271 
    7372        Glib::ustring known_hosts_file = Glib::build_filename( 
    7473                Glib::get_home_dir(), GOBBY_CONFIGDIR"/known_hosts"); 
     74 
     75        const std::string trust_file = m_preferences.security.trust_file; 
    7576        m_cert_manager = inf_gtk_certificate_manager_new( 
    7677                parent.gobj(), m_xmpp_manager, 
    77                 NULL, known_hosts_file.c_str()); 
     78                trust_file.empty() ? NULL : trust_file.c_str(), 
     79                known_hosts_file.c_str()); 
    7880 
    7981        m_browser_view = 
     
    103105        ); 
    104106 
     107        m_preferences.security.policy.signal_changed().connect( 
     108                sigc::mem_fun(*this, &Browser::on_security_policy_changed)); 
     109        m_preferences.security.trust_file.signal_changed().connect( 
     110                sigc::mem_fun(*this, &Browser::on_trust_file_changed)); 
     111 
    105112        set_spacing(6); 
    106113        pack_start(m_scroll, Gtk::PACK_EXPAND_WIDGET); 
     
    120127        g_object_unref(m_cert_manager); 
    121128        g_object_unref(m_xmpp_manager); 
     129#ifdef INFINOTE_HAVE_AVAHI 
     130        g_object_unref(m_discovery); 
     131#endif 
    122132        g_object_unref(m_io); 
    123133} 
     
    319329        inf_gtk_browser_view_set_selected(m_browser_view, &tree_iter); 
    320330} 
     331 
     332void Gobby::Browser::on_security_policy_changed() 
     333{ 
     334#ifdef INFINOTE_HAVE_AVAHI 
     335        inf_discovery_avahi_set_security_policy( 
     336                m_discovery, m_preferences.security.policy); 
     337#endif 
     338} 
     339 
     340void Gobby::Browser::on_trust_file_changed() 
     341{ 
     342        const std::string trust_file = m_preferences.security.trust_file; 
     343 
     344        g_object_set(G_OBJECT(m_cert_manager), "trust-file", 
     345                     trust_file.empty() ? NULL : trust_file.c_str(), NULL); 
     346} 
  • src/dialogs/preferencesdialog.cpp

    r04fe422 ra2a811e  
    2929        using namespace Gobby; 
    3030 
    31         Gtk::ToolbarStyle rownum_to_toolstyle(int rownum) 
    32         { 
    33                 switch(rownum) 
    34                 { 
    35                 case 0: return Gtk::TOOLBAR_TEXT; 
    36                 case 1: return Gtk::TOOLBAR_ICONS; 
    37                 case 3: return Gtk::TOOLBAR_BOTH_HORIZ; 
    38                 case 2: default: return Gtk::TOOLBAR_BOTH; 
    39                 } 
    40         } 
    41  
    4231        Gtk::WrapMode 
    4332        wrap_mode_from_check_buttons(Gtk::CheckButton& char_button, 
     
    10695                                        entry, 
    10796                                        &Gtk::Entry::get_text 
    108                                 ) 
    109                         ) 
    110                 ); 
    111         } 
    112  
    113         void 
    114         connect_toolbar_style_option(Gtk::ComboBox& box, 
    115                                      Preferences::Option<Gtk::ToolbarStyle>& 
    116                                      option) 
    117         { 
    118                 box.signal_changed().connect( 
    119                         sigc::compose( 
    120                                 sigc::mem_fun( 
    121                                         option, 
    122                                         &Preferences::Option< 
    123                                                 Gtk::ToolbarStyle>::set 
    124                                 ), 
    125                                 sigc::compose( 
    126                                         sigc::ptr_fun(rownum_to_toolstyle), 
    127                                         sigc::mem_fun( 
    128                                                 box, 
    129                                                 &Gtk::ComboBox:: 
    130                                                         get_active_row_number 
    131                                         ) 
    13297                                ) 
    13398                        ) 
     
    482447} 
    483448 
    484 Gobby::PreferencesDialog::Appearance:: 
    485         Appearance(Gobby::Preferences& preferences): 
     449Gobby::PreferencesDialog::Appearance::Appearance(Preferences& preferences): 
    486450        m_group_toolbar(_("Toolbar") ), 
    487         m_group_font(_("Font") ) 
    488 { 
    489         Gtk::ToolbarStyle style = preferences.appearance.toolbar_style; 
     451        m_group_font(_("Font") ), 
     452        m_cmb_toolbar_style(preferences.appearance.toolbar_style) 
     453{ 
    490454        const Pango::FontDescription& font = preferences.appearance.font; 
    491455 
    492         m_cmb_toolbar_style.append_text(_("Show text only") ); 
    493         m_cmb_toolbar_style.append_text(_("Show icons only") ); 
    494         m_cmb_toolbar_style.append_text(_("Show both icons and text") ); 
    495         m_cmb_toolbar_style.append_text(_("Show text besides icons") ); 
     456        m_cmb_toolbar_style.add(_("Show text only"), 
     457                                Gtk::TOOLBAR_TEXT); 
     458        m_cmb_toolbar_style.add(_("Show icons only"), 
     459                                Gtk::TOOLBAR_ICONS); 
     460        m_cmb_toolbar_style.add(_("Show both icons and text"), 
     461                                Gtk::TOOLBAR_BOTH ); 
     462        m_cmb_toolbar_style.add(_("Show text besides icons"), 
     463                                Gtk::TOOLBAR_BOTH_HORIZ ); 
    496464        m_cmb_toolbar_style.show(); 
    497         connect_toolbar_style_option(m_cmb_toolbar_style, 
    498                                      preferences.appearance.toolbar_style); 
    499  
    500         switch(style) 
    501         { 
    502         case Gtk::TOOLBAR_TEXT: m_cmb_toolbar_style.set_active(0); break; 
    503         case Gtk::TOOLBAR_ICONS: m_cmb_toolbar_style.set_active(1); break; 
    504         case Gtk::TOOLBAR_BOTH: m_cmb_toolbar_style.set_active(2); break; 
    505         case Gtk::TOOLBAR_BOTH_HORIZ: m_cmb_toolbar_style.set_active(3); break; 
    506         default: break; // Avoids compiler warnings 
    507         } 
    508465 
    509466        m_btn_font.set_font_name(font.to_string()); 
     
    519476        add(m_group_toolbar); 
    520477        add(m_group_font); 
     478} 
     479 
     480Gobby::PreferencesDialog::Security::Security(Preferences& preferences): 
     481        m_group_trust_file(_("Trusted CAs")), 
     482        m_group_connection_policy(_("Secure Connection")), 
     483        m_btn_path_trust_file(_("Select a file containing trusted CAs")), 
     484        m_cmb_connection_policy(preferences.security.policy) 
     485{ 
     486        const std::string& trust_file = preferences.security.trust_file; 
     487        if(!trust_file.empty()) 
     488                m_btn_path_trust_file.set_filename(trust_file); 
     489 
     490        connect_path_option(m_btn_path_trust_file, 
     491                            preferences.security.trust_file); 
     492        m_btn_path_trust_file.show(); 
     493        m_group_trust_file.add(m_btn_path_trust_file); 
     494        m_group_trust_file.show(); 
     495 
     496/*      m_cmb_connection_policy.add( 
     497                _("Never use a secure connection"), 
     498                INF_XMPP_CONNECTION_SECURITY_ONLY_UNSECURED);*/ 
     499        m_cmb_connection_policy.add( 
     500                _("Use TLS if possible"), 
     501                INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS); 
     502        m_cmb_connection_policy.add( 
     503                _("Always use TLS"), 
     504                INF_XMPP_CONNECTION_SECURITY_ONLY_TLS); 
     505        m_cmb_connection_policy.show(); 
     506        m_group_connection_policy.add(m_cmb_connection_policy); 
     507        m_group_connection_policy.show(); 
     508 
     509        add(m_group_trust_file); 
     510        add(m_group_connection_policy); 
    521511} 
    522512 
     
    525515        Gtk::Dialog(_("Preferences"), parent), m_preferences(preferences), 
    526516        m_page_user(*this, preferences), m_page_editor(preferences), 
    527         m_page_view(preferences), m_page_appearance(preferences) 
     517        m_page_view(preferences), m_page_appearance(preferences), 
     518        m_page_security(preferences) 
    528519{ 
    529520        m_notebook.append_page(m_page_user, _("User")); 
     
    531522        m_notebook.append_page(m_page_view, _("View")); 
    532523        m_notebook.append_page(m_page_appearance, _("Appearance")); 
     524        m_notebook.append_page(m_page_security, _("Security")); 
    533525 
    534526        m_page_user.show(); 
     
    536528        m_page_view.show(); 
    537529        m_page_appearance.show(); 
     530        m_page_security.show(); 
    538531 
    539532        get_vbox()->set_spacing(6); 
     
    544537 
    545538        set_border_width(12); 
     539        set_resizable(false); 
    546540} 
    547541