Import GtkRecent* from libegg.

2006-03-29  Emmanuele Bassi  <ebassi@cvs.gnome.org>

	Import GtkRecent* from libegg.

	* gtk/gtkrecentmanager.[ch]: Add GtkRecentManager, an object
	for managing a list of recently used resources.

	* gtk/gtkrecentchooser.[ch]:
	* gtk/gtkrecentchooserdefault.[ch]:
	* gtk/gtkrecentchooserdialog.[ch]:
	* gtk/gtkrecentchoosermenu.[ch]:
	* gtk/gtkrecentchooserprivate.h:
	* gtk/gtkrecentchooserutils.[ch]:
	* gtk/gtkrecentchooserwidget.[ch]: Add GtkRecentChooser, a
	GTypeInterface for widgets implementing viewers for recently
	used resources.

	* gtk/gtkrecentfilter.[ch]: GtkRecentFilter, a filter object
	for GtkRecentChooser implementations.

	* gtk/gtk.h:
	* gtk/gtk.symbols:
	* gtk/Makefile.am: Build glue for GtkRecent*.
This commit is contained in:
Emmanuele Bassi 2006-03-29 20:16:44 +00:00 committed by Emmanuele Bassi
parent 5f5de68e82
commit 056f6db533
20 changed files with 9123 additions and 0 deletions

View File

@ -228,6 +228,12 @@ gtk_public_h_sources = \
gtkradiotoolbutton.h \ gtkradiotoolbutton.h \
gtkrange.h \ gtkrange.h \
gtkrc.h \ gtkrc.h \
gtkrecentchooser.h \
gtkrecentchooserdialog.h \
gtkrecentchoosermenu.h \
gtkrecentchooserwidget.h \
gtkrecentfilter.h \
gtkrecentmanager.h \
gtkruler.h \ gtkruler.h \
gtkscale.h \ gtkscale.h \
gtkscrollbar.h \ gtkscrollbar.h \
@ -310,6 +316,9 @@ gtk_private_h_sources = \
gtkpathbar.h \ gtkpathbar.h \
gtkplugprivate.h \ gtkplugprivate.h \
gtkrbtree.h \ gtkrbtree.h \
gtkrecentchooserdefault.h \
gtkrecentchooserprivate.h \
gtkrecentchooserutils.h \
gtksequence.h \ gtksequence.h \
gtksocketprivate.h \ gtksocketprivate.h \
gtktextbtree.h \ gtktextbtree.h \
@ -459,6 +468,14 @@ gtk_c_sources = \
gtkrange.c \ gtkrange.c \
gtkrbtree.c \ gtkrbtree.c \
gtkrc.c \ gtkrc.c \
gtkrecentchooserdefault.c \
gtkrecentchooserdialog.c \
gtkrecentchoosermenu.c \
gtkrecentchooserwidget.c \
gtkrecentchooserutils.c \
gtkrecentchooser.c \
gtkrecentfilter.c \
gtkrecentmanager.c \
gtkruler.c \ gtkruler.c \
gtkscale.c \ gtkscale.c \
gtkscrollbar.c \ gtkscrollbar.c \

View File

@ -140,6 +140,12 @@
#include <gtk/gtkradiotoolbutton.h> #include <gtk/gtkradiotoolbutton.h>
#include <gtk/gtkrange.h> #include <gtk/gtkrange.h>
#include <gtk/gtkrc.h> #include <gtk/gtkrc.h>
#include <gtk/gtkrecentchooser.h>
#include <gtk/gtkrecentchooserdialog.h>
#include <gtk/gtkrecentchoosermenu.h>
#include <gtk/gtkrecentchooserwidget.h>
#include <gtk/gtkrecentfilter.h>
#include <gtk/gtkrecentmanager.h>
#include <gtk/gtkruler.h> #include <gtk/gtkruler.h>
#include <gtk/gtkscale.h> #include <gtk/gtkscale.h>
#include <gtk/gtkscrollbar.h> #include <gtk/gtkscrollbar.h>

View File

@ -2621,6 +2621,134 @@ gtk_rc_style_unref
#endif #endif
#endif #endif
#if IN_HEADER(__GTK_RECENT_CHOOSER_H__)
#if IN_FILE(__GTK_RECENT_CHOOSER_C__))
gtk_recent_chooser_set_show_private
gtk_recent_chooser_get_show_private
gtk_recent_chooser_set_show_not_found
gtk_recent_chooser_get_show_not_found
gtk_recent_chooser_set_show_icons
gtk_recent_chooser_get_show_icons
gtk_recent_chooser_set_select_multiple
gtk_recent_chooser_get_select_multiple
gtk_recent_chooser_set_local_only
gtk_recent_chooser_get_local_only
gtk_recent_chooser_set_limit
gtk_recent_chooser_get_limit
gtk_recent_chooser_set_show_tips
gtk_recent_chooser_get_show_tips
gtk_recent_chooser_set_show_numbers
gtk_recent_chooser_get_show_numbers
gtk_recent_chooser_set_sort_type
gtk_recent_chooser_get_sort_type
gtk_recent_chooser_set_sort_func
gtk_recent_chooser_set_current_uri
gtk_recent_chooser_get_current_uri
gtk_recent_chooser_get_current_item
gtk_recent_chooser_select_uri
gtk_recent_chooser_unselect_uri
gtk_recent_chooser_select_all
gtk_recent_chooser_unselect_all
gtk_recent_chooser_get_items
gtk_recent_chooser_get_uris
gtk_recent_chooser_add_filter
gtk_recent_chooser_remove_filter
gtk_recent_chooser_list_filters
gtk_recent_chooser_set_filter
gtk_recent_chooser_get_filter
gtk_recent_chooser_get_type G_GNUC_CONST
gtk_recent_chooser_error_quark
#endif
#endif
#if IN_HEADER(__GTK_RECENT_CHOOSER_DIALOG_H__)
#if IN_FILE(__GTK_RECENT_CHOOSER_DIALOG_C__)
gtk_recent_chooser_dialog_get_type G_GNUC_CONST
gtk_recent_chooser_dialog_new G_GNUC_NULL_TERMINATED
gtk_recent_chooser_dialog_new_for_manager G_GNUC_NULL_TERMINATED
#endif
#endif
#if IN_HEADER(__GTK_RECENT_CHOOSER_MENU_H__)
#if IN_FILE(__GTK_RECENT_CHOOSER_MENU_C__)
gtk_recent_chooser_menu_get_type G_GNUC_CONST
gtk_recent_chooser_menu_new
gtk_recent_chooser_menu_new_for_manager
gtk_recent_chooser_menu_get_show_numbers
gtk_recent_chooser_menu_set_show_numbers
#endif
#endif
#if IN_HEADER(__GTK_RECENT_CHOOSER_WIDGET_H__)
#if IN_FILE(__GTK_RECENT_CHOOSER_WIDGET_C__)
gtk_recent_chooser_widget_get_type G_GNUC_CONST
gtk_recent_chooser_widget_new
gtk_recent_chooser_widget_new_for_manager
#endif
#endif
#if IN_HEADER(__GTK_RECENT_FILTER_H__)
#if IN_FILE(__GTK_RECENT_FILTER_C__)
gtk_recent_filter_get_type G_GNUC_CONST
gtk_recent_filter_new
gtk_recent_filter_set_name
gtk_recent_filter_get_name
gtk_recent_filter_add_mime_type
gtk_recent_filter_add_pattern
gtk_recent_filter_add_pixbuf_formats
gtk_recent_filter_add_application
gtk_recent_filter_add_group
gtk_recent_filter_add_age
gtk_recent_filter_add_custom
gtk_recent_filter_get_needed
gtk_recent_filter_filter
#endif
#endif
#if IN_HEADER(__GTK_RECENT_MANAGER_H__)
#if IN_FILE(__GTK_RECENT_MANAGER_C__)
gtk_recent_manager_error_quark
gtk_recent_manager_get_type G_GNUC_CONST
gtk_recent_manager_new
gtk_recent_manager_get_default
gtk_recent_manager_get_for_screen
gtk_recent_manager_set_screen
gtk_recent_manager_add_item
gtk_recent_manager_add_full
gtk_recent_manager_remove_item
gtk_recent_manager_lookup_item
gtk_recent_manager_has_item
gtk_recent_manager_move_item
gtk_recent_manager_set_limit
gtk_recent_manager_get_limit
gtk_recent_manager_purge_items
gtk_recent_info_get_type G_GNUC_CONST
gtk_recent_info_ref
gtk_recent_info_unref
gtk_recent_info_get_uri
gtk_recent_info_get_display_name
gtk_recent_info_get_description
gtk_recent_info_get_mime_type
gtk_recent_info_get_added
gtk_recent_info_get_modified
gtk_recent_info_get_visited
gtk_recent_info_get_private_hint
gtk_recent_info_get_application_info
gtk_recent_info_get_applications G_GNUC_MALLOC
gtk_recent_info_last_application G_GNUC_MALLOC
gtk_recent_info_has_application
gtk_recent_info_get_groups G_GNUC_MALLOC
gtk_recent_info_has_group
gtk_recent_info_get_icon
gtk_recent_info_get_short_name G_GNUC_MALLOC
gtk_recent_info_get_uri_display G_GNUC_MALLOC
gtk_recent_info_get_age
gtk_recent_info_is_local
gtk_recent_info_exists
gtk_recent_info_match
#endif
#endif
#if IN_HEADER(__GTK_TEXT_BUFFER_RICH_TEXT_H__) #if IN_HEADER(__GTK_TEXT_BUFFER_RICH_TEXT_H__)
#if IN_FILE(__GTK_TEXT_BUFFER_RICH_TEXT_C__) #if IN_FILE(__GTK_TEXT_BUFFER_RICH_TEXT_C__)
gtk_text_buffer_deserialize gtk_text_buffer_deserialize

966
gtk/gtkrecentchooser.c Normal file
View File

