Changeset debf4abb25a94c2355deabff93cc6d1398ac7278

Show
Ignore:
Timestamp:
01/06/07 23:59:02 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
8975b6e0f22d55b275ae4beeab91bec67a2d5bbb
Children:
50fd8625a91817104b85ce1f4f61945dd3a73274
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:59:02Z+0000
Message:

[project @ Replaced DefaultDialog? by Gtk::Dialog::set_default_response [fixes #117]]

Original author: Armin Burgmeier <armin@…>
Date: 2006-03-17 18:25:42+00:00

Files:
2 removed
16 modified

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r84c0261 rdebf4ab  
    2424noinst_HEADERS += inc/application_state.hpp 
    2525noinst_HEADERS += inc/encoding_selector.hpp 
    26 noinst_HEADERS += inc/defaultdialog.hpp 
    2726noinst_HEADERS += inc/historyentry.hpp 
    2827noinst_HEADERS += inc/fileentry.hpp 
     
    7877gobby_SOURCES += src/application_state.cpp 
    7978gobby_SOURCES += src/encoding_selector.cpp 
    80 gobby_SOURCES += src/defaultdialog.cpp 
    8179gobby_SOURCES += src/historyentry.cpp 
    8280gobby_SOURCES += src/fileentry.cpp 
  • inc/entrydialog.hpp

    rdb38fa5 rdebf4ab  
    2222#include <gtkmm/label.h> 
    2323#include <gtkmm/entry.h> 
    24 #include "defaultdialog.hpp" 
     24#include <gtkmm/dialog.h> 
    2525 
    2626namespace Gobby 
    2727{ 
    2828 
    29 class EntryDialog : public DefaultDialog 
     29class EntryDialog: public Gtk::Dialog 
    3030{ 
    3131public: 
  • inc/hostdialog.hpp

    rb6b3405 rdebf4ab  
    2525#include <gtkmm/entry.h> 
    2626#include <gtkmm/colorbutton.h> 
    27 #include "defaultdialog.hpp" 
    2827#include "colorsel.hpp" 
    2928#include "config.hpp" 
     
    3332{ 
    3433 
    35 class HostDialog : public DefaultDialog 
     34class HostDialog: public Gtk::Dialog 
    3635{ 
    3736public: 
  • inc/joindialog.hpp

    r2292265 rdebf4ab  
    2525#include <gtkmm/entry.h> 
    2626#include <gtkmm/colorbutton.h> 
    27 #include "defaultdialog.hpp" 
    2827#include "config.hpp" 
    2928#include "features.hpp" 
     
    4241{ 
    4342 
    44 class JoinDialog : public DefaultDialog 
     43class JoinDialog: public Gtk::Dialog 
    4544{ 
    4645public: 
    4746#ifdef WITH_HOWL 
    48         class Columns : public Gtk::TreeModel::ColumnRecord 
     47        class Columns: public Gtk::TreeModel::ColumnRecord 
    4948        { 
    5049        public: 
  • inc/joinprogressdialog.hpp

    r882c708 rdebf4ab  
    4646        typedef ClientBuffer::connection_settings connection_settings; 
    4747 
    48         class Prompt: public DefaultDialog 
     48        class Prompt: public Gtk::Dialog 
    4949        { 
    50         public: 
     50        protected: 
    5151                Prompt(Gtk::Window& parent, 
    5252                       const Glib::ustring& title, 
    5353                       const Glib::ustring& info, 
    54                        Gtk::Widget& widget, 
    5554                       const Gtk::StockID& icon); 
    56         protected: 
     55 
     56                void set_custom_widget(Widget& widget); 
     57 
    5758                Gtk::Table m_table; 
    5859                Gtk::Label m_info; 
    5960                Gtk::Image m_icon; 
     61        }; 
     62 
     63        class NamePrompt: public Prompt 
     64        { 
     65        public: 
     66                NamePrompt(Gtk::Window& parent, 
     67                           const Glib::ustring& initial_name); 
     68 
     69                Glib::ustring get_name() const; 
     70        protected: 
     71                void on_change(); 
     72 
     73                const Glib::ustring m_initial_name; 
     74 
     75                Gtk::HBox m_box; 
     76                Gtk::Label m_label; 
     77                Gtk::Entry m_entry; 
     78        }; 
     79 
     80        class ColorPrompt: public Prompt 
     81        { 
     82        public: 
     83                ColorPrompt(Gtk::Window& parent, 
     84                            const Gdk::Color& initial_color); 
     85 
     86                Gdk::Color get_color() const; 
     87        protected: 
     88                Gtk::ColorButton m_button; 
     89        }; 
     90 
     91        class SessionPasswordPrompt: public Prompt 
     92        { 
     93        public: 
     94                SessionPasswordPrompt(Gtk::Window& parent); 
     95 
     96                Glib::ustring get_password() const; 
     97        protected: 
     98                void on_change(); 
     99 
     100                Gtk::HBox m_box; 
     101                Gtk::Label m_label; 
     102                Gtk::Entry m_entry; 
     103        }; 
     104 
     105        class UserPasswordPrompt: public Prompt 
     106        { 
     107        public: 
     108                UserPasswordPrompt(Gtk::Window& parent, 
     109                                   const Glib::ustring& initial_name); 
     110 
     111                Glib::ustring get_name() const; 
     112                Glib::ustring get_password() const; 
     113        protected: 
     114                void on_change(); 
     115 
     116                const Glib::ustring m_initial_name; 
     117 
     118                Gtk::Table m_table; 
     119                Gtk::Label m_lbl_name; 
     120                Gtk::Label m_lbl_password; 
     121                Gtk::Entry m_ent_name; 
     122                Gtk::Entry m_ent_password; 
    60123        }; 
    61124 
  • inc/passworddialog.hpp

    r1662ea7 rdebf4ab  
    2020#define _GOBBY_PASSWORDDIALOG_HPP_ 
    2121 
    22 #include "defaultdialog.hpp" 
    2322#include <gtkmm/table.h> 
    2423#include <gtkmm/label.h> 
     
    2928{ 
    3029 
    31 class PasswordDialog : public DefaultDialog 
     30class PasswordDialog: public Gtk::Dialog 
    3231{ 
    3332public: 
    34         PasswordDialog(Gtk::Window& parent, const Glib::ustring& title, 
    35                        bool request); 
    36         ~PasswordDialog(); 
     33        PasswordDialog(Gtk::Window& parent, const Glib::ustring& title); 
    3734 
    3835        void set_info(const Glib::ustring& info); 
     
    4037protected: 
    4138        void on_password_changed(); 
    42  
    43         bool m_request; 
    4439 
    4540        Gtk::Table m_table; 
  • src/buffer_def.cpp

    rba89078 rdebf4ab  
    3434bool Gobby::is_subscribable(const LocalDocumentInfo& info) 
    3535{ 
    36         // Gobby only allow subscriptions to UTF-8 encoded documents 
     36        // Gobby only allows subscriptions to UTF-8 encoded documents 
    3737        for(std::size_t n = 0; n < utf8_repr_count; ++ n) 
    3838                if(info.get_encoding() == utf8_reprs[n]) 
  • src/document.cpp

    r124a20e rdebf4ab  
    242242        ); 
    243243 
     244        // TODO: This belongs to document 
     245        m_buffer->begin_not_undoable_action(); 
     246 
    244247        // TODO: Connect to user table's signal handler - as soon as it 
    245248        // has some... 
  • src/docwindow.cpp

    ra8762fa rdebf4ab  
    5757        m_view.set_buffer(buf); 
    5858 
    59         // TODO: This belongs to document 
    60         buf->begin_not_undoable_action(); 
    61  
    6259        // Set source language by filename 
    6360        buf->set_highlight(false); 
  • src/entrydialog.cpp

    rdb38fa5 rdebf4ab  
    2323Gobby::EntryDialog::EntryDialog(Gtk::Window& parent, 
    2424                                const Glib::ustring& title, 
    25                                 const Glib::ustring& label) 
    26  : DefaultDialog(title, parent, true, true), 
    27    m_label(label), 
    28    m_box(false, 5), 
    29    m_check_valid_entry(false) 
     25                                const Glib::ustring& label): 
     26        Gtk::Dialog(title, parent, true, true), m_label(label), m_box(false, 5), 
     27        m_check_valid_entry(false) 
    3028{ 
     29        m_entry.set_activates_default(true); 
     30 
    3131        m_box.pack_start(m_label); 
    3232        m_box.pack_start(m_entry); 
     
    3535        get_vbox()->pack_start(m_box); 
    3636 
    37         set_default_response(Gtk::RESPONSE_OK); 
     37        m_entry.signal_changed().connect( 
     38                sigc::mem_fun(*this, &EntryDialog::on_entry_changed) 
     39        ); 
    3840 
    3941        add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    4042        add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 
    41  
    42         m_entry.signal_changed().connect( 
    43                 sigc::mem_fun(*this, &EntryDialog::on_entry_changed) ); 
     43        set_default_response(Gtk::RESPONSE_OK); 
    4444 
    4545        show_all(); 
     
    8686        set_response_sensitive(Gtk::RESPONSE_OK, !disable); 
    8787} 
    88  
  • src/fileentry.cpp

    r3bec576 rdebf4ab  
    2121 
    2222Gobby::FileEntry::FileEntry(const Glib::ustring& title): 
    23         Gtk::HBox(), m_dialog(title), m_btn_browse(Gtk::Stock::OPEN) 
     23        Gtk::HBox(), m_btn_browse(Gtk::Stock::OPEN), m_dialog(title) 
    2424{ 
    2525        init(); 
     
    2727 
    2828Gobby::FileEntry::FileEntry(Gtk::Window& parent, const Glib::ustring& title): 
    29         Gtk::HBox(), m_dialog(parent, title), m_btn_browse(Gtk::Stock::OPEN) 
     29        Gtk::HBox(), m_btn_browse(Gtk::Stock::OPEN), m_dialog(parent, title) 
    3030{ 
    3131        init(); 
     
    3838 
    3939        m_btn_browse.signal_clicked().connect( 
    40                 sigc::mem_fun(*this, &FileEntry::on_browse) ); 
     40                sigc::mem_fun(*this, &FileEntry::on_browse) 
     41        ); 
    4142 
    4243        pack_start(m_ent_file, Gtk::PACK_EXPAND_WIDGET); 
    4344        pack_start(m_btn_browse, Gtk::PACK_SHRINK); 
     45 
     46        m_ent_file.set_activates_default(true); 
    4447 
    4548        set_spacing(5); 
  • src/hostdialog.cpp

    r67b341e rdebf4ab  
    2222 
    2323Gobby::HostDialog::HostDialog(Gtk::Window& parent, Config& config): 
    24         DefaultDialog(_("Create obby session"), parent, true, true), 
     24        Gtk::Dialog(_("Create obby session"), parent, true, true), 
    2525        m_config(config), 
    2626        m_table(4, 2), 
     
    5151        m_ent_name.set_text(name); 
    5252        m_btn_color.set_color(color); 
     53 
     54        sigc::slot<void> response( 
     55                sigc::bind( 
     56                        sigc::mem_fun(*this, &Gtk::Dialog::response), 
     57                        Gtk::RESPONSE_OK 
     58                ) 
     59        ); 
     60 
     61        m_ent_port.set_activates_default(true); 
     62        m_ent_name.set_activates_default(true); 
     63        m_ent_password.set_activates_default(true); 
    5364 
    5465        m_table.attach(m_lbl_port, 0, 1, 0, 1, 
     
    93104        add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    94105        Gtk::Button* host_btn = add_button(_("_Host"), Gtk::RESPONSE_OK); 
     106 
    95107        Gtk::Image* img = Gtk::manage( 
    96108                new Gtk::Image(Gtk::Stock::NETWORK, Gtk::ICON_SIZE_BUTTON) 
    97                 ); 
     109        ); 
     110 
    98111        host_btn->set_image(*img); 
     112 
     113        set_default_response(Gtk::RESPONSE_OK); 
    99114 
    100115        show_all(); 
  • src/joindialog.cpp

    rcd79074 rdebf4ab  
    3232 
    3333#ifndef WITH_HOWL 
    34 Gobby::JoinDialog::JoinDialog(Gtk::Window& parent, Gobby::Config& config) 
     34Gobby::JoinDialog::JoinDialog(Gtk::Window& parent, Gobby::Config& config): 
    3535#else 
    3636Gobby::JoinDialog::JoinDialog(Gtk::Window& parent, Gobby::Config& config, 
    37                               obby::zeroconf* zeroconf) 
    38 #endif 
    39  : DefaultDialog(_("Join obby session"), parent, true, true), 
     37                              obby::zeroconf* zeroconf): 
     38#endif 
     39        Gtk::Dialog(_("Join obby session"), parent, true, true), 
    4040   m_config(config), 
    4141   m_table(4, 2), 
     
    7171        m_ent_name.set_text(name); 
    7272        m_btn_color.set_color(color); 
     73 
     74        m_ent_host.set_activates_default(true); 
     75        m_ent_port.set_activates_default(true); 
     76        m_ent_name.set_activates_default(true); 
    7377 
    7478        m_table.attach(m_lbl_host, 0, 1, 0, 1, 
     
    124128        add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    125129        add_button(Gtk::Stock::CONNECT, Gtk::RESPONSE_OK); 
     130        set_default_response(Gtk::RESPONSE_OK); 
    126131 
    127132        show_all(); 
  • src/joinprogressdialog.cpp

    r27da386 rdebf4ab  
    2121#include <obby/format_string.hpp> 
    2222#include "common.hpp" 
    23 #include "defaultdialog.hpp" 
    2423#include "colorsel.hpp" 
    2524#include "passworddialog.hpp" 
     
    2726#include "joinprogressdialog.hpp" 
    2827 
    29 namespace { 
    30         // TODO: How to use std::logical_and and such? 
    31         bool logical_and(bool lhs, bool rhs) { return lhs && rhs; } 
    32         bool logical_or(bool lhs, bool rhs) { return lhs || rhs; } 
    33         bool logical_not(bool arg) { return !arg; } 
    34  
    35         typedef bool(*compare_ustring_func)( 
    36                 const Glib::ustring&, 
    37                 const Glib::ustring& 
    38         ); 
     28namespace 
     29{ 
     30        Glib::ustring make_user_password_info(const Glib::ustring& username) 
     31        { 
     32                obby::format_string str( 
     33                        Gobby::_( 
     34                                "User password for user '%0%' required. You " 
     35                                "may either choose another user name, type " 
     36                                "in your user password or cancel the " 
     37                                "connection." 
     38                        ) 
     39                ); 
     40 
     41                str << username.raw(); 
     42                return str.str(); 
     43        } 
    3944 
    4045        obby::colour gdk_to_obby(const Gdk::Color& color) 
     
    6065                                          const Glib::ustring& title, 
    6166                                          const Glib::ustring& info, 
    62                                           Gtk::Widget& widget, 
    6367                                          const Gtk::StockID& icon): 
    64         DefaultDialog(title, parent, true, true), m_table(2, 2), m_info(info), 
     68        Gtk::Dialog(title, parent, true, true), m_table(2, 2), m_info(info), 
    6569        m_icon(icon, Gtk::ICON_SIZE_DIALOG) 
    6670{ 
     
    6872 
    6973        m_table.attach(m_icon, 0, 1, 0, 2, Gtk::SHRINK, Gtk::SHRINK); 
    70         m_table.attach(m_info, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); 
    71         m_table.attach(widget, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); 
     74        m_table.attach( 
     75                m_info, 
     76                1, 2, 0, 1, 
     77                Gtk::EXPAND | Gtk::FILL, 
     78                Gtk::SHRINK 
     79        ); 
     80 
    7281        m_table.set_spacings(10); 
    7382 
     
    7988        add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 
    8089 
     90        set_default_response(Gtk::RESPONSE_OK); 
    8191        set_border_width(10); 
    82  
    8392        set_resizable(false); 
     93} 
     94 
     95void Gobby::JoinProgressDialog::Prompt::set_custom_widget(Widget& widget) 
     96{ 
     97        m_table.attach( 
     98                widget, 
     99                1, 2, 1, 2, 
     100                Gtk::EXPAND | Gtk::FILL, 
     101                Gtk::SHRINK 
     102        ); 
     103} 
     104 
     105Gobby::JoinProgressDialog::NamePrompt:: 
     106        NamePrompt(Gtk::Window& parent, 
     107                   const Glib::ustring& initial_name): 
     108        Prompt( 
     109                parent, 
     110                obby::login::errstring(net6::login::ERROR_NAME_IN_USE), 
     111                _("Name is already in use. You may choose another name or " 
     112                  "cancel the connection."), 
     113                Gtk::Stock::DIALOG_QUESTION 
     114        ), 
     115        m_initial_name(initial_name), 
     116        m_label(_("New name:") ) 
     117{ 
     118        m_entry.signal_changed().connect( 
     119                sigc::mem_fun(*this, &NamePrompt::on_change) 
     120        ); 
     121 
     122        m_entry.set_text(m_initial_name); 
     123        m_entry.set_activates_default(true); 
     124 
     125        m_box.pack_start(m_label, Gtk::PACK_SHRINK); 
     126        m_box.pack_start(m_entry, Gtk::PACK_EXPAND_WIDGET); 
     127        m_box.set_spacing(10); 
     128 
     129        m_box.show_all(); 
     130        set_custom_widget(m_box); 
     131 
     132        m_entry.grab_focus(); 
     133} 
     134 
     135Glib::ustring Gobby::JoinProgressDialog::NamePrompt::get_name() const 
     136{ 
     137        return m_entry.get_text(); 
     138} 
     139 
     140void Gobby::JoinProgressDialog::NamePrompt::on_change() 
     141{ 
     142        const Glib::ustring name = m_entry.get_text(); 
     143 
     144        set_response_sensitive( 
     145                Gtk::RESPONSE_OK, 
     146                name != m_initial_name && !name.empty() 
     147        ); 
     148} 
     149 
     150Gobby::JoinProgressDialog::ColorPrompt:: 
     151        ColorPrompt(Gtk::Window& parent, 
     152                    const Gdk::Color& initial_color): 
     153        Prompt( 
     154                parent, 
     155                obby::login::errstring(obby::login::ERROR_COLOUR_IN_USE), 
     156                _("Colour is already in use. You may choose another colour or " 
     157                  "cancel the connection."), 
     158                Gtk::Stock::DIALOG_QUESTION 
     159        ) 
     160{ 
     161        m_button.set_color(initial_color); 
     162        m_button.show_all(); 
     163 
     164        set_custom_widget(m_button); 
     165        m_button.grab_focus(); 
     166} 
     167 
     168Gdk::Color Gobby::JoinProgressDialog::ColorPrompt::get_color() const 
     169{ 
     170        return m_button.get_color(); 
     171} 
     172 
     173Gobby::JoinProgressDialog::SessionPasswordPrompt:: 
     174        SessionPasswordPrompt(Gtk::Window& parent): 
     175        Prompt( 
     176                parent, 
     177                obby::login::errstring( 
     178                        obby::login::ERROR_WRONG_GLOBAL_PASSWORD 
     179                ), 
     180                _("Session password required. You have to type in the " 
     181                  "password to be able to join the obby session."), 
     182                Gtk::Stock::DIALOG_AUTHENTICATION 
     183        ), 
     184        m_label(_("Session password:") ) 
     185{ 
     186        m_entry.signal_changed().connect( 
     187                sigc::mem_fun(*this, &SessionPasswordPrompt::on_change) 
     188        ); 
     189 
     190        m_entry.set_activates_default(true); 
     191        m_entry.set_visibility(false); 
     192 
     193        m_box.pack_start(m_label, Gtk::PACK_SHRINK); 
     194        m_box.pack_start(m_entry, Gtk::PACK_EXPAND_WIDGET); 
     195        m_box.set_spacing(10); 
     196 
     197        m_box.show_all(); 
     198        set_custom_widget(m_box); 
     199        set_response_sensitive(Gtk::RESPONSE_OK, false); 
     200 
     201        m_entry.grab_focus(); 
     202} 
     203 
     204Glib::ustring Gobby::JoinProgressDialog::SessionPasswordPrompt:: 
     205        get_password() const 
     206{ 
     207        return m_entry.get_text(); 
     208} 
     209 
     210void Gobby::JoinProgressDialog::SessionPasswordPrompt::on_change() 
     211{ 
     212        set_response_sensitive(Gtk::RESPONSE_OK, !m_entry.get_text().empty() ); 
     213} 
     214 
     215Gobby::JoinProgressDialog::UserPasswordPrompt:: 
     216        UserPasswordPrompt(Gtk::Window& parent, 
     217                           const Glib::ustring& initial_name): 
     218        Prompt( 
     219                parent, 
     220                obby::login::errstring(obby::login::ERROR_WRONG_USER_PASSWORD), 
     221                make_user_password_info(initial_name), 
     222                Gtk::Stock::DIALOG_AUTHENTICATION 
     223        ), 
     224        m_initial_name(initial_name), m_table(2, 2), 
     225        m_lbl_name(_("New name:"), Gtk::ALIGN_RIGHT), 
     226        m_lbl_password(_("User password:"), Gtk::ALIGN_RIGHT) 
     227{ 
     228        m_ent_name.set_text(m_initial_name); 
     229        m_ent_password.set_visibility(false); 
     230 
     231        m_ent_name.set_activates_default(true); 
     232        m_ent_password.set_activates_default(true); 
     233 
     234        m_ent_name.signal_changed().connect( 
     235                sigc::mem_fun(*this, &UserPasswordPrompt::on_change) 
     236        ); 
     237 
     238        m_ent_password.signal_changed().connect( 
     239                sigc::mem_fun(*this, &UserPasswordPrompt::on_change) 
     240        ); 
     241 
     242        m_table.attach( 
     243                m_lbl_name, 
     244                0, 1, 0, 1, 
     245                Gtk::SHRINK, Gtk::SHRINK 
     246        ); 
     247 
     248        m_table.attach( 
     249                m_lbl_password, 
     250                0, 1, 1, 2, 
     251                Gtk::SHRINK, Gtk::SHRINK 
     252        ); 
     253 
     254        m_table.attach( 
     255                m_ent_name, 
     256                1, 2, 0, 1, 
     257                Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK 
     258        ); 
     259 
     260        m_table.attach( 
     261                m_ent_password, 
     262                1, 2, 1, 2, 
     263                Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK 
     264        ); 
     265 
     266        m_table.set_spacings(5); 
     267 
     268        set_response_sensitive(Gtk::RESPONSE_OK, false); 
     269        m_ent_password.grab_focus(); 
     270 
     271        m_table.show_all(); 
     272        set_custom_widget(m_table); 
     273 
     274        m_ent_password.grab_focus(); 
     275} 
     276 
     277Glib::ustring Gobby::JoinProgressDialog::UserPasswordPrompt::get_name() const 
     278{ 
     279        return m_ent_name.get_text(); 
     280} 
     281 
     282Glib::ustring Gobby::JoinProgressDialog::UserPasswordPrompt:: 
     283        get_password() const 
     284{ 
     285        return m_ent_password.get_text(); 
     286} 
     287 
     288void Gobby::JoinProgressDialog::UserPasswordPrompt::on_change() 
     289{ 
     290        const Glib::ustring name = m_ent_name.get_name(); 
     291        const Glib::ustring password = m_ent_password.get_name(); 
     292 
     293        set_response_sensitive( 
     294                Gtk::RESPONSE_OK, 
     295                !name.empty() && (name != m_initial_name || !password.empty()) 
     296        ); 
    84297} 
    85298 
     
    257470bool Gobby::JoinProgressDialog::on_prompt_name(connection_settings& settings) 
    258471{ 
    259         Gtk::HBox box; 
    260         Gtk::Label label(_("New name:") ); 
    261         Gtk::Entry entry; 
    262         entry.set_text(m_username); 
    263  
    264         box.pack_start(label, Gtk::PACK_SHRINK); 
    265         box.pack_start(entry, Gtk::PACK_EXPAND_WIDGET); 
    266         box.set_spacing(10); 
    267  
    268         Prompt prompt( 
    269                 *this, 
    270                 obby::login::errstring(net6::login::ERROR_NAME_IN_USE), 
    271                 _("Name is already in use. You may choose another name or " 
    272                   "cancel the connection."), 
    273                 box, 
    274                 Gtk::Stock::DIALOG_QUESTION 
    275         ); 
    276  
    277         prompt.set_response_sensitive(Gtk::RESPONSE_OK, false); 
    278  
    279         // We are using the logical_or and logical_not functions defined above, 
    280         // but the standard library provides functors like std::logical_or, but 
    281         // how to use these? 
    282         sigc::slot<void> changed_slot( 
    283                 sigc::compose( 
    284                         sigc::bind<0>( 
    285                                 sigc::mem_fun( 
    286                                         prompt, 
    287                                         &DefaultDialog::set_response_sensitive 
    288                                 ), 
    289                                 Gtk::RESPONSE_OK 
    290                         ), 
    291                         sigc::compose( 
    292                                 sigc::ptr_fun(&logical_and), 
    293                                 sigc::compose( 
    294                                         sigc::bind( 
    295                                                 sigc::ptr_fun(static_cast< 
    296                                                         compare_ustring_func 
    297                                                 >(&Glib::operator!=) ), 
    298                                                 sigc::ref(m_username) 
    299                                         ), 
    300                                         sigc::mem_fun( 
    301                                                 entry, 
    302                                                 &Gtk::Entry::get_text 
    303                                         ) 
    304                                 ), 
    305                                 sigc::compose( 
    306                                         sigc::ptr_fun(&logical_not), 
    307                                         sigc::compose( 
    308                                                 &Glib::ustring::empty, 
    309                                                 sigc::mem_fun( 
    310                                                         entry, 
    311                                                         &Gtk::Entry::get_text 
    312                                                 ) 
    313                                         ) 
    314                                 ) 
    315                         ) 
    316                 ) 
    317         ); 
    318  
    319         entry.signal_changed().connect(changed_slot); 
     472        NamePrompt prompt(*this, m_username); 
     473 
    320474        if(prompt.run() == Gtk::RESPONSE_OK) 
    321475        { 
    322                 settings.name = entry.get_text(); 
     476                settings.name = prompt.get_name(); 
    323477                m_username = settings.name; 
    324478                return true; 
     
    333487bool Gobby::JoinProgressDialog::on_prompt_colour(connection_settings& settings) 
    334488{ 
    335         ColorButton btn; 
    336         btn.set_color(m_color); 
    337  
    338         Prompt prompt( 
    339                 *this, 
    340                 obby::login::errstring(obby::login::ERROR_COLOUR_IN_USE), 
    341                 _("Colour is already in use. You may choose another colour or " 
    342                   "cancel the connection."), 
    343                 btn, 
    344                 Gtk::Stock::DIALOG_QUESTION 
    345         ); 
    346  
     489        ColorPrompt prompt(*this, m_color); 
    347490        if(prompt.run() == Gtk::RESPONSE_OK) 
    348491        { 
    349                 settings.colour = gdk_to_obby(btn.get_color() ); 
    350                 m_color = btn.get_color(); 
     492                settings.colour = gdk_to_obby(prompt.get_color() ); 
     493                m_color = prompt.get_color(); 
    351494                return true; 
    352495        } 
     
    361504        on_prompt_global_password(connection_settings& settings) 
    362505{ 
    363         Gtk::HBox box; 
    364         Gtk::Label label(_("Session password:") ); 
    365         Gtk::Entry entry; 
    366         entry.set_visibility(false); 
    367  
    368         box.pack_start(label, Gtk::PACK_SHRINK); 
    369         box.pack_start(entry, Gtk::PACK_EXPAND_WIDGET); 
    370         box.set_spacing(10); 
    371  
    372         Prompt prompt( 
    373                 *this, 
    374                 obby::login::errstring( 
    375                         obby::login::ERROR_WRONG_GLOBAL_PASSWORD 
    376                 ), 
    377                 _("Session password required. You have to type in the " 
    378                   "password to be able to join the obby session."), 
    379                 box, 
    380                 Gtk::Stock::DIALOG_AUTHENTICATION 
    381         ); 
    382  
    383         // Do not allow OK if the entry is empty 
    384         prompt.set_response_sensitive(Gtk::RESPONSE_OK, false); 
    385         entry.signal_changed().connect( 
    386                 sigc::compose( 
    387                         sigc::bind<0>( 
    388                                 sigc::mem_fun( 
    389                                         prompt, 
    390                                         &DefaultDialog::set_response_sensitive 
    391                                 ), 
    392                                 Gtk::RESPONSE_OK 
    393                         ), 
    394                         sigc::compose( 
    395                                 sigc::ptr_fun(&logical_not), 
    396                                 sigc::compose( 
    397                                         &Glib::ustring::empty, 
    398                                         sigc::mem_fun( 
    399                                                 entry, 
    400                                                 &Gtk::Entry::get_text 
    401                                         ) 
    402                                 ) 
    403                         ) 
    404                 ) 
    405         ); 
    406  
     506        SessionPasswordPrompt prompt(*this); 
    407507        if(prompt.run() == Gtk::RESPONSE_OK) 
    408508        { 
    409                 settings.global_password = entry.get_text(); 
     509                settings.global_password = prompt.get_password(); 
    410510                return true; 
    411511        } 
     
    420520        on_prompt_user_password(connection_settings& settings) 
    421521{ 
    422         Gtk::Table table; 
    423         Gtk::Label lbl_name(_("New name:"), Gtk::ALIGN_RIGHT); 
    424         Gtk::Label lbl_password(_("User password:"), Gtk::ALIGN_RIGHT); 
    425         Gtk::Entry ent_name; 
    426         Gtk::Entry ent_password; 
    427         ent_name.set_text(m_username); 
    428         ent_password.set_visibility(false); 
    429  
    430         table.attach(lbl_name, 0, 1, 0, 1, 
    431                 Gtk::SHRINK, Gtk::SHRINK); 
    432         table.attach(lbl_password, 0, 1, 1, 2, 
    433                 Gtk::SHRINK, Gtk::SHRINK); 
    434         table.attach(ent_name, 1, 2, 0, 1, 
    435                 Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); 
    436         table.attach(ent_password, 1, 2, 1, 2, 
    437                 Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); 
    438         table.set_spacings(5); 
    439  
    440         obby::format_string str( 
    441                 _("User password for user '%0%' required. You may either " 
    442                   "choose another user name, type in your user password or " 
    443                   "cancel the connection.") 
    444         ); 
    445  
    446         str << m_username; 
    447         Prompt prompt( 
    448                 *this, 
    449                 obby::login::errstring(obby::login::ERROR_WRONG_USER_PASSWORD), 
    450                 str.str(), 
    451                 table, 
    452                 Gtk::Stock::DIALOG_AUTHENTICATION 
    453         ); 
    454  
    455         prompt.set_response_sensitive(Gtk::RESPONSE_OK, false); 
    456         ent_password.grab_focus(); 
    457  
    458         sigc::slot<void> changed_slot( 
    459                 sigc::compose( 
    460                         sigc::bind<0>( 
    461                                 sigc::mem_fun( 
    462                                         prompt, 
    463                                         &DefaultDialog::set_response_sensitive 
    464                                 ), 
    465                                 Gtk::RESPONSE_OK 
    466                         ), 
    467                         sigc::compose( 
    468                                 sigc::ptr_fun(&logical_and), 
    469                                 sigc::compose( 
    470                                         sigc::ptr_fun(&logical_not), 
    471                                         sigc::compose( 
    472                                                 &Glib::ustring::empty, 
    473                                                 sigc::mem_fun( 
    474                                                         ent_name, 
    475                                                         &Gtk::Entry:: 
    476                                                                 get_text 
    477                                                 ) 
    478                                         ) 
    479                                 ), 
    480                                 sigc::compose( 
    481                                         sigc::ptr_fun(&logical_or), 
    482                                         sigc::compose( 
    483                                                 sigc::bind( 
    484                                                         sigc::ptr_fun(static_cast< 
    485                                                                 compare_ustring_func 
    486                                                         >(&Glib::operator!=) ), 
    487                                                         sigc::ref(m_username) 
    488                                                 ), 
    489                                                 sigc::mem_fun( 
    490                                                         ent_name, 
    491                                                         &Gtk::Entry::get_text 
    492                                                 ) 
    493                                         ), 
    494                                         sigc::compose( 
    495                                                 sigc::ptr_fun(&logical_not), 
    496                                                 sigc::compose( 
    497                                                         &Glib::ustring::empty, 
    498                                                         sigc::mem_fun( 
    499                                                                 ent_password, 
    500                                                                 &Gtk::Entry:: 
    501                                                                         get_text 
    502                                                         ) 
    503                                                 ) 
    504                                         ) 
    505                                 ) 
    506                         ) 
    507                 ) 
    508         ); 
    509  
    510         ent_name.signal_changed().connect(changed_slot); 
    511         ent_password.signal_changed().connect(changed_slot); 
    512  
     522        UserPasswordPrompt prompt(*this, m_username); 
    513523        if(prompt.run() == Gtk::RESPONSE_OK) 
    514524        { 
    515                 m_username = ent_name.get_text(); 
    516                 settings.name = ent_name.get_text(); 
    517                 settings.user_password = ent_password.get_text(); 
     525                m_username = prompt.get_name(); 
     526                settings.name = prompt.get_name(); 
     527                settings.user_password = prompt.get_password(); 
    518528                return true; 
    519529        } 
  • src/passworddialog.cpp

    r1662ea7 rdebf4ab  
    2323 
    2424Gobby::PasswordDialog::PasswordDialog(Gtk::Window& parent, 
    25                                       const Glib::ustring& title, 
    26                                       bool request) 
    27  : DefaultDialog(title, parent, true, true), m_request(request), 
    28    m_table(3, 3), 
    29    m_icon(Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_DIALOG), 
    30    m_lbl_password("Password:", Gtk::ALIGN_RIGHT), 
    31    m_lbl_conf_password("Confirm password:", Gtk::ALIGN_RIGHT) 
     25                                      const Glib::ustring& title): 
     26        Gtk::Dialog(title, parent, true, true), m_table(3, 3), 
     27        m_icon(Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_DIALOG), 
     28        m_lbl_password("Password:", Gtk::ALIGN_RIGHT), 
     29        m_lbl_conf_password("Confirm password:", Gtk::ALIGN_RIGHT) 
    3230{ 
    3331        m_ent_password.set_visibility(false); 
    3432        m_ent_conf_password.set_visibility(false); 
    3533        m_info.set_line_wrap(true); 
     34 
     35        m_ent_password.set_activates_default(true); 
     36        m_ent_conf_password.set_activates_default(true); 
    3637 
    3738        m_table.set_spacings(5); 
     
    5253        add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 
    5354        add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 
     55        set_default_response(Gtk::RESPONSE_OK); 
    5456 
    5557        show_all(); 
     
    5860        m_info.hide(); 
    5961 
    60         // Hide confirm password fields if a password is requested 
    61         if(request) 
    62         { 
    63                 m_lbl_conf_password.hide(); 
    64                 m_ent_conf_password.hide(); 
    65         } 
    66         else 
    67         { 
    68                 m_ent_password.signal_changed().connect( 
    69                         sigc::mem_fun( 
    70                                 *this, 
    71                                 &PasswordDialog::on_password_changed 
    72                         ) 
    73                 ); 
     62        m_ent_password.signal_changed().connect( 
     63                sigc::mem_fun(*this, &PasswordDialog::on_password_changed) 
     64        ); 
    7465 
    75                 m_ent_conf_password.signal_changed().connect( 
    76                         sigc::mem_fun( 
    77                                 *this, 
    78                                 &PasswordDialog::on_password_changed 
    79                         ) 
    80                 ); 
    81         } 
     66        m_ent_conf_password.signal_changed().connect( 
     67                sigc::mem_fun(*this, &PasswordDialog::on_password_changed) 
     68        ); 
    8269 
    8370        set_response_sensitive(Gtk::RESPONSE_OK, false); 
     
    8572        set_resizable(false); 
    8673        set_border_width(10); 
    87 } 
    88  
    89 Gobby::PasswordDialog::~PasswordDialog() 
    90 { 
    9174} 
    9275 
  • src/window.cpp

    r84c0261 rdebf4ab  
    903903{ 
    904904        // Build password dialog with info 
    905         PasswordDialog dlg(*this, _("Set user password"), false); 
     905        PasswordDialog dlg(*this, _("Set user password") ); 
    906906        dlg.set_info(_( 
    907907                "Set a user password for your user account. When you try to "