- Better Preferences management

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@987 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-01 23:28:23 +00:00
parent 23e24e87e5
commit d570314405
5 changed files with 222 additions and 42 deletions

View File

@ -345,7 +345,7 @@
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="Policies.Loaded.Treeview">
<widget class="GtkTreeView" id="Policies.Loaded.TreeView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>

View File

@ -22,6 +22,9 @@
#include "module.hh"
// FIXME: remove this header
#include <iostream>
using namespace sgpem;
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :

View File

@ -22,51 +22,96 @@
#include "gettext.h"
#include "graphical_preferences_editor.hh"
#include "backend/cpu_policy_manager.hh"
#include "backend/cpu_policies_gatekeeper.hh"
#include "backend/cpu_policy.hh"
#include "backend/module.hh"
#include "backend/plugin_manager.hh"
#include <glibmm/ustring.h>
#include <gtkmm/filechooserdialog.h>
// FIXME: remove include
#include <iostream>
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(Xml::create(gladefile)),
preferences_dialog(NULL),
plugins_dirs_treeview(NULL), plugins_treeview(NULL),
policies_dirs_treeview(NULL), policies_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
// - Plugins
// - create model
Gtk::TreeModelColumnRecord model_columns;
// List of the currently loaded plugins
// set up the model
Gtk::TreeModelColumnRecord column_record_plugins;
Gtk::TreeModelColumn<Glib::ustring> column_name_plug;
Gtk::TreeModelColumn<Glib::ustring> column_desc_plug;
Gtk::TreeModelColumn<Glib::ustring> column_author_plug;
column_record_plugins.add(column_name_plug);
column_record_plugins.add(column_desc_plug);
column_record_plugins.add(column_author_plug);
plugins_model = Gtk::ListStore::create(column_record_plugins);
// set up the widget
_refXml->get_widget("Plugins.Loaded.TreeView", plugins_treeview);
plugins_treeview->set_model(plugins_model);
plugins_treeview->append_column("name", column_name_plug);
plugins_treeview->append_column("description", column_desc_plug);
plugins_treeview->append_column("author", column_author_plug);
// update the model with the backend information
update_plugins();
// List of the policies search paths
// set up the model
Gtk::TreeModelColumnRecord column_record_plugins_dirs;
Gtk::TreeModelColumn<Glib::ustring> single_column;
model_columns.add(single_column);
column_record_plugins_dirs.add(single_column);
plugins_dirs_model = Gtk::ListStore::create(column_record_plugins_dirs);
// here is our model
plugins_dirs_model = Gtk::ListStore::create(model_columns);
// set up the widget
_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
// update the model with the backend information
typedef std::vector<Glib::ustring> Strings;
Strings & plugin_dirs = prefs.get_plugin_dirs();
// clear the content of the model
plugins_dirs_model->clear();
// for all the paths provided by the singleton global preferences
Strings plugin_dirs = GlobalPreferences::get_instance().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
// append one record to the model, describing the path
// note that plugin dirs are returned in reverse order
Gtk::TreeModel::iterator new_row = plugins_dirs_model->prepend();
new_row->set_value(0, *i_pd);
}
// when the model gets updated, the associated TreeView
// widget is automatically updated
// Add and remove directory buttons
Gtk::Button* add_plugins_dir = NULL;
_refXml->get_widget("Plugins.Add", add_plugins_dir);
@ -78,33 +123,66 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile)
// ========================================
// POLICIES
// List of the currently loaded policies
// set up the model
Gtk::TreeModelColumnRecord column_record_policies;
Gtk::TreeModelColumn<Glib::ustring> column_name_pol;
Gtk::TreeModelColumn<Glib::ustring> column_desc_pol;
column_record_policies.add(column_name_pol);
column_record_policies.add(column_desc_pol);
policies_model = Gtk::ListStore::create(column_record_policies);
// set up the widget
_refXml->get_widget("Policies.Loaded.TreeView", policies_treeview);
policies_treeview->set_model(policies_model);
policies_treeview->append_column("name", column_name_pol);
policies_treeview->append_column("description", column_desc_pol);
// update the model with the backend information
update_policies();
// - Policies
// - create model
Gtk::TreeModelColumnRecord model_columns2;
Gtk::TreeModelColumn<Glib::ustring> single_column2;
model_columns2.add(single_column2);
// List of the policies search paths
// here is our model
policies_dirs_model = Gtk::ListStore::create(model_columns2);
// set up the model
Gtk::TreeModelColumnRecord column_record_policies_dirs;
Gtk::TreeModelColumn<Glib::ustring> column_path_policies_dirs;
column_record_policies_dirs.add(column_path_policies_dirs);
policies_dirs_model = Gtk::ListStore::create(column_record_policies_dirs);
// set up the widget
_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);
policies_dirs_treeview->append_column("path", column_path_policies_dirs);
// - fill model
// update the model with the backend information
typedef std::vector<Glib::ustring> Strings;
Strings & policies_dirs = prefs.get_policy_dirs();
// clear the content of the model
policies_dirs_model->clear();
// for all the paths provided by the singleton global preferences
Strings policies_dirs = GlobalPreferences::get_instance().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
// append one record to the model, describing the path
// note that policies dirs are returned in reverse order
Gtk::TreeModel::iterator new_row = policies_dirs_model->prepend();
new_row->set_value(0, *i_pd);
}
// when the model gets updated, the associated TreeView
// widget is automatically updated
// Add and remove directory buttons
Gtk::Button* add_policies_dir = NULL;
_refXml->get_widget("Policies.Add", add_policies_dir);
@ -116,26 +194,105 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile)
// - Speed
// ========================================
// SPEED
_refXml->get_widget("Speed.SpinButton", speed_spin);
speed_spin->set_value(prefs.get_speed());
speed_spin->set_value(GlobalPreferences::get_instance().get_speed());
speed_spin->signal_value_changed().connect(sigc::mem_fun(*this, &PreferencesEditor::on_set_speed));
// ========================================
// GENERAL
// Close button
Gtk::Button* close = NULL;
_refXml->get_widget("Close", close);
close->signal_clicked().connect(sigc::mem_fun(*this, &PreferencesEditor::on_close));
// Window& main_window = get_initial_window();
preferences_dialog->show();
}
void PreferencesEditor::update_policies()
{
typedef std::vector<CPUPolicyManager*> Managers;
typedef std::vector<CPUPolicy*> Policies;
// clear the content of the model
policies_model->clear();
// for all the cpu policy managers provided by the singleton gatekeeper
Managers managers = CPUPoliciesGatekeeper::get_instance().get_registered();
for (Managers::const_iterator i_m = managers.begin(); i_m != managers.end(); i_m++)
{
// for all the policies provided by the manager
const Policies & policies = (**i_m).get_avail_policies();
for (Policies::const_iterator i_p = policies.begin(); i_p != policies.end(); i_p++)
{
// append one record to the model, describing the policy
Gtk::TreeModel::iterator new_row = policies_model->append();
// featuring its name and its description
new_row->set_value(0, (**i_p).get_name());
new_row->set_value(1, (**i_p).get_description());
}
}
// when the model gets updated, the associated TreeView
// widget is automatically updated
}
void PreferencesEditor::update_plugins()
{
typedef std::vector<Module*> Modules;
// clear the content of the model
plugins_model->clear();
// for all the plugins provided by the singleton manager
Modules plugins = PluginManager::get_instance().get_module_list();
for (Modules::const_iterator i_p = plugins.begin(); i_p != plugins.end(); i_p++)
{
// append one record to the model, describing the plugin
Gtk::TreeModel::iterator new_row = plugins_model->append();
// featuring its name, its description, and its author
// FIXME: the plugins do not behave correctly
// new_row->set_value(0, (**i_p).get_name());
// new_row->set_value(1, (**i_p).describe());
// new_row->set_value(2, (**i_p).get_author());
// std::cout << (**i_p).get_name() << std::endl;
// std::cout << (**i_p).describe() << std::endl;
// std::cout << (**i_p).get_author().c_str() << std::endl;
Glib::ustring name("name!");
Glib::ustring author("author!");
Glib::ustring desc("description!");
new_row->set_value(0, name);
new_row->set_value(1, desc);
new_row->set_value(2, author);
}
// when the model gets updated, the associated TreeView
// widget is automatically updated
}
void
PreferencesEditor::on_close()
{
preferences_dialog->hide();
prefs.write_configrc();
GlobalPreferences::get_instance().write_configrc();
}
void
PreferencesEditor::on_add_plugins_dir()
{
@ -152,19 +309,23 @@ PreferencesEditor::on_add_plugins_dir()
if (response == Gtk::RESPONSE_OK)
{
path = ask_path->get_filename();
prefs.add_modules_dir(path);
GlobalPreferences::get_instance().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()
{
@ -181,27 +342,31 @@ PreferencesEditor::on_add_policies_dir()
if (response == Gtk::RESPONSE_OK)
{
path = ask_path->get_filename();
prefs.add_policies_dir(path);
GlobalPreferences::get_instance().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());
GlobalPreferences::get_instance().set_speed(static_cast<int>(speed_spin->get_value()));
}
PreferencesEditor::~PreferencesEditor()
{
}

View File

@ -67,13 +67,28 @@ namespace sgpem
~PreferencesEditor();
private:
void
update_policies();
void
update_plugins();
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* plugins_treeview;
Glib::RefPtr<Gtk::ListStore> plugins_model;
Gtk::TreeView* policies_dirs_treeview;
Glib::RefPtr<Gtk::ListStore> policies_dirs_model;
Gtk::TreeView* policies_treeview;
Glib::RefPtr<Gtk::ListStore> policies_model;
Gtk::SpinButton* speed_spin;
};

View File

@ -1664,10 +1664,7 @@ TextSimulation::update(const Simulation& changed_simulation)
// Print header for each instant:
if (changed_simulation.get_front() > 1)
printed_instant = static_cast<int>(changed_simulation.get_front()) - 1;
else
printed_instant = 0;
printed_instant = static_cast<int>(changed_simulation.get_front()) - 1;
oss << endl << ">>>> " << printed_instant;