From f84c7bbf40d4c5e9aaa8d3e529f3261d8bd81404 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Thu, 6 Jul 2006 12:23:29 +0000 Subject: [PATCH] - Do things in a more C++ style git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@739 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/{start_gui.cc => gui_builder.cc} | 56 +++++++++++++++++----------- src/{start_gui.hh => gui_builder.hh} | 28 +++++++++++--- src/parse_opts.cc | 13 +++---- 3 files changed, 62 insertions(+), 35 deletions(-) rename src/{start_gui.cc => gui_builder.cc} (71%) rename src/{start_gui.hh => gui_builder.hh} (62%) diff --git a/src/start_gui.cc b/src/gui_builder.cc similarity index 71% rename from src/start_gui.cc rename to src/gui_builder.cc index b5235b2..25b8766 100644 --- a/src/start_gui.cc +++ b/src/gui_builder.cc @@ -21,9 +21,8 @@ #include "config.h" #include "gettext.h" -#include "start_gui.hh" +#include "gui_builder.hh" -#include #include #include #include @@ -32,42 +31,57 @@ #include #include -Gtk::Window* -start_gui(const std::string& filename) +using namespace sgpem; +using Gnome::Glade::Xml; + + +GuiBuilder::GuiBuilder(const std::string& gladefile) + : _refXml(Xml::create(gladefile)) { - using namespace Gnome; using namespace Gtk; - // Debug line (erase me when done): - std::cout << _("Filename to open: ") << filename << std::endl; - - Glib::RefPtr refXml = - Glade::Xml::create(GLADEDIR "/main-window.glade"); - - Window* main_window = NULL; - refXml->get_widget("MainWindow", main_window); - assert(main_window != NULL); + Window& main_window = get_initial_window(); // Connect extra signals (decide where to do this... // here -- ugly -- derive widgets and then use // Glade::Xml::get_widget_derived -- better --) MenuItem* file_quit = NULL; - refXml->get_widget("MenuItem.File.Quit", file_quit); + _refXml->get_widget("MenuItem.File.Quit", file_quit); assert(file_quit != NULL); file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit)); // About dialog MenuItem* help_about = NULL; - refXml->get_widget("MenuItem.Help.About", help_about); + _refXml->get_widget("MenuItem.Help.About", help_about); assert(help_about != NULL); AboutDialog* about_dialog = NULL; - refXml->get_widget("AboutDialog", about_dialog); + _refXml->get_widget("AboutDialog", about_dialog); assert(about_dialog != NULL); help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show)); - // FIXME: Here open filename if != "" - - main_window->show_all_children(); - return main_window; + // main_window.show_all_children(); } + +GuiBuilder::~GuiBuilder() +{ +} + + +Gtk::Window& +GuiBuilder::get_initial_window() const +{ + Gtk::Window* main_window = NULL; + _refXml->get_widget("MainWindow", main_window); + assert(main_window != NULL); + return *main_window; +} + + +void +GuiBuilder::open_file(const std::string& filename) +{ + // FIXME: to be written. + // Debug line (erase me when done): + std::cout << _("Filename to open: ") << filename << std::endl; +} diff --git a/src/start_gui.hh b/src/gui_builder.hh similarity index 62% rename from src/start_gui.hh rename to src/gui_builder.hh index ec3bd10..bd6cddd 100644 --- a/src/start_gui.hh +++ b/src/gui_builder.hh @@ -1,4 +1,4 @@ -// src/startgui.hh - Copyright 2005, 2006, University +// src/gui_builder.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -18,19 +18,35 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#ifndef GTKGUI_STARTGUI_HH -#define GTKGUI_STARTGUI_HH 1 +#ifndef GUI_BUILDER_HH +#define GUI_BUILDER_HH 1 #include "config.h" #include +#include #include -/** \brief This function initialize and starts the whole GUI +/** \brief This class initialize and starts the whole GUI */ -Gtk::Window* start_gui(const std::string& filename); +namespace sgpem { -#endif + class GuiBuilder + { + public: + GuiBuilder(const std::string& gladefile = GLADEDIR "/main-window.glade"); + ~GuiBuilder(); + + Gtk::Window& get_initial_window() const; + void open_file(const std::string& filename); + + private: + Glib::RefPtr _refXml; + }; + +} //~ namespace sgpem + +#endif //~ GUI_BUILDER_HH diff --git a/src/parse_opts.cc b/src/parse_opts.cc index 9ec689d..b126583 100644 --- a/src/parse_opts.cc +++ b/src/parse_opts.cc @@ -23,8 +23,8 @@ #include "backend/global_preferences.hh" #include "backend/plugin_manager.hh" +#include "gui_builder.hh" #include "parse_opts.hh" -#include "start_gui.hh" #include #include @@ -121,12 +121,11 @@ parse_options(int argc, char** argv) } else { - Gtk::Window* main_window; + GuiBuilder* gui = new GuiBuilder(); if(fnames.begin() != fnames.end()) - main_window = start_gui(*fnames.begin()); - else - main_window = start_gui(""); - main_loop.run(*main_window); + gui->open_file(*fnames.begin()); + main_loop.run(gui->get_initial_window()); + delete gui; } } // ~ try catch(Glib::OptionError e) @@ -150,5 +149,3 @@ print_license() "see file COPYING contained in the source package. \n" << std::endl; } - -