[evince/wip/recent-view: 1/4] ev-recent-view: Added bookshelf view for recent documents



commit 13651f44d68310b3cffccc36341cf633e25dd2c9
Author: Aakash Goenka <aakash goenka gmail com>
Date:   Sun Feb 23 14:53:19 2014 -0800

    ev-recent-view: Added bookshelf view for recent documents
    
    * Files are added to the bookshelf only if they exists
    * Save thumbnails and metadata
    * Use gtk_recent_info_get_modified instead of
      gtk_recent_info_get_visited for ordering the recent items.

 shell/Makefile.am          |    2 +
 shell/ev-metadata.c        |   33 +++
 shell/ev-metadata.h        |    6 +
 shell/ev-recent-view.c     |  596 ++++++++++++++++++++++++++++++++++++++++++++
 shell/ev-recent-view.h     |   60 +++++
 shell/evince.gresource.xml |    1 +
 shell/thumbnail-frame.png  |  Bin 0 -> 832 bytes
 7 files changed, 698 insertions(+), 0 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 3d3d3e7..a2d9d49 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -47,6 +47,8 @@ evince_SOURCES=                               \
        ev-properties-license.h         \
        ev-open-recent-action.c         \
        ev-open-recent-action.h         \
+       ev-recent-view.c                \
+       ev-recent-view.h                \
        ev-toolbar.c                    \
        ev-toolbar.h                    \
        ev-utils.c                      \
diff --git a/shell/ev-metadata.c b/shell/ev-metadata.c
index b0e23a1..52e40c1 100644
--- a/shell/ev-metadata.c
+++ b/shell/ev-metadata.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include <glib.h>
 #include <gio/gio.h>
 #include <string.h>
 
@@ -229,6 +230,26 @@ ev_metadata_get_int (EvMetadata  *metadata,
 }
 
 gboolean
+ev_metadata_get_uint64 (EvMetadata  *metadata,
+                        const gchar *key,
+                        guint64     *value)
+{
+       gchar   *string_value;
+       gchar   *endptr;
+       guint64  uint64_value;
+
+       if (!ev_metadata_get_string (metadata, key, &string_value))
+               return FALSE;
+
+       uint64_value = g_ascii_strtoull (string_value, &endptr, 0);
+       if (uint64_value == 0 && string_value == endptr)
+               return FALSE;
+
+       *value = uint64_value;
+       return TRUE;
+}
+
+gboolean
 ev_metadata_set_int (EvMetadata  *metadata,
                     const gchar *key,
                     gint         value)
@@ -241,6 +262,18 @@ ev_metadata_set_int (EvMetadata  *metadata,
 }
 
 gboolean
+ev_metadata_set_uint64 (EvMetadata  *metadata,
+                       const gchar *key,
+                       guint64      value)
+{
+       gchar string_value[21];
+
+       g_snprintf (string_value, sizeof (string_value), "%"G_GUINT64_FORMAT, value);
+
+       return ev_metadata_set_string (metadata, key, string_value);
+}
+
+gboolean
 ev_metadata_get_double (EvMetadata  *metadata,
                        const gchar *key,
                        gdouble     *value)
