Merge branch 'master' into treeview-refactor

Conflicts:
	tests/Makefile.am
This commit is contained in:
Tristan Van Berkom 2010-12-02 13:58:02 +09:00
commit 03a72118ad
69 changed files with 12501 additions and 6835 deletions

47
NEWS
View File

@ -1,3 +1,50 @@
Overview of Changes from GTK+ 2.91.4 to 2.91.5
==============================================
* GtkSwitch: a new widget that provides switch-like on/off functionality
* Deprecations and cleanups:
- GtkCallbackMarshal and GtkFunction have been deprecated
- gtk_init_add has been removed
- The ::size-request signal has been removed
- GtkRuler has been removed
* The default value for the GtkBox::fill property has been changed
back to TRUE
* Bugs fixed:
613942 Deprecate GtkRuler, GtkVruler and GtkHRuler
629955 Deprecate / remove gtk_main and gtk_init_add / remove* API
633324 Stop invoking size-request completely
633896 Printing: Use XDG_DOCUMENTS_DIR as the default location...
634474 infinite loop in gtk_icon_view_accessible_set_adjustment
634558 Selecting "Search" should focus text box for keyboard entry
634592 GtkNotebook doesn't expand (in a typical GtkDialog)
634697 gdk: Add XSetting for "gtk-cursor-blink-timeout"
634821 Fix a BadMatch when create an icon pixmap for an ARGB visual
634987 add a switch widget
635175 Leak in gtk_plug_realize
635253 GtkRadioButton constructors don't mark group as "allow-none"
635307 iconcache: Ensure we don't lose data on power loss
635380 gdk_event_apply_filters is unsafe against changes in filter list
635588 clicking URL to be opened freezes the application for 3-5 seconds
635693 Bad pointer grab bug with GtkMenu/GtkComboBox
635879 Change the gdk_rgba_parse() function to be usable from bindings
* Updated translations:
Arabic
British English
Catalan
Czech
German
Hungarian
Indonesian
Norwegian bokmål
Romanian
Thai
Uyghur
Overview of Changes from GTK+ 2.91.3 to 2.91.4
==============================================

View File

@ -10,7 +10,7 @@
m4_define([gtk_major_version], [2])
m4_define([gtk_minor_version], [91])
m4_define([gtk_micro_version], [5])
m4_define([gtk_micro_version], [6])
m4_define([gtk_interface_age], [0])
m4_define([gtk_binary_age],
[m4_eval(100 * gtk_minor_version + gtk_micro_version)])
@ -61,8 +61,8 @@ cflags_set=${CFLAGS+set}
AM_INIT_AUTOMAKE([1.10 no-define -Wno-portability dist-bzip2])
AM_MAINTAINER_MODE([enable])
# Support silent build rules, requires at least automake-1.11. Enable
# by either passing --enable-silent-rules to configure or passing V=0
# Support silent build rules, requires at least automake-1.11. Disable
# by either passing --disable-silent-rules to configure or passing V=1
# to make
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@ -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
##################################################

View File

@ -437,7 +437,26 @@ do_combobox (GtkWidget *do_widget)
gtk_container_remove (GTK_CONTAINER (combo), gtk_bin_get_child (GTK_BIN (combo)));
gtk_container_add (GTK_CONTAINER (combo), entry);
/* A combobox with string IDs */
frame = gtk_frame_new ("String IDs");
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (frame), box);
combo = gtk_combo_box_text_new ();
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "never", "Not visible");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "when-active", "Visible when active");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "always", "Always visible");
gtk_container_add (GTK_CONTAINER (box), combo);
entry = gtk_entry_new ();
g_object_bind_property (combo, "active-id",
entry, "text",
G_BINDING_BIDIRECTIONAL);
gtk_container_add (GTK_CONTAINER (box), entry);
}
if (!gtk_widget_get_visible (window))

View File

@ -322,7 +322,8 @@ HTML_IMAGES = \
$(srcdir)/images/layout-tblr.png \
$(srcdir)/images/layout-tbrl.png \
$(srcdir)/images/window-default.png \
$(srcdir)/images/hello-world.png
$(srcdir)/images/hello-world.png \
$(srcdir)/images/switch.png
# Extra options to supply to gtkdoc-fixref
FIXXREF_OPTIONS=--extra-dir=../gdk/html \

View File

@ -97,6 +97,7 @@
<xi:include href="xml/gtklinkbutton.xml" />
<xi:include href="xml/gtkscalebutton.xml" />
<xi:include href="xml/gtkvolumebutton.xml" />
<xi:include href="xml/gtkswitch.xml" />
</chapter>
<chapter id="NumericEntry">
@ -286,13 +287,6 @@
<xi:include href="xml/gtksocket.xml" />
</chapter>
<chapter id="SpecialObjects">
<title>Special-purpose features</title>
<xi:include href="xml/gtkruler.xml" />
<xi:include href="xml/gtkhruler.xml" />
<xi:include href="xml/gtkvruler.xml" />
</chapter>
<chapter id="RecentDocuments">
<title>Recently Used Documents</title>
<xi:include href="xml/gtkrecentmanager.xml" />
@ -303,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" />

View File

@ -801,6 +801,10 @@ gtk_combo_box_get_active
gtk_combo_box_set_active
gtk_combo_box_get_active_iter
gtk_combo_box_set_active_iter
gtk_combo_box_get_id_column
gtk_combo_box_set_id_column
gtk_combo_box_get_active_id
gtk_combo_box_set_active_id
gtk_combo_box_get_model
gtk_combo_box_set_model
gtk_combo_box_popup_for_device
@ -840,9 +844,12 @@ gtk_combo_box_get_type
GtkComboBoxText
gtk_combo_box_text_new
gtk_combo_box_text_new_with_entry
gtk_combo_box_text_append
gtk_combo_box_text_prepend
gtk_combo_box_text_insert
gtk_combo_box_text_append_text
gtk_combo_box_text_insert_text
gtk_combo_box_text_prepend_text
gtk_combo_box_text_insert_text
gtk_combo_box_text_remove
gtk_combo_box_text_remove_all
gtk_combo_box_text_get_active_text
@ -6382,3 +6389,120 @@ GTK_GRID_GET_CLASS
GtkGridPrivate
gtk_grid_get_type
</SECTION>
<SECTION>
<FILE>gtkswitch</FILE>
GtkSwitch
gtk_switch_new
gtk_switch_set_active
gtk_switch_get_active
<SUBSECTION Standard>
GtkSwitchClass
GTK_TYPE_SWITCH
GTK_SWITCH
GTK_SWITCH_CLASS
GTK_IS_SWITCH
GTK_IS_SWITCH_CLASS
GTK_SWITCH_GET_CLASS
<SUBSECTION Private>
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_set_active_custom_item
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>

View File

@ -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
@ -66,7 +70,6 @@ gtk_handle_box_get_type
gtk_hbox_get_type
gtk_hbutton_box_get_type
gtk_hpaned_get_type
gtk_hruler_get_type
gtk_hscale_get_type
gtk_hscrollbar_get_type
gtk_hseparator_get_type
@ -121,7 +124,6 @@ gtk_recent_chooser_dialog_get_type
gtk_recent_chooser_menu_get_type
gtk_recent_chooser_widget_get_type
gtk_recent_manager_get_type
gtk_ruler_get_type
gtk_scale_button_get_type
gtk_scale_get_type
gtk_scrollable_get_type
@ -137,6 +139,7 @@ gtk_spin_button_get_type
gtk_spinner_get_type
gtk_statusbar_get_type
gtk_status_icon_get_type
gtk_switch_get_type
gtk_style_get_type
gtk_table_get_type
gtk_tearoff_menu_item_get_type
@ -171,7 +174,6 @@ gtk_vbutton_box_get_type
gtk_viewport_get_type
gtk_volume_button_get_type
gtk_vpaned_get_type
gtk_vruler_get_type
gtk_vscale_get_type
gtk_vscrollbar_get_type
gtk_vseparator_get_type

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -30,20 +30,8 @@ toggles the value.
<!-- ##### STRUCT GtkCheckMenuItem ##### -->
<para>
The #GtkCheckMenuItem-struct struct contains the following fields.
(These fields should be considered read-only. They should never be set by
an application.)
<informaltable pgwide="1" frame="none" role="struct">
<tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
<tbody>
<row>
<entry>#guint active;</entry>
<entry>TRUE if the check box is active.</entry>
</row>
</tbody></tgroup></informaltable>
The #GtkCheckMenuItem-struct struct contains only private fields that
should not be directly accessed.
</para>
@ -53,8 +41,8 @@ This signal is emitted when the state of the check box is changed.
</para>
<para>
A signal handler can examine the <structfield>active</structfield>
field of the #GtkCheckMenuItem-struct struct to discover the new state.
A signal handler can use gtk_check_menu_item_get_active()
to discover the new state.
</para>
@checkmenuitem: the object which received the signal.

View File

@ -123,4 +123,7 @@
<link linkend="GtkFileChooserDialog">
<inlinegraphic fileref="filechooser.png" format="PNG"></inlinegraphic>
</link>
<link linkend="GtkSwitch">
<inlinegraphic fileref="switch.png" format="PNG"></inlinegraphic>
</link>
</para>

View File