@ -0,0 +1,966 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooser.c - Abstract interface for recent file selectors GUIs
*
* Copyright (C) 2006, Emmanuele Bassi
*
* 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.
*/
#include "config.h"
#include "gtkrecentchooser.h"
#include "gtkrecentchooserprivate.h"
#include "gtkrecentmanager.h"
#include "gtkintl.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtkmarshalers.h"
#include "gtkalias.h"
enum
{
ITEM_ACTIVATED,
SELECTION_CHANGED,
LAST_SIGNAL
};
static void gtk_recent_chooser_class_init (gpointer g_iface);
static guint chooser_signals[LAST_SIGNAL] = { 0, };
GType
gtk_recent_chooser_get_type (void)
{
static GType chooser_type = 0;
if (!chooser_type)
{
static const GTypeInfo chooser_info =
{
sizeof (GtkRecentChooserIface),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_recent_chooser_class_init,
};
chooser_type = g_type_register_static (G_TYPE_INTERFACE,
I_("GtkRecentChooser"),
&chooser_info, 0);
g_type_interface_add_prerequisite (chooser_type, GTK_TYPE_OBJECT);
}
return chooser_type;
}
static void
gtk_recent_chooser_class_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
/**
* GtkRecentChooser::selection-changed
* @chooser: the object which received the signal
*
* This signal is emitted when there is a change in the set of
* selected recently used resources. This can happen when a user
* modifies the selection with the mouse or the keyboard, or when
* explicitely calling functions to change the selection.
*
* Since: 2.10
*/
chooser_signals[SELECTION_CHANGED] =
g_signal_new (I_("selection-changed"),
iface_type,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkRecentChooser::item-activated
* @chooser: the object which received the signal
*
* This signal is emitted when the user "activates" a recent item
* in the recent chooser. This can happen by double-clicking on an item
* in the recently used resources list, or by pressing
* <keycap>Enter</keycap>.
*
* Since: 2.10
*/
chooser_signals[ITEM_ACTIVATED] =
g_signal_new (I_("item-activated"),
iface_type,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_object_interface_install_property (g_iface,
g_param_spec_object ("recent-manager",
P_("Recent Manager"),
P_("The RecentManager object to use"),
GTK_TYPE_RECENT_MANAGER,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("show-private",
P_("Show Private"),
P_("Whether the private items should be displayed"),
FALSE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("show-tips",
P_("Show Tooltips"),
P_("Whether there should be a tooltip on the item"),
FALSE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("show-icons",
P_("Show Icons"),
P_("Whether there should be an icon near the item"),
TRUE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("show-not-found",
P_("Show Not Found"),
P_("Whether the items pointing to unavailable resources should be displayed"),
FALSE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("select-multiple",
P_("Select Multiple"),
P_("Whether to allow multiple items to be selected"),
FALSE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_boolean ("local-only",
P_("Local only"),
P_("Whether the selected resource(s) should be limited to local file: URIs"),
TRUE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_int ("limit",
P_("Limit"),
P_("The maximum number of items to be displayed"),
-1,
G_MAXINT,
-1,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_enum ("sort-type",
P_("Sort Type"),
P_("The sorting order of the items displayed"),
GTK_TYPE_RECENT_SORT_TYPE,
GTK_RECENT_SORT_NONE,
G_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_object ("filter",
P_("Filter"),
P_("The current filter for selecting which resources are displayed"),
GTK_TYPE_RECENT_FILTER,
G_PARAM_READWRITE));
}
GQuark
gtk_recent_chooser_error_quark (void)
{
static GQuark error_quark = 0;
if (!error_quark)
error_quark = g_quark_from_static_string ("gtk-recent-chooser-error-quark");
return error_quark;
}
/**
* _gtk_recent_chooser_get_recent_manager:
* @chooser: a #GtkRecentChooser
*
* Gets the #GtkRecentManager used by @chooser.
*
* Return value: the recent manager for @chooser.
*
* Since: 2.10
*/
GtkRecentManager *
_gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
}
/**
* gtk_recent_chooser_set_show_private:
* @chooser: a #GtkRecentChooser
* @show_private: %TRUE to show private items, %FALSE otherwise
*
* Whether to show recently used resources marked registered as private.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
gboolean show_private)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "show-private", show_private, NULL);
}
/**
* gtk_recent_chooser_get_show_private:
* @chooser: a #GtkRecentChooser
*
* Returns whether @chooser should display recently used resources
* registered as private.
*
* Return value: %TRUE if the recent chooser should show private items,
* %FALSE otherwise.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
{
gboolean show_private;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "show-private", &show_private, NULL);
return show_private;
}
/**
* gtk_recent_chooser_set_show_not_found:
* @chooser: a #GtkRecentChooser
* @show_not_found: whether to show the local items we didn't find
*
* Sets whether @chooser should display the recently used resources that
* it didn't find. This only applies to local resources.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
gboolean show_not_found)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "show-not-found", show_not_found, NULL);
}
/**
* gtk_recent_chooser_get_show_not_found:
* @chooser: a #GtkRecentChooser
*
* Retrieves whether @chooser should show the recently used resources that
* were not found.
*
* Return value: %TRUE if the resources not found should be displayed, and
* %FALSE otheriwse.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
{
gboolean show_not_found;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "show-not-found", &show_not_found, NULL);
return show_not_found;
}
/**
* gtk_recent_chooser_set_show_icons:
* @chooser: a #GtkRecentChooser
* @show_icons: whether to show an icon near the resource
*
* Sets whether @chooser should show an icon near the resource when
* displaying it.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
gboolean show_icons)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "show-icons", show_icons, NULL);
}
/**
* gtk_recent_chooser_get_show_icons:
* @chooser: a #GtkRecentChooser
*
* Retrieves whether @chooser should show an icon near the resource.
*
* Return value: %TRUE if the icons should be displayed, %FALSE otherwise.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
{
gboolean show_icons;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "show-icons", &show_icons, NULL);
return show_icons;
}
/**
* gtk_recent_chooser_set_select_multiple:
* @chooser: a #GtkRecentChooser
* @select_multiple: %TRUE if @chooser can select more than one item
*
* Sets whether @chooser can select multiple items.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
gboolean select_multiple)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "select-multiple", select_multiple, NULL);
}
/**
* gtk_recent_chooser_get_select_multiple:
* @chooser: a #GtkRecentChooser
*
* Gets whether @chooser can select multiple items.
*
* Return value: %TRUE if @chooser can select more than one item.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
{
gboolean select_multiple;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "select-multiple", &select_multiple, NULL);
return select_multiple;
}
/**
* gtk_recent_chooser_set_local_only:
* @chooser: a #GtkRecentChooser
* @local_only: %TRUE if only local files can be shown
*
* Sets whether only local resources, that is resources using the file:// URI
* scheme, should be shown in the recently used resources selector. If
* @local_only is %TRUE (the default) then the shown resources are guaranteed
* to be accessible through the operating system native file system.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
gboolean local_only)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "local-only", local_only, NULL);
}
/**
* gtk_recent_chooser_get_local_only:
* @chooser: a #GtkRecentChooser
*
* Gets whether only local resources should be shown in the recently used
* resources selector. See gtk_recent_chooser_set_local_only()
*
* Return value: %TRUE if only local resources should be shown.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
{
gboolean local_only;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "local-only", &local_only, NULL);
return local_only;
}
/**
* gtk_recent_chooser_set_limit:
* @chooser: a #GtkRecentChooser
* @limit: a positive integer, or -1 for all items
*
* Sets the number of items that should be returned by
* gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
gint limit)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "limit", limit, NULL);
}
/**
* gtk_recent_chooser_get_limit:
* @chooser: a #GtkRecentChooser
*
* Gets the number of items returned by gtk_recent_chooser_get_items()
* and gtk_recent_chooser_get_uris().
*
* Return value: A positive integer, or -1 meaning that all items are
* returned.
*
* Since: 2.10
*/
gint
gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
{
gint limit;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
g_object_get (chooser, "limit", &limit, NULL);
return limit;
}
/**
* gtk_recent_chooser_set_show_tips:
* @chooser: a #GtkRecentChooser
* @show_tips: %TRUE if tooltips should be shown
*
* Sets whether to show a tooltips on the widget.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
gboolean show_tips)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "show-tips", show_tips, NULL);
}
/**
* gtk_recent_chooser_get_show_tips:
* @chooser: a #GtkRecentChooser
*
* Gets whether @chooser should display tooltips.
*
* Return value: %TRUE if the recent chooser should show tooltips,
* %FALSE otherwise.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
{
gboolean show_tips;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "show-tips", &show_tips, NULL);
return show_tips;
}
/**
* gtk_recent_chooser_set_show_numbers:
* @chooser: a #GtkRecentChooser
* @show_private: %TRUE to show numbers, %FALSE otherwise
*
* Whether to show recently used resources prepended by a unique number.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_show_numbers (GtkRecentChooser *chooser,
gboolean show_numbers)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "show-numbers", show_numbers, NULL);
}
/**
* gtk_recent_chooser_get_show_numbers:
* @chooser: a #GtkRecentChooser
*
* Returns whether @chooser should display recently used resources
* prepended by a unique number.
*
* Return value: %TRUE if the recent chooser should show display numbers,
* %FALSE otherwise.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_get_show_numbers (GtkRecentChooser *chooser)
{
gboolean show_numbers;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
g_object_get (chooser, "show-numbers", &show_numbers, NULL);
return show_numbers;
}
/**
* gtk_recent_chooser_set_sort_type:
* @chooser: a #GtkRecentChooser
* @sort_type: sort order that the chooser should use
*
* Changes the sorting order of the recently used resources list displayed by
* @chooser.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
GtkRecentSortType sort_type)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (chooser, "sort-type", sort_type, NULL);
}
/**
* gtk_recent_chooser_get_sort_type:
* @chooser: a #GtkRecentChooser
*
* Gets the value set by gtk_recent_chooser_set_sort_type().
*
* Return value: the sorting order of the @chooser.
*
* Since: 2.10
*/
GtkRecentSortType
gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
{
GtkRecentSortType sort_type;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
g_object_get (chooser, "sort-type", &sort_type, NULL);
return sort_type;
}
/**
* gtk_recent_chooser_set_sort_func:
* @chooser: a #GtkRecentChooser
* @sort_func: the comparison function
* @sort_data: user data to pass to @sort_func, or %NULL
* @destroy_data: destroy notifier for @sort_data, or %NULL
*
* Sets the comparison function used when sorting to be @sort_func. If
* the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
* the chooser will sort using this function.
*
* To the comparison function will be passed two #GtkRecentInfo structs and
* @sort_data; @sort_func should return a positive integer if the first
* item comes before the second, zero if the two items are equal and
* a negative integer if the first item comes after the second.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
GtkRecentSortFunc sort_func,
gpointer sort_data,
GDestroyNotify data_destroy)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
sort_func,
sort_data,
data_destroy);
}
/**
* gtk_recent_chooser_set_current_uri:
* @chooser: a #GtkRecentChooser
* @uri: a URI
* @error: return location for a #GError, or %NULL
*
* Sets @uri as the current URI for @chooser.
*
* Return value: %TRUE if the URI was found.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
}
/**
* gtk_recent_chooser_get_current_uri:
* @chooser: a #GtkRecentChooser
*
* Gets the URI currently selected by @chooser.
*
* Return value: a newly allocated string holding a URI.
*
* Since: 2.10
*/
gchar *
gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
}
/**
* gtk_recent_chooser_get_current_item:
* @chooser: a #GtkRecentChooser
*
* Gets the #GtkRecentInfo currently selected by @chooser.
*
* Return value: a #GtkRecentInfo. Use gtk_recent_info_unref() when
* when you have finished using it.
*
* Since: 2.10
*/
GtkRecentInfo *
gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
{
GtkRecentManager *manager;
GtkRecentInfo *retval;
gchar *uri;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
uri = gtk_recent_chooser_get_current_uri (chooser);
if (!uri)
return NULL;
manager = _gtk_recent_chooser_get_recent_manager (chooser);
retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
g_free (uri);
return retval;
}
/**
* gtk_recent_chooser_select_uri:
* @chooser: a #GtkRecentChooser
* @uri: a URI
* @error: return location for a #GError, or %NULL
*
* Selects @uri inside @chooser.
*
* Return value: %TRUE if @uri was found.
*
* Since: 2.10
*/
gboolean
gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
}
/**
* gtk_recent_chooser_unselect_uri:
* @chooser: a #GtkRecentChooser
* @uri: a URI
*
* Unselects @uri inside @chooser.
*
* Since: 2.10
*/
void
gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
const gchar *uri)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
}
/**
* gtk_recent_chooser_select_all:
* @chooser: a #GtkRecentChooser
*
* Selects all the items inside @chooser, if the @chooser supports
* multiple selection.
*
* Since: 2.10
*/
void
gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
}
/**
* gtk_recent_chooser_unselect_all:
* @chooser: a #GtkRecentChooser
*
* Unselects all the items inside @chooser.
*
* Since: 2.10
*/
void
gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
}
/**
* gtk_recent_chooser_get_items:
* @chooser: a #GtkRecentChooser
*
* Gets the list of recently used resources in form of #GtkRecentInfo objects.
*
* The return value of this function is affected by the "sort-type" and
* "limit" properties of @chooser.
*
* Return value: A newly allocated list of #GtkRecentInfo objects. You should
* use gtk_recent_info_unref() on every item of the list, and then free
* the list itself using g_list_free().
*
* Since: 2.10
*/
GList *
gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
}
/**
* gtk_recent_chooser_get_uris:
* @chooser: a #GtkRecentChooser
* @length: return location for a the length of the URI list, or %NULL
*
* Gets the URI of the recently used resources.
*
* The return value of this function is affected by the "sort-type" and "limit"
* properties of @chooser.
*
* Since the returned array is %NULL terminated, @length may be %NULL.
*
* Return value: A newly allocated, %NULL terminated array of strings. Use
* g_strfreev() to free it.
*
* Since: 2.10
*/
gchar **
gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
gsize *length)
{
GList *items, *l;
gchar **retval;
gsize n_items, i;
items = gtk_recent_chooser_get_items (chooser);
if (!items)
return NULL;
n_items = g_list_length (items);
retval = g_new0 (gchar *, n_items + 1);
for (l = items, i = 0; l != NULL; l = l->next)
{
GtkRecentInfo *info = (GtkRecentInfo *) l->data;
const gchar *uri;
g_assert (info != NULL);
uri = gtk_recent_info_get_uri (info);
g_assert (uri != NULL);
retval[i++] = g_strdup (uri);
}
retval[i] = NULL;
if (length)
*length = i;
g_list_foreach (items,
(GFunc) gtk_recent_info_unref,
NULL);
g_list_free (items);
return retval;
}
/**
* gtk_recent_chooser_add_filter:
* @chooser: a #GtkRecentChooser
* @filter: a #GtkRecentFilter
*
* Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
*
* If no previous filter objects were defined, this function will call
* gtk_recent_chooser_set_filter().
*
* Since: 2.10
*/
void
gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
}
/**
* gtk_recent_chooser_remove_filter:
* @chooser: a #GtkRecentChooser
* @filter: a #GtkRecentFilter
*
* Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
*
* Since: 2.10
*/
void
gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
}
/**
* gtk_recent_chooser_list_filters:
* @chooser: a #GtkRecentChooser
*
* Gets the #GtkRecentFilter objects held by @chooser.
*
* Return value: A singly linked list of #GtkRecentFilter objects. You
* should just free the returned list using g_slist_free().
*
* Since: 2.10
*/
GSList *
gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
{
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
}
/**
* gtk_recent_chooser_set_filter:
* @chooser: a #GtkRecentChooser
* @filter: a #GtkRecentFilter
*
* Sets @filter as the current #GtkRecentFilter object used by @chooser
* to affect the displayed recently used resources.
*
* Since: 2.10
*/
void
gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
}
/**
* gtk_recent_chooser_get_filter:
* @chooser: a #GtkRecentChooser
*
* Gets the #GtkRecentFilter object currently used by @chooser to affect
* the display of the recently used resources.
*
* Return value: a #GtkRecentFilter object.
*
* Since: 2.10
*/
GtkRecentFilter *
gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
{
GtkRecentFilter *filter;
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
/* we need this hack because g_object_get() increases the refcount
* of the returned object; see also gtk_file_chooser_get_filter()
* inside gtkfilechooser.c
*/
if (filter)
g_object_unref (filter);
return filter;
}
void
_gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
}
void
_gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
}
#define __GTK_RECENT_CHOOSER_H__
#include "gtkaliasdef.c"