diff --git a/shell/ev-metadata.h b/shell/ev-metadata.h
index 7fd4f05..ba31069 100644
--- a/shell/ev-metadata.h
+++ b/shell/ev-metadata.h
@@ -62,6 +62,12 @@ gboolean    ev_metadata_get_boolean           (EvMetadata  *metadata,
 gboolean    ev_metadata_set_boolean           (EvMetadata  *metadata,
                                               const gchar *key,
                                               gboolean     value);
+gboolean    ev_metadata_get_uint64            (EvMetadata  *metadata,
+                                               const gchar *key,
+                                               guint64     *value);
+gboolean    ev_metadata_set_uint64            (EvMetadata  *metadata,
+                                              const gchar *key,
+                                              guint64      value);
 gboolean    ev_metadata_has_key               (EvMetadata  *metadata,
                                                const gchar *key);
 
diff --git a/shell/ev-recent-view.c b/shell/ev-recent-view.c
new file mode 100644
index 0000000..7d58a89
--- /dev/null
+++ b/shell/ev-recent-view.c
@@ -0,0 +1,596 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2013 Aakash Goenka
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#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 "ev-document-misc.h"
+#include "ev-document-model.h"
+#include "ev-jobs.h"
+#include "ev-job-scheduler.h"
+#include "ev-metadata.h"
+
+typedef enum {
+       EV_RECENT_VIEW_JOB_COLUMN = GD_MAIN_COLUMN_LAST,
+       EV_RECENT_VIEW_THUMBNAILED_COLUMN,
+       EV_RECENT_VIEW_DOCUMENT_COLUMN,
+       EV_RECENT_VIEW_METADATA_COLUMN,
+       NUM_COLUMNS
+} EvRecentViewColumns;
+
+struct _EvRecentViewPrivate {
+       GtkWidget         *view;
+       GtkListStore      *model;
+       GtkRecentManager  *recent_manager;
+       GtkTreePath       *pressed_item_tree_path;
+       guint              recent_manager_changed_handler_id;
+};
+
+enum {
+       ITEM_ACTIVATED,
+       NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
+static void     thumbnail_job_completed_callback         (EvJobThumbnail  *job,
+                                                         EvRecentView     *ev_recent_view);
+static void     document_load_job_completed_callback     (EvJobLoad   *job_load,
+                                                         EvRecentView *ev_recent_view);
+static gboolean ev_recent_view_clear_job                 (GtkTreeModel *model,
+                                                          GtkTreePath  *path,
+                                                          GtkTreeIter  *iter,
+                                                          gpointer      data);
+static void     ev_recent_view_clear_model               (EvRecentView *ev_recent_view);
+static void     ev_recent_view_refresh                   (EvRecentView *ev_recent_view);
+
+G_DEFINE_TYPE (EvRecentView, ev_recent_view, GTK_TYPE_SCROLLED_WINDOW)
+
+#define ICON_VIEW_SIZE 128
+#define MAX_RECENT_VIEW_ITEMS 20
+
+static void
+ev_recent_view_dispose (GObject *obj)
+{
+       EvRecentView        *ev_recent_view = EV_RECENT_VIEW (obj);
+       EvRecentViewPrivate *priv = ev_recent_view->priv;
+       
+       if (priv->model) {
+               ev_recent_view_clear_model (ev_recent_view);
+               g_object_unref (priv->model);
+               priv->model = NULL;
+       }
+
+       if (priv->recent_manager_changed_handler_id) {
+               g_signal_handler_disconnect (priv->recent_manager,
+                                            priv->recent_manager_changed_handler_id);
+               priv->recent_manager_changed_handler_id = 0;
+       }
+       priv->recent_manager = NULL;
+
+       G_OBJECT_CLASS (ev_recent_view_parent_class)->dispose (obj);
+}
+
+static gboolean
+metadata_is_stale (EvMetadata *metadata,
+                   GFile      *file)
+{
+       GFileInfo *info = NULL;
+       GError    *error = NULL;
+       guint64    mtime_metadata;
+       guint64    mtime_file;
+
+       info = g_file_query_info (file,
+                                 G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                 0,
+                                 NULL,
+                                 &error);
+       if (!info) {
+               g_warning ("%s", error->message);
+               g_error_free (error);
+
+               return TRUE;
+       }
+
+       if (!ev_metadata_get_uint64 (metadata, "mtime", &mtime_metadata))
+               return TRUE;
+
+       mtime_file = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+       if (mtime_file != 0 && mtime_metadata >= mtime_file)
+               return FALSE;
+
+       return TRUE;
+}
+
+static void
+save_thumbnail (GdkPixbuf  *pixbuf,
+                EvMetadata *metadata)
+{
+       GFile     *thumbnail_file = NULL;
+       GError    *error = NULL;
+       gchar     *thumbnail_path = NULL;
+
+       thumbnail_file = ev_mkstemp_file ("thumb.XXXXXX", &error);
+
+       if (thumbnail_file) {
+               thumbnail_path = g_file_get_path (thumbnail_file);
+               g_object_unref (thumbnail_file);
+       }
+
+       if (thumbnail_path) {
+               gdk_pixbuf_save (pixbuf, thumbnail_path,
+                                "png", &error, NULL);
+               if (!error)
+                       ev_metadata_set_string (metadata, "thumbnail-path", thumbnail_path);
+               g_free (thumbnail_path);
+       }
+
+       if (error)
+               g_error_free (error);
+}
+
+static gboolean
+ev_recent_view_clear_job (GtkTreeModel *model,
+                          GtkTreePath  *path,
+                          GtkTreeIter  *iter,
+                          gpointer      data)
+{
+       EvJob *job;
+
+       gtk_tree_model_get (model, iter, EV_RECENT_VIEW_JOB_COLUMN, &job, -1);
+
+       if (job != NULL) {
+               ev_job_cancel (job);
+               g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, data);
+               g_signal_handlers_disconnect_by_func (job, document_load_job_completed_callback, data);
+               g_object_unref (job);
+       }
+
+       return FALSE;
+}
+
+static void
+ev_recent_view_clear_model (EvRecentView *ev_recent_view)
+{
+       EvRecentViewPrivate *priv = ev_recent_view->priv;
+
+       gtk_tree_model_foreach (GTK_TREE_MODEL (priv->model), ev_recent_view_clear_job, ev_recent_view);
+       gtk_list_store_clear (priv->model);
+}
+
+static gint
+compare_recent_items (GtkRecentInfo *a,
+                      GtkRecentInfo *b)
+{
+       gboolean     has_ev_a, has_ev_b;
+       const gchar *evince = g_get_application_name ();
+
+       has_ev_a = gtk_recent_info_has_application (a, evince);
+       has_ev_b = gtk_recent_info_has_application (b, evince);
+       
+       if (has_ev_a && has_ev_b) {
+               time_t time_a, time_b;
+
+               time_a = gtk_recent_info_get_modified (a);
+               time_b = gtk_recent_info_get_modified (b);
+
+               return (time_b - time_a);
+       } else if (has_ev_a) {
+               return -1;
+       } else if (has_ev_b) {
+               return 1;
+       }
+
+       return 0;
+}
+
+static GdMainViewGeneric *
+get_generic (EvRecentView *ev_recent_view)
+{
+       if (ev_recent_view->priv->view != NULL)
+               return GD_MAIN_VIEW_GENERIC (ev_recent_view->priv->view);
+
+       return NULL;
+}
+
+static gboolean
+on_button_release_event (GtkWidget      *view,
+                         GdkEventButton *event,
+                         EvRecentView   *ev_recent_view)
+{
+       GdMainViewGeneric *generic = get_generic (ev_recent_view);
+       GtkTreePath       *path;
+       gboolean           result = FALSE;
+
+       /* eat double/triple click events */
+       if (event->type != GDK_BUTTON_RELEASE)
+               return TRUE;
+
+       path = gd_main_view_generic_get_path_at_pos (generic, event->x, event->y);
+
+       if (path == NULL)
+               return result;
+
+       if (ev_recent_view->priv->pressed_item_tree_path == NULL) {
+               gtk_tree_path_free (path);
+               return result;
+       }
+
+       if (!gtk_tree_path_compare (path, ev_recent_view->priv->pressed_item_tree_path))
+               result = TRUE;
+       gtk_tree_path_free (ev_recent_view->priv->pressed_item_tree_path);
+       ev_recent_view->priv->pressed_item_tree_path = NULL;
+
+       if (result) {
+               GtkTreeIter iter;
+               gchar      *uri;
+
+               if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (ev_recent_view->priv->model), &iter, path)) {
+                       gtk_tree_path_free (path);
+                       return result;
+               }
+
+               gtk_tree_model_get (GTK_TREE_MODEL (ev_recent_view->priv->model), &iter,
+                                   GD_MAIN_COLUMN_URI, &uri,
+                                   -1);
+               gtk_list_store_set (ev_recent_view->priv->model,
+                                   &iter,
+                                   GD_MAIN_COLUMN_SELECTED, TRUE,
+                                   -1);
+               g_signal_emit (ev_recent_view, signals[ITEM_ACTIVATED], 0, uri);
+       }
+       gtk_tree_path_free (path);
+       return result;
+}
+
+static gboolean
+on_button_press_event (GtkWidget      *view,
+                       GdkEventButton *event,
+                       EvRecentView   *ev_recent_view)
+{
+       GdMainViewGeneric *generic = get_generic (ev_recent_view);
+
+       if (ev_recent_view->priv->pressed_item_tree_path != NULL)
+               gtk_tree_path_free (ev_recent_view->priv->pressed_item_tree_path);
+
+       ev_recent_view->priv->pressed_item_tree_path =
+               gd_main_view_generic_get_path_at_pos (generic, event->x, event->y);
+
+       return FALSE;
+}
+
+static void
+thumbnail_job_completed_callback (EvJobThumbnail *job,
+                                  EvRecentView   *ev_recent_view)
+{
+       EvRecentViewPrivate *priv = ev_recent_view->priv;
+       GtkTreeIter         *iter;
+       GdkPixbuf           *pixbuf;
+       EvDocument          *document;
+       EvMetadata          *metadata;
+       GtkBorder            border;
+
+       border.left = 4;
+       border.right = 3;
+       border.top = 3;
+       border.bottom = 6;
+
+       pixbuf = ev_document_misc_render_thumbnail_with_frame (GTK_WIDGET (ev_recent_view), job->thumbnail);
+
+       pixbuf = gd_embed_image_in_frame (pixbuf,
+                                         "resource:///org/gnome/evince/shell/ui/thumbnail-frame.png",
+                                         &border, &border);
+       iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
+
+       gtk_tree_model_get (GTK_TREE_MODEL (priv->model),
+                           iter,
+                           EV_RECENT_VIEW_DOCUMENT_COLUMN, &document,
+                           EV_RECENT_VIEW_METADATA_COLUMN, &metadata,
+                           -1);
+
+       gtk_list_store_set (priv->model,
+                           iter,
+                           GD_MAIN_COLUMN_ICON, pixbuf,
+                           EV_RECENT_VIEW_THUMBNAILED_COLUMN, TRUE,
+                           EV_RECENT_VIEW_JOB_COLUMN, NULL,
+                           -1);
+
+       if (metadata) {
+               save_thumbnail (pixbuf, metadata);
+               ev_metadata_set_uint64 (metadata, "mtime", g_get_real_time ());
+               g_object_unref (metadata);
+       }
+        g_object_unref (pixbuf);
+}
+
+static void
+document_load_job_completed_callback (EvJobLoad    *job_load,
+                                      EvRecentView *ev_recent_view)
+{
+       EvRecentViewPrivate *priv = ev_recent_view->priv;
+       GtkTreeIter         *iter;
+       EvDocument          *document;
+       EvMetadata          *metadata;
+
+       document = EV_JOB (job_load)->document;
+       iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job_load), "tree_iter");
+
+       if (document) {
+               EvJob           *job_thumbnail;
+               gdouble          height;
+               gdouble          width;
+               gdouble          scale;
+
+               ev_document_get_page_size (document, 0, &width, &height);
+
+               scale = (gdouble)ICON_VIEW_SIZE / height < (gdouble)ICON_VIEW_SIZE / width ?
+                       (gdouble)ICON_VIEW_SIZE / height : (gdouble)ICON_VIEW_SIZE / width;
+               job_thumbnail = ev_job_thumbnail_new (document, 0, 0, scale);
+
+               ev_job_thumbnail_set_has_frame (EV_JOB_THUMBNAIL (job_thumbnail), FALSE);
+
+               g_object_set_data_full (G_OBJECT (job_thumbnail), "tree_iter",
+                                       gtk_tree_iter_copy (iter),
+                                       (GDestroyNotify) gtk_tree_iter_free);
+
+               g_signal_connect (job_thumbnail, "finished",
+                                 G_CALLBACK (thumbnail_job_completed_callback),
+                                 ev_recent_view);
+
+               gtk_list_store_set (priv->model,
+                                   iter,
+                                   EV_RECENT_VIEW_THUMBNAILED_COLUMN, FALSE,
+                                   EV_RECENT_VIEW_JOB_COLUMN, job_thumbnail,
+                                   EV_RECENT_VIEW_DOCUMENT_COLUMN, document,
+                                   -1);
+
+               ev_job_scheduler_push_job (EV_JOB (job_thumbnail), EV_JOB_PRIORITY_HIGH);
+
+               g_object_unref (job_thumbnail);
+
+       } else {
+               gtk_tree_model_get (GTK_TREE_MODEL (priv->model),
+                                   iter,
+                                   EV_RECENT_VIEW_METADATA_COLUMN, &metadata,
+                                   -1);
+
+               gtk_list_store_set (priv->model,
+                                   iter,
+                                   EV_RECENT_VIEW_THUMBNAILED_COLUMN, TRUE,
+                                   EV_RECENT_VIEW_JOB_COLUMN, NULL,
+                                   -1);
+
+               if (metadata) {
+                       GdkPixbuf *thumbnail;
+
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->model),
+                                           iter,
+                                           GD_MAIN_COLUMN_ICON, &thumbnail,
+                                           -1);
+
+                       if (thumbnail)
+                               save_thumbnail (thumbnail, metadata);
+
+                       ev_metadata_set_uint64 (metadata, "mtime", g_get_real_time ());
+
+                       g_object_unref (metadata);
+                       g_object_unref (thumbnail);
+               }
+       }
+}
+
+static void
+ev_recent_view_refresh (EvRecentView *ev_recent_view)
+{
+       GList             *items, *l;
+       guint              n_items = 0;
+       const gchar       *evince = g_get_application_name ();
+       GdMainViewGeneric *generic = get_generic (ev_recent_view);
+
+       items = gtk_recent_manager_get_items (ev_recent_view->priv->recent_manager);
+       items = g_list_sort (items, (GCompareFunc) compare_recent_items);
+
+       gtk_list_store_clear (ev_recent_view->priv->model);
+
+       for (l = items; l && l->data; l = g_list_next (l)) {
+               EvJob         *job_load = NULL;
+               EvMetadata    *metadata = NULL;
+               GFile         *file;
+               const gchar   *name;
+               const gchar   *uri;
+               gchar         *thumbnail_path;
+               GtkRecentInfo *info;
+               GdkPixbuf     *thumbnail;
+               GtkTreeIter    iter;
+               long           access_time;
+
+               info = (GtkRecentInfo *) l->data;
+
+               if (!gtk_recent_info_has_application (info, evince))
+                       continue;
+
+               if (gtk_recent_info_is_local (info) && !gtk_recent_info_exists (info))
+                       continue;
+
+               name = gtk_recent_info_get_display_name (info);
+               uri = gtk_recent_info_get_uri (info);
+               file = g_file_new_for_uri (uri);
+
+               if (ev_is_metadata_supported_for_file (file)) {
+                       
+                       metadata = ev_metadata_new (file);
+                       if (metadata_is_stale (metadata, file) ||
+                           !ev_metadata_get_string (metadata, "thumbnail-path", &thumbnail_path))
+                               goto load_document;
+
+                       thumbnail = gdk_pixbuf_new_from_file (thumbnail_path, NULL);
+                       if (!thumbnail)
+                               goto load_document;
+               } else {
+
+               load_document:
+
+                       thumbnail = gtk_recent_info_get_icon (info, ICON_VIEW_SIZE);
+                       job_load = ev_job_load_new (uri);
+                       g_signal_connect (job_load, "finished",
+                                         G_CALLBACK (document_load_job_completed_callback),
+                                         ev_recent_view);
+               }
+               access_time = gtk_recent_info_get_modified (info);
+
+               gtk_list_store_append (ev_recent_view->priv->model, &iter);
+
+               gtk_list_store_set (ev_recent_view->priv->model, &iter,
+                                   GD_MAIN_COLUMN_URI, uri,
+                                   GD_MAIN_COLUMN_PRIMARY_TEXT, name,
+                                   GD_MAIN_COLUMN_SECONDARY_TEXT, NULL,
+                                   GD_MAIN_COLUMN_ICON, thumbnail,
+                                   GD_MAIN_COLUMN_MTIME, access_time,
+                                   GD_MAIN_COLUMN_SELECTED, FALSE,
+                                   EV_RECENT_VIEW_DOCUMENT_COLUMN, NULL,
+                                   EV_RECENT_VIEW_JOB_COLUMN, job_load,
+                                   EV_RECENT_VIEW_THUMBNAILED_COLUMN, FALSE,
+                                   EV_RECENT_VIEW_METADATA_COLUMN, metadata,
+                                   -1);
+
+               if (job_load) {
+                       
+                       g_object_set_data_full (G_OBJECT (job_load), "tree_iter",
+                                               gtk_tree_iter_copy (&iter),
+                                               (GDestroyNotify) gtk_tree_iter_free);
+
+                       ev_job_scheduler_push_job (EV_JOB (job_load), EV_JOB_PRIORITY_HIGH);
+               }
+               if (thumbnail != NULL)
+                        g_object_unref (thumbnail);
+
+               if (++n_items == MAX_RECENT_VIEW_ITEMS)
+                       break;
+       }
+
+       g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
+       g_list_free (items);
+
+       gd_main_view_generic_set_model (generic, GTK_TREE_MODEL (ev_recent_view->priv->model));
+}
+
+static void
+ev_recent_view_rebuild (EvRecentView *ev_recent_view)
+{
+       GtkStyleContext *context;
+
+       if (ev_recent_view->priv->view != NULL)
+               gtk_widget_destroy (ev_recent_view->priv->view);
+
+       ev_recent_view->priv->view = gd_main_icon_view_new ();
+
+       context = gtk_widget_get_style_context (ev_recent_view->priv->view);
+       gtk_style_context_add_class (context, "content-view");
+
+       gtk_container_add (GTK_CONTAINER (ev_recent_view), ev_recent_view->priv->view);
+
+       g_signal_connect (ev_recent_view->priv->view, "button-press-event",
+                         G_CALLBACK (on_button_press_event), ev_recent_view);
+
+       g_signal_connect (ev_recent_view->priv->view, "button-release-event",
+                         G_CALLBACK (on_button_release_event), ev_recent_view);
+
+       ev_recent_view_refresh (ev_recent_view);
+
+       gtk_widget_show_all (GTK_WIDGET (ev_recent_view));
+}
+
+static void
+ev_recent_view_constructed (GObject *object)
+{
+       EvRecentView *ev_recent_view = EV_RECENT_VIEW (object);
+
+       G_OBJECT_CLASS (ev_recent_view_parent_class)->constructed (object);
+       ev_recent_view_rebuild (ev_recent_view);
+}
+
+static void
+ev_recent_view_init (EvRecentView *ev_recent_view)
+{
+       ev_recent_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_recent_view, EV_TYPE_RECENT_VIEW, 
EvRecentViewPrivate);
+       ev_recent_view->priv->recent_manager = gtk_recent_manager_get_default ();
+       ev_recent_view->priv->model = gtk_list_store_new (NUM_COLUMNS,
+                                                         G_TYPE_STRING,
+                                                         G_TYPE_STRING,
+                                                         G_TYPE_STRING,
+                                                         G_TYPE_STRING,
+                                                         GDK_TYPE_PIXBUF,
+                                                         G_TYPE_LONG,
+                                                         G_TYPE_BOOLEAN,
+                                                         EV_TYPE_JOB,
+                                                         G_TYPE_BOOLEAN,
+                                                         EV_TYPE_DOCUMENT,
+                                                         EV_TYPE_METADATA);
+       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (ev_recent_view->priv->model),
+                                             GD_MAIN_COLUMN_MTIME,
+                                             GTK_SORT_DESCENDING);
+
+       gtk_widget_set_hexpand (GTK_WIDGET (ev_recent_view), TRUE);
+       gtk_widget_set_vexpand (GTK_WIDGET (ev_recent_view), TRUE);
+       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (ev_recent_view), GTK_SHADOW_IN);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ev_recent_view),
+                                       GTK_POLICY_NEVER,
+                                       GTK_POLICY_AUTOMATIC);
+       ev_recent_view->priv->recent_manager_changed_handler_id =
+               g_signal_connect_swapped (ev_recent_view->priv->recent_manager,
+                                         "changed",
+                                         G_CALLBACK (ev_recent_view_refresh),
+                                         ev_recent_view);
+}
+
+static void
+ev_recent_view_class_init (EvRecentViewClass *klass)
+{
+       GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+        g_object_class->constructed = ev_recent_view_constructed;
+       g_object_class->dispose = ev_recent_view_dispose;
+
+       /* Signals */
+       
+       signals[ITEM_ACTIVATED] =
+                 g_signal_new ("item-activated",
+                               EV_TYPE_RECENT_VIEW,
+                               G_SIGNAL_RUN_LAST,
+                               G_STRUCT_OFFSET (EvRecentViewClass, item_activated),
+                               NULL, NULL,
+                               g_cclosure_marshal_generic,
+                               G_TYPE_NONE, 1,
+                               G_TYPE_STRING);
+
+       g_type_class_add_private (klass, sizeof (EvRecentViewPrivate));
+}
+
+EvRecentView *
+ev_recent_view_new (void)
+{
+       return EV_RECENT_VIEW (g_object_new (EV_TYPE_RECENT_VIEW, NULL));
+}
diff --git a/shell/ev-recent-view.h b/shell/ev-recent-view.h
new file mode 100644
index 0000000..3f9a9a3
--- /dev/null
+++ b/shell/ev-recent-view.h
@@ -0,0 +1,60 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2013 Aakash Goenka
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __EV_RECENT_VIEW_H__
+#define __EV_RECENT_VIEW_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EvRecentView        EvRecentView;
+typedef struct _EvRecentViewClass   EvRecentViewClass;
+typedef struct _EvRecentViewPrivate EvRecentViewPrivate;
+
+#define EV_TYPE_RECENT_VIEW              (ev_recent_view_get_type ())
+#define EV_RECENT_VIEW(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_RECENT_VIEW, 
EvRecentView))
+#define EV_IS_RECENT_VIEW(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_RECENT_VIEW))
+#define EV_RECENT_VIEW_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_RECENT_VIEW, 
EvRecentViewClass))
+#define EV_IS_RECENT_VIEW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_RECENT_VIEW))
+#define EV_RECENT_VIEW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_RECENT_VIEW, 
EvRecentViewClass))
+
+struct _EvRecentView
+{
+       GtkScrolledWindow parent;
+
+       EvRecentViewPrivate *priv;
+};
+
+struct _EvRecentViewClass
+{
+       GtkScrolledWindowClass parent_class;
+
+       /* Signals  */
+       void (* item_activated) (EvRecentView *bookshelf,
+                                const char  *uri);
+};
+
+GType         ev_recent_view_get_type          (void) G_GNUC_CONST;
+EvRecentView *ev_recent_view_new               (void);
+
+G_END_DECLS
+
+#endif /* __EV_RECENT_VIEW_H__ */
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 83c1dd7..6ab80bf 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -20,5 +20,6 @@
     <file alias="ui/evince.xml" compressed="true" preprocess="xml-stripblanks">evince-ui.xml</file>
     <file alias="ui/evince.css" compressed="true">evince.css</file>
     <file alias="ui/appmenu.ui" compressed="true" preprocess="xml-stripblanks">evince-appmenu.ui</file>
+    <file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
   </gresource>
 </gresources>
diff --git a/shell/thumbnail-frame.png b/shell/thumbnail-frame.png
new file mode 100644
index 0000000..ba5d721
Binary files /dev/null and b/shell/thumbnail-frame.png differ


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]