summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2007-03-14 10:33:36 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2007-03-14 10:33:36 +0000
commit86ea351bd71aaf1c420b9a3b1cee74649f197b8a (patch)
treebbe071490825a78940a36ce00a1d6f457900bde5
parent4b3364ccc947230f62be8339ad7476d7151bfb51 (diff)
downloadgtk+-86ea351bd71aaf1c420b9a3b1cee74649f197b8a.tar.gz
Various clean ups in the GtkRecent code. (see #338843)
2007-03-14 Emmanuele Bassi <ebassi@gnome.org> Various clean ups in the GtkRecent code. (see #338843) * gtk/gtkrecentchooserdefault.c: * gtk/gtkrecentchoosermenu.c: * gtk/gtkrecentchooserprivate.h: * gtk/gtkrecentchooserutils.c: Move the recent chooser function for getting the sorted and clamped list of recent files from the manager outside the implementations. * gtk/gtkrecentchooserdefault.c (chooser_set_sort_type): Repopulate the list when the sorting order changes. (gtk_recent_chooser_default_dispose), (gtk_recent_chooser_default_finalize): Move object unref and source removal from finalize to dispose. * gtk/gtkrecentchooser.c (gtk_recent_chooser_type_init): Relax the prerequisite for the GtkRecentChooser interface implementations, from GtkObject to GObject. (gtk_recent_chooser_class_init): Use GTK_PARAM_* instead of G_PARAM_* svn path=/trunk/; revision=17514
-rw-r--r--ChangeLog25
-rw-r--r--gtk/gtkrecentchooser.c22
-rw-r--r--gtk/gtkrecentchooserdefault.c231
-rw-r--r--gtk/gtkrecentchoosermenu.c149
-rw-r--r--gtk/gtkrecentchooserprivate.h11
-rw-r--r--gtk/gtkrecentchooserutils.c136
-rw-r--r--gtk/gtkrecentchooserutils.h1
7 files changed, 290 insertions, 285 deletions
diff --git a/ChangeLog b/ChangeLog
index 69728d6c3d..5bb8b14a13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2007-03-14 Emmanuele Bassi <ebassi@gnome.org>
+
+ Various clean ups in the GtkRecent code. (see #338843)
+
+ * gtk/gtkrecentchooserdefault.c:
+ * gtk/gtkrecentchoosermenu.c:
+ * gtk/gtkrecentchooserprivate.h:
+ * gtk/gtkrecentchooserutils.c: Move the recent chooser function
+ for getting the sorted and clamped list of recent files from the
+ manager outside the implementations.
+
+ * gtk/gtkrecentchooserdefault.c (chooser_set_sort_type): Repopulate
+ the list when the sorting order changes.
+
+ (gtk_recent_chooser_default_dispose),
+ (gtk_recent_chooser_default_finalize): Move object unref and
+ source removal from finalize to dispose.
+
+ * gtk/gtkrecentchooser.c (gtk_recent_chooser_type_init): Relax the
+ prerequisite for the GtkRecentChooser interface implementations,
+ from GtkObject to GObject.
+
+ (gtk_recent_chooser_class_init): Use GTK_PARAM_* instead of
+ G_PARAM_*
+
2007-03-13 Emmanuele Bassi <ebassi@gnome.org>
Apply patch by Vytautas Liuolia for changing the startup
diff --git a/gtk/gtkrecentchooser.c b/gtk/gtkrecentchooser.c
index d8cc65e6d1..ef16d77766 100644
--- a/gtk/gtkrecentchooser.c
+++ b/gtk/gtkrecentchooser.c
@@ -56,7 +56,7 @@ gtk_recent_chooser_get_type (void)
(GClassInitFunc) gtk_recent_chooser_class_init,
0, NULL, 0);
- g_type_interface_add_prerequisite (chooser_type, GTK_TYPE_OBJECT);
+ g_type_interface_add_prerequisite (chooser_type, G_TYPE_OBJECT);
}
return chooser_type;
@@ -112,43 +112,43 @@ gtk_recent_chooser_class_init (gpointer g_iface)
P_("Recent Manager"),
P_("The RecentManager object to use"),
GTK_TYPE_RECENT_MANAGER,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ GTK_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));
+ GTK_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));
+ GTK_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));
+ GTK_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));
+ GTK_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));
+ GTK_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));
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (g_iface,
g_param_spec_int ("limit",
P_("Limit"),
@@ -156,20 +156,20 @@ gtk_recent_chooser_class_init (gpointer g_iface)
-1,
G_MAXINT,
-1,
- G_PARAM_READWRITE));
+ GTK_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));
+ GTK_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));
+ GTK_PARAM_READWRITE));
}
GQuark
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index fcac5ca286..faffa7ffc2 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -75,6 +75,7 @@
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserdefault.h"
+#include "gtkprivate.h"
#include "gtkalias.h"
@@ -178,6 +179,7 @@ static GObject *gtk_recent_chooser_default_constructor (GType
guint n_construct_prop,
GObjectConstructParam *construct_params);
static void gtk_recent_chooser_default_finalize (GObject *object);
+static void gtk_recent_chooser_default_dispose (GObject *object);
static void gtk_recent_chooser_default_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -313,10 +315,11 @@ _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- gobject_class->constructor = gtk_recent_chooser_default_constructor;
- gobject_class->finalize = gtk_recent_chooser_default_finalize;
+ gobject_class->constructor = gtk_recent_chooser_default_constructor;
gobject_class->set_property = gtk_recent_chooser_default_set_property;
gobject_class->get_property = gtk_recent_chooser_default_get_property;
+ gobject_class->dispose = gtk_recent_chooser_default_dispose;
+ gobject_class->finalize = gtk_recent_chooser_default_finalize;
widget_class->map = gtk_recent_chooser_default_map;
widget_class->show_all = gtk_recent_chooser_default_show_all;
@@ -359,17 +362,17 @@ _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
static GObject *
gtk_recent_chooser_default_constructor (GType type,
- guint n_construct_prop,
- GObjectConstructParam *construct_params)
+ guint n_params,
+ GObjectConstructParam *params)
{
+ GObjectClass *parent_class;
GtkRecentChooserDefault *impl;
GObject *object;
-
GtkWidget *scrollw;
GtkCellRenderer *renderer;
-
- object = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->constructor (type, n_construct_prop, construct_params);
+ parent_class = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class);
+ object = parent_class->constructor (type, n_params, params);
impl = GTK_RECENT_CHOOSER_DEFAULT (object);
g_assert (impl->manager);
@@ -397,7 +400,8 @@ gtk_recent_chooser_default_constructor (GType type,
g_signal_connect (impl->recent_view, "drag_data_get",
G_CALLBACK (recent_view_drag_data_get_cb), impl);
- g_object_set_data (G_OBJECT (impl->recent_view), "GtkRecentChooserDefault", impl);
+ g_object_set_data (G_OBJECT (impl->recent_view),
+ "GtkRecentChooserDefault", impl);
gtk_container_add (GTK_CONTAINER (scrollw), impl->recent_view);
gtk_widget_show (impl->recent_view);
@@ -587,15 +591,19 @@ gtk_recent_chooser_default_get_property (GObject *object,
}
static void
-gtk_recent_chooser_default_finalize (GObject *object)
+gtk_recent_chooser_default_dispose (GObject *object)
{
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
+ if (impl->load_id)
+ {
+ g_source_remove (impl->load_id);
+ impl->load_id = 0;
+ }
+
if (impl->recent_items)
{
- g_list_foreach (impl->recent_items,
- (GFunc) gtk_recent_info_unref,
- NULL);
+ g_list_foreach (impl->recent_items, (GFunc) gtk_recent_info_unref, NULL);
g_list_free (impl->recent_items);
impl->recent_items = NULL;
}
@@ -606,36 +614,55 @@ gtk_recent_chooser_default_finalize (GObject *object)
impl->manager_changed_id = 0;
}
- impl->manager = NULL;
-
- if (impl->sort_data_destroy)
- {
- impl->sort_data_destroy (impl->sort_data);
-
- impl->sort_data_destroy = NULL;
- impl->sort_data = NULL;
- impl->sort_func = NULL;
- }
-
if (impl->filters)
{
- g_slist_foreach (impl->filters,
- (GFunc) g_object_unref,
- NULL);
- g_slist_free (impl->filters);
+ g_slist_foreach (impl->filters, (GFunc) g_object_unref, NULL);
+ g_slist_free (impl->filters);
+ impl->filters = NULL;
}
if (impl->current_filter)
- g_object_unref (impl->current_filter);
+ {
+ g_object_unref (impl->current_filter);
+ impl->current_filter = NULL;
+ }
if (impl->recent_store_filter)
- g_object_unref (impl->recent_store_filter);
+ {
+ g_object_unref (impl->recent_store_filter);
+ impl->recent_store_filter = NULL;
+ }
if (impl->recent_store)
- g_object_unref (impl->recent_store);
+ {
+ g_object_unref (impl->recent_store);
+ impl->recent_store = NULL;
+ }
if (impl->tooltips)
- g_object_unref (impl->tooltips);
+ {
+ g_object_unref (impl->tooltips);
+ impl->tooltips = NULL;
+ }
+
+ G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
+}
+
+static void
+gtk_recent_chooser_default_finalize (GObject *object)
+{
+ GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
+
+ impl->manager = NULL;
+
+ if (impl->sort_data_destroy)
+ {
+ impl->sort_data_destroy (impl->sort_data);
+ impl->sort_data_destroy = NULL;
+ }
+
+ impl->sort_data = NULL;
+ impl->sort_func = NULL;
G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
}
@@ -879,9 +906,9 @@ reload_recent_items (GtkRecentChooserDefault *impl)
impl->load_state = LOAD_EMPTY;
impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
- load_recent_items,
- impl,
- cleanup_after_load);
+ load_recent_items,
+ impl,
+ cleanup_after_load);
}
/* taken form gtkfilechooserdialog.c */
@@ -1209,11 +1236,11 @@ gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
if (impl->sort_data_destroy)
{
impl->sort_data_destroy (impl->sort_data);
-
- impl->sort_func = NULL;
- impl->sort_data = NULL;
impl->sort_data_destroy = NULL;
}
+
+ impl->sort_func = NULL;
+ impl->sort_data = NULL;
if (sort_func)
{
@@ -1223,129 +1250,22 @@ gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
}
}
-static gint
-sort_recent_items_mru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) < gtk_recent_info_get_modified (b));
-}
-
-static gint
-sort_recent_items_lru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) > gtk_recent_info_get_modified (b));
-}
-
-/* our proxy sorting function */
-static gint
-sort_recent_items_proxy (gpointer *a,
- gpointer *b,
- gpointer user_data)
-{
- GtkRecentInfo *info_a = (GtkRecentInfo *) a;
- GtkRecentInfo *info_b = (GtkRecentInfo *) b;
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- if (impl->sort_func)
- return (* impl->sort_func) (info_a,
- info_b,
- impl->sort_data);
-
- /* fallback */
- return 0;
-}
-
-static void
-chooser_set_sort_type (GtkRecentChooserDefault *impl,
- GtkRecentSortType sort_type)
-{
- if (impl->sort_type == sort_type)
- return;
-
- impl->sort_type = sort_type;
-}
-
static GList *
gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
{
GtkRecentChooserDefault *impl;
- gint limit;
- GtkRecentSortType sort_type;
- GList *items;
- GCompareDataFunc compare_func;
- gint length;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- if (!impl->manager)
- return NULL;
- items = gtk_recent_manager_get_items (impl->manager);
- if (!items)
- return NULL;
-
- limit = gtk_recent_chooser_get_limit (chooser);
- if (limit == 0)
- return NULL;
+ impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
- sort_type = gtk_recent_chooser_get_sort_type (chooser);
- switch (sort_type)
- {
- case GTK_RECENT_SORT_NONE:
- compare_func = NULL;
- break;
- case GTK_RECENT_SORT_MRU:
- compare_func = (GCompareDataFunc) sort_recent_items_mru;
- break;
- case GTK_RECENT_SORT_LRU:
- compare_func = (GCompareDataFunc) sort_recent_items_lru;
- break;
- case GTK_RECENT_SORT_CUSTOM:
- compare_func = (GCompareDataFunc) sort_recent_items_proxy;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- /* sort the items; the filtering will be dealt with using
- * the treeview's own filter object
- */
- if (compare_func)
- items = g_list_sort_with_data (items, compare_func, impl);
-
- length = g_list_length (items);
- if ((limit != -1) && (length > limit))
- {
- GList *clamp, *l;
-
- clamp = g_list_nth (items, limit - 1);
- if (!clamp)
- return items;
-
- l = clamp->next;
- clamp->next = NULL;
-
- g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (l);
- }
-
- return items;
+ return _gtk_recent_chooser_get_items (chooser,
+ impl->sort_func,
+ impl->sort_data);
}
static GtkRecentManager *
gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- return impl->manager;
+ return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
}
static void
@@ -1566,6 +1486,19 @@ set_current_filter (GtkRecentChooserDefault *impl,
}
}
+static void
+chooser_set_sort_type (GtkRecentChooserDefault *impl,
+ GtkRecentSortType sort_type)
+{
+ if (impl->sort_type == sort_type)
+ return;
+
+ impl->sort_type = sort_type;
+
+ reload_recent_items (impl);
+}
+
+
static GtkIconTheme *
get_icon_theme_for_widget (GtkWidget *widget)
{
diff --git a/gtk/gtkrecentchoosermenu.c b/gtk/gtkrecentchoosermenu.c
index 11731a1a90..99097fa8c8 100644
--- a/gtk/gtkrecentchoosermenu.c
+++ b/gtk/gtkrecentchoosermenu.c
@@ -46,6 +46,7 @@
#include "gtkobject.h"
#include "gtktooltips.h"
#include "gtktypebuiltins.h"
+#include "gtkprivate.h"
#include "gtkalias.h"
struct _GtkRecentChooserMenuPrivate
@@ -211,7 +212,7 @@ gtk_recent_chooser_menu_class_init (GtkRecentChooserMenuClass *klass)
P_("Show Numbers"),
P_("Whether the items should be displayed with a number"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (GtkRecentChooserMenuPrivate));
}
@@ -353,26 +354,27 @@ gtk_recent_chooser_menu_set_property (GObject *object,
GParamSpec *pspec)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
switch (prop_id)
{
case PROP_SHOW_NUMBERS:
- menu->priv->show_numbers = g_value_get_boolean (value);
+ priv->show_numbers = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
set_recent_manager (menu, g_value_get_object (value));
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- menu->priv->show_private = g_value_get_boolean (value);
+ priv->show_private = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- menu->priv->show_not_found = g_value_get_boolean (value);
+ priv->show_not_found = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
gtk_recent_chooser_menu_set_show_tips (menu, g_value_get_boolean (value));
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- menu->priv->show_icons = g_value_get_boolean (value);
+ priv->show_icons = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
@@ -380,10 +382,10 @@ gtk_recent_chooser_menu_set_property (GObject *object,
G_OBJECT_TYPE_NAME (object));
break;
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- menu->priv->local_only = g_value_get_boolean (value);
+ priv->local_only = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_LIMIT:
- menu->priv->limit = g_value_get_int (value);
+ priv->limit = g_value_get_int (value);
break;
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
chooser_set_sort_type (menu, g_value_get_enum (value));
@@ -404,32 +406,33 @@ gtk_recent_chooser_menu_get_property (GObject *object,
GParamSpec *pspec)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
switch (prop_id)
{
case PROP_SHOW_NUMBERS:
- g_value_set_boolean (value, menu->priv->show_numbers);
+ g_value_set_boolean (value, priv->show_numbers);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- g_value_set_boolean (value, menu->priv->show_tips);
+ g_value_set_boolean (value, priv->show_tips);
break;
case GTK_RECENT_CHOOSER_PROP_LIMIT:
- g_value_set_int (value, menu->priv->limit);
+ g_value_set_int (value, priv->limit);
break;
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- g_value_set_boolean (value, menu->priv->local_only);
+ g_value_set_boolean (value, priv->local_only);
break;
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- g_value_set_enum (value, menu->priv->sort_type);
+ g_value_set_enum (value, priv->sort_type);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- g_value_set_boolean (value, menu->priv->show_private);
+ g_value_set_boolean (value, priv->show_private);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- g_value_set_boolean (value, menu->priv->show_not_found);
+ g_value_set_boolean (value, priv->show_not_found);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- g_value_set_boolean (value, menu->priv->show_icons);
+ g_value_set_boolean (value, priv->show_icons);
break;
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
@@ -437,7 +440,7 @@ gtk_recent_chooser_menu_get_property (GObject *object,
G_OBJECT_TYPE_NAME (object));
break;
case GTK_RECENT_CHOOSER_PROP_FILTER:
- g_value_set_object (value, menu->priv->current_filter);
+ g_value_set_object (value, priv->current_filter);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -456,6 +459,7 @@ gtk_recent_chooser_menu_set_current_uri (GtkRecentChooser *chooser,
gboolean found = FALSE;
children = gtk_container_get_children (GTK_CONTAINER (menu));
+
for (l = children; l != NULL; l = l->next)
{
GtkRecentInfo *info;
@@ -588,11 +592,12 @@ gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
if (priv->sort_data_destroy)
{
priv->sort_data_destroy (priv->sort_data);
-
- priv->sort_func = NULL;
- priv->sort_data = NULL;
priv->sort_data_destroy = NULL;
}
+
+ priv->sort_func = NULL;
+ priv->sort_data = NULL;
+ priv->sort_data_destroy = NULL;
if (sort_func)
{
@@ -602,45 +607,6 @@ gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
}
}
-static gint
-sort_recent_items_mru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) < gtk_recent_info_get_modified (b));
-}
-
-static gint
-sort_recent_items_lru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) > gtk_recent_info_get_modified (b));
-}
-
-/* our proxy sorting function */
-static gint
-sort_recent_items_proxy (gpointer *a,
- gpointer *b,
- gpointer user_data)
-{
- GtkRecentInfo *info_a = (GtkRecentInfo *) a;
- GtkRecentInfo *info_b = (GtkRecentInfo *) b;
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (user_data);
-
- if (menu->priv->sort_func)
- return (* menu->priv->sort_func) (info_a,
- info_b,
- menu->priv->sort_data);
-
- /* fallback */
- return 0;
-}
-
static void
chooser_set_sort_type (GtkRecentChooserMenu *menu,
GtkRecentSortType sort_type)
@@ -656,66 +622,11 @@ static GList *
gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GtkRecentChooserMenuPrivate *priv;
- gint limit;
- GtkRecentSortType sort_type;
- GList *items;
- GCompareDataFunc compare_func;
- gint length;
-
- priv = menu->priv;
-
- if (!priv->manager)
- return NULL;
-
- limit = gtk_recent_chooser_get_limit (chooser);
- if (limit == 0)
- return NULL;
-
- sort_type = gtk_recent_chooser_get_sort_type (chooser);
- switch (sort_type)
- {
- case GTK_RECENT_SORT_NONE:
- compare_func = NULL;
- break;
- case GTK_RECENT_SORT_MRU:
- compare_func = (GCompareDataFunc) sort_recent_items_mru;
- break;
- case GTK_RECENT_SORT_LRU:
- compare_func = (GCompareDataFunc) sort_recent_items_lru;
- break;
- case GTK_RECENT_SORT_CUSTOM:
- compare_func = (GCompareDataFunc) sort_recent_items_proxy;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- items = gtk_recent_manager_get_items (priv->manager);
- if (!items)
- return NULL;
-
- if (compare_func)
- items = g_list_sort_with_data (items, compare_func, menu);
-
- length = g_list_length (items);
- if ((limit != -1) && (length > limit))
- {
- GList *clamp, *l;
-
- clamp = g_list_nth (items, limit - 1);
- if (!clamp)
- return items;
-
- l = clamp->next;
- clamp->next = NULL;
-
- g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (l);
- }
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
- return items;
+ return _gtk_recent_chooser_get_items (chooser,
+ priv->sort_func,
+ priv->sort_data);
}
static GtkRecentManager *
@@ -970,7 +881,7 @@ gtk_recent_chooser_menu_create_item (GtkRecentChooserMenu *menu,
* display name is huge.
*/
label = GTK_BIN (item)->child;
- if (label)
+ if (GTK_IS_LABEL (label))
{
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_max_width_chars (GTK_LABEL (label), priv->label_width);
@@ -1395,7 +1306,7 @@ gtk_recent_chooser_menu_get_show_numbers (GtkRecentChooserMenu *menu)
*
* Sets whether a number should be added to the items of @menu. The
* numbers are shown to provide a unique character for a mnemonic to
- * be used inside the menu item's label. Only the first the items
+ * be used inside ten menu item's label. Only the first the items
* get a number to avoid clashes.
*
* Since: 2.10
diff --git a/gtk/gtkrecentchooserprivate.h b/gtk/gtkrecentchooserprivate.h
index fcd3c832d6..476c932751 100644
--- a/gtk/gtkrecentchooserprivate.h
+++ b/gtk/gtkrecentchooserprivate.h
@@ -30,12 +30,13 @@
G_BEGIN_DECLS
-#define GTK_DEFAULT_RECENT_MANAGER "gtk-recent-manager-default"
+GtkRecentManager *_gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser);
+GList * _gtk_recent_chooser_get_items (GtkRecentChooser *chooser,
+ GtkRecentSortFunc func,
+ gpointer data);
-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);
+void _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser);
+void _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser);
G_END_DECLS
diff --git a/gtk/gtkrecentchooserutils.c b/gtk/gtkrecentchooserutils.c
index f931486c6c..64fc81e331 100644
--- a/gtk/gtkrecentchooserutils.c
+++ b/gtk/gtkrecentchooserutils.c
@@ -294,3 +294,139 @@ delegate_item_activated (GtkRecentChooser *receiver,
{
_gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
}
+
+static gint
+sort_recent_items_mru (GtkRecentInfo *a,
+ GtkRecentInfo *b,
+ gpointer unused)
+{
+ g_assert (a != NULL && b != NULL);
+
+ return (gtk_recent_info_get_modified (a) < gtk_recent_info_get_modified (b));
+}
+
+static gint
+sort_recent_items_lru (GtkRecentInfo *a,
+ GtkRecentInfo *b,
+ gpointer unused)
+{
+ g_assert (a != NULL && b != NULL);
+
+ return (gtk_recent_info_get_modified (a) > gtk_recent_info_get_modified (b));
+}
+
+typedef struct
+{
+ GtkRecentSortFunc func;
+ gpointer data;
+} SortRecentData;
+
+/* our proxy sorting function */
+static gint
+sort_recent_items_proxy (gpointer *a,
+ gpointer *b,
+ gpointer user_data)
+{
+ GtkRecentInfo *info_a = (GtkRecentInfo *) a;
+ GtkRecentInfo *info_b = (GtkRecentInfo *) b;
+ SortRecentData *sort_recent = user_data;
+
+ if (sort_recent->func)
+ return (* sort_recent->func) (info_a,
+ info_b,
+ sort_recent->data);
+
+ /* fallback */
+ return 0;
+}
+
+/*
+ * _gtk_recent_chooser_get_items:
+ * @chooser: a #GtkRecentChooser
+ * @sort_func: sorting function, or %NULL
+ * @sort_data: sorting function data, or %NULL
+ *
+ * Default implementation for getting the (sorted and clamped) list
+ * of recently used resources from a #GtkRecentChooser. This function
+ * should be used by implementations of the #GtkRecentChooser
+ * interface inside the GtkRecentChooser::get_items vfunc.
+ *
+ * Return value: a list of #GtkRecentInfo objects
+ */
+GList *
+_gtk_recent_chooser_get_items (GtkRecentChooser *chooser,
+ GtkRecentSortFunc sort_func,
+ gpointer sort_data)
+{
+ GtkRecentManager *manager;
+ gint limit;
+ GtkRecentSortType sort_type;
+ GList *items;
+ GCompareDataFunc compare_func;
+ gint length;
+
+ g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
+
+ manager = _gtk_recent_chooser_get_recent_manager (chooser);
+ if (!manager)
+ return NULL;
+
+ items = gtk_recent_manager_get_items (manager);
+ if (!items)
+ return NULL;
+
+ limit = gtk_recent_chooser_get_limit (chooser);
+ if (limit == 0)
+ return NULL;
+
+ sort_type = gtk_recent_chooser_get_sort_type (chooser);
+ switch (sort_type)
+ {
+ case GTK_RECENT_SORT_NONE:
+ compare_func = NULL;
+ break;
+ case GTK_RECENT_SORT_MRU:
+ compare_func = (GCompareDataFunc) sort_recent_items_mru;
+ break;
+ case GTK_RECENT_SORT_LRU:
+ compare_func = (GCompareDataFunc) sort_recent_items_lru;
+ break;
+ case GTK_RECENT_SORT_CUSTOM:
+ compare_func = (GCompareDataFunc) sort_recent_items_proxy;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ if (compare_func)
+ {
+ SortRecentData *sort_recent;
+
+ sort_recent = g_slice_new (SortRecentData);
+ sort_recent->func = sort_func;
+ sort_recent->data = sort_data;
+
+ items = g_list_sort_with_data (items, compare_func, sort_recent);
+
+ g_slice_free (SortRecentData, sort_recent);
+ }
+
+ length = g_list_length (items);
+ if ((limit != -1) && (length > limit))
+ {
+ GList *clamp, *l;
+
+ clamp = g_list_nth (items, limit - 1);
+ if (!clamp)
+ return items;
+
+ l = clamp->next;
+ clamp->next = NULL;
+
+ g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
+ g_list_free (l);
+ }
+
+ return items;
+}
diff --git a/gtk/gtkrecentchooserutils.h b/gtk/gtkrecentchooserutils.h
index 79adca301a..24ba75b67c 100644
--- a/gtk/gtkrecentchooserutils.h
+++ b/gtk/gtkrecentchooserutils.h
@@ -57,7 +57,6 @@ void _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
GQuark _gtk_recent_chooser_delegate_get_quark (void) G_GNUC_CONST;
-
G_END_DECLS
#endif /* __GTK_RECENT_CHOOSER_UTILS_H__ */