186
gtk/gtkrecentchooser.h Normal file
View File

@ -0,0 +1,186 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooser.h - Abstract interface for recent file selectors GUIs
*
* Copyright (C) 2006, Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_H__
#define __GTK_RECENT_CHOOSER_H__
#include <gtk/gtkwidget.h>
#include "gtkrecentmanager.h"
#include "gtkrecentfilter.h"
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_CHOOSER (gtk_recent_chooser_get_type ())
#define GTK_RECENT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER, GtkRecentChooser))
#define GTK_IS_RECENT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER))
#define GTK_RECENT_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_RECENT_CHOOSER, GtkRecentChooserIface))
/**
* GtkRecentSortType:
* @GTK_RECENT_SORT_NONE: Do not sort the returned list of recently used
* resources.
* @GTK_RECENT_SORT_MRU: Sort the returned list with the most recently used
* items first.
* @GTK_RECENT_SORT_LRU: Sort the returned list with the least recently used
* items first.
* @GTK_RECENT_SORT_CUSTOM: Sort the returned list using a custom sorting
* function passed using gtk_recent_manager_set_sort_func().
*
* Used to specify the sorting method to be applyed to the recently
* used resource list.
**/
typedef enum
{
GTK_RECENT_SORT_NONE = 0,
GTK_RECENT_SORT_MRU,
GTK_RECENT_SORT_LRU,
GTK_RECENT_SORT_CUSTOM
} GtkRecentSortType;
typedef gint (*GtkRecentSortFunc) (GtkRecentInfo *a,
GtkRecentInfo *b,
gpointer user_data);
typedef struct _GtkRecentChooser GtkRecentChooser; /* dummy */
typedef struct _GtkRecentChooserIface GtkRecentChooserIface;
#define GTK_RECENT_CHOOSER_ERROR (gtk_recent_chooser_error_quark ())
typedef enum
{
GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
GTK_RECENT_CHOOSER_ERROR_INVALID_URI
} GtkRecentChooserError;
GQuark gtk_recent_chooser_error_quark (void);
struct _GtkRecentChooserIface
{
GTypeInterface base_iface;
/*
* Methods
*/
gboolean (* set_current_uri) (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
gchar * (* get_current_uri) (GtkRecentChooser *chooser);
gboolean (* select_uri) (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
void (* unselect_uri) (GtkRecentChooser *chooser,
const gchar *uri);
void (* select_all) (GtkRecentChooser *chooser);
void (* unselect_all) (GtkRecentChooser *chooser);
GList * (* get_items) (GtkRecentChooser *chooser);
GtkRecentManager *(* get_recent_manager) (GtkRecentChooser *chooser);
void (* add_filter) (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
void (* remove_filter) (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
GSList * (* list_filters) (GtkRecentChooser *chooser);
void (* set_sort_func) (GtkRecentChooser *chooser,
GtkRecentSortFunc sort_func,
gpointer data,
GDestroyNotify destroy);
/*
* Signals
*/
void (* item_activated) (GtkRecentChooser *chooser);
void (* selection_changed) (GtkRecentChooser *chooser);
};
GType gtk_recent_chooser_get_type (void) G_GNUC_CONST;
/*
* Configuration
*/
void gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
gboolean show_private);
gboolean gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
gboolean show_not_found);
gboolean gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
gboolean select_multiple);
gboolean gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
gint limit);
gint gtk_recent_chooser_get_limit (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
gboolean local_only);
gboolean gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
gboolean show_tips);
gboolean gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_show_numbers (GtkRecentChooser *chooser,
gboolean show_numbers);
gboolean gtk_recent_chooser_get_show_numbers (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
gboolean show_icons);
gboolean gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
GtkRecentSortType sort_type);
GtkRecentSortType gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
GtkRecentSortFunc sort_func,
gpointer sort_data,
GDestroyNotify data_destroy);
/*
* Items handling
*/
gboolean gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
gchar * gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser);
GtkRecentInfo *gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser);
gboolean gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
void gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
const gchar *uri);
void gtk_recent_chooser_select_all (GtkRecentChooser *chooser);
void gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser);
GList * gtk_recent_chooser_get_items (GtkRecentChooser *chooser);
gchar ** gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
gsize *length);
/*
* Filters
*/
void gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
void gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
GSList * gtk_recent_chooser_list_filters (GtkRecentChooser *chooser);
void gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
GtkRecentFilter *gtk_recent_chooser_get_filter (GtkRecentChooser *chooser);
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooserdefault.h
* Copyright (C) 2006 Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_DEFAULT_H__
#define __GTK_RECENT_CHOOSER_DEFAULT_H__
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_CHOOSER_DEFAULT (gtk_recent_chooser_default_get_type ())
#define GTK_RECENT_CHOOSER_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_DEFAULT, GtkRecentChooserDefault))
#define GTK_IS_RECENT_CHOOSER_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_DEFAULT))
typedef struct _GtkRecentChooserDefault GtkRecentChooserDefault;
GType _gtk_recent_chooser_default_get_type (void) G_GNUC_CONST;
GtkWidget *_gtk_recent_chooser_default_new (GtkRecentManager *recent_manager);
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_DEFAULT_H__ */

