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 
00025 /** @class ConfigEditDialog "config_edit_dialog.h"
00026  * Dialog to edit a config value.
00027  *
00028  * @author Daniel Beck
00029  */
00030 
00031 /** @var ConfigEditDialog::is_bool
00032  * A flag to store wether the config value is boolean.
00033  */
00034 
00035 /** @var ConfigEditDialog::m_ent_value
00036  * An entry field to edit the config value.
00037  */
00038 
00039 /** @var ConfigEditDialog::m_cob_bool_value
00040  * A combo box to select TRUE or FALSE
00041  */
00042 
00043 /** @var ConfigEditDialog::m_type_pages
00044  * A Gtk::Notebook element to switch between boolean values and the rest
00045  */
00046 
00047 /** @var ConfigEditDialog::m_chb_is_default
00048  * The Gtk::CheckButton to set the default flag
00049  */
00050 
00051 /** Constructor.
00052  * @param ent_value entry field for value
00053  * @param cob_bool_value combo box for bool value
00054  * @param type_pages pages for types
00055  * @param chb_is_default checkbutton to mark default values
00056  */     
00057 ConfigEditDialog::ConfigEditDialog(Gtk::Entry *ent_value, Gtk::ComboBox *cob_bool_value,
00058                                    Gtk::Notebook *type_pages, Gtk::CheckButton *chb_is_default)
00059   : Gtk::Dialog()
00060 {
00061   m_ent_value       = m_ent_value;
00062   m_cob_bool_value  = cob_bool_value;
00063   m_type_pages      = type_pages;
00064   m_chb_is_default  = chb_is_default;
00065 }
00066 
00067 #ifdef HAVE_GLADEMM
00068 /** Constructor.
00069  * @param cobject pointer to base object type
00070  * @param ref_xml Glade XML file
00071  */     
00072 ConfigEditDialog::ConfigEditDialog( BaseObjectType* cobject,
00073                                     const Glib::RefPtr<Gnome::Glade::Xml>& ref_xml )
00074   : Gtk::Dialog(cobject)
00075 {
00076   ref_xml->get_widget("entValueEdit", m_ent_value);
00077   ref_xml->get_widget("cmbBoolEdit", m_cob_bool_value);
00078   ref_xml->get_widget("nbkTypesEdit", m_type_pages);
00079   ref_xml->get_widget("chbIsDefaultEdit", m_chb_is_default);
00080 }
00081 #endif
00082 
00083 /** Initialize the dialog.
00084  * @param path config path
00085  * @param type type of config entry
00086  * @param value value of the config entry
00087  */
00088 void
00089 ConfigEditDialog::init( const Glib::ustring& path, const Glib::ustring& type,
00090                         const Glib::ustring& value )
00091 {
00092   is_bool = (type == "bool");
00093   set_title(path);
00094   m_ent_value->set_text(value);
00095   m_cob_bool_value->set_active(value == "TRUE" ? 0 : 1);
00096   m_type_pages->set_current_page(!is_bool ? 0 : 1);
00097   m_chb_is_default->set_active(false);
00098 }
00099 
00100 /** Destructor. */
00101 ConfigEditDialog::~ConfigEditDialog()
00102 {
00103 }
00104 
00105 /** Get the value of the entry widget.
00106  * @return the text in the entry widget
00107  */
00108 Glib::ustring
00109 ConfigEditDialog::get_value() const
00110 {
00111   if (!is_bool) return m_ent_value->get_text();
00112   else 
00113     {
00114       Gtk::TreeIter iter = m_cob_bool_value->get_active();
00115       Gtk::TreeRow row = *iter;
00116       Glib::ustring type;  
00117       
00118       row.get_value(0, type);
00119   
00120       return type;
00121     }
00122 }
00123 
00124 /** Get the default flag of the new entry
00125  * @return if true edit the default config database
00126  */
00127 bool
00128 ConfigEditDialog::get_is_default() const
00129 {
00130   return m_chb_is_default->get_active();
00131 }

Generated on Tue Feb 22 13:31:30 2011 for Fawkes API by  doxygen 1.4.7