Fawkes API  Fawkes Development Version
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 /** Constructor.
00068  * @param cobject pointer to base object type
00069  * @param builder Gtk builder
00070  */     
00071 ConfigEditDialog::ConfigEditDialog(BaseObjectType* cobject,
00072                                    const Glib::RefPtr<Gtk::Builder> &builder)
00073   : Gtk::Dialog(cobject)
00074 {
00075   builder->get_widget("entValueEdit", m_ent_value);
00076   builder->get_widget("cmbBoolEdit", m_cob_bool_value);
00077   builder->get_widget("nbkTypesEdit", m_type_pages);
00078   builder->get_widget("chbIsDefaultEdit", m_chb_is_default);
00079 }
00080 
00081 /** Initialize the dialog.
00082  * @param path config path
00083  * @param type type of config entry
00084  * @param value value of the config entry
00085  */
00086 void
00087 ConfigEditDialog::init( const Glib::ustring& path, const Glib::ustring& type,
00088                         const Glib::ustring& value )
00089 {
00090   is_bool = (type == "bool");
00091   set_title(path);
00092   m_ent_value->set_text(value);
00093   m_cob_bool_value->set_active(value == "TRUE" ? 0 : 1);
00094   m_type_pages->set_current_page(!is_bool ? 0 : 1);
00095   m_chb_is_default->set_active(false);
00096 }
00097 
00098 /** Destructor. */
00099 ConfigEditDialog::~ConfigEditDialog()
00100 {
00101 }
00102 
00103 /** Get the value of the entry widget.
00104  * @return the text in the entry widget
00105  */
00106 Glib::ustring
00107 ConfigEditDialog::get_value() const
00108 {
00109   if (!is_bool) return m_ent_value->get_text();
00110   else 
00111     {
00112       Gtk::TreeIter iter = m_cob_bool_value->get_active();
00113       Gtk::TreeRow row = *iter;
00114       Glib::ustring type;  
00115       
00116       row.get_value(0, type);
00117   
00118       return type;
00119     }
00120 }
00121 
00122 /** Get the default flag of the new entry
00123  * @return if true edit the default config database
00124  */
00125 bool
00126 ConfigEditDialog::get_is_default() const
00127 {
00128   return m_chb_is_default->get_active();
00129 }