25 #include <gui_utils/plugin_tree_view.h>
26 #include <gui_utils/twolines_cellrenderer.h>
27 #include <netcomm/fawkes/client.h>
28 #include <plugin/net/list_message.h>
29 #include <plugin/net/messages.h>
61 PluginTreeView::PluginTreeView() : m_dispatcher(FAWKES_CID_PLUGINMANAGER)
71 : Gtk::TreeView(cobject), m_dispatcher(FAWKES_CID_PLUGINMANAGER)
77 PluginTreeView::ctor()
79 m_plugin_list = Gtk::ListStore::create(m_plugin_record);
80 set_model(m_plugin_list);
82 append_column(
"#", m_plugin_record.index);
83 append_column_editable(
"Status", m_plugin_record.loaded);
84 append_plugin_column();
87 Gtk::TreeViewColumn *column = get_column(0);
88 column->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_id_clicked));
89 column = get_column(1);
90 column->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_status_clicked));
92 Gtk::CellRendererToggle *renderer;
93 renderer =
dynamic_cast<Gtk::CellRendererToggle *
>(get_column_cell_renderer(1));
94 renderer->signal_toggled().connect(sigc::mem_fun(*
this, &PluginTreeView::on_status_toggled));
98 m_dispatcher.
signal_connected().connect(sigc::mem_fun(*
this, &PluginTreeView::on_connected));
100 sigc::mem_fun(*
this, &PluginTreeView::on_disconnected));
102 sigc::mem_fun(*
this, &PluginTreeView::on_message_received));
119 gconf_->remove_dir(gconf_prefix_);
141 gconf_ = Gnome::Conf::Client::get_default_client();
143 gconf_->remove_dir(gconf_prefix_);
146 gconf_->add_dir(gconf_prefix);
147 gconf_prefix_ = gconf_prefix;
149 if (gconf_connection_) {
150 gconf_connection_.disconnect();
152 gconf_connection_ = gconf_->signal_value_changed().connect(
153 sigc::hide(sigc::hide(sigc::mem_fun(*
this, &PluginTreeView::on_config_changed))));
160 PluginTreeView::on_connected()
177 }
catch (Exception &e) {
184 PluginTreeView::on_disconnected()
186 m_plugin_list->clear();
192 if (msg->
cid() != FAWKES_CID_PLUGINMANAGER)
196 unsigned int msgid = msg->
msgid();
199 Glib::ustring name =
"";
203 if (msg->
payload_size() !=
sizeof(plugin_loaded_msg_t)) {
204 printf(
"Invalid message size (load succeeded)\n");
206 plugin_loaded_msg_t *m = (plugin_loaded_msg_t *)msg->
payload();
211 if (msg->
payload_size() !=
sizeof(plugin_load_failed_msg_t)) {
212 printf(
"Invalid message size (load failed)\n");
214 plugin_load_failed_msg_t *m = (plugin_load_failed_msg_t *)msg->
payload();
219 if (msg->
payload_size() !=
sizeof(plugin_unloaded_msg_t)) {
220 printf(
"Invalid message size (unload succeeded)\n");
222 plugin_unloaded_msg_t *m = (plugin_unloaded_msg_t *)msg->
payload();
227 if (msg->
payload_size() !=
sizeof(plugin_unload_failed_msg_t)) {
228 printf(
"Invalid message size (unload failed)\n");
230 plugin_unload_failed_msg_t *m = (plugin_unload_failed_msg_t *)msg->
payload();
237 for (iter = m_plugin_list->children().begin(); iter != m_plugin_list->children().end();
239 Glib::ustring n = (*iter)[m_plugin_record.name];
241 (*iter)[m_plugin_record.loaded] = loaded;
246 m_plugin_list->clear();
247 PluginListMessage *plm = msg->
msgc<PluginListMessage>();
248 while (plm->has_next()) {
249 char *plugin_name = plm->next();
250 char *plugin_desc = NULL;
251 if (plm->has_next()) {
252 plugin_desc = plm->next();
254 plugin_desc = strdup(
"Unknown, malformed plugin list message?");
257 Gtk::TreeModel::Row row = *m_plugin_list->append();
258 unsigned int index = m_plugin_list->children().size();
259 row[m_plugin_record.index] = index;
260 row[m_plugin_record.name] = plugin_name;
261 row[m_plugin_record.description] = plugin_desc;
262 row[m_plugin_record.loaded] =
false;
269 printf(
"Obtaining list of available plugins failed\n");
271 PluginListMessage *plm = msg->
msgc<PluginListMessage>();
272 while (plm->has_next()) {
273 char *name = plm->next();
276 for (iter = m_plugin_list->children().begin(); iter != m_plugin_list->children().end();
278 Glib::ustring n = (*iter)[m_plugin_record.name];
280 (*iter)[m_plugin_record.loaded] =
true;
288 printf(
"Obtaining list of loaded plugins failed\n");
293 printf(
"received message with msg-id %d\n", msg->
msgid());
302 PluginTreeView::on_status_toggled(
const Glib::ustring &path)
307 Gtk::TreeModel::Row row = *m_plugin_list->get_iter(path);
308 Glib::ustring plugin_name = row[m_plugin_record.name];
309 bool loaded = row[m_plugin_record.loaded];
312 plugin_load_msg_t *m = (plugin_load_msg_t *)calloc(1,
sizeof(plugin_load_msg_t));
313 strncpy(m->name, plugin_name.c_str(), PLUGIN_MSG_NAME_LENGTH - 1);
315 FawkesNetworkMessage *msg =
new FawkesNetworkMessage(FAWKES_CID_PLUGINMANAGER,
318 sizeof(plugin_load_msg_t));
321 plugin_unload_msg_t *m = (plugin_unload_msg_t *)calloc(1,
sizeof(plugin_unload_msg_t));
322 strncpy(m->name, plugin_name.c_str(), PLUGIN_MSG_NAME_LENGTH - 1);
324 FawkesNetworkMessage *msg =
new FawkesNetworkMessage(FAWKES_CID_PLUGINMANAGER,
327 sizeof(plugin_unload_msg_t));
336 PluginTreeView::on_id_clicked()
338 m_plugin_list->set_sort_column(0, Gtk::SORT_ASCENDING);
345 PluginTreeView::on_status_clicked()
347 m_plugin_list->set_sort_column(2, Gtk::SORT_DESCENDING);
354 PluginTreeView::on_name_clicked()
356 m_plugin_list->set_sort_column(1, Gtk::SORT_ASCENDING);
363 PluginTreeView::on_config_changed()
365 Gtk::TreeViewColumn *plugin_col = get_column(2);
367 remove_column(*plugin_col);
369 append_plugin_column();
376 PluginTreeView::append_plugin_column()
378 #if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14)
379 bool description_as_tooltip =
false;
382 description_as_tooltip = gconf_->get_bool(gconf_prefix_ +
"/description_as_tooltip");
387 #if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14)
388 if (description_as_tooltip) {
390 append_column(
"Plugin", m_plugin_record.name);
391 #if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 14)
392 set_tooltip_column(2);
394 TwoLinesCellRenderer *twolines_renderer =
new TwoLinesCellRenderer();
395 Gtk::TreeViewColumn *tlcol =
new Gtk::TreeViewColumn(
"Plugin", *Gtk::manage(twolines_renderer));
396 append_column(*Gtk::manage(tlcol));
398 # ifdef GLIBMM_PROPERTIES_ENABLED
399 tlcol->add_attribute(twolines_renderer->property_line1(), m_plugin_record.name);
400 tlcol->add_attribute(twolines_renderer->property_line2(), m_plugin_record.description);
402 tlcol->add_attribute(*twolines_renderer,
"line1", m_plugin_record.name);
403 tlcol->add_attribute(*twolines_renderer,
"line2", m_plugin_record.description);
406 set_tooltip_column(-1);
410 set_headers_clickable();
411 Gtk::TreeViewColumn *plugin_col = get_column(2);
413 plugin_col->signal_clicked().connect(sigc::mem_fun(*
this, &PluginTreeView::on_name_clicked));
void set_client(FawkesNetworkClient *client)
Set Fawkes network client.
sigc::signal< void > signal_connected()
Get "connected" signal.
FawkesNetworkClient * get_client()
Get client.
sigc::signal< void, FawkesNetworkMessage * > signal_message_received()
Get "message received" signal.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
Simple Fawkes network client.
bool connected() const
Check if connection is alive.
void deregister_handler(unsigned int component_id)
Deregister handler.
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.
unsigned short int cid() const
Get component ID.
void * payload() const
Get payload buffer.
size_t payload_size() const
Get payload size.
MT * msgc() const
Get correctly parsed output.
virtual ~PluginTreeView()
Destructor.
PluginTreeView()
Constructor.
void set_network_client(fawkes::FawkesNetworkClient *client)
Set the network client.
void set_gconf_prefix(Glib::ustring gconf_prefix)
Set Gconf prefix.
Fawkes library namespace.
@ MSG_PLUGIN_UNLOAD
request plugin unload (plugin_unload_msg_t)
@ MSG_PLUGIN_UNLOAD_FAILED
plugin unload failed (plugin_unload_failed_msg_t)
@ MSG_PLUGIN_LIST_LOADED
request lif of loaded plugins
@ MSG_PLUGIN_AVAIL_LIST_FAILED
listing available plugins failed
@ MSG_PLUGIN_LOADED_LIST_FAILED
listing loaded plugins failed
@ MSG_PLUGIN_AVAIL_LIST
list of available plugins (plugin_list_msg_t)
@ MSG_PLUGIN_LOAD
request plugin load (plugin_load_msg_t)
@ MSG_PLUGIN_LOAD_FAILED
plugin load failed (plugin_load_failed_msg_t)
@ MSG_PLUGIN_LOADED_LIST
list of loaded plugins (plugin_list_msg_t)
@ MSG_PLUGIN_LIST_AVAIL
request list of available plugins
@ MSG_PLUGIN_SUBSCRIBE_WATCH
Subscribe for watching load/unload events.
@ MSG_PLUGIN_UNSUBSCRIBE_WATCH
Unsubscribe from watching load/unload events.
@ MSG_PLUGIN_UNLOADED
plugin unloaded (plugin_unloaded_msg_t)
@ MSG_PLUGIN_LOADED
plugin loaded (plugin_loaded_msg_t)