@ -115,6 +115,7 @@ new_widget_info (const char *name,
else
{
info->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_has_resize_grip (GTK_WINDOW (info->window), FALSE);
info->include_decorations = FALSE;
gtk_widget_show_all (widget);
gtk_container_add (GTK_CONTAINER (info->window), widget);
@ -159,6 +160,26 @@ create_button (void)
return new_widget_info ("button", align, SMALL);
}
static WidgetInfo *
create_switch (void)
{
GtkWidget *widget;
GtkWidget *align;
GtkWidget *sw;
widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
sw = gtk_switch_new ();
gtk_switch_set_active (GTK_SWITCH (sw), TRUE);
gtk_box_pack_start (GTK_BOX (widget), sw, TRUE, TRUE, 0);
sw = gtk_switch_new ();
gtk_box_pack_start (GTK_BOX (widget), sw, TRUE, TRUE, 0);
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_add (GTK_CONTAINER (align), widget);
return new_widget_info ("switch", align, SMALL);
}
static WidgetInfo *
create_toggle_button (void)
{
@ -1095,6 +1116,7 @@ get_all_widgets (void)
retval = g_list_prepend (retval, create_page_setup_dialog ());
retval = g_list_prepend (retval, create_print_dialog ());
retval = g_list_prepend (retval, create_volume_button ());
retval = g_list_prepend (retval, create_switch ());
return retval;
}

View File

@ -60,6 +60,7 @@ gdk_device_get_key
gdk_device_get_mode
gdk_device_get_name
gdk_device_get_n_axes
gdk_device_get_n_keys
gdk_device_get_source
gdk_device_get_state
gdk_device_get_type G_GNUC_CONST
@ -372,6 +373,7 @@ gdk_visual_get_system
gdk_visual_get_type G_GNUC_CONST
gdk_visual_get_visual_type
gdk_visual_type_get_type G_GNUC_CONST
#ifdef GDK_WINDOWING_WIN32
gdk_win32_drawable_get_handle
gdk_win32_handle_table_lookup
gdk_win32_icon_to_pixbuf_libgtk_only
@ -379,6 +381,7 @@ gdk_win32_pixbuf_to_hicon_libgtk_only
gdk_win32_selection_add_targets
gdk_win32_set_modal_dialog_libgtk_only
gdk_win32_window_is_win32
#endif
gdk_window_add_filter
gdk_window_at_pointer
gdk_window_attributes_type_get_type G_GNUC_CONST

View File

@ -115,8 +115,8 @@ parse_rgb_value (const char *str,
/**
* gdk_rgba_parse:
* @spec: the string specifying the color
* @rgba: the #GdkRGBA struct to fill in
* @spec: the string specifying the color
*
* Parses a textual representation of a color, filling in
* the <structfield>red</structfield>, <structfield>green</structfield>,
@ -150,8 +150,8 @@ parse_rgb_value (const char *str,
* Since: 3.0
**/
gboolean
gdk_rgba_parse (const gchar *spec,
GdkRGBA *rgba)
gdk_rgba_parse (GdkRGBA *rgba,
const gchar *spec)
{
gboolean has_alpha;
gdouble r, g, b, a;

View File

@ -48,8 +48,8 @@ struct _GdkRGBA
GdkRGBA * gdk_rgba_copy (GdkRGBA *rgba);
void gdk_rgba_free (GdkRGBA *rgba);
gboolean gdk_rgba_parse (const gchar *spec,
GdkRGBA *rgba);
gboolean gdk_rgba_parse (GdkRGBA *rgba,
const gchar *spec);
guint gdk_rgba_hash (gconstpointer p);
gboolean gdk_rgba_equal (gconstpointer p1,

View File

@ -8,17 +8,17 @@ test_color_parse (void)
GdkRGBA expected;
gboolean res;
res = gdk_rgba_parse ("foo", &color);
res = gdk_rgba_parse (&color, "foo");
g_assert (!res);
res = gdk_rgba_parse ("", &color);
res = gdk_rgba_parse (&color, "");
g_assert (!res);
expected.red = 100/255.;
expected.green = 90/255.;
expected.blue = 80/255.;
expected.alpha = 0.1;
res = gdk_rgba_parse ("rgba(100,90,80,0.1)", &color);
res = gdk_rgba_parse (&color, "rgba(100,90,80,0.1)");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
@ -26,11 +26,11 @@ test_color_parse (void)
expected.green = 0.3;
expected.blue = 0.2;
expected.alpha = 0.1;
res = gdk_rgba_parse ("rgba(40%,30%,20%,0.1)", &color);
res = gdk_rgba_parse (&color, "rgba(40%,30%,20%,0.1)");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
res = gdk_rgba_parse ("rgba( 40 % , 30 % , 20 % , 0.1 )", &color);
res = gdk_rgba_parse (&color, "rgba( 40 % , 30 % , 20 % , 0.1 )");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
@ -38,7 +38,7 @@ test_color_parse (void)
expected.green = 0.0;
expected.blue = 0.0;
expected.alpha = 1.0;
res = gdk_rgba_parse ("red", &color);
res = gdk_rgba_parse (&color, "red");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
@ -46,7 +46,7 @@ test_color_parse (void)
expected.green = 0x8080 / 65535.;
expected.blue = 1.0;
expected.alpha = 1.0;
res = gdk_rgba_parse ("#0080ff", &color);
res = gdk_rgba_parse (&color, "#0080ff");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
}
@ -71,7 +71,7 @@ test_color_to_string (void)
orig = g_strdup (setlocale (LC_ALL, NULL));
res = gdk_rgba_to_string (&rgba);
gdk_rgba_parse (res, &out);
gdk_rgba_parse (&out, res);
g_assert (gdk_rgba_equal (&rgba, &out));
setlocale (LC_ALL, "de_DE.utf-8");

View File

@ -36,54 +36,43 @@
#include <unistd.h>
static char *
get_display_name (GFile *file)
get_display_name (GFile *file,
GFileInfo *info)
{
GFileInfo *info;
char *name, *tmp;
/* This does sync I/O, which isn't ideal.
* It should probably use the NautilusFile machinery
*/
name = NULL;
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
if (info)
{
name = g_strdup (g_file_info_get_display_name (info));
g_object_unref (info);
}
name = g_strdup (g_file_info_get_display_name (info));
if (name == NULL)
{
name = g_file_get_basename (file);
if (!g_utf8_validate (name, -1, NULL))
{
tmp = name;
name =
g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
TRUE);
g_free (tmp);
}
{
tmp = name;
name =
g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
g_free (tmp);
}
}
return name;
}
static GIcon *
get_icon (GFile *file)
get_icon (GFile *file,
GFileInfo *info)
{
GFileInfo *info;
GIcon *icon;
icon = NULL;
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_ICON, 0, NULL, NULL);
if (info)
{
icon = g_file_info_get_icon (info);
if (icon)
g_object_ref (icon);
g_object_unref (info);
g_object_ref (icon);
}
return icon;
@ -99,13 +88,13 @@ gicon_to_string (GIcon *icon)
{
file = g_file_icon_get_file (G_FILE_ICON (icon));
if (file)
return g_file_get_path (file);
return g_file_get_path (file);
}
else if (G_IS_THEMED_ICON (icon))
{
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
if (names)
return g_strdup (names[0]);
return g_strdup (names[0]);
}
else if (G_IS_EMBLEMED_ICON (icon))
{
@ -121,11 +110,11 @@ gicon_to_string (GIcon *icon)
static void
end_startup_notification (GdkDisplay *display,
const char *startup_id)
const char *startup_id)
{
gdk_x11_display_broadcast_startup_message (display, "remove",
"ID", startup_id,
NULL);
"ID", startup_id,
NULL);
}
@ -210,19 +199,19 @@ startup_timeout (void *data)
next = tmp->next;
elapsed =
((((double) now.tv_sec - sn_data->time.tv_sec) * G_USEC_PER_SEC +
(now.tv_usec - sn_data->time.tv_usec))) / 1000.0;
((((double) now.tv_sec - sn_data->time.tv_sec) * G_USEC_PER_SEC +
(now.tv_usec - sn_data->time.tv_usec))) / 1000.0;
if (elapsed >= STARTUP_TIMEOUT_LENGTH)
{
std->contexts = g_slist_remove (std->contexts, sn_data);
end_startup_notification (sn_data->display, sn_data->startup_id);
free_startup_notification_data (sn_data);
}
{
std->contexts = g_slist_remove (std->contexts, sn_data);
end_startup_notification (sn_data->display, sn_data->startup_id);
free_startup_notification_data (sn_data);
}
else
{
min_timeout = MIN (min_timeout, (STARTUP_TIMEOUT_LENGTH - elapsed));
}
{
min_timeout = MIN (min_timeout, (STARTUP_TIMEOUT_LENGTH - elapsed));
}
tmp = next;
}
@ -239,7 +228,7 @@ startup_timeout (void *data)
static void
add_startup_timeout (GdkScreen *screen,
const char *startup_id)
const char *startup_id)
{
StartupTimeoutData *data;
StartupNotificationData *sn_data;
@ -253,7 +242,7 @@ add_startup_timeout (GdkScreen *screen,
data->timeout_id = 0;
g_object_set_data_full (G_OBJECT (screen), "appinfo-startup-data",
data, free_startup_timeout);
data, free_startup_timeout);
}
sn_data = g_new (StartupNotificationData, 1);
@ -265,14 +254,14 @@ add_startup_timeout (GdkScreen *screen,
if (data->timeout_id == 0)
data->timeout_id = g_timeout_add_seconds (STARTUP_TIMEOUT_LENGTH_SECONDS,
startup_timeout, data);
startup_timeout, data);
}
char *
_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GAppInfo *info,
GList *files)
GAppInfo *info,
GList *files)
{
static int sequence = 0;
GdkAppLaunchContextPrivate *priv;
@ -288,6 +277,7 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
GIcon *icon;
guint32 timestamp;
char *startup_id;
GFileInfo *fileinfo;
priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;
@ -307,20 +297,32 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
screen = gdk_display_get_default_screen (display);
}
fileinfo = NULL;
files_count = g_list_length (files);
if (files_count == 0)
description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info));
{
description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info));
}
else if (files_count == 1)
{
gchar *display_name = get_display_name (files->data);
gchar *display_name;
if (g_file_is_native (files->data))
fileinfo = g_file_query_info (files->data,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_ICON,
0, NULL, NULL);
display_name = get_display_name (files->data, fileinfo);
description = g_strdup_printf (_("Opening %s"), display_name);
g_free (display_name);
}
else
description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
"Opening %d Item",
"Opening %d Items",
files_count), files_count);
"Opening %d Item",
"Opening %d Items",
files_count), files_count);
icon_name = NULL;
if (priv->icon_name)
@ -330,18 +332,18 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
icon = NULL;
if (priv->icon != NULL)
icon = g_object_ref (priv->icon);
icon = g_object_ref (priv->icon);
else if (files_count == 1)
icon = get_icon (files->data);
icon = get_icon (files->data, fileinfo);
if (icon == NULL)
{
icon = g_app_info_get_icon (info);
g_object_ref (icon);
}
{
icon = g_app_info_get_icon (info);
g_object_ref (icon);
}
if (icon)
icon_name = gicon_to_string (icon);
icon_name = gicon_to_string (icon);
g_object_unref (icon);
}
@ -353,7 +355,7 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
timestamp = gdk_x11_display_get_user_time (display);
screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen));
if (priv->workspace > -1)
if (priv->workspace > -1)
workspace_str = g_strdup_printf ("%d", priv->workspace);
else
workspace_str = NULL;
@ -364,30 +366,31 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
application_id = NULL;
startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
g_get_prgname (),
(unsigned long)getpid (),
g_get_host_name (),
binary_name,
sequence++,
(unsigned long)timestamp);
g_get_prgname (),
(unsigned long)getpid (),
g_get_host_name (),
binary_name,
sequence++,
(unsigned long)timestamp);
gdk_x11_display_broadcast_startup_message (display, "new",
"ID", startup_id,
"NAME", g_app_info_get_name (info),
"SCREEN", screen_str,
"BIN", binary_name,
"ICON", icon_name,
"DESKTOP", workspace_str,
"DESCRIPTION", description,
"WMCLASS", NULL, /* FIXME */
"APPLICATION_ID", application_id,
NULL);
"ID", startup_id,
"NAME", g_app_info_get_name (info),
"SCREEN", screen_str,
"BIN", binary_name,
"ICON", icon_name,
"DESKTOP", workspace_str,
"DESCRIPTION", description,
"WMCLASS", NULL, /* FIXME */
"APPLICATION_ID", application_id,
NULL);
g_free (description);
g_free (screen_str);
g_free (workspace_str);
g_free (icon_name);
if (fileinfo)
g_object_unref (fileinfo);
add_startup_timeout (screen, startup_id);
@ -396,8 +399,8 @@ _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
void
_gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
_gdk_windowing_launch_failed (GAppLaunchContext *context,
const char *startup_notify_id)
{
GdkAppLaunchContextPrivate *priv;
GdkScreen *screen;
@ -419,22 +422,22 @@ _gdk_windowing_launch_failed (GAppLaunchContext *context,
if (data)
{
for (l = data->contexts; l != NULL; l = l->next)
{
sn_data = l->data;
if (strcmp (startup_notify_id, sn_data->startup_id) == 0)
{
data->contexts = g_slist_remove (data->contexts, sn_data);
end_startup_notification (sn_data->display, sn_data->startup_id);
free_startup_notification_data (sn_data);
break;
}
}
{
sn_data = l->data;
if (strcmp (startup_notify_id, sn_data->startup_id) == 0)
{
data->contexts = g_slist_remove (data->contexts, sn_data);
end_startup_notification (sn_data->display, sn_data->startup_id);
free_startup_notification_data (sn_data);
break;
}
}
if (data->contexts == NULL)
{
g_source_remove (data->timeout_id);
data->timeout_id = 0;
}
{
g_source_remove (data->timeout_id);
data->timeout_id = 0;
}
}
}

View File

@ -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 \
@ -292,6 +296,7 @@ gtk_public_h_sources = \
gtkstatusicon.h \
gtkstock.h \
gtkstyle.h \
gtkswitch.h \
gtktable.h \
gtktearoffmenuitem.h \
gtktestutils.h \
@ -350,6 +355,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 \
@ -374,6 +391,9 @@ gtk_private_h_sources = \
gtkmenuprivate.h \
gtkmnemonichash.h \
gtkmountoperationprivate.h \
gtkappchooserprivate.h \
gtkappchoosermodule.h \
gtkappchooseronline.h \
gtkpango.h \
gtkpathbar.h \
gtkplugprivate.h \
@ -401,7 +421,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 = \
@ -419,7 +440,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 \
@ -569,6 +596,7 @@ gtk_base_c_sources = \
gtkstatusicon.c \
gtkstock.c \
gtkstyle.c \
gtkswitch.c \
gtktable.c \
gtktearoffmenuitem.c \
gtktestutils.c \
@ -622,7 +650,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)

View File

@ -1,5 +1,5 @@
#! /bin/sh
cpp -P -DG_OS_UNIX -DGTK_WINDOWING_X11 ${srcdir:-.}/gtk.symbols | sed -e '/^$/d' -e 's/ G_GNUC.*$//' -e 's/ PRIVATE//' | sort > expected-abi
cpp -P -DG_OS_UNIX -DGDK_WINDOWING_X11 ${srcdir:-.}/gtk.symbols | sed -e '/^$/d' -e 's/ G_GNUC.*$//' -e 's/ PRIVATE//' | sort > expected-abi
nm -D -g --defined-only .libs/libgtk-x11-3.0.so | cut -d ' ' -f 3 | egrep -v '^(__bss_start|_edata|_end)' | sort > actual-abi
diff -u expected-abi actual-abi && rm -f expected-abi actual-abi

View File

@ -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>
@ -174,6 +178,7 @@
#include <gtk/gtkstatusicon.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkstyle.h>
#include <gtk/gtkswitch.h>
#include <gtk/gtktable.h>
#include <gtk/gtktearoffmenuitem.h>
#include <gtk/gtktextbuffer.h>

View File

@ -178,6 +178,35 @@ 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_active_custom_item
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
@ -490,6 +519,7 @@ gtk_color_selection_set_previous_alpha
gtk_color_selection_set_previous_color
gtk_color_selection_set_previous_rgba
gtk_combo_box_get_active
gtk_combo_box_get_active_id
gtk_combo_box_get_active_iter
gtk_combo_box_get_add_tearoffs
gtk_combo_box_get_button_sensitivity
@ -497,6 +527,7 @@ gtk_combo_box_get_column_span_column
gtk_combo_box_get_entry_text_column
gtk_combo_box_get_focus_on_click
gtk_combo_box_get_has_entry
gtk_combo_box_get_id_column
gtk_combo_box_get_model
gtk_combo_box_get_popup_accessible
gtk_combo_box_get_popup_fixed_width
@ -513,24 +544,29 @@ gtk_combo_box_popdown
gtk_combo_box_popup
gtk_combo_box_popup_for_device
gtk_combo_box_set_active
gtk_combo_box_set_active_id
gtk_combo_box_set_active_iter
gtk_combo_box_set_add_tearoffs
gtk_combo_box_set_button_sensitivity
gtk_combo_box_set_column_span_column
gtk_combo_box_set_entry_text_column
gtk_combo_box_set_focus_on_click
gtk_combo_box_set_id_column
gtk_combo_box_set_model
gtk_combo_box_set_popup_fixed_width
gtk_combo_box_set_row_separator_func
gtk_combo_box_set_row_span_column
gtk_combo_box_set_title
gtk_combo_box_set_wrap_width
gtk_combo_box_text_append
gtk_combo_box_text_append_text
gtk_combo_box_text_get_active_text
gtk_combo_box_text_get_type G_GNUC_CONST
gtk_combo_box_text_insert
gtk_combo_box_text_insert_text
gtk_combo_box_text_new
gtk_combo_box_text_new_with_entry
gtk_combo_box_text_prepend
gtk_combo_box_text_prepend_text
gtk_combo_box_text_remove
gtk_combo_box_text_remove_all
@ -1200,9 +1236,11 @@ gtk_info_bar_set_default_response
gtk_info_bar_set_message_type
gtk_info_bar_set_response_sensitive
gtk_init
gtk_init_abi_check
gtk_init_check
#ifdef GDK_WINDOWING_WIN32
gtk_init_abi_check
gtk_init_check_abi_check
#endif
gtk_init_with_args
gtk_invisible_get_screen
gtk_invisible_get_type G_GNUC_CONST
@ -1386,7 +1424,6 @@ gtk_message_dialog_new_with_markup G_GNUC_PRINTF(5,6)
gtk_message_dialog_set_image
gtk_message_dialog_set_markup
gtk_message_type_get_type G_GNUC_CONST
gtk_metric_type_get_type G_GNUC_CONST
gtk_misc_get_alignment
gtk_misc_get_padding
gtk_misc_get_type G_GNUC_CONST
@ -1699,8 +1736,6 @@ gtk_print_operation_set_use_full_page
gtk_print_pages_get_type G_GNUC_CONST
gtk_print_quality_get_type G_GNUC_CONST
gtk_print_run_page_setup_dialog
gtk_print_run_page_setup_dialog
gtk_print_run_page_setup_dialog_async
gtk_print_run_page_setup_dialog_async
gtk_print_settings_copy
gtk_print_settings_foreach
@ -1797,10 +1832,12 @@ gtk_print_unix_dialog_set_manual_capabilities
gtk_print_unix_dialog_set_page_setup
gtk_print_unix_dialog_set_settings
gtk_print_unix_dialog_set_support_selection
#ifdef GDK_WINDOWING_WIN32
gtk_print_win32_devnames_free
gtk_print_win32_devnames_from_printer_name
gtk_print_win32_devnames_from_win32
gtk_print_win32_devnames_to_win32
#endif
gtk_progress_bar_get_ellipsize
gtk_progress_bar_get_fraction
gtk_progress_bar_get_inverted
@ -2236,6 +2273,10 @@ gtk_stock_item_free
gtk_stock_list_ids
gtk_stock_lookup
gtk_stock_set_translate_func
gtk_switch_get_active
gtk_switch_get_type G_GNUC_CONST
gtk_switch_new
gtk_switch_set_active
gtk_style_apply_default_background
gtk_style_attach
gtk_style_copy
@ -3313,7 +3354,9 @@ gtk_widget_trigger_tooltip_query
gtk_widget_unmap
gtk_widget_unparent
gtk_widget_unrealize
#ifdef GDK_WINDOWING_WIN32
gtk_win32_embed_widget_get_type G_GNUC_CONST
#endif
gtk_window_activate_default
gtk_window_activate_focus
gtk_window_activate_key