View File

@ -0,0 +1,376 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooserdialog.c: Recent files selector dialog
* Copyright (C) 2006 Emmanuele Bassi
*
* 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.
*/
#include <config.h>
#include "gtkrecentchooserdialog.h"
#include "gtkrecentchooserwidget.h"
#include "gtkrecentchooserutils.h"
#include "gtkrecentmanager.h"
#include "gtktypebuiltins.h"
#include "gtkalias.h"
#include <stdarg.h>
struct _GtkRecentChooserDialogPrivate
{
GtkRecentManager *manager;
GtkWidget *chooser;
};
#define GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE(obj) (GTK_RECENT_CHOOSER_DIALOG (obj)->priv)
static void gtk_recent_chooser_dialog_class_init (GtkRecentChooserDialogClass *klass);
static void gtk_recent_chooser_dialog_init (GtkRecentChooserDialog *dialog);
static void gtk_recent_chooser_dialog_finalize (GObject *object);
static GObject *gtk_recent_chooser_dialog_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params);
static void gtk_recent_chooser_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_recent_chooser_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_recent_chooser_dialog_map (GtkWidget *widget);
static void gtk_recent_chooser_dialog_unmap (GtkWidget *widget);
static void gtk_recent_chooser_dialog_style_set (GtkWidget *widget,
GtkStyle *old_style);
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDialog,
gtk_recent_chooser_dialog,
GTK_TYPE_DIALOG,
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
_gtk_recent_chooser_delegate_iface_init));
static void
gtk_recent_chooser_dialog_class_init (GtkRecentChooserDialogClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->set_property = gtk_recent_chooser_dialog_set_property;
gobject_class->get_property = gtk_recent_chooser_dialog_get_property;
gobject_class->constructor = gtk_recent_chooser_dialog_constructor;
gobject_class->finalize = gtk_recent_chooser_dialog_finalize;
widget_class->map = gtk_recent_chooser_dialog_map;
widget_class->unmap = gtk_recent_chooser_dialog_unmap;
widget_class->style_set = gtk_recent_chooser_dialog_style_set;
_gtk_recent_chooser_install_properties (gobject_class);
g_type_class_add_private (klass, sizeof (GtkRecentChooserDialogPrivate));
}
static void
gtk_recent_chooser_dialog_init (GtkRecentChooserDialog *dialog)
{
GtkRecentChooserDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_RECENT_CHOOSER_DIALOG,
GtkRecentChooserDialogPrivate);
dialog->priv = priv;
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
}
/* we intercept the GtkRecentChooser::item_activated signal and try to
* make the dialog emit a valid response signal
*/
static void
gtk_recent_chooser_item_activated_cb (GtkRecentChooser *chooser,
gpointer user_data)
{
GtkRecentChooserDialog *dialog;
GList *children, *l;
dialog = GTK_RECENT_CHOOSER_DIALOG (user_data);
if (gtk_window_activate_default (GTK_WINDOW (dialog)))
return;
children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
for (l = children; l; l = l->next)
{
GtkWidget *widget;
gint response_id;
widget = GTK_WIDGET (l->data);
response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
if (response_id == GTK_RESPONSE_ACCEPT ||
response_id == GTK_RESPONSE_OK ||
response_id == GTK_RESPONSE_YES ||
response_id == GTK_RESPONSE_APPLY)
{
g_list_free (children);
gtk_dialog_response (GTK_DIALOG (dialog), response_id);
return;
}
}
g_list_free (children);
}
static GObject *
gtk_recent_chooser_dialog_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
GtkRecentChooserDialogPrivate *priv;
object = G_OBJECT_CLASS (gtk_recent_chooser_dialog_parent_class)->constructor (type,
n_construct_properties,
construct_params);
priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
gtk_widget_push_composite_child ();
if (priv->manager)
priv->chooser = g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
"recent-manager", priv->manager,
NULL);
else
priv->chooser = g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
g_signal_connect (priv->chooser, "item-activated",
G_CALLBACK (gtk_recent_chooser_item_activated_cb),
object);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox),
priv->chooser, TRUE, TRUE, 0);
gtk_widget_show (priv->chooser);
_gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
GTK_RECENT_CHOOSER (priv->chooser));
gtk_widget_pop_composite_child ();
return object;
}
static void
gtk_recent_chooser_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkRecentChooserDialogPrivate *priv;
priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
switch (prop_id)
{
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
priv->manager = g_value_get_object (value);
break;
default:
g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
break;
}
}
static void
gtk_recent_chooser_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkRecentChooserDialogPrivate *priv;
priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
}
static void
gtk_recent_chooser_dialog_finalize (GObject *object)
{
GtkRecentChooserDialog *dialog = GTK_RECENT_CHOOSER_DIALOG (object);
dialog->priv->manager = NULL;
G_OBJECT_CLASS (gtk_recent_chooser_dialog_parent_class)->finalize (object);
}
static void
gtk_recent_chooser_dialog_map (GtkWidget *widget)
{
GtkRecentChooserDialog *dialog = GTK_RECENT_CHOOSER_DIALOG (widget);
GtkRecentChooserDialogPrivate *priv = dialog->priv;
if (!GTK_WIDGET_MAPPED (priv->chooser))
gtk_widget_map (priv->chooser);
GTK_WIDGET_CLASS (gtk_recent_chooser_dialog_parent_class)->map (widget);
}
static void
gtk_recent_chooser_dialog_unmap (GtkWidget *widget)
{
GtkRecentChooserDialog *dialog = GTK_RECENT_CHOOSER_DIALOG (widget);
GtkRecentChooserDialogPrivate *priv = dialog->priv;
GTK_WIDGET_CLASS (gtk_recent_chooser_dialog_parent_class)->unmap (widget);
gtk_widget_unmap (priv->chooser);
}
/* taken from gtkfilechooserdialog.c */
static void
gtk_recent_chooser_dialog_style_set (GtkWidget *widget,
GtkStyle *old_style)
{
GtkDialog *dialog;
dialog = GTK_DIALOG (widget);
/* Override the style properties with HIG-compliant spacings. Ugh.
* http://developer.gnome.org/projects/gup/hig/1.0/layout.html#layout-dialogs
* http://developer.gnome.org/projects/gup/hig/1.0/windows.html#alert-spacing
*/
gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 12);
gtk_box_set_spacing (GTK_BOX (dialog->vbox), 24);
gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0);
gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
if (GTK_WIDGET_CLASS (gtk_recent_chooser_dialog_parent_class)->style_set)
GTK_WIDGET_CLASS (gtk_recent_chooser_dialog_parent_class)->style_set (widget, old_style);
}
static GtkWidget *
gtk_recent_chooser_dialog_new_valist (const gchar *title,
GtkWindow *parent,
GtkRecentManager *manager,
const gchar *first_button_text,
va_list varargs)
{
GtkWidget *result;
const char *button_text = first_button_text;
gint response_id;
result = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
"title", title,
"recent-manager", manager,
NULL);
if (parent)
gtk_window_set_transient_for (GTK_WINDOW (result), parent);
while (button_text)
{
response_id = va_arg (varargs, gint);
gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
button_text = va_arg (varargs, const gchar *);
}
return result;
}
/**
* gtk_recent_chooser_dialog_new:
* @title: Title of the dialog, or %NULL
* @parent: Transient parent of the dialog, or %NULL,
* @first_button_text: stock ID or text to go in the first button, or %NULL
* @Varargs: response ID for the first button, then additional (button, id)
* pairs, ending with %NULL
*
* Creates a new #GtkRecentChooserDialog. This function is analogous to
* gtk_dialog_new_with_buttons().
*
* Return value: a new #GtkRecentChooserDialog
*
* Since: 2.10
*/
GtkWidget *
gtk_recent_chooser_dialog_new (const gchar *title,
GtkWindow *parent,
const gchar *first_button_text,
...)
{
GtkWidget *result;
va_list varargs;
va_start (varargs, first_button_text);
result = gtk_recent_chooser_dialog_new_valist (title,
parent,
NULL,
first_button_text,
varargs);
va_end (varargs);
return result;
}
/**
* gtk_recent_chooser_dialog_new_for_manager:
* @title: Title of the dialog, or %NULL
* @parent: Transient parent of the dialog, or %NULL,
* @manager: a #GtkRecentManager
* @first_button_text: stock ID or text to go in the first button, or %NULL
* @Varargs: response ID for the first button, then additional (button, id)
* pairs, ending with %NULL
*
* Creates a new #GtkRecentChooserDialog with a specified recent manager.
*
* This is useful if you have implemented your own recent manager, or if you
* have a customized instance of a #GtkRecentManager object.
*
* Return value: a new #GtkRecentChooserDialog
*
* Since: 2.10
*/
GtkWidget *
gtk_recent_chooser_dialog_new_for_manager (const gchar *title,
GtkWindow *parent,
GtkRecentManager *manager,
const gchar *first_button_text,
...)
{
GtkWidget *result;
va_list varargs;
va_start (varargs, first_button_text);
result = gtk_recent_chooser_dialog_new_valist (title,
parent,
manager,
first_button_text,
varargs);
va_end (varargs);
return result;
}
#define __GTK_RECENT_CHOOSER_DIALOG_C__
#include "gtkaliasdef.c"

View File

