#include "gtkseparatormenuitem.h"
#include "gtksizegroup.h"
#include "gtktable.h"
-#include "gtktreeview.h"
#include "gtktreemodelsort.h"
#include "gtktreemodelfilter.h"
#include "gtktreeselection.h"
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserdefault.h"
+#include "gtkprivate.h"
#include "gtkalias.h"
\f
guint show_private : 1;
guint show_not_found : 1;
guint select_multiple : 1;
- guint show_numbers : 1;
guint show_tips : 1;
guint show_icons : 1;
guint local_only : 1;
GtkWidget *recent_view;
GtkListStore *recent_store;
- GtkTreeModel *recent_store_filter;
GtkTreeViewColumn *icon_column;
GtkTreeViewColumn *meta_column;
GtkCellRenderer *meta_renderer;
{ "text/uri-list", 0, TEXT_URI_LIST }
};
-static const int num_recent_list_source_targets = (sizeof (recent_list_source_targets)
- / sizeof (recent_list_source_targets[0]));
-
/* Icon size for if we can't get it from the theme */
#define FALLBACK_ICON_SIZE 48
#define FALLBACK_ITEM_LIMIT 20
\f
/* GObject */
-static void gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass);
-static void gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl);
+static void _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass);
+static void _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl);
static GObject *gtk_recent_chooser_default_constructor (GType type,
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,
static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
GtkRecentSortType sort_type);
-static gboolean recent_store_filter_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data);
-
static void recent_manager_changed_cb (GtkRecentManager *manager,
gpointer user_data);
static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
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;
static void
_gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
{
- gtk_box_set_spacing (GTK_BOX (impl), 12);
+ gtk_box_set_spacing (GTK_BOX (impl), 6);
/* by default, we use the global manager */
impl->local_manager = FALSE;
impl->show_icons = TRUE;
impl->show_private = FALSE;
- impl->show_not_found = FALSE;
+ impl->show_not_found = TRUE;
impl->show_tips = TRUE;
impl->select_multiple = FALSE;
impl->local_only = TRUE;
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);
G_CALLBACK (recent_view_popup_menu_cb), impl);
g_signal_connect (impl->recent_view, "button-press-event",
G_CALLBACK (recent_view_button_press_cb), impl);
- g_signal_connect (impl->recent_view, "drag-begin",
+ g_signal_connect (impl->recent_view, "drag_begin",
G_CALLBACK (recent_view_drag_begin_cb), impl);
- g_signal_connect (impl->recent_view, "drag-data-get",
+ 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);
gtk_drag_source_set (impl->recent_view,
GDK_BUTTON1_MASK,
recent_list_source_targets,
- num_recent_list_source_targets,
+ G_N_ELEMENTS (recent_list_source_targets),
GDK_ACTION_COPY);
impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
impl->show_private = g_value_get_boolean (value);
-
- if (impl->recent_store && impl->recent_store_filter)
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->recent_store_filter));
-
if (impl->recent_popup_menu_show_private_item)
{
GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->recent_popup_menu_show_private_item);
gtk_check_menu_item_set_active (item, impl->show_private);
g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
}
+ reload_recent_items (impl);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
impl->show_not_found = g_value_get_boolean (value);
-
- if (impl->recent_store && impl->recent_store_filter)
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->recent_store_filter));
+ reload_recent_items (impl);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
impl->show_tips = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
impl->local_only = g_value_get_boolean (value);
+ reload_recent_items (impl);
break;
case GTK_RECENT_CHOOSER_PROP_LIMIT:
impl->limit = g_value_get_int (value);
+ reload_recent_items (impl);
break;
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
chooser_set_sort_type (impl, g_value_get_enum (value));
}
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;
}
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);
-
- if (impl->recent_store_filter)
- g_object_unref (impl->recent_store_filter);
+ {
+ g_object_unref (impl->current_filter);
+ impl->current_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);
}
chooser_set_model (GtkRecentChooserDefault *impl)
{
g_assert (impl->recent_store != NULL);
- g_assert (impl->recent_store_filter == NULL);
g_assert (impl->load_state == LOAD_LOADING);
-
- impl->recent_store_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->recent_store), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->recent_store_filter),
- recent_store_filter_func,
- impl,
- NULL);
-
+
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view),
- impl->recent_store_filter);
+ GTK_TREE_MODEL (impl->recent_store));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->recent_view));
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->recent_view), TRUE);
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->recent_view),
const gchar *uri, *name;
gboolean retval;
- GDK_THREADS_ENTER ();
-
impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
g_assert ((impl->load_state == LOAD_EMPTY) ||
impl->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
if (!impl->recent_items)
{
- GDK_THREADS_LEAVE ();
-
impl->load_state = LOAD_FINISHED;
return FALSE;
impl->recent_items = NULL;
impl->n_recent_items = 0;
impl->loaded_items = 0;
-
- if (impl->recent_store_filter)
- {
- g_object_unref (impl->recent_store_filter);
- impl->recent_store_filter = NULL;
- }
-
+
/* load the filled up model */
chooser_set_model (impl);
retval = TRUE;
}
- GDK_THREADS_LEAVE ();
-
return retval;
}
{
GtkRecentChooserDefault *impl;
- GDK_THREADS_ENTER ();
-
impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
if (impl->load_id != 0)
(impl->load_state == LOAD_FINISHED));
set_busy_cursor (impl, FALSE);
-
- GDK_THREADS_LEAVE ();
}
/* clears the current model and reloads the recently used resources */
set_busy_cursor (impl, TRUE);
impl->load_state = LOAD_EMPTY;
- impl->load_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 30,
- load_recent_items,
- impl,
- cleanup_after_load);
+ impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
+ load_recent_items,
+ impl,
+ cleanup_after_load);
}
/* taken form gtkfilechooserdialog.c */
g_object_set (cell,
"markup", data->str,
- "sensitive", gtk_recent_info_exists (info),
NULL);
g_string_free (data, TRUE);
gpointer user_data)
{
SelectURIData *select_data = (SelectURIData *) user_data;
- gchar *uri;
+ gchar *uri = NULL;
if (!select_data)
return TRUE;
return TRUE;
gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
- if (uri && (0 == strcmp (uri, select_data->uri)))
+ if (!uri)
+ return FALSE;
+
+ if (strcmp (uri, select_data->uri) == 0)
{
select_data->found = TRUE;
if (select_data->do_activate)
- {
- gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
- path,
- select_data->impl->meta_column);
-
- return TRUE;
- }
+ gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
+ path,
+ select_data->impl->meta_column);
if (select_data->do_select)
- gtk_tree_selection_select_iter (select_data->impl->selection, iter);
+ gtk_tree_selection_select_path (select_data->impl->selection, path);
else
- gtk_tree_selection_unselect_iter (select_data->impl->selection, iter);
+ gtk_tree_selection_unselect_path (select_data->impl->selection, path);
+
+ g_free (uri);
return TRUE;
}
+
+ g_free (uri);
return FALSE;
}
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)
{
}
}
-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);
- sort_type = gtk_recent_chooser_get_sort_type (chooser);
+ impl = GTK_RECENT_CHOOSER_DEFAULT (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->current_filter,
+ 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
return g_slist_copy (impl->filters);
}
-static gboolean
-get_is_recent_filtered (GtkRecentChooserDefault *impl,
- GtkRecentInfo *info)
-{
- GtkRecentFilter *current_filter;
- GtkRecentFilterInfo filter_info;
- GtkRecentFilterFlags needed;
- gboolean retval;
-
- g_assert (info != NULL);
-
- if (!impl->current_filter)
- return FALSE;
-
- current_filter = impl->current_filter;
- needed = gtk_recent_filter_get_needed (current_filter);
-
- filter_info.contains = GTK_RECENT_FILTER_URI | GTK_RECENT_FILTER_MIME_TYPE;
-
- filter_info.uri = gtk_recent_info_get_uri (info);
- filter_info.mime_type = gtk_recent_info_get_mime_type (info);
-
- if (needed & GTK_RECENT_FILTER_DISPLAY_NAME)
- {
- filter_info.display_name = gtk_recent_info_get_display_name (info);
- filter_info.contains |= GTK_RECENT_FILTER_DISPLAY_NAME;
- }
- else
- filter_info.uri = NULL;
-
- if (needed & GTK_RECENT_FILTER_APPLICATION)
- {
- filter_info.applications = (const gchar **) gtk_recent_info_get_applications (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_APPLICATION;
- }
- else
- filter_info.applications = NULL;
-
- if (needed & GTK_RECENT_FILTER_GROUP)
- {
- filter_info.groups = (const gchar **) gtk_recent_info_get_groups (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_GROUP;
- }
- else
- filter_info.groups = NULL;
-
- if (needed & GTK_RECENT_FILTER_AGE)
- {
- filter_info.age = gtk_recent_info_get_age (info);
- filter_info.contains |= GTK_RECENT_FILTER_AGE;
- }
- else
- filter_info.age = -1;
-
- retval = gtk_recent_filter_filter (current_filter, &filter_info);
-
- /* this we own */
- if (filter_info.applications)
- g_strfreev ((gchar **) filter_info.applications);
-
- return !retval;
-}
-
-static gboolean
-recent_store_filter_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- GtkRecentInfo *info = NULL;
-
- if (!impl->current_filter)
- return TRUE;
-
- gtk_tree_model_get (model, iter,
- RECENT_INFO_COLUMN, &info,
- -1);
- if (!info)
- return TRUE;
-
- if (get_is_recent_filtered (impl, info))
- return FALSE;
-
- if (impl->local_only && !gtk_recent_info_is_local (info))
- return FALSE;
-
- if ((!impl->show_private) && gtk_recent_info_get_private_hint (info))
- return FALSE;
-
- if ((!impl->show_not_found) && !gtk_recent_info_exists (info))
- return FALSE;
-
- return TRUE;
-}
-
static void
set_current_filter (GtkRecentChooserDefault *impl,
GtkRecentFilter *filter)
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
filter_idx);
- if (impl->recent_store && impl->recent_store_filter)
- {
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->recent_store_filter));
- }
-
+ if (impl->recent_store)
+ reload_recent_items (impl);
+
g_object_notify (G_OBJECT (impl), "filter");
}
}
+static void
+chooser_set_sort_type (GtkRecentChooserDefault *impl,
+ GtkRecentSortType sort_type)
+{
+ if (impl->sort_type != sort_type)
+ {
+ impl->sort_type = sort_type;
+ reload_recent_items (impl);
+
+ g_object_notify (G_OBJECT (impl), "sort-type");
+ }
+}
+
+
static GtkIconTheme *
get_icon_theme_for_widget (GtkWidget *widget)
{
"recent-manager", manager,
NULL);
}
-
-#define __GTK_RECENT_CHOOSER_DEFAULT_C__
-#include "gtkaliasdef.c"