2010-11-17 18:28:48 +00:00
|
|
|
|
/*
|
2010-11-23 16:23:37 +00:00
|
|
|
|
* gtkappchooserwidget.c: an app-chooser widget
|
2010-11-17 18:28:48 +00:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2004 Novell, Inc.
|
|
|
|
|
* Copyright (C) 2007, 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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-17 18:28:48 +00:00
|
|
|
|
*
|
|
|
|
|
* Authors: Dave Camp <dave@novell.com>
|
|
|
|
|
* Alexander Larsson <alexl@redhat.com>
|
|
|
|
|
* Cosimo Cecchi <ccecchi@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
#include "config.h"
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
#include "gtkappchooserwidget.h"
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtkmarshalers.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
|
#include "gtkappchooserwidget.h"
|
2010-11-23 16:23:37 +00:00
|
|
|
|
#include "gtkappchooserprivate.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
|
#include "gtkliststore.h"
|
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
|
#include "gtktreemodelsort.h"
|
|
|
|
|
#include "gtkorientable.h"
|
|
|
|
|
#include "gtkscrolledwindow.h"
|
2014-02-13 05:14:42 +00:00
|
|
|
|
#include "gtklabel.h"
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
2011-01-06 07:07:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkappchooserwidget
|
|
|
|
|
* @Title: GtkAppChooserWidget
|
|
|
|
|
* @Short_description: Application chooser widget that can be embedded in other widgets
|
|
|
|
|
*
|
|
|
|
|
* #GtkAppChooserWidget is a widget for selecting applications.
|
|
|
|
|
* It is the main building block for #GtkAppChooserDialog. Most
|
|
|
|
|
* applications only need to use the latter; but you can use
|
|
|
|
|
* this widget as part of a larger widget if you have special needs.
|
2011-09-10 05:40:05 +00:00
|
|
|
|
*
|
|
|
|
|
* #GtkAppChooserWidget offers detailed control over what applications
|
|
|
|
|
* are shown, using the
|
|
|
|
|
* #GtkAppChooserWidget:show-default,
|
|
|
|
|
* #GtkAppChooserWidget:show-recommended,
|
|
|
|
|
* #GtkAppChooserWidget:show-fallback,
|
|
|
|
|
* #GtkAppChooserWidget:show-other and
|
|
|
|
|
* #GtkAppChooserWidget:show-all
|
|
|
|
|
* properties. See the #GtkAppChooser documentation for more information
|
|
|
|
|
* about these groups of applications.
|
|
|
|
|
*
|
|
|
|
|
* To keep track of the selected application, use the
|
|
|
|
|
* #GtkAppChooserWidget::application-selected and #GtkAppChooserWidget::application-activated signals.
|
2016-01-14 04:38:14 +00:00
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* GtkAppChooserWidget has a single CSS node with name appchooser.
|
2011-01-06 07:07:35 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
struct _GtkAppChooserWidgetPrivate {
|
2010-11-17 18:28:48 +00:00
|
|
|
|
GAppInfo *selected_app_info;
|
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
GtkWidget *overlay;
|
|
|
|
|
|
2010-11-23 11:46:34 +00:00
|
|
|
|
gchar *content_type;
|
|
|
|
|
gchar *default_text;
|
2011-04-12 16:24:34 +00:00
|
|
|
|
|
|
|
|
|
guint show_default : 1;
|
|
|
|
|
guint show_recommended : 1;
|
|
|
|
|
guint show_fallback : 1;
|
|
|
|
|
guint show_other : 1;
|
|
|
|
|
guint show_all : 1;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget *program_list;
|
|
|
|
|
GtkListStore *program_list_store;
|
2014-02-13 05:14:42 +00:00
|
|
|
|
GtkWidget *no_apps_label;
|
|
|
|
|
GtkWidget *no_apps;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2013-03-23 12:59:30 +00:00
|
|
|
|
GtkTreeViewColumn *column;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
GtkCellRenderer *padding_renderer;
|
2013-03-23 12:59:30 +00:00
|
|
|
|
GtkCellRenderer *secondary_padding;
|
2013-12-18 01:34:37 +00:00
|
|
|
|
|
|
|
|
|
GAppInfoMonitor *monitor;
|
2013-12-18 04:20:34 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget *popup_menu;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
COLUMN_APP_INFO,
|
|
|
|
|
COLUMN_GICON,
|
|
|
|
|
COLUMN_NAME,
|
2010-11-17 23:04:35 +00:00
|
|
|
|
COLUMN_DESC,
|
2010-11-17 18:28:48 +00:00
|
|
|
|
COLUMN_EXEC,
|
2010-11-23 15:48:48 +00:00
|
|
|
|
COLUMN_DEFAULT,
|
2010-11-17 18:28:48 +00:00
|
|
|
|
COLUMN_HEADING,
|
|
|
|
|
COLUMN_HEADING_TEXT,
|
|
|
|
|
COLUMN_RECOMMENDED,
|
2010-11-18 17:44:28 +00:00
|
|
|
|
COLUMN_FALLBACK,
|
2010-11-17 18:28:48 +00:00
|
|
|
|
NUM_COLUMNS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_CONTENT_TYPE = 1,
|
|
|
|
|
PROP_GFILE,
|
2010-11-23 15:48:48 +00:00
|
|
|
|
PROP_SHOW_DEFAULT,
|
2010-11-22 21:59:05 +00:00
|
|
|
|
PROP_SHOW_RECOMMENDED,
|
|
|
|
|
PROP_SHOW_FALLBACK,
|
|
|
|
|
PROP_SHOW_OTHER,
|
|
|
|
|
PROP_SHOW_ALL,
|
2010-11-23 11:46:34 +00:00
|
|
|
|
PROP_DEFAULT_TEXT,
|
2010-11-17 18:28:48 +00:00
|
|
|
|
N_PROPERTIES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
SIGNAL_APPLICATION_SELECTED,
|
|
|
|
|
SIGNAL_APPLICATION_ACTIVATED,
|
2010-11-24 16:04:38 +00:00
|
|
|
|
SIGNAL_POPULATE_POPUP,
|
2010-11-17 18:28:48 +00:00
|
|
|
|
N_SIGNALS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0, };
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
static void gtk_app_chooser_widget_iface_init (GtkAppChooserIface *iface);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserWidget, gtk_app_chooser_widget, GTK_TYPE_WIDGET,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkAppChooserWidget)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
|
|
|
|
gtk_app_chooser_widget_iface_init));
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
refresh_and_emit_app_selected (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GtkTreeSelection *selection)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GAppInfo *info = NULL;
|
|
|
|
|
gboolean should_emit = FALSE;
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gtk_tree_model_get (model, &iter, COLUMN_APP_INFO, &info, -1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-11-23 17:10:01 +00:00
|
|
|
|
if (self->priv->selected_app_info)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!g_app_info_equal (self->priv->selected_app_info, info))
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
should_emit = TRUE;
|
2016-11-14 19:19:58 +00:00
|
|
|
|
g_set_object (&self->priv->selected_app_info, info);
|
2010-11-24 23:32:05 +00:00
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
should_emit = TRUE;
|
2016-11-14 19:19:58 +00:00
|
|
|
|
g_set_object (&self->priv->selected_app_info, info);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 19:19:58 +00:00
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
if (should_emit)
|
|
|
|
|
g_signal_emit (self, signals[SIGNAL_APPLICATION_SELECTED], 0,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
self->priv->selected_app_info);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 16:04:38 +00:00
|
|
|
|
static GAppInfo *
|
|
|
|
|
get_app_info_for_event (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GdkEventButton *event)
|
2010-11-24 16:04:38 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GAppInfo *info;
|
|
|
|
|
gboolean recommended;
|
2017-08-25 14:42:39 +00:00
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
|
|
if (!gdk_event_get_coords ((GdkEvent *) event, &x, &y))
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
|
|
|
|
if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (self->priv->program_list),
|
2017-08-25 14:42:39 +00:00
|
|
|
|
x, y,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
&path,
|
|
|
|
|
NULL, NULL, NULL))
|
2010-11-24 16:04:38 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->priv->program_list));
|
|
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we only allow interaction with recommended applications */
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_APP_INFO, &info,
|
|
|
|
|
COLUMN_RECOMMENDED, &recommended,
|
|
|
|
|
-1);
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
|
|
|
|
if (!recommended)
|
|
|
|
|
g_clear_object (&info);
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 04:20:34 +00:00
|
|
|
|
static void
|
|
|
|
|
popup_menu_detach (GtkWidget *attach_widget,
|
|
|
|
|
GtkMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (attach_widget);
|
|
|
|
|
|
|
|
|
|
self->priv->popup_menu = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 16:04:38 +00:00
|
|
|
|
static gboolean
|
2010-11-24 23:32:05 +00:00
|
|
|
|
widget_button_press_event_cb (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event,
|
|
|
|
|
gpointer user_data)
|
2010-11-24 16:04:38 +00:00
|
|
|
|
{
|
|
|
|
|
GtkAppChooserWidget *self = user_data;
|
2017-08-25 14:42:39 +00:00
|
|
|
|
guint button;
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
2017-08-25 14:42:39 +00:00
|
|
|
|
if (gdk_event_get_button ((GdkEvent *) event, &button) &&
|
|
|
|
|
button == GDK_BUTTON_SECONDARY &&
|
|
|
|
|
gdk_event_get_event_type ((GdkEvent *) event) == GDK_BUTTON_PRESS)
|
2010-11-24 16:04:38 +00:00
|
|
|
|
{
|
|
|
|
|
GAppInfo *info;
|
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
GList *children;
|
|
|
|
|
gint n_children;
|
|
|
|
|
|
|
|
|
|
info = get_app_info_for_event (self, event);
|
|
|
|
|
|
|
|
|
|
if (info == NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
return FALSE;
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
2013-12-18 04:20:34 +00:00
|
|
|
|
if (self->priv->popup_menu)
|
|
|
|
|
gtk_widget_destroy (self->priv->popup_menu);
|
|
|
|
|
|
|
|
|
|
self->priv->popup_menu = menu = gtk_menu_new ();
|
2013-12-18 04:25:21 +00:00
|
|
|
|
gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), popup_menu_detach);
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
2013-12-18 04:20:34 +00:00
|
|
|
|
g_signal_emit (self, signals[SIGNAL_POPULATE_POPUP], 0, menu, info);
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
|
|
/* see if clients added menu items to this container */
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
n_children = g_list_length (children);
|
|
|
|
|
|
|
|
|
|
if (n_children > 0)
|
2013-12-18 04:20:34 +00:00
|
|
|
|
/* actually popup the menu */
|
2016-07-12 18:08:36 +00:00
|
|
|
|
gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) event);
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 20:38:22 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
path_is_heading (GtkTreeView *view,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GtkTreePath *path)
|
2010-11-17 20:38:22 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (view);
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_HEADING, &res,
|
|
|
|
|
-1);
|
2010-11-17 20:38:22 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
|
program_list_selection_activated (GtkTreeView *view,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
|
gpointer user_data)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = user_data;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2010-11-17 20:38:22 +00:00
|
|
|
|
if (path_is_heading (view, path))
|
|
|
|
|
return;
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->program_list));
|
|
|
|
|
|
|
|
|
|
refresh_and_emit_app_selected (self, selection);
|
|
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[SIGNAL_APPLICATION_ACTIVATED], 0,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
self->priv->selected_app_info);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_search_equal_func (GtkTreeModel *model,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gint column,
|
|
|
|
|
const gchar *key,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gchar *normalized_key;
|
|
|
|
|
gchar *name, *normalized_name;
|
|
|
|
|
gchar *path, *normalized_path;
|
|
|
|
|
gchar *basename, *normalized_basename;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
|
if (key != NULL)
|
|
|
|
|
{
|
|
|
|
|
normalized_key = g_utf8_casefold (key, -1);
|
|
|
|
|
g_assert (normalized_key != NULL);
|
|
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_NAME, &name,
|
|
|
|
|
COLUMN_EXEC, &path,
|
|
|
|
|
-1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
if (name != NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
normalized_name = g_utf8_casefold (name, -1);
|
|
|
|
|
g_assert (normalized_name != NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
if (strncmp (normalized_name, normalized_key, strlen (normalized_key)) == 0)
|
|
|
|
|
ret = FALSE;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_free (normalized_name);
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
if (ret && path != NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
normalized_path = g_utf8_casefold (path, -1);
|
|
|
|
|
g_assert (normalized_path != NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
basename = g_path_get_basename (path);
|
|
|
|
|
g_assert (basename != NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
normalized_basename = g_utf8_casefold (basename, -1);
|
|
|
|
|
g_assert (normalized_basename != NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
if (strncmp (normalized_path, normalized_key, strlen (normalized_key)) == 0 ||
|
|
|
|
|
strncmp (normalized_basename, normalized_key, strlen (normalized_key)) == 0)
|
|
|
|
|
ret = FALSE;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_free (basename);
|
|
|
|
|
g_free (normalized_basename);
|
|
|
|
|
g_free (normalized_path);
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (path);
|
|
|
|
|
g_free (normalized_key);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_sort_func (GtkTreeModel *model,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean a_recommended, b_recommended;
|
2010-11-18 17:44:28 +00:00
|
|
|
|
gboolean a_fallback, b_fallback;
|
2010-11-17 20:38:22 +00:00
|
|
|
|
gboolean a_heading, b_heading;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
gboolean a_default, b_default;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
gchar *a_name, *b_name, *a_casefold, *b_casefold;
|
2010-11-19 12:07:56 +00:00
|
|
|
|
gint retval = 0;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
/* this returns:
|
|
|
|
|
* - <0 if a should show before b
|
|
|
|
|
* - =0 if a is the same as b
|
|
|
|
|
* - >0 if a should show after b
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, a,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_NAME, &a_name,
|
|
|
|
|
COLUMN_RECOMMENDED, &a_recommended,
|
|
|
|
|
COLUMN_FALLBACK, &a_fallback,
|
|
|
|
|
COLUMN_HEADING, &a_heading,
|
|
|
|
|
COLUMN_DEFAULT, &a_default,
|
|
|
|
|
-1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, b,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_NAME, &b_name,
|
|
|
|
|
COLUMN_RECOMMENDED, &b_recommended,
|
|
|
|
|
COLUMN_FALLBACK, &b_fallback,
|
|
|
|
|
COLUMN_HEADING, &b_heading,
|
|
|
|
|
COLUMN_DEFAULT, &b_default,
|
|
|
|
|
-1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 15:48:48 +00:00
|
|
|
|
/* the default one always wins */
|
|
|
|
|
if (a_default && !b_default)
|
|
|
|
|
{
|
|
|
|
|
retval = -1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_default && !a_default)
|
|
|
|
|
{
|
|
|
|
|
retval = 1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
/* the recommended one always wins */
|
|
|
|
|
if (a_recommended && !b_recommended)
|
|
|
|
|
{
|
|
|
|
|
retval = -1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_recommended && !a_recommended)
|
|
|
|
|
{
|
|
|
|
|
retval = 1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 17:44:28 +00:00
|
|
|
|
/* the recommended one always wins */
|
|
|
|
|
if (a_fallback && !b_fallback)
|
|
|
|
|
{
|
|
|
|
|
retval = -1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_fallback && !a_fallback)
|
|
|
|
|
{
|
|
|
|
|
retval = 1;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
|
/* they're both recommended/fallback or not, so if one is a heading, wins */
|
2010-11-17 20:38:22 +00:00
|
|
|
|
if (a_heading)
|
|
|
|
|
{
|
2010-12-07 09:08:47 +00:00
|
|
|
|
retval = -1;
|
2010-11-17 20:38:22 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_heading)
|
|
|
|
|
{
|
2010-12-07 09:08:47 +00:00
|
|
|
|
retval = 1;
|
2010-11-17 20:38:22 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 12:07:56 +00:00
|
|
|
|
/* don't order by name recommended applications, but use GLib's ordering */
|
|
|
|
|
if (!a_recommended)
|
|
|
|
|
{
|
|
|
|
|
a_casefold = a_name != NULL ?
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_utf8_casefold (a_name, -1) : NULL;
|
2010-11-19 12:07:56 +00:00
|
|
|
|
b_casefold = b_name != NULL ?
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_utf8_casefold (b_name, -1) : NULL;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-19 12:07:56 +00:00
|
|
|
|
retval = g_strcmp0 (a_casefold, b_casefold);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-19 12:07:56 +00:00
|
|
|
|
g_free (a_casefold);
|
|
|
|
|
g_free (b_casefold);
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_free (a_name);
|
|
|
|
|
g_free (b_name);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
padding_cell_renderer_func (GtkTreeViewColumn *column,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean heading;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_HEADING, &heading,
|
|
|
|
|
-1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
if (heading)
|
|
|
|
|
g_object_set (cell,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
"visible", FALSE,
|
|
|
|
|
"xpad", 0,
|
|
|
|
|
"ypad", 0,
|
|
|
|
|
NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
else
|
|
|
|
|
g_object_set (cell,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
"visible", TRUE,
|
|
|
|
|
"xpad", 3,
|
|
|
|
|
"ypad", 3,
|
|
|
|
|
NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_selection_func (GtkTreeSelection *selection,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean path_currently_selected,
|
|
|
|
|
gpointer user_data)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean heading;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_HEADING, &heading,
|
|
|
|
|
-1);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
return !heading;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
compare_apps_func (gconstpointer a,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gconstpointer b)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
return !g_app_info_equal (G_APP_INFO (a), G_APP_INFO (b));
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
static gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
const gchar *heading_title,
|
|
|
|
|
gboolean show_headings,
|
|
|
|
|
gboolean recommended,
|
|
|
|
|
gboolean fallback,
|
|
|
|
|
GList *applications,
|
|
|
|
|
GList *exclude_apps)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-17 23:04:35 +00:00
|
|
|
|
gboolean heading_added, unref_icon;
|
2010-11-18 17:44:28 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GAppInfo *app;
|
|
|
|
|
gchar *app_string, *bold_string;
|
|
|
|
|
GIcon *icon;
|
|
|
|
|
GList *l;
|
2010-11-22 21:59:05 +00:00
|
|
|
|
gboolean retval;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
retval = FALSE;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
heading_added = FALSE;
|
2010-11-18 17:44:28 +00:00
|
|
|
|
bold_string = g_strdup_printf ("<b>%s</b>", heading_title);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-18 17:44:28 +00:00
|
|
|
|
for (l = applications; l != NULL; l = l->next)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-18 17:44:28 +00:00
|
|
|
|
app = l->data;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 17:10:01 +00:00
|
|
|
|
if (!g_app_info_supports_uris (app) &&
|
2010-11-24 23:32:05 +00:00
|
|
|
|
!g_app_info_supports_files (app))
|
2012-10-15 22:45:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
if (g_list_find_custom (exclude_apps, app,
|
|
|
|
|
(GCompareFunc) compare_apps_func))
|
|
|
|
|
continue;
|
2010-11-18 17:44:28 +00:00
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
if (!heading_added && show_headings)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_list_store_append (self->priv->program_list_store, &iter);
|
|
|
|
|
gtk_list_store_set (self->priv->program_list_store, &iter,
|
|
|
|
|
COLUMN_HEADING_TEXT, bold_string,
|
|
|
|
|
COLUMN_HEADING, TRUE,
|
|
|
|
|
COLUMN_RECOMMENDED, recommended,
|
|
|
|
|
COLUMN_FALLBACK, fallback,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
heading_added = TRUE;
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2011-01-20 21:40:29 +00:00
|
|
|
|
app_string = g_markup_printf_escaped ("%s",
|
|
|
|
|
g_app_info_get_name (app) != NULL ?
|
|
|
|
|
g_app_info_get_name (app) : "");
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
|
|
|
|
icon = g_app_info_get_icon (app);
|
2010-11-24 21:09:55 +00:00
|
|
|
|
unref_icon = FALSE;
|
2010-11-17 23:04:35 +00:00
|
|
|
|
if (icon == NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
icon = g_themed_icon_new ("application-x-executable");
|
|
|
|
|
unref_icon = TRUE;
|
|
|
|
|
}
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
gtk_list_store_append (self->priv->program_list_store, &iter);
|
|
|
|
|
gtk_list_store_set (self->priv->program_list_store, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_APP_INFO, app,
|
|
|
|
|
COLUMN_GICON, icon,
|
2011-01-20 21:40:29 +00:00
|
|
|
|
COLUMN_NAME, g_app_info_get_name (app),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_DESC, app_string,
|
|
|
|
|
COLUMN_EXEC, g_app_info_get_executable (app),
|
|
|
|
|
COLUMN_HEADING, FALSE,
|
|
|
|
|
COLUMN_RECOMMENDED, recommended,
|
|
|
|
|
COLUMN_FALLBACK, fallback,
|
|
|
|
|
-1);
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
2010-11-17 23:04:35 +00:00
|
|
|
|
g_free (app_string);
|
|
|
|
|
if (unref_icon)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_object_unref (icon);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 17:44:28 +00:00
|
|
|
|
g_free (bold_string);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
return retval;
|
2010-11-18 17:44:28 +00:00
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GAppInfo *app)
|
2010-11-23 15:48:48 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GIcon *icon;
|
|
|
|
|
gchar *string;
|
|
|
|
|
gboolean unref_icon;
|
|
|
|
|
|
|
|
|
|
unref_icon = FALSE;
|
|
|
|
|
string = g_strdup_printf ("<b>%s</b>", _("Default Application"));
|
|
|
|
|
|
|
|
|
|
gtk_list_store_append (self->priv->program_list_store, &iter);
|
|
|
|
|
gtk_list_store_set (self->priv->program_list_store, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_HEADING_TEXT, string,
|
|
|
|
|
COLUMN_HEADING, TRUE,
|
|
|
|
|
COLUMN_DEFAULT, TRUE,
|
|
|
|
|
-1);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
|
|
2011-01-20 21:40:29 +00:00
|
|
|
|
string = g_markup_printf_escaped ("%s",
|
|
|
|
|
g_app_info_get_name (app) != NULL ?
|
|
|
|
|
g_app_info_get_name (app) : "");
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
icon = g_app_info_get_icon (app);
|
|
|
|
|
if (icon == NULL)
|
|
|
|
|
{
|
|
|
|
|
icon = g_themed_icon_new ("application-x-executable");
|
|
|
|
|
unref_icon = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_list_store_append (self->priv->program_list_store, &iter);
|
|
|
|
|
gtk_list_store_set (self->priv->program_list_store, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_APP_INFO, app,
|
|
|
|
|
COLUMN_GICON, icon,
|
2011-01-20 21:40:29 +00:00
|
|
|
|
COLUMN_NAME, g_app_info_get_name (app),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_DESC, string,
|
|
|
|
|
COLUMN_EXEC, g_app_info_get_executable (app),
|
|
|
|
|
COLUMN_HEADING, FALSE,
|
|
|
|
|
COLUMN_DEFAULT, TRUE,
|
|
|
|
|
-1);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
|
|
|
|
|
|
if (unref_icon)
|
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 17:44:28 +00:00
|
|
|
|
static void
|
2014-02-14 12:02:32 +00:00
|
|
|
|
update_no_applications_label (GtkAppChooserWidget *self)
|
2010-11-18 17:44:28 +00:00
|
|
|
|
{
|
2011-03-01 10:41:15 +00:00
|
|
|
|
gchar *text = NULL, *desc = NULL;
|
2010-11-23 11:46:34 +00:00
|
|
|
|
const gchar *string;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 11:46:34 +00:00
|
|
|
|
if (self->priv->default_text == NULL)
|
|
|
|
|
{
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if (self->priv->content_type)
|
|
|
|
|
desc = g_content_type_get_description (self->priv->content_type);
|
|
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
|
string = text = g_strdup_printf (_("No applications found for “%s”."), desc);
|
2010-11-23 11:46:34 +00:00
|
|
|
|
g_free (desc);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string = self->priv->default_text;
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (self->priv->no_apps_label), string);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_free (text);
|
2010-11-18 17:44:28 +00:00
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 15:48:48 +00:00
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_select_first (GtkAppChooserWidget *self)
|
2010-11-23 15:48:48 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GAppInfo *info = NULL;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->priv->program_list));
|
2014-02-13 05:14:42 +00:00
|
|
|
|
if (!gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
|
return;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
while (info == NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
COLUMN_APP_INFO, &info,
|
|
|
|
|
-1);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
if (info != NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
break;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
if (!gtk_tree_model_iter_next (model, &iter))
|
2010-11-24 23:32:05 +00:00
|
|
|
|
break;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info != NULL)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->program_list));
|
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 17:44:28 +00:00
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
2010-11-18 17:44:28 +00:00
|
|
|
|
{
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GList *all_applications = NULL;
|
|
|
|
|
GList *recommended_apps = NULL;
|
|
|
|
|
GList *fallback_apps = NULL;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
GList *exclude_apps = NULL;
|
|
|
|
|
GAppInfo *default_app = NULL;
|
2010-11-22 21:59:05 +00:00
|
|
|
|
gboolean show_headings;
|
|
|
|
|
gboolean apps_added;
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
show_headings = TRUE;
|
|
|
|
|
apps_added = FALSE;
|
|
|
|
|
|
|
|
|
|
if (self->priv->show_all)
|
|
|
|
|
show_headings = FALSE;
|
|
|
|
|
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if (self->priv->show_default && self->priv->content_type)
|
2010-11-23 15:48:48 +00:00
|
|
|
|
{
|
|
|
|
|
default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE);
|
|
|
|
|
|
|
|
|
|
if (default_app != NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_app_chooser_add_default (self, default_app);
|
|
|
|
|
apps_added = TRUE;
|
|
|
|
|
exclude_apps = g_list_prepend (exclude_apps, default_app);
|
|
|
|
|
}
|
2010-11-23 15:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 15:13:34 +00:00
|
|
|
|
#ifndef G_OS_WIN32
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if ((self->priv->content_type && self->priv->show_recommended) || self->priv->show_all)
|
2010-11-18 17:44:28 +00:00
|
|
|
|
{
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if (self->priv->content_type)
|
|
|
|
|
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
show_headings,
|
|
|
|
|
!self->priv->show_all, /* mark as recommended */
|
|
|
|
|
FALSE, /* mark as fallback */
|
|
|
|
|
recommended_apps, exclude_apps);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
exclude_apps = g_list_concat (exclude_apps,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_list_copy (recommended_apps));
|
2010-11-18 17:44:28 +00:00
|
|
|
|
}
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if ((self->priv->content_type && self->priv->show_fallback) || self->priv->show_all)
|
2010-11-18 17:44:28 +00:00
|
|
|
|
{
|
2011-03-01 10:41:15 +00:00
|
|
|
|
if (self->priv->content_type)
|
|
|
|
|
fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
show_headings,
|
|
|
|
|
FALSE, /* mark as recommended */
|
|
|
|
|
!self->priv->show_all, /* mark as fallback */
|
|
|
|
|
fallback_apps, exclude_apps);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
exclude_apps = g_list_concat (exclude_apps,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
g_list_copy (fallback_apps));
|
2010-11-18 17:44:28 +00:00
|
|
|
|
}
|
2011-01-11 15:13:34 +00:00
|
|
|
|
#endif
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
if (self->priv->show_other || self->priv->show_all)
|
2010-11-18 17:44:28 +00:00
|
|
|
|
{
|
2010-11-22 21:59:05 +00:00
|
|
|
|
all_applications = g_app_info_get_all ();
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
apps_added |= gtk_app_chooser_widget_add_section (self, _("Other Applications"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
show_headings,
|
|
|
|
|
FALSE,
|
|
|
|
|
FALSE,
|
|
|
|
|
all_applications, exclude_apps);
|
2010-11-18 17:44:28 +00:00
|
|
|
|
}
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
if (!apps_added)
|
2014-02-14 12:02:32 +00:00
|
|
|
|
update_no_applications_label (self);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_visible (self->priv->no_apps, !apps_added);
|
2010-11-17 23:04:35 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_select_first (self);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
if (default_app != NULL)
|
|
|
|
|
g_object_unref (default_app);
|
|
|
|
|
|
2014-12-08 20:38:41 +00:00
|
|
|
|
g_list_free_full (all_applications, g_object_unref);
|
|
|
|
|
g_list_free_full (recommended_apps, g_object_unref);
|
|
|
|
|
g_list_free_full (fallback_apps, g_object_unref);
|
|
|
|
|
g_list_free (exclude_apps);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-03-23 12:59:30 +00:00
|
|
|
|
gtk_app_chooser_widget_initialize_items (GtkAppChooserWidget *self)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
/* initial padding */
|
2013-03-23 12:59:30 +00:00
|
|
|
|
g_object_set (self->priv->padding_renderer,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
"xpad", self->priv->show_all ? 0 : 6,
|
|
|
|
|
NULL);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
/* populate the widget */
|
2015-09-22 19:14:00 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 01:34:37 +00:00
|
|
|
|
static void
|
|
|
|
|
app_info_changed (GAppInfoMonitor *monitor,
|
|
|
|
|
GtkAppChooserWidget *self)
|
|
|
|
|
{
|
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gtk_app_chooser_widget_set_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CONTENT_TYPE:
|
|
|
|
|
self->priv->content_type = g_value_dup_string (value);
|
|
|
|
|
break;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
case PROP_SHOW_DEFAULT:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_default (self, g_value_get_boolean (value));
|
2010-11-23 15:48:48 +00:00
|
|
|
|
break;
|
2010-11-22 21:59:05 +00:00
|
|
|
|
case PROP_SHOW_RECOMMENDED:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_recommended (self, g_value_get_boolean (value));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_FALLBACK:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_fallback (self, g_value_get_boolean (value));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_OTHER:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_other (self, g_value_get_boolean (value));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_ALL:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_all (self, g_value_get_boolean (value));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
break;
|
2010-11-23 11:46:34 +00:00
|
|
|
|
case PROP_DEFAULT_TEXT:
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_default_text (self, g_value_get_string (value));
|
2010-11-23 11:46:34 +00:00
|
|
|
|
break;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gtk_app_chooser_widget_get_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CONTENT_TYPE:
|
|
|
|
|
g_value_set_string (value, self->priv->content_type);
|
|
|
|
|
break;
|
2010-11-23 15:48:48 +00:00
|
|
|
|
case PROP_SHOW_DEFAULT:
|
|
|
|
|
g_value_set_boolean (value, self->priv->show_default);
|
|
|
|
|
break;
|
2010-11-22 21:59:05 +00:00
|
|
|
|
case PROP_SHOW_RECOMMENDED:
|
|
|
|
|
g_value_set_boolean (value, self->priv->show_recommended);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_FALLBACK:
|
|
|
|
|
g_value_set_boolean (value, self->priv->show_fallback);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_OTHER:
|
|
|
|
|
g_value_set_boolean (value, self->priv->show_other);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_ALL:
|
|
|
|
|
g_value_set_boolean (value, self->priv->show_all);
|
|
|
|
|
break;
|
2010-11-23 11:46:34 +00:00
|
|
|
|
case PROP_DEFAULT_TEXT:
|
|
|
|
|
g_value_set_string (value, self->priv->default_text);
|
|
|
|
|
break;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_constructed (GObject *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
if (G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed != NULL)
|
|
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2013-03-23 12:59:30 +00:00
|
|
|
|
gtk_app_chooser_widget_initialize_items (self);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_finalize (GObject *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
g_free (self->priv->content_type);
|
2010-11-23 11:46:34 +00:00
|
|
|
|
g_free (self->priv->default_text);
|
2013-12-18 01:34:37 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (self->priv->monitor, app_info_changed, self);
|
|
|
|
|
g_object_unref (self->priv->monitor);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->finalize (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_dispose (GObject *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2017-03-25 20:10:27 +00:00
|
|
|
|
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_clear_object (&priv->selected_app_info);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
if (priv->overlay)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_unparent (priv->overlay);
|
|
|
|
|
priv->overlay = NULL;
|
|
|
|
|
}
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->dispose (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_app_chooser_widget_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline)
|
|
|
|
|
{
|
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
|
|
|
|
|
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
gtk_widget_measure (priv->overlay, orientation, for_size,
|
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_app_chooser_widget_snapshot (GtkWidget *widget,
|
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
|
{
|
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
|
|
|
|
|
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
gtk_widget_snapshot_child (widget, priv->overlay, snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-07-11 07:58:21 +00:00
|
|
|
|
gtk_app_chooser_widget_size_allocate (GtkWidget *widget,
|
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
|
int baseline,
|
|
|
|
|
GtkAllocation *out_clip)
|
2017-03-25 20:10:27 +00:00
|
|
|
|
{
|
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
|
|
|
|
|
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
|
|
|
|
|
2017-07-11 07:58:21 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_app_chooser_widget_parent_class)->size_allocate (widget, allocation, baseline, out_clip);
|
2017-04-30 19:53:05 +00:00
|
|
|
|
|
2017-07-11 07:58:21 +00:00
|
|
|
|
gtk_widget_size_allocate (priv->overlay, allocation, baseline, out_clip);
|
2017-03-25 20:10:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2013-03-23 12:59:30 +00:00
|
|
|
|
GtkWidgetClass *widget_class;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gobject_class->dispose = gtk_app_chooser_widget_dispose;
|
|
|
|
|
gobject_class->finalize = gtk_app_chooser_widget_finalize;
|
|
|
|
|
gobject_class->set_property = gtk_app_chooser_widget_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_app_chooser_widget_get_property;
|
|
|
|
|
gobject_class->constructed = gtk_app_chooser_widget_constructed;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
widget_class->measure = gtk_app_chooser_widget_measure;
|
|
|
|
|
widget_class->size_allocate = gtk_app_chooser_widget_size_allocate;
|
|
|
|
|
widget_class->snapshot = gtk_app_chooser_widget_snapshot;
|
|
|
|
|
|
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:show-default:
|
|
|
|
|
*
|
|
|
|
|
* The ::show-default property determines whether the app chooser
|
|
|
|
|
* should show the default handler for the content type in a
|
|
|
|
|
* separate section. If %FALSE, the default handler is listed
|
|
|
|
|
* among the recommended applications.
|
|
|
|
|
*/
|
2010-11-23 15:48:48 +00:00
|
|
|
|
pspec = g_param_spec_boolean ("show-default",
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("Show default app"),
|
|
|
|
|
P_("Whether the widget should show the default application"),
|
|
|
|
|
FALSE,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHOW_DEFAULT, pspec);
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:show-recommended:
|
|
|
|
|
*
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* The #GtkAppChooserWidget:show-recommended property determines
|
|
|
|
|
* whether the app chooser should show a section for recommended
|
|
|
|
|
* applications. If %FALSE, the recommended applications are listed
|
|
|
|
|
* among the other applications.
|
2010-11-24 23:32:05 +00:00
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
pspec = g_param_spec_boolean ("show-recommended",
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("Show recommended apps"),
|
|
|
|
|
P_("Whether the widget should show recommended applications"),
|
|
|
|
|
TRUE,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHOW_RECOMMENDED, pspec);
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:show-fallback:
|
|
|
|
|
*
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* The #GtkAppChooserWidget:show-fallback property determines whether
|
|
|
|
|
* the app chooser should show a section for fallback applications.
|
|
|
|
|
* If %FALSE, the fallback applications are listed among the other
|
|
|
|
|
* applications.
|
2010-11-24 23:32:05 +00:00
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
pspec = g_param_spec_boolean ("show-fallback",
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("Show fallback apps"),
|
|
|
|
|
P_("Whether the widget should show fallback applications"),
|
|
|
|
|
FALSE,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHOW_FALLBACK, pspec);
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:show-other:
|
|
|
|
|
*
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* The #GtkAppChooserWidget:show-other property determines whether
|
|
|
|
|
* the app chooser should show a section for other applications.
|
2010-11-24 23:32:05 +00:00
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
pspec = g_param_spec_boolean ("show-other",
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("Show other apps"),
|
|
|
|
|
P_("Whether the widget should show other applications"),
|
|
|
|
|
FALSE,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHOW_OTHER, pspec);
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:show-all:
|
|
|
|
|
*
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* If the #GtkAppChooserWidget:show-all property is %TRUE, the app
|
|
|
|
|
* chooser presents all applications in a single list, without
|
|
|
|
|
* subsections for default, recommended or related applications.
|
2010-11-24 23:32:05 +00:00
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
pspec = g_param_spec_boolean ("show-all",
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("Show all apps"),
|
|
|
|
|
P_("Whether the widget should show all applications"),
|
|
|
|
|
FALSE,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHOW_ALL, pspec);
|
|
|
|
|
|
2010-11-30 16:27:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget:default-text:
|
|
|
|
|
*
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* The #GtkAppChooserWidget:default-text property determines the text
|
|
|
|
|
* that appears in the widget when there are no applications for the
|
|
|
|
|
* given content type.
|
2010-11-30 16:27:53 +00:00
|
|
|
|
* See also gtk_app_chooser_widget_set_default_text().
|
|
|
|
|
*/
|
2010-11-23 11:46:34 +00:00
|
|
|
|
pspec = g_param_spec_string ("default-text",
|
2016-10-03 16:20:03 +00:00
|
|
|
|
P_("Widget’s default text"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
P_("The default text appearing when there are no applications"),
|
|
|
|
|
NULL,
|
2014-06-07 18:04:16 +00:00
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-23 11:46:34 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEFAULT_TEXT, pspec);
|
|
|
|
|
|
2010-11-30 14:03:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget::application-selected:
|
|
|
|
|
* @self: the object which received the signal
|
|
|
|
|
* @application: the selected #GAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Emitted when an application item is selected from the widget's list.
|
|
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
|
signals[SIGNAL_APPLICATION_SELECTED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
|
g_signal_new (I_("application-selected"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GTK_TYPE_APP_CHOOSER_WIDGET,
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserWidgetClass, application_selected),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1, G_TYPE_APP_INFO);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-30 14:03:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget::application-activated:
|
|
|
|
|
* @self: the object which received the signal
|
|
|
|
|
* @application: the activated #GAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Emitted when an application item is activated from the widget's list.
|
2011-09-10 05:40:05 +00:00
|
|
|
|
*
|
2010-11-30 14:03:33 +00:00
|
|
|
|
* This usually happens when the user double clicks an item, or an item
|
|
|
|
|
* is selected and the user presses one of the keys Space, Shift+Space,
|
|
|
|
|
* Return or Enter.
|
|
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
|
signals[SIGNAL_APPLICATION_ACTIVATED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
|
g_signal_new (I_("application-activated"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GTK_TYPE_APP_CHOOSER_WIDGET,
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserWidgetClass, application_activated),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1, G_TYPE_APP_INFO);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-30 14:03:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkAppChooserWidget::populate-popup:
|
|
|
|
|
* @self: the object which received the signal
|
|
|
|
|
* @menu: the #GtkMenu to populate
|
|
|
|
|
* @application: the current #GAppInfo
|
|
|
|
|
*
|
|
|
|
|
* Emitted when a context menu is about to popup over an application item.
|
|
|
|
|
* Clients can insert menu items into the provided #GtkMenu object in the
|
2011-09-10 05:40:05 +00:00
|
|
|
|
* callback of this signal; the context menu will be shown over the item
|
|
|
|
|
* if at least one item has been added to the menu.
|
2010-11-30 14:03:33 +00:00
|
|
|
|
*/
|
2010-11-24 16:04:38 +00:00
|
|
|
|
signals[SIGNAL_POPULATE_POPUP] =
|
2015-09-12 13:13:00 +00:00
|
|
|
|
g_signal_new (I_("populate-popup"),
|
2010-11-24 23:32:05 +00:00
|
|
|
|
GTK_TYPE_APP_CHOOSER_WIDGET,
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserWidgetClass, populate_popup),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__OBJECT_OBJECT,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
2, GTK_TYPE_MENU, G_TYPE_APP_INFO);
|
2010-11-24 16:04:38 +00:00
|
|
|
|
|
2013-03-23 12:59:30 +00:00
|
|
|
|
/* Bind class to template
|
|
|
|
|
*/
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2014-01-23 23:59:20 +00:00
|
|
|
|
"/org/gtk/libgtk/ui/gtkappchooserwidget.ui");
|
2013-07-26 20:29:12 +00:00
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, program_list);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, program_list_store);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, column);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, padding_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, secondary_padding);
|
2014-02-13 05:14:42 +00:00
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, no_apps_label);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, no_apps);
|
2017-03-25 20:10:27 +00:00
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, overlay);
|
2013-07-26 17:49:49 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, refresh_and_emit_app_selected);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, program_list_selection_activated);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, widget_button_press_event_cb);
|
2016-01-14 04:38:14 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "appchooser");
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
2013-03-23 12:59:30 +00:00
|
|
|
|
GtkTreeModel *sort;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
self->priv = gtk_app_chooser_widget_get_instance_private (self);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2017-03-25 20:10:27 +00:00
|
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
|
|
|
|
|
|
2013-03-23 12:59:30 +00:00
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
|
|
|
|
|
|
/* Various parts of the GtkTreeView code need custom code to setup, mostly
|
|
|
|
|
* because we lack signals to connect to, or properties to set.
|
|
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->program_list));
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_tree_selection_set_select_function (selection, gtk_app_chooser_selection_func,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
self, NULL);
|
2013-03-23 12:59:30 +00:00
|
|
|
|
|
|
|
|
|
sort = gtk_tree_view_get_model (GTK_TREE_VIEW (self->priv->program_list));
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort),
|
|
|
|
|
COLUMN_NAME,
|
|
|
|
|
GTK_SORT_ASCENDING);
|
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sort),
|
|
|
|
|
COLUMN_NAME,
|
|
|
|
|
gtk_app_chooser_sort_func,
|
|
|
|
|
self, NULL);
|
|
|
|
|
|
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (self->priv->program_list), COLUMN_NAME);
|
|
|
|
|
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (self->priv->program_list),
|
|
|
|
|
gtk_app_chooser_search_equal_func,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_cell_data_func (self->priv->column,
|
|
|
|
|
self->priv->secondary_padding,
|
|
|
|
|
padding_cell_renderer_func,
|
|
|
|
|
NULL, NULL);
|
2013-12-18 01:34:37 +00:00
|
|
|
|
|
|
|
|
|
self->priv->monitor = g_app_info_monitor_get ();
|
|
|
|
|
g_signal_connect (self->priv->monitor, "changed",
|
|
|
|
|
G_CALLBACK (app_info_changed), self);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GAppInfo *
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_app_info (GtkAppChooser *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
|
|
if (self->priv->selected_app_info == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return g_object_ref (self->priv->selected_app_info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_refresh (GtkAppChooser *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
2010-11-17 23:06:49 +00:00
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
|
if (self->priv->program_list_store != NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_store_clear (self->priv->program_list_store);
|
|
|
|
|
|
|
|
|
|
/* don't add additional xpad if we don't have headings */
|
|
|
|
|
g_object_set (self->priv->padding_renderer,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
"visible", !self->priv->show_all,
|
|
|
|
|
NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_real_add_items (self);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 22:02:57 +00:00
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_iface_init (GtkAppChooserIface *iface)
|
2010-11-22 22:02:57 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
iface->get_app_info = gtk_app_chooser_widget_get_app_info;
|
|
|
|
|
iface->refresh = gtk_app_chooser_widget_refresh;
|
2010-11-22 22:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_new:
|
|
|
|
|
* @content_type: the content type to show applications for
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkAppChooserWidget for applications
|
|
|
|
|
* that can handle content of the given type.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a newly created #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
|
GtkWidget *
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_new (const gchar *content_type)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_APP_CHOOSER_WIDGET,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
"content-type", content_type,
|
|
|
|
|
NULL);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_show_default:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @setting: the new value for #GtkAppChooserWidget:show-default
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the app chooser should show the default handler
|
|
|
|
|
* for the content type in a separate section.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-23 15:48:48 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_default (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gboolean setting)
|
2010-11-23 15:48:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
if (self->priv->show_default != setting)
|
|
|
|
|
{
|
|
|
|
|
self->priv->show_default = setting;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-default");
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-23 15:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_show_default:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the current value of the #GtkAppChooserWidget:show-default
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:show-default
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-23 15:48:48 +00:00
|
|
|
|
gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_show_default (GtkAppChooserWidget *self)
|
2010-11-23 15:48:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
2010-11-23 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
return self->priv->show_default;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_show_recommended:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @setting: the new value for #GtkAppChooserWidget:show-recommended
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the app chooser should show recommended applications
|
|
|
|
|
* for the content type in a separate section.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_recommended (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gboolean setting)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-22 21:59:05 +00:00
|
|
|
|
if (self->priv->show_recommended != setting)
|
2010-11-17 18:28:48 +00:00
|
|
|
|
{
|
2010-11-22 21:59:05 +00:00
|
|
|
|
self->priv->show_recommended = setting;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-recommended");
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-17 18:28:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_show_recommended:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the current value of the #GtkAppChooserWidget:show-recommended
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:show-recommended
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_show_recommended (GtkAppChooserWidget *self)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
return self->priv->show_recommended;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_show_fallback:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @setting: the new value for #GtkAppChooserWidget:show-fallback
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the app chooser should show related applications
|
|
|
|
|
* for the content type in a separate section.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_fallback (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gboolean setting)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
if (self->priv->show_fallback != setting)
|
|
|
|
|
{
|
|
|
|
|
self->priv->show_fallback = setting;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-fallback");
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_show_fallback:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the current value of the #GtkAppChooserWidget:show-fallback
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:show-fallback
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_show_fallback (GtkAppChooserWidget *self)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
return self->priv->show_fallback;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_show_other:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @setting: the new value for #GtkAppChooserWidget:show-other
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the app chooser should show applications
|
|
|
|
|
* which are unrelated to the content type.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_other (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gboolean setting)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
if (self->priv->show_other != setting)
|
|
|
|
|
{
|
|
|
|
|
self->priv->show_other = setting;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-other");
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_show_other:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the current value of the #GtkAppChooserWidget:show-other
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:show-other
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_app_chooser_widget_get_show_other (GtkAppChooserWidget *self)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
return self->priv->show_other;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_show_all:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @setting: the new value for #GtkAppChooserWidget:show-all
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the app chooser should show all applications
|
|
|
|
|
* in a flat list.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_show_all (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
gboolean setting)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
|
|
|
|
if (self->priv->show_all != setting)
|
|
|
|
|
{
|
|
|
|
|
self->priv->show_all = setting;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-all");
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-22 21:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_show_all:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the current value of the #GtkAppChooserWidget:show-all
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:show-all
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-22 21:59:05 +00:00
|
|
|
|
gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_show_all (GtkAppChooserWidget *self)
|
2010-11-22 21:59:05 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
2010-11-22 21:59:05 +00:00
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
return self->priv->show_all;
|
2010-11-22 21:59:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_set_default_text:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
* @text: the new value for #GtkAppChooserWidget:default-text
|
|
|
|
|
*
|
|
|
|
|
* Sets the text that is shown if there are not applications
|
|
|
|
|
* that can handle the content type.
|
|
|
|
|
*/
|
2010-11-23 11:46:34 +00:00
|
|
|
|
void
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_set_default_text (GtkAppChooserWidget *self,
|
2010-11-24 23:32:05 +00:00
|
|
|
|
const gchar *text)
|
2010-11-23 11:46:34 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
2010-11-23 11:46:34 +00:00
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (text, self->priv->default_text) != 0)
|
|
|
|
|
{
|
|
|
|
|
g_free (self->priv->default_text);
|
|
|
|
|
self->priv->default_text = g_strdup (text);
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "default-text");
|
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-23 11:46:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_app_chooser_widget_get_default_text:
|
|
|
|
|
* @self: a #GtkAppChooserWidget
|
|
|
|
|
*
|
|
|
|
|
* Returns the text that is shown if there are not applications
|
|
|
|
|
* that can handle the content type.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the value of #GtkAppChooserWidget:default-text
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.0
|
|
|
|
|
*/
|
2010-11-23 11:46:34 +00:00
|
|
|
|
const gchar *
|
2010-11-23 16:23:37 +00:00
|
|
|
|
gtk_app_chooser_widget_get_default_text (GtkAppChooserWidget *self)
|
2010-11-23 11:46:34 +00:00
|
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), NULL);
|
2010-11-23 11:46:34 +00:00
|
|
|
|
|
|
|
|
|
return self->priv->default_text;
|
|
|
|
|
}
|
2014-02-14 12:02:32 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self,
|
|
|
|
|
GtkEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (self->priv->program_list), entry);
|
|
|
|
|
|
|
|
|
|
g_object_bind_property (self->priv->no_apps, "visible",
|
|
|
|
|
entry, "sensitive",
|
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
|
|
|
|
|
}
|