109
gtk/gtkappchooser.c Normal file
View 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
View 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__ */

784
gtk/gtkappchooserbutton.c Normal file
View File

@ -0,0 +1,784 @@
/*
* 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, iter2;
if (!self->priv->show_dialog_item)
return;
icon = g_themed_icon_new ("application-x-executable");
if (prev_iter == NULL)
gtk_list_store_append (self->priv->store, &iter);
else
gtk_list_store_insert_after (self->priv->store, &iter, prev_iter);
real_insert_separator (self, FALSE, &iter);
iter2 = iter;
gtk_list_store_insert_after (self->priv->store, &iter, &iter2);
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 cycled_recommended;
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
cycled_recommended = FALSE;
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 (cycled_recommended)
{
gtk_list_store_insert_after (self->priv->store, &iter2, &iter);
iter = iter2;
}
else
{
get_first_iter (self->priv->store, &iter);
cycled_recommended = TRUE;
}
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);
}
if (!cycled_recommended)
gtk_app_chooser_button_ensure_dialog_item (self, NULL);
else
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 gboolean
app_chooser_button_iter_from_custom_name (GtkAppChooserButton *self,
const gchar *name,
GtkTreeIter *set_me)
{
GtkTreeIter iter;
gchar *custom_name = NULL;
if (!gtk_tree_model_get_iter_first
(GTK_TREE_MODEL (self->priv->store), &iter))
return FALSE;
do {
gtk_tree_model_get (GTK_TREE_MODEL (self->priv->store), &iter,
COLUMN_NAME, &custom_name,
-1);
if (g_strcmp0 (custom_name, name) == 0)
{
g_free (custom_name);
*set_me = iter;
return TRUE;
}
g_free (custom_name);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->store), &iter));
return FALSE;
}
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_select_custom_item:
* @self: a #GtkAppChooserButton
* @name: the name of the custom item
*
* Selects a custom item previously added with
* gtk_app_chooser_button_append_custom_item().
* Use gtk_app_chooser_refresh() to bring the selection to its initial
* state.
*
* Since: 3.0
*/
void
gtk_app_chooser_button_set_active_custom_item (GtkAppChooserButton *self,
const gchar *name)
{
GtkTreeIter iter;
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
g_return_if_fail (name != NULL);
if (g_hash_table_lookup (self->priv->custom_item_names, name) == NULL ||
!app_chooser_button_iter_from_custom_name (self, name, &iter))
{
g_warning ("Can't find the item named %s in the app chooser.",
name);
return;
}
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &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));
}
}

78
gtk/gtkappchooserbutton.h Normal file
View File

@ -0,0 +1,78 @@
/*
* 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_active_custom_item (GtkAppChooserButton *self,
const gchar *name);
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
View 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
View 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
View 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
View 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
View 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
View 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
View 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;
}

View 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__ */

View 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

File diff suppressed because it is too large Load Diff

101
gtk/gtkappchooserwidget.h Normal file
View 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__ */

View File

