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;