@ -0,0 +1,70 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooserdialog.h: Recent files selector dialog
* Copyright (C) 2006 Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_DIALOG_H__
#define __GTK_RECENT_CHOOSER_DIALOG_H__
#include <gtk/gtkdialog.h>
#include "gtkrecentchooser.h"
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_CHOOSER_DIALOG (gtk_recent_chooser_dialog_get_type ())
#define GTK_RECENT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialog))
#define GTK_IS_RECENT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG))
#define GTK_RECENT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialogClass))
#define GTK_IS_RECENT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_DIALOG))
#define GTK_RECENT_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialogClass))
typedef struct _GtkRecentChooserDialog GtkRecentChooserDialog;
typedef struct _GtkRecentChooserDialogClass GtkRecentChooserDialogClass;
typedef struct _GtkRecentChooserDialogPrivate GtkRecentChooserDialogPrivate;
struct _GtkRecentChooserDialog
{
/*< private >*/
GtkDialog parent_instance;
GtkRecentChooserDialogPrivate *priv;
};
struct _GtkRecentChooserDialogClass
{
GtkDialogClass parent_class;
};
GType gtk_recent_chooser_dialog_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_recent_chooser_dialog_new (const gchar *title,
GtkWindow *parent,
const gchar *first_button_text,
...) G_GNUC_NULL_TERMINATED;
GtkWidget *gtk_recent_chooser_dialog_new_for_manager (const gchar *title,
GtkWindow *parent,
GtkRecentManager *manager,
const gchar *first_button_text,
...) G_GNUC_NULL_TERMINATED;
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_DIALOG_H__ */

1225
gtk/gtkrecentchoosermenu.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
/* GTK - The GIMP Toolkit
* gtkrecentchoosermenu.h - Recently used items menu widget
* Copyright (C) 2006, Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_MENU_H__
#define __GTK_RECENT_CHOOSER_MENU_H__
#include <gtk/gtkmenu.h>
#include "gtkrecentchooser.h"
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_CHOOSER_MENU (gtk_recent_chooser_menu_get_type ())
#define GTK_RECENT_CHOOSER_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenu))
#define GTK_IS_RECENT_CHOOSER_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_MENU))
#define GTK_RECENT_CHOOSER_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenuClass))
#define GTK_IS_RECENT_CHOOSER_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_MENU))
#define GTK_RECENT_CHOOSER_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenuClass))
typedef struct _GtkRecentChooserMenu GtkRecentChooserMenu;
typedef struct _GtkRecentChooserMenuClass GtkRecentChooserMenuClass;
typedef struct _GtkRecentChooserMenuPrivate GtkRecentChooserMenuPrivate;
struct _GtkRecentChooserMenu
{
/*< private >*/
GtkMenu parent_instance;
GtkRecentChooserMenuPrivate *priv;
};
struct _GtkRecentChooserMenuClass
{
GtkMenuClass parent_class;
/* padding for future expansion */
void (* gtk_recent1) (void);
void (* gtk_recent2) (void);
void (* gtk_recent3) (void);
void (* gtk_recent4) (void);
};
GType gtk_recent_chooser_menu_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_recent_chooser_menu_new (void);
GtkWidget *gtk_recent_chooser_menu_new_for_manager (GtkRecentManager *manager);
gboolean gtk_recent_chooser_menu_get_show_numbers (GtkRecentChooserMenu *menu);
void gtk_recent_chooser_menu_set_show_numbers (GtkRecentChooserMenu *menu,
gboolean show_numbers);
G_END_DECLS
#endif /* ! __GTK_RECENT_CHOOSER_MENU_H__ */

View File

@ -0,0 +1,42 @@
/* gtkrecentprivatechooser.h - Interface definitions for recent selectors UI
*
* Copyright (C) 2006 Emmanuele Bassi
*
* All rights reserved
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_PRIVATE_H__
#define __GTK_RECENT_CHOOSER_PRIVATE_H__
#include <glib-object.h>
#include "gtkrecentmanager.h"
#include "gtkrecentchooser.h"
G_BEGIN_DECLS
#define GTK_DEFAULT_RECENT_MANAGER "gtk-recent-manager-default"
GtkRecentManager *_gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser);
void _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser);
void _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser);
G_END_DECLS
#endif /* ! __GTK_RECENT_CHOOSER_PRIVATE_H__ */

298
gtk/gtkrecentchooserutils.c Normal file
View File

@ -0,0 +1,298 @@
/* gtkrecentchooserutils.h - Private utility functions for implementing a
* GtkRecentChooser interface
*
* Copyright (C) 2006 Emmanuele Bassi
*
* All rights reserved
*
* 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.
*
* Based on gtkfilechooserutils.c:
* Copyright (C) 2003 Red Hat, Inc.
*/
#include "config.h"
#include "gtkrecentchooserutils.h"
/* Methods */
static void delegate_set_sort_func (GtkRecentChooser *chooser,
GtkRecentSortFunc sort_func,
gpointer sort_data,
GDestroyNotify data_destroy);
static void delegate_add_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
static void delegate_remove_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter);
static GSList *delegate_list_filters (GtkRecentChooser *chooser);
static gboolean delegate_select_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
static void delegate_unselect_uri (GtkRecentChooser *chooser,
const gchar *uri);
static GList *delegate_get_items (GtkRecentChooser *chooser);
static GtkRecentManager *delegate_get_recent_manager (GtkRecentChooser *chooser);
static void delegate_select_all (GtkRecentChooser *chooser);
static void delegate_unselect_all (GtkRecentChooser *chooser);
static gboolean delegate_set_current_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error);
static gchar * delegate_get_current_uri (GtkRecentChooser *chooser);
/* Signals */
static void delegate_notify (GObject *object,
GParamSpec *pspec,
gpointer user_data);
static void delegate_selection_changed (GtkRecentChooser *receiver,
gpointer user_data);
static void delegate_item_activated (GtkRecentChooser *receiver,
gpointer user_data);
/**
* _gtk_recent_chooser_install_properties:
* @klass: the class structure for a type deriving from #GObject
*
* Installs the necessary properties for a class implementing
* #GtkRecentChooser. A #GtkParamSpecOverride property is installed
* for each property, using the values from the #GtkRecentChooserProp
* enumeration. The caller must make sure itself that the enumeration
* values don't collide with some other property values they
* are using.
*/
void
_gtk_recent_chooser_install_properties (GObjectClass *klass)
{
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER,
"recent-manager");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE,
"show-private");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SHOW_TIPS,
"show-tips");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SHOW_ICONS,
"show-icons");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND,
"show-not-found");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE,
"select-multiple");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_LIMIT,
"limit");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY,
"local-only");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_SORT_TYPE,
"sort-type");
g_object_class_override_property (klass,
GTK_RECENT_CHOOSER_PROP_FILTER,
"filter");
}
/**
* _gtk_recent_chooser_delegate_iface_init:
* @iface: a #GtkRecentChooserIface
*
* An interface-initialization function for use in cases where
* an object is simply delegating the methods, signals of
* the #GtkRecentChooser interface to another object.
* _gtk_recent_chooser_set_delegate() must be called on each
* instance of the object so that the delegate object can
* be found.
*/
void
_gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface)
{
iface->set_current_uri = delegate_set_current_uri;
iface->get_current_uri = delegate_get_current_uri;
iface->select_uri = delegate_select_uri;
iface->unselect_uri = delegate_unselect_uri;
iface->select_all = delegate_select_all;
iface->unselect_all = delegate_unselect_all;
iface->get_items = delegate_get_items;
iface->get_recent_manager = delegate_get_recent_manager;
iface->set_sort_func = delegate_set_sort_func;
iface->add_filter = delegate_add_filter;
iface->remove_filter = delegate_remove_filter;
iface->list_filters = delegate_list_filters;
}
/**
* _gtk_recent_chooser_set_delegate:
* @receiver: a #GObject implementing #GtkRecentChooser
* @delegate: another #GObject implementing #GtkRecentChooser
*
* Establishes that calls on @receiver for #GtkRecentChooser
* methods should be delegated to @delegate, and that
* #GtkRecentChooser signals emitted on @delegate should be
* forwarded to @receiver. Must be used in conjunction with
* _gtk_recent_chooser_delegate_iface_init().
*/
void
_gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
GtkRecentChooser *delegate)
{
g_return_if_fail (GTK_IS_RECENT_CHOOSER (receiver));
g_return_if_fail (GTK_IS_RECENT_CHOOSER (delegate));
g_object_set_data (G_OBJECT (receiver),
"gtk-recent-chooser-delegate", delegate);
g_signal_connect (delegate, "notify",
G_CALLBACK (delegate_notify), receiver);
g_signal_connect (delegate, "selection-changed",
G_CALLBACK (delegate_selection_changed), receiver);
g_signal_connect (delegate, "item-activated",
G_CALLBACK (delegate_item_activated), receiver);
}
GQuark
_gtk_recent_chooser_delegate_get_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("gtk-recent-chooser-delegate");
return quark;
}
static GtkRecentChooser *
get_delegate (GtkRecentChooser *receiver)
{
return g_object_get_qdata (G_OBJECT (receiver),
GTK_RECENT_CHOOSER_DELEGATE_QUARK);
}
static void
delegate_set_sort_func (GtkRecentChooser *chooser,
GtkRecentSortFunc sort_func,
gpointer sort_data,
GDestroyNotify data_destroy)
{
gtk_recent_chooser_set_sort_func (get_delegate (chooser),
sort_func,
sort_data,
data_destroy);
}
static void
delegate_add_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
gtk_recent_chooser_add_filter (get_delegate (chooser), filter);
}
static void
delegate_remove_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
gtk_recent_chooser_remove_filter (get_delegate (chooser), filter);
}
static GSList *
delegate_list_filters (GtkRecentChooser *chooser)
{
return gtk_recent_chooser_list_filters (get_delegate (chooser));
}
static gboolean
delegate_select_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error)
{
return gtk_recent_chooser_select_uri (get_delegate (chooser), uri, error);
}
static void
delegate_unselect_uri (GtkRecentChooser *chooser,
const gchar *uri)
{
return gtk_recent_chooser_unselect_uri (get_delegate (chooser), uri);
}
static GList *
delegate_get_items (GtkRecentChooser *chooser)
{
return gtk_recent_chooser_get_items (get_delegate (chooser));
}
static GtkRecentManager *
delegate_get_recent_manager (GtkRecentChooser *chooser)
{
return _gtk_recent_chooser_get_recent_manager (get_delegate (chooser));
}
static void
delegate_select_all (GtkRecentChooser *chooser)
{
gtk_recent_chooser_select_all (get_delegate (chooser));
}
static void
delegate_unselect_all (GtkRecentChooser *chooser)
{
gtk_recent_chooser_unselect_all (get_delegate (chooser));
}
static gboolean
delegate_set_current_uri (GtkRecentChooser *chooser,
const gchar *uri,
GError **error)
{
return gtk_recent_chooser_set_current_uri (get_delegate (chooser), uri, error);
}
static gchar *
delegate_get_current_uri (GtkRecentChooser *chooser)
{
return gtk_recent_chooser_get_current_uri (get_delegate (chooser));
}
static void
delegate_notify (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
gpointer iface;
iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
gtk_recent_chooser_get_type ());
if (g_object_interface_find_property (iface, pspec->name))
g_object_notify (user_data, pspec->name);
}
static void
delegate_selection_changed (GtkRecentChooser *receiver,
gpointer user_data)
{
_gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
}
static void
delegate_item_activated (GtkRecentChooser *receiver,
gpointer user_data)
{
_gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
}
#define __GTK_RECENT_CHOOSER_UTILS_H__
#include "gtkaliasdef.c"

