Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
config_add_dialog.cpp
1 
2 /***************************************************************************
3  * config_add_dialog.cpp - Add config entries
4  *
5  * Created: Thu Sep 25 17:31:40 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <tools/config_editor/config_add_dialog.h>
24 
25 /** @class ConfigAddDialog "config_add_dialog.h"
26  * Dialog to add a config entry
27  *
28  * @author Daniel Beck
29  */
30 
31 /** @var ConfigAddDialog::m_ent_path
32  * The Gtk::Entry that contains the path of the new entry.
33  */
34 
35 /** @var ConfigAddDialog::m_ent_value
36  * The Gtk::Entry that contains the value of the new entry.
37  */
38 
39 /** @var ConfigAddDialog::m_cob_bool_value
40  * A combo box to select TRUE or FALSE
41  */
42 
43 /** @var ConfigAddDialog::m_type_pages
44  * A Gtk::Notebook element to switch between boolean values and the rest
45  */
46 
47 /** @var ConfigAddDialog::m_cmb_type
48  * The Gtk::ComboBox to select the type of the new entry.
49  */
50 
51 /** @var ConfigAddDialog::m_chb_is_default
52  * The Gtk::CheckButton to set the default flag
53  */
54 
55 /** Constructor.
56  * @param ent_path entry field for path
57  * @param ent_value entry field for value
58  * @param cob_bool_value combo box for bool values
59  * @param type_pages pages for different types
60  * @param cmb_type combo box for type
61  * @param chb_is_default check button for default values
62  */
63 ConfigAddDialog::ConfigAddDialog(Gtk::Entry *ent_path,
64  Gtk::Entry *ent_value,
65  Gtk::ComboBox *cob_bool_value,
66  Gtk::Notebook *type_pages,
67  Gtk::ComboBox *cmb_type,
68  Gtk::CheckButton *chb_is_default)
69 {
70  m_ent_path = ent_path;
71  m_cmb_type = cmb_type;
72  m_ent_value = ent_value;
73  m_cob_bool_value = cob_bool_value;
74  m_type_pages = type_pages;
75  m_chb_is_default = chb_is_default;
76 
77  m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) );
78 }
79 
80 /** Constructor.
81  * @param cobject pointer to base object type
82  * @param builder Gtk builder
83  */
84 ConfigAddDialog::ConfigAddDialog(BaseObjectType* cobject,
85  const Glib::RefPtr<Gtk::Builder> &builder)
86  : Gtk::Dialog(cobject)
87 {
88  builder->get_widget("entPathAdd", m_ent_path);
89  builder->get_widget("cmbTypeAdd", m_cmb_type);
90  builder->get_widget("entValueAdd", m_ent_value);
91  builder->get_widget("cmbBoolAdd", m_cob_bool_value);
92  builder->get_widget("nbkTypesAdd", m_type_pages);
93  builder->get_widget("chbIsDefaultAdd", m_chb_is_default);
94 
95  m_cmb_type->signal_changed().connect( sigc::mem_fun( *this, &ConfigAddDialog::on_my_changed) );
96 }
97 
98 /** Destructor. */
100 {
101 }
102 
103 /** Initialize the dialog.
104  * @param path the config path of the selected row
105  */
106 void
107 ConfigAddDialog::init(const Glib::ustring& path)
108 {
109  m_ent_path->set_text(path);
110  m_ent_value->set_text("");
111  m_cmb_type->set_active(-1);
112  m_cob_bool_value->set_active(-1);
113  m_chb_is_default->set_active(true);
114 }
115 
116 /** Get the path of the new entry.
117  * @return the path of the new entry
118  */
119 Glib::ustring
121 {
122  return m_ent_path->get_text();
123 }
124 
125 /** Get the type of the new entry.
126  * @return the type of the new entry
127  */
128 Glib::ustring
130 {
131  Gtk::TreeIter iter = m_cmb_type->get_active();
132  Gtk::TreeRow row = *iter;
133  Glib::ustring type;
134 
135  row.get_value(0, type);
136 
137  return type;
138 }
139 
140 /** Get the value of the new entry.
141  * @return the value of the new entry
142  */
143 Glib::ustring
145 {
146  if (get_type() != "bool") return m_ent_value->get_text();
147  else
148  {
149  Gtk::TreeIter iter = m_cob_bool_value->get_active();
150  Gtk::TreeRow row = *iter;
151  Glib::ustring type;
152 
153  row.get_value(0, type);
154 
155  return type;
156  }
157 }
158 
159 /** Get the default flag of the new entry
160  * @return if true add to default config database
161  */
162 bool
164 {
165  return m_chb_is_default->get_active();
166 }
167 
168 /**
169  * Swiches the (invisible) pages to add either a bool or a different type value
170  */
171 void
173 {
174  m_type_pages->set_current_page(get_type() != "bool" ? 0 : 1);
175 }
void init(const Glib::ustring &path)
Initialize the dialog.
Glib::ustring get_value() const
Get the value of the new entry.
ConfigAddDialog(Gtk::Entry *ent_path, Gtk::Entry *ent_value, Gtk::ComboBox *cob_bool_value, Gtk::Notebook *type_pages, Gtk::ComboBox *cmb_type, Gtk::CheckButton *chb_is_default)
Constructor.
Glib::ustring get_path() const
Get the path of the new entry.
Gtk::Notebook * m_type_pages
A Gtk::Notebook element to switch between boolean values and the rest.
Gtk::Entry * m_ent_path
The Gtk::Entry that contains the path of the new entry.
Gtk::Entry * m_ent_value
The Gtk::Entry that contains the value of the new entry.
Glib::ustring get_type() const
Get the type of the new entry.
virtual ~ConfigAddDialog()
Destructor.
Gtk::ComboBox * m_cob_bool_value
A combo box to select TRUE or FALSE.
bool get_is_default() const
Get the default flag of the new entry.
Gtk::CheckButton * m_chb_is_default
The Gtk::CheckButton to set the default flag.
void on_my_changed()
Swiches the (invisible) pages to add either a bool or a different type value.
Gtk::ComboBox * m_cmb_type
The Gtk::ComboBox to select the type of the new entry.