config_edit_dialog.cpp

00001
00002 /***************************************************************************
00003  *  config_edit_dialog.cpp - Edit config entries
00004  *
00005  *  Created: Wed Sep 24 15:44:46 2008
00006  *  Copyright  2008  Daniel Beck
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022
00023 #include <tools/config_editor/config_edit_dialog.h>
00024 #include <gui_utils/utils.h>
00025
00026 using namespace fawkes;
00027 
00028 /** @class ConfigEditDialog tools/config_editor/config_edit_dialog.h
00029  * Dialog to edit a config value.
00030  *
00031  * @author Daniel Beck
00032  */
00033 
00034 /** @var ConfigEditDialog::is_bool
00035  * A flag to store wether the config value is boolean.
00036  */
00037 
00038 /** @var ConfigEditDialog::m_ent_value
00039  * An entry field to edit the config value.
00040  */
00041 
00042 /** @var ConfigEditDialog::m_cob_bool_value
00043  * A combo box to select TRUE or FALSE
00044  */
00045 
00046 /** @var ConfigEditDialog::m_type_pages
00047  * A Gtk::Notebook element to switch between boolean values and the rest
00048  */
00049 
00050 /** @var ConfigEditDialog::m_chb_is_default
00051  * The Gtk::CheckButton to set the default flag
00052  */
00053 
00054 /** Constructor.
00055  * @param cobject pointer to base object type
00056  * @param ref_xml Glade XML file
00057  */
00058 ConfigEditDialog::ConfigEditDialog( BaseObjectType* cobject,
00059                                     const Glib::RefPtr<Gnome::Glade::Xml>& ref_xml )
00060   : Gtk::Dialog(cobject)
00061 {
00062   m_ent_value      = dynamic_cast<Gtk::Entry*>( get_widget(ref_xml, "entValueEdit") );
00063   m_cob_bool_value = dynamic_cast<Gtk::ComboBox*>( get_widget(ref_xml, "cmbBoolEdit") );
00064   m_type_pages     = dynamic_cast<Gtk::Notebook*>( get_widget(ref_xml, "nbkTypesEdit") );
00065   m_chb_is_default = dynamic_cast<Gtk::CheckButton*>( get_widget(ref_xml, "chbIsDefaultEdit") );
00066 }
00067 
00068 /** Initialize the dialog.
00069  * @param path config path
00070  * @param type type of config entry
00071  * @param value value of the config entry
00072  */
00073 void
00074 ConfigEditDialog::init( const Glib::ustring& path, const Glib::ustring& type,
00075                         const Glib::ustring& value )
00076 {
00077   is_bool = (type == "bool");
00078   set_title(path);
00079   m_ent_value->set_text(value);
00080   m_cob_bool_value->set_active(value == "TRUE" ? 0 : 1);
00081   m_type_pages->set_current_page(!is_bool ? 0 : 1);
00082   m_chb_is_default->set_active(false);
00083 }
00084 
00085 /** Destructor. */
00086 ConfigEditDialog::~ConfigEditDialog()
00087 {
00088 }
00089 
00090 /** Get the value of the entry widget.
00091  * @return the text in the entry widget
00092  */
00093 Glib::ustring
00094 ConfigEditDialog::get_value() const
00095 {
00096   if (!is_bool) return m_ent_value->get_text();
00097   else
00098     {
00099       Gtk::TreeIter iter = m_cob_bool_value->get_active();
00100       Gtk::TreeRow row = *iter;
00101       Glib::ustring type;
00102
00103       row.get_value(0, type);
00104
00105       return type;
00106     }
00107 }
00108 
00109 /** Get the default flag of the new entry
00110  * @return if true edit the default config database
00111  */
00112 bool
00113 ConfigEditDialog::get_is_default() const
00114 {
00115   return m_chb_is_default->get_active();
00116 }