25 #include <gui_utils/plugin_tree_view.h>
26 #include <netcomm/fawkes/client.h>
27 #include <plugin/net/messages.h>
28 #include <plugin/net/list_message.h>
29 #include <gui_utils/twolines_cellrenderer.h>
64 PluginTreeView::PluginTreeView()
65 : m_dispatcher(FAWKES_CID_PLUGINMANAGER)
75 const Glib::RefPtr<Gtk::Builder> builder)
76 : Gtk::TreeView(cobject),
77 m_dispatcher(FAWKES_CID_PLUGINMANAGER)
84 PluginTreeView::ctor()
86 m_plugin_list = Gtk::ListStore::create(m_plugin_record);
87 set_model(m_plugin_list);
89 append_column(
"#", m_plugin_record.index);
90 append_column_editable(
"Status", m_plugin_record.loaded);
91 append_plugin_column();
94 Gtk::TreeViewColumn *column = get_column(0);
95 column->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_id_clicked));
96 column = get_column(1);
97 column->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_status_clicked));
99 Gtk::CellRendererToggle* renderer;
100 renderer =
dynamic_cast<Gtk::CellRendererToggle*
>( get_column_cell_renderer(1) );
101 renderer->signal_toggled().connect( sigc::mem_fun(*
this, &PluginTreeView::on_status_toggled));
103 m_dispatcher.
signal_connected().connect(sigc::mem_fun(*
this, &PluginTreeView::on_connected));
104 m_dispatcher.
signal_disconnected().connect(sigc::mem_fun(*
this, &PluginTreeView::on_disconnected));
124 # ifdef GLIBMM_EXCEPTIONS_ENABLED
125 __gconf->remove_dir(__gconf_prefix);
127 std::auto_ptr<Glib::Error> error;
128 __gconf->remove_dir(__gconf_prefix, error);
153 __gconf = Gnome::Conf::Client::get_default_client();
155 # ifdef GLIBMM_EXCEPTIONS_ENABLED
156 __gconf->remove_dir(__gconf_prefix);
158 std::auto_ptr<Glib::Error> error;
159 __gconf->remove_dir(__gconf_prefix, error);
163 #ifdef GLIBMM_EXCEPTIONS_ENABLED
164 __gconf->add_dir(gconf_prefix);
166 std::auto_ptr<Glib::Error> error;
167 __gconf->add_dir(gconf_prefix, Gnome::Conf::CLIENT_PRELOAD_NONE, error);
169 __gconf_prefix = gconf_prefix;
171 if (__gconf_connection) {
172 __gconf_connection.disconnect();
174 __gconf_connection = __gconf->signal_value_changed().connect(sigc::hide(sigc::hide(sigc::mem_fun(*
this, &PluginTreeView::on_config_changed))));
181 PluginTreeView::on_connected()
210 PluginTreeView::on_disconnected()
212 m_plugin_list->clear();
219 if (msg->
cid() != FAWKES_CID_PLUGINMANAGER)
return;
222 unsigned int msgid = msg->
msgid();
228 Glib::ustring name =
"";
233 if ( msg->
payload_size() !=
sizeof(plugin_loaded_msg_t) )
235 printf(
"Invalid message size (load succeeded)\n");
239 plugin_loaded_msg_t* m = (plugin_loaded_msg_t*) msg->
payload();
246 if ( msg->
payload_size() !=
sizeof(plugin_load_failed_msg_t) )
248 printf(
"Invalid message size (load failed)\n");
252 plugin_load_failed_msg_t* m = (plugin_load_failed_msg_t*) msg->
payload();
259 if ( msg->
payload_size() !=
sizeof(plugin_unloaded_msg_t) )
261 printf(
"Invalid message size (unload succeeded)\n");
265 plugin_unloaded_msg_t* m = (plugin_unloaded_msg_t*) msg->
payload();
272 if ( msg->
payload_size() !=
sizeof(plugin_unload_failed_msg_t) )
274 printf(
"Invalid message size (unload failed)\n");
278 plugin_unload_failed_msg_t* m = (plugin_unload_failed_msg_t*) msg->
payload();
285 for ( iter = m_plugin_list->children().begin();
286 iter != m_plugin_list->children().end();
289 Glib::ustring n = (*iter)[m_plugin_record.name];
292 (*iter)[m_plugin_record.loaded] = loaded;
299 m_plugin_list->clear();
300 PluginListMessage* plm = msg->
msgc<PluginListMessage>();
301 while ( plm->has_next() )
303 char *plugin_name = plm->next();
304 char *plugin_desc = NULL;
305 if ( plm->has_next() ) {
306 plugin_desc = plm->next();
308 plugin_desc = strdup(
"Unknown, malformed plugin list message?");
311 Gtk::TreeModel::Row row = *m_plugin_list->append();
312 unsigned int index = m_plugin_list->children().size();
313 row[m_plugin_record.index] = index;
314 row[m_plugin_record.name] = plugin_name;
315 row[m_plugin_record.description] = plugin_desc;
316 row[m_plugin_record.loaded] =
false;
325 printf(
"Obtaining list of available plugins failed\n");
329 PluginListMessage* plm = msg->
msgc<PluginListMessage>();
330 while ( plm->has_next() )
332 char* name = plm->next();
335 for ( iter = m_plugin_list->children().begin();
336 iter != m_plugin_list->children().end();
339 Glib::ustring n = (*iter)[m_plugin_record.name];
342 (*iter)[m_plugin_record.loaded] =
true;
352 printf(
"Obtaining list of loaded plugins failed\n");
358 printf(
"received message with msg-id %d\n", msg->
msgid());
367 PluginTreeView::on_status_toggled(
const Glib::ustring& path)
371 Gtk::TreeModel::Row row = *m_plugin_list->get_iter(path);
372 Glib::ustring plugin_name = row[m_plugin_record.name];
373 bool loaded = row[m_plugin_record.loaded];
377 plugin_load_msg_t* m = (plugin_load_msg_t*) calloc(1,
sizeof(plugin_load_msg_t));
378 strncpy(m->name, plugin_name.c_str(), PLUGIN_MSG_NAME_LENGTH);
380 FawkesNetworkMessage *msg =
new FawkesNetworkMessage(FAWKES_CID_PLUGINMANAGER,
382 m,
sizeof(plugin_load_msg_t));
387 plugin_unload_msg_t* m = (plugin_unload_msg_t *)calloc(1,
sizeof(plugin_unload_msg_t));
388 strncpy(m->name, plugin_name.c_str(), PLUGIN_MSG_NAME_LENGTH);
390 FawkesNetworkMessage *msg =
new FawkesNetworkMessage(FAWKES_CID_PLUGINMANAGER,
392 m,
sizeof(plugin_unload_msg_t));
401 PluginTreeView::on_id_clicked()
403 m_plugin_list->set_sort_column(0, Gtk::SORT_ASCENDING);
410 PluginTreeView::on_status_clicked()
412 m_plugin_list->set_sort_column(2, Gtk::SORT_DESCENDING);
419 PluginTreeView::on_name_clicked()
421 m_plugin_list->set_sort_column(1, Gtk::SORT_ASCENDING);
428 PluginTreeView::on_config_changed()
430 Gtk::TreeViewColumn *plugin_col = get_column(2);
431 if (plugin_col) remove_column(*plugin_col);
433 append_plugin_column();
440 PluginTreeView::append_plugin_column()
442 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14 )
443 bool description_as_tooltip =
false;
447 # ifdef GLIBMM_EXCEPTIONS_ENABLED
448 description_as_tooltip = __gconf->get_bool(__gconf_prefix +
"/description_as_tooltip");
450 std::auto_ptr<Glib::Error> error;
451 description_as_tooltip = __gconf->get_bool(__gconf_prefix +
"/description_as_tooltip", error);
457 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14 )
458 if (description_as_tooltip)
461 append_column(
"Plugin", m_plugin_record.name);
462 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14 )
463 set_tooltip_column(2);
467 TwoLinesCellRenderer *twolines_renderer =
new TwoLinesCellRenderer();
468 Gtk::TreeViewColumn *tlcol =
469 new Gtk::TreeViewColumn(
"Plugin", *Gtk::manage(twolines_renderer));
470 append_column(*Gtk::manage(tlcol));
472 # ifdef GLIBMM_PROPERTIES_ENABLED
473 tlcol->add_attribute(twolines_renderer->property_line1(), m_plugin_record.name);
474 tlcol->add_attribute(twolines_renderer->property_line2(), m_plugin_record.description);
476 tlcol->add_attribute(*twolines_renderer,
"line1", m_plugin_record.name);
477 tlcol->add_attribute(*twolines_renderer,
"line2", m_plugin_record.description);
480 set_tooltip_column(-1);
484 set_headers_clickable();
485 Gtk::TreeViewColumn *plugin_col = get_column(2);
486 if (plugin_col) plugin_col->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_name_clicked));
request list of available plugins
plugin unloaded (plugin_unloaded_msg_t)
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
listing available plugins failed
sigc::signal< void > signal_connected()
Get "connected" signal.
Unsubscribe from watching load/unload events.
Simple Fawkes network client.
void * payload() const
Get payload buffer.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
Representation of a message that is sent over the network.
unsigned short int msgid() const
Get message type ID.
PluginTreeView()
Constructor.
void set_client(FawkesNetworkClient *client)
Set Fawkes network client.
list of loaded plugins (plugin_list_msg_t)
plugin unload failed (plugin_unload_failed_msg_t)
size_t payload_size() const
Get payload size.
plugin loaded (plugin_loaded_msg_t)
request plugin unload (plugin_unload_msg_t)
list of available plugins (plugin_list_msg_t)
void set_gconf_prefix(Glib::ustring gconf_prefix)
Set Gconf prefix.
listing loaded plugins failed
bool connected() const
Check if connection is alive.
MT * msgc() const
Get correctly parsed output.
request lif of loaded plugins
request plugin load (plugin_load_msg_t)
void set_network_client(fawkes::FawkesNetworkClient *client)
Set the network client.
void deregister_handler(unsigned int component_id)
Deregister handler.
sigc::signal< void, FawkesNetworkMessage * > signal_message_received()
Get "message received" signal.
Subscribe for watching load/unload events.
plugin load failed (plugin_load_failed_msg_t)
unsigned short int cid() const
Get component ID.
virtual ~PluginTreeView()
Destructor.
FawkesNetworkClient * get_client()
Get client.