]> Pileus Git - ~andy/gtk/blob - gtk/gtkappchooserdialog.c
Coding style fixups
[~andy/gtk] / gtk / gtkappchooserdialog.c
1 /*
2  * gtkappchooserdialog.c: an app-chooser dialog
3  *
4  * Copyright (C) 2004 Novell, Inc.
5  * Copyright (C) 2007, 2010 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
19  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * Authors: Dave Camp <dave@novell.com>
23  *          Alexander Larsson <alexl@redhat.com>
24  *          Cosimo Cecchi <ccecchi@redhat.com>
25  */
26
27 #include "config.h"
28
29 #include "gtkappchooserdialog.h"
30
31 #include "gtkintl.h"
32 #include "gtkappchooser.h"
33 #include "gtkappchooseronline.h"
34 #include "gtkappchooserprivate.h"
35 #include "gtkappchooserprivate.h"
36
37 #include "gtkmessagedialog.h"
38 #include "gtklabel.h"
39 #include "gtkbbox.h"
40 #include "gtkbutton.h"
41 #include "gtkmenuitem.h"
42 #include "gtkstock.h"
43
44 #include <string.h>
45 #include <glib/gi18n-lib.h>
46 #include <gio/gio.h>
47
48 #define sure_string(s) ((const char *) ((s) != NULL ? (s) : ""))
49
50 struct _GtkAppChooserDialogPrivate {
51   char *content_type;
52   GFile *gfile;
53
54   GtkWidget *label;
55   GtkWidget *button;
56   GtkWidget *online_button;
57
58   GtkWidget *open_label;
59
60   GtkWidget *app_chooser_widget;
61   GtkWidget *show_more_button;
62
63   gboolean show_more_clicked;
64 };
65
66 enum {
67   PROP_GFILE = 1,
68   PROP_CONTENT_TYPE,
69   N_PROPERTIES
70 };
71
72 static void gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface);
73 G_DEFINE_TYPE_WITH_CODE (GtkAppChooserDialog, gtk_app_chooser_dialog, GTK_TYPE_DIALOG,
74                          G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
75                                                 gtk_app_chooser_dialog_iface_init));
76
77 static void
78 show_error_dialog (const gchar *primary,
79                    const gchar *secondary,
80                    GtkWindow   *parent)
81 {
82   GtkWidget *message_dialog;
83
84   message_dialog = gtk_message_dialog_new (parent, 0,
85                                            GTK_MESSAGE_ERROR,
86                                            GTK_BUTTONS_OK,
87                                            NULL);
88   g_object_set (message_dialog,
89                 "text", primary,
90                 "secondary-text", secondary,
91                 NULL);
92   gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_OK);
93
94   gtk_widget_show (message_dialog);
95
96   g_signal_connect (message_dialog, "response",
97                     G_CALLBACK (gtk_widget_destroy), NULL);
98 }
99
100 static void
101 search_for_mimetype_ready_cb (GObject      *source,
102                               GAsyncResult *res,
103                               gpointer      user_data)
104 {
105   GtkAppChooserOnline *online = GTK_APP_CHOOSER_ONLINE (source);
106   GtkAppChooserDialog *self = user_data;
107   GError *error = NULL;
108
109   gtk_app_chooser_online_search_for_mimetype_finish (online, res, &error);
110
111   if (error != NULL)
112     {
113       show_error_dialog (_("Failed to look for applications online"),
114                          error->message, GTK_WINDOW (self));
115       g_error_free (error);
116     }
117   else
118     {
119       gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
120     }
121
122   g_object_unref (online);
123 }
124
125 static void
126 online_button_clicked_cb (GtkButton *b,
127                           gpointer   user_data)
128 {
129   GtkAppChooserOnline *online;
130   GtkAppChooserDialog *self = user_data;
131
132   online = gtk_app_chooser_online_get_default ();
133
134   gtk_app_chooser_online_search_for_mimetype_async (online,
135                                                     self->priv->content_type,
136                                                     GTK_WINDOW (self),
137                                                     search_for_mimetype_ready_cb,
138                                                     self);
139 }
140
141 /* An application is valid if:
142  *
143  * 1) The file exists
144  * 2) The user has permissions to run the file
145  */
146 static gboolean
147 check_application (GtkAppChooserDialog  *self,
148                    GAppInfo            **app_out)
149 {
150   const char *command;
151   char *path = NULL;
152   char **argv = NULL;
153   int argc;
154   GError *error = NULL;
155   gint retval = TRUE;
156   GAppInfo *info;
157
158   command = NULL;
159
160   info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
161   command = g_app_info_get_executable (info);
162
163   g_shell_parse_argv (command, &argc, &argv, &error);
164
165   if (error)
166     {
167       show_error_dialog (_("Could not run application"),
168                          error->message,
169                          GTK_WINDOW (self));
170       g_error_free (error);
171       retval = FALSE;
172       goto cleanup;
173     }
174
175   path = g_find_program_in_path (argv[0]);
176   if (!path)
177     {
178       char *error_message;
179
180       error_message = g_strdup_printf (_("Could not find '%s'"),
181                                        argv[0]);
182
183       show_error_dialog (_("Could not find application"),
184                          error_message,
185                          GTK_WINDOW (self));
186       g_free (error_message);
187       retval = FALSE;
188       goto cleanup;
189     }
190
191   *app_out = info;
192
193  cleanup:
194   g_strfreev (argv);
195   g_free (path);
196
197   return retval;
198 }
199
200 static void
201 add_or_find_application (GtkAppChooserDialog *self)
202 {
203   GAppInfo *app;
204
205   app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
206
207   /* we don't care about reporting errors here */
208   g_app_info_add_supports_type (app,
209                                 self->priv->content_type,
210                                 NULL);
211
212   g_object_unref (app);
213 }
214
215 static void
216 gtk_app_chooser_dialog_response (GtkDialog *dialog,
217                                  gint       response_id,
218                                  gpointer   user_data)
219 {
220   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (dialog);
221
222   switch (response_id)
223     {
224     case GTK_RESPONSE_OK:
225       add_or_find_application (self);
226       break;
227     default :
228       break;
229     }
230 }
231
232 static void
233 widget_application_selected_cb (GtkAppChooserWidget *widget,
234                                 GAppInfo            *app_info,
235                                 gpointer             user_data)
236 {
237   GtkAppChooserDialog *self = user_data;
238
239   gtk_widget_set_sensitive (self->priv->button, TRUE);
240 }
241
242 static void
243 widget_application_activated_cb (GtkAppChooserWidget *widget,
244                                  GAppInfo            *app_info,
245                                  gpointer             user_data)
246 {
247   GtkAppChooserDialog *self = user_data;
248
249   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
250 }
251
252 static char *
253 get_extension (const char *basename)
254 {
255   char *p;
256
257   p = strrchr (basename, '.');
258
259   if (p && *(p + 1) != '\0')
260     return g_strdup (p + 1);
261
262   return NULL;
263 }
264
265 static void
266 set_dialog_properties (GtkAppChooserDialog *self)
267 {
268   gchar *label;
269   gchar *name;
270   gchar *extension;
271   gchar *description;
272   gchar *default_text;
273   gchar *string;
274   PangoFontDescription *font_desc;
275
276   name = NULL;
277   extension = NULL;
278   label = NULL;
279   description = NULL;
280
281   if (self->priv->gfile != NULL)
282     {
283       name = g_file_get_basename (self->priv->gfile);
284       extension = get_extension (name);
285     }
286
287   description = g_content_type_get_description (self->priv->content_type);
288   gtk_window_set_title (GTK_WINDOW (self), "");
289
290   if (name != NULL)
291     {
292       /* Translators: %s is a filename */
293       label = g_strdup_printf (_("Select an application to open \"%s\""), name);
294       string = g_strdup_printf (_("No applications available to open \"%s\""),
295                                 name);
296     }
297   else
298     {
299       /* Translators: %s is a file type description */
300       label = g_strdup_printf (_("Select an application for \"%s\" files"),
301                                g_content_type_is_unknown (self->priv->content_type) ?
302                                self->priv->content_type : description);
303       string = g_strdup_printf (_("No applications available to open \"%s\" files"),
304                                g_content_type_is_unknown (self->priv->content_type) ?
305                                self->priv->content_type : description);
306     }
307
308   font_desc = pango_font_description_new ();
309   pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
310   gtk_widget_modify_font (self->priv->label, font_desc);
311   pango_font_description_free (font_desc);
312
313   gtk_label_set_markup (GTK_LABEL (self->priv->label), label);
314
315   default_text = g_strdup_printf ("<big><b>%s</b></big>\n%s",
316                                   string,
317                                   _("Click \"Show other applications\", for more options, or "
318                                     "\"Find applications online\" to install a new application"));
319
320   gtk_app_chooser_widget_set_default_text (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget),
321                                            default_text);
322
323   g_free (label);
324   g_free (name);
325   g_free (extension);
326   g_free (description);
327   g_free (string);
328   g_free (default_text);
329 }
330
331 static void
332 show_more_button_clicked_cb (GtkButton *button,
333                              gpointer   user_data)
334 {
335   GtkAppChooserDialog *self = user_data;
336
337   g_object_set (self->priv->app_chooser_widget,
338                 "show-recommended", TRUE,
339                 "show-fallback", TRUE,
340                 "show-other", TRUE,
341                 NULL);
342
343   gtk_widget_hide (self->priv->show_more_button);
344   self->priv->show_more_clicked = TRUE;
345 }
346
347 static void
348 widget_notify_for_button_cb (GObject    *source,
349                              GParamSpec *pspec,
350                              gpointer    user_data)
351 {
352   GtkAppChooserDialog *self = user_data;
353   GtkAppChooserWidget *widget = GTK_APP_CHOOSER_WIDGET (source);
354   gboolean should_hide;
355
356   should_hide = gtk_app_chooser_widget_get_show_all (widget) ||
357     self->priv->show_more_clicked;
358
359   if (should_hide)
360     gtk_widget_hide (self->priv->show_more_button);
361 }
362
363 static void
364 forget_menu_item_activate_cb (GtkMenuItem *item,
365                               gpointer     user_data)
366 {
367   GtkAppChooserDialog *self = user_data;
368   GAppInfo *info;
369
370   info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
371
372   if (info != NULL)
373     {
374       g_app_info_remove_supports_type (info, self->priv->content_type, NULL);
375
376       gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
377
378       g_object_unref (info);
379     }
380 }
381
382 static GtkWidget *
383 build_forget_menu_item (GtkAppChooserDialog *self)
384 {
385   GtkWidget *retval;
386
387   retval = gtk_menu_item_new_with_label (_("Forget association"));
388   gtk_widget_show (retval);
389
390   g_signal_connect (retval, "activate",
391                     G_CALLBACK (forget_menu_item_activate_cb), self);
392
393   return retval;
394 }
395
396 static void
397 widget_populate_popup_cb (GtkAppChooserWidget *widget,
398                           GtkMenu             *menu,
399                           GAppInfo            *info,
400                           gpointer             user_data)
401 {
402   GtkAppChooserDialog *self = user_data;
403   GtkWidget *menu_item;
404
405   if (g_app_info_can_remove_supports_type (info))
406     {
407       menu_item = build_forget_menu_item (self);
408       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
409     }
410 }
411
412 static void
413 build_dialog_ui (GtkAppChooserDialog *self)
414 {
415   GtkWidget *vbox;
416   GtkWidget *vbox2;
417   GtkWidget *label;
418   GtkWidget *action_area, *button, *w;
419
420   gtk_container_set_border_width (GTK_CONTAINER (self), 5);
421
422   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
423   gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
424   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
425   gtk_widget_show (vbox);
426
427   vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
428   gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
429   gtk_widget_show (vbox2);
430
431   self->priv->label = gtk_label_new ("");
432   gtk_misc_set_alignment (GTK_MISC (self->priv->label), 0, 0.5);
433   gtk_label_set_line_wrap (GTK_LABEL (self->priv->label), TRUE);
434   gtk_box_pack_start (GTK_BOX (vbox2), self->priv->label,
435                       FALSE, FALSE, 0);
436   gtk_widget_show (self->priv->label);
437
438   self->priv->app_chooser_widget =
439     gtk_app_chooser_widget_new (self->priv->content_type);
440   gtk_box_pack_start (GTK_BOX (vbox2), self->priv->app_chooser_widget, TRUE, TRUE, 0);
441   gtk_widget_show (self->priv->app_chooser_widget);
442
443   g_signal_connect (self->priv->app_chooser_widget, "application-selected",
444                     G_CALLBACK (widget_application_selected_cb), self);
445   g_signal_connect (self->priv->app_chooser_widget, "application-activated",
446                     G_CALLBACK (widget_application_activated_cb), self);
447   g_signal_connect (self->priv->app_chooser_widget, "notify::show-all",
448                     G_CALLBACK (widget_notify_for_button_cb), self);
449   g_signal_connect (self->priv->app_chooser_widget, "populate-popup",
450                     G_CALLBACK (widget_populate_popup_cb), self);
451
452   button = gtk_button_new_with_label (_("Show other applications"));
453   self->priv->show_more_button = button;
454   w = gtk_image_new_from_stock (GTK_STOCK_ADD,
455                                 GTK_ICON_SIZE_BUTTON);
456   gtk_button_set_image (GTK_BUTTON (button), w);
457   gtk_box_pack_start (GTK_BOX (self->priv->app_chooser_widget), button, FALSE, FALSE, 6);
458   gtk_widget_show_all (button);
459
460   g_signal_connect (button, "clicked",
461                     G_CALLBACK (show_more_button_clicked_cb), self);
462
463   gtk_dialog_add_button (GTK_DIALOG (self),
464                          GTK_STOCK_CANCEL,
465                          GTK_RESPONSE_CANCEL);
466
467   /* Create a custom stock icon */
468   self->priv->button = gtk_button_new ();
469
470   label = gtk_label_new_with_mnemonic (_("_Open"));
471   gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (self->priv->button));
472   gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
473   gtk_widget_show (label);
474   self->priv->open_label = label;
475
476   gtk_container_add (GTK_CONTAINER (self->priv->button),
477                      self->priv->open_label);
478
479   gtk_widget_show (self->priv->button);
480   gtk_widget_set_can_default (self->priv->button, TRUE);
481
482   gtk_dialog_add_action_widget (GTK_DIALOG (self),
483                                 self->priv->button, GTK_RESPONSE_OK);
484
485   action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
486   self->priv->online_button = gtk_button_new_with_label (_("Find applications online"));
487   gtk_box_pack_start (GTK_BOX (action_area), self->priv->online_button,
488                       FALSE, FALSE, 0);
489   gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), self->priv->online_button,
490                                       TRUE);
491   gtk_widget_show (self->priv->online_button);
492   g_signal_connect (self->priv->online_button, "clicked",
493                     G_CALLBACK (online_button_clicked_cb), self);
494
495   gtk_dialog_set_default_response (GTK_DIALOG (self),
496                                    GTK_RESPONSE_OK);
497 }
498
499 static void
500 set_gfile_and_content_type (GtkAppChooserDialog *self,
501                             GFile *file)
502 {
503   GFileInfo *info;
504
505   if (file == NULL)
506     return;
507
508   self->priv->gfile = g_object_ref (file);
509
510   info = g_file_query_info (self->priv->gfile,
511                             G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
512                             0, NULL, NULL);
513   self->priv->content_type = g_strdup (g_file_info_get_content_type (info));
514
515   g_object_unref (info);
516 }
517
518 static GAppInfo *
519 gtk_app_chooser_dialog_get_app_info (GtkAppChooser *object)
520 {
521   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
522   GAppInfo *app = NULL;
523
524   if (!check_application (self, &app))
525     return NULL;
526
527   return app;
528 }
529
530 static void
531 gtk_app_chooser_dialog_refresh (GtkAppChooser *object)
532 {
533   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
534
535   gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
536 }
537
538 static void
539 gtk_app_chooser_dialog_constructed (GObject *object)
540 {
541   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
542
543   g_assert (self->priv->content_type != NULL ||
544             self->priv->gfile != NULL);
545
546   if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
547     G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
548
549   build_dialog_ui (self);
550   set_dialog_properties (self);
551 }
552
553 static void
554 gtk_app_chooser_dialog_finalize (GObject *object)
555 {
556   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
557
558   if (self->priv->gfile)
559     g_object_unref (self->priv->gfile);
560
561   g_free (self->priv->content_type);
562
563   G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->finalize (object);
564 }
565
566 static void
567 gtk_app_chooser_dialog_set_property (GObject      *object,
568                                      guint         property_id,
569                                      const GValue *value,
570                                      GParamSpec   *pspec)
571 {
572   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
573
574   switch (property_id)
575     {
576     case PROP_GFILE:
577       set_gfile_and_content_type (self, g_value_get_object (value));
578       break;
579     case PROP_CONTENT_TYPE:
580       /* don't try to override a value previously set with the GFile */
581       if (self->priv->content_type == NULL)
582         self->priv->content_type = g_value_dup_string (value);
583       break;
584     default:
585       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
586       break;
587     }
588 }
589
590 static void
591 gtk_app_chooser_dialog_get_property (GObject    *object,
592                                      guint       property_id,
593                                      GValue     *value,
594                                      GParamSpec *pspec)
595 {
596   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
597
598   switch (property_id)
599     {
600     case PROP_GFILE:
601       if (self->priv->gfile != NULL)
602         g_value_set_object (value, self->priv->gfile);
603       break;
604     case PROP_CONTENT_TYPE:
605       g_value_set_string (value, self->priv->content_type);
606       break;
607     default:
608       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
609       break;
610     }
611 }
612
613 static void
614 gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface)
615 {
616   iface->get_app_info = gtk_app_chooser_dialog_get_app_info;
617   iface->refresh = gtk_app_chooser_dialog_refresh;
618 }
619
620 static void
621 gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
622 {
623   GObjectClass *gobject_class;
624   GParamSpec *pspec;
625
626   gobject_class = G_OBJECT_CLASS (klass);
627   gobject_class->finalize = gtk_app_chooser_dialog_finalize;
628   gobject_class->set_property = gtk_app_chooser_dialog_set_property;
629   gobject_class->get_property = gtk_app_chooser_dialog_get_property;
630   gobject_class->constructed = gtk_app_chooser_dialog_constructed;
631
632   g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
633
634   pspec = g_param_spec_object ("gfile",
635                                P_("GFile"),
636                                P_("The GFile used by the open with dialog"),
637                                G_TYPE_FILE,
638                                G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
639                                G_PARAM_STATIC_STRINGS);
640   g_object_class_install_property (gobject_class, PROP_GFILE, pspec);
641
642   g_type_class_add_private (klass, sizeof (GtkAppChooserDialogPrivate));
643 }
644
645 static void
646 gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
647 {
648   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_DIALOG,
649                                             GtkAppChooserDialogPrivate);
650
651   /* we can't override the class signal handler here, as it's a RUN_LAST;
652    * we want our signal handler instead to be executed before any user code.
653    */
654   g_signal_connect (self, "response",
655                     G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
656 }
657
658 static void
659 set_parent_and_flags (GtkWidget      *dialog,
660                       GtkWindow      *parent,
661                       GtkDialogFlags  flags)
662 {
663   if (parent != NULL)
664     gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
665
666   if (flags & GTK_DIALOG_MODAL)
667     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
668
669   if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
670     gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
671 }
672
673 /**
674  * gtk_app_chooser_dialog_new:
675  * @parent: (allow-none): a #GtkWindow, or %NULL
676  * @flags: flags for this dialog
677  * @file: a #GFile
678  *
679  * Creates a new #GtkAppChooserDialog for the provided #GFile,
680  * to allow the user to select an application for it.
681  *
682  * Returns: a newly created #GtkAppChooserDialog
683  *
684  * Since: 3.0
685  **/
686 GtkWidget *
687 gtk_app_chooser_dialog_new (GtkWindow      *parent,
688                             GtkDialogFlags  flags,
689                             GFile          *file)
690 {
691   GtkWidget *retval;
692
693   g_return_val_if_fail (G_IS_FILE (file), NULL);
694
695   retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
696                          "gfile", file,
697                          NULL);
698
699   set_parent_and_flags (retval, parent, flags);
700
701   return retval;
702 }
703
704 /**
705  * gtk_app_chooser_dialog_new_for_content_type:
706  * @parent: (allow-none): a #GtkWindow, or %NULL
707  * @flags: flags for this dialog
708  * @content_type: a content type string
709  *
710  * Creates a new #GtkAppChooserDialog for the provided content type,
711  * to allow the user to select an application for it.
712  *
713  * Returns: a newly created #GtkAppChooserDialog
714  *
715  * Since: 3.0
716  **/
717 GtkWidget *
718 gtk_app_chooser_dialog_new_for_content_type (GtkWindow      *parent,
719                                              GtkDialogFlags  flags,
720                                              const gchar    *content_type)
721 {
722   GtkWidget *retval;
723
724   g_return_val_if_fail (content_type != NULL, NULL);
725
726   retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
727                          "content-type", content_type,
728                          NULL);
729
730   set_parent_and_flags (retval, parent, flags);
731
732   return retval;
733 }
734
735 /**
736  * gtk_app_chooser_dialog_get_widget:
737  * @self: a #GtkAppChooserDialog
738  *
739  * Returns the #GtkAppChooserWidget of this dialog.
740  *
741  * Returns: the #GtkAppChooserWidget of @self
742  *
743  * Since: 3.0
744  */
745 GtkWidget *
746 gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self)
747 {
748   g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
749
750   return self->priv->app_chooser_widget;
751 }