static GList* twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider, GtkWidget *window, GList *files) { GtkWidget *action = NULL; GFile *location; GList *actions = NULL; gchar selection_name[100]; Atom xfce_selection_atom; Atom nautilus_selection_atom; GdkScreen *gdk_screen = gdk_screen_get_default(); gint xscreen = gdk_screen_get_number(gdk_screen); desktop_type = DESKTOP_TYPE_NONE; /* we can only set a single wallpaper */ if (files->next == NULL) { /* get the location of the file */ location = thunarx_file_info_get_location (files->data); /* unable to handle non-local files */ if (G_UNLIKELY (!g_file_has_uri_scheme (location, "file"))) { g_object_unref (location); return NULL; } /* release the location */ g_object_unref (location); if (!thunarx_file_info_is_directory (files->data)) { if (thunarx_file_info_has_mime_type (files->data, "image/jpeg") ||thunarx_file_info_has_mime_type (files->data, "image/png") ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml") ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml-compressed")) { action = g_object_new (GTK_TYPE_ACTION, "name", "Twp::setwallpaper", "icon-name", "background", "label", _("Set as wallpaper"), NULL); g_signal_connect (action, "activate", G_CALLBACK (twp_action_set_wallpaper), files->data); actions = g_list_append (actions, action); } } } g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen); xfce_selection_atom = XInternAtom (gdk_display, selection_name, False); if ((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom))) { if (_has_xfconf_query) desktop_type = DESKTOP_TYPE_XFCE; } else { /* FIXME: This is wrong, nautilus WINDOW_ID is not a selection */ g_snprintf(selection_name, 100, NAUTILUS_SELECTION_FMT); nautilus_selection_atom = XInternAtom (gdk_display, selection_name, False); if((XGetSelectionOwner(GDK_DISPLAY(), nautilus_selection_atom))) { if (_has_gconftool) desktop_type = DESKTOP_TYPE_NAUTILUS; } } if ((desktop_type == DESKTOP_TYPE_NONE) && (action != NULL)) { /* gtk_widget_set_sensitive (action, FALSE); */ } return actions; }
int get_actions_page (ThunarxProviderFactory* f, GList *flist, gboolean dirs_as_files, GtkWindow *win, const char *class_name, GtkWidget **page, char *title, int tlen) { GList *ps, *lp, *files, *dirs, *fas, *das, *as; GtkWidget *vbox; files = NULL; dirs = NULL; if (! dirs_as_files) { for (flist; flist != NULL; flist = flist->next) { if (thunarx_file_info_is_directory(THUNARX_FILE_INFO(flist->data))) { dirs = g_list_append(dirs, flist->data); } else { files = g_list_append(files, flist->data); } } } else { files = flist; } ps = thunarx_provider_factory_list_providers(f, THUNARX_TYPE_MENU_PROVIDER); snprintf(title, tlen, "Choose an action for the %i selected object(s)\n", g_list_length(files) + g_list_length(dirs)); *page = gtk_frame_new (title); gtk_container_set_border_width (GTK_CONTAINER(*page), 10); vbox = gtk_vbox_new(TRUE, 10); gtk_container_set_border_width (GTK_CONTAINER(vbox), 10); gtk_container_add(GTK_CONTAINER(*page), GTK_WIDGET(vbox)); fas = NULL; das = NULL; for (lp = ps; lp != NULL; lp = lp->next) { GList *dp, *as; if (strncmp(class_name, G_OBJECT_TYPE_NAME(lp->data), 256) == 0) { as = thunarx_menu_provider_get_file_actions(lp->data, GTK_WIDGET(win), files); fas = g_list_merge(fas, as); for (dp = dirs; dp != NULL; dp = dp->next) { GList *as; as = thunarx_menu_provider_get_folder_actions(lp->data, GTK_WIDGET(win), dp->data); das = g_list_merge(das, as); g_list_foreach (as, (GFunc) g_object_unref, NULL); g_list_free (as); } g_list_foreach (as, (GFunc) g_object_unref, NULL); g_list_free (as); } } g_list_foreach (ps, (GFunc) g_object_unref, NULL); g_list_free (ps); fas = g_list_merge(fas, das); g_list_foreach (das, (GFunc) g_object_unref, NULL); g_list_free (das); if (g_list_length(fas) > 0) { GList *ap; for (ap = fas; ap != NULL; ap = ap->next) { GtkWidget *b; b = gtk_button_new (); gtk_action_connect_proxy (GTK_ACTION(ap->data), b); gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(b)); g_signal_connect_object (G_OBJECT(b), "clicked", G_CALLBACK(gtk_widget_destroy), win, G_CONNECT_AFTER | G_CONNECT_SWAPPED); } return 1; } else { gtk_container_add(GTK_CONTAINER(vbox), gtk_label_new ("No actions available")); return 1; } }