config_add_dialog.cpp

00001
00002 /***************************************************************************
00003  *  config_add_dialog.cpp - Add config entries
00004  *
00005  *  Created: Thu Sep 25 17:31:40 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_add_dialog.h>
00024 #include <gui_utils/utils.h>
00025
00026 using namespace fawkes;
00027 
00028 /** @class ConfigAddDialog tools/config_editor/config_add_dialog.h
00029  * Dialog to add a config entry
00030  *
00031  * @author Daniel Beck
00032  */
00033 
00034 /** @var ConfigAddDialog::m_ent_path
00035  * The Gtk::Entry that contains the path of the new entry.
00036  */
00037 
00038 /** @var ConfigAddDialog::m_ent_value
00039  * The Gtk::Entry that contains the value of the new entry.
00040  */
00041 
00042 /** @var ConfigAddDialog::m_cob_bool_value
00043  * A combo box to select TRUE or FALSE
00044  */
00045 
00046 /** @var ConfigAddDialog::m_type_pages
00047  * A Gtk::Notebook element to switch between boolean values and the rest
00048  */
00049 
00050 /** @var ConfigAddDialog::m_cmb_type
00051  * The Gtk::ComboBox to select the type of the new entry.
00052  */
00053 
00054 /** @var ConfigAddDialog::m_chb_is_default
00055  * The Gtk::CheckButton to set the default flag
00056  */
00057 
00058 /** Constructor.
00059  * @param cobject pointer to base object type
00060  * @param ref_xml Glade XML file
00061  */
00062 ConfigAddDialog::ConfigAddDialog( BaseObjectType* cobject,
00063                                   const Glib::RefPtr<Gnome::Glade::Xml>& ref_xml )
00064   : Gtk::Dialog(cobject)
00065 {
00066   m_ent_path       = dynamic_cast<Gtk::Entry*>( get_widget(ref_xml, "entPathAdd") );
00067   m_cmb_type       = dynamic_cast<Gtk::ComboBox*>( get_widget(ref_xml, "cmbTypeAdd") );
00068   m_ent_value      = dynamic_cast<Gtk::Entry*>( get_widget(ref_xml, "entValueAdd") );
00069   m_cob_bool_value = dynamic_cast<Gtk::ComboBox*>( get_widget(ref_xml, "cmbBoolAdd") );
00070   m_type_pages     = dynamic_cast<Gtk::Notebook*>( get_widget(ref_xml, "nbkTypesAdd") );
00071   m_chb_is_default = dynamic_cast<Gtk::CheckButton*>( get_widget(ref_xml, "chbIsDefaultAdd") );
00072
00073   m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) );
00074 }
00075 
00076 /** Destructor. */
00077 ConfigAddDialog::~ConfigAddDialog()
00078 {
00079 }
00080 
00081 /** Initialize the dialog.
00082  * @param path the config path of the selected row
00083  */
00084 void
00085 ConfigAddDialog::init(const Glib::ustring& path)
00086 {
00087   m_ent_path->set_text(path);
00088   m_ent_value->set_text("");
00089   m_cmb_type->set_active(-1);
00090   m_cob_bool_value->set_active(-1);
00091   m_chb_is_default->set_active(true);
00092 }
00093 
00094 /** Get the path of the new entry.
00095  * @return the path of the new entry
00096  */
00097 Glib::ustring
00098 ConfigAddDialog::get_path() const
00099 {
00100   return m_ent_path->get_text();
00101 }
00102 
00103 /** Get the type of the new entry.
00104  * @return the type of the new entry
00105  */
00106 Glib::ustring
00107 ConfigAddDialog::get_type() const
00108 {
00109   Gtk::TreeIter iter = m_cmb_type->get_active();
00110   Gtk::TreeRow row = *iter;
00111   Glib::ustring type;
00112
00113   row.get_value(0, type);
00114
00115   return type;
00116 }
00117 
00118 /** Get the value of the new entry.
00119  * @return the value of the new entry
00120  */
00121 Glib::ustring
00122 ConfigAddDialog::get_value() const
00123 {
00124   if (get_type() != "bool") return m_ent_value->get_text();
00125   else
00126     {
00127       Gtk::TreeIter iter = m_cob_bool_value->get_active();
00128       Gtk::TreeRow row = *iter;
00129       Glib::ustring type;
00130
00131       row.get_value(0, type);
00132
00133       return type;
00134     }
00135 }
00136 
00137 /** Get the default flag of the new entry
00138  * @return if true add to default config database
00139  */
00140 bool
00141 ConfigAddDialog::get_is_default() const
00142 {
00143   return m_chb_is_default->get_active();
00144 }
00145 
00146 /**
00147  * Swiches the (invisible) pages to add either a bool or a different type value
00148  */
00149 void
00150 ConfigAddDialog::on_my_changed()
00151 {
00152   m_type_pages->set_current_page(get_type() != "bool" ? 0 : 1);
00153 }