static VALUE rg_initialize(int argc, VALUE *argv, VALUE self) { VALUE options, rb_parent, rb_file, rb_flags, rb_content_type; GtkWindow *parent; GtkDialogFlags flags; GtkWidget *widget = NULL; rb_scan_args(argc, argv, "01", &options); rbg_scan_options(options, "parent", &rb_parent, "flags", &rb_flags, "file", &rb_file, "content_type", &rb_content_type, NULL); parent = NIL_P(rb_parent) ? NULL : RVAL2GTKWINDOW(rb_parent); flags = NIL_P(rb_flags) ? 0 : RVAL2GTKDIALOGFLAGS(rb_flags); if (!NIL_P(rb_file)) widget = gtk_app_chooser_dialog_new(parent, flags, RVAL2GFILE(rb_file)); else widget = gtk_app_chooser_dialog_new_for_content_type(parent, flags, RVAL2CSTR(rb_content_type)); RBGTK_INITIALIZE(self, widget); return Qnil; }
static void test_app_chooser_dialog_basic (void) { GtkWidget *widget; widget = gtk_app_chooser_dialog_new_for_content_type (NULL, 0, "text/plain"); g_assert (GTK_IS_APP_CHOOSER_DIALOG (widget)); /* GtkAppChooserDialog bug, if destroyed before spinning * the main context then app_chooser_online_get_default_ready_cb() * will be eventually called and segfault. */ g_timeout_add (500, main_loop_quit_cb, NULL); gtk_main(); gtk_widget_destroy (widget); }
static gboolean open_file_in_application (gpointer user_data) { HandleUnsupportedFileData *data; g_autoptr (GAppInfo) application = NULL; data = user_data; application = nautilus_mime_get_default_application_for_file (data->file); if (!application) { GtkWidget *dialog; g_autofree gchar *mime_type = NULL; mime_type = nautilus_file_get_mime_type (data->file); dialog = gtk_app_chooser_dialog_new_for_content_type (data->parent_window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, mime_type); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { application = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog)); } gtk_widget_destroy (dialog); } if (application) { g_autoptr (GList) files = NULL; files = g_list_append (NULL, data->file); nautilus_launch_application (application, files, data->parent_window); } return G_SOURCE_REMOVE; }
static void prepare_dialog (void) { gboolean use_file = FALSE; gchar *content_type = NULL; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file))) use_file = TRUE; else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content))) use_file = FALSE; if (use_file) { dialog = gtk_app_chooser_dialog_new (GTK_WINDOW (toplevel), 0, file); } else { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); content_type = g_strdup (g_file_info_get_content_type (info)); g_object_unref (info); dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (toplevel), 0, content_type); } gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), "Select one already, you <i>fool</i>"); g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL); g_free (content_type); app_chooser_widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog)); bind_props (); }
static void other_application_item_activated_cb (GtkAppChooserButton *self) { GtkWidget *dialog, *widget; GtkWindow *toplevel; toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))); dialog = gtk_app_chooser_dialog_new_for_content_type (toplevel, GTK_DIALOG_DESTROY_WITH_PARENT, self->priv->content_type); gtk_window_set_modal (GTK_WINDOW (dialog), gtk_window_get_modal (toplevel)); gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), self->priv->heading); widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog)); g_object_set (widget, "show-fallback", TRUE, "show-other", TRUE, NULL); gtk_widget_show (dialog); g_signal_connect (dialog, "response", G_CALLBACK (other_application_dialog_response_cb), self); }