Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
config_edit_dialog.cpp
1 
2 /***************************************************************************
3  * config_edit_dialog.cpp - Edit config entries
4  *
5  * Created: Wed Sep 24 15:44:46 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_edit_dialog.h>
24 
25 /** @class ConfigEditDialog "config_edit_dialog.h"
26  * Dialog to edit a config value.
27  *
28  * @author Daniel Beck
29  */
30 
31 /** @var ConfigEditDialog::is_bool
32  * A flag to store wether the config value is boolean.
33  */
34 
35 /** @var ConfigEditDialog::m_ent_value
36  * An entry field to edit the config value.
37  */
38 
39 /** @var ConfigEditDialog::m_cob_bool_value
40  * A combo box to select TRUE or FALSE
41  */
42 
43 /** @var ConfigEditDialog::m_type_pages
44  * A Gtk::Notebook element to switch between boolean values and the rest
45  */
46 
47 /** @var ConfigEditDialog::m_chb_is_default
48  * The Gtk::CheckButton to set the default flag
49  */
50 
51 /** Constructor.
52  * @param ent_value entry field for value
53  * @param cob_bool_value combo box for bool value
54  * @param type_pages pages for types
55  * @param chb_is_default checkbutton to mark default values
56  */
57 ConfigEditDialog::ConfigEditDialog(Gtk::Entry *ent_value, Gtk::ComboBox *cob_bool_value,
58  Gtk::Notebook *type_pages, Gtk::CheckButton *chb_is_default)
59  : Gtk::Dialog()
60 {
62  m_cob_bool_value = cob_bool_value;
63  m_type_pages = type_pages;
64  m_chb_is_default = chb_is_default;
65 }
66 
67 /** Constructor.
68  * @param cobject pointer to base object type
69  * @param builder Gtk builder
70  */
71 ConfigEditDialog::ConfigEditDialog(BaseObjectType* cobject,
72  const Glib::RefPtr<Gtk::Builder> &builder)
73  : Gtk::Dialog(cobject)
74 {
75  builder->get_widget("entValueEdit", m_ent_value);
76  builder->get_widget("cmbBoolEdit", m_cob_bool_value);
77  builder->get_widget("nbkTypesEdit", m_type_pages);
78  builder->get_widget("chbIsDefaultEdit", m_chb_is_default);
79 }
80 
81 /** Initialize the dialog.
82  * @param path config path
83  * @param type type of config entry
84  * @param value value of the config entry
85  */
86 void
87 ConfigEditDialog::init( const Glib::ustring& path, const Glib::ustring& type,
88  const Glib::ustring& value )
89 {
90  is_bool = (type == "bool");
91  set_title(path);
92  m_ent_value->set_text(value);
93  m_cob_bool_value->set_active(value == "TRUE" ? 0 : 1);
94  m_type_pages->set_current_page(!is_bool ? 0 : 1);
95  m_chb_is_default->set_active(false);
96 }
97 
98 /** Destructor. */
100 {
101 }
102 
103 /** Get the value of the entry widget.
104  * @return the text in the entry widget
105  */
106 Glib::ustring
108 {
109  if (!is_bool) return m_ent_value->get_text();
110  else
111  {
112  Gtk::TreeIter iter = m_cob_bool_value->get_active();
113  Gtk::TreeRow row = *iter;
114  Glib::ustring type;
115 
116  row.get_value(0, type);
117 
118  return type;
119  }
120 }
121 
122 /** Get the default flag of the new entry
123  * @return if true edit the default config database
124  */
125 bool
127 {
128  return m_chb_is_default->get_active();
129 }
virtual ~ConfigEditDialog()
Destructor.
Gtk::Entry * m_ent_value
An entry field to edit the config value.
Glib::ustring get_value() const
Get the value of the entry widget.
Gtk::ComboBox * m_cob_bool_value
A combo box to select TRUE or FALSE.
Gtk::Notebook * m_type_pages
A Gtk::Notebook element to switch between boolean values and the rest.
ConfigEditDialog(Gtk::Entry *ent_value, Gtk::ComboBox *cob_bool_value, Gtk::Notebook *type_pages, Gtk::CheckButton *chb_is_default)
Constructor.
bool is_bool
A flag to store wether the config value is boolean.
void init(const Glib::ustring &path, const Glib::ustring &type, const Glib::ustring &value)
Initialize the dialog.
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.