View File

@ -0,0 +1,63 @@
/* gtkrecentchooserutils.h - Private utility functions for implementing a
* GtkRecentChooser interface
*
* Copyright (C) 2006 Emmanuele Bassi
*
* All rights reserved
*
* 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.
*
* Based on gtkfilechooserutils.h:
* Copyright (C) 2003 Red Hat, Inc.
*/
#ifndef __GTK_RECENT_CHOOSER_UTILS_H__
#define __GTK_RECENT_CHOOSER_UTILS_H__
#include "gtkrecentchooserprivate.h"
G_BEGIN_DECLS
#define GTK_RECENT_CHOOSER_DELEGATE_QUARK (_gtk_recent_chooser_delegate_get_quark ())
typedef enum {
GTK_RECENT_CHOOSER_PROP_FIRST = 0x3000,
GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER,
GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE,
GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND,
GTK_RECENT_CHOOSER_PROP_SHOW_TIPS,
GTK_RECENT_CHOOSER_PROP_SHOW_ICONS,
GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE,
GTK_RECENT_CHOOSER_PROP_LIMIT,
GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY,
GTK_RECENT_CHOOSER_PROP_SORT_TYPE,
GTK_RECENT_CHOOSER_PROP_FILTER,
GTK_RECENT_CHOOSER_PROP_LAST
} GtkRecentChooserProp;
void _gtk_recent_chooser_install_properties (GObjectClass *klass);
void _gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface);
void _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
GtkRecentChooser *delegate);
GQuark _gtk_recent_chooser_delegate_get_quark (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_UTILS_H__ */

View File

@ -0,0 +1,194 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
* Copyright (C) 2006 Emmanuele Bassi
*
* 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.
*/
#include <config.h>
#include "gtkrecentchooserwidget.h"
#include "gtkrecentchooserdefault.h"
#include "gtkrecentchooserutils.h"
#include "gtktypebuiltins.h"
#include "gtkalias.h"
struct _GtkRecentChooserWidgetPrivate
{
GtkRecentManager *manager;
GtkWidget *chooser;
};
#define GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE(obj) (GTK_RECENT_CHOOSER_WIDGET (obj)->priv)
static GObject *gtk_recent_chooser_widget_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gtk_recent_chooser_widget_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_recent_chooser_widget_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_recent_chooser_widget_finalize (GObject *object);
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
gtk_recent_chooser_widget,
GTK_TYPE_VBOX,
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
_gtk_recent_chooser_delegate_iface_init));
static void
gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = gtk_recent_chooser_widget_constructor;
gobject_class->set_property = gtk_recent_chooser_widget_set_property;
gobject_class->get_property = gtk_recent_chooser_widget_get_property;
gobject_class->finalize = gtk_recent_chooser_widget_finalize;
_gtk_recent_chooser_install_properties (gobject_class);
g_type_class_add_private (klass, sizeof (GtkRecentChooserWidgetPrivate));
}
static void
gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
{
widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget, GTK_TYPE_RECENT_CHOOSER_WIDGET,
GtkRecentChooserWidgetPrivate);
}
static GObject *
gtk_recent_chooser_widget_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GtkRecentChooserWidgetPrivate *priv;
object = G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->constructor (type,
n_params,
params);
priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
priv->chooser = _gtk_recent_chooser_default_new (priv->manager);
gtk_container_add (GTK_CONTAINER (object), priv->chooser);
gtk_widget_show (priv->chooser);
_gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
GTK_RECENT_CHOOSER (priv->chooser));
return object;
}
static void
gtk_recent_chooser_widget_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkRecentChooserWidgetPrivate *priv;
priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
switch (prop_id)
{
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
priv->manager = g_value_get_object (value);
break;
default:
g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
break;
}
}
static void
gtk_recent_chooser_widget_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkRecentChooserWidgetPrivate *priv;
priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
}
static void
gtk_recent_chooser_widget_finalize (GObject *object)
{
GtkRecentChooserWidgetPrivate *priv;
priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
priv->manager = NULL;
G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
}
/*
* Public API
*/
/**
* gtk_recent_chooser_widget_new:
*
* Creates a new #GtkRecentChooserWidget object. This is an embeddable widget
* used to access the recently used resources list.
*
* Return value: a new #GtkRecentChooserWidget
*
* Since: 2.10
*/
GtkWidget *
gtk_recent_chooser_widget_new (void)
{
return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
}
/**
* gtk_recent_chooser_widget_new_for_manager:
* @manager: a #GtkRecentManager
*
* Creates a new #GtkRecentChooserWidget with a specified recent manager.
*
* This is useful if you have implemented your own recent manager, or if you
* have a customized instance of a #GtkRecentManager object.
*
* Return value: a new #GtkRecentChooserWidget
*
* Since: 2.10
*/
GtkWidget *
gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
{
g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
"recent-manager", manager,
NULL);
}
#define __GTK_RECENT_CHOOSER_WIDGET_C__
#include "gtkaliasdef.c"

View File

@ -0,0 +1,60 @@
/* GTK - The GIMP Toolkit
* gtkrecentchooserwidget.h: embeddable recently used resources chooser widget
* Copyright (C) 2006 Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_CHOOSER_WIDGET_H__
#define __GTK_RECENT_CHOOSER_WIDGET_H__
#include "gtkrecentchooser.h"
#include <gtk/gtkvbox.h>
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_CHOOSER_WIDGET (gtk_recent_chooser_widget_get_type ())
#define GTK_RECENT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidget))
#define GTK_IS_RECENT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET))
#define GTK_RECENT_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidgetClass))
#define GTK_IS_RECENT_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_WIDGET))
#define GTK_RECENT_CHOOSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidgetClass))
typedef struct _GtkRecentChooserWidget GtkRecentChooserWidget;
typedef struct _GtkRecentChooserWidgetClass GtkRecentChooserWidgetClass;
typedef struct _GtkRecentChooserWidgetPrivate GtkRecentChooserWidgetPrivate;
struct _GtkRecentChooserWidget
{
/*< private >*/
GtkVBox parent_instance;
GtkRecentChooserWidgetPrivate *priv;
};
struct _GtkRecentChooserWidgetClass
{
GtkVBoxClass parent_class;
};
GType gtk_recent_chooser_widget_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_recent_chooser_widget_new (void);
GtkWidget *gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager);
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_WIDGET_H__ */

579
gtk/gtkrecentfilter.c Normal file
View File

