/* * callback function for a plugin */ static void curses_select_plugin(void *plugin) { /* prevent the selection when the list is empty */ if (plugin == NULL) return; /* print the message */ if (plugin_is_activated(plugin) == 0) INSTANT_USER_MSG("Activating %s plugin...\n", plugin); else INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); /* * pay attention on this ! * if the plugin init does not return, * we are blocked here. So it is encouraged * to write plugins which spawn a thread * and immediately return */ if (plugin_is_activated(plugin) == 1) plugin_fini(plugin); else plugin_init(plugin); /* refres the array for the list widget */ curses_plugins_update(); }
/* * callback function for a plugin */ static void gtkui_select_plugin(void) { GtkTreeIter iter; GtkTreeModel *model; char *plugin = NULL; model = GTK_TREE_MODEL (ls_plugins); if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { gtk_tree_model_get (model, &iter, 1, &plugin, -1); } else return; /* nothing is selected */ if(!plugin) return; /* bad pointer from gtk_tree_model_get, shouldn't happen */ /* print the message */ if (plugin_is_activated(plugin) == 0) INSTANT_USER_MSG("Activating %s plugin...\n", plugin); else INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); /* * pay attention on this ! * if the plugin init does not return, * we are blocked here. So it is encouraged * to write plugins which spawn a thread * and immediately return */ if (plugin_is_activated(plugin) == 1) plugin_fini(plugin); else plugin_init(plugin); /* refresh the list to mark plugin active */ gtkui_create_plug_array(); }
gboolean gtkui_plugin_context(GtkWidget *widget, GdkEventButton *event, gpointer data) { GtkTreeIter iter; GtkTreeModel *model; GtkWidget *menu, *item; char *plugin = NULL; (void) widget; (void) data; model = GTK_TREE_MODEL(ls_plugins); menu = gtk_menu_new(); item = gtk_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtkui_select_plugin), NULL); gtk_widget_show(item); if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION(selection), &model, &iter)) { gtk_tree_model_get (model, &iter, 1, &plugin, -1); } else return FALSE; /* nothing is selected */ if(!plugin) return FALSE; /* bad pointer from gtk_tree_model_get, shouldn't happen */ /* print the message */ if (plugin_is_activated(plugin) == 0) gtk_menu_item_set_label(GTK_MENU_ITEM(item), "Activate"); else gtk_menu_item_set_label(GTK_MENU_ITEM(item), "Deactivate"); if (event->button == 3) { #if GTK_CHECK_VERSION(3,22,0) gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)event); #else gtk_menu_popup(GTK_MENU(data), NULL, NULL, NULL, NULL, 3, event->time); #endif /* * button press event handle must return TRUE to keep the selection * active when pressing the mouse button */ return TRUE; } return FALSE; }