- Do things in a more C++ style

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@739 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-06 12:23:29 +00:00
parent 483cf2815d
commit f84c7bbf40
3 changed files with 62 additions and 35 deletions

View File

@ -21,9 +21,8 @@
#include "config.h"
#include "gettext.h"
#include "start_gui.hh"
#include "gui_builder.hh"
#include <libglademm/xml.h>
#include <glibmm/ustring.h>
#include <gtkmm/aboutdialog.h>
#include <gtkmm/main.h>
@ -32,42 +31,57 @@
#include <cassert>
#include <iostream>
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<Glade::Xml> 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;
}

View File

@ -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 <gtkmm/window.h>
#include <libglademm/xml.h>
#include <string>
/** \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<Gnome::Glade::Xml> _refXml;
};
} //~ namespace sgpem
#endif //~ GUI_BUILDER_HH

View File

@ -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 <glibmm/optioncontext.h>
#include <gtkmm/main.h>
@ -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;
}