I'm trying to add an info bar to a dialog when my program is not connected to the databse. The info bar shows, however, if I close the dialog and open it again, every time there is a new button. Here's my code:
Window.hpp
class Window: public Gtk::Window {
private:
/// more things
Gtk::InfoBar info;
Gtk::Container* infoBarContainer;
Gtk::Label info_label;
protected:
void onConnectedBody(void);
void onNotConnectedBody(void);
void onInfoBarResponse(int response);
void onMenuDbConnect(void);
void onMenuDbDisconnect(void);
public:
/// more things...
};
Window.cpp
Window::Window(
) :
infoBarContainer(0),
info_label("")
{
// more things
info.add_button(Gtk::Stock::OK, 0);
infoBarContainer = dynamic_cast<Gtk::Container*>(info.get_content_area());
if( infoBarContainer ) infoBarContainer->add(info_label);
}
Window::onMenuDbConnect(){
if( controller->Connected() ) {
onConnectedBody();
} else {
onNotConnectedBody();
}
}
Window::onConnectedBody(){
Gtk::Dialog dialog("Connected to database",true,true);
dialog.set_resizable( false );
dialog.set_has_separator(true);
Gtk::Button close;
Gtk::VBox* vbox = dialog.get_vbox();
Gtk::Label label;
label.set_markup("<b>Already connected.</b>");
vbox->pack_start(label,false,false);
close.set_label("Close");
close.signal_clicked().connect(sigc::mem_fun(*this,&Window::onButtonClose));
dialog.set_size_request(250,80);
vbox = 0;
close.set_can_default( true );
dialog.add_action_widget(close,1);
close.grab_default();
dialog.show_all_children();
dialog.run();
}
Window::onNotConnectedBody(){
Gtk::Dialog dialog("Connect to database",true,true);
dialog.set_resizable( false );
dialog.set_has_separator(true);
Gtk::Button close;
Gtk::VBox* b = dialog.get_vbox();
info.signal_response().connect(sigc::mem_fun(*this,&Window::onInfoBarResponse) );
info_label.set_text("Remember to fill all fields");
b->pack_start(info,Gtk::PACK_SHRINK);
Gtk::Label label;
label.set_markup("<b>Database:</b>");
Gtk::Label label_host;
label_host.set_markup("<b>Host:</b>");
Gtk::Label label_user;
label_user.set_markup("<b>User:</b>");
Gtk::Label label_pass;
label_pass.set_markup("<b>Pass:</b>");
label.set_justify(Gtk::JUSTIFY_LEFT);
label_host.set_justify(Gtk::JUSTIFY_LEFT);
label_user.set_justify(Gtk::JUSTIFY_LEFT);
label_pass.set_justify(Gtk::JUSTIFY_LEFT);
entry.set_max_length(10);
entry.set_text("Figures");
entry_host.set_text("localhost");
label.set_markup("<b>Database:</b>");
b->pack_start(label,false,false);
b->pack_start(entry,false,false);
b->pack_start(label_host,false,false);
b->pack_start(entry_host,false,false);
b->pack_start(label_user,false,false);
b->pack_start(entry_user,false,false);
b->pack_start(label_pass,false,false);
b->pack_start(entry_pass,false,false);
close.set_label("Connect");
close.signal_clicked().connect(sigc::mem_fun(*this,&Window::onButtonDbConnect));
close.set_can_default( true );
dialog.add_action_widget(close,1);
close.grab_default();
dialog.set_size_request(250,250);
dialog.show_all_children();
dialog.run();
}
void Window::onInfoBarResponse(int response) {
info.hide();
}
So, what I want is to show the info bar whenever I enter the onMenuDbConnect and is not yet connected to the database. If it is connected, no info bar is shown. The other components of my program, like the DB controller, works perfectly.
Any ideas? Thaanks.