void main(int argc, char **argv) { ThunarPluggerFile *file; GList *flist; GtkWidget *win; char title[1024] = ""; ThunarxProviderFactory* f; GtkWidget *page; int ret = 0; GOptionContext *octx; GError *error = NULL; int i; octx = g_option_context_new ("PATH [PATH ...] - display a Thunar plugin dialog for path(s)"); g_option_context_add_main_entries (octx, opts, NULL); g_option_context_add_group (octx, gtk_get_option_group (TRUE)); if (!g_option_context_parse (octx, &argc, &argv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); exit (1); } if (class_name == NULL || strlen(class_name) == 0) { fprintf (stderr, "Specify the plugin page class name, please.\n"); exit (1); } if (argc < 2) { fprintf (stderr, "Please, specify one path at least.\n"); exit (1); } gtk_init(&argc, &argv); flist = NULL; for (i = 1; i < argc; i++) { file = thunar_plugger_file_get(argv[i]); flist = g_list_append(flist, file); } win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position (GTK_WINDOW(win), GTK_WIN_POS_CENTER_ALWAYS); g_signal_connect_swapped(G_OBJECT(win), "destroy", G_CALLBACK(gtk_main_quit), NULL); f = thunarx_provider_factory_get_default(); page = NULL; if (!page_mode && !menu_mode) { page_mode = TRUE; } if (page_mode) { ret = ! get_property_page(f, flist, class_name, &page, title, sizeof(title), GTK_WINDOW(win)); } else if (menu_mode) { ret = ! get_actions_page (f, flist, dirs_as_files, GTK_WINDOW(win), class_name, &page, title, sizeof(title)); } g_object_unref(f); if (page == NULL || ret) { GtkWidget *label; label = gtk_label_new ("Unable to initialize the plugin\n"); gtk_container_add(GTK_CONTAINER(win), label); } else { gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(page)); if (strlen(title) > 0) { gtk_window_set_title(GTK_WINDOW(win), title); } } gtk_widget_show_all(win); gtk_main(); g_list_foreach (flist, (GFunc) g_object_unref, NULL); g_list_free (flist); exit(ret); }
/** * thunar_dnd_ask: * @widget : the widget on which the drop was performed. * @folder : the #ThunarFile to which the @path_list is being dropped. * @path_list : the #GFile<!---->s of the files being dropped to @file. * @timestamp : the time of the drop event. * @actions : the list of actions supported for the drop. * * Pops up a menu that asks the user to choose one of the * @actions or to cancel the drop. If the user chooses a * valid #GdkDragAction from @actions, then this action is * returned. Else if the user cancels the drop, 0 will be * returned. * * This method can be used to implement a response to the * #GDK_ACTION_ASK action on drops. * * Return value: the selected #GdkDragAction or 0 to cancel. **/ GdkDragAction thunar_dnd_ask (GtkWidget *widget, ThunarFile *folder, GList *path_list, guint timestamp, GdkDragAction dnd_actions) { static const GdkDragAction dnd_action_items[] = { GDK_ACTION_COPY, GDK_ACTION_MOVE, GDK_ACTION_LINK }; static const gchar *dnd_action_names[] = { N_ ("_Copy here"), N_ ("_Move here"), N_ ("_Link here") }; static const gchar *dnd_action_icons[] = { "stock_folder-copy", "stock_folder-move", NULL }; ThunarxProviderFactory *factory; GdkDragAction dnd_action = 0; ThunarFile *file; GtkWidget *window; GtkWidget *image; GtkWidget *menu; GtkWidget *item; GList *file_list = NULL; GList *providers = NULL; GList *actions = NULL; GList *lp; guint n; _thunar_return_val_if_fail (thunar_file_is_directory (folder), 0); _thunar_return_val_if_fail (GTK_IS_WIDGET (widget), 0); /* connect to the provider factory */ factory = thunarx_provider_factory_get_default (); /* prepare the popup menu */ menu = gtk_menu_new (); /* append the various items */ for (n = 0; n < G_N_ELEMENTS (dnd_action_items); ++n) if (G_LIKELY ((dnd_actions & dnd_action_items[n]) != 0)) { item = gtk_image_menu_item_new_with_mnemonic (_(dnd_action_names[n])); g_object_set_data (G_OBJECT (item), I_("dnd-action"), GUINT_TO_POINTER (dnd_action_items[n])); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (dnd_action_selected), &dnd_action); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* add image to the menu item */ if (G_LIKELY (dnd_action_icons[n] != NULL)) { image = gtk_image_new_from_icon_name (dnd_action_icons[n], GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); } } /* append the separator */ item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* determine the toplevel window the widget belongs to */ window = gtk_widget_get_toplevel (widget); if (G_LIKELY (window != NULL && gtk_widget_get_toplevel (window))) { /* check if we can resolve all paths */ for (lp = path_list; lp != NULL; lp = lp->next) { /* try to resolve this path */ file = thunar_file_cache_lookup (lp->data); if (G_LIKELY (file != NULL)) file_list = g_list_prepend (file_list, file); else break; } /* check if we resolved all paths (and have atleast one file) */ if (G_LIKELY (file_list != NULL && lp == NULL)) { /* load the menu providers from the provider factory */ providers = thunarx_provider_factory_list_providers (factory, THUNARX_TYPE_MENU_PROVIDER); /* load the dnd actions offered by the menu providers */ for (lp = providers; lp != NULL; lp = lp->next) { /* merge the actions from this provider */ actions = g_list_concat (actions, thunarx_menu_provider_get_dnd_actions (lp->data, window, THUNARX_FILE_INFO (folder), file_list)); g_object_unref (G_OBJECT (lp->data)); } g_list_free (providers); /* check if we have atleast one action */ if (G_UNLIKELY (actions != NULL)) { /* add menu items for all actions */ for (lp = actions; lp != NULL; lp = lp->next) { /* add a menu item for the action */ item = gtk_action_create_menu_item (lp->data); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_object_unref (G_OBJECT (lp->data)); gtk_widget_show (item); } g_list_free (actions); /* append another separator */ item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } } } /* append the cancel item */ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CANCEL, NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* run the menu on the widget's screen (takes over the floating reference of menu) */ thunar_gtk_menu_run (GTK_MENU (menu), widget, NULL, NULL, 3, timestamp); /* cleanup */ g_object_unref (G_OBJECT (factory)); g_list_free_full (file_list, g_object_unref); return dnd_action; }