@ -164,6 +164,7 @@ static void gtk_assistant_get_child_property (GtkContainer *container,
GParamSpec *pspec);
static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
static GType gtk_assistant_accessible_factory_get_type (void);
static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
@ -2438,27 +2439,59 @@ gtk_assistant_commit (GtkAssistant *assistant)
set_assistant_buttons_state (assistant);
}
static AtkObject *
gtk_assistant_get_accessible (GtkWidget *widget)
{
static gboolean first_time = TRUE;
if (first_time)
{
AtkObjectFactory *factory;
AtkRegistry *registry;
GType derived_type;
GType derived_atk_type;
/*
* Figure out whether accessibility is enabled by looking at the
* type of the accessible object which would be created for
* the parent type of GtkAssistant.
*/
derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
registry = atk_get_default_registry ();
factory = atk_registry_get_factory (registry, derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
atk_registry_set_factory_type (registry,
GTK_TYPE_ASSISTANT,
gtk_assistant_accessible_factory_get_type ());
first_time = FALSE;
}
return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
}
/* accessible implementation */
/* dummy typedefs */
typedef struct _GtkAssistantAccessible GtkAssistantAccessible;
typedef struct _GtkAssistantAccessibleClass GtkAssistantAccessibleClass;
ATK_DEFINE_TYPE (GtkAssistantAccessible, gtk_assistant_accessible, GTK_TYPE_ASSISTANT);
static gint
gtk_assistant_accessible_get_n_children (AtkObject *accessible)
{
GtkAssistant *assistant;
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
if (widget == NULL)
return 0;
assistant = GTK_ASSISTANT (widget);
return g_list_length (assistant->priv->pages) + 1;
return g_list_length (GTK_ASSISTANT (accessible)->priv->pages) + 1;
}
static AtkObject *
gtk_assistant_accessible_ref_child (AtkObject *accessible,
gint index)
@ -2471,7 +2504,7 @@ gtk_assistant_accessible_ref_child (AtkObject *accessible,
const gchar *title;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (!widget)
if (widget == NULL)
return NULL;
assistant = GTK_ASSISTANT (widget);
@ -2504,57 +2537,26 @@ gtk_assistant_accessible_ref_child (AtkObject *accessible,
}
static void
gtk_assistant_accessible_class_init (AtkObjectClass *class)
gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
{
class->get_n_children = gtk_assistant_accessible_get_n_children;
class->ref_child = gtk_assistant_accessible_ref_child;
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
atk_class->ref_child = gtk_assistant_accessible_ref_child;
}
static GType
gtk_assistant_accessible_get_type (void)
static void
gtk_assistant_accessible_init (GtkAssistantAccessible *self)
{
static GType type = 0;
if (!type)
{
/*
* Figure out the size of the class and instance
* we are deriving from
*/
AtkObjectFactory *factory;
GType derived_type;
GTypeQuery query;
GType derived_atk_type;
derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
factory = atk_registry_get_factory (atk_get_default_registry (),
derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
g_type_query (derived_atk_type, &query);
type = g_type_register_static_simple (derived_atk_type,
I_("GtkAssistantAccessible"),
query.class_size,
(GClassInitFunc) gtk_assistant_accessible_class_init,
query.instance_size,
NULL, 0);
}
return type;
}
static AtkObject *
gtk_assistant_accessible_new (GObject *obj)
{
AtkObject *accessible;
/* factory */
typedef AtkObjectFactory GtkAssistantAccessibleFactory;
typedef AtkObjectFactoryClass GtkAssistantAccessibleFactoryClass;
g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
return accessible;
}
G_DEFINE_TYPE (GtkAssistantAccessibleFactory,
gtk_assistant_accessible_factory,
ATK_TYPE_OBJECT_FACTORY);
static GType
gtk_assistant_accessible_factory_get_accessible_type (void)
@ -2565,7 +2567,12 @@ gtk_assistant_accessible_factory_get_accessible_type (void)
static AtkObject*
gtk_assistant_accessible_factory_create_accessible (GObject *obj)
{
return gtk_assistant_accessible_new (obj);
AtkObject *accessible;
accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
return accessible;
}
static void
@ -2575,59 +2582,12 @@ gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
}
static GType
gtk_assistant_accessible_factory_get_type (void)
static void
gtk_assistant_accessible_factory_init (AtkObjectFactory *factory)
{
static GType type = 0;
if (!type)
{
type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
I_("GtkAssistantAccessibleFactory"),
sizeof (AtkObjectFactoryClass),
(GClassInitFunc) gtk_assistant_accessible_factory_class_init,
sizeof (AtkObjectFactory),
NULL, 0);
}
return type;
}
static AtkObject *
gtk_assistant_get_accessible (GtkWidget *widget)
{
static gboolean first_time = TRUE;
if (first_time)
{
AtkObjectFactory *factory;
AtkRegistry *registry;
GType derived_type;
GType derived_atk_type;
/*
* Figure out whether accessibility is enabled by looking at the
* type of the accessible object which would be created for
* the parent type of GtkAssistant.
*/
derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
registry = atk_get_default_registry ();
factory = atk_registry_get_factory (registry,
derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
{
atk_registry_set_factory_type (registry,
GTK_TYPE_ASSISTANT,
gtk_assistant_accessible_factory_get_type ());
}
first_time = FALSE;
}
return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
}
/* buildable implementation */
static GtkBuildableIface *parent_buildable_iface;

View File

@ -1563,7 +1563,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
{
GdkRGBA rgba = { 0 };
if (gdk_rgba_parse (string, &rgba))
if (gdk_rgba_parse (&rgba, string))
g_value_set_boxed (value, &rgba);
else
{

View File

@ -539,7 +539,7 @@ gtk_cell_renderer_set_property (GObject *object,
if (!g_value_get_string (value))
set_cell_bg_color (cell, NULL);
else if (gdk_rgba_parse (g_value_get_string (value), &rgba))
else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
set_cell_bg_color (cell, &rgba);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));

View File

@ -1201,7 +1201,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
if (!g_value_get_string (value))
set_bg_color (celltext, NULL); /* reset to background_set to FALSE */
else if (gdk_rgba_parse (g_value_get_string (value), &rgba))
else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
set_bg_color (celltext, &rgba);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
@ -1216,7 +1216,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
if (!g_value_get_string (value))
set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
else if (gdk_rgba_parse (g_value_get_string (value), &rgba))
else if (gdk_rgba_parse (&rgba, g_value_get_string (value)))
set_fg_color (celltext, &rgba);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));

View File

@ -143,6 +143,8 @@ struct _GtkComboBoxPrivate
gint text_column;
GtkCellRenderer *text_renderer;
gint id_column;
GSList *cells;
guint popup_in_progress : 1;
@ -245,7 +247,9 @@ enum {
PROP_EDITING_CANCELED,
PROP_HAS_ENTRY,
PROP_ENTRY_TEXT_COLUMN,
PROP_POPUP_FIXED_WIDTH
PROP_POPUP_FIXED_WIDTH,
PROP_ID_COLUMN,
PROP_ACTIVE_ID
};
static guint combo_box_signals[LAST_SIGNAL] = {0,};
@ -948,6 +952,38 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
/**
* GtkComboBox:id-column:
*
* The column in the combo box's model that provides string
* IDs for the values in the model, if != -1.
*
* Since: 3.0
*/
g_object_class_install_property (object_class,
PROP_ID_COLUMN,
g_param_spec_int ("id-column",
P_("ID Column"),
P_("The column in the combo box's model that provides "
"string IDs for the values in the model"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
/**
* GtkComboBox:active-id:
*
* The value of the ID column of the active row.
*
* Since: 3.0
*/
g_object_class_install_property (object_class,
PROP_ACTIVE_ID,
g_param_spec_string ("active-id",
P_("Active id"),
P_("The value of the id column "
"for the active row"),
NULL, GTK_PARAM_READWRITE));
/**
* GtkComboBox:popup-fixed-width:
*
@ -1077,6 +1113,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
priv->text_column = -1;
priv->text_renderer = NULL;
priv->id_column = -1;
gtk_combo_box_check_appearance (combo_box);
}
@ -1168,6 +1205,14 @@ gtk_combo_box_set_property (GObject *object,
gtk_combo_box_set_entry_text_column (combo_box, g_value_get_int (value));
break;
case PROP_ID_COLUMN:
gtk_combo_box_set_id_column (combo_box, g_value_get_int (value));
break;
case PROP_ACTIVE_ID:
gtk_combo_box_set_active_id (combo_box, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1245,6 +1290,14 @@ gtk_combo_box_get_property (GObject *object,
g_value_set_int (value, priv->text_column);
break;
case PROP_ID_COLUMN:
g_value_set_int (value, priv->id_column);
break;
case PROP_ACTIVE_ID:
g_value_set_string (value, gtk_combo_box_get_active_id (combo_box));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -4879,6 +4932,7 @@ gtk_combo_box_new_with_model (GtkTreeModel *model)
/**
* gtk_combo_box_new_with_model_and_entry:
* @model: A #GtkTreeModel
*
* Creates a new empty #GtkComboBox with an entry
* and with the model initialized to @model.
@ -5199,6 +5253,8 @@ gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
g_signal_emit (combo_box, combo_box_signals[CHANGED], 0);
g_object_notify (G_OBJECT (combo_box), "active");
if (combo_box->priv->id_column >= 0)
g_object_notify (G_OBJECT (combo_box), "active-id");
}
@ -6587,3 +6643,157 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
if (natural_size)
*natural_size = nat_height;
}
/**
* gtk_combo_box_set_id_column:
* @combo_box: A #GtkComboBox
* @id_column: A column in @model to get string IDs for values from
*
* Sets the model column which @combo_box should use to get string IDs
* for values from. The column @id_column in the model of @combo_box
* must be of type %G_TYPE_STRING.
*
* Since: 3.0
*/
void
gtk_combo_box_set_id_column (GtkComboBox *combo_box,
gint id_column)
{
GtkComboBoxPrivate *priv = combo_box->priv;
GtkTreeModel *model;
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
if (id_column != priv->id_column)
{
model = gtk_combo_box_get_model (combo_box);
g_return_if_fail (id_column >= 0);
g_return_if_fail (model == NULL ||
id_column < gtk_tree_model_get_n_columns (model));
priv->id_column = id_column;
g_object_notify (G_OBJECT (combo_box), "id-column");
g_object_notify (G_OBJECT (combo_box), "active-id");
}
}
/**
* gtk_combo_box_get_id_column:
* @combo_box: A #GtkComboBox
*
* Returns the column which @combo_box is using to get string IDs
* for values from.
*
* Return value: A column in the data source model of @combo_box.
*
* Since: 3.0
*/
gint
gtk_combo_box_get_id_column (GtkComboBox *combo_box)
{
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
return combo_box->priv->id_column;
}
/**
* gtk_combo_box_get_active_id:
* @combo_box: a #GtkComboBox
*
* Returns the ID of the active row of @combo_box. This value is taken
* from the active row and the column specified by the 'id-column'
* property of @combo_box (see gtk_combo_box_set_id_column()).
*
* The returned value is an interned string which means that you can
* compare the pointer by value to other interned strings and that you
* must not free it.
*
* If the 'id-column' property of @combo_box is not set or if no row is
* selected then %NULL is returned.
*
* Return value: the ID of the active row, or %NULL
*
* Since: 3.0
**/
const gchar *
gtk_combo_box_get_active_id (GtkComboBox *combo_box)
{
GtkTreeModel *model;
GtkTreeIter iter;
gint column;
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
column = combo_box->priv->id_column;
if (column < 0)
return NULL;
model = gtk_combo_box_get_model (combo_box);
g_return_val_if_fail (gtk_tree_model_get_column_type (model, column) ==
G_TYPE_STRING, NULL);
if (gtk_combo_box_get_active_iter (combo_box, &iter))
{
const gchar *interned;
gchar *id;
gtk_tree_model_get (model, &iter, column, &id, -1);
interned = g_intern_string (id);
g_free (id);
return interned;
}
return NULL;
}
/**
* gtk_combo_box_set_active_id:
* @combo_box: a #GtkComboBox
* @active_id: the ID of the row to select
*
* Changes the active row of @combo_box to the one that has an ID equal to @id.
*
* If the 'id-column' property of @combo_box is unset or if no row has
* the given ID then nothing happens.
*
* Since: 3.0
**/
void
gtk_combo_box_set_active_id (GtkComboBox *combo_box,
const gchar *active_id)
{
GtkTreeModel *model;
GtkTreeIter iter;
gint column;
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
column = combo_box->priv->id_column;
if (column < 0)
return;
model = gtk_combo_box_get_model (combo_box);
g_return_if_fail (gtk_tree_model_get_column_type (model, column) ==
G_TYPE_STRING);
if (gtk_tree_model_get_iter_first (model, &iter))
do {
gboolean match;
gchar *id;
gtk_tree_model_get (model, &iter, column, &id, -1);
match = strcmp (id, active_id) == 0;
g_free (id);
if (match)
{
gtk_combo_box_set_active_iter (combo_box, &iter);
break;
}
} while (gtk_tree_model_iter_next (model, &iter));
}

View File

@ -134,6 +134,12 @@ void gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
void gtk_combo_box_popdown (GtkComboBox *combo_box);
AtkObject* gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box);
gint gtk_combo_box_get_id_column (GtkComboBox *combo_box);
void gtk_combo_box_set_id_column (GtkComboBox *combo_box,
gint id_column);
const gchar * gtk_combo_box_get_active_id (GtkComboBox *combo_box);
void gtk_combo_box_set_active_id (GtkComboBox *combo_box,
const gchar *active_id);
G_END_DECLS

View File

@ -72,7 +72,7 @@ gtk_combo_box_text_init (GtkComboBoxText *combo_box)
{
GtkListStore *store;
store = gtk_list_store_new (1, G_TYPE_STRING);
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
g_object_unref (store);
}
@ -102,6 +102,7 @@ gtk_combo_box_text_new (void)
{
return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
"entry-text-column", 0,
"id-column", 1,
NULL);
}
@ -121,6 +122,7 @@ gtk_combo_box_text_new_with_entry (void)
return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
"has-entry", TRUE,
"entry-text-column", 0,
"id-column", 1,
NULL);
}
@ -131,13 +133,16 @@ gtk_combo_box_text_new_with_entry (void)
*
* Appends @text to the list of strings stored in @combo_box.
*
* This is the same as calling gtk_combo_box_text_insert_text() with a
* position of -1.
*
* Since: 2.24
*/
void
gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
const gchar *text)
{
gtk_combo_box_text_insert_text (combo_box, G_MAXINT, text);
gtk_combo_box_text_insert (combo_box, -1, NULL, text);
}
/**
@ -147,13 +152,16 @@ gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
*
* Prepends @text to the list of strings stored in @combo_box.
*
* This is the same as calling gtk_combo_box_text_insert_text() with a
* position of 0.
*
* Since: 2.24
*/
void
gtk_combo_box_text_prepend_text (GtkComboBoxText *combo_box,
const gchar *text)
{
gtk_combo_box_text_insert_text (combo_box, 0, text);
gtk_combo_box_text_insert (combo_box, 0, NULL, text);
}
/**
@ -164,12 +172,84 @@ gtk_combo_box_text_prepend_text (GtkComboBoxText *combo_box,
*
* Inserts @text at @position in the list of strings stored in @combo_box.
*
* If @position is negative then @text is appended.
*
* This is the same as calling gtk_combo_box_text_insert() with a %NULL
* ID string.
*
* Since: 2.24
*/
void
gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
gint position,
const gchar *text)
{
gtk_combo_box_text_insert (combo_box, position, NULL, text);
}
/**
* gtk_combo_box_text_append:
* @combo_box: A #GtkComboBoxText
* @text: A string
*
* Appends @text to the list of strings stored in @combo_box. If @id is
* non-%NULL then it is used as the ID of the row.
*
* This is the same as calling gtk_combo_box_text_insert() with a
* position of -1.
*
* Since: 2.24
*/
void
gtk_combo_box_text_append (GtkComboBoxText *combo_box,
const gchar *id,
const gchar *text)
{
gtk_combo_box_text_insert (combo_box, -1, id, text);
}
/**
* gtk_combo_box_text_prepend:
* @combo_box: A #GtkComboBox
* @text: A string
*
* Prepends @text to the list of strings stored in @combo_box. If @id
* is non-%NULL then it is used as the ID of the row.
*
* This is the same as calling gtk_combo_box_text_insert() with a
* position of 0.
*
* Since: 2.24
*/
void
gtk_combo_box_text_prepend (GtkComboBoxText *combo_box,
const gchar *id,
const gchar *text)
{
gtk_combo_box_text_insert (combo_box, 0, id, text);
}
/**
* gtk_combo_box_text_insert:
* @combo_box: A #GtkComboBoxText
* @position: An index to insert @text
* @id: a string ID for this value, or %NULL
* @text: A string to display
*
* Inserts @text at @position in the list of strings stored in @combo_box.
* If @id is non-%NULL then it is used as the ID of the row. See
* #GtkComboBox::id-column.
*
* If @position is negative then @text is appended.
*
* Since: 3.0
*/
void
gtk_combo_box_text_insert (GtkComboBoxText *combo_box,
gint position,
const gchar *id,
const gchar *text)
{
GtkListStore *store;
GtkTreeIter iter;
@ -177,9 +257,11 @@ gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
gint column_type;
g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
g_return_if_fail (position >= 0);
g_return_if_fail (text != NULL);
if (position < 0)
position = G_MAXINT;
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
g_return_if_fail (GTK_IS_LIST_STORE (store));
text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
@ -188,6 +270,17 @@ gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
gtk_list_store_insert (store, &iter, position);
gtk_list_store_set (store, &iter, text_column, text, -1);
if (id != NULL)
{
gint id_column;
id_column = gtk_combo_box_get_id_column (GTK_COMBO_BOX (combo_box));
column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), id_column);
g_return_if_fail (column_type == G_TYPE_STRING);
gtk_list_store_set (store, &iter, id_column, id, -1);
}
}
/**

View File

@ -72,6 +72,16 @@ void gtk_combo_box_text_remove (GtkComboBoxText *combo_box
void gtk_combo_box_text_remove_all (GtkComboBoxText *combo_box);
gchar *gtk_combo_box_text_get_active_text (GtkComboBoxText *combo_box);
void gtk_combo_box_text_insert (GtkComboBoxText *combo_box,
gint position,
const gchar *id,
const gchar *text);
void gtk_combo_box_text_append (GtkComboBoxText *combo_box,
const gchar *id,
const gchar *text);
void gtk_combo_box_text_prepend (GtkComboBoxText *combo_box,
const gchar *id,
const gchar *text);
G_END_DECLS

View File

@ -557,7 +557,6 @@ typedef enum
GTK_SCROLL_NATURAL
} GtkScrollablePolicy;
G_END_DECLS

View File

@ -317,7 +317,7 @@ static void gtk_icon_view_set_hadjustment (GtkIco
GtkAdjustment *adjustment);
static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
GtkAdjustment *adjustment);
static void gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view,
static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
GtkOrientation orientation,
GtkAdjustment *adjustment);
static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
@ -2707,6 +2707,7 @@ gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
GtkAdjustment *adjustment)
{
GtkIconViewPrivate *priv = icon_view->priv;
AtkObject *atk_obj;
if (adjustment && priv->hadjustment == adjustment)
return;
@ -2728,9 +2729,10 @@ gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
priv->hadjustment = g_object_ref_sink (adjustment);
gtk_icon_view_set_hadjustment_values (icon_view);
gtk_icon_view_accessible_set_adjustment (icon_view,
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
gtk_icon_view_accessible_set_adjustment (atk_obj,
GTK_ORIENTATION_HORIZONTAL,
priv->hadjustment);
adjustment);
g_object_notify (G_OBJECT (icon_view), "hadjustment");
}
@ -2740,6 +2742,7 @@ gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
GtkAdjustment *adjustment)
{
GtkIconViewPrivate *priv = icon_view->priv;
AtkObject *atk_obj;
if (adjustment && priv->vadjustment == adjustment)
return;
@ -2761,9 +2764,10 @@ gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
priv->vadjustment = g_object_ref_sink (adjustment);
gtk_icon_view_set_vadjustment_values (icon_view);
gtk_icon_view_accessible_set_adjustment (icon_view,
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
gtk_icon_view_accessible_set_adjustment (atk_obj,
GTK_ORIENTATION_VERTICAL,
priv->vadjustment);
adjustment);
g_object_notify (G_OBJECT (icon_view), "vadjustment");
}
@ -9207,32 +9211,21 @@ gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
}
static void
gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
GtkIconView *icon_view)
gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
GtkIconViewAccessible *view)
{
AtkObject *obj;
GtkIconViewAccessible *view;
/*
* The scrollbars have changed
*/
obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
view = GTK_ICON_VIEW_ACCESSIBLE (obj);
gtk_icon_view_accessible_traverse_items (view, NULL);
}
static void
gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view,
gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
GtkOrientation orientation,
GtkAdjustment *adjustment)
{
AtkObject *atk_obj;
GtkIconViewAccessiblePrivate *priv;
GtkAdjustment **old_adj_ptr;
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
priv = gtk_icon_view_accessible_get_priv (atk_obj);
priv = gtk_icon_view_accessible_get_priv (accessible);
/* Adjustments are set for the first time in constructor and priv is not
* initialized at that time, so skip this first setting. */
@ -9261,7 +9254,7 @@ gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view,
(gpointer *)&priv->old_hadj);
g_signal_handlers_disconnect_by_func (*old_adj_ptr,
gtk_icon_view_accessible_adjustment_changed,
icon_view);
accessible);
}
/* Connect signal */
@ -9269,7 +9262,7 @@ gtk_icon_view_accessible_set_adjustment (GtkIconView *icon_view,
g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
icon_view);
accessible);
}
static void
@ -9572,11 +9565,11 @@ gtk_icon_view_accessible_initialize (AtkObject *accessible,
icon_view = GTK_ICON_VIEW (data);
if (icon_view->priv->hadjustment)
gtk_icon_view_accessible_set_adjustment (icon_view,
gtk_icon_view_accessible_set_adjustment (accessible,
GTK_ORIENTATION_HORIZONTAL,
icon_view->priv->hadjustment);
if (icon_view->priv->vadjustment)
gtk_icon_view_accessible_set_adjustment (icon_view,
gtk_icon_view_accessible_set_adjustment (accessible,
GTK_ORIENTATION_VERTICAL,
icon_view->priv->vadjustment);
g_signal_connect (data,
@ -9623,7 +9616,7 @@ gtk_icon_view_accessible_destroyed (GtkWidget *widget,
g_signal_handlers_disconnect_by_func (priv->old_hadj,
(gpointer) gtk_icon_view_accessible_adjustment_changed,
widget);
accessible);
priv->old_hadj = NULL;
}
if (priv->old_vadj)
@ -9633,7 +9626,7 @@ gtk_icon_view_accessible_destroyed (GtkWidget *widget,
g_signal_handlers_disconnect_by_func (priv->old_vadj,
(gpointer) gtk_icon_view_accessible_adjustment_changed,
widget);
accessible);
priv->old_vadj = NULL;
}
}

View File

@ -1280,7 +1280,7 @@ gtk_range_set_range (GtkRange *range,
gdouble value;
g_return_if_fail (GTK_IS_RANGE (range));
g_return_if_fail (min < max);
g_return_if_fail (min <= max);
priv = range->priv;
@ -2016,11 +2016,16 @@ gtk_range_draw (GtkWidget *widget,
gint focus_line_width = 0;
gint focus_padding = 0;
gboolean touchscreen;
gboolean draw_trough = TRUE;
g_object_get (gtk_widget_get_settings (widget),
"gtk-touchscreen-mode", &touchscreen,
NULL);
if (GTK_IS_SCALE (widget) &&
priv->adjustment->upper == priv->adjustment->lower)
draw_trough = FALSE;
style = gtk_widget_get_style (widget);
if (gtk_widget_get_can_focus (GTK_WIDGET (range)))
gtk_widget_style_get (GTK_WIDGET (range),
@ -2112,6 +2117,7 @@ gtk_range_draw (GtkWidget *widget,
}
}
if (draw_trough)
{
gint trough_change_pos_x = width;
gint trough_change_pos_y = height;
@ -2147,6 +2153,17 @@ gtk_range_draw (GtkWidget *widget,
width - trough_change_pos_x,
height - trough_change_pos_y);
}
else
{
gtk_paint_box (style, cr,
sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
GTK_SHADOW_IN,
GTK_WIDGET (range),
"trough-upper",
x, y,
width,
height);
}
if (priv->show_fill_level &&
priv->adjustment->upper - priv->adjustment->page_size -
@ -2236,6 +2253,7 @@ gtk_range_draw (GtkWidget *widget,
gdk_cairo_rectangle (cr, &priv->slider);
cairo_clip (cr);
if (draw_trough)
{
gtk_paint_slider (style,
cr,

View File

@ -55,6 +55,11 @@
* To detect changes to the value, you would normally use the
* #GtkRange::value-changed signal.
*
* Note that using the same upper and lower bounds for the #GtkScale (through
* the #GtkRange methods) will hide the slider itself. This is useful for
* applications that want to show an undeterminate value on the scale, without
* changing the layout of the application (such as movie or music players).
*
* <refsect2 id="GtkScale-BUILDER-UI"><title>GtkScale as GtkBuildable</title>
* GtkScale supports a custom &lt;marks&gt; element, which
* can contain multiple &lt;mark&gt; elements. The "value" and "position"

View File

@ -68,9 +68,9 @@ struct _GtkSelectionData
struct _GtkTargetEntry
{
const gchar *target;
guint flags;
guint info;
gchar *target;
guint flags;
guint info;
};
/* These structures not public, and are here only for the convenience of

View File

@ -293,6 +293,7 @@ gtk_spinner_add_timeout (GtkSpinner *spinner)
priv = spinner->priv;
g_assert (priv->timeout == 0);
priv->timeout = gdk_threads_add_timeout ((guint) priv->cycle_duration / priv->num_steps, gtk_spinner_timeout, spinner);
}
@ -315,7 +316,7 @@ gtk_spinner_map (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_spinner_parent_class)->map (widget);
if (priv->active)
if (priv->active && priv->timeout == 0)
gtk_spinner_add_timeout (spinner);
}
@ -364,20 +365,22 @@ gtk_spinner_dispose (GObject *gobject)
}
static void
gtk_spinner_set_active (GtkSpinner *spinner, gboolean active)
gtk_spinner_set_active (GtkSpinner *spinner,
gboolean active)
{
GtkSpinnerPrivate *priv;
GtkSpinnerPrivate *priv = spinner->priv;
active = active != FALSE;
priv = GTK_SPINNER (spinner)->priv;
active = !!active;
if (priv->active != active)
{
priv->active = active;
g_object_notify (G_OBJECT (spinner), "active");
if (active && gtk_widget_get_realized (GTK_WIDGET (spinner)) && priv->timeout == 0)
if (active &&
gtk_widget_get_realized (GTK_WIDGET (spinner)) &&
priv->timeout == 0)
{
gtk_spinner_add_timeout (spinner);
}
@ -388,84 +391,7 @@ gtk_spinner_set_active (GtkSpinner *spinner, gboolean active)
}
}
static GType
gtk_spinner_accessible_factory_get_accessible_type (void)
{
return gtk_spinner_accessible_get_type ();
}
static AtkObject *
gtk_spinner_accessible_new (GObject *obj)
{
AtkObject *accessible;
g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
accessible = g_object_new (gtk_spinner_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
return accessible;
}
static AtkObject*
gtk_spinner_accessible_factory_create_accessible (GObject *obj)
{
return gtk_spinner_accessible_new (obj);
}
static void
gtk_spinner_accessible_factory_class_init (AtkObjectFactoryClass *klass)
{
klass->create_accessible = gtk_spinner_accessible_factory_create_accessible;
klass->get_accessible_type = gtk_spinner_accessible_factory_get_accessible_type;
}
static GType
gtk_spinner_accessible_factory_get_type (void)
{
static GType type = 0;
if (!type)
{
const GTypeInfo tinfo =
{
sizeof (AtkObjectFactoryClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_spinner_accessible_factory_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (AtkObjectFactory),
0, /* n_preallocs */
NULL, NULL
};
type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
I_("GtkSpinnerAccessibleFactory"),
&tinfo, 0);
}
return type;
}
static AtkObjectClass *a11y_parent_class = NULL;
static void
gtk_spinner_accessible_initialize (AtkObject *accessible,
gpointer widget)
{
atk_object_set_name (accessible, C_("throbbing progress animation widget", "Spinner"));
atk_object_set_description (accessible, _("Provides visual indication of progress"));
a11y_parent_class->initialize (accessible, widget);
}
static void
gtk_spinner_accessible_class_init (AtkObjectClass *klass)
{
a11y_parent_class = g_type_class_peek_parent (klass);
klass->initialize = gtk_spinner_accessible_initialize;
}
/* accessible implementation */
static void
gtk_spinner_accessible_image_get_size (AtkImage *image,
@ -476,7 +402,7 @@ gtk_spinner_accessible_image_get_size (AtkImage *image,
GtkWidget *widget;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
if (!widget)
if (widget == NULL)
{
*width = *height = 0;
}
@ -489,62 +415,79 @@ gtk_spinner_accessible_image_get_size (AtkImage *image,
}
static void
gtk_spinner_accessible_image_interface_init (AtkImageIface *iface)
gtk_spinner_accessible_image_iface_init (AtkImageIface *iface)
{
iface->get_image_size = gtk_spinner_accessible_image_get_size;
}
static GType
gtk_spinner_accessible_get_type (void)
/* dummy typedef */
typedef struct _GtkSpinnerAccessible GtkSpinnerAccessible;
typedef struct _GtkSpinnerAccessibleClass GtkSpinnerAccessibleClass;
ATK_DEFINE_TYPE_WITH_CODE (GtkSpinnerAccessible,
gtk_spinner_accessible,
GTK_TYPE_IMAGE,
G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE,
gtk_spinner_accessible_image_iface_init));
static void
gtk_spinner_accessible_initialize (AtkObject *accessible,
gpointer widget)
{
static GType type = 0;
ATK_OBJECT_CLASS (gtk_spinner_accessible_parent_class)->initialize (accessible, widget);
/* Action interface
Name etc. ... */
if (G_UNLIKELY (type == 0))
{
const GInterfaceInfo atk_image_info = {
(GInterfaceInitFunc) gtk_spinner_accessible_image_interface_init,
(GInterfaceFinalizeFunc) NULL,
NULL
};
GType parent_atk_type;
GTypeInfo tinfo = { 0 };
GTypeQuery query;
AtkObjectFactory *factory;
atk_object_set_name (accessible, C_("throbbing progress animation widget", "Spinner"));
atk_object_set_description (accessible, _("Provides visual indication of progress"));
}
if ((type = g_type_from_name ("GtkSpinnerAccessible")))
return type;
static void
gtk_spinner_accessible_class_init (GtkSpinnerAccessibleClass *klass)
{
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
factory = atk_registry_get_factory (atk_get_default_registry (),
GTK_TYPE_IMAGE);
if (!factory)
return G_TYPE_INVALID;
atk_class->initialize = gtk_spinner_accessible_initialize;
}
parent_atk_type = atk_object_factory_get_accessible_type (factory);
if (!parent_atk_type)
return G_TYPE_INVALID;
static void
gtk_spinner_accessible_init (GtkSpinnerAccessible *self)
{
}
/*
* Figure out the size of the class and instance
* we are deriving from
*/
g_type_query (parent_atk_type, &query);
/* factory */
typedef AtkObjectFactory GtkSpinnerAccessibleFactory;
typedef AtkObjectFactoryClass GtkSpinnerAccessibleFactoryClass;
tinfo.class_init = (GClassInitFunc) gtk_spinner_accessible_class_init;
tinfo.class_size = query.class_size;
tinfo.instance_size = query.instance_size;
G_DEFINE_TYPE (GtkSpinnerAccessibleFactory,
gtk_spinner_accessible_factory,
ATK_TYPE_OBJECT_FACTORY);
/* Register the type */
type = g_type_register_static (parent_atk_type,
"GtkSpinnerAccessible",
&tinfo, 0);
static GType
gtk_spinner_accessible_factory_get_accessible_type (void)
{
return gtk_spinner_accessible_get_type ();
}
g_type_add_interface_static (type, ATK_TYPE_IMAGE,
&atk_image_info);
}
static AtkObject *
gtk_spinner_accessible_factory_create_accessible (GObject *obj)
{
AtkObject *accessible;
return type;
accessible = g_object_new (gtk_spinner_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
return accessible;
}
static void
gtk_spinner_accessible_factory_class_init (AtkObjectFactoryClass *klass)
{
klass->create_accessible = gtk_spinner_accessible_factory_create_accessible;
klass->get_accessible_type = gtk_spinner_accessible_factory_get_accessible_type;
}
static void
gtk_spinner_accessible_factory_init (AtkObjectFactory *factory)
{
}
static AtkObject *
@ -567,8 +510,7 @@ gtk_spinner_get_accessible (GtkWidget *widget)
derived_type = g_type_parent (GTK_TYPE_SPINNER);
registry = atk_get_default_registry ();
factory = atk_registry_get_factory (registry,
derived_type);
factory = atk_registry_get_factory (registry, derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
atk_registry_set_factory_type (registry,
@ -576,6 +518,7 @@ gtk_spinner_get_accessible (GtkWidget *widget)
gtk_spinner_accessible_factory_get_type ());
first_time = FALSE;
}
return GTK_WIDGET_CLASS (gtk_spinner_parent_class)->get_accessible (widget);
}

997
gtk/gtkswitch.c Normal file
View File

@ -0,0 +1,997 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2010 Intel Corporation
* Copyright (C) 2010 RedHat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
* Matthias Clasen <mclasen@redhat.com>
*
* Based on similar code from Mx.
*/
/**
* SECTION:gtkswitch
* @Short_Description: A "light switch" style toggle
* @Title: GtkSwitch
* @See_Also: #GtkToggleButton
*
* #GtkSwitch is a widget that has two states: on or off. The user can control
* which state should be active by clicking the empty area, or by dragging the
* handle.
*/
#include "config.h"
#include "gtkswitch.h"
#include <gdk/gdkkeysyms.h>
#include "gtkaccessible.h"
#include "gtkactivatable.h"
#include "gtkintl.h"
#include "gtkstyle.h"
#include "gtkprivate.h"
#include "gtktoggleaction.h"
#include "gtkwidget.h"
#define DEFAULT_SLIDER_WIDTH (36)
#define DEFAULT_SLIDER_HEIGHT (22)
struct _GtkSwitchPrivate
{
GdkWindow *event_window;
GtkAction *action;
gint handle_x;
gint offset;
gint drag_start;
gint drag_threshold;
guint is_active : 1;
guint is_dragging : 1;
guint in_press : 1;
guint in_switch : 1;
guint use_action_appearance : 1;
};
enum
{
PROP_0,
PROP_ACTIVE,
PROP_RELATED_ACTION,
PROP_USE_ACTION_APPEARANCE,
LAST_PROP
};
static GParamSpec *switch_props[LAST_PROP] = { NULL, };
static GType gtk_switch_accessible_factory_get_type (void);
static void gtk_switch_activatable_interface_init (GtkActivatableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkSwitch, gtk_switch, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
gtk_switch_activatable_interface_init));
static gboolean
gtk_switch_button_press (GtkWidget *widget,
GdkEventButton *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
if (priv->is_active)
{
/* if the event occurred in the "off" area, then this
* is a direct toggle
*/
if (event->x <= allocation.width / 2)
{
priv->in_press = TRUE;
return FALSE;
}
priv->offset = event->x - allocation.width / 2;
}
else
{
/* if the event occurred in the "on" area, then this
* is a direct toggle
*/
if (event->x >= allocation.width / 2)
{
priv->in_press = TRUE;
return FALSE;
}
priv->offset = event->x;
}
priv->drag_start = event->x;
g_object_get (gtk_widget_get_settings (widget),
"gtk-dnd-drag-threshold", &priv->drag_threshold,
NULL);
return FALSE;
}
static gboolean
gtk_switch_motion (GtkWidget *widget,
GdkEventMotion *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
/* if this is a direct toggle we don't handle motion */
if (priv->in_press)
return FALSE;
if (ABS (event->x - priv->drag_start) < priv->drag_threshold)
return TRUE;
if (event->state & GDK_BUTTON1_MASK)
{
gint position = event->x - priv->offset;
GtkAllocation allocation;
GtkStyle *style;
style = gtk_widget_get_style (widget);
gtk_widget_get_allocation (widget, &allocation);
/* constrain the handle within the trough width */
if (position > (allocation.width / 2 - style->xthickness))
priv->handle_x = allocation.width / 2 - style->xthickness;
else if (position < style->xthickness)
priv->handle_x = style->xthickness;
else
priv->handle_x = position;
priv->is_dragging = TRUE;
/* we need to redraw the handle */
gtk_widget_queue_draw (widget);
return TRUE;
}
return FALSE;
}
static gboolean
gtk_switch_button_release (GtkWidget *widget,
GdkEventButton *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
/* dragged toggles have a "soft" grab, so we don't care whether we
* are in the switch or not when the button is released; we do care
* for direct toggles, instead
*/
if (!priv->is_dragging && !priv->in_switch)
return FALSE;
/* direct toggle */
if (priv->in_press)
{
priv->in_press = FALSE;
gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
return TRUE;
}
/* dragged toggle */
if (priv->is_dragging)
{
priv->is_dragging = FALSE;
/* if half the handle passed the middle of the switch, then we
* consider it to be on
*/
if ((priv->handle_x + (allocation.width / 4)) >= (allocation.width / 2))
{
gtk_switch_set_active (GTK_SWITCH (widget), TRUE);
priv->handle_x = allocation.width / 2;
}
else
{
gtk_switch_set_active (GTK_SWITCH (widget), FALSE);
priv->handle_x = 0;
}
gtk_widget_queue_draw (widget);
return TRUE;
}
return FALSE;
}
static gboolean
gtk_switch_enter (GtkWidget *widget,
GdkEventCrossing *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
if (event->window == priv->event_window)
priv->in_switch = TRUE;
return FALSE;
}
static gboolean
gtk_switch_leave (GtkWidget *widget,
GdkEventCrossing *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
if (event->window == priv->event_window)
priv->in_switch = FALSE;
return FALSE;
}
static gboolean
gtk_switch_key_release (GtkWidget *widget,
GdkEventKey *event)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
if (event->keyval == GDK_KEY_Return ||
event->keyval == GDK_KEY_KP_Enter ||
event->keyval == GDK_KEY_ISO_Enter ||
event->keyval == GDK_KEY_space ||
event->keyval == GDK_KEY_KP_Space)
{
gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
}
return FALSE;
}
static void
gtk_switch_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
GtkStyle *style = gtk_widget_get_style (widget);
gint width, slider_width, focus_width, focus_pad;
PangoLayout *layout;
PangoRectangle logical_rect;
width = style->xthickness * 2;
gtk_widget_style_get (widget,
"slider-width", &slider_width,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
width += 2 * (focus_width + focus_pad);
/* Translators: if the "on" state label requires more than three
* glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
* the state
*/
layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_extents_to_pixels (&logical_rect, NULL);
width += MAX (logical_rect.width, slider_width);
/* Translators: if the "off" state label requires more than three
* glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
*/
pango_layout_set_text (layout, C_("switch", "OFF"), -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_extents_to_pixels (&logical_rect, NULL);
width += MAX (logical_rect.width, slider_width);
g_object_unref (layout);
if (minimum)
*minimum = width;
if (natural)
*natural = width;
}
static void
gtk_switch_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural)
{
GtkStyle *style = gtk_widget_get_style (widget);
gint height, focus_width, focus_pad;
PangoLayout *layout;
PangoRectangle logical_rect;
gchar *str;
height = style->ythickness * 2;
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
height += 2 * (focus_width + focus_pad);
str = g_strdup_printf ("%s%s",
C_("switch", "ON"),
C_("switch", "OFF"));
layout = gtk_widget_create_pango_layout (widget, str);
pango_layout_get_extents (layout, NULL, &logical_rect);
pango_extents_to_pixels (&logical_rect, NULL);
height += MAX (DEFAULT_SLIDER_HEIGHT, logical_rect.height);
g_object_unref (layout);
g_free (str);
if (minimum)
*minimum = height;
if (natural)
*natural = height;
}
static void
gtk_switch_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
gdk_window_move_resize (priv->event_window,
allocation->x,
allocation->y,
allocation->width,
allocation->height);
}
static void
gtk_switch_realize (GtkWidget *widget)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GdkWindow *parent_window;
GdkWindowAttr attributes;
gint attributes_mask;
GtkAllocation allocation;
gtk_widget_set_realized (widget, TRUE);
parent_window = gtk_widget_get_parent_window (widget);
gtk_widget_set_window (widget, parent_window);
g_object_ref (parent_window);
gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_ONLY;
attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_POINTER_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y;
priv->event_window = gdk_window_new (parent_window,
&attributes,
attributes_mask);
gdk_window_set_user_data (priv->event_window, widget);
gtk_widget_style_attach (widget);
}
static void
gtk_switch_unrealize (GtkWidget *widget)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
if (priv->event_window != NULL)
{
gdk_window_set_user_data (priv->event_window, NULL);
gdk_window_destroy (priv->event_window);
priv->event_window = NULL;
}
GTK_WIDGET_CLASS (gtk_switch_parent_class)->unrealize (widget);
}
static void
gtk_switch_map (GtkWidget *widget)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GTK_WIDGET_CLASS (gtk_switch_parent_class)->map (widget);
if (priv->event_window)
gdk_window_show (priv->event_window);
}
static void
gtk_switch_unmap (GtkWidget *widget)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
if (priv->event_window)
gdk_window_hide (priv->event_window);
GTK_WIDGET_CLASS (gtk_switch_parent_class)->unmap (widget);
}
static inline void
gtk_switch_paint_handle (GtkWidget *widget,
cairo_t *cr,
GdkRectangle *box)
{
GtkStyle *style = gtk_widget_get_style (widget);
gtk_paint_slider (style, cr,
gtk_widget_get_state (widget),
GTK_SHADOW_OUT,
GTK_WIDGET (widget), "switch-slider",
box->x,
box->y,
box->width,
box->height,
GTK_ORIENTATION_HORIZONTAL);
}
static gboolean
gtk_switch_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
GtkStyle *style;
GdkRectangle handle;
PangoLayout *layout;
PangoRectangle rect;
gint label_x, label_y;
GtkStateType state;
gint focus_width, focus_pad;
gint x, y, width, height;
gtk_widget_style_get (widget,
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
style = gtk_widget_get_style (widget);
x = 0;
y = 0;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
if (gtk_widget_has_focus (widget))
gtk_paint_focus (style, cr,
gtk_widget_get_state (widget),
widget, "button",
x, y, width, height);
x += focus_width + focus_pad;
y += focus_width + focus_pad;
width -= 2 * (focus_width + focus_pad);
height -= 2 * (focus_width + focus_pad);
state = priv->is_active ? GTK_STATE_SELECTED : gtk_widget_get_state (widget);
/* background - XXX should this be a flat box instead? we're missing
* the border given by the shadow with that, which would require
* fixing all theme engines to add a subtle border for this widget
*/
gtk_paint_box (style, cr,
state,
GTK_SHADOW_IN,
widget, "switch-background",
x, y, width, height);
if (!gtk_widget_is_sensitive (widget))
state = GTK_STATE_INSENSITIVE;
/* XXX the +1/-1 it's pixel wriggling after checking with the default
* theme and xmag
*/
handle.y = y + style->ythickness + 1;
handle.width = (width - style->xthickness * 2) / 2;
handle.height = (height - style->ythickness * 2) - 1;
/* Translators: if the "on" state label requires more than three
* glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
* the state
*/
layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
pango_layout_get_extents (layout, NULL, &rect);
pango_extents_to_pixels (&rect, NULL);
label_x = x + style->xthickness
+ ((width / 2) - rect.width - (style->xthickness * 2)) / 2;
label_y = y + style->ythickness
+ (height - rect.height - (style->ythickness * 2)) / 2;
gtk_paint_layout (style, cr,
state,
FALSE,
widget, "switch-on-label",
label_x, label_y,
layout);
g_object_unref (layout);
/* Translators: if the "off" state label requires more than three
* glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
*/
layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));
pango_layout_get_extents (layout, NULL, &rect);
pango_extents_to_pixels (&rect, NULL);
label_x = x + style->xthickness
+ (width / 2)
+ ((width / 2) - rect.width - (style->xthickness * 2)) / 2;
label_y = y + style->ythickness
+ (height - rect.height - (style->ythickness * 2)) / 2;
gtk_paint_layout (style, cr,
state,
FALSE,
widget, "switch-off-label",
label_x, label_y,
layout);
g_object_unref (layout);
if (priv->is_dragging)
handle.x = x + priv->handle_x;
else if (priv->is_active)
handle.x = x + width - handle.width - style->xthickness;
else
handle.x = x + style->xthickness;
gtk_switch_paint_handle (widget, cr, &handle);
return FALSE;
}
static AtkObject *
gtk_switch_get_accessible (GtkWidget *widget)
{
static gboolean first_time = TRUE;
if (G_UNLIKELY (first_time))
{
AtkObjectFactory *factory;
AtkRegistry *registry;
GType derived_type;
GType derived_atk_type;
/* Figure out whether accessibility is enabled by looking at the
* type of the accessible object which would be created for the
* parent type of GtkSwitch
*/
derived_type = g_type_parent (GTK_TYPE_SWITCH);
registry = atk_get_default_registry ();
factory = atk_registry_get_factory (registry, derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
atk_registry_set_factory_type (registry,
GTK_TYPE_SWITCH,
gtk_switch_accessible_factory_get_type ());
first_time = FALSE;
}
return GTK_WIDGET_CLASS (gtk_switch_parent_class)->get_accessible (widget);
}
static void
gtk_switch_set_related_action (GtkSwitch *sw,
GtkAction *action)
{
GtkSwitchPrivate *priv = sw->priv;
if (priv->action == action)
return;
gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (sw), action);
priv->action = action;
}
static void
gtk_switch_set_use_action_appearance (GtkSwitch *sw,
gboolean use_appearance)
{
GtkSwitchPrivate *priv = sw->priv;
if (priv->use_action_appearance != use_appearance)
{
priv->use_action_appearance = use_appearance;
gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (sw), priv->action);
}
}
static void
gtk_switch_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkSwitch *sw = GTK_SWITCH (gobject);
switch (prop_id)
{
case PROP_ACTIVE:
gtk_switch_set_active (sw, g_value_get_boolean (value));
break;
case PROP_RELATED_ACTION:
gtk_switch_set_related_action (sw, g_value_get_object (value));
break;
case PROP_USE_ACTION_APPEARANCE:
gtk_switch_set_use_action_appearance (sw, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}
static void
gtk_switch_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkSwitchPrivate *priv = GTK_SWITCH (gobject)->priv;
switch (prop_id)
{
case PROP_ACTIVE:
g_value_set_boolean (value, priv->is_active);
break;
case PROP_RELATED_ACTION:
g_value_set_object (value, priv->action);
break;
case PROP_USE_ACTION_APPEARANCE:
g_value_set_boolean (value, priv->use_action_appearance);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}
static void
gtk_switch_dispose (GObject *object)
{
GtkSwitchPrivate *priv = GTK_SWITCH (object)->priv;
if (priv->action)
{
gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (object), NULL);
priv->action = NULL;
}
G_OBJECT_CLASS (gtk_switch_parent_class)->dispose (object);
}
static void
gtk_switch_class_init (GtkSwitchClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gpointer activatable_iface;
g_type_class_add_private (klass, sizeof (GtkSwitchPrivate));
activatable_iface = g_type_default_interface_peek (GTK_TYPE_ACTIVATABLE);
switch_props[PROP_RELATED_ACTION] =
g_param_spec_override ("related-action",
g_object_interface_find_property (activatable_iface,
"related-action"));
switch_props[PROP_USE_ACTION_APPEARANCE] =
g_param_spec_override ("use-action-appearance",
g_object_interface_find_property (activatable_iface,
"use-action-appearance"));
/**
* GtkSwitch:active:
*
* Whether the #GtkSwitch widget is in its on or off state.
*/
switch_props[PROP_ACTIVE] =
g_param_spec_boolean ("active",
P_("Active"),
P_("Whether the switch is on or off"),
FALSE,
GTK_PARAM_READWRITE);
gobject_class->set_property = gtk_switch_set_property;
gobject_class->get_property = gtk_switch_get_property;
gobject_class->dispose = gtk_switch_dispose;
g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
widget_class->get_preferred_width = gtk_switch_get_preferred_width;
widget_class->get_preferred_height = gtk_switch_get_preferred_height;
widget_class->size_allocate = gtk_switch_size_allocate;
widget_class->realize = gtk_switch_realize;
widget_class->unrealize = gtk_switch_unrealize;
widget_class->map = gtk_switch_map;
widget_class->unmap = gtk_switch_unmap;
widget_class->draw = gtk_switch_draw;
widget_class->button_press_event = gtk_switch_button_press;
widget_class->button_release_event = gtk_switch_button_release;
widget_class->motion_notify_event = gtk_switch_motion;
widget_class->enter_notify_event = gtk_switch_enter;
widget_class->leave_notify_event = gtk_switch_leave;
widget_class->key_release_event = gtk_switch_key_release;
widget_class->get_accessible = gtk_switch_get_accessible;
/**
* GtkSwitch:slider-width:
*
* The minimum width of the #GtkSwitch handle, in pixels.
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("slider-width",
P_("Slider Width"),
P_("The minimum width of the handle"),
DEFAULT_SLIDER_WIDTH, G_MAXINT,
DEFAULT_SLIDER_WIDTH,
GTK_PARAM_READABLE));
}
static void
gtk_switch_init (GtkSwitch *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_SWITCH, GtkSwitchPrivate);
self->priv->use_action_appearance = TRUE;
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
}
/**
* gtk_switch_new:
*
* Creates a new #GtkSwitch widget.
*
* Return value: the newly created #GtkSwitch instance
*
* Since: 3.0
*/
GtkWidget *
gtk_switch_new (void)
{
return g_object_new (GTK_TYPE_SWITCH, NULL);
}
/**
* gtk_switch_set_active:
* @sw: a #GtkSwitch
* @is_active: %TRUE if @sw should be active, and %FALSE otherwise
*
* Changes the state of @sw to the desired one.
*
* Since: 3.0
*/
void
gtk_switch_set_active (GtkSwitch *sw,
gboolean is_active)
{
GtkSwitchPrivate *priv;
g_return_if_fail (GTK_IS_SWITCH (sw));
is_active = !!is_active;
priv = sw->priv;
if (priv->is_active != is_active)
{
AtkObject *accessible;
priv->is_active = is_active;
g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]);
if (priv->action)
gtk_action_activate (priv->action);
accessible = gtk_widget_get_accessible (GTK_WIDGET (sw));
atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active);
gtk_widget_queue_draw (GTK_WIDGET (sw));
}
}
/**
* gtk_switch_get_active:
* @sw: a #GtkSwitch
*
* Gets whether the #GtkSwitch is in its "on" or "off" state.
*
* Return value: %TRUE if the #GtkSwitch is active, and %FALSE otherwise
*
* Since: 3.0
*/
gboolean
gtk_switch_get_active (GtkSwitch *sw)
{
g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE);
return sw->priv->is_active;
}
static void
gtk_switch_update (GtkActivatable *activatable,
GtkAction *action,
const gchar *property_name)
{
if (strcmp (property_name, "visible") == 0)
{
if (gtk_action_is_visible (action))
gtk_widget_show (GTK_WIDGET (activatable));
else
gtk_widget_hide (GTK_WIDGET (activatable));
}
else if (strcmp (property_name, "sensitive") == 0)
{
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
}
else if (strcmp (property_name, "active") == 0)
{
gtk_action_block_activate (action);
gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
}
}
static void
gtk_switch_sync_action_properties (GtkActivatable *activatable,
GtkAction *action)
{
if (!action)
return;
if (gtk_action_is_visible (action))
gtk_widget_show (GTK_WIDGET (activatable));
else
gtk_widget_hide (GTK_WIDGET (activatable));
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
gtk_action_block_activate (action);
gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
}
static void
gtk_switch_activatable_interface_init (GtkActivatableIface *iface)
{
iface->update = gtk_switch_update;
iface->sync_action_properties = gtk_switch_sync_action_properties;
}
/* accessibility: object */
/* dummy typedefs */
typedef struct _GtkSwitchAccessible GtkSwitchAccessible;
typedef struct _GtkSwitchAccessibleClass GtkSwitchAccessibleClass;
ATK_DEFINE_TYPE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_WIDGET);
static AtkStateSet *
gtk_switch_accessible_ref_state_set (AtkObject *accessible)
{
AtkStateSet *state_set;
GtkWidget *widget;
state_set = ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->ref_state_set (accessible);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (widget == NULL)
return state_set;
if (gtk_switch_get_active (GTK_SWITCH (widget)))
atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
return state_set;
}
static void
_gtk_switch_accessible_initialize (AtkObject *accessible,
gpointer widget)
{
ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->initialize (accessible, widget);
atk_object_set_role (accessible, ATK_ROLE_TOGGLE_BUTTON);
atk_object_set_name (accessible, C_("light switch widget", "Switch"));
atk_object_set_description (accessible, _("Switches between on and off states"));
}
static void
_gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
{
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
atk_class->initialize = _gtk_switch_accessible_initialize;
atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
}
static void
_gtk_switch_accessible_init (GtkSwitchAccessible *self)
{
}
/* accessibility: factory */
typedef AtkObjectFactoryClass GtkSwitchAccessibleFactoryClass;
typedef AtkObjectFactory GtkSwitchAccessibleFactory;
G_DEFINE_TYPE (GtkSwitchAccessibleFactory,
gtk_switch_accessible_factory,
ATK_TYPE_OBJECT_FACTORY);
static GType
gtk_switch_accessible_factory_get_accessible_type (void)
{
return _gtk_switch_accessible_get_type ();
}
static AtkObject *
gtk_switch_accessible_factory_create_accessible (GObject *obj)
{
AtkObject *accessible;
accessible = g_object_new (_gtk_switch_accessible_get_type (), NULL);
atk_object_initialize (accessible, obj);
return accessible;
}
static void
gtk_switch_accessible_factory_class_init (AtkObjectFactoryClass *klass)
{
klass->create_accessible = gtk_switch_accessible_factory_create_accessible;
klass->get_accessible_type = gtk_switch_accessible_factory_get_accessible_type;
}
static void
gtk_switch_accessible_factory_init (AtkObjectFactory *factory)
{
}

