sgpemv2/src/graphical_preferences_edito...

208 lines
5.9 KiB
C++
Raw Normal View History

// 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();
prefs.write_configrc();
}
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()
{
}