- Added a best-effort preferences dialog:

the user may now add plugin directories,
  policy directories, and set the simulation
  speed.
- Added some menu voice to the main window.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@872 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-08-15 17:33:47 +00:00
parent 047f0b8f86
commit cfd7a025db
8 changed files with 1449 additions and 633 deletions

View file

@ -32,7 +32,7 @@ using namespace sgpem;
template class SG_DLLEXPORT Singleton<GlobalPreferences>;
GlobalPreferences::GlobalPreferences()
: _mod_dirs(1, PLUGDIR), _pol_dirs(1, POLDIR)
: _mod_dirs(1, PLUGDIR), _pol_dirs(1, POLDIR), _speed(1000)
{}

View file

@ -0,0 +1,206 @@
// src/graphical_preferences_editor.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#include "graphical_preferences_editor.hh"
#include <glibmm/ustring.h>
#include <gtkmm/filechooserdialog.h>
using namespace sgpem;
using Gnome::Glade::Xml;
PreferencesEditor::PreferencesEditor(const std::string& gladefile)
: _refXml(Xml::create(gladefile)), prefs(GlobalPreferences::get_instance()),
preferences_dialog(NULL), plugins_dirs_treeview(NULL), speed_spin(NULL)
{
_refXml->get_widget("ConfigureDialog", preferences_dialog);
// - General Dialog Settings
// preferences dialog
Gtk::Button* close = NULL;
_refXml->get_widget("Close", close);
close->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_close));
// - Plugins
// - create model
Gtk::TreeModelColumnRecord model_columns;
Gtk::TreeModelColumn<Glib::ustring> single_column;
model_columns.add(single_column);
// here is our model
plugins_dirs_model = Gtk::ListStore::create(model_columns);
_refXml->get_widget("Plugins.Additional.TreeView", plugins_dirs_treeview);
plugins_dirs_treeview->set_model(plugins_dirs_model);
plugins_dirs_treeview->append_column("path", single_column);
// - fill model
typedef std::vector<Glib::ustring> Strings;
Strings & plugin_dirs = prefs.get_plugin_dirs();
for (Strings::const_iterator i_pd = plugin_dirs.begin(); i_pd != plugin_dirs.end(); i_pd++)
{
Gtk::TreeModel::iterator new_row = plugins_dirs_model->prepend(); // plugin dirs are sorted by backend in reverse order
new_row->set_value(0, *i_pd);
}
Gtk::Button* add_plugins_dir = NULL;
_refXml->get_widget("Plugins.Add", add_plugins_dir);
add_plugins_dir->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_add_plugins_dir));
Gtk::Button* remove_plugins_dir = NULL;
_refXml->get_widget("Plugins.Remove", remove_plugins_dir);
remove_plugins_dir->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_remove_plugins_dir));
// - Policies
// - create model
Gtk::TreeModelColumnRecord model_columns2;
Gtk::TreeModelColumn<Glib::ustring> single_column2;
model_columns2.add(single_column2);
// here is our model
policies_dirs_model = Gtk::ListStore::create(model_columns2);
_refXml->get_widget("Policies.Additional.TreeView", policies_dirs_treeview);
policies_dirs_treeview->set_model(policies_dirs_model);
policies_dirs_treeview->append_column("path", single_column2);
// - fill model
typedef std::vector<Glib::ustring> Strings;
Strings & policies_dirs = prefs.get_policy_dirs();
for (Strings::const_iterator i_pd = policies_dirs.begin(); i_pd != policies_dirs.end(); i_pd++)
{
Gtk::TreeModel::iterator new_row = policies_dirs_model->prepend(); // plugin dirs are sorted by backend in reverse order
new_row->set_value(0, *i_pd);
}
Gtk::Button* add_policies_dir = NULL;
_refXml->get_widget("Policies.Add", add_policies_dir);
add_policies_dir->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_add_policies_dir));
Gtk::Button* remove_policies_dir = NULL;
_refXml->get_widget("Policies.Remove", remove_policies_dir);
remove_policies_dir->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_remove_policies_dir));
// - Speed
_refXml->get_widget("Speed.SpinButton", speed_spin);
speed_spin->set_value(prefs.get_speed());
speed_spin->signal_value_changed().connect(sigc::mem_fun(*this, &PreferencesEditor::on_set_speed));
// Window& main_window = get_initial_window();
preferences_dialog->show();
}
void
PreferencesEditor::on_close()
{
preferences_dialog->hide();
}
void
PreferencesEditor::on_add_plugins_dir()
{
// I must get a string
Glib::ustring path;
Gtk::FileChooserDialog* ask_path = new Gtk::FileChooserDialog::FileChooserDialog(
_("Select a directory to add"),
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path);
ask_path->add_button("gtk-cancel", Gtk::RESPONSE_CANCEL);
ask_path->add_button("gtk-ok", Gtk::RESPONSE_OK);
ask_path->show();
int response = ask_path->run();
ask_path->hide();
if (response == Gtk::RESPONSE_OK)
{
path = ask_path->get_filename();
prefs.add_modules_dir(path);
Gtk::TreeModel::iterator new_row = plugins_dirs_model->append();
new_row->set_value(0, path);
}
}
void
PreferencesEditor::on_remove_plugins_dir()
{
// Feature not supported by backend
}
void
PreferencesEditor::on_add_policies_dir()
{
// I must get a string
Glib::ustring path;
Gtk::FileChooserDialog* ask_path = new Gtk::FileChooserDialog::FileChooserDialog(
_("Select a directory to add"),
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path);
ask_path->add_button("gtk-cancel", Gtk::RESPONSE_CANCEL);
ask_path->add_button("gtk-ok", Gtk::RESPONSE_OK);
ask_path->show();
int response = ask_path->run();
ask_path->hide();
if (response == Gtk::RESPONSE_OK)
{
path = ask_path->get_filename();
prefs.add_policies_dir(path);
Gtk::TreeModel::iterator new_row = policies_dirs_model->append();
new_row->set_value(0, path);
}
}
void
PreferencesEditor::on_remove_policies_dir()
{
// Feature not supported by backend
}
void
PreferencesEditor::on_set_speed()
{
prefs.set_speed(speed_spin->get_value());
}
PreferencesEditor::~PreferencesEditor()
{
}