94
gtk/gtkswitch.h Normal file
View File

@ -0,0 +1,94 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2010 Intel Corporation
* Copyright (C) 2010 RedHat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
* Matthias Clasen <mclasen@redhat.com>
*
* Based on similar code from Mx.
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_SWITCH_H__
#define __GTK_SWITCH_H__
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
#define GTK_TYPE_SWITCH (gtk_switch_get_type ())
#define GTK_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SWITCH, GtkSwitch))
#define GTK_IS_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SWITCH))
#define GTK_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SWITCH, GtkSwitchClass))
#define GTK_IS_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SWITCH))
#define GTK_SWITCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SWITCH, GtkSwitchClass))
typedef struct _GtkSwitch GtkSwitch;
typedef struct _GtkSwitchPrivate GtkSwitchPrivate;
typedef struct _GtkSwitchClass GtkSwitchClass;
/**
* GtkSwitch:
*
* The <structname>GtkSwitch</structname> structure contains private
* data and it should only be accessed using the provided API.
*/
struct _GtkSwitch
{
/*< private >*/
GtkWidget parent_instance;
GtkSwitchPrivate *priv;
};
/**
* GtkSwitchClass:
*
* The <structname>GtkSwitchClass</structname> structure contains only
* private data.
*/
struct _GtkSwitchClass
{
/*< private >*/
GtkWidgetClass parent_class;
void (* _switch_padding_1) (void);
void (* _switch_padding_2) (void);
void (* _switch_padding_3) (void);
void (* _switch_padding_4) (void);
void (* _switch_padding_5) (void);
void (* _switch_padding_6) (void);
void (* _switch_padding_7) (void);
};
GType gtk_switch_get_type (void) G_GNUC_CONST;
GtkWidget * gtk_switch_new (void);
void gtk_switch_set_active (GtkSwitch *sw,
gboolean is_active);
gboolean gtk_switch_get_active (GtkSwitch *sw);
G_END_DECLS
#endif /* __GTK_SWITCH_H__ */

