Fawkes API
Fawkes Development Version
|
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 00025 /** @class ConfigAddDialog "config_add_dialog.h" 00026 * Dialog to add a config entry 00027 * 00028 * @author Daniel Beck 00029 */ 00030 00031 /** @var ConfigAddDialog::m_ent_path 00032 * The Gtk::Entry that contains the path of the new entry. 00033 */ 00034 00035 /** @var ConfigAddDialog::m_ent_value 00036 * The Gtk::Entry that contains the value of the new entry. 00037 */ 00038 00039 /** @var ConfigAddDialog::m_cob_bool_value 00040 * A combo box to select TRUE or FALSE 00041 */ 00042 00043 /** @var ConfigAddDialog::m_type_pages 00044 * A Gtk::Notebook element to switch between boolean values and the rest 00045 */ 00046 00047 /** @var ConfigAddDialog::m_cmb_type 00048 * The Gtk::ComboBox to select the type of the new entry. 00049 */ 00050 00051 /** @var ConfigAddDialog::m_chb_is_default 00052 * The Gtk::CheckButton to set the default flag 00053 */ 00054 00055 /** Constructor. 00056 * @param ent_path entry field for path 00057 * @param ent_value entry field for value 00058 * @param cob_bool_value combo box for bool values 00059 * @param type_pages pages for different types 00060 * @param cmb_type combo box for type 00061 * @param chb_is_default check button for default values 00062 */ 00063 ConfigAddDialog::ConfigAddDialog(Gtk::Entry *ent_path, 00064 Gtk::Entry *ent_value, 00065 Gtk::ComboBox *cob_bool_value, 00066 Gtk::Notebook *type_pages, 00067 Gtk::ComboBox *cmb_type, 00068 Gtk::CheckButton *chb_is_default) 00069 { 00070 m_ent_path = ent_path; 00071 m_cmb_type = cmb_type; 00072 m_ent_value = ent_value; 00073 m_cob_bool_value = cob_bool_value; 00074 m_type_pages = type_pages; 00075 m_chb_is_default = chb_is_default; 00076 00077 m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) ); 00078 } 00079 00080 #ifdef HAVE_GLADEMM 00081 /** Constructor. 00082 * @param cobject pointer to base object type 00083 * @param ref_xml Glade XML file 00084 */ 00085 ConfigAddDialog::ConfigAddDialog( BaseObjectType* cobject, 00086 const Glib::RefPtr<Gnome::Glade::Xml>& ref_xml ) 00087 : Gtk::Dialog(cobject) 00088 { 00089 ref_xml->get_widget("entPathAdd", m_ent_path); 00090 ref_xml->get_widget("cmbTypeAdd", m_cmb_type); 00091 ref_xml->get_widget("entValueAdd", m_ent_value); 00092 ref_xml->get_widget("cmbBoolAdd", m_cob_bool_value); 00093 ref_xml->get_widget("nbkTypesAdd", m_type_pages); 00094 ref_xml->get_widget("chbIsDefaultAdd", m_chb_is_default); 00095 00096 m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) ); 00097 } 00098 #endif 00099 00100 /** Destructor. */ 00101 ConfigAddDialog::~ConfigAddDialog() 00102 { 00103 } 00104 00105 /** Initialize the dialog. 00106 * @param path the config path of the selected row 00107 */ 00108 void 00109 ConfigAddDialog::init(const Glib::ustring& path) 00110 { 00111 m_ent_path->set_text(path); 00112 m_ent_value->set_text(""); 00113 m_cmb_type->set_active(-1); 00114 m_cob_bool_value->set_active(-1); 00115 m_chb_is_default->set_active(true); 00116 } 00117 00118 /** Get the path of the new entry. 00119 * @return the path of the new entry 00120 */ 00121 Glib::ustring 00122 ConfigAddDialog::get_path() const 00123 { 00124 return m_ent_path->get_text(); 00125 } 00126 00127 /** Get the type of the new entry. 00128 * @return the type of the new entry 00129 */ 00130 Glib::ustring 00131 ConfigAddDialog::get_type() const 00132 { 00133 Gtk::TreeIter iter = m_cmb_type->get_active(); 00134 Gtk::TreeRow row = *iter; 00135 Glib::ustring type; 00136 00137 row.get_value(0, type); 00138 00139 return type; 00140 } 00141 00142 /** Get the value of the new entry. 00143 * @return the value of the new entry 00144 */ 00145 Glib::ustring 00146 ConfigAddDialog::get_value() const 00147 { 00148 if (get_type() != "bool") return m_ent_value->get_text(); 00149 else 00150 { 00151 Gtk::TreeIter iter = m_cob_bool_value->get_active(); 00152 Gtk::TreeRow row = *iter; 00153 Glib::ustring type; 00154 00155 row.get_value(0, type); 00156 00157 return type; 00158 } 00159 } 00160 00161 /** Get the default flag of the new entry 00162 * @return if true add to default config database 00163 */ 00164 bool 00165 ConfigAddDialog::get_is_default() const 00166 { 00167 return m_chb_is_default->get_active(); 00168 } 00169 00170 /** 00171 * Swiches the (invisible) pages to add either a bool or a different type value 00172 */ 00173 void 00174 ConfigAddDialog::on_my_changed() 00175 { 00176 m_type_pages->set_current_page(get_type() != "bool" ? 0 : 1); 00177 }