forked from AuroraMiddleware/gtk
Merge branch 'open-with-dialog'
This commit is contained in:
commit
117e88646f
19
configure.ac
19
configure.ac
@ -1488,6 +1488,25 @@ GLIB_GSETTINGS
|
||||
|
||||
GOBJECT_INTROSPECTION_CHECK([0.9.3])
|
||||
|
||||
##################################################
|
||||
# Packagekit module
|
||||
#################################################
|
||||
|
||||
AC_ARG_ENABLE(packagekit,
|
||||
AC_HELP_STRING([--disable-packagekit],
|
||||
[build packagekit open with module]))
|
||||
|
||||
ENABLE_PACKAGEKIT=
|
||||
if test "os_win32" != "yes"; then
|
||||
if test "x$enable_packagekit" != "xno"; then
|
||||
ENABLE_PACKAGEKIT=1
|
||||
AC_DEFINE(ENABLE_PACKAGEKIT, 1, [define to enable packagekit])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(ENABLE_PACKAGEKIT)
|
||||
AM_CONDITIONAL(ENABLE_PACKAGEKIT, test "x$ENABLE_PACKAGEKIT" = "x1")
|
||||
|
||||
##################################################
|
||||
# Checks for gtk-doc and docbook-tools
|
||||
##################################################
|
||||
|
@ -297,6 +297,14 @@
|
||||
<xi:include href="xml/gtkrecentfilter.xml" />
|
||||
</chapter>
|
||||
|
||||
<chapter id="ApplicationChoosing">
|
||||
<title>Choosing from installed applications</title>
|
||||
<xi:include href="xml/gtkappchooser.xml" />
|
||||
<xi:include href="xml/gtkappchooserbutton.xml" />
|
||||
<xi:include href="xml/gtkappchooserdialog.xml" />
|
||||
<xi:include href="xml/gtkappchooserwidget.xml" />
|
||||
</chapter>
|
||||
|
||||
<chapter id="Builder">
|
||||
<title>Interface builder</title>
|
||||
<xi:include href="xml/gtkbuildable.xml" />
|
||||
|
@ -6410,3 +6410,98 @@ GTK_SWITCH_GET_CLASS
|
||||
GtkSwitchPrivate
|
||||
gtk_switch_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkappchooser</FILE>
|
||||
<TITLE>GtkAppChooser</TITLE>
|
||||
GtkAppChooser
|
||||
gtk_app_chooser_get_app_info
|
||||
gtk_app_chooser_get_content_type
|
||||
gtk_app_chooser_refresh
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_APP_CHOOSER
|
||||
GTK_APP_CHOOSER
|
||||
GTK_IS_APP_CHOOSER
|
||||
|
||||
<SUBSECTION Private>
|
||||
gtk_app_chooser_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkappchooserbutton</FILE>
|
||||
<TITLE>GtkAppChooserButton</TITLE>
|
||||
GtkAppChooserButton
|
||||
gtk_app_chooser_button_new
|
||||
gtk_app_chooser_button_append_custom_item
|
||||
gtk_app_chooser_button_append_separator
|
||||
gtk_app_chooser_button_get_show_dialog_item
|
||||
gtk_app_chooser_button_set_show_dialog_item
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GtkAppChooserButtonClass
|
||||
GTK_TYPE_APP_CHOOSER_BUTTON
|
||||
GTK_APP_CHOOSER_BUTTON
|
||||
GTK_APP_CHOOSER_BUTTON_CLASS
|
||||
GTK_IS_APP_CHOOSER_BUTTON
|
||||
GTK_IS_APP_CHOOSER_BUTTON_CLASS
|
||||
GTK_APP_CHOOSER_BUTTON_GET_CLASS
|
||||
|
||||
<SUBSECTION Private>
|
||||
GtkAppChooserButtonPrivate
|
||||
gtk_app_chooser_button_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkappchooserdialog</FILE>
|
||||
<TITLE>GtkAppChooserDialog</TITLE>
|
||||
GtkAppChooserDialog
|
||||
gtk_app_chooser_dialog_new
|
||||
gtk_app_chooser_dialog_new_for_content_type
|
||||
gtk_app_chooser_dialog_get_widget
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GtkAppChooserDialogClass
|
||||
GTK_TYPE_APP_CHOOSER_DIALOG
|
||||
GTK_APP_CHOOSER_DIALOG
|
||||
GTK_APP_CHOOSER_DIALOG_CLASS
|
||||
GTK_IS_APP_CHOOSER_DIALOG
|
||||
GTK_IS_APP_CHOOSER_DIALOG_CLASS
|
||||
GTK_APP_CHOOSER_DIALOG_GET_CLASS
|
||||
|
||||
<SUBSECTION Private>
|
||||
GtkAppChooserDialogPrivate
|
||||
gtk_app_chooser_dialog_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkappchooserwidget</FILE>
|
||||
<TITLE>GtkAppChooserWidget</TITLE>
|
||||
GtkAppChooserWidget
|
||||
gtk_app_chooser_widget_new
|
||||
gtk_app_chooser_widget_set_show_default
|
||||
gtk_app_chooser_widget_get_show_default
|
||||
gtk_app_chooser_widget_set_show_recommended
|
||||
gtk_app_chooser_widget_get_show_recommended
|
||||
gtk_app_chooser_widget_set_show_fallback
|
||||
gtk_app_chooser_widget_get_show_fallback
|
||||
gtk_app_chooser_widget_set_show_other
|
||||
gtk_app_chooser_widget_get_show_other
|
||||
gtk_app_chooser_widget_set_show_all
|
||||
gtk_app_chooser_widget_get_show_all
|
||||
gtk_app_chooser_widget_set_default_text
|
||||
gtk_app_chooser_widget_get_default_text
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GtkAppChooserWidgetClass
|
||||
GTK_TYPE_APP_CHOOSER_WIDGET
|
||||
GTK_APP_CHOOSER_WIDGET
|
||||
GTK_APP_CHOOSER_WIDGET_CLASS
|
||||
GTK_IS_APP_CHOOSER_WIDGET
|
||||
GTK_IS_APP_CHOOSER_WIDGET_CLASS
|
||||
GTK_APP_CHOOSER_WIDGET_GET_CLASS
|
||||
|
||||
<SUBSECTION Private>
|
||||
GtkAppChooserWidgetPrivate
|
||||
gtk_app_chooser_widget_get_type
|
||||
</SECTION>
|
||||
|
@ -11,6 +11,10 @@ gtk_action_group_get_type
|
||||
gtk_activatable_get_type
|
||||
gtk_adjustment_get_type
|
||||
gtk_alignment_get_type
|
||||
gtk_app_chooser_get_type
|
||||
gtk_app_chooser_button_get_type
|
||||
gtk_app_chooser_dialog_get_type
|
||||
gtk_app_chooser_widget_get_type
|
||||
gtk_application_get_type
|
||||
gtk_arrow_get_type
|
||||
gtk_aspect_frame_get_type
|
||||
|
@ -156,7 +156,11 @@ gtk_public_h_sources = \
|
||||
gtkactivatable.h \
|
||||
gtkadjustment.h \
|
||||
gtkalignment.h \
|
||||
gtkapplication.h \
|
||||
gtkappchooser.h \
|
||||
gtkappchooserdialog.h \
|
||||
gtkappchooserbutton.h \
|
||||
gtkappchooserwidget.h \
|
||||
gtkapplication.h \
|
||||
gtkarrow.h \
|
||||
gtkaspectframe.h \
|
||||
gtkassistant.h \
|
||||
@ -347,6 +351,18 @@ endif
|
||||
gtk_semi_private_h_sources = \
|
||||
gtktextlayout.h
|
||||
|
||||
if ENABLE_PACKAGEKIT
|
||||
gtk_appchooser_impl_h_sources = \
|
||||
gtkappchooseronlinepk.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
if ENABLE_PACKAGEKIT
|
||||
gtk_appchooser_impl_c_sources = \
|
||||
gtkappchooseronlinepk.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
# GTK+ header files that don't get installed
|
||||
gtk_private_h_sources = \
|
||||
gtkbuttonprivate.h \
|
||||
@ -371,6 +387,9 @@ gtk_private_h_sources = \
|
||||
gtkmenuprivate.h \
|
||||
gtkmnemonichash.h \
|
||||
gtkmountoperationprivate.h \
|
||||
gtkappchooserprivate.h \
|
||||
gtkappchoosermodule.h \
|
||||
gtkappchooseronline.h \
|
||||
gtkpango.h \
|
||||
gtkpathbar.h \
|
||||
gtkplugprivate.h \
|
||||
@ -398,7 +417,8 @@ gtk_private_h_sources = \
|
||||
gtktreeprivate.h \
|
||||
gtkwindow-decorate.h \
|
||||
gtkwidgetprivate.h \
|
||||
$(gtk_clipboard_dnd_h_sources)
|
||||
$(gtk_clipboard_dnd_h_sources) \
|
||||
$(gtk_appchooser_impl_h_sources)
|
||||
|
||||
# GTK+ C sources to build the library from
|
||||
gtk_base_c_sources = \
|
||||
@ -416,7 +436,13 @@ gtk_base_c_sources = \
|
||||
gtkactivatable.c \
|
||||
gtkadjustment.c \
|
||||
gtkalignment.c \
|
||||
gtkapplication.c \
|
||||
gtkappchooser.c \
|
||||
gtkappchooserwidget.c \
|
||||
gtkappchooserbutton.c \
|
||||
gtkappchooserdialog.c \
|
||||
gtkappchoosermodule.c \
|
||||
gtkappchooseronline.c \
|
||||
gtkapplication.c \
|
||||
gtkarrow.c \
|
||||
gtkaspectframe.c \
|
||||
gtkassistant.c \
|
||||
@ -616,7 +642,8 @@ gtk_base_c_sources = \
|
||||
gtkwidget.c \
|
||||
gtkwindow-decorate.c \
|
||||
gtkwindow.c \
|
||||
$(gtk_clipboard_dnd_c_sources)
|
||||
$(gtk_clipboard_dnd_c_sources) \
|
||||
$(gtk_appchooser_impl_c_sources)
|
||||
|
||||
gtk_c_sources = $(gtk_base_c_sources)
|
||||
gtk_all_c_sources = $(gtk_base_c_sources)
|
||||
|
@ -40,6 +40,10 @@
|
||||
#include <gtk/gtkactivatable.h>
|
||||
#include <gtk/gtkadjustment.h>
|
||||
#include <gtk/gtkalignment.h>
|
||||
#include <gtk/gtkappchooser.h>
|
||||
#include <gtk/gtkappchooserdialog.h>
|
||||
#include <gtk/gtkappchooserwidget.h>
|
||||
#include <gtk/gtkappchooserbutton.h>
|
||||
#include <gtk/gtkapplication.h>
|
||||
#include <gtk/gtkarrow.h>
|
||||
#include <gtk/gtkaspectframe.h>
|
||||
|
@ -178,6 +178,34 @@ gtk_alignment_new
|
||||
gtk_alignment_set
|
||||
gtk_alignment_set_padding
|
||||
gtk_alternative_dialog_button_order
|
||||
gtk_app_chooser_get_app_info
|
||||
gtk_app_chooser_get_content_type
|
||||
gtk_app_chooser_get_type G_GNUC_CONST
|
||||
gtk_app_chooser_refresh
|
||||
gtk_app_chooser_button_append_custom_item
|
||||
gtk_app_chooser_button_append_separator
|
||||
gtk_app_chooser_button_get_show_dialog_item
|
||||
gtk_app_chooser_button_get_type G_GNUC_CONST;
|
||||
gtk_app_chooser_button_new
|
||||
gtk_app_chooser_button_set_show_dialog_item
|
||||
gtk_app_chooser_dialog_new
|
||||
gtk_app_chooser_dialog_new_for_content_type
|
||||
gtk_app_chooser_dialog_get_type G_GNUC_CONST
|
||||
gtk_app_chooser_dialog_get_widget
|
||||
gtk_app_chooser_widget_new
|
||||
gtk_app_chooser_widget_get_show_all
|
||||
gtk_app_chooser_widget_get_default_text
|
||||
gtk_app_chooser_widget_get_show_default
|
||||
gtk_app_chooser_widget_get_show_fallback
|
||||
gtk_app_chooser_widget_get_show_other
|
||||
gtk_app_chooser_widget_get_show_recommended
|
||||
gtk_app_chooser_widget_get_type G_GNUC_CONST
|
||||
gtk_app_chooser_widget_set_default_text
|
||||
gtk_app_chooser_widget_set_show_all
|
||||
gtk_app_chooser_widget_set_show_default
|
||||
gtk_app_chooser_widget_set_show_fallback
|
||||
gtk_app_chooser_widget_set_show_other
|
||||
gtk_app_chooser_widget_set_show_recommended
|
||||
gtk_application_add_window
|
||||
gtk_application_get_type G_GNUC_CONST
|
||||
gtk_application_get_windows
|
||||
|
109
gtk/gtkappchooser.c
Normal file
109
gtk/gtkappchooser.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* gtkappchooser.c: app-chooser interface
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchooser.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkappchooserprivate.h"
|
||||
#include "gtkwidget.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_DEFINE_INTERFACE (GtkAppChooser, gtk_app_chooser, GTK_TYPE_WIDGET);
|
||||
|
||||
static void
|
||||
gtk_app_chooser_default_init (GtkAppChooserIface *iface)
|
||||
{
|
||||
GParamSpec *pspec;
|
||||
|
||||
/**
|
||||
* GtkAppChooser:content-type:
|
||||
*
|
||||
* The content type of the #GtkAppChooser object.
|
||||
*/
|
||||
pspec = g_param_spec_string ("content-type",
|
||||
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);
|
||||
g_object_interface_install_property (iface, pspec);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
gchar *
|
||||
gtk_app_chooser_get_content_type (GtkAppChooser *self)
|
||||
{
|
||||
gchar *retval = NULL;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER (self), NULL);
|
||||
|
||||
g_object_get (self,
|
||||
"content-type", &retval,
|
||||
NULL);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_get_app_info:
|
||||
* @self: a #GtkAppChooser
|
||||
*
|
||||
* Returns the currently selected application.
|
||||
*
|
||||
* Returns: (transfer full): a #GAppInfo for the currently selected
|
||||
* application, or %NULL if none is selected. Free with g_object_unref()
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
GAppInfo *
|
||||
gtk_app_chooser_get_app_info (GtkAppChooser *self)
|
||||
{
|
||||
return GTK_APP_CHOOSER_GET_IFACE (self)->get_app_info (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_refresh:
|
||||
* @self: a #GtkAppChooser
|
||||
*
|
||||
* Reloads the list of applications.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_app_chooser_refresh (GtkAppChooser *self)
|
||||
{
|
||||
GTK_APP_CHOOSER_GET_IFACE (self)->refresh (self);
|
||||
}
|
51
gtk/gtkappchooser.h
Normal file
51
gtk/gtkappchooser.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* gtkappchooser.h: app-chooser interface
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_H__
|
||||
#define __GTK_APP_CHOOSER_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER (gtk_app_chooser_get_type ())
|
||||
#define GTK_APP_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_APP_CHOOSER, GtkAppChooser))
|
||||
#define GTK_IS_APP_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_APP_CHOOSER))
|
||||
|
||||
typedef struct _GtkAppChooser GtkAppChooser;
|
||||
|
||||
GType gtk_app_chooser_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GAppInfo * gtk_app_chooser_get_app_info (GtkAppChooser *self);
|
||||
gchar * gtk_app_chooser_get_content_type (GtkAppChooser *self);
|
||||
void gtk_app_chooser_refresh (GtkAppChooser *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_H__ */
|
||||
|
713
gtk/gtkappchooserbutton.c
Normal file
713
gtk/gtkappchooserbutton.c
Normal file
@ -0,0 +1,713 @@
|
||||
/*
|
||||
* gtkappchooserbutton.h: an app-chooser combobox
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchooserbutton.h"
|
||||
|
||||
#include "gtkappchooser.h"
|
||||
#include "gtkappchooserdialog.h"
|
||||
#include "gtkappchooserprivate.h"
|
||||
#include "gtkcelllayout.h"
|
||||
#include "gtkcellrendererpixbuf.h"
|
||||
#include "gtkcellrenderertext.h"
|
||||
#include "gtkcombobox.h"
|
||||
#include "gtkdialog.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkmarshalers.h"
|
||||
|
||||
enum {
|
||||
PROP_CONTENT_TYPE = 1,
|
||||
PROP_SHOW_DIALOG_ITEM,
|
||||
};
|
||||
|
||||
enum {
|
||||
SIGNAL_CUSTOM_ITEM_ACTIVATED,
|
||||
NUM_SIGNALS
|
||||
};
|
||||
|
||||
enum {
|
||||
COLUMN_APP_INFO,
|
||||
COLUMN_NAME,
|
||||
COLUMN_LABEL,
|
||||
COLUMN_ICON,
|
||||
COLUMN_CUSTOM,
|
||||
COLUMN_SEPARATOR,
|
||||
NUM_COLUMNS,
|
||||
};
|
||||
|
||||
#define CUSTOM_ITEM_OTHER_APP "gtk-internal-item-other-app"
|
||||
|
||||
static void app_chooser_iface_init (GtkAppChooserIface *iface);
|
||||
|
||||
static void real_insert_custom_item (GtkAppChooserButton *self,
|
||||
const gchar *name,
|
||||
const gchar *label,
|
||||
GIcon *icon,
|
||||
gboolean custom,
|
||||
GtkTreeIter *iter);
|
||||
|
||||
static void real_insert_separator (GtkAppChooserButton *self,
|
||||
gboolean custom,
|
||||
GtkTreeIter *iter);
|
||||
|
||||
static guint signals[NUM_SIGNALS] = { 0, };
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserButton, gtk_app_chooser_button, GTK_TYPE_COMBO_BOX,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
||||
app_chooser_iface_init));
|
||||
|
||||
struct _GtkAppChooserButtonPrivate {
|
||||
GtkListStore *store;
|
||||
|
||||
gchar *content_type;
|
||||
gboolean show_dialog_item;
|
||||
|
||||
GHashTable *custom_item_names;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
row_separator_func (GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean separator;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
COLUMN_SEPARATOR, &separator,
|
||||
-1);
|
||||
|
||||
return separator;
|
||||
}
|
||||
|
||||
static void
|
||||
get_first_iter (GtkListStore *store,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GtkTreeIter iter2;
|
||||
|
||||
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), iter))
|
||||
{
|
||||
/* the model is empty, append */
|
||||
gtk_list_store_append (store, iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_insert_before (store, &iter2, iter);
|
||||
*iter = iter2;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GtkAppChooserButton *self;
|
||||
GAppInfo *info;
|
||||
gint active_index;
|
||||
} SelectAppData;
|
||||
|
||||
static void
|
||||
select_app_data_free (SelectAppData *data)
|
||||
{
|
||||
g_clear_object (&data->self);
|
||||
g_clear_object (&data->info);
|
||||
|
||||
g_slice_free (SelectAppData, data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
select_application_func_cb (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer user_data)
|
||||
{
|
||||
SelectAppData *data = user_data;
|
||||
GAppInfo *app_to_match = data->info, *app = NULL;
|
||||
gboolean custom;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
COLUMN_APP_INFO, &app,
|
||||
COLUMN_CUSTOM, &custom,
|
||||
-1);
|
||||
|
||||
/* cutsom items are always after GAppInfos, so iterating further here
|
||||
* is just useless.
|
||||
*/
|
||||
if (custom)
|
||||
return TRUE;
|
||||
|
||||
if (g_app_info_equal (app, app_to_match))
|
||||
{
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (data->self), iter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_select_application (GtkAppChooserButton *self,
|
||||
GAppInfo *info)
|
||||
{
|
||||
SelectAppData *data;
|
||||
|
||||
data = g_slice_new0 (SelectAppData);
|
||||
data->self = g_object_ref (self);
|
||||
data->info = g_object_ref (info);
|
||||
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (self->priv->store),
|
||||
select_application_func_cb, data);
|
||||
|
||||
select_app_data_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
other_application_dialog_response_cb (GtkDialog *dialog,
|
||||
gint response_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserButton *self = user_data;
|
||||
GAppInfo *info;
|
||||
|
||||
if (response_id != GTK_RESPONSE_OK)
|
||||
{
|
||||
/* reset the active item, otherwise we are stuck on
|
||||
* 'Other application...'
|
||||
*/
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (self), 0);
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
|
||||
|
||||
/* refresh the combobox to get the new application */
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
||||
gtk_app_chooser_button_select_application (self, info);
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
static void
|
||||
other_application_item_activated_cb (GtkAppChooserButton *self)
|
||||
{
|
||||
GtkWidget *dialog, *widget;
|
||||
GtkWindow *toplevel;
|
||||
|
||||
toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
|
||||
dialog = gtk_app_chooser_dialog_new_for_content_type (toplevel, GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
self->priv->content_type);
|
||||
widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
|
||||
g_object_set (widget,
|
||||
"show-fallback", TRUE,
|
||||
"show-other", TRUE,
|
||||
NULL);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (other_application_dialog_response_cb), self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_ensure_dialog_item (GtkAppChooserButton *self,
|
||||
GtkTreeIter *prev_iter)
|
||||
{
|
||||
GIcon *icon;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (!self->priv->show_dialog_item)
|
||||
return;
|
||||
|
||||
icon = g_themed_icon_new ("application-x-executable");
|
||||
|
||||
gtk_list_store_insert_after (self->priv->store, &iter, prev_iter);
|
||||
real_insert_separator (self, FALSE, &iter);
|
||||
*prev_iter = iter;
|
||||
|
||||
gtk_list_store_insert_after (self->priv->store, &iter, prev_iter);
|
||||
real_insert_custom_item (self, CUSTOM_ITEM_OTHER_APP,
|
||||
_("Other application..."), icon,
|
||||
FALSE, &iter);
|
||||
|
||||
g_object_unref (icon);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_populate (GtkAppChooserButton *self)
|
||||
{
|
||||
GList *recommended_apps = NULL, *l;
|
||||
GAppInfo *app;
|
||||
GtkTreeIter iter, iter2;
|
||||
GIcon *icon;
|
||||
gboolean first;
|
||||
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||
first = TRUE;
|
||||
|
||||
for (l = recommended_apps; l != NULL; l = l->next)
|
||||
{
|
||||
app = l->data;
|
||||
|
||||
icon = g_app_info_get_icon (app);
|
||||
|
||||
if (icon == NULL)
|
||||
icon = g_themed_icon_new ("application-x-executable");
|
||||
else
|
||||
g_object_ref (icon);
|
||||
|
||||
if (first)
|
||||
{
|
||||
get_first_iter (self->priv->store, &iter);
|
||||
first = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_insert_after (self->priv->store, &iter2, &iter);
|
||||
iter = iter2;
|
||||
}
|
||||
|
||||
gtk_list_store_set (self->priv->store, &iter,
|
||||
COLUMN_APP_INFO, app,
|
||||
COLUMN_LABEL, g_app_info_get_display_name (app),
|
||||
COLUMN_ICON, icon,
|
||||
COLUMN_CUSTOM, FALSE,
|
||||
-1);
|
||||
|
||||
g_object_unref (icon);
|
||||
}
|
||||
|
||||
gtk_app_chooser_button_ensure_dialog_item (self, &iter);
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (self), 0);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
|
||||
{
|
||||
GtkCellRenderer *cell;
|
||||
|
||||
self->priv->store = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_APP_INFO,
|
||||
G_TYPE_STRING, /* name */
|
||||
G_TYPE_STRING, /* label */
|
||||
G_TYPE_ICON,
|
||||
G_TYPE_BOOLEAN, /* separator */
|
||||
G_TYPE_BOOLEAN); /* custom */
|
||||
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (self),
|
||||
GTK_TREE_MODEL (self->priv->store));
|
||||
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self),
|
||||
row_separator_func, NULL, NULL);
|
||||
|
||||
cell = gtk_cell_renderer_pixbuf_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), cell,
|
||||
"gicon", COLUMN_ICON,
|
||||
NULL);
|
||||
|
||||
cell = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, TRUE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), cell,
|
||||
"text", COLUMN_LABEL,
|
||||
NULL);
|
||||
g_object_set (cell,
|
||||
"xpad", 6,
|
||||
NULL);
|
||||
|
||||
gtk_app_chooser_button_populate (self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_remove_non_custom (GtkAppChooserButton *self)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
gboolean custom, res;
|
||||
|
||||
model = GTK_TREE_MODEL (self->priv->store);
|
||||
|
||||
if (!gtk_tree_model_get_iter_first (model, &iter))
|
||||
return;
|
||||
|
||||
do {
|
||||
gtk_tree_model_get (model, &iter,
|
||||
COLUMN_CUSTOM, &custom,
|
||||
-1);
|
||||
if (custom)
|
||||
res = gtk_tree_model_iter_next (model, &iter);
|
||||
else
|
||||
res = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
||||
} while (res);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_changed (GtkComboBox *object)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
|
||||
GtkTreeIter iter;
|
||||
gchar *name = NULL;
|
||||
gboolean custom;
|
||||
GQuark name_quark;
|
||||
|
||||
if (!gtk_combo_box_get_active_iter (object, &iter))
|
||||
return;
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (self->priv->store), &iter,
|
||||
COLUMN_NAME, &name,
|
||||
COLUMN_CUSTOM, &custom,
|
||||
-1);
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
if (custom)
|
||||
{
|
||||
name_quark = g_quark_from_string (name);
|
||||
g_signal_emit (self, signals[SIGNAL_CUSTOM_ITEM_ACTIVATED], name_quark, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* trigger the dialog internally */
|
||||
other_application_item_activated_cb (self);
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_refresh (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
|
||||
|
||||
gtk_app_chooser_button_remove_non_custom (self);
|
||||
gtk_app_chooser_button_populate (self);
|
||||
}
|
||||
|
||||
static GAppInfo *
|
||||
gtk_app_chooser_button_get_app_info (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
|
||||
GtkTreeIter iter;
|
||||
GAppInfo *info;
|
||||
|
||||
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
|
||||
return NULL;
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (self->priv->store), &iter,
|
||||
COLUMN_APP_INFO, &info,
|
||||
-1);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_constructed (GObject *obj)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
||||
|
||||
if (G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed (obj);
|
||||
|
||||
g_assert (self->priv->content_type != NULL);
|
||||
|
||||
gtk_app_chooser_button_build_ui (self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_set_property (GObject *obj,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTENT_TYPE:
|
||||
self->priv->content_type = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_SHOW_DIALOG_ITEM:
|
||||
gtk_app_chooser_button_set_show_dialog_item (self, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_get_property (GObject *obj,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTENT_TYPE:
|
||||
g_value_set_string (value, self->priv->content_type);
|
||||
break;
|
||||
case PROP_SHOW_DIALOG_ITEM:
|
||||
g_value_set_boolean (value, self->priv->show_dialog_item);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_finalize (GObject *obj)
|
||||
{
|
||||
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
||||
|
||||
g_hash_table_destroy (self->priv->custom_item_names);
|
||||
g_free (self->priv->content_type);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
app_chooser_iface_init (GtkAppChooserIface *iface)
|
||||
{
|
||||
iface->get_app_info = gtk_app_chooser_button_get_app_info;
|
||||
iface->refresh = gtk_app_chooser_button_refresh;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_class_init (GtkAppChooserButtonClass *klass)
|
||||
{
|
||||
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
||||
GtkComboBoxClass *combo_class = GTK_COMBO_BOX_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
oclass->set_property = gtk_app_chooser_button_set_property;
|
||||
oclass->get_property = gtk_app_chooser_button_get_property;
|
||||
oclass->finalize = gtk_app_chooser_button_finalize;
|
||||
oclass->constructed = gtk_app_chooser_button_constructed;
|
||||
|
||||
combo_class->changed = gtk_app_chooser_button_changed;
|
||||
|
||||
g_object_class_override_property (oclass, PROP_CONTENT_TYPE, "content-type");
|
||||
|
||||
/**
|
||||
* GtkAppChooserButton:show-dialog-item:
|
||||
*
|
||||
* The #GtkAppChooserButton:show-dialog-item property determines whether the dropdown menu
|
||||
* should show an item that triggers a #GtkAppChooserDialog when clicked.
|
||||
*/
|
||||
pspec =
|
||||
g_param_spec_boolean ("show-dialog-item",
|
||||
P_("Include an 'Other...' item"),
|
||||
P_("Whether the combobox should include an item that triggers a GtkAppChooserDialog"),
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_property (oclass, PROP_SHOW_DIALOG_ITEM, pspec);
|
||||
|
||||
/**
|
||||
* GtkAppChooserButton::custom-item-activated:
|
||||
* @self: the object which received the signal
|
||||
* @item_name: the name of the activated item
|
||||
*
|
||||
* Emitted when a custom item, previously added with
|
||||
* gtk_app_chooser_button_append_custom_item(), is activated from the
|
||||
* dropdown menu.
|
||||
*/
|
||||
signals[SIGNAL_CUSTOM_ITEM_ACTIVATED] =
|
||||
g_signal_new ("custom-item-activated",
|
||||
GTK_TYPE_APP_CHOOSER_BUTTON,
|
||||
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
|
||||
G_STRUCT_OFFSET (GtkAppChooserButtonClass, custom_item_activated),
|
||||
NULL, NULL,
|
||||
_gtk_marshal_VOID__STRING,
|
||||
G_TYPE_NONE,
|
||||
1, G_TYPE_STRING);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GtkAppChooserButtonPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_button_init (GtkAppChooserButton *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_BUTTON,
|
||||
GtkAppChooserButtonPrivate);
|
||||
self->priv->custom_item_names =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
real_insert_custom_item (GtkAppChooserButton *self,
|
||||
const gchar *name,
|
||||
const gchar *label,
|
||||
GIcon *icon,
|
||||
gboolean custom,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
if (custom)
|
||||
{
|
||||
if (g_hash_table_lookup (self->priv->custom_item_names,
|
||||
name) != NULL)
|
||||
{
|
||||
g_warning ("Attempting to add custom item %s to GtkAppChooserButton, "
|
||||
"when there's already an item with the same name", name);
|
||||
return;
|
||||
}
|
||||
|
||||
g_hash_table_insert (self->priv->custom_item_names,
|
||||
g_strdup (name), GINT_TO_POINTER (1));
|
||||
}
|
||||
|
||||
gtk_list_store_set (self->priv->store, iter,
|
||||
COLUMN_NAME, name,
|
||||
COLUMN_LABEL, label,
|
||||
COLUMN_ICON, icon,
|
||||
COLUMN_CUSTOM, custom,
|
||||
COLUMN_SEPARATOR, FALSE,
|
||||
-1);
|
||||
}
|
||||
|
||||
static void
|
||||
real_insert_separator (GtkAppChooserButton *self,
|
||||
gboolean custom,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
gtk_list_store_set (self->priv->store, iter,
|
||||
COLUMN_CUSTOM, custom,
|
||||
COLUMN_SEPARATOR, TRUE,
|
||||
-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_button_new:
|
||||
* @content_type: the content type to show applications for
|
||||
*
|
||||
* Creates a new #GtkAppChooserButton for applications
|
||||
* that can handle content of the given type.
|
||||
*
|
||||
* Returns: a newly created #GtkAppChooserButton
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_app_chooser_button_new (const gchar *content_type)
|
||||
{
|
||||
g_return_val_if_fail (content_type != NULL, NULL);
|
||||
|
||||
return g_object_new (GTK_TYPE_APP_CHOOSER_BUTTON,
|
||||
"content-type", content_type,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_button_append_separator:
|
||||
* @self: a #GtkAppChooserButton
|
||||
*
|
||||
* Appends a separator to the list of applications that is shown
|
||||
* in the popup.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_app_chooser_button_append_separator (GtkAppChooserButton *self)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
||||
|
||||
gtk_list_store_append (self->priv->store, &iter);
|
||||
real_insert_separator (self, TRUE, &iter);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_button_append_custom_item:
|
||||
* @self: a #GtkAppChooserButton
|
||||
* @name: the name of the custom item
|
||||
* @label: the label for the custom item
|
||||
* @icon: the icon for the custom item
|
||||
*
|
||||
* Appends a custom item to the list of applications that is shown
|
||||
* in the popup; the item name must be unique per-widget.
|
||||
* Clients can use the provided name as a detail for the ::custom-item-activated
|
||||
* signal, to add a callback for the activation of a particular
|
||||
* custom item in the list.
|
||||
* See also gtk_app_chooser_button_append_separator().
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self,
|
||||
const gchar *name,
|
||||
const gchar *label,
|
||||
GIcon *icon)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
gtk_list_store_append (self->priv->store, &iter);
|
||||
real_insert_custom_item (self, name, label, icon, TRUE, &iter);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_button_get_show_dialog_item:
|
||||
* @self: a #GtkAppChooserButton
|
||||
*
|
||||
* Returns the current value of the #GtkAppChooserButton:show-dialog-item
|
||||
* property.
|
||||
*
|
||||
* Returns: the value of #GtkAppChooserButton:show-dialog-item
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
gboolean
|
||||
gtk_app_chooser_button_get_show_dialog_item (GtkAppChooserButton *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
|
||||
|
||||
return self->priv->show_dialog_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_button_set_show_dialog_item:
|
||||
* @self: a #GtkAppChooserButton
|
||||
* @setting: the new value for #GtkAppChooserButton:show-dialog-item
|
||||
*
|
||||
* Sets whether the dropdown menu of this button should show an
|
||||
* entry to trigger a #GtkAppChooserDialog.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_app_chooser_button_set_show_dialog_item (GtkAppChooserButton *self,
|
||||
gboolean setting)
|
||||
{
|
||||
if (self->priv->show_dialog_item != setting)
|
||||
{
|
||||
self->priv->show_dialog_item = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-dialog-item");
|
||||
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
||||
}
|
||||
}
|
76
gtk/gtkappchooserbutton.h
Normal file
76
gtk/gtkappchooserbutton.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* gtkappchooserbutton.h: an app-chooser combobox
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_BUTTON_H__
|
||||
#define __GTK_APP_CHOOSER_BUTTON_H__
|
||||
|
||||
#include <gtk/gtkcombobox.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER_BUTTON (gtk_app_chooser_button_get_type ())
|
||||
#define GTK_APP_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_APP_CHOOSER_BUTTON, GtkAppChooserButton))
|
||||
#define GTK_APP_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_APP_CHOOSER_BUTTON, GtkAppChooserButtonClass))
|
||||
#define GTK_IS_APP_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_APP_CHOOSER_BUTTON))
|
||||
#define GTK_IS_APP_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_APP_CHOOSER_BUTTON))
|
||||
#define GTK_APP_CHOOSER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_APP_CHOOSER_BUTTON, GtkAppChooserButtonClass))
|
||||
|
||||
typedef struct _GtkAppChooserButton GtkAppChooserButton;
|
||||
typedef struct _GtkAppChooserButtonClass GtkAppChooserButtonClass;
|
||||
typedef struct _GtkAppChooserButtonPrivate GtkAppChooserButtonPrivate;
|
||||
|
||||
struct _GtkAppChooserButton {
|
||||
GtkComboBox parent;
|
||||
|
||||
/*< private >*/
|
||||
GtkAppChooserButtonPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserButtonClass {
|
||||
GtkComboBoxClass parent_class;
|
||||
|
||||
void (* custom_item_activated) (GtkAppChooserButton *self,
|
||||
const gchar *item_name);
|
||||
|
||||
/* padding for future class expansion */
|
||||
gpointer padding[16];
|
||||
};
|
||||
|
||||
GType gtk_app_chooser_button_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gtk_app_chooser_button_new (const gchar *content_type);
|
||||
|
||||
void gtk_app_chooser_button_append_separator (GtkAppChooserButton *self);
|
||||
void gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self,
|
||||
const gchar *name,
|
||||
const gchar *label,
|
||||
GIcon *icon);
|
||||
|
||||
void gtk_app_chooser_button_set_show_dialog_item (GtkAppChooserButton *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_button_get_show_dialog_item (GtkAppChooserButton *self);
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_BUTTON_H__ */
|
787
gtk/gtkappchooserdialog.c
Normal file
787
gtk/gtkappchooserdialog.c
Normal file
@ -0,0 +1,787 @@
|
||||
/*
|
||||
* gtkappchooserdialog.c: an app-chooser dialog
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Dave Camp <dave@novell.com>
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
* Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchooserdialog.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkappchooser.h"
|
||||
#include "gtkappchooseronline.h"
|
||||
#include "gtkappchooserprivate.h"
|
||||
#include "gtkappchooserprivate.h"
|
||||
|
||||
#include "gtkmessagedialog.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtkbbox.h"
|
||||
#include "gtkbutton.h"
|
||||
#include "gtkmenuitem.h"
|
||||
#include "gtkstock.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define sure_string(s) ((const char *) ((s) != NULL ? (s) : ""))
|
||||
|
||||
struct _GtkAppChooserDialogPrivate {
|
||||
char *content_type;
|
||||
GFile *gfile;
|
||||
|
||||
GtkWidget *label;
|
||||
GtkWidget *button;
|
||||
GtkWidget *online_button;
|
||||
|
||||
GtkWidget *open_label;
|
||||
|
||||
GtkWidget *app_chooser_widget;
|
||||
GtkWidget *show_more_button;
|
||||
|
||||
GtkAppChooserOnline *online;
|
||||
|
||||
gboolean show_more_clicked;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_GFILE = 1,
|
||||
PROP_CONTENT_TYPE,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
static void gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserDialog, gtk_app_chooser_dialog, GTK_TYPE_DIALOG,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
||||
gtk_app_chooser_dialog_iface_init));
|
||||
|
||||
static void
|
||||
show_error_dialog (const gchar *primary,
|
||||
const gchar *secondary,
|
||||
GtkWindow *parent)
|
||||
{
|
||||
GtkWidget *message_dialog;
|
||||
|
||||
message_dialog = gtk_message_dialog_new (parent, 0,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_OK,
|
||||
NULL);
|
||||
g_object_set (message_dialog,
|
||||
"text", primary,
|
||||
"secondary-text", secondary,
|
||||
NULL);
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_OK);
|
||||
|
||||
gtk_widget_show (message_dialog);
|
||||
|
||||
g_signal_connect (message_dialog, "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
search_for_mimetype_ready_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnline *online = GTK_APP_CHOOSER_ONLINE (source);
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
GError *error = NULL;
|
||||
|
||||
gtk_app_chooser_online_search_for_mimetype_finish (online, res, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
show_error_dialog (_("Failed to look for applications online"),
|
||||
error->message, GTK_WINDOW (self));
|
||||
g_error_free (error);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
online_button_clicked_cb (GtkButton *b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
gtk_app_chooser_online_search_for_mimetype_async (self->priv->online,
|
||||
self->priv->content_type,
|
||||
GTK_WINDOW (self),
|
||||
search_for_mimetype_ready_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
app_chooser_online_get_default_ready_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
self->priv->online = gtk_app_chooser_online_get_default_finish (source, res);
|
||||
|
||||
if (self->priv->online != NULL)
|
||||
{
|
||||
GtkWidget *action_area;
|
||||
|
||||
action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
|
||||
self->priv->online_button = gtk_button_new_with_label (_("Find applications online"));
|
||||
gtk_box_pack_start (GTK_BOX (action_area), self->priv->online_button,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), self->priv->online_button,
|
||||
TRUE);
|
||||
g_signal_connect (self->priv->online_button, "clicked",
|
||||
G_CALLBACK (online_button_clicked_cb), self);
|
||||
|
||||
gtk_widget_show (self->priv->online_button);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_online_button (GtkAppChooserDialog *self)
|
||||
{
|
||||
gtk_app_chooser_online_get_default_async (app_chooser_online_get_default_ready_cb, self);
|
||||
}
|
||||
|
||||
/* An application is valid if:
|
||||
*
|
||||
* 1) The file exists
|
||||
* 2) The user has permissions to run the file
|
||||
*/
|
||||
static gboolean
|
||||
check_application (GtkAppChooserDialog *self,
|
||||
GAppInfo **app_out)
|
||||
{
|
||||
const char *command;
|
||||
char *path = NULL;
|
||||
char **argv = NULL;
|
||||
int argc;
|
||||
GError *error = NULL;
|
||||
gint retval = TRUE;
|
||||
GAppInfo *info;
|
||||
|
||||
command = NULL;
|
||||
|
||||
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
|
||||
command = g_app_info_get_executable (info);
|
||||
|
||||
g_shell_parse_argv (command, &argc, &argv, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
show_error_dialog (_("Could not run application"),
|
||||
error->message,
|
||||
GTK_WINDOW (self));
|
||||
g_error_free (error);
|
||||
retval = FALSE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
path = g_find_program_in_path (argv[0]);
|
||||
if (!path)
|
||||
{
|
||||
char *error_message;
|
||||
|
||||
error_message = g_strdup_printf (_("Could not find '%s'"),
|
||||
argv[0]);
|
||||
|
||||
show_error_dialog (_("Could not find application"),
|
||||
error_message,
|
||||
GTK_WINDOW (self));
|
||||
g_free (error_message);
|
||||
retval = FALSE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*app_out = info;
|
||||
|
||||
cleanup:
|
||||
g_strfreev (argv);
|
||||
g_free (path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
add_or_find_application (GtkAppChooserDialog *self)
|
||||
{
|
||||
GAppInfo *app;
|
||||
|
||||
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
||||
|
||||
/* we don't care about reporting errors here */
|
||||
g_app_info_add_supports_type (app,
|
||||
self->priv->content_type,
|
||||
NULL);
|
||||
|
||||
g_object_unref (app);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_response (GtkDialog *dialog,
|
||||
gint response_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (dialog);
|
||||
|
||||
switch (response_id)
|
||||
{
|
||||
case GTK_RESPONSE_OK:
|
||||
add_or_find_application (self);
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
widget_application_selected_cb (GtkAppChooserWidget *widget,
|
||||
GAppInfo *app_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
gtk_widget_set_sensitive (self->priv->button, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
widget_application_activated_cb (GtkAppChooserWidget *widget,
|
||||
GAppInfo *app_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
|
||||
}
|
||||
|
||||
static char *
|
||||
get_extension (const char *basename)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strrchr (basename, '.');
|
||||
|
||||
if (p && *(p + 1) != '\0')
|
||||
return g_strdup (p + 1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
set_dialog_properties (GtkAppChooserDialog *self)
|
||||
{
|
||||
gchar *label;
|
||||
gchar *name;
|
||||
gchar *extension;
|
||||
gchar *description;
|
||||
gchar *default_text;
|
||||
gchar *string;
|
||||
PangoFontDescription *font_desc;
|
||||
|
||||
name = NULL;
|
||||
extension = NULL;
|
||||
label = NULL;
|
||||
description = NULL;
|
||||
|
||||
if (self->priv->gfile != NULL)
|
||||
{
|
||||
name = g_file_get_basename (self->priv->gfile);
|
||||
extension = get_extension (name);
|
||||
}
|
||||
|
||||
description = g_content_type_get_description (self->priv->content_type);
|
||||
gtk_window_set_title (GTK_WINDOW (self), "");
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
/* Translators: %s is a filename */
|
||||
label = g_strdup_printf (_("Select an application to open \"%s\""), name);
|
||||
string = g_strdup_printf (_("No applications available to open \"%s\""),
|
||||
name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Translators: %s is a file type description */
|
||||
label = g_strdup_printf (_("Select an application for \"%s\" files"),
|
||||
g_content_type_is_unknown (self->priv->content_type) ?
|
||||
self->priv->content_type : description);
|
||||
string = g_strdup_printf (_("No applications available to open \"%s\" files"),
|
||||
g_content_type_is_unknown (self->priv->content_type) ?
|
||||
self->priv->content_type : description);
|
||||
}
|
||||
|
||||
font_desc = pango_font_description_new ();
|
||||
pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
|
||||
gtk_widget_modify_font (self->priv->label, font_desc);
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
gtk_label_set_markup (GTK_LABEL (self->priv->label), label);
|
||||
|
||||
default_text = g_strdup_printf ("<big><b>%s</b></big>\n%s",
|
||||
string,
|
||||
_("Click \"Show other applications\", for more options, or "
|
||||
"\"Find applications online\" to install a new application"));
|
||||
|
||||
gtk_app_chooser_widget_set_default_text (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget),
|
||||
default_text);
|
||||
|
||||
g_free (label);
|
||||
g_free (name);
|
||||
g_free (extension);
|
||||
g_free (description);
|
||||
g_free (string);
|
||||
g_free (default_text);
|
||||
}
|
||||
|
||||
static void
|
||||
show_more_button_clicked_cb (GtkButton *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
g_object_set (self->priv->app_chooser_widget,
|
||||
"show-recommended", TRUE,
|
||||
"show-fallback", TRUE,
|
||||
"show-other", TRUE,
|
||||
NULL);
|
||||
|
||||
gtk_widget_hide (self->priv->show_more_button);
|
||||
self->priv->show_more_clicked = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
widget_notify_for_button_cb (GObject *source,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
GtkAppChooserWidget *widget = GTK_APP_CHOOSER_WIDGET (source);
|
||||
gboolean should_hide;
|
||||
|
||||
should_hide = gtk_app_chooser_widget_get_show_all (widget) ||
|
||||
self->priv->show_more_clicked;
|
||||
|
||||
if (should_hide)
|
||||
gtk_widget_hide (self->priv->show_more_button);
|
||||
}
|
||||
|
||||
static void
|
||||
forget_menu_item_activate_cb (GtkMenuItem *item,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
GAppInfo *info;
|
||||
|
||||
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
||||
|
||||
if (info != NULL)
|
||||
{
|
||||
g_app_info_remove_supports_type (info, self->priv->content_type, NULL);
|
||||
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
build_forget_menu_item (GtkAppChooserDialog *self)
|
||||
{
|
||||
GtkWidget *retval;
|
||||
|
||||
retval = gtk_menu_item_new_with_label (_("Forget association"));
|
||||
gtk_widget_show (retval);
|
||||
|
||||
g_signal_connect (retval, "activate",
|
||||
G_CALLBACK (forget_menu_item_activate_cb), self);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
widget_populate_popup_cb (GtkAppChooserWidget *widget,
|
||||
GtkMenu *menu,
|
||||
GAppInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
GtkWidget *menu_item;
|
||||
|
||||
if (g_app_info_can_remove_supports_type (info))
|
||||
{
|
||||
menu_item = build_forget_menu_item (self);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
build_dialog_ui (GtkAppChooserDialog *self)
|
||||
{
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *vbox2;
|
||||
GtkWidget *label;
|
||||
GtkWidget *button, *w;
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (self), 5);
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
|
||||
gtk_widget_show (vbox);
|
||||
|
||||
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
|
||||
gtk_widget_show (vbox2);
|
||||
|
||||
self->priv->label = gtk_label_new ("");
|
||||
gtk_misc_set_alignment (GTK_MISC (self->priv->label), 0, 0.5);
|
||||
gtk_label_set_line_wrap (GTK_LABEL (self->priv->label), TRUE);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), self->priv->label,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_widget_show (self->priv->label);
|
||||
|
||||
self->priv->app_chooser_widget =
|
||||
gtk_app_chooser_widget_new (self->priv->content_type);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), self->priv->app_chooser_widget, TRUE, TRUE, 0);
|
||||
gtk_widget_show (self->priv->app_chooser_widget);
|
||||
|
||||
g_signal_connect (self->priv->app_chooser_widget, "application-selected",
|
||||
G_CALLBACK (widget_application_selected_cb), self);
|
||||
g_signal_connect (self->priv->app_chooser_widget, "application-activated",
|
||||
G_CALLBACK (widget_application_activated_cb), self);
|
||||
g_signal_connect (self->priv->app_chooser_widget, "notify::show-all",
|
||||
G_CALLBACK (widget_notify_for_button_cb), self);
|
||||
g_signal_connect (self->priv->app_chooser_widget, "populate-popup",
|
||||
G_CALLBACK (widget_populate_popup_cb), self);
|
||||
|
||||
button = gtk_button_new_with_label (_("Show other applications"));
|
||||
self->priv->show_more_button = button;
|
||||
w = gtk_image_new_from_stock (GTK_STOCK_ADD,
|
||||
GTK_ICON_SIZE_BUTTON);
|
||||
gtk_button_set_image (GTK_BUTTON (button), w);
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->app_chooser_widget), button, FALSE, FALSE, 6);
|
||||
gtk_widget_show_all (button);
|
||||
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (show_more_button_clicked_cb), self);
|
||||
|
||||
gtk_dialog_add_button (GTK_DIALOG (self),
|
||||
GTK_STOCK_CANCEL,
|
||||
GTK_RESPONSE_CANCEL);
|
||||
|
||||
/* Create a custom stock icon */
|
||||
self->priv->button = gtk_button_new ();
|
||||
|
||||
label = gtk_label_new_with_mnemonic (_("_Open"));
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (self->priv->button));
|
||||
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
|
||||
gtk_widget_show (label);
|
||||
self->priv->open_label = label;
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (self->priv->button),
|
||||
self->priv->open_label);
|
||||
|
||||
gtk_widget_show (self->priv->button);
|
||||
gtk_widget_set_can_default (self->priv->button, TRUE);
|
||||
|
||||
gtk_dialog_add_action_widget (GTK_DIALOG (self),
|
||||
self->priv->button, GTK_RESPONSE_OK);
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (self),
|
||||
GTK_RESPONSE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
set_gfile_and_content_type (GtkAppChooserDialog *self,
|
||||
GFile *file)
|
||||
{
|
||||
GFileInfo *info;
|
||||
|
||||
if (file == NULL)
|
||||
return;
|
||||
|
||||
self->priv->gfile = g_object_ref (file);
|
||||
|
||||
info = g_file_query_info (self->priv->gfile,
|
||||
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
||||
0, NULL, NULL);
|
||||
self->priv->content_type = g_strdup (g_file_info_get_content_type (info));
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
static GAppInfo *
|
||||
gtk_app_chooser_dialog_get_app_info (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
GAppInfo *app = NULL;
|
||||
|
||||
if (!check_application (self, &app))
|
||||
return NULL;
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_refresh (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_constructed (GObject *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
g_assert (self->priv->content_type != NULL ||
|
||||
self->priv->gfile != NULL);
|
||||
|
||||
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
|
||||
|
||||
build_dialog_ui (self);
|
||||
set_dialog_properties (self);
|
||||
ensure_online_button (self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_dispose (GObject *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
g_clear_object (&self->priv->gfile);
|
||||
g_clear_object (&self->priv->online);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_finalize (GObject *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
g_free (self->priv->content_type);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_GFILE:
|
||||
set_gfile_and_content_type (self, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_CONTENT_TYPE:
|
||||
/* don't try to override a value previously set with the GFile */
|
||||
if (self->priv->content_type == NULL)
|
||||
self->priv->content_type = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_GFILE:
|
||||
if (self->priv->gfile != NULL)
|
||||
g_value_set_object (value, self->priv->gfile);
|
||||
break;
|
||||
case PROP_CONTENT_TYPE:
|
||||
g_value_set_string (value, self->priv->content_type);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface)
|
||||
{
|
||||
iface->get_app_info = gtk_app_chooser_dialog_get_app_info;
|
||||
iface->refresh = gtk_app_chooser_dialog_refresh;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class = G_OBJECT_CLASS (klass);
|
||||
gobject_class->dispose = gtk_app_chooser_dialog_dispose;
|
||||
gobject_class->finalize = gtk_app_chooser_dialog_finalize;
|
||||
gobject_class->set_property = gtk_app_chooser_dialog_set_property;
|
||||
gobject_class->get_property = gtk_app_chooser_dialog_get_property;
|
||||
gobject_class->constructed = gtk_app_chooser_dialog_constructed;
|
||||
|
||||
g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
|
||||
|
||||
/**
|
||||
* GtkAppChooserDialog:gfile:
|
||||
*
|
||||
* The GFile used by the #GtkAppChooserDialog.
|
||||
* The dialog's #GtkAppChooserWidget content type will be guessed from the
|
||||
* file, if present.
|
||||
*/
|
||||
pspec = g_param_spec_object ("gfile",
|
||||
P_("GFile"),
|
||||
P_("The GFile used by the app chooser dialog"),
|
||||
G_TYPE_FILE,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_property (gobject_class, PROP_GFILE, pspec);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GtkAppChooserDialogPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_DIALOG,
|
||||
GtkAppChooserDialogPrivate);
|
||||
|
||||
/* we can't override the class signal handler here, as it's a RUN_LAST;
|
||||
* we want our signal handler instead to be executed before any user code.
|
||||
*/
|
||||
g_signal_connect (self, "response",
|
||||
G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
set_parent_and_flags (GtkWidget *dialog,
|
||||
GtkWindow *parent,
|
||||
GtkDialogFlags flags)
|
||||
{
|
||||
if (parent != NULL)
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
|
||||
|
||||
if (flags & GTK_DIALOG_MODAL)
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
|
||||
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_dialog_new:
|
||||
* @parent: (allow-none): a #GtkWindow, or %NULL
|
||||
* @flags: flags for this dialog
|
||||
* @file: a #GFile
|
||||
*
|
||||
* Creates a new #GtkAppChooserDialog for the provided #GFile,
|
||||
* to allow the user to select an application for it.
|
||||
*
|
||||
* Returns: a newly created #GtkAppChooserDialog
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_app_chooser_dialog_new (GtkWindow *parent,
|
||||
GtkDialogFlags flags,
|
||||
GFile *file)
|
||||
{
|
||||
GtkWidget *retval;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
|
||||
"gfile", file,
|
||||
NULL);
|
||||
|
||||
set_parent_and_flags (retval, parent, flags);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_dialog_new_for_content_type:
|
||||
* @parent: (allow-none): a #GtkWindow, or %NULL
|
||||
* @flags: flags for this dialog
|
||||
* @content_type: a content type string
|
||||
*
|
||||
* Creates a new #GtkAppChooserDialog for the provided content type,
|
||||
* to allow the user to select an application for it.
|
||||
*
|
||||
* Returns: a newly created #GtkAppChooserDialog
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_app_chooser_dialog_new_for_content_type (GtkWindow *parent,
|
||||
GtkDialogFlags flags,
|
||||
const gchar *content_type)
|
||||
{
|
||||
GtkWidget *retval;
|
||||
|
||||
g_return_val_if_fail (content_type != NULL, NULL);
|
||||
|
||||
retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
|
||||
"content-type", content_type,
|
||||
NULL);
|
||||
|
||||
set_parent_and_flags (retval, parent, flags);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_app_chooser_dialog_get_widget:
|
||||
* @self: a #GtkAppChooserDialog
|
||||
*
|
||||
* Returns the #GtkAppChooserWidget of this dialog.
|
||||
*
|
||||
* Returns: (transfer none): the #GtkAppChooserWidget of @self
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
|
||||
|
||||
return self->priv->app_chooser_widget;
|
||||
}
|
73
gtk/gtkappchooserdialog.h
Normal file
73
gtk/gtkappchooserdialog.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* gtkappchooserdialog.h: an app-chooser dialog
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Dave Camp <dave@novell.com>
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
* Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_DIALOG_H__
|
||||
#define __GTK_APP_CHOOSER_DIALOG_H__
|
||||
|
||||
#include <gtk/gtkdialog.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER_DIALOG (gtk_app_chooser_dialog_get_type ())
|
||||
#define GTK_APP_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_APP_CHOOSER_DIALOG, GtkAppChooserDialog))
|
||||
#define GTK_APP_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_APP_CHOOSER_DIALOG, GtkAppChooserDialogClass))
|
||||
#define GTK_IS_APP_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_APP_CHOOSER_DIALOG))
|
||||
#define GTK_IS_APP_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_APP_CHOOSER_DIALOG))
|
||||
#define GTK_APP_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_APP_CHOOSER_DIALOG, GtkAppChooserDialogClass))
|
||||
|
||||
typedef struct _GtkAppChooserDialog GtkAppChooserDialog;
|
||||
typedef struct _GtkAppChooserDialogClass GtkAppChooserDialogClass;
|
||||
typedef struct _GtkAppChooserDialogPrivate GtkAppChooserDialogPrivate;
|
||||
|
||||
struct _GtkAppChooserDialog {
|
||||
GtkDialog parent;
|
||||
|
||||
/*< private >*/
|
||||
GtkAppChooserDialogPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserDialogClass {
|
||||
GtkDialogClass parent_class;
|
||||
|
||||
/* padding for future class expansion */
|
||||
gpointer padding[16];
|
||||
};
|
||||
|
||||
GType gtk_app_chooser_dialog_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gtk_app_chooser_dialog_new (GtkWindow *parent,
|
||||
GtkDialogFlags flags,
|
||||
GFile *file);
|
||||
GtkWidget * gtk_app_chooser_dialog_new_for_content_type (GtkWindow *parent,
|
||||
GtkDialogFlags flags,
|
||||
const gchar *content_type);
|
||||
|
||||
GtkWidget * gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self);
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_DIALOG_H__ */
|
59
gtk/gtkappchoosermodule.c
Normal file
59
gtk/gtkappchoosermodule.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* gtkappchoosermodule.c: an extension point for online integration
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchoosermodule.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "gtkappchooseronline.h"
|
||||
|
||||
#ifdef ENABLE_PACKAGEKIT
|
||||
#include "gtkappchooseronlinepk.h"
|
||||
#endif
|
||||
|
||||
G_LOCK_DEFINE_STATIC (registered_ep);
|
||||
|
||||
void
|
||||
_gtk_app_chooser_module_ensure (void)
|
||||
{
|
||||
static gboolean registered_ep = FALSE;
|
||||
GIOExtensionPoint *ep;
|
||||
|
||||
G_LOCK (registered_ep);
|
||||
|
||||
if (!registered_ep)
|
||||
{
|
||||
registered_ep = TRUE;
|
||||
|
||||
ep = g_io_extension_point_register ("gtkappchooser-online");
|
||||
g_io_extension_point_set_required_type (ep, GTK_TYPE_APP_CHOOSER_ONLINE);
|
||||
|
||||
#ifdef ENABLE_PACKAGEKIT
|
||||
_gtk_app_chooser_online_pk_get_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
G_UNLOCK (registered_ep);
|
||||
}
|
35
gtk/gtkappchoosermodule.h
Normal file
35
gtk/gtkappchoosermodule.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gtkappchoosermodule.h: an extension point for online integration
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_MODULE_H__
|
||||
#define __GTK_APP_CHOOSER_MODULE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void _gtk_app_chooser_module_ensure (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_MODULE_H__ */
|
106
gtk/gtkappchooseronline.c
Normal file
106
gtk/gtkappchooseronline.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* gtkappchooseronline.h: an extension point for online integration
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchooseronline.h"
|
||||
|
||||
#include "gtkappchoosermodule.h"
|
||||
#include "gtkintl.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define gtk_app_chooser_online_get_type _gtk_app_chooser_online_get_type
|
||||
static void gtk_app_chooser_online_default_init (GtkAppChooserOnlineInterface *iface);
|
||||
G_DEFINE_INTERFACE_WITH_CODE (GtkAppChooserOnline, gtk_app_chooser_online, G_TYPE_OBJECT,
|
||||
g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_ASYNC_INITABLE);)
|
||||
|
||||
static void
|
||||
gtk_app_chooser_online_default_init (GtkAppChooserOnlineInterface *iface)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
GtkAppChooserOnline *
|
||||
gtk_app_chooser_online_get_default_finish (GObject *source,
|
||||
GAsyncResult *result)
|
||||
{
|
||||
GtkAppChooserOnline *retval;
|
||||
|
||||
retval = GTK_APP_CHOOSER_ONLINE (g_async_initable_new_finish (G_ASYNC_INITABLE (source),
|
||||
result, NULL));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_app_chooser_online_get_default_async (GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GIOExtensionPoint *ep;
|
||||
GIOExtension *extension;
|
||||
GList *extensions;
|
||||
|
||||
_gtk_app_chooser_module_ensure ();
|
||||
|
||||
ep = g_io_extension_point_lookup ("gtkappchooser-online");
|
||||
extensions = g_io_extension_point_get_extensions (ep);
|
||||
|
||||
if (extensions != NULL)
|
||||
{
|
||||
/* pick the first */
|
||||
extension = extensions->data;
|
||||
g_async_initable_new_async (g_io_extension_get_type (extension), G_PRIORITY_DEFAULT,
|
||||
NULL, callback, user_data, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_app_chooser_online_search_for_mimetype_async (GtkAppChooserOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlineInterface *iface;
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self));
|
||||
|
||||
iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
|
||||
|
||||
(* iface->search_for_mimetype_async) (self, content_type, parent, callback, user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_app_chooser_online_search_for_mimetype_finish (GtkAppChooserOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GtkAppChooserOnlineInterface *iface;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self), FALSE);
|
||||
|
||||
iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
|
||||
|
||||
return ((* iface->search_for_mimetype_finish) (self, res, error));
|
||||
}
|
73
gtk/gtkappchooseronline.h
Normal file
73
gtk/gtkappchooseronline.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* gtkappchooseronline.h: an extension point for online integration
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_ONLINE_H__
|
||||
#define __GTK_APP_CHOOSER_ONLINE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER_ONLINE (_gtk_app_chooser_online_get_type ())
|
||||
#define GTK_APP_CHOOSER_ONLINE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_APP_CHOOSER_ONLINE, GtkAppChooserOnline))
|
||||
#define GTK_IS_APP_CHOOSER_ONLINE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_APP_CHOOSER_ONLINE))
|
||||
#define GTK_APP_CHOOSER_ONLINE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_APP_CHOOSER_ONLINE, GtkAppChooserOnlineInterface))
|
||||
|
||||
typedef struct _GtkAppChooserOnline GtkAppChooserOnline;
|
||||
typedef struct _GtkAppChooserOnlineInterface GtkAppChooserOnlineInterface;
|
||||
|
||||
struct _GtkAppChooserOnlineInterface {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
/* Methods */
|
||||
void (*search_for_mimetype_async) (GtkAppChooserOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean (*search_for_mimetype_finish) (GtkAppChooserOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
};
|
||||
|
||||
GType _gtk_app_chooser_online_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gtk_app_chooser_online_get_default_async (GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
GtkAppChooserOnline * gtk_app_chooser_online_get_default_finish (GObject *source,
|
||||
GAsyncResult *result);
|
||||
|
||||
void gtk_app_chooser_online_search_for_mimetype_async (GtkAppChooserOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean gtk_app_chooser_online_search_for_mimetype_finish (GtkAppChooserOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_ONLINE_H__ */
|
263
gtk/gtkappchooseronlinepk.c
Normal file
263
gtk/gtkappchooseronlinepk.c
Normal file
@ -0,0 +1,263 @@
|
||||
/*
|
||||
* gtkappchooseronlinepk.c: packagekit module for app-chooser
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkappchooseronlinepk.h"
|
||||
|
||||
#include "gtkappchooseronline.h"
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
#include "x11/gdkx.h"
|
||||
#endif
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define gtk_app_chooser_online_pk_get_type _gtk_app_chooser_online_pk_get_type
|
||||
static void app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface);
|
||||
static void app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserOnlinePk, gtk_app_chooser_online_pk,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
||||
app_chooser_online_pk_async_initable_init)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER_ONLINE,
|
||||
app_chooser_online_iface_init)
|
||||
g_io_extension_point_implement ("gtkappchooser-online",
|
||||
g_define_type_id,
|
||||
"packagekit", 10));
|
||||
|
||||
struct _GtkAppChooserOnlinePkPrivate {
|
||||
GSimpleAsyncResult *init_result;
|
||||
guint watch_id;
|
||||
|
||||
GDBusProxy *proxy;
|
||||
GSimpleAsyncResult *result;
|
||||
GtkWindow *parent;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_app_chooser_online_pk_dispose (GObject *obj)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
|
||||
|
||||
g_clear_object (&self->priv->result);
|
||||
g_clear_object (&self->priv->proxy);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_online_pk_parent_class)->dispose (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_online_pk_class_init (GtkAppChooserOnlinePkClass *klass)
|
||||
{
|
||||
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
||||
|
||||
oclass->dispose = gtk_app_chooser_online_pk_dispose;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GtkAppChooserOnlinePkPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_online_pk_init (GtkAppChooserOnlinePk *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_ONLINE_PK,
|
||||
GtkAppChooserOnlinePkPrivate);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pk_search_mime_finish (GtkAppChooserOnline *obj,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
|
||||
return !g_simple_async_result_propagate_error (simple, error);
|
||||
}
|
||||
|
||||
static void
|
||||
install_mime_types_ready_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = user_data;
|
||||
GDBusProxy *proxy = G_DBUS_PROXY (source);
|
||||
GError *error = NULL;
|
||||
GVariant *variant;
|
||||
|
||||
variant = g_dbus_proxy_call_finish (proxy, res, &error);
|
||||
|
||||
if (variant == NULL)
|
||||
{
|
||||
/* don't show errors if the user cancelled the installation explicitely
|
||||
* or if PK wasn't able to find any apps
|
||||
*/
|
||||
if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Cancelled") != 0 &&
|
||||
g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.NoPackagesFound") != 0)
|
||||
g_simple_async_result_set_from_error (self->priv->result, error);
|
||||
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_simple_async_result_complete (self->priv->result);
|
||||
}
|
||||
|
||||
static void
|
||||
pk_search_mime_async (GtkAppChooserOnline *obj,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
|
||||
guint xid = 0;
|
||||
GdkWindow *window;
|
||||
const gchar *mime_types[2];
|
||||
|
||||
self->priv->result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback, user_data,
|
||||
gtk_app_chooser_online_search_for_mimetype_async);
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
window = gtk_widget_get_window (GTK_WIDGET (parent));
|
||||
xid = GDK_WINDOW_XID (window);
|
||||
#endif
|
||||
|
||||
mime_types[0] = content_type;
|
||||
mime_types[1] = NULL;
|
||||
|
||||
g_dbus_proxy_call (self->priv->proxy,
|
||||
"InstallMimeTypes",
|
||||
g_variant_new ("(u^ass)",
|
||||
xid,
|
||||
mime_types,
|
||||
"hide-confirm-search"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
G_MAXINT, /* no timeout */
|
||||
NULL,
|
||||
install_mime_types_ready_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface)
|
||||
{
|
||||
iface->search_for_mimetype_async = pk_search_mime_async;
|
||||
iface->search_for_mimetype_finish = pk_search_mime_finish;
|
||||
}
|
||||
|
||||
static void
|
||||
pk_proxy_created_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = user_data;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
proxy = g_dbus_proxy_new_finish (result, NULL);
|
||||
|
||||
if (proxy == NULL)
|
||||
{
|
||||
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, TRUE);
|
||||
self->priv->proxy = proxy;
|
||||
}
|
||||
|
||||
g_simple_async_result_complete (self->priv->init_result);
|
||||
g_clear_object (&self->priv->init_result);
|
||||
}
|
||||
|
||||
static void
|
||||
pk_appeared_cb (GDBusConnection *conn,
|
||||
const gchar *name,
|
||||
const gchar *owner,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = user_data;
|
||||
|
||||
/* create the proxy */
|
||||
g_dbus_proxy_new (conn, 0, NULL,
|
||||
"org.freedesktop.PackageKit",
|
||||
"/org/freedesktop/PackageKit",
|
||||
"org.freedesktop.PackageKit.Modify",
|
||||
NULL,
|
||||
pk_proxy_created_cb,
|
||||
self);
|
||||
|
||||
g_bus_unwatch_name (self->priv->watch_id);
|
||||
}
|
||||
|
||||
static void
|
||||
pk_vanished_cb (GDBusConnection *conn,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = user_data;
|
||||
|
||||
/* just return */
|
||||
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
|
||||
g_simple_async_result_complete (self->priv->init_result);
|
||||
|
||||
g_bus_unwatch_name (self->priv->watch_id);
|
||||
|
||||
g_clear_object (&self->priv->init_result);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
app_chooser_online_pk_init_finish (GAsyncInitable *init,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res));
|
||||
}
|
||||
|
||||
static void
|
||||
app_chooser_online_pk_init_async (GAsyncInitable *init,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (init);
|
||||
|
||||
self->priv->init_result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback, user_data,
|
||||
gtk_app_chooser_online_get_default_async);
|
||||
|
||||
self->priv->watch_id =
|
||||
g_bus_watch_name (G_BUS_TYPE_SESSION,
|
||||
"org.freedesktop.PackageKit",
|
||||
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||
pk_appeared_cb,
|
||||
pk_vanished_cb,
|
||||
self,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface)
|
||||
{
|
||||
iface->init_async = app_chooser_online_pk_init_async;
|
||||
iface->init_finish = app_chooser_online_pk_init_finish;
|
||||
}
|
53
gtk/gtkappchooseronlinepk.h
Normal file
53
gtk/gtkappchooseronlinepk.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* gtkappchooseronlinepk.h: an extension point for online integration
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_ONLINE_PK_H__
|
||||
#define __GTK_APP_CHOOSER_ONLINE_PK_H__
|
||||
|
||||
#include <gtk/gtkappchooseronline.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER_ONLINE_PK (_gtk_app_chooser_online_pk_get_type ())
|
||||
#define GTK_APP_CHOOSER_ONLINE_PK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_APP_CHOOSER_ONLINE_PK, GtkAppChooserOnlinePk))
|
||||
#define GTK_APP_CHOOSER_ONLINE_PK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_APP_CHOOSER_ONLINE_PK, GtkAppChooserOnlinePkClass))
|
||||
#define GTK_IS_APP_CHOOSER_ONLINE_PK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_APP_CHOOSER_ONLINE_PK))
|
||||
#define GTK_IS_APP_CHOOSER_ONLINE_PK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_APP_CHOOSER_ONLINE_PK))
|
||||
#define GTK_APP_CHOOSER_ONLINE_PK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_APP_CHOOSER_ONLINE_PK, GtkAppChooserOnlinePkClass))
|
||||
|
||||
typedef struct _GtkAppChooserOnlinePk GtkAppChooserOnlinePk;
|
||||
typedef struct _GtkAppChooserOnlinePkClass GtkAppChooserOnlinePkClass;
|
||||
typedef struct _GtkAppChooserOnlinePkPrivate GtkAppChooserOnlinePkPrivate;
|
||||
|
||||
struct _GtkAppChooserOnlinePk {
|
||||
GObject parent;
|
||||
|
||||
GtkAppChooserOnlinePkPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserOnlinePkClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType _gtk_app_chooser_online_pk_get_type (void);
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_ONLINE_PK_H__ */
|
45
gtk/gtkappchooserprivate.h
Normal file
45
gtk/gtkappchooserprivate.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* gtkappchooserprivate.h: app-chooser interface
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_PRIVATE_H__
|
||||
#define __GTK_APP_CHOOSER_PRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "gtkappchooser.h"
|
||||
#include "gtkappchooserwidget.h"
|
||||
|
||||
typedef struct _GtkAppChooserIface GtkAppChooserIface;
|
||||
typedef GtkAppChooserIface GtkAppChooserInterface;
|
||||
|
||||
#define GTK_APP_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_APP_CHOOSER, GtkAppChooserIface))
|
||||
|
||||
struct _GtkAppChooserIface {
|
||||
GTypeInterface base_iface;
|
||||
|
||||
GAppInfo * (* get_app_info) (GtkAppChooser *object);
|
||||
void (* refresh) (GtkAppChooser *object);
|
||||
};
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_PRIVATE_H__ */
|
1503
gtk/gtkappchooserwidget.c
Normal file
1503
gtk/gtkappchooserwidget.c
Normal file
File diff suppressed because it is too large
Load Diff
101
gtk/gtkappchooserwidget.h
Normal file
101
gtk/gtkappchooserwidget.h
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* gtkappchooserwidget.h: an app-chooser widget
|
||||
*
|
||||
* 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
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Dave Camp <dave@novell.com>
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
* Cosimo Cecchi <ccecchi@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __GTK_APP_CHOOSER_WIDGET_H__
|
||||
#define __GTK_APP_CHOOSER_WIDGET_H__
|
||||
|
||||
#include <gtk/gtkbox.h>
|
||||
#include <gtk/gtkmenu.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define GTK_TYPE_APP_CHOOSER_WIDGET (gtk_app_chooser_widget_get_type ())
|
||||
#define GTK_APP_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_APP_CHOOSER_WIDGET, GtkAppChooserWidget))
|
||||
#define GTK_APP_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_APP_CHOOSER_WIDGET, GtkAppChooserWidgetClass))
|
||||
#define GTK_IS_APP_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_APP_CHOOSER_WIDGET))
|
||||
#define GTK_IS_APP_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_APP_CHOOSER_WIDGET))
|
||||
#define GTK_APP_CHOOSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_APP_CHOOSER_WIDGET, GtkAppChooserWidgetClass))
|
||||
|
||||
typedef struct _GtkAppChooserWidget GtkAppChooserWidget;
|
||||
typedef struct _GtkAppChooserWidgetClass GtkAppChooserWidgetClass;
|
||||
typedef struct _GtkAppChooserWidgetPrivate GtkAppChooserWidgetPrivate;
|
||||
|
||||
struct _GtkAppChooserWidget {
|
||||
GtkBox parent;
|
||||
|
||||
/*< private >*/
|
||||
GtkAppChooserWidgetPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserWidgetClass {
|
||||
GtkBoxClass parent_class;
|
||||
|
||||
void (* application_selected) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
|
||||
void (* application_activated) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
|
||||
void (* populate_popup) (GtkAppChooserWidget *self,
|
||||
GtkMenu *menu,
|
||||
GAppInfo *app_info);
|
||||
|
||||
/* padding for future class expansion */
|
||||
gpointer padding[16];
|
||||
};
|
||||
|
||||
GType gtk_app_chooser_widget_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget * gtk_app_chooser_widget_new (const gchar *content_type);
|
||||
|
||||
void gtk_app_chooser_widget_set_show_default (GtkAppChooserWidget *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_widget_get_show_default (GtkAppChooserWidget *self);
|
||||
|
||||
void gtk_app_chooser_widget_set_show_recommended (GtkAppChooserWidget *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_widget_get_show_recommended (GtkAppChooserWidget *self);
|
||||
|
||||
void gtk_app_chooser_widget_set_show_fallback (GtkAppChooserWidget *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_widget_get_show_fallback (GtkAppChooserWidget *self);
|
||||
|
||||
void gtk_app_chooser_widget_set_show_other (GtkAppChooserWidget *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_widget_get_show_other (GtkAppChooserWidget *self);
|
||||
|
||||
void gtk_app_chooser_widget_set_show_all (GtkAppChooserWidget *self,
|
||||
gboolean setting);
|
||||
gboolean gtk_app_chooser_widget_get_show_all (GtkAppChooserWidget *self);
|
||||
|
||||
void gtk_app_chooser_widget_set_default_text (GtkAppChooserWidget *self,
|
||||
const gchar *text);
|
||||
const gchar * gtk_app_chooser_widget_get_default_text (GtkAppChooserWidget *self);
|
||||
|
||||
#endif /* __GTK_APP_CHOOSER_WIDGET_H__ */
|
@ -557,7 +557,6 @@ typedef enum
|
||||
GTK_SCROLL_NATURAL
|
||||
} GtkScrollablePolicy;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
|
||||
print-editor \
|
||||
testaccel \
|
||||
testadjustsize \
|
||||
testappchooser \
|
||||
testappchooserbutton \
|
||||
testassistant \
|
||||
testbbox \
|
||||
testbuttons \
|
||||
@ -154,6 +156,8 @@ testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
|
||||
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
|
||||
testoffscreen_DEPENDENCIES = $(TEST_DEPS)
|
||||
testoffscreenwindow_DEPENDENCIES = $(TEST_DEPS)
|
||||
testappchooser_DEPENDENCIES = $(TEST_DEPS)
|
||||
testappchooserbutton_DEPENDENCIES = $(TEST_DEPS)
|
||||
testorientable_DEPENDENCIES = $(TEST_DEPS)
|
||||
testprint_DEPENDENCIES = $(TEST_DEPS)
|
||||
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
|
||||
@ -227,6 +231,8 @@ testnotebookdnd_LDADD = $(LDADDS)
|
||||
testnouiprint_LDADD = $(LDADDS)
|
||||
testoffscreen_LDADD = $(LDADDS)
|
||||
testoffscreenwindow_LDADD = $(LDADDS)
|
||||
testappchooser_LDADD = $(LDADDS)
|
||||
testappchooserbutton_LDADD = $(LDADDS)
|
||||
testorientable_LDADD = $(LDADDS)
|
||||
testprint_LDADD = $(LDADDS)
|
||||
testrecentchooser_LDADD = $(LDADDS)
|
||||
@ -378,6 +384,12 @@ testoffscreen_SOURCES = \
|
||||
testoffscreenwindow_SOURCES = \
|
||||
testoffscreenwindow.c
|
||||
|
||||
testappchooser_SOURCES = \
|
||||
testappchooser.c
|
||||
|
||||
testappchooserbutton_SOURCES = \
|
||||
testappchooserbutton.c
|
||||
|
||||
testwindows_SOURCES = \
|
||||
testwindows.c
|
||||
|
||||
|
218
tests/testappchooser.c
Normal file
218
tests/testappchooser.c
Normal file
@ -0,0 +1,218 @@
|
||||
/* testappchooser.c
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
* Authors: Cosimo Cecchi
|
||||
*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static GtkWidget *toplevel;
|
||||
static GFile *file;
|
||||
static GtkWidget *grid, *file_l, *open;
|
||||
static GtkWidget *radio_file, *radio_content, *dialog;
|
||||
static GtkWidget *app_chooser_widget;
|
||||
static GtkWidget *recommended, *fallback, *other, *all;
|
||||
|
||||
static void
|
||||
dialog_response (GtkDialog *d,
|
||||
gint response_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GAppInfo *app_info;
|
||||
const gchar *name;
|
||||
|
||||
g_print ("Response: %d\n", response_id);
|
||||
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
{
|
||||
app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (d));
|
||||
name = g_app_info_get_name (app_info);
|
||||
g_print ("Application selected: %s\n", name);
|
||||
|
||||
g_object_unref (app_info);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (d));
|
||||
dialog = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
bind_props (void)
|
||||
{
|
||||
g_object_bind_property (recommended, "active",
|
||||
app_chooser_widget, "show-recommended",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (fallback, "active",
|
||||
app_chooser_widget, "show-fallback",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (other, "active",
|
||||
app_chooser_widget, "show-other",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
g_object_bind_property (all, "active",
|
||||
app_chooser_widget, "show-all",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_dialog (void)
|
||||
{
|
||||
gboolean use_file = FALSE;
|
||||
gchar *content_type = NULL;
|
||||
|
||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
|
||||
use_file = TRUE;
|
||||
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content)))
|
||||
use_file = FALSE;
|
||||
|
||||
if (use_file)
|
||||
{
|
||||
dialog = gtk_app_chooser_dialog_new (GTK_WINDOW (toplevel), 0, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
GFileInfo *info;
|
||||
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
||||
0, NULL, NULL);
|
||||
content_type = g_strdup (g_file_info_get_content_type (info));
|
||||
|
||||
g_object_unref (info);
|
||||
|
||||
dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (toplevel),
|
||||
0, content_type);
|
||||
}
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (dialog_response), NULL);
|
||||
|
||||
g_free (content_type);
|
||||
|
||||
app_chooser_widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
|
||||
bind_props ();
|
||||
}
|
||||
|
||||
static void
|
||||
display_dialog (void)
|
||||
{
|
||||
if (dialog == NULL)
|
||||
prepare_dialog ();
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
button_clicked (GtkButton *b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *w;
|
||||
gchar *path;
|
||||
|
||||
w = gtk_file_chooser_dialog_new ("Select file",
|
||||
GTK_WINDOW (toplevel),
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (w));
|
||||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (w));
|
||||
path = g_file_get_path (file);
|
||||
gtk_button_set_label (GTK_BUTTON (file_l), path);
|
||||
|
||||
gtk_widget_destroy (w);
|
||||
|
||||
gtk_widget_set_sensitive (open, TRUE);
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GtkWidget *w1;
|
||||
gchar *path;
|
||||
|
||||
g_type_init ();
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
|
||||
grid = gtk_grid_new ();
|
||||
|
||||
w1 = gtk_label_new ("File:");
|
||||
gtk_widget_set_halign (w1, GTK_ALIGN_START);
|
||||
gtk_grid_attach (GTK_GRID (grid),
|
||||
w1, 0, 0, 1, 1);
|
||||
|
||||
file_l = gtk_button_new ();
|
||||
path = g_build_filename (g_get_current_dir (), "apple-red.png", NULL);
|
||||
file = g_file_new_for_path (path);
|
||||
gtk_button_set_label (GTK_BUTTON (file_l), path);
|
||||
g_free (path);
|
||||
|
||||
gtk_widget_set_halign (file_l, GTK_ALIGN_START);
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), file_l,
|
||||
w1, GTK_POS_RIGHT, 3, 1);
|
||||
g_signal_connect (file_l, "clicked",
|
||||
G_CALLBACK (button_clicked), NULL);
|
||||
|
||||
radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile");
|
||||
radio_content = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
|
||||
"Use content type");
|
||||
|
||||
gtk_grid_attach (GTK_GRID (grid), radio_file,
|
||||
0, 1, 1, 1);
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), radio_content,
|
||||
radio_file, GTK_POS_BOTTOM, 1, 1);
|
||||
|
||||
open = gtk_button_new_with_label ("Trigger App Chooser dialog");
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), open,
|
||||
radio_content, GTK_POS_BOTTOM, 1, 1);
|
||||
|
||||
recommended = gtk_check_button_new_with_label ("Show recommended");
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), recommended,
|
||||
open, GTK_POS_BOTTOM, 1, 1);
|
||||
g_object_set (recommended, "active", TRUE, NULL);
|
||||
|
||||
fallback = gtk_check_button_new_with_label ("Show fallback");
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), fallback,
|
||||
recommended, GTK_POS_RIGHT, 1, 1);
|
||||
|
||||
other = gtk_check_button_new_with_label ("Show other");
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), other,
|
||||
fallback, GTK_POS_RIGHT, 1, 1);
|
||||
|
||||
all = gtk_check_button_new_with_label ("Show all");
|
||||
gtk_grid_attach_next_to (GTK_GRID (grid), all,
|
||||
other, GTK_POS_RIGHT, 1, 1);
|
||||
|
||||
prepare_dialog ();
|
||||
g_signal_connect (open, "clicked",
|
||||
G_CALLBACK (display_dialog), NULL);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (toplevel), grid);
|
||||
|
||||
gtk_widget_show_all (toplevel);
|
||||
g_signal_connect (toplevel, "delete-event",
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
133
tests/testappchooserbutton.c
Normal file
133
tests/testappchooserbutton.c
Normal file
@ -0,0 +1,133 @@
|
||||
/* testappchooserbutton.c
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
* Authors: Cosimo Cecchi
|
||||
*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define CUSTOM_ITEM "custom-item"
|
||||
|
||||
static GtkWidget *toplevel, *combobox, *box;
|
||||
static GtkWidget *sel_image, *sel_name;
|
||||
|
||||
static void
|
||||
combo_changed_cb (GtkComboBox *cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
GAppInfo *app_info;
|
||||
|
||||
app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));
|
||||
|
||||
if (app_info == NULL)
|
||||
return;
|
||||
|
||||
gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
|
||||
GTK_ICON_SIZE_DIALOG);
|
||||
gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));
|
||||
|
||||
g_object_unref (app_info);
|
||||
}
|
||||
|
||||
static void
|
||||
special_item_activated_cb (GtkAppChooserButton *b,
|
||||
const gchar *item_name,
|
||||
gpointer user_data)
|
||||
{
|
||||
gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_themed_icon_new ("face-smile"),
|
||||
GTK_ICON_SIZE_DIALOG);
|
||||
gtk_label_set_text (GTK_LABEL (sel_name), "Special Item");
|
||||
}
|
||||
|
||||
static void
|
||||
action_cb (GtkAppChooserButton *b,
|
||||
const gchar *item_name,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("Activated custom item %s\n", item_name);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
GtkWidget *w;
|
||||
|
||||
g_type_init ();
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
||||
gtk_container_add (GTK_CONTAINER (toplevel), box);
|
||||
|
||||
combobox = gtk_app_chooser_button_new ("image/jpeg");
|
||||
gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);
|
||||
|
||||
g_signal_connect (combobox, "changed",
|
||||
G_CALLBACK (combo_changed_cb), NULL);
|
||||
|
||||
w = gtk_label_new (NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
|
||||
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
|
||||
|
||||
w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
||||
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
|
||||
|
||||
sel_image = gtk_image_new ();
|
||||
gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
|
||||
sel_name = gtk_label_new (NULL);
|
||||
gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);
|
||||
|
||||
gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
|
||||
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
||||
CUSTOM_ITEM,
|
||||
"Hey, I'm special!",
|
||||
g_themed_icon_new ("face-smile"));
|
||||
|
||||
/* this one will trigger a warning, and will not be added */
|
||||
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
||||
CUSTOM_ITEM,
|
||||
"Hey, I'm fake!",
|
||||
g_themed_icon_new ("face-evil"));
|
||||
|
||||
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
||||
TRUE);
|
||||
|
||||
/* connect to the detailed signal */
|
||||
g_signal_connect (combobox, "custom-item-activated::" CUSTOM_ITEM,
|
||||
G_CALLBACK (special_item_activated_cb), NULL);
|
||||
|
||||
/* connect to the generic signal too */
|
||||
g_signal_connect (combobox, "custom-item-activated",
|
||||
G_CALLBACK (action_cb), NULL);
|
||||
|
||||
/* test refresh on a combo */
|
||||
gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
|
||||
|
||||
gtk_widget_show_all (toplevel);
|
||||
|
||||
g_signal_connect (toplevel, "delete-event",
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user