@ -0,0 +1,579 @@
/* GTK - The GIMP Toolkit
* gtkrecentfilter.h - Filter object for recently used resources
* Copyright (C) 2006, Emmanuele Bassi
*
* 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.
*/
#include "config.h"
#include <string.h>
#include "gtkrecentfilter.h"
#include "gtkobject.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkalias.h"
#ifdef G_OS_UNIX
#define XDG_PREFIX _gtk_xdg
#include "xdgmime/xdgmime.h"
#endif
typedef struct _GtkRecentFilterClass GtkRecentFilterClass;
typedef struct _FilterRule FilterRule;
typedef enum {
FILTER_RULE_URI,
FILTER_RULE_DISPLAY_NAME,
FILTER_RULE_MIME_TYPE,
FILTER_RULE_PIXBUF_FORMATS,
FILTER_RULE_APPLICATION,
FILTER_RULE_AGE,
FILTER_RULE_GROUP,
FILTER_RULE_CUSTOM,
} FilterRuleType;
struct _GtkRecentFilter
{
GtkObject parent_instance;
gchar *name;
GSList *rules;
GtkRecentFilterFlags needed;
};
struct _GtkRecentFilterClass
{
GtkObjectClass parent_class;
};
struct _FilterRule
{
FilterRuleType type;
GtkRecentFilterFlags needed;
union {
gchar *uri;
gchar *pattern;
gchar *mime_type;
GSList *pixbuf_formats;
gchar *application;
gchar *group;
gint age;
struct {
GtkRecentFilterFunc func;
gpointer data;
GDestroyNotify data_destroy;
} custom;
} u;
};
G_DEFINE_TYPE (GtkRecentFilter, gtk_recent_filter, GTK_TYPE_OBJECT);
static void
filter_rule_free (FilterRule *rule)
{
switch (rule->type)
{
case FILTER_RULE_MIME_TYPE:
g_free (rule->u.mime_type);
break;
case FILTER_RULE_URI:
g_free (rule->u.uri);
break;
case FILTER_RULE_DISPLAY_NAME:
g_free (rule->u.pattern);
break;
case FILTER_RULE_PIXBUF_FORMATS:
g_slist_free (rule->u.pixbuf_formats);
break;
case FILTER_RULE_AGE:
break;
case FILTER_RULE_APPLICATION:
g_free (rule->u.application);
break;
case FILTER_RULE_GROUP:
g_free (rule->u.group);
break;
case FILTER_RULE_CUSTOM:
if (rule->u.custom.data_destroy)
rule->u.custom.data_destroy (rule->u.custom.data);
break;
default:
g_assert_not_reached ();
break;
}
g_free (rule);
}
static void
gtk_recent_filter_finalize (GObject *object)
{
GtkRecentFilter *filter = GTK_RECENT_FILTER (object);
if (filter->name)
g_free (filter->name);
if (filter->rules)
{
g_slist_foreach (filter->rules,
(GFunc) filter_rule_free,
NULL);
g_slist_free (filter->rules);
}
G_OBJECT_CLASS (gtk_recent_filter_parent_class)->finalize (object);
}
static void
gtk_recent_filter_class_init (GtkRecentFilterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = gtk_recent_filter_finalize;
}
static void
gtk_recent_filter_init (GtkRecentFilter *filter)
{
}
/*
* Public API
*/
/**
* gtk_recent_filter_new:
*
* Creates a new #GtkRecentFilter with no rules added to it.
* Such filter does not accept any recently used resources, so is not
* particularly useful until you add rules with
* gtk_recent_filter_add_pattern(), gtk_recent_filter_add_mime_type(),
* gtk_recent_filter_add_application(), gtk_recent_filter_add_age().
* To create a filter that accepts any recently used resource, use:
*
* <informalexample><programlisting>
* GtkRecentFilter *filter = gtk_recent_filter_new (<!-- -->);
* gtk_recent_filter_add_pattern (filter, "*");
* </programlisting></informalexample>
*
* Return value: a new #GtkRecentFilter
*
* Since: 2.10
*/
GtkRecentFilter *
gtk_recent_filter_new (void)
{
return g_object_new (GTK_TYPE_RECENT_FILTER, NULL);
}
/**
* gtk_recent_filter_set_name:
* @filter: a #GtkRecentFilter
* @name: then human readable name of @filter
*
* Sets the human-readable name of the filter; this is the string
* that will be displayed in the recently used resources selector
* user interface if there is a selectable list of filters.
*
* Since: 2.10
*/
void
gtk_recent_filter_set_name (GtkRecentFilter *filter,
const gchar *name)
{
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
if (filter->name)
g_free (filter->name);
if (name)
filter->name = g_strdup (name);
}
/**
* gtk_recent_filter_get_name:
* @filter: a #GtkRecentFilter
*
* Gets the human-readable name for the filter.
* See gtk_recent_filter_set_name().
*
* Return value: the name of the filter, or %NULL. The returned string
* is owned by the filter object and should not be freed.
*
* Since: 2.10
*/
G_CONST_RETURN gchar *
gtk_recent_filter_get_name (GtkRecentFilter *filter)
{
g_return_val_if_fail (GTK_IS_RECENT_FILTER (filter), NULL);
return filter->name;
}
/**
* gtk_recent_filter_get_needed:
* @filter: a #GtkRecentFilter
*
* Gets the fields that need to be filled in for the structure
* passed to gtk_recent_filter_filter()
*
* This function will not typically be used by applications; it
* is intended principally for use in the implementation of
* #GtkRecentChooser.
*
* Return value: bitfield of flags indicating needed fields when
* calling gtk_recent_filter_filter()
*
* Since: 2.10
*/
GtkRecentFilterFlags
gtk_recent_filter_get_needed (GtkRecentFilter *filter)
{
return filter->needed;
}
static void
recent_filter_add_rule (GtkRecentFilter *filter,
FilterRule *rule)
{
filter->needed |= rule->needed;
filter->rules = g_slist_append (filter->rules, rule);
}
/**
* gtk_recent_filter_add_mime_type:
* @filter: a #GtkRecentFilter
* @mime_type: a MIME type
*
* Adds a rule that allows resources based on their registered MIME type.
*
* Since: 2.10
*/
void
gtk_recent_filter_add_mime_type (GtkRecentFilter *filter,
const gchar *mime_type)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_return_if_fail (mime_type != NULL);
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_MIME_TYPE;
rule->needed = GTK_RECENT_FILTER_MIME_TYPE;
rule->u.mime_type = g_strdup (mime_type);
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_pattern:
* @filter: a #GtkRecentFilter
* @pattern: a file pattern
*
* Adds a rule that allows resources based on a pattern matching their
* display name.
*
* Since: 2.10
*/
void
gtk_recent_filter_add_pattern (GtkRecentFilter *filter,
const gchar *pattern)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_return_if_fail (pattern != NULL);
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_DISPLAY_NAME;
rule->needed = GTK_RECENT_FILTER_DISPLAY_NAME;
rule->u.pattern = g_strdup (pattern);
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_pixbuf_formats:
* @filter: a #GtkRecentFilter
*
* Adds a rule allowing image files in the formats supported
* by GdkPixbuf.
*
* Since: 2.10
*/
void
gtk_recent_filter_add_pixbuf_formats (GtkRecentFilter *filter)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_PIXBUF_FORMATS;
rule->needed = GTK_RECENT_FILTER_MIME_TYPE;
rule->u.pixbuf_formats = gdk_pixbuf_get_formats ();
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_application:
* @filter: a #GtkRecentFilter
* @application: an application name
*
* Adds a rule that allows resources based on the name of the application
* that has registered them.
*
* Since: 2.10
*/
void
gtk_recent_filter_add_application (GtkRecentFilter *filter,
const gchar *application)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_return_if_fail (application != NULL);
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_APPLICATION;
rule->needed = GTK_RECENT_FILTER_APPLICATION;
rule->u.application = g_strdup (application);
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_group:
* @filter: a #GtkRecentFilter
* @group: a group name
*
* Adds a rule that allows resources based on the name of the group
* to which they belong
*
* Since: 2.10
*/
void
gtk_recent_filter_add_group (GtkRecentFilter *filter,
const gchar *group)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_return_if_fail (group != NULL);
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_GROUP;
rule->needed = GTK_RECENT_FILTER_GROUP;
rule->u.group = g_strdup (group);
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_mime_type:
* @filter: a #GtkRecentFilter
* @days: number of days
*
* Adds a rule that allows resources based on their age - that is, the number
* of days elapsed since they were last modified.
*
* Since: 2.10
*/
void
gtk_recent_filter_add_age (GtkRecentFilter *filter,
gint days)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_AGE;
rule->needed = GTK_RECENT_FILTER_AGE;
rule->u.age = days;
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_add_custom:
* @filter: a #GtkRecentFilter
* @needed: bitfield of flags indicating the information that the custom
* filter function needs.
* @func: callback function; if the function returns %TRUE, then
* the file will be displayed.
* @data: data to pass to @func
* @data_destroy: function to call to free @data when it is no longer needed.
*
* Adds a rule to a filter that allows resources based on a custom callback
* function. The bitfield @needed which is passed in provides information
* about what sorts of information that the filter function needs;
* this allows GTK+ to avoid retrieving expensive information when
* it isn't needed by the filter.
*
* Since: 2.10
**/
void
gtk_recent_filter_add_custom (GtkRecentFilter *filter,
GtkRecentFilterFlags needed,
GtkRecentFilterFunc func,
gpointer data,
GDestroyNotify data_destroy)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
g_return_if_fail (func != NULL);
rule = g_new0 (FilterRule, 1);
rule->type = FILTER_RULE_CUSTOM;
rule->needed = needed;
rule->u.custom.func = func;
rule->u.custom.data = data;
rule->u.custom.data_destroy = data_destroy;
recent_filter_add_rule (filter, rule);
}
/**
* gtk_recent_filter_filter:
* @filter: a #GtkRecentFilter
* @filter_info: a #GtkRecentFilterInfo structure containing information
* about a recently used resource
*
* Tests whether a file should be displayed according to @filter.
* The #GtkRecentFilterInfo structure @filter_info should include
* the fields returned from gtk_recent_filter_get_needed().
*
* This function will not typically be used by applications; it
* is intended principally for use in the implementation of
* #GtkRecentChooser.
*
* Return value: %TRUE if the file should be displayed
*/
gboolean
gtk_recent_filter_filter (GtkRecentFilter *filter,
const GtkRecentFilterInfo *filter_info)
{
GSList *l;
g_return_val_if_fail (GTK_IS_RECENT_FILTER (filter), FALSE);
g_return_val_if_fail (filter_info != NULL, FALSE);
for (l = filter->rules; l != NULL; l = l->next)
{
FilterRule *rule = (FilterRule *) l->data;
if ((filter_info->contains & rule->needed) != rule->needed)
continue;
switch (rule->type)
{
case FILTER_RULE_MIME_TYPE:
if ((filter_info->mime_type != NULL)
#ifdef G_OS_UNIX
&& (xdg_mime_mime_type_subclass (filter_info->mime_type, rule->u.mime_type)))
#else
&& (strcmp (filter_info->mime_type, rule->u.mime_type) == 0))
#endif
return TRUE;
break;
case FILTER_RULE_APPLICATION:
if (filter_info->applications)
{
gint i;
for (i = 0; filter_info->applications[i] != NULL; i++)
{
if (strcmp (filter_info->applications[i], rule->u.application) == 0)
return TRUE;
}
}
break;
case FILTER_RULE_GROUP:
if (filter_info->groups)
{
gint i;
for (i = 0; filter_info->groups[i] != NULL; i++)
{
if (strcmp (filter_info->groups[i], rule->u.group) == 0)
return TRUE;
}
}
break;
case FILTER_RULE_PIXBUF_FORMATS:
{
GSList *list;
if (!filter_info->mime_type)
break;
for (list = rule->u.pixbuf_formats; list; list = list->next)
{
gint i;
gchar **mime_types;
mime_types = gdk_pixbuf_format_get_mime_types (list->data);
for (i = 0; mime_types[i] != NULL; i++)
{
if (strcmp (mime_types[i], filter_info->mime_type) == 0)
{
g_strfreev (mime_types);
return TRUE;
}
}
g_strfreev (mime_types);
}
break;
}
case FILTER_RULE_URI:
if ((filter_info->uri != NULL) &&
_gtk_fnmatch (rule->u.uri, filter_info->uri, FALSE))
return TRUE;
break;
case FILTER_RULE_DISPLAY_NAME:
if ((filter_info->display_name != NULL) &&
_gtk_fnmatch (rule->u.pattern, filter_info->display_name, FALSE))
return TRUE;
break;
case FILTER_RULE_AGE:
if ((filter_info->age != -1) &&
(filter_info->age < rule->u.age))
return TRUE;
break;
case FILTER_RULE_CUSTOM:
if (rule->u.custom.func (filter_info, rule->u.custom.data))
return TRUE;
break;
}
}
return FALSE;
}
#define __GTK_RECENT_FILTER_C__
#include "gtkaliasdef.c"

90
gtk/gtkrecentfilter.h Normal file
View File