View File

@ -3125,8 +3125,12 @@ gtk_toolbar_finalize (GObject *object)
g_timer_destroy (priv->timer);
if (priv->menu)
gtk_widget_destroy (GTK_WIDGET (priv->menu));
{
g_signal_handlers_disconnect_by_func (priv->menu,
menu_deactivated, toolbar);
gtk_widget_destroy (GTK_WIDGET (priv->menu));
}
if (priv->idle_id)
g_source_remove (priv->idle_id);

View File

@ -86,7 +86,6 @@ gtk/gtkhandlebox.c
gtk/gtkhbbox.c
gtk/gtkhbox.c
gtk/gtkhpaned.c
gtk/gtkhruler.c
gtk/gtkhscale.c
gtk/gtkhscrollbar.c
gtk/gtkhseparator.c
@ -147,7 +146,6 @@ gtk/gtkrecentchooser.c
gtk/gtkrecentchooserdefault.c
gtk/gtkrecentchoosermenu.c
gtk/gtkrecentmanager.c
gtk/gtkruler.c
gtk/gtkscalebutton.c
gtk/gtkscale.c
gtk/gtkscrollbar.c
@ -164,6 +162,7 @@ gtk/gtkstatusbar.c
gtk/gtkstatusicon.c
gtk/gtkstock.c
gtk/gtkstyle.c
gtk/gtkswitch.c
gtk/gtktable.c
gtk/gtktearoffmenuitem.c
gtk/gtktextbuffer.c
@ -205,7 +204,6 @@ gtk/gtkvbox.c
gtk/gtkviewport.c
gtk/gtkvolumebutton.c
gtk/gtkvpaned.c
gtk/gtkvruler.c
gtk/gtkvscale.c
gtk/gtkvscrollbar.c
gtk/gtkvseparator.c

