gtkappchooser.c 3.91 KB
Newer Older
1
/*
2
 * gtkappchooser.c: app-chooser interface
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * Copyright (C) 2010 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
17
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 19 20 21
 *
 * Authors: Cosimo Cecchi <ccecchi@redhat.com>
 */

Matthias Clasen's avatar
Matthias Clasen committed
22 23 24
/**
 * SECTION:gtkappchooser
 * @Title: GtkAppChooser
25
 * @Short_description: Interface implemented by widgets for choosing an application
26
 * @See_also: #GAppInfo
Matthias Clasen's avatar
Matthias Clasen committed
27 28 29 30 31
 *
 * #GtkAppChooser is an interface that can be implemented by widgets which
 * allow the user to choose an application (typically for the purpose of
 * opening a file). The main objects that implement this interface are
 * #GtkAppChooserWidget, #GtkAppChooserDialog and #GtkAppChooserButton.
32 33 34 35 36 37 38 39 40 41 42 43 44
 *
 * Applications are represented by GIO #GAppInfo objects here.
 * GIO has a concept of recommended and fallback applications for a
 * given content type. Recommended applications are those that claim
 * to handle the content type itself, while fallback also includes
 * applications that handle a more generic content type. GIO also
 * knows the default and last-used application for a given content
 * type. The #GtkAppChooserWidget provides detailed control over
 * whether the shown list of applications should include default,
 * recommended or fallback applications.
 *
 * To obtain the application that has been selected in a #GtkAppChooser,
 * use gtk_app_chooser_get_app_info().
Matthias Clasen's avatar
Matthias Clasen committed
45 46
 */

Matthias Clasen's avatar
Matthias Clasen committed
47
#include "config.h"
48

49
#include "gtkappchooser.h"
50 51

#include "gtkintl.h"
52
#include "gtkappchooserprivate.h"
53 54 55 56
#include "gtkwidget.h"

#include <glib.h>

57
G_DEFINE_INTERFACE (GtkAppChooser, gtk_app_chooser, GTK_TYPE_WIDGET);
58 59

static void
60
gtk_app_chooser_default_init (GtkAppChooserIface *iface)
61 62 63
{
  GParamSpec *pspec;

Cosimo Cecchi's avatar
Cosimo Cecchi committed
64 65 66 67
  /**
   * GtkAppChooser:content-type:
   *
   * The content type of the #GtkAppChooser object.
68
   *
69
   * See [GContentType][gio-GContentType]
70
   * for more information about content types.
Cosimo Cecchi's avatar
Cosimo Cecchi committed
71
   */
72
  pspec = g_param_spec_string ("content-type",
Matthias Clasen's avatar
Matthias Clasen committed
73 74 75 76 77
                               P_("Content type"),
                               P_("The content type used by the open with object"),
                               NULL,
                               G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
                               G_PARAM_STATIC_STRINGS);
78 79 80
  g_object_interface_install_property (iface, pspec);
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
81 82 83 84 85 86 87 88 89 90 91

/**
 * gtk_app_chooser_get_content_type:
 * @self: a #GtkAppChooser
 *
 * Returns the current value of the #GtkAppChooser:content-type property.
 *
 * Returns: the content type of @self. Free with g_free()
 *
 * Since: 3.0
 */
92
gchar *
93
gtk_app_chooser_get_content_type (GtkAppChooser *self)
94 95 96
{
  gchar *retval = NULL;

97
  g_return_val_if_fail (GTK_IS_APP_CHOOSER (self), NULL);
98 99

  g_object_get (self,
Matthias Clasen's avatar
Matthias Clasen committed
100 101
                "content-type", &retval,
                NULL);
102 103 104 105

  return retval;
}

Matthias Clasen's avatar
Matthias Clasen committed
106 107 108 109 110 111 112
/**
 * gtk_app_chooser_get_app_info:
 * @self: a #GtkAppChooser
 *
 * Returns the currently selected application.
 *
 * Returns: (transfer full): a #GAppInfo for the currently selected
Cosimo Cecchi's avatar
Cosimo Cecchi committed
113
 *     application, or %NULL if none is selected. Free with g_object_unref()
Matthias Clasen's avatar
Matthias Clasen committed
114 115 116
 *
 * Since: 3.0
 */
117
GAppInfo *
118
gtk_app_chooser_get_app_info (GtkAppChooser *self)
119
{
120
  return GTK_APP_CHOOSER_GET_IFACE (self)->get_app_info (self);
121
}
122

Matthias Clasen's avatar
Matthias Clasen committed
123 124 125 126
/**
 * gtk_app_chooser_refresh:
 * @self: a #GtkAppChooser
 *
Cosimo Cecchi's avatar
Cosimo Cecchi committed
127
 * Reloads the list of applications.
Matthias Clasen's avatar
Matthias Clasen committed
128 129 130
 *
 * Since: 3.0
 */
131
void
132
gtk_app_chooser_refresh (GtkAppChooser *self)
133
{
134
  GTK_APP_CHOOSER_GET_IFACE (self)->refresh (self);
135
}