From 0ac236ac684215cc04d9383ab0bfbc28e186a4c4 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sat, 10 May 2014 14:07:08 +0200 Subject: [PATCH] recent-view: Use a GtkIconView and get rid of most of libgd cut-n-paste --- cut-n-paste/libgd/Makefile.am | 6 - cut-n-paste/libgd/gd-main-icon-view.c | 393 ------------------ cut-n-paste/libgd/gd-main-icon-view.h | 74 ---- cut-n-paste/libgd/gd-main-view-generic.c | 311 -------------- cut-n-paste/libgd/gd-main-view-generic.h | 116 ------ cut-n-paste/libgd/gd-toggle-pixbuf-renderer.c | 199 --------- cut-n-paste/libgd/gd-toggle-pixbuf-renderer.h | 75 ---- shell/ev-recent-view.c | 91 ++-- 8 files changed, 56 insertions(+), 1209 deletions(-) delete mode 100644 cut-n-paste/libgd/gd-main-icon-view.c delete mode 100644 cut-n-paste/libgd/gd-main-icon-view.h delete mode 100644 cut-n-paste/libgd/gd-main-view-generic.c delete mode 100644 cut-n-paste/libgd/gd-main-view-generic.h delete mode 100644 cut-n-paste/libgd/gd-toggle-pixbuf-renderer.c delete mode 100644 cut-n-paste/libgd/gd-toggle-pixbuf-renderer.h diff --git a/cut-n-paste/libgd/Makefile.am b/cut-n-paste/libgd/Makefile.am index aa65bc22..7962c513 100644 --- a/cut-n-paste/libgd/Makefile.am +++ b/cut-n-paste/libgd/Makefile.am @@ -3,12 +3,6 @@ noinst_LTLIBRARIES = libgd.la libgd_la_SOURCES = \ gd-icon-utils.c \ gd-icon-utils.h \ - gd-main-icon-view.c \ - gd-main-icon-view.h \ - gd-main-view-generic.c \ - gd-main-view-generic.h \ - gd-toggle-pixbuf-renderer.c \ - gd-toggle-pixbuf-renderer.h \ gd-two-lines-renderer.c \ gd-two-lines-renderer.h diff --git a/cut-n-paste/libgd/gd-main-icon-view.c b/cut-n-paste/libgd/gd-main-icon-view.c deleted file mode 100644 index 9b56681a..00000000 --- a/cut-n-paste/libgd/gd-main-icon-view.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#include "gd-main-icon-view.h" -#include "gd-main-view-generic.h" -#include "gd-toggle-pixbuf-renderer.h" -#include "gd-two-lines-renderer.h" - -#include -#include - -#define VIEW_ITEM_WIDTH 140 -#define VIEW_ITEM_WRAP_WIDTH 128 -#define VIEW_COLUMN_SPACING 20 -#define VIEW_MARGIN 16 - -struct _GdMainIconViewPrivate { - GtkCellRenderer *pixbuf_cell; - gboolean selection_mode; -}; - -static void gd_main_view_generic_iface_init (GdMainViewGenericIface *iface); -G_DEFINE_TYPE_WITH_CODE (GdMainIconView, gd_main_icon_view, GTK_TYPE_ICON_VIEW, - G_IMPLEMENT_INTERFACE (GD_TYPE_MAIN_VIEW_GENERIC, - gd_main_view_generic_iface_init)) - -static GtkTreePath* -get_source_row (GdkDragContext *context) -{ - GtkTreeRowReference *ref; - - ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row"); - - if (ref) - return gtk_tree_row_reference_get_path (ref); - else - return NULL; -} - -static void -gd_main_icon_view_drag_data_get (GtkWidget *widget, - GdkDragContext *drag_context, - GtkSelectionData *data, - guint info, - guint time) -{ - GdMainIconView *self = GD_MAIN_ICON_VIEW (widget); - GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self)); - - if (info != 0) - return; - - _gd_main_view_generic_dnd_common (model, self->priv->selection_mode, - get_source_row (drag_context), data); - - GTK_WIDGET_CLASS (gd_main_icon_view_parent_class)->drag_data_get (widget, drag_context, - data, info, time); -} - -static void -gd_main_icon_view_constructed (GObject *obj) -{ - GdMainIconView *self = GD_MAIN_ICON_VIEW (obj); - GtkCellRenderer *cell; - const GtkTargetEntry targets[] = { - { (char *) "text/uri-list", GTK_TARGET_OTHER_APP, 0 } - }; - - G_OBJECT_CLASS (gd_main_icon_view_parent_class)->constructed (obj); - - gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE); - gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE); - gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (self), GTK_SELECTION_NONE); - - g_object_set (self, - "column-spacing", VIEW_COLUMN_SPACING, - "margin", VIEW_MARGIN, - NULL); - - self->priv->pixbuf_cell = cell = gd_toggle_pixbuf_renderer_new (); - g_object_set (cell, - "xalign", 0.5, - "yalign", 0.5, - NULL); - - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell, - "active", GD_MAIN_COLUMN_SELECTED); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell, - "surface", GD_MAIN_COLUMN_ICON); - - cell = gd_two_lines_renderer_new (); - g_object_set (cell, - "xalign", 0.5, - "alignment", PANGO_ALIGN_CENTER, - "wrap-mode", PANGO_WRAP_WORD_CHAR, - "wrap-width", VIEW_ITEM_WRAP_WIDTH, - "text-lines", 3, - NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell, - "text", GD_MAIN_COLUMN_PRIMARY_TEXT); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell, - "line-two", GD_MAIN_COLUMN_SECONDARY_TEXT); - - gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (self), - GDK_BUTTON1_MASK, - targets, 1, - GDK_ACTION_COPY); -} - -static void -path_from_line_rects (cairo_t *cr, - GdkRectangle *lines, - int n_lines) -{ - int start_line, end_line; - GdkRectangle *r; - int i; - - /* Join rows vertically by extending to the middle */ - for (i = 0; i < n_lines - 1; i++) - { - GdkRectangle *r1 = &lines[i]; - GdkRectangle *r2 = &lines[i+1]; - int gap = r2->y - (r1->y + r1->height); - int old_y; - - r1->height += gap / 2; - old_y = r2->y; - r2->y = r1->y + r1->height; - r2->height += old_y - r2->y; - } - - cairo_new_path (cr); - start_line = 0; - - do - { - for (i = start_line; i < n_lines; i++) - { - r = &lines[i]; - if (i == start_line) - cairo_move_to (cr, r->x + r->width, r->y); - else - cairo_line_to (cr, r->x + r->width, r->y); - cairo_line_to (cr, r->x + r->width, r->y + r->height); - - if (i < n_lines - 1 && - (r->x + r->width < lines[i+1].x || - r->x > lines[i+1].x + lines[i+1].width)) - { - i++; - break; - } - } - end_line = i; - for (i = end_line - 1; i >= start_line; i--) - { - r = &lines[i]; - cairo_line_to (cr, r->x, r->y + r->height); - cairo_line_to (cr, r->x, r->y); - } - cairo_close_path (cr); - start_line = end_line; - } - while (end_line < n_lines); -} - -static gboolean -gd_main_icon_view_draw (GtkWidget *widget, - cairo_t *cr) -{ - GdMainIconView *self = GD_MAIN_ICON_VIEW (widget); - GtkAllocation allocation; - GtkStyleContext *context; - GdkRectangle line_rect; - GdkRectangle rect; - GtkTreePath *path; - GArray *lines; - GtkTreePath *rubberband_start, *rubberband_end; - - GTK_WIDGET_CLASS (gd_main_icon_view_parent_class)->draw (widget, cr); - - _gd_main_view_generic_get_rubberband_range (GD_MAIN_VIEW_GENERIC (self), - &rubberband_start, &rubberband_end); - - if (rubberband_start) - { - cairo_save (cr); - - context = gtk_widget_get_style_context (widget); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND); - - path = gtk_tree_path_copy (rubberband_start); - - line_rect.width = 0; - lines = g_array_new (FALSE, FALSE, sizeof (GdkRectangle)); - - while (gtk_tree_path_compare (path, rubberband_end) <= 0) - { - if (gtk_icon_view_get_cell_rect (GTK_ICON_VIEW (widget), - path, - NULL, &rect)) - { - if (line_rect.width == 0) - line_rect = rect; - else - { - if (rect.y == line_rect.y) - gdk_rectangle_union (&rect, &line_rect, &line_rect); - else - { - g_array_append_val (lines, line_rect); - line_rect = rect; - } - } - } - gtk_tree_path_next (path); - } - - if (line_rect.width != 0) - g_array_append_val (lines, line_rect); - - if (lines->len > 0) - { - GtkStateFlags state; - cairo_path_t *path; - GtkBorder border; - GdkRGBA border_color; - - path_from_line_rects (cr, (GdkRectangle *)lines->data, lines->len); - - /* For some reason we need to copy and reapply the path, or it gets - eaten by gtk_render_background() */ - path = cairo_copy_path (cr); - - cairo_save (cr); - cairo_clip (cr); - gtk_widget_get_allocation (widget, &allocation); - gtk_render_background (context, cr, - 0, 0, - allocation.width, allocation.height); - cairo_restore (cr); - - cairo_append_path (cr, path); - cairo_path_destroy (path); - - state = gtk_widget_get_state_flags (widget); - gtk_style_context_get_border_color (context, - state, - &border_color); - gtk_style_context_get_border (context, state, - &border); - - cairo_set_line_width (cr, border.left); - gdk_cairo_set_source_rgba (cr, &border_color); - cairo_stroke (cr); - } - g_array_free (lines, TRUE); - - gtk_tree_path_free (path); - - gtk_style_context_restore (context); - cairo_restore (cr); - } - - return FALSE; -} - -static void -gd_main_icon_view_class_init (GdMainIconViewClass *klass) -{ - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass); - GtkBindingSet *binding_set; - GdkModifierType activate_modifiers[] = { GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK | GDK_CONTROL_MASK }; - int i; - - binding_set = gtk_binding_set_by_class (klass); - - oclass->constructed = gd_main_icon_view_constructed; - wclass->drag_data_get = gd_main_icon_view_drag_data_get; - wclass->draw = gd_main_icon_view_draw; - - gtk_widget_class_install_style_property (wclass, - g_param_spec_int ("check-icon-size", - "Check icon size", - "Check icon size", - -1, G_MAXINT, 40, - G_PARAM_READWRITE)); - - g_type_class_add_private (klass, sizeof (GdMainIconViewPrivate)); - - - for (i = 0; i < G_N_ELEMENTS (activate_modifiers); i++) - { - gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, activate_modifiers[i], - "activate-cursor-item", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, activate_modifiers[i], - "activate-cursor-item", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, activate_modifiers[i], - "activate-cursor-item", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, activate_modifiers[i], - "activate-cursor-item", 0); - gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, activate_modifiers[i], - "activate-cursor-item", 0); - } -} - -static void -gd_main_icon_view_init (GdMainIconView *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewPrivate); -} - -static GtkTreePath * -gd_main_icon_view_get_path_at_pos (GdMainViewGeneric *mv, - gint x, - gint y) -{ - return gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (mv), x, y); -} - -static void -gd_main_icon_view_set_selection_mode (GdMainViewGeneric *mv, - gboolean selection_mode) -{ - GdMainIconView *self = GD_MAIN_ICON_VIEW (mv); - - self->priv->selection_mode = selection_mode; - - g_object_set (self->priv->pixbuf_cell, - "toggle-visible", selection_mode, - NULL); - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -gd_main_icon_view_scroll_to_path (GdMainViewGeneric *mv, - GtkTreePath *path) -{ - gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (mv), path, TRUE, 0.5, 0.5); -} - -static void -gd_main_icon_view_set_model (GdMainViewGeneric *mv, - GtkTreeModel *model) -{ - gtk_icon_view_set_model (GTK_ICON_VIEW (mv), model); -} - -static GtkTreeModel * -gd_main_icon_view_get_model (GdMainViewGeneric *mv) -{ - return gtk_icon_view_get_model (GTK_ICON_VIEW (mv)); -} - -static void -gd_main_view_generic_iface_init (GdMainViewGenericIface *iface) -{ - iface->set_model = gd_main_icon_view_set_model; - iface->get_model = gd_main_icon_view_get_model; - iface->get_path_at_pos = gd_main_icon_view_get_path_at_pos; - iface->scroll_to_path = gd_main_icon_view_scroll_to_path; - iface->set_selection_mode = gd_main_icon_view_set_selection_mode; -} - -GtkWidget * -gd_main_icon_view_new (void) -{ - return g_object_new (GD_TYPE_MAIN_ICON_VIEW, NULL); -} diff --git a/cut-n-paste/libgd/gd-main-icon-view.h b/cut-n-paste/libgd/gd-main-icon-view.h deleted file mode 100644 index 7370b2af..00000000 --- a/cut-n-paste/libgd/gd-main-icon-view.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#ifndef __GD_MAIN_ICON_VIEW_H__ -#define __GD_MAIN_ICON_VIEW_H__ - -#include -#include - -G_BEGIN_DECLS - -#define GD_TYPE_MAIN_ICON_VIEW gd_main_icon_view_get_type() - -#define GD_MAIN_ICON_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - GD_TYPE_MAIN_ICON_VIEW, GdMainIconView)) - -#define GD_MAIN_ICON_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewClass)) - -#define GD_IS_MAIN_ICON_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - GD_TYPE_MAIN_ICON_VIEW)) - -#define GD_IS_MAIN_ICON_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - GD_TYPE_MAIN_ICON_VIEW)) - -#define GD_MAIN_ICON_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewClass)) - -typedef struct _GdMainIconView GdMainIconView; -typedef struct _GdMainIconViewClass GdMainIconViewClass; -typedef struct _GdMainIconViewPrivate GdMainIconViewPrivate; - -struct _GdMainIconView -{ - GtkIconView parent; - - GdMainIconViewPrivate *priv; -}; - -struct _GdMainIconViewClass -{ - GtkIconViewClass parent_class; -}; - -GType gd_main_icon_view_get_type (void) G_GNUC_CONST; - -GtkWidget * gd_main_icon_view_new (void); - -G_END_DECLS - -#endif /* __GD_MAIN_ICON_VIEW_H__ */ diff --git a/cut-n-paste/libgd/gd-main-view-generic.c b/cut-n-paste/libgd/gd-main-view-generic.c deleted file mode 100644 index 200153ca..00000000 --- a/cut-n-paste/libgd/gd-main-view-generic.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#include "gd-main-view-generic.h" - -enum { - VIEW_SELECTION_CHANGED, - NUM_SIGNALS -}; - -static guint signals[NUM_SIGNALS] = { 0, }; - -typedef GdMainViewGenericIface GdMainViewGenericInterface; -G_DEFINE_INTERFACE (GdMainViewGeneric, gd_main_view_generic, GTK_TYPE_WIDGET) - -static void -gd_main_view_generic_default_init (GdMainViewGenericInterface *iface) -{ - signals[VIEW_SELECTION_CHANGED] = - g_signal_new ("view-selection-changed", - GD_TYPE_MAIN_VIEW_GENERIC, - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 0); -} - -/** - * gd_main_view_generic_set_model: - * @self: - * @model: (allow-none): - * - */ -void -gd_main_view_generic_set_model (GdMainViewGeneric *self, - GtkTreeModel *model) -{ - GdMainViewGenericInterface *iface; - - iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self); - - (* iface->set_model) (self, model); -} - -GtkTreePath * -gd_main_view_generic_get_path_at_pos (GdMainViewGeneric *self, - gint x, - gint y) -{ - GdMainViewGenericInterface *iface; - - iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self); - - return (* iface->get_path_at_pos) (self, x, y); -} - -void -gd_main_view_generic_set_selection_mode (GdMainViewGeneric *self, - gboolean selection_mode) -{ - GdMainViewGenericInterface *iface; - - iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self); - - (* iface->set_selection_mode) (self, selection_mode); -} - - -typedef struct { - GtkTreePath *rubberband_start; - GtkTreePath *rubberband_end; -} RubberbandInfo; - -static void -rubber_band_info_destroy (RubberbandInfo *info) -{ - g_clear_pointer (&info->rubberband_start, - gtk_tree_path_free); - g_clear_pointer (&info->rubberband_end, - gtk_tree_path_free); - g_slice_free (RubberbandInfo, info); -} - -static RubberbandInfo* -get_rubber_band_info (GdMainViewGeneric *self) -{ - RubberbandInfo *info; - - info = g_object_get_data (G_OBJECT (self), "gd-main-view-generic-rubber-band"); - if (info == NULL) - { - info = g_slice_new0 (RubberbandInfo); - g_object_set_data_full (G_OBJECT (self), "gd-main-view-generic-rubber-band", - info, (GDestroyNotify)rubber_band_info_destroy); - } - - return info; -} - -void -gd_main_view_generic_set_rubberband_range (GdMainViewGeneric *self, - GtkTreePath *start, - GtkTreePath *end) -{ - RubberbandInfo *info; - - info = get_rubber_band_info (self); - - if (start == NULL || end == NULL) - { - g_clear_pointer (&info->rubberband_start, - gtk_tree_path_free); - g_clear_pointer (&info->rubberband_end, - gtk_tree_path_free); - } - else - { - if (gtk_tree_path_compare (start, end) < 0) - { - info->rubberband_start = gtk_tree_path_copy (start); - info->rubberband_end = gtk_tree_path_copy (end); - } - else - { - info->rubberband_start = gtk_tree_path_copy (end); - info->rubberband_end = gtk_tree_path_copy (start); - } - } - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -void -_gd_main_view_generic_get_rubberband_range (GdMainViewGeneric *self, - GtkTreePath **start, - GtkTreePath **end) -{ - RubberbandInfo *info; - - info = get_rubber_band_info (self); - - *start = info->rubberband_start; - *end = info->rubberband_end; -} - -void -gd_main_view_generic_scroll_to_path (GdMainViewGeneric *self, - GtkTreePath *path) -{ - GdMainViewGenericInterface *iface; - - iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self); - - (* iface->scroll_to_path) (self, path); -} - -/** - * gd_main_view_generic_get_model: - * - * Returns: (transfer none): The associated model - */ -GtkTreeModel * -gd_main_view_generic_get_model (GdMainViewGeneric *self) -{ - GdMainViewGenericInterface *iface; - - iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self); - - return (* iface->get_model) (self); -} - -static gboolean -build_selection_uris_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) -{ - GPtrArray *ptr_array = user_data; - gchar *uri; - gboolean is_selected; - - gtk_tree_model_get (model, iter, - GD_MAIN_COLUMN_URI, &uri, - GD_MAIN_COLUMN_SELECTED, &is_selected, - -1); - - if (is_selected) - g_ptr_array_add (ptr_array, uri); - else - g_free (uri); - - return FALSE; -} - -static gchar ** -model_get_selection_uris (GtkTreeModel *model) -{ - GPtrArray *ptr_array = g_ptr_array_new (); - - gtk_tree_model_foreach (model, - build_selection_uris_foreach, - ptr_array); - - g_ptr_array_add (ptr_array, NULL); - return (gchar **) g_ptr_array_free (ptr_array, FALSE); -} - -static gboolean -set_selection_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) -{ - gboolean selection = GPOINTER_TO_INT (user_data); - - gtk_list_store_set (GTK_LIST_STORE (model), iter, - GD_MAIN_COLUMN_SELECTED, selection, - -1); - - return FALSE; -} - -static void -set_all_selection (GdMainViewGeneric *self, - GtkTreeModel *model, - gboolean selection) -{ - GtkTreeModel *actual_model; - - if (!model) - return; - - if (GTK_IS_TREE_MODEL_FILTER (model)) - actual_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); - else - actual_model = model; - - gtk_tree_model_foreach (actual_model, - set_selection_foreach, - GINT_TO_POINTER (selection)); - g_signal_emit (self, signals[VIEW_SELECTION_CHANGED], 0); -} - -void -gd_main_view_generic_select_all (GdMainViewGeneric *self) -{ - GtkTreeModel *model = gd_main_view_generic_get_model (self); - - set_all_selection (self, model, TRUE); -} - -void -gd_main_view_generic_unselect_all (GdMainViewGeneric *self) -{ - GtkTreeModel *model = gd_main_view_generic_get_model (self); - - set_all_selection (self, model, FALSE); -} - -void -_gd_main_view_generic_dnd_common (GtkTreeModel *model, - gboolean selection_mode, - GtkTreePath *path, - GtkSelectionData *data) -{ - gchar **uris; - - if (selection_mode) - { - uris = model_get_selection_uris (model); - } - else - { - GtkTreeIter iter; - gboolean res; - gchar *uri = NULL; - - if (path != NULL) - { - res = gtk_tree_model_get_iter (model, &iter, path); - if (res) - gtk_tree_model_get (model, &iter, - GD_MAIN_COLUMN_URI, &uri, - -1); - } - - uris = g_new0 (gchar *, 2); - uris[0] = uri; - uris[1] = NULL; - } - - gtk_selection_data_set_uris (data, uris); - g_strfreev (uris); -} diff --git a/cut-n-paste/libgd/gd-main-view-generic.h b/cut-n-paste/libgd/gd-main-view-generic.h deleted file mode 100644 index 4df84ff4..00000000 --- a/cut-n-paste/libgd/gd-main-view-generic.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#ifndef __GD_MAIN_VIEW_GENERIC_H__ -#define __GD_MAIN_VIEW_GENERIC_H__ - -#include - -#include - -G_BEGIN_DECLS - -typedef enum { - GD_MAIN_COLUMN_ID, - GD_MAIN_COLUMN_URI, - GD_MAIN_COLUMN_PRIMARY_TEXT, - GD_MAIN_COLUMN_SECONDARY_TEXT, - GD_MAIN_COLUMN_ICON, - GD_MAIN_COLUMN_MTIME, - GD_MAIN_COLUMN_SELECTED, - - GD_MAIN_COLUMN_LAST -} GdMainColumns; - -#define GD_TYPE_MAIN_VIEW_GENERIC gd_main_view_generic_get_type() - -#define GD_MAIN_VIEW_GENERIC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - GD_TYPE_MAIN_VIEW_GENERIC, GdMainViewGeneric)) - -#define GD_MAIN_VIEW_GENERIC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - GD_TYPE_MAIN_VIEW_GENERIC, GdMainViewGenericIface)) - -#define GD_IS_MAIN_VIEW_GENERIC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - GD_TYPE_MAIN_VIEW_GENERIC)) - -#define GD_IS_MAIN_VIEW_GENERIC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - GD_TYPE_MAIN_VIEW_GENERIC)) - -#define GD_MAIN_VIEW_GENERIC_GET_IFACE(obj) \ - (G_TYPE_INSTANCE_GET_INTERFACE ((obj), \ - GD_TYPE_MAIN_VIEW_GENERIC, GdMainViewGenericIface)) - -typedef struct _GdMainViewGeneric GdMainViewGeneric; -typedef struct _GdMainViewGenericIface GdMainViewGenericIface; - -struct _GdMainViewGenericIface -{ - GTypeInterface base_iface; - - /* vtable */ - void (* set_model) (GdMainViewGeneric *self, - GtkTreeModel *model); - GtkTreeModel * (* get_model) (GdMainViewGeneric *self); - - GtkTreePath * (* get_path_at_pos) (GdMainViewGeneric *self, - gint x, - gint y); - void (* scroll_to_path) (GdMainViewGeneric *self, - GtkTreePath *path); - void (* set_selection_mode) (GdMainViewGeneric *self, - gboolean selection_mode); -}; - -GType gd_main_view_generic_get_type (void) G_GNUC_CONST; - -void gd_main_view_generic_set_model (GdMainViewGeneric *self, - GtkTreeModel *model); -GtkTreeModel * gd_main_view_generic_get_model (GdMainViewGeneric *self); - -void gd_main_view_generic_scroll_to_path (GdMainViewGeneric *self, - GtkTreePath *path); -void gd_main_view_generic_set_selection_mode (GdMainViewGeneric *self, - gboolean selection_mode); -GtkTreePath * gd_main_view_generic_get_path_at_pos (GdMainViewGeneric *self, - gint x, - gint y); -void gd_main_view_generic_select_all (GdMainViewGeneric *self); -void gd_main_view_generic_unselect_all (GdMainViewGeneric *self); -void gd_main_view_generic_set_rubberband_range (GdMainViewGeneric *self, - GtkTreePath *start, - GtkTreePath *end); - -/* private */ -void _gd_main_view_generic_dnd_common (GtkTreeModel *model, - gboolean selection_mode, - GtkTreePath *path, - GtkSelectionData *data); -void _gd_main_view_generic_get_rubberband_range (GdMainViewGeneric *self, - GtkTreePath **start, - GtkTreePath **end); - -G_END_DECLS - -#endif /* __GD_MAIN_VIEW_GENERIC_H__ */ diff --git a/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.c b/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.c deleted file mode 100644 index 63f1d740..00000000 --- a/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#include "gd-toggle-pixbuf-renderer.h" - -G_DEFINE_TYPE (GdTogglePixbufRenderer, gd_toggle_pixbuf_renderer, GTK_TYPE_CELL_RENDERER_PIXBUF); - -enum { - PROP_ACTIVE = 1, - PROP_TOGGLE_VISIBLE, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; - -struct _GdTogglePixbufRendererPrivate { - gboolean active; - gboolean toggle_visible; -}; - -static void -gd_toggle_pixbuf_renderer_render (GtkCellRenderer *cell, - cairo_t *cr, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - gint icon_size = -1; - gint check_x, check_y, x_offset, xpad, ypad; - GtkStyleContext *context; - GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (cell); - GtkTextDirection direction; - - GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->render - (cell, cr, widget, - background_area, cell_area, flags); - - if (!self->priv->toggle_visible) - return; - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - direction = gtk_widget_get_direction (widget); - gtk_widget_style_get (widget, - "check-icon-size", &icon_size, - NULL); - - if (icon_size == -1) - icon_size = 40; - - if (direction == GTK_TEXT_DIR_RTL) - x_offset = xpad; - else - x_offset = cell_area->width - icon_size - xpad; - - check_x = cell_area->x + x_offset; - check_y = cell_area->y + cell_area->height - icon_size - ypad; - - context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK); - - if (self->priv->active) - gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE); - - gtk_render_check (context, cr, - check_x, check_y, - icon_size, icon_size); - - gtk_style_context_restore (context); -} - -static void -gd_toggle_pixbuf_renderer_get_size (GtkCellRenderer *cell, - GtkWidget *widget, - const GdkRectangle *cell_area, - gint *x_offset, - gint *y_offset, - gint *width, - gint *height) -{ - gint icon_size; - - gtk_widget_style_get (widget, - "check-icon-size", &icon_size, - NULL); - - GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->get_size - (cell, widget, cell_area, - x_offset, y_offset, width, height); - - *width += icon_size / 4; -} - -static void -gd_toggle_pixbuf_renderer_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (object); - - switch (property_id) - { - case PROP_ACTIVE: - g_value_set_boolean (value, self->priv->active); - break; - case PROP_TOGGLE_VISIBLE: - g_value_set_boolean (value, self->priv->toggle_visible); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gd_toggle_pixbuf_renderer_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (object); - - switch (property_id) - { - case PROP_ACTIVE: - self->priv->active = g_value_get_boolean (value); - break; - case PROP_TOGGLE_VISIBLE: - self->priv->toggle_visible = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gd_toggle_pixbuf_renderer_class_init (GdTogglePixbufRendererClass *klass) -{ - GObjectClass *oclass = G_OBJECT_CLASS (klass); - GtkCellRendererClass *crclass = GTK_CELL_RENDERER_CLASS (klass); - - crclass->render = gd_toggle_pixbuf_renderer_render; - crclass->get_size = gd_toggle_pixbuf_renderer_get_size; - oclass->get_property = gd_toggle_pixbuf_renderer_get_property; - oclass->set_property = gd_toggle_pixbuf_renderer_set_property; - - properties[PROP_ACTIVE] = - g_param_spec_boolean ("active", - "Active", - "Whether the cell renderer is active", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - properties[PROP_TOGGLE_VISIBLE] = - g_param_spec_boolean ("toggle-visible", - "Toggle visible", - "Whether to draw the toggle indicator", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_type_class_add_private (klass, sizeof (GdTogglePixbufRendererPrivate)); - g_object_class_install_properties (oclass, NUM_PROPERTIES, properties); -} - -static void -gd_toggle_pixbuf_renderer_init (GdTogglePixbufRenderer *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_TOGGLE_PIXBUF_RENDERER, - GdTogglePixbufRendererPrivate); -} - -GtkCellRenderer * -gd_toggle_pixbuf_renderer_new (void) -{ - return g_object_new (GD_TYPE_TOGGLE_PIXBUF_RENDERER, - "follow-state", TRUE, NULL); -} diff --git a/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.h b/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.h deleted file mode 100644 index fe54cf46..00000000 --- a/cut-n-paste/libgd/gd-toggle-pixbuf-renderer.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2011 Red Hat, Inc. - * - * This program 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 program 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 program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Cosimo Cecchi - * - */ - -#ifndef _GD_TOGGLE_PIXBUF_RENDERER_H -#define _GD_TOGGLE_PIXBUF_RENDERER_H - -#include - -#include - -G_BEGIN_DECLS - -#define GD_TYPE_TOGGLE_PIXBUF_RENDERER gd_toggle_pixbuf_renderer_get_type() - -#define GD_TOGGLE_PIXBUF_RENDERER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - GD_TYPE_TOGGLE_PIXBUF_RENDERER, GdTogglePixbufRenderer)) - -#define GD_TOGGLE_PIXBUF_RENDERER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - GD_TYPE_TOGGLE_PIXBUF_RENDERER, GdTogglePixbufRendererClass)) - -#define GD_IS_TOGGLE_PIXBUF_RENDERER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - GD_TYPE_TOGGLE_PIXBUF_RENDERER)) - -#define GD_IS_TOGGLE_PIXBUF_RENDERER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - GD_TYPE_TOGGLE_PIXBUF_RENDERER)) - -#define GD_TOGGLE_PIXBUF_RENDERER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - GD_TYPE_TOGGLE_PIXBUF_RENDERER, GdTogglePixbufRendererClass)) - -typedef struct _GdTogglePixbufRenderer GdTogglePixbufRenderer; -typedef struct _GdTogglePixbufRendererClass GdTogglePixbufRendererClass; -typedef struct _GdTogglePixbufRendererPrivate GdTogglePixbufRendererPrivate; - -struct _GdTogglePixbufRenderer -{ - GtkCellRendererPixbuf parent; - - GdTogglePixbufRendererPrivate *priv; -}; - -struct _GdTogglePixbufRendererClass -{ - GtkCellRendererPixbufClass parent_class; -}; - -GType gd_toggle_pixbuf_renderer_get_type (void) G_GNUC_CONST; - -GtkCellRenderer *gd_toggle_pixbuf_renderer_new (void); - -G_END_DECLS - -#endif /* _GD_TOGGLE_PIXBUF_RENDERER_H */ diff --git a/shell/ev-recent-view.c b/shell/ev-recent-view.c index c0aa00ae..995bcd25 100644 --- a/shell/ev-recent-view.c +++ b/shell/ev-recent-view.c @@ -26,15 +26,19 @@ #include "ev-recent-view.h" #include "ev-file-helpers.h" #include "gd-icon-utils.h" -#include "gd-main-view-generic.h" -#include "gd-main-icon-view.h" +#include "gd-two-lines-renderer.h" #include "ev-document-misc.h" #include "ev-document-model.h" #include "ev-jobs.h" #include "ev-job-scheduler.h" typedef enum { - EV_RECENT_VIEW_JOB_COLUMN = GD_MAIN_COLUMN_LAST, + EV_RECENT_VIEW_COLUMN_URI, + EV_RECENT_VIEW_COLUMN_PRIMARY_TEXT, + EV_RECENT_VIEW_COLUMN_SECONDARY_TEXT, + EV_RECENT_VIEW_COLUMN_ICON, + EV_RECENT_VIEW_COLUMN_MTIME, + EV_RECENT_VIEW_COLUMN_JOB, NUM_COLUMNS } EvRecentViewColumns; @@ -66,7 +70,7 @@ ev_recent_view_clear_job (GtkTreeModel *model, { EvJob *job; - gtk_tree_model_get (model, iter, EV_RECENT_VIEW_JOB_COLUMN, &job, -1); + gtk_tree_model_get (model, iter, EV_RECENT_VIEW_COLUMN_JOB, &job, -1); if (job != NULL) { ev_job_cancel (job); @@ -142,7 +146,6 @@ on_button_release_event (GtkWidget *view, EvRecentView *ev_recent_view) { EvRecentViewPrivate *priv = ev_recent_view->priv; - GdMainViewGeneric *generic = GD_MAIN_VIEW_GENERIC (priv->view); GtkTreePath *path; /* eat double/triple click events */ @@ -152,7 +155,7 @@ on_button_release_event (GtkWidget *view, if (priv->pressed_item_tree_path == NULL) return FALSE; - path = gd_main_view_generic_get_path_at_pos (generic, event->x, event->y); + path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (priv->view), event->x, event->y); if (path == NULL) return FALSE; @@ -170,11 +173,7 @@ on_button_release_event (GtkWidget *view, gtk_tree_path_free (path); gtk_tree_model_get (GTK_TREE_MODEL (priv->model), &iter, - GD_MAIN_COLUMN_URI, &uri, - -1); - gtk_list_store_set (priv->model, - &iter, - GD_MAIN_COLUMN_SELECTED, TRUE, + EV_RECENT_VIEW_COLUMN_URI, &uri, -1); g_signal_emit (ev_recent_view, signals[ITEM_ACTIVATED], 0, uri); g_free (uri); @@ -194,10 +193,10 @@ on_button_press_event (GtkWidget *view, EvRecentView *ev_recent_view) { EvRecentViewPrivate *priv = ev_recent_view->priv; - GdMainViewGeneric *generic = GD_MAIN_VIEW_GENERIC (priv->view); g_clear_pointer (&priv->pressed_item_tree_path, gtk_tree_path_free); - priv->pressed_item_tree_path = gd_main_view_generic_get_path_at_pos (generic, event->x, event->y); + priv->pressed_item_tree_path = + gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (priv->view), event->x, event->y); return TRUE; } @@ -230,8 +229,8 @@ thumbnail_job_completed_callback (EvJobThumbnail *job, gtk_tree_path_free (path); gtk_list_store_set (priv->model, &iter, - GD_MAIN_COLUMN_ICON, surface, - EV_RECENT_VIEW_JOB_COLUMN, NULL, + EV_RECENT_VIEW_COLUMN_ICON, surface, + EV_RECENT_VIEW_COLUMN_JOB, NULL, -1); } @@ -287,22 +286,22 @@ document_load_job_completed_callback (EvJobLoad *job_load, info = ev_document_get_info (document); if (info->fields_mask & EV_DOCUMENT_INFO_TITLE && info->title && info->title[0] != '\0') gtk_list_store_set (priv->model, &iter, - GD_MAIN_COLUMN_PRIMARY_TEXT, info->title, + EV_RECENT_VIEW_COLUMN_PRIMARY_TEXT, info->title, -1); if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR && info->author && info->author[0] != '\0') gtk_list_store_set (priv->model, &iter, - GD_MAIN_COLUMN_SECONDARY_TEXT, info->author, + EV_RECENT_VIEW_COLUMN_SECONDARY_TEXT, info->author, -1); gtk_list_store_set (priv->model, &iter, - EV_RECENT_VIEW_JOB_COLUMN, job_thumbnail, + EV_RECENT_VIEW_COLUMN_JOB, job_thumbnail, -1); ev_job_scheduler_push_job (EV_JOB (job_thumbnail), EV_JOB_PRIORITY_HIGH); g_object_unref (job_thumbnail); } else { gtk_list_store_set (priv->model, &iter, - EV_RECENT_VIEW_JOB_COLUMN, NULL, + EV_RECENT_VIEW_COLUMN_JOB, NULL, -1); } } @@ -314,7 +313,6 @@ ev_recent_view_refresh (EvRecentView *ev_recent_view) guint n_items = 0; const gchar *evince = g_get_application_name (); EvRecentViewPrivate *priv = ev_recent_view->priv; - GdMainViewGeneric *generic = GD_MAIN_VIEW_GENERIC (priv->view); items = gtk_recent_manager_get_items (priv->recent_manager); items = g_list_sort (items, (GCompareFunc) compare_recent_items); @@ -351,13 +349,12 @@ ev_recent_view_refresh (EvRecentView *ev_recent_view) gtk_list_store_append (priv->model, &iter); gtk_list_store_set (priv->model, &iter, - GD_MAIN_COLUMN_URI, uri, - GD_MAIN_COLUMN_PRIMARY_TEXT, gtk_recent_info_get_display_name (info), - GD_MAIN_COLUMN_SECONDARY_TEXT, NULL, - GD_MAIN_COLUMN_ICON, thumbnail, - GD_MAIN_COLUMN_MTIME, gtk_recent_info_get_modified (info), - GD_MAIN_COLUMN_SELECTED, FALSE, - EV_RECENT_VIEW_JOB_COLUMN, job_load, + EV_RECENT_VIEW_COLUMN_URI, uri, + EV_RECENT_VIEW_COLUMN_PRIMARY_TEXT, gtk_recent_info_get_display_name (info), + EV_RECENT_VIEW_COLUMN_SECONDARY_TEXT, NULL, + EV_RECENT_VIEW_COLUMN_ICON, thumbnail, + EV_RECENT_VIEW_COLUMN_MTIME, gtk_recent_info_get_modified (info), + EV_RECENT_VIEW_COLUMN_JOB, job_load, -1); if (job_load) { @@ -383,8 +380,6 @@ ev_recent_view_refresh (EvRecentView *ev_recent_view) } g_list_free_full (items, (GDestroyNotify)gtk_recent_info_unref); - - gd_main_view_generic_set_model (generic, GTK_TREE_MODEL (priv->model)); } static void @@ -392,10 +387,39 @@ ev_recent_view_constructed (GObject *object) { EvRecentView *ev_recent_view = EV_RECENT_VIEW (object); EvRecentViewPrivate *priv = ev_recent_view->priv; + GtkCellRenderer *renderer; G_OBJECT_CLASS (ev_recent_view_parent_class)->constructed (object); - priv->view = gd_main_icon_view_new (); + priv->view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->model)); + + gtk_icon_view_set_column_spacing (GTK_ICON_VIEW (priv->view), 20); + gtk_icon_view_set_margin (GTK_ICON_VIEW (priv->view), 16); + gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (priv->view), GTK_SELECTION_NONE); + gtk_widget_set_hexpand (priv->view, TRUE); + gtk_widget_set_vexpand (priv->view, TRUE); + + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "xalign", 0.5, "yalign", 0.5, NULL); + + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->view), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer, + "surface", EV_RECENT_VIEW_COLUMN_ICON); + + renderer = gd_two_lines_renderer_new (); + g_object_set (renderer, + "xalign", 0.5, + "alignment", PANGO_ALIGN_CENTER, + "wrap-mode", PANGO_WRAP_WORD_CHAR, + "wrap-width", 128, + "text-lines", 3, + NULL); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->view), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer, + "text", EV_RECENT_VIEW_COLUMN_PRIMARY_TEXT); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer, + "line-two", EV_RECENT_VIEW_COLUMN_SECONDARY_TEXT); + g_signal_connect (priv->view, "button-press-event", G_CALLBACK (on_button_press_event), ev_recent_view); @@ -423,15 +447,12 @@ ev_recent_view_init (EvRecentView *ev_recent_view) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, CAIRO_GOBJECT_TYPE_SURFACE, G_TYPE_LONG, - G_TYPE_BOOLEAN, - EV_TYPE_JOB, - G_TYPE_BOOLEAN); + EV_TYPE_JOB); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->model), - GD_MAIN_COLUMN_MTIME, + EV_RECENT_VIEW_COLUMN_MTIME, GTK_SORT_DESCENDING); gtk_widget_set_hexpand (GTK_WIDGET (ev_recent_view), TRUE);