View file

@ -0,0 +1,83 @@
// src/graphical_preferences_editor.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef GRAPHICAL_PREFERENCES_EDITOR_HH
#define GRAPHICAL_PREFERENCES_EDITOR_HH 1
#include "config.h"
#include "backend/global_preferences.hh"
#include <libglademm/xml.h>
#include <gtkmm/liststore.h>
#include <gtkmm/dialog.h>
#include <gtkmm/treeview.h>
#include <gtkmm/spinbutton.h>
#include <string>
namespace sgpem
{
class PreferencesEditor
{
public:
PreferencesEditor(const std::string& gladefile = GLADEDIR "/configure-dialog.glade");
void
on_close();
void
on_add_plugins_dir();
void
on_remove_plugins_dir();
void
on_add_policies_dir();
void
on_remove_policies_dir();
void
on_set_speed();
~PreferencesEditor();
private:
Glib::RefPtr<Gnome::Glade::Xml> _refXml;
GlobalPreferences& prefs;
Gtk::Dialog* preferences_dialog;
Gtk::TreeView* plugins_dirs_treeview;
Glib::RefPtr<Gtk::ListStore> plugins_dirs_model;
Gtk::TreeView* policies_dirs_treeview;
Glib::RefPtr<Gtk::ListStore> policies_dirs_model;
Gtk::SpinButton* speed_spin;
};
}
#endif

View file

@ -25,6 +25,7 @@
#include "simulation_widget.hh"
#include "gui_builder.hh"
#include "graphical_preferences_editor.hh"
#include "backend/history.hh"
#include "backend/simulation.hh"
@ -49,13 +50,19 @@ test_me()
sim.get_history().add_process("goofy", 0, 0);
}
void
GuiBuilder::on_edit_preferences_activate()
{
new PreferencesEditor(); //FIXME: are we leaking this way?
}
GuiBuilder::GuiBuilder(const std::string& gladefile)
: _refXml(Xml::create(gladefile))
{
using namespace Gtk;
Window& main_window = get_initial_window();
//Window& main_window = get_initial_window();
// Connect extra signals (decide where to do this...
// here -- ugly -- derive widgets and then use
@ -64,13 +71,29 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
_refXml->get_widget("MenuItem.File.Quit", file_quit);
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
// preferences dialog
MenuItem* edit_preferences = NULL;
_refXml->get_widget("MenuItem.Edit.Preferences", edit_preferences);
edit_preferences->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
// About dialog
MenuItem* help_about = NULL;
_refXml->get_widget("MenuItem.Help.About", help_about);
AboutDialog* about_dialog = NULL;
_refXml->get_widget("AboutDialog", about_dialog);
//help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
help_about->signal_activate().connect(sigc::ptr_fun(test_me));
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
// Random Error Generator
MenuItem* debug_error = NULL;
_refXml->get_widget("MenuItem.Debug.Error", debug_error);
debug_error->signal_activate().connect(sigc::ptr_fun(test_me));
// Temporary code to test the Schedulables custom widget
Expander* scheds_expander = NULL;
@ -82,6 +105,8 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
scheds_widget->show();
// Main simulation widget
ScrolledWindow* simulation_window = NULL;
_refXml->get_widget("SimulationScrolledWindow", simulation_window);

View file

@ -42,6 +42,7 @@ namespace sgpem
Gtk::Window& get_initial_window() const;
void open_file(const std::string& filename);
void on_edit_preferences_activate();
private:
Glib::RefPtr<Gnome::Glade::Xml> _refXml;