View File

@ -1,10 +1 @@
demos/gtk-demo/demo.ui
gdk-pixbuf/io-gdip-bmp.c
gdk-pixbuf/io-gdip-emf.c
gdk-pixbuf/io-gdip-gif.c
gdk-pixbuf/io-gdip-ico.c
gdk-pixbuf/io-gdip-jpeg.c
gdk-pixbuf/io-gdip-png.c
gdk-pixbuf/io-gdip-utils.c
gdk-pixbuf/io-gdip-wmf.c

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,6 @@ gtk/gtkhandlebox.c
gtk/gtkhbbox.c
gtk/gtkhbox.c
gtk/gtkhpaned.c
gtk/gtkhruler.c
gtk/gtkhscale.c
gtk/gtkhscrollbar.c
gtk/gtkhseparator.c
@ -147,7 +146,6 @@ gtk/gtkrecentchooser.c
gtk/gtkrecentchooserdefault.c
gtk/gtkrecentchoosermenu.c
gtk/gtkrecentmanager.c
gtk/gtkruler.c
gtk/gtkscalebutton.c
gtk/gtkscale.c
gtk/gtkscrollbar.c
@ -165,6 +163,7 @@ gtk/gtkstatusbar.c
gtk/gtkstatusicon.c
gtk/gtkstock.c
gtk/gtkstyle.c
gtk/gtkswitch.c
gtk/gtktable.c
gtk/gtktearoffmenuitem.c
gtk/gtktextbuffer.c
@ -206,7 +205,6 @@ gtk/gtkvbox.c
gtk/gtkviewport.c
gtk/gtkvolumebutton.c
gtk/gtkvpaned.c
gtk/gtkvruler.c
gtk/gtkvscale.c
gtk/gtkvscrollbar.c
gtk/gtkvseparator.c

View File

@ -1,3 +1,2 @@
demos/gtk-demo/demo.ui
gtk/paper_names.c

View File

@ -16,8 +16,8 @@ msgstr ""
"Project-Id-Version: gtk+ MASTER\n"
"Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?product=gtk"
"%2b&component=general\n"
"POT-Creation-Date: 2010-11-03 02:36+0000\n"
"PO-Revision-Date: 2010-11-05 09:08+0200\n"
"POT-Creation-Date: 2010-11-29 20:28+0000\n"
"PO-Revision-Date: 2010-11-30 14:03+0200\n"
"Last-Translator: Ivar Smolin <okul@linux.ee>\n"
"Language-Team: Estonian <gnome-et@linux.ee>\n"
"MIME-Version: 1.0\n"
@ -1646,7 +1646,7 @@ msgstr "URI-ga '%s' pole võimalik leida ühtegi kirjet"
#, c-format
msgid "No registered application with name '%s' for item with URI '%s' found"
msgstr ""
msgstr "URI '%2$s' jaoks puudub registreeritud rakendust nimega '%1$s'"
msgctxt "throbbing progress animation widget"
msgid "Spinner"
@ -2065,6 +2065,28 @@ msgctxt "Stock label"
msgid "Zoom _Out"
msgstr "_Vähenda"
#. Translators: if the "on" state label requires more than three
#. * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
#. * the state
#.
msgctxt "switch"
msgid "ON"
msgstr "❙"
#. Translators: if the "off" state label requires more than three
#. * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
#.
msgctxt "switch"
msgid "OFF"
msgstr "○"
msgctxt "light switch widget"
msgid "Switch"
msgstr "Lüliti"
msgid "Switches between on and off states"
msgstr "Kahe olekuga (sees/väljas) lüliti"
#, c-format
msgid "Unknown error when trying to deserialize %s"
msgstr "Tundmatu viga %s deserialiseerimise katsel"

4015
po/fa.po

File diff suppressed because it is too large Load Diff

1897
po/id.po

File diff suppressed because it is too large Load Diff

1826
po/ro.po

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,8 @@ msgstr ""
"Project-Id-Version: gtk+ master\n"
"Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?product=gtk%2b&component=general\n"
"POT-Creation-Date: 2010-10-12 17:16+0000\n"
"PO-Revision-Date: 2010-10-12 20:07+0100\n"
"Last-Translator: Matej Urbančič <mateju@svn.gnome.org>\n"
"PO-Revision-Date: 2010-11-29 09:32+0100\n"
"Last-Translator: Andrej Žnidaršič <andrej.znidarsic@gmail.com>\n"
"Language-Team: Slovenian GNOME Translation Team <gnome-si@googlegroups.com>\n"
"Language: \n"
"MIME-Version: 1.0\n"
@ -103,12 +103,12 @@ msgstr "Premik nazaj"
#: ../gdk/keyname-table.h:3941
msgctxt "keyboard label"
msgid "Tab"
msgstr "Tab"
msgstr "Tabulator"
#: ../gdk/keyname-table.h:3942
msgctxt "keyboard label"
msgid "Return"
msgstr "Vnesi"
msgstr "Vnosna tipka"
#: ../gdk/keyname-table.h:3943
msgctxt "keyboard label"
@ -398,7 +398,7 @@ msgstr "Grafična podobo oblikovali"
#: ../gtk/gtkaccellabel.c:160
msgctxt "keyboard label"
msgid "Shift"
msgstr "Premakni"
msgstr "Shift"
#. This is the text that should appear next to menu accelerators
#. * that use the control key. If the text on this key isn't typically

View File

