diff --git a/glade/configure-dialog.glade b/glade/configure-dialog.glade index e8a4a84..7abb7e6 100644 --- a/glade/configure-dialog.glade +++ b/glade/configure-dialog.glade @@ -345,7 +345,7 @@ GTK_CORNER_TOP_LEFT - + True True True diff --git a/src/backend/module.cc b/src/backend/module.cc index 5ae8676..754e5a8 100644 --- a/src/backend/module.cc +++ b/src/backend/module.cc @@ -22,6 +22,9 @@ #include "module.hh" +// FIXME: remove this header +#include + using namespace sgpem; Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) : diff --git a/src/graphical_preferences_editor.cc b/src/graphical_preferences_editor.cc index 217a03e..c2d2218 100644 --- a/src/graphical_preferences_editor.cc +++ b/src/graphical_preferences_editor.cc @@ -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 #include - - +// FIXME: remove include +#include 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 column_name_plug; + Gtk::TreeModelColumn column_desc_plug; + Gtk::TreeModelColumn 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 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 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 column_name_pol; + Gtk::TreeModelColumn 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 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 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 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 Managers; + typedef std::vector 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 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(speed_spin->get_value())); } + PreferencesEditor::~PreferencesEditor() { } - diff --git a/src/graphical_preferences_editor.hh b/src/graphical_preferences_editor.hh index 0f20d65..9346bd9 100644 --- a/src/graphical_preferences_editor.hh +++ b/src/graphical_preferences_editor.hh @@ -67,13 +67,28 @@ namespace sgpem ~PreferencesEditor(); private: + + void + update_policies(); + + void + update_plugins(); + Glib::RefPtr _refXml; - GlobalPreferences& prefs; Gtk::Dialog* preferences_dialog; + Gtk::TreeView* plugins_dirs_treeview; Glib::RefPtr plugins_dirs_model; + + Gtk::TreeView* plugins_treeview; + Glib::RefPtr plugins_model; + Gtk::TreeView* policies_dirs_treeview; Glib::RefPtr policies_dirs_model; + + Gtk::TreeView* policies_treeview; + Glib::RefPtr policies_model; + Gtk::SpinButton* speed_spin; }; diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 0598572..0024542 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -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(changed_simulation.get_front()) - 1; - else - printed_instant = 0; + printed_instant = static_cast(changed_simulation.get_front()) - 1; oss << endl << ">>>> " << printed_instant;