1 | /* |
2 | * gtkappchooser.c: app-chooser interface |
3 | * |
4 | * Copyright (C) 2010 Red Hat, Inc. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public License as |
8 | * published by the Free Software Foundation; either version 2 of the |
9 | * License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public |
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
18 | * |
19 | * Authors: Cosimo Cecchi <ccecchi@redhat.com> |
20 | */ |
21 | |
22 | /** |
23 | * GtkAppChooser: |
24 | * |
25 | * `GtkAppChooser` is an interface for widgets which allow the user to |
26 | * choose an application. |
27 | * |
28 | * The main objects that implement this interface are |
29 | * [class@Gtk.AppChooserWidget], |
30 | * [class@Gtk.AppChooserDialog] and [class@Gtk.AppChooserButton]. |
31 | * |
32 | * Applications are represented by GIO `GAppInfo` objects here. |
33 | * GIO has a concept of recommended and fallback applications for a |
34 | * given content type. Recommended applications are those that claim |
35 | * to handle the content type itself, while fallback also includes |
36 | * applications that handle a more generic content type. GIO also |
37 | * knows the default and last-used application for a given content |
38 | * type. The `GtkAppChooserWidget` provides detailed control over |
39 | * whether the shown list of applications should include default, |
40 | * recommended or fallback applications. |
41 | * |
42 | * To obtain the application that has been selected in a `GtkAppChooser`, |
43 | * use [method@Gtk.AppChooser.get_app_info]. |
44 | */ |
45 | |
46 | #include "config.h" |
47 | |
48 | #include "gtkappchooser.h" |
49 | |
50 | #include "gtkintl.h" |
51 | #include "gtkappchooserprivate.h" |
52 | #include "gtkwidget.h" |
53 | |
54 | #include <glib.h> |
55 | |
56 | G_DEFINE_INTERFACE (GtkAppChooser, gtk_app_chooser, GTK_TYPE_WIDGET); |
57 | |
58 | static void |
59 | gtk_app_chooser_default_init (GtkAppChooserIface *iface) |
60 | { |
61 | GParamSpec *pspec; |
62 | |
63 | /** |
64 | * GtkAppChooser:content-type: (attributes org.gtk.Property.get=gtk_app_chooser_get_content_type) |
65 | * |
66 | * The content type of the `GtkAppChooser` object. |
67 | * |
68 | * See `GContentType` for more information about content types. |
69 | */ |
70 | pspec = g_param_spec_string (name: "content-type" , |
71 | P_("Content type" ), |
72 | P_("The content type used by the open with object" ), |
73 | NULL, |
74 | flags: G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | |
75 | G_PARAM_STATIC_STRINGS); |
76 | g_object_interface_install_property (g_iface: iface, pspec); |
77 | } |
78 | |
79 | |
80 | /** |
81 | * gtk_app_chooser_get_content_type: (attributes org.gtk.Method.get_property=content-type) |
82 | * @self: a `GtkAppChooser` |
83 | * |
84 | * Returns the content type for which the `GtkAppChooser` |
85 | * shows applications. |
86 | * |
87 | * Returns: the content type of @self. Free with g_free() |
88 | */ |
89 | char * |
90 | gtk_app_chooser_get_content_type (GtkAppChooser *self) |
91 | { |
92 | char *retval = NULL; |
93 | |
94 | g_return_val_if_fail (GTK_IS_APP_CHOOSER (self), NULL); |
95 | |
96 | g_object_get (object: self, |
97 | first_property_name: "content-type" , &retval, |
98 | NULL); |
99 | |
100 | return retval; |
101 | } |
102 | |
103 | /** |
104 | * gtk_app_chooser_get_app_info: |
105 | * @self: a `GtkAppChooser` |
106 | * |
107 | * Returns the currently selected application. |
108 | * |
109 | * Returns: (nullable) (transfer full): a `GAppInfo` for the |
110 | * currently selected application |
111 | */ |
112 | GAppInfo * |
113 | gtk_app_chooser_get_app_info (GtkAppChooser *self) |
114 | { |
115 | return GTK_APP_CHOOSER_GET_IFACE (self)->get_app_info (self); |
116 | } |
117 | |
118 | /** |
119 | * gtk_app_chooser_refresh: |
120 | * @self: a `GtkAppChooser` |
121 | * |
122 | * Reloads the list of applications. |
123 | */ |
124 | void |
125 | gtk_app_chooser_refresh (GtkAppChooser *self) |
126 | { |
127 | GTK_APP_CHOOSER_GET_IFACE (self)->refresh (self); |
128 | } |
129 | |