@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: gtk+\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-10-01 15:41-0400\n"
"PO-Revision-Date: 2010-04-06 15:08+0700\n"
"PO-Revision-Date: 2010-11-29 18:55+0700\n"
"Last-Translator: Theppitak Karoonboonyanan <thep@linux.thai.net>\n"
"Language-Team: Thai <thai-l10n@googlegroups.com>\n"
"Language: th\n"
@ -70,9 +70,8 @@ msgstr "SCREEN"
#. Description of --gdk-debug=FLAGS in --help output
#: gdk/gdk.c:164
#, fuzzy
msgid "GDK debugging flags to set"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะเปิดใช้"
msgstr "แฟล็กการดีบั๊กของ GDK ที่จะเปิดใช้"
#. Placeholder in --gdk-debug=FLAGS in --help output
#. Placeholder in --gdk-no-debug=FLAGS in --help output
@ -84,9 +83,8 @@ msgstr "FLAGS"
#. Description of --gdk-no-debug=FLAGS in --help output
#: gdk/gdk.c:167
#, fuzzy
msgid "GDK debugging flags to unset"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะปิด"
msgstr "แฟล็กการดีบั๊กของ GDK ที่จะปิด"
#: gdk/keyname-table.h:3940
msgctxt "keyboard label"
@ -330,7 +328,7 @@ msgstr "เรียกใช้ X แบบประสานเวลา"
#: gtk/gtkaboutdialog.c:101
#, c-format
msgid "This program comes with ABSOLUTELY NO WARRANTY; for details, visit %s"
msgstr ""
msgstr "โปรแกรมนี้ไม่มีการรับประกันใดๆ ดูรายละเอียดเพิ่มเติมได้ที่ %s"
#: gtk/gtkaboutdialog.c:339 gtk/gtkaboutdialog.c:2235
msgid "License"
@ -455,9 +453,9 @@ msgid "Invalid type function on line %d: '%s'"
msgstr "ฟังก์ชันถามชนิดใช้ไม่ได้ที่บรรทัด %d: '%s'"
#: gtk/gtkbuilderparser.c:407
#, fuzzy, c-format
#, c-format
msgid "Duplicate object ID '%s' on line %d (previously on line %d)"
msgstr "id ของอ็อบเจกต์ '%s' ซ้ำที่บรรทัด %d (ใช้แล้วที่บรรทัด %d)"
msgstr "ID ของอ็อบเจกต์ '%s' ซ้ำที่บรรทัด %d (ใช้แล้วที่บรรทัด %d)"
#: gtk/gtkbuilderparser.c:859
#, c-format
@ -612,9 +610,8 @@ msgid "_Saturation:"
msgstr "ความส_ด:"
#: gtk/gtkcolorsel.c:421
#, fuzzy
msgid "Intensity of the color."
msgstr "ความโปร่งแสงของสี"
msgstr "ความเข้มของสี"
#: gtk/gtkcolorsel.c:422
msgid "_Value:"
@ -789,12 +786,11 @@ msgstr "แ_ทรกอักขระควบคุมของยูนิ
#: gtk/gtkentry.c:10015
msgid "Caps Lock and Num Lock are on"
msgstr ""
msgstr "ปุ่ม Caps Lock และ Num Lock ติดอยู่"
#: gtk/gtkentry.c:10017
#, fuzzy
msgid "Num Lock is on"
msgstr "ปุ่ม Caps Lock ติดอยู่"
msgstr "ปุ่ม Num Lock ติดอยู่"
#: gtk/gtkentry.c:10019
msgid "Caps Lock is on"
@ -1267,12 +1263,12 @@ msgstr "ให้ความสำคัญกับคำเตือนปร
#. Description of --gtk-debug=FLAGS in --help output
#: gtk/gtkmain.c:532
msgid "GTK+ debugging flags to set"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะเปิดใช้"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะเปิดใช้"
#. Description of --gtk-no-debug=FLAGS in --help output
#: gtk/gtkmain.c:535
msgid "GTK+ debugging flags to unset"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะปิด"
msgstr "แฟล็กการดีบักของ GTK+ ที่จะปิด"
#. Translate to default:RTL if you want your widgets
#. * to be RTL, otherwise translate to default:LTR.
@ -1333,9 +1329,9 @@ msgid "Remember _forever"
msgstr "จำรหัสผ่านไว้_ตลอดไป"
#: gtk/gtkmountoperation.c:883
#, fuzzy, c-format
#, c-format
msgid "Unknown Application (PID %d)"
msgstr "โปรแกรมไม่ทราบชื่อ (pid %d)"
msgstr "โปรแกรมไม่ทราบชื่อ (PID %d)"
#: gtk/gtkmountoperation.c:1066
#, c-format
@ -1347,9 +1343,9 @@ msgid "_End Process"
msgstr "_จบโพรเซส"
#: gtk/gtkmountoperation-stub.c:64
#, fuzzy, c-format
#, c-format
msgid "Cannot kill process with PID %d. Operation is not implemented."
msgstr "ไม่สามารถฆ่าโพรเซสที่มี pid %d ได้ เนื่องจากยังไม่ได้ทำปฏิบัติการนี้"
msgstr "ไม่สามารถฆ่าโพรเซสที่มี PID %d ได้ เนื่องจากยังไม่ได้พัฒนาปฏิบัติการนี้"
#. translators: this string is a name for the 'less' command
#: gtk/gtkmountoperation-x11.c:862
@ -1373,9 +1369,9 @@ msgid "Z Shell"
msgstr "Z Shell"
#: gtk/gtkmountoperation-x11.c:963
#, fuzzy, c-format
#, c-format
msgid "Cannot end process with PID %d: %s"
msgstr "ไม่สามารถจบโพรเซสที่มี pid %d ได้: %s"
msgstr "ไม่สามารถจบโพรเซสที่มี PID %d ได้: %s"
#: gtk/gtknotebook.c:4619 gtk/gtknotebook.c:7170
#, c-format
@ -1450,9 +1446,8 @@ msgid "Not available"
msgstr "ไม่มี"
#: gtk/gtkprinteroptionwidget.c:794
#, fuzzy
msgid "Select a folder"
msgstr "เลือกแฟ้ม"
msgstr "เลือกโฟลเดอร์"
#: gtk/gtkprinteroptionwidget.c:813
msgid "_Save in folder:"
@ -2091,10 +2086,9 @@ msgid "_Cancel"
msgstr "_ยกเลิก"
#: gtk/gtkstock.c:326
#, fuzzy
msgctxt "Stock label"
msgid "_CD-ROM"
msgstr "_ซีดีรอม"
msgstr "ซีดี_รอม"
#: gtk/gtkstock.c:327
msgctxt "Stock label"
@ -2152,7 +2146,6 @@ msgid "_Edit"
msgstr "แ_ก้ไข"
#: gtk/gtkstock.c:338
#, fuzzy
msgctxt "Stock label"
msgid "_File"
msgstr "แ_ฟ้ม"
@ -2231,7 +2224,6 @@ msgid "_Up"
msgstr "_ขึ้น"
#: gtk/gtkstock.c:360
#, fuzzy
msgctxt "Stock label"
msgid "_Hard Disk"
msgstr "ฮาร์_ดดิสก์"
@ -2569,9 +2561,9 @@ msgid "The attribute \"%s\" was found twice on the <%s> element"
msgstr "พบแอตทริบิวต์ \"%s\" ซ้ำในอิลิเมนต์ <%s>"
#: gtk/gtktextbufferserialize.c:845
#, fuzzy, c-format
#, c-format
msgid "<%s> element has invalid ID \"%s\""
msgstr "อิลิเมนต์ <%s> มี id \"%s\" ซึ่งไม่ถูกต้อง"
msgstr "อิลิเมนต์ <%s> มี ID \"%s\" ซึ่งไม่ถูกต้อง"
#: gtk/gtktextbufferserialize.c:855
#, c-format
@ -3886,7 +3878,7 @@ msgid "Printer '%s' is out of paper."
msgstr "เครื่องพิมพ์ '%s' กระดาษหมด"
#: modules/printbackends/cups/gtkprintbackendcups.c:1686
#, fuzzy, c-format
#, c-format
msgid "Printer '%s' is currently offline."
msgstr "เครื่องพิมพ์ '%s' ออฟไลน์อยู่"
@ -4195,10 +4187,10 @@ msgid ""
msgstr "เปิดแฟ้มรูปภาพ '%s' ไม่สำเร็จ: ไม่แน่ใจว่าเพราะอะไร แต่อาจเป็นเพราะแฟ้มเสียหาย"
#~ msgid "Gdk debugging flags to set"
#~ msgstr "แฟล็กการดีบักของ GDK ที่จะเปิดใช้"
#~ msgstr "แฟล็กการดีบักของ GDK ที่จะเปิดใช้"
#~ msgid "Gdk debugging flags to unset"
#~ msgstr "แฟล็กการดีบักของ GDK ที่จะปิด"
#~ msgstr "แฟล็กการดีบักของ GDK ที่จะปิด"
#~ msgid "Image file '%s' contains no data"
#~ msgstr "แฟ้มรูปภาพ '%s' ไม่มีข้อมูล"

View File

@ -31,6 +31,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
print-editor \
testaccel \
testadjustsize \
testappchooser \
testappchooserbutton \
testassistant \
testbbox \
testbuttons \
@ -96,7 +98,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testexpander \
testvolumebutton \
testscrolledwindow \
testcellarea
testcellarea \
testswitch
if USE_X11
noinst_PROGRAMS += testerrors
@ -154,6 +157,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)
@ -186,6 +191,7 @@ testcellarea_DEPENDENCIES = $(TEST_DEPS)
testwindows_DEPENDENCIES = $(TEST_DEPS)
testexpand_DEPENDENCIES = $(TEST_DEPS)
testexpander_DEPENDENCIES = $(TEST_DEPS)
testswitch_DEPENDENCIES = $(TEST_DEPS)
flicker_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
@ -227,6 +233,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)
@ -261,6 +269,7 @@ testcellarea_LDADD = $(LDADDS)
testwindows_LDADD = $(LDADDS)
testexpand_LDADD = $(LDADDS)
testexpander_LDADD = $(LDADDS)
testswitch_LDADD = $(LDADDS)
testentrycompletion_SOURCES = \
prop-editor.c \
@ -383,6 +392,12 @@ testoffscreen_SOURCES = \
testoffscreenwindow_SOURCES = \
testoffscreenwindow.c
testappchooser_SOURCES = \
testappchooser.c
testappchooserbutton_SOURCES = \
testappchooserbutton.c
testwindows_SOURCES = \
testwindows.c
@ -390,6 +405,8 @@ testexpand_SOURCES = testexpand.c
testexpander_SOURCES = testexpander.c
testswitch_SOURCES = testswitch.c
EXTRA_DIST += \
prop-editor.h \
testgtk.1 \

218
tests/testappchooser.c Normal file
View 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;
}

View File

@ -0,0 +1,136 @@
/* 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_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
CUSTOM_ITEM);
gtk_widget_show_all (toplevel);
g_signal_connect (toplevel, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
gtk_main ();
return EXIT_SUCCESS;
}

View File

@ -592,6 +592,7 @@ main (int argc, char **argv)
GtkUIManager *merge;
GtkWidget *window, *table, *frame, *menu_box, *vbox, *view;
GtkWidget *button, *area, *statusbar;
GtkWidget *box;
gint i;
gtk_init (&argc, &argv);
@ -652,6 +653,15 @@ main (int argc, char **argv)
gtk_action_group_get_action (action_group, "BoldAction"));
gtk_widget_show (button);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_end (GTK_BOX (menu_box), box, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Bold:"));
button = gtk_switch_new ();
gtk_container_add (GTK_CONTAINER (box), button);
gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
gtk_action_group_get_action (action_group, "BoldAction"));
gtk_widget_show_all (box);
merge = gtk_ui_manager_new ();
g_signal_connect (merge, "connect-proxy", G_CALLBACK (connect_proxy), statusbar);

View File

@ -20,6 +20,16 @@
#include <gtk/gtk.h>
static void
show_trough_toggled (GtkToggleButton *button,
GtkScale *scale)
{
gboolean value;
value = gtk_toggle_button_get_active (button);
gtk_range_set_range (GTK_RANGE (scale), 0., value ? 100.0 : 0.);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
@ -27,6 +37,7 @@ int main (int argc, char *argv[])
GtkWidget *box2;
GtkWidget *frame;
GtkWidget *scale;
GtkWidget *toggle;
gdouble marks[3] = { 0.0, 50.0, 100.0 };
const gchar *labels[3] = {
"<small>Left</small>",
@ -96,6 +107,19 @@ int main (int argc, char *argv[])
gtk_container_add (GTK_CONTAINER (frame), scale);
gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
frame = gtk_frame_new ("Show/hide trough");
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
0, 100, 1);
gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
toggle = gtk_toggle_button_new_with_label ("Show slider trough");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
g_signal_connect (G_OBJECT (toggle), "toggled",
G_CALLBACK (show_trough_toggled), scale);
gtk_box_pack_start (GTK_BOX (box2), toggle, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (frame), box2);
gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);

86
tests/testswitch.c Normal file
View File

@ -0,0 +1,86 @@
#include <stdlib.h>
#include <gtk/gtk.h>
static gboolean
boolean_to_text (GBinding *binding,
const GValue *source,
GValue *target,
gpointer dummy G_GNUC_UNUSED)
{
if (g_value_get_boolean (source))
g_value_set_string (target, "Enabled");
else
g_value_set_string (target, "Disabled");
return TRUE;
}
static GtkWidget *
make_switch (gboolean is_on,
gboolean is_sensitive)
{
GtkWidget *hbox;
GtkWidget *sw, *label;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
sw = gtk_switch_new ();
gtk_switch_set_active (GTK_SWITCH (sw), is_on);
gtk_box_pack_start (GTK_BOX (hbox), sw, FALSE, FALSE, 0);
gtk_widget_set_sensitive (sw, is_sensitive);
gtk_widget_show (sw);
label = gtk_label_new (is_on ? "Enabled" : "Disabled");
gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
g_object_bind_property_full (sw, "active",
label, "label",
G_BINDING_DEFAULT,
boolean_to_text,
NULL,
NULL, NULL);
return hbox;
}
int
main (int argc,
char *argv[])
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "GtkSwitch");
gtk_window_set_default_size (GTK_WINDOW (window), 400, -1);
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
hbox = make_switch (FALSE, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
hbox = make_switch (TRUE, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
hbox = make_switch (FALSE, FALSE);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
hbox = make_switch (TRUE, FALSE);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
gtk_main ();
return EXIT_SUCCESS;
}