static void populate_from_directory (NemoScriptConfigWidget *widget, const gchar *path) { GDir *dir; dir = g_dir_open (path, 0, NULL); if (dir) { const char *name; while ((name = g_dir_read_name (dir))) { char *filename; filename = g_build_filename (path, name, NULL); if (g_file_test (filename, G_FILE_TEST_IS_DIR)) { populate_from_directory (widget, filename); g_free (filename); continue; } ScriptProxy *p = g_slice_new0 (ScriptProxy); p->name = g_strdup (name); p->widget = widget; widget->scripts = g_list_append (widget->scripts, p); g_free (filename); } g_dir_close (dir); } }
static void refresh_widget (NemoActionConfigWidget *widget) { gchar **data_dirs; gchar *path; guint i; if (widget->actions != NULL) { g_list_free_full (widget->actions, (GDestroyNotify) action_proxy_free); widget->actions = NULL; } nemo_config_base_widget_clear_list (NEMO_CONFIG_BASE_WIDGET (widget)); data_dirs = (gchar **) g_get_system_data_dirs (); for (i = 0; i < g_strv_length (data_dirs); i++) { path = g_build_filename (data_dirs[i], "nemo", "actions", NULL); populate_from_directory (widget, path); g_clear_pointer (&path, g_free); } path = nemo_action_manager_get_user_directory_path (); populate_from_directory (widget, path); g_clear_pointer (&path, g_free); if (widget->actions == NULL) { GtkWidget *empty_label = gtk_label_new (NULL); gchar *markup = NULL; markup = g_strdup_printf ("<i>%s</i>", _("No actions found")); gtk_label_set_markup (GTK_LABEL (empty_label), markup); g_free (markup); GtkWidget *empty_row = gtk_list_box_row_new (); gtk_container_add (GTK_CONTAINER (empty_row), empty_label); gtk_widget_show_all (empty_row); gtk_container_add (GTK_CONTAINER (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), empty_row); gtk_widget_set_sensitive (GTK_WIDGET (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), FALSE); } else { GList *l; gchar **blacklist = g_settings_get_strv (nemo_plugin_preferences, NEMO_PLUGIN_PREFERENCES_DISABLED_ACTIONS); for (l = widget->actions; l != NULL; l=l->next) { ActionProxy *proxy = l->data; gboolean active = TRUE; guint i = 0; for (i = 0; i < g_strv_length (blacklist); i++) { if (g_strcmp0 (blacklist[i], proxy->filename) == 0) { active = FALSE; break; } } GtkWidget *w; GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget *button = gtk_check_button_new (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active); g_signal_connect (button, "toggled", G_CALLBACK (on_check_toggled), proxy); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2); w = gtk_image_new (); if (proxy->stock_id != NULL) gtk_image_set_from_stock (GTK_IMAGE (w), proxy->stock_id, GTK_ICON_SIZE_MENU); else if (proxy->icon_name != NULL) gtk_image_set_from_icon_name (GTK_IMAGE (w), proxy->icon_name, GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 2); gchar *display_name = strip_accel (proxy->name); w = gtk_label_new (display_name); g_free (display_name); gtk_widget_set_tooltip_text(w, proxy->comment); gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 2); GtkWidget *row = gtk_list_box_row_new (); gtk_container_add (GTK_CONTAINER (row), box); gtk_widget_show_all (row); gtk_container_add (GTK_CONTAINER (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), row); } gtk_widget_set_sensitive (GTK_WIDGET (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), TRUE); g_strfreev (blacklist); } nemo_config_base_widget_set_default_buttons_sensitive (NEMO_CONFIG_BASE_WIDGET (widget), widget->actions != NULL); }
static void refresh_widget (NemoScriptConfigWidget *widget) { if (widget->scripts != NULL) { g_list_free_full (widget->scripts, (GDestroyNotify) script_proxy_free); widget->scripts = NULL; } nemo_config_base_widget_clear_list (NEMO_CONFIG_BASE_WIDGET (widget)); gchar *path = NULL; path = nemo_get_scripts_directory_path (); populate_from_directory (widget, path); g_clear_pointer (&path, g_free); if (widget->scripts == NULL) { GtkWidget *empty_label = gtk_label_new (NULL); gchar *markup = NULL; markup = g_strdup_printf ("<i>%s</i>", _("No scripts found")); gtk_label_set_markup (GTK_LABEL (empty_label), markup); g_free (markup); GtkWidget *empty_row = gtk_list_box_row_new (); gtk_container_add (GTK_CONTAINER (empty_row), empty_label); gtk_widget_show_all (empty_row); gtk_container_add (GTK_CONTAINER (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), empty_row); gtk_widget_set_sensitive (GTK_WIDGET (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), FALSE); } else { GList *l; gchar **blacklist = g_settings_get_strv (nemo_plugin_preferences, NEMO_PLUGIN_PREFERENCES_DISABLED_SCRIPTS); for (l = widget->scripts; l != NULL; l=l->next) { ScriptProxy *proxy = l->data; gboolean active = TRUE; gint i = 0; for (i = 0; i < g_strv_length (blacklist); i++) { if (g_strcmp0 (blacklist[i], proxy->name) == 0) { active = FALSE; break; } } GtkWidget *w; GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget *button = gtk_check_button_new (); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active); g_signal_connect (button, "toggled", G_CALLBACK (on_check_toggled), proxy); gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 2); w = gtk_label_new (proxy->name); gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 2); GtkWidget *row = gtk_list_box_row_new (); gtk_container_add (GTK_CONTAINER (row), box); gtk_widget_show_all (row); gtk_container_add (GTK_CONTAINER (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), row); } gtk_widget_set_sensitive (GTK_WIDGET (NEMO_CONFIG_BASE_WIDGET (widget)->listbox), TRUE); g_strfreev (blacklist); } nemo_config_base_widget_set_default_buttons_sensitive (NEMO_CONFIG_BASE_WIDGET (widget), widget->scripts != NULL); }