23 #include "config_tree_view.h"
24 #include "config_edit_dialog.h"
25 #include "config_add_dialog.h"
26 #include "config_remove_dialog.h"
27 #include "config_editor_plugin.h"
29 #include <core/exceptions/system.h>
30 #include <config/netconf.h>
31 #include <config/sqlite.h>
32 #include <netcomm/fawkes/client.h>
39 using namespace fawkes;
94 const Glib::RefPtr<Gtk::Builder> &builder)
95 : Gtk::TreeView(cobject)
98 builder->get_widget_derived(
"dlgConfigEdit",
m_dlg_edit);
101 builder->get_widget_derived(
"dlgConfigAdd",
m_dlg_add);
104 builder->get_widget_derived(
"dlgConfigRemove",
m_dlg_remove);
112 Gtk::TreeViewColumn *column = get_column(0);
113 Gtk::CellRendererText *cell =
114 #if GTK_VERSION_GE(3,0)
115 (Gtk::CellRendererText *)column->get_first_cell();
117 (Gtk::CellRendererText *)column->get_first_cell_renderer();
119 #ifdef GLIBMM_PROPERTIES_ENABLED
147 for ( std::map< string, ConfigEditorPlugin* >::iterator iter =
m_plugins.begin();
150 {
delete iter->second; }
175 for ( std::map< string, ConfigEditorPlugin* >::iterator i =
m_plugins.begin();
178 { i->second->set_config(
m_config ); }
204 for ( std::map< string, ConfigEditorPlugin* >::iterator i =
m_plugins.begin();
207 { i->second->set_config(
m_config ); }
240 std::map< string, ConfigEditorPlugin* >::iterator iter =
m_plugins.find( config_path );
251 ConfigTreeView::read_config()
260 while ( cit->
next() )
288 Gtk::TreeModel::Row row;
289 row = *get_iter(path);
306 Gtk::TreeModel::Row row;
307 row = *get_iter(path);
329 Gtk::TreeModel::Row row;
330 row = *get_iter(path);
352 Gtk::TreeModel::Row row;
353 row = *get_iter(path);
375 Gtk::TreeModel::Row row;
376 row = *get_iter(path);
384 ConfigTreeView::get_iter(
const char* p)
389 if (asprintf(&full_path,
"%s", p) == -1) {
392 char* node = strtok(full_path,
"/");
394 if (asprintf(&path,
"/%s", node) == -1) {
398 Gtk::TreeModel::Children children =
m_config_tree->children();
399 Gtk::TreeIter iter = children.begin();
401 while ( node != NULL )
404 iter = children.begin();
406 while ( !found && iter != children.end() )
408 Gtk::TreeModel::Row row = *iter;
411 if ( strcmp(r.c_str(), node) == 0 )
414 children = row.children();
415 iter = children.begin();
424 Gtk::TreeModel::Row row = *iter;
428 children = row.children();
431 node = strtok(NULL,
"/");
434 if (asprintf(&t,
"%s/%s", path, node) == -1) {
448 ConfigTreeView::search_path(
const char* path )
450 Gtk::TreeModel::Children children =
m_config_tree->children();
451 Gtk::TreeModel::iterator iter = children.begin();
453 while ( iter != children.end() )
455 Gtk::TreeModel::Row row = *iter;
457 size_t len = strlen( p.c_str() );
459 if ( strncmp( p.c_str(), path, len) == 0 )
461 if ( strcmp( p.c_str(), path ) == 0 )
464 { iter = iter->children().begin(); }
480 if (event->type == GDK_2BUTTON_PRESS)
482 Gtk::TreeModel::Row row = *( get_selection()->get_selected() );
485 std::map< string, ConfigEditorPlugin* >::iterator i =
m_plugins.find( path.c_str() );
487 { i->second->run(); }
489 { edit_entry( get_selection()->get_selected() ); }
491 else if ( event->type == GDK_BUTTON_PRESS && (event->button == 3) )
502 edit_entry( get_selection()->get_selected() );
511 add_entry( get_selection()->get_selected() );
520 remove_entry( get_selection()->get_selected() );
524 ConfigTreeView::edit_entry(
const Gtk::TreeIter& iter)
528 Gtk::TreeModel::Row row = *iter;
541 Gtk::Window* parent =
dynamic_cast<Gtk::Window*
>( get_toplevel() );
547 case Gtk::RESPONSE_OK:
551 const char* p = path.c_str();
552 const char* t = type.c_str();
562 else if (value ==
"FALSE")
572 i = atoi( value.c_str() );
581 i = atoi( value.c_str() );
586 set_value(p, t, is_default, (
unsigned int) i);
592 f = atof( value.c_str() );
600 string s( value.c_str() );
624 ConfigTreeView::remove_entry(
const Gtk::TreeIter& iter)
626 bool ret_val =
false;
628 Gtk::TreeModel::Row row = *iter;
639 Gtk::Window* parent =
dynamic_cast<Gtk::Window*
>( get_toplevel() );
645 case Gtk::RESPONSE_OK:
647 const char* p = path.c_str();
657 if (!rem_default && cit->
next())
686 ConfigTreeView::add_entry(
const Gtk::TreeIter& iter)
688 bool ret_val =
false;
690 Gtk::TreeModel::Row row = *iter;
695 Gtk::Window* parent =
dynamic_cast<Gtk::Window*
>( get_toplevel() );
701 case Gtk::RESPONSE_OK:
708 const char* t = type.c_str();
709 const char* p = path.c_str();
713 if ( type ==
"bool" )
717 if ( value ==
"TRUE" || value ==
"true" )
719 else if ( value ==
"FALSE" || value ==
"false" )
727 else if ( type ==
"int" )
730 i = atoi( value.c_str() );
737 else if ( type ==
"uint" )
740 i = atoi( value.c_str() );
745 set_value(p, t, is_default, (
unsigned int) i);
749 else if ( type ==
"float" )
752 f = atof( value.c_str() );
759 else if ( type ==
"string")
761 string s( value.c_str() );
771 cout <<
"Unknown type." << endl;
void init(const Glib::ustring &path)
Initialize the dialog.
Glib::ustring get_value() const
Get the value of the new entry.
virtual ValueIterator * iterator()=0
Iterator for all values.
Gtk::TreeModelColumn< bool > value_bool
bool config value
virtual void set_default_float(const char *path, float f)=0
Set new default value in configuration of type float.
Simple Fawkes network client.
virtual bool is_string(const char *path)=0
Check if a value is of type string.
virtual void set_default_int(const char *path, int i)=0
Set new default value in configuration of type int.
bool m_own_config
True if config was created by ConfigTreeView object.
virtual void on_menu_edit_selected()
Signal handler that is called when the 'edit' entry is selected from popup menu.
Gtk::TreeModelColumn< uint > value_uint
unsigned int config value
virtual const char * type() const =0
Type of value.
Configuration storage using SQLite.
virtual bool is_bool() const =0
Check if current value is a bool.
virtual void on_menu_add_selected()
Signal handler that is called when the 'add' entry is selected from popup menu.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
Glib::ustring get_path() const
Get the path of the new entry.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual float get_float() const =0
Get float value.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual unsigned int get_uint() const =0
Get unsigned int value.
Gtk::TreeModelColumn< Glib::ustring > value_string
config value as string
virtual bool is_float() const =0
Check if current value is a float.
virtual void set_bool(const char *path, bool b)=0
Set new value in configuration of type bool.
virtual bool is_int() const =0
Check if current value is a int.
Glib::ustring get_value() const
Get the value of the entry widget.
virtual bool get_bool() const =0
Get bool value.
Glib::ustring get_type() const
Get the type of the new entry.
virtual void set_float(const char *path, float f)=0
Set new value in configuration of type float.
virtual ~ConfigTreeView()
Destructor.
Gtk::TreeModelColumn< Glib::ustring > type
config value type
ConfigAddDialog * m_dlg_add
A dialog to add a config entry.
virtual int get_int() const =0
Get int value.
void register_plugin(ConfigEditorPlugin *plugin)
Register a plugin.
virtual bool is_bool(const char *path)=0
Check if a value is of type bool.
bool get_remove_default() const
Get the remove default flag of the entry to be deleted.
void remove_plugin(std::string config_path)
Remove a plugin.
virtual bool is_string() const =0
Check if current value is a string.
virtual void erase_default(const char *path)=0
Erase the given default value from the configuration.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
void initialize()
Initialize the plugin.
virtual void set_default_bool(const char *path, bool b)=0
Set new default value in configuration of type bool.
ConfigEditDialog * m_dlg_edit
A dialog to edit a config entry.
virtual void set_default_uint(const char *path, unsigned int uint)=0
Set new default value in configuration of type unsigned int.
Glib::RefPtr< Gtk::TreeStore > m_config_tree
Storage object.
fawkes::Configuration * m_config
The fawkes::Configuration that is displayed and editted.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual void on_menu_remove_selected()
Signal handler that is called when the 'remove' entry is selected from popup menu.
virtual std::string get_string() const =0
Get string value.
Gtk::TreeModelColumn< Glib::ustring > node
node name
void set_value(const char *path, const char *type, bool is_default, bool value)
Add a config entry to the TreeModel storage object.
virtual void set_mirror_mode(bool mirror)
Enable or disable mirror mode.
virtual const char * path() const =0
Path of value.
void set_network_client(fawkes::FawkesNetworkClient *client)
Set a network client that is used to open a fawkes::NetworkConfiguration.
ConfigRecord m_config_record
Column record object to access the columns of the storage object.
std::map< std::string, ConfigEditorPlugin * > m_plugins
A map of registered plugins: config-prefix => config editor plugin.
virtual bool is_float(const char *path)=0
Check if a value is of type float.
Gtk::TreeModelColumn< Glib::ustring > path
config path
void init(const Glib::ustring &path, const Glib::ustring &type, const Glib::ustring &value)
Initialize the dialog.
virtual void unlock()=0
Unlock the config.
virtual bool is_uint(const char *path)=0
Check if a value is of type unsigned int.
Gtk::TreeModelColumn< int > value_int
int config value
void set_config_file(const char *filename)
Set the file to read the config from.
bool get_is_default() const
Get the default flag of the new entry.
std::string get_config_path() const
Get the config prefix specified for this config editor plugin.
Iterator interface to iterate over config values.
Gtk::TreeModelColumn< float > value_float
float config value
virtual void on_button_press_event_custom(GdkEventButton *event)
Signal handler for the button press event.
virtual bool is_default() const =0
Check if current value was read from the default config.
ConfigRemoveDialog * m_dlg_remove
A dialog to remove a config entry.
Gtk::TreeModelColumn< bool > is_default
default flag
void set_config(fawkes::Configuration *config)
Set the fawkes::Configuration to be displayed.
Base class for plugins for the Fawkes config editor.
void init(const Glib::ustring &path, bool is_default)
Initialize the dialog.
bool get_is_default() const
Get the default flag of the new entry.
virtual void set_default_string(const char *path, std::string &s)=0
Set new default value in configuration of type string.
virtual bool is_int(const char *path)=0
Check if a value is of type int.
ConfigTreeView(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
Interface for configuration handling.
virtual void set_uint(const char *path, unsigned int uint)=0
Set new value in configuration of type unsigned int.
virtual void set_string(const char *path, std::string &s)=0
Set new value in configuration of type string.
System ran out of memory and desired operation could not be fulfilled.
virtual void lock()=0
Lock the config.
Remote configuration via Fawkes net.