From 64585113998f51ab30767fcc13c87e7390c0be73 Mon Sep 17 00:00:00 2001 From: matrevis Date: Thu, 7 Sep 2006 00:23:50 +0000 Subject: [PATCH] - Preferences completed. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1032 3ecf2c5c-341e-0410-92b4-d18e462d057c --- glade/configure-dialog.glade | 2 -- src/backend/global_preferences.cc | 12 +++++-- src/graphical_preferences_editor.cc | 51 +++++++++++++++++++++++++---- src/parse_opts.cc | 2 +- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/glade/configure-dialog.glade b/glade/configure-dialog.glade index 3183b33..1621521 100644 --- a/glade/configure-dialog.glade +++ b/glade/configure-dialog.glade @@ -230,7 +230,6 @@ True - False True True gtk-remove @@ -475,7 +474,6 @@ True - False True True gtk-remove diff --git a/src/backend/global_preferences.cc b/src/backend/global_preferences.cc index d2f7597..330fecb 100644 --- a/src/backend/global_preferences.cc +++ b/src/backend/global_preferences.cc @@ -194,6 +194,12 @@ GlobalPreferences::key_file_read(KeyFile& kf) _mod_dirs.clear(); _pol_dirs.clear(); + std::vector old_mod_dirs(1, PLUGDIR); + std::vector old_pol_dirs(1, POLDIR); + _mod_dirs = old_mod_dirs; + _pol_dirs = old_pol_dirs; + + // read speed { int new_speed = 1000; // use a default value @@ -218,14 +224,14 @@ GlobalPreferences::key_file_read(KeyFile& kf) ostr << "modules-dir-" << i; Glib::ustring key(ostr.str()); val = kf.search_value(key); - if (val) + if (val && *val != _mod_dirs[0]) { // add_modules_dir(*val); _mod_dirs.push_back(*val); } } } - } + } // read policies directories { @@ -241,7 +247,7 @@ GlobalPreferences::key_file_read(KeyFile& kf) ostr << "policies-dir-" << i; Glib::ustring key(ostr.str().c_str()); val = kf.search_value(key); - if (val) + if (val && *val != _pol_dirs[0]) { // add_policies_dir(*val); _pol_dirs.push_back(*val); diff --git a/src/graphical_preferences_editor.cc b/src/graphical_preferences_editor.cc index 6f49b13..ba5b144 100644 --- a/src/graphical_preferences_editor.cc +++ b/src/graphical_preferences_editor.cc @@ -82,7 +82,7 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile) - // List of the policies search paths + // List of the plugins search paths // set up the model Gtk::TreeModelColumnRecord column_record_plugins_dirs; @@ -95,6 +95,7 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile) _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); + plugins_dirs_treeview->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); // update the model with the backend information typedef std::vector Strings; @@ -108,7 +109,7 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile) { // 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(); + Gtk::TreeModel::iterator new_row = plugins_dirs_model->append(); new_row->set_value(0, *i_pd); } // when the model gets updated, the associated TreeView @@ -169,6 +170,7 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile) _refXml->get_widget("Policies.Additional.TreeView", policies_dirs_treeview); policies_dirs_treeview->set_model(policies_dirs_model); policies_dirs_treeview->append_column("path", column_path_policies_dirs); + policies_dirs_treeview->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); // update the model with the backend information typedef std::vector Strings; @@ -182,7 +184,7 @@ PreferencesEditor::PreferencesEditor(const std::string& gladefile) { // 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(); + Gtk::TreeModel::iterator new_row = policies_dirs_model->append(); new_row->set_value(0, *i_pd); } // when the model gets updated, the associated TreeView @@ -319,7 +321,8 @@ PreferencesEditor::on_add_plugins_dir() if (response == Gtk::RESPONSE_OK) { path = ask_path->get_filename(); - GlobalPreferences::get_instance().add_modules_dir(path); + std::vector& modules = GlobalPreferences::get_instance().get_plugin_dirs(); + modules.push_back(path); Gtk::TreeModel::iterator new_row = plugins_dirs_model->append(); new_row->set_value(0, path); @@ -331,7 +334,23 @@ PreferencesEditor::on_add_plugins_dir() void PreferencesEditor::on_remove_plugins_dir() { - // Feature not supported by backend + std::vector& modules = GlobalPreferences::get_instance().get_plugin_dirs(); + std::vector::iterator mit = modules.begin(); + Glib::RefPtr selection = plugins_dirs_treeview->get_selection(); + Gtk::TreeModel::iterator pit = plugins_dirs_model->children().begin(); + while(pit && mit != modules.end()) + { + if(selection->is_selected(pit)) + { + modules.erase(mit); + pit = plugins_dirs_model->erase(pit); + } + else + { + mit++; + pit++; + } + } } @@ -352,7 +371,8 @@ PreferencesEditor::on_add_policies_dir() if (response == Gtk::RESPONSE_OK) { path = ask_path->get_filename(); - GlobalPreferences::get_instance().add_policies_dir(path); + std::vector& policies = GlobalPreferences::get_instance().get_policy_dirs(); + policies.push_back(path); Gtk::TreeModel::iterator new_row = policies_dirs_model->append(); new_row->set_value(0, path); @@ -364,7 +384,24 @@ PreferencesEditor::on_add_policies_dir() void PreferencesEditor::on_remove_policies_dir() { - // Feature not supported by backend + std::vector& policies = GlobalPreferences::get_instance().get_policy_dirs(); + std::vector::iterator mit = policies.begin(); + Glib::RefPtr selection = policies_dirs_treeview->get_selection(); + Gtk::TreeModel::iterator pit = policies_dirs_model->children().begin(); + while(pit && mit != policies.end()) + { + if(selection->is_selected(pit)) + { + policies.erase(mit); + pit = policies_dirs_model->erase(pit); + } + else + { + mit++; + pit++; + } + } + } diff --git a/src/parse_opts.cc b/src/parse_opts.cc index 1166bde..062701b 100644 --- a/src/parse_opts.cc +++ b/src/parse_opts.cc @@ -103,7 +103,7 @@ parse_options(int argc, char** argv) GlobalPreferences& prefs = GlobalPreferences::get_instance(); try { - //prefs.load_configrc(); + prefs.load_configrc(); } catch (std::exception e)