Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
config_tree_view.h
1 
2 /***************************************************************************
3  * config_tree_view.h - TreeView class for displaying the configuration
4  *
5  * Created: Wed Sep 24 13:39:47 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 #ifndef __TOOLS_CONFIG_EDITOR_CONFIG_TREE_VIEW_H_
24 #define __TOOLS_CONFIG_EDITOR_CONFIG_TREE_VIEW_H_
25 
26 #include <gtkmm.h>
27 #include <string>
28 
29 namespace fawkes {
30  class Configuration;
31  class FawkesNetworkClient;
32 }
33 
34 class ConfigEditDialog;
35 class ConfigAddDialog;
36 class ConfigRemoveDialog;
37 class ConfigEditorPlugin;
38 
39 class ConfigTreeView : public Gtk::TreeView
40 {
41  public:
42  ConfigTreeView(BaseObjectType* cobject,
43  const Glib::RefPtr<Gtk::Builder>& builder);
44  virtual ~ConfigTreeView();
45 
46  void set_config(fawkes::Configuration* config);
48  void set_config_file(const char* filename);
49 
50  void register_plugin( ConfigEditorPlugin* plugin );
51  void remove_plugin( std::string config_path );
52 
53  protected:
54  void set_value(const char* path, const char* type, bool is_default, bool value);
55  void set_value(const char* path, const char* type, bool is_default, int value);
56  void set_value(const char* path, const char* type, bool is_default, uint value);
57  void set_value(const char* path, const char* type, bool is_default, float value);
58  void set_value(const char* path, const char* type, bool is_default, std::string value);
59 
60  virtual void on_button_press_event_custom(GdkEventButton* event);
61  virtual void on_menu_edit_selected();
62  virtual void on_menu_add_selected();
63  virtual void on_menu_remove_selected();
64 
65  class ConfigRecord : public Gtk::TreeModelColumnRecord
66  {
67  public:
68  ConfigRecord()
69  {
70  add(node);
71  add(path);
72  add(type);
73  add(is_default);
74  add(value_bool);
75  add(value_int);
76  add(value_uint);
77  add(value_float);
78  add(value_string);
79  }
80 
81  Gtk::TreeModelColumn<Glib::ustring> node; /**< node name */
82  Gtk::TreeModelColumn<Glib::ustring> path; /**< config path */
83  Gtk::TreeModelColumn<Glib::ustring> type; /**< config value type */
84  Gtk::TreeModelColumn<bool> is_default; /**< default flag */
85  Gtk::TreeModelColumn<bool> value_bool; /**< bool config value */
86  Gtk::TreeModelColumn<int> value_int; /**< int config value */
87  Gtk::TreeModelColumn<uint> value_uint; /**< unsigned int config value */
88  Gtk::TreeModelColumn<float> value_float; /**< float config value */
89  Gtk::TreeModelColumn<Glib::ustring> value_string; /**< config value as string */
90  };
91 
93  Glib::RefPtr<Gtk::TreeStore> m_config_tree;
94 
95  Gtk::Menu m_menu;
99 
100  std::map< std::string, ConfigEditorPlugin* > m_plugins;
101 
104 
105  private:
106  void read_config();
107 
108  Gtk::TreeIter get_iter(const char* path);
109  Gtk::TreeIter search_path( const char* path );
110 
111  bool edit_entry(const Gtk::TreeIter& iter);
112  bool add_entry(const Gtk::TreeIter& iter);
113  bool remove_entry(const Gtk::TreeIter& iter);
114 };
115 
116 #endif /* __TOOLS_CONFIG_EDITOR_CONFIG_TREE_VIEW_H_ */