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 /** Constructor. 00081 * @param cobject pointer to base object type 00082 * @param builder Gtk builder 00083 */ 00084 ConfigAddDialog::ConfigAddDialog(BaseObjectType* cobject, 00085 const Glib::RefPtr<Gtk::Builder> &builder) 00086 : Gtk::Dialog(cobject) 00087 { 00088 builder->get_widget("entPathAdd", m_ent_path); 00089 builder->get_widget("cmbTypeAdd", m_cmb_type); 00090 builder->get_widget("entValueAdd", m_ent_value); 00091 builder->get_widget("cmbBoolAdd", m_cob_bool_value); 00092 builder->get_widget("nbkTypesAdd", m_type_pages); 00093 builder->get_widget("chbIsDefaultAdd", m_chb_is_default); 00094 00095 m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) ); 00096 } 00097 00098 /** Destructor. */ 00099 ConfigAddDialog::~ConfigAddDialog() 00100 { 00101 } 00102 00103 /** Initialize the dialog. 00104 * @param path the config path of the selected row 00105 */ 00106 void 00107 ConfigAddDialog::init(const Glib::ustring& path) 00108 { 00109 m_ent_path->set_text(path); 00110 m_ent_value->set_text(""); 00111 m_cmb_type->set_active(-1); 00112 m_cob_bool_value->set_active(-1); 00113 m_chb_is_default->set_active(true); 00114 } 00115 00116 /** Get the path of the new entry. 00117 * @return the path of the new entry 00118 */ 00119 Glib::ustring 00120 ConfigAddDialog::get_path() const 00121 { 00122 return m_ent_path->get_text(); 00123 } 00124 00125 /** Get the type of the new entry. 00126 * @return the type of the new entry 00127 */ 00128 Glib::ustring 00129 ConfigAddDialog::get_type() const 00130 { 00131 Gtk::TreeIter iter = m_cmb_type->get_active(); 00132 Gtk::TreeRow row = *iter; 00133 Glib::ustring type; 00134 00135 row.get_value(0, type); 00136 00137 return type; 00138 } 00139 00140 /** Get the value of the new entry. 00141 * @return the value of the new entry 00142 */ 00143 Glib::ustring 00144 ConfigAddDialog::get_value() const 00145 { 00146 if (get_type() != "bool") return m_ent_value->get_text(); 00147 else 00148 { 00149 Gtk::TreeIter iter = m_cob_bool_value->get_active(); 00150 Gtk::TreeRow row = *iter; 00151 Glib::ustring type; 00152 00153 row.get_value(0, type); 00154 00155 return type; 00156 } 00157 } 00158 00159 /** Get the default flag of the new entry 00160 * @return if true add to default config database 00161 */ 00162 bool 00163 ConfigAddDialog::get_is_default() const 00164 { 00165 return m_chb_is_default->get_active(); 00166 } 00167 00168 /** 00169 * Swiches the (invisible) pages to add either a bool or a different type value 00170 */ 00171 void 00172 ConfigAddDialog::on_my_changed() 00173 { 00174 m_type_pages->set_current_page(get_type() != "bool" ? 0 : 1); 00175 }