@ -0,0 +1,90 @@
/* GTK - The GIMP Toolkit
* gtkrecentfilter.h - Filter object for recently used resources
* Copyright (C) 2006, Emmanuele Bassi
*
* 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.
*/
#ifndef __GTK_RECENT_FILTER_H__
#define __GTK_RECENT_FILTER_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_FILTER (gtk_recent_filter_get_type ())
#define GTK_RECENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_FILTER, GtkRecentFilter))
#define GTK_IS_RECENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_FILTER))
typedef struct _GtkRecentFilter GtkRecentFilter;
typedef struct _GtkRecentFilterInfo GtkRecentFilterInfo;
typedef enum {
GTK_RECENT_FILTER_URI = 1 << 0,
GTK_RECENT_FILTER_DISPLAY_NAME = 1 << 1,
GTK_RECENT_FILTER_MIME_TYPE = 1 << 2,
GTK_RECENT_FILTER_APPLICATION = 1 << 3,
GTK_RECENT_FILTER_GROUP = 1 << 4,
GTK_RECENT_FILTER_AGE = 1 << 5
} GtkRecentFilterFlags;
typedef gboolean (*GtkRecentFilterFunc) (const GtkRecentFilterInfo *filter_info,
gpointer user_data);
struct _GtkRecentFilterInfo
{
GtkRecentFilterFlags contains;
const gchar *uri;
const gchar *display_name;
const gchar *mime_type;
const gchar **applications;
const gchar **groups;
gint age;
};
GType gtk_recent_filter_get_type (void) G_GNUC_CONST;
GtkRecentFilter * gtk_recent_filter_new (void);
void gtk_recent_filter_set_name (GtkRecentFilter *filter,
const gchar *name);
G_CONST_RETURN gchar *gtk_recent_filter_get_name (GtkRecentFilter *filter);
void gtk_recent_filter_add_mime_type (GtkRecentFilter *filter,
const gchar *mime_type);
void gtk_recent_filter_add_pattern (GtkRecentFilter *filter,
const gchar *pattern);
void gtk_recent_filter_add_pixbuf_formats (GtkRecentFilter *filter);
void gtk_recent_filter_add_application (GtkRecentFilter *filter,
const gchar *application);
void gtk_recent_filter_add_group (GtkRecentFilter *filter,
const gchar *group);
void gtk_recent_filter_add_age (GtkRecentFilter *filter,
gint days);
void gtk_recent_filter_add_custom (GtkRecentFilter *filter,
GtkRecentFilterFlags needed,
GtkRecentFilterFunc func,
gpointer data,
GDestroyNotify data_destroy);
GtkRecentFilterFlags gtk_recent_filter_get_needed (GtkRecentFilter *filter);
gboolean gtk_recent_filter_filter (GtkRecentFilter *filter,
const GtkRecentFilterInfo *filter_info);
G_END_DECLS
#endif /* ! __GTK_RECENT_FILTER_H__ */

2424
gtk/gtkrecentmanager.c Normal file

File diff suppressed because it is too large Load Diff

214
gtk/gtkrecentmanager.h Normal file
View File

@ -0,0 +1,214 @@
/* GTK - The GIMP Toolkit
* gtkrecentmanager.h: a manager for the recently used resources
*
* Copyright (C) 2006 Emmanuele Bassi
*
* 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,
*/
#ifndef __GTK_RECENT_MANAGER_H__
#define __GTK_RECENT_MANAGER_H__
#include <glib-object.h>
#include <gdk/gdkscreen.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <time.h>
G_BEGIN_DECLS
#define GTK_TYPE_RECENT_INFO (gtk_recent_info_get_type ())
#define GTK_TYPE_RECENT_MANAGER (gtk_recent_manager_get_type ())
#define GTK_RECENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManager))
#define GTK_IS_RECENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_MANAGER))
#define GTK_RECENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerClass))
#define GTK_IS_RECENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_MANAGER))
#define GTK_RECENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerClass))
typedef struct _GtkRecentInfo GtkRecentInfo;
typedef struct _GtkRecentData GtkRecentData;
typedef struct _GtkRecentManager GtkRecentManager;
typedef struct _GtkRecentManagerClass GtkRecentManagerClass;
typedef struct _GtkRecentManagerPrivate GtkRecentManagerPrivate;
/**
* GtkRecentData:
*
* @display_name: a UTF-8 encoded string, containing the name of the recently
* used resource to be displayed, or %NULL;
* @description: a UTF-8 encoded string, containing a short description of
* the resource, or %NULL;
* @mime_type: the MIME type of the resource;
* @app_name: the name of the application that is registering this recently
* used resource;
* @app_exec: command line used to launch this resource; may contain the
* "%f" and "%u" escape characters which will be expanded to the resource
* file path and URI respectively when the command line is retrieved;
* @groups: a vector of strings containing groups names;
* @is_private: whether this resource should be displayed only by the
* applications that have registered it or not.
*
* Meta-data to be passed to gtk_recent_manager_add_full() when
* registering a recently used resource.
**/
struct _GtkRecentData
{
gchar *display_name;
gchar *description;
gchar *mime_type;
gchar *app_name;
gchar *app_exec;
gchar **groups;
gboolean is_private;
};
struct _GtkRecentManager
{
/*< private >*/
GObject parent_instance;
GtkRecentManagerPrivate *priv;
};
struct _GtkRecentManagerClass
{
/*< private >*/
GObjectClass parent_class;
void (*changed) (GtkRecentManager *manager);
/* padding for future expansion */
void (*_gtk_recent1) (void);
void (*_gtk_recent2) (void);
void (*_gtk_recent3) (void);
void (*_gtk_recent4) (void);
};
/**
* GtkRecentManagerError:
* @GTK_RECENT_MANAGER_ERROR_NOT_FOUND: the URI specified does not exists in
* the recently used resources list.
* @GTK_RECENT_MANAGER_ERROR_INVALID_URI: the URI specified is not valid.
* @GTK_RECENT_MANAGER_ERROR_INVALID_MIME: the MIME type specified is not
* valid.
* @GTK_RECENT_MANAGER_ERROR_INVALID_ENCODING: the supplied string is not
* UTF-8 encoded.
* @GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED: no application has registered
* the specified item.
* @GTK_RECENT_MANAGER_ERROR_READ: failure while reading the recently used
* resources file.
* @GTK_RECENT_MANAGER_ERROR_WRITE: failure while writing the recently used
* resources file.
* @GTK_RECENT_MANAGER_ERROR_UNKNOWN: unspecified error.
*
* Error codes for GtkRecentManager operations
**/
typedef enum
{
GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
GTK_RECENT_MANAGER_ERROR_INVALID_URI,
GTK_RECENT_MANAGER_ERROR_INVALID_MIME,
GTK_RECENT_MANAGER_ERROR_INVALID_ENCODING,
GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED,
GTK_RECENT_MANAGER_ERROR_BAD_EXEC_STRING,
GTK_RECENT_MANAGER_ERROR_READ,
GTK_RECENT_MANAGER_ERROR_WRITE,
GTK_RECENT_MANAGER_ERROR_UNKNOWN
} GtkRecentManagerError;
#define GTK_RECENT_MANAGER_ERROR (gtk_recent_manager_error_quark ())
GQuark gtk_recent_manager_error_quark (void);
GType gtk_recent_manager_get_type (void) G_GNUC_CONST;
GtkRecentManager *gtk_recent_manager_new (void);
GtkRecentManager *gtk_recent_manager_get_default (void);
GtkRecentManager *gtk_recent_manager_get_for_screen (GdkScreen *screen);
void gtk_recent_manager_set_screen (GtkRecentManager *manager,
GdkScreen *screen);
gboolean gtk_recent_manager_add_item (GtkRecentManager *manager,
const gchar *uri,
GError **error);
gboolean gtk_recent_manager_add_full (GtkRecentManager *manager,
const gchar *uri,
const GtkRecentData *recent_data,
GError **error);
gboolean gtk_recent_manager_remove_item (GtkRecentManager *manager,
const gchar *uri,
GError **error);
GtkRecentInfo * gtk_recent_manager_lookup_item (GtkRecentManager *manager,
const gchar *uri,
GError **error);
gboolean gtk_recent_manager_has_item (GtkRecentManager *manager,
const gchar *uri);
gboolean gtk_recent_manager_move_item (GtkRecentManager *manager,
const gchar *uri,
const gchar *new_uri,
GError **error);
void gtk_recent_manager_set_limit (GtkRecentManager *manager,
gint limit);
gint gtk_recent_manager_get_limit (GtkRecentManager *manager);
GList * gtk_recent_manager_get_items (GtkRecentManager *manager);
gint gtk_recent_manager_purge_items (GtkRecentManager *manager,
GError **error);
GType gtk_recent_info_get_type (void) G_GNUC_CONST;
GtkRecentInfo * gtk_recent_info_ref (GtkRecentInfo *info);
void gtk_recent_info_unref (GtkRecentInfo *info);
G_CONST_RETURN gchar *gtk_recent_info_get_uri (GtkRecentInfo *info);
G_CONST_RETURN gchar *gtk_recent_info_get_display_name (GtkRecentInfo *info);
G_CONST_RETURN gchar *gtk_recent_info_get_description (GtkRecentInfo *info);
G_CONST_RETURN gchar *gtk_recent_info_get_mime_type (GtkRecentInfo *info);
time_t gtk_recent_info_get_added (GtkRecentInfo *info);
time_t gtk_recent_info_get_modified (GtkRecentInfo *info);
time_t gtk_recent_info_get_visited (GtkRecentInfo *info);
gboolean gtk_recent_info_get_private_hint (GtkRecentInfo *info);
gboolean gtk_recent_info_get_application_info (GtkRecentInfo *info,
const gchar *app_name,
gchar **app_exec,
guint *count,
time_t *time);
gchar ** gtk_recent_info_get_applications (GtkRecentInfo *info,
gsize *length) G_GNUC_MALLOC;
gchar * gtk_recent_info_last_application (GtkRecentInfo *info) G_GNUC_MALLOC;
gboolean gtk_recent_info_has_application (GtkRecentInfo *info,
const gchar *app_name);
gchar ** gtk_recent_info_get_groups (GtkRecentInfo *info,
gsize *length) G_GNUC_MALLOC;
gboolean gtk_recent_info_has_group (GtkRecentInfo *info,
const gchar *group_name);
GdkPixbuf * gtk_recent_info_get_icon (GtkRecentInfo *info,
gint size);
gchar * gtk_recent_info_get_short_name (GtkRecentInfo *info) G_GNUC_MALLOC;
gchar * gtk_recent_info_get_uri_display (GtkRecentInfo *info) G_GNUC_MALLOC;
gint gtk_recent_info_get_age (GtkRecentInfo *info);
gboolean gtk_recent_info_is_local (GtkRecentInfo *info);
gboolean gtk_recent_info_exists (GtkRecentInfo *info);
gboolean gtk_recent_info_match (GtkRecentInfo *info_a,
GtkRecentInfo *info_b);
G_END_DECLS
#endif /* __GTK_RECENT_MANAGER_H__ */