[evince/wip/recent-view: 8/12] ev-recent-view: Make variables and arguments meaningful



commit 2de5b38175d405923013752aef4192c757101b64
Author: Aakash Goenka <aakash goenka gmail com>
Date:   Wed Aug 21 06:43:53 2013 +0530

    ev-recent-view: Make variables and arguments meaningful
    
    * Use 'model' instead of 'list_store'
    * Use 'ev_recent_view' instead of 'self'
    * Use 'EvRecentView *' in the parameter instead of the generic
      gpointer user_data for callbacks.
    * Make the code conform Evince convention to name objects
    * Rename tree_path to make its purpose clearer
    * Use 'pressed_item_tree_path' instead of 'button_press_item_tree_path'
      to make clear the intention of use.
    * Use 'result' instead of 'res'
    * Remove unnecesary use of label and string functions.  Based on
      feedback from https://bugzilla.gnome.org/show_bug.cgi?id=633501

 shell/ev-recent-view.c |  143 +++++++++++++++++++++++-------------------------
 1 files changed, 68 insertions(+), 75 deletions(-)
---
diff --git a/shell/ev-recent-view.c b/shell/ev-recent-view.c
index 9bd343f..2d14ba9 100644
--- a/shell/ev-recent-view.c
+++ b/shell/ev-recent-view.c
@@ -42,9 +42,9 @@ typedef enum {
 
 struct _EvRecentViewPrivate {
        GtkWidget         *view;
-       GtkListStore      *list_store;
+       GtkListStore      *model;
        GtkRecentManager  *recent_manager;
-       gchar             *button_press_item_path;
+       GtkTreePath       *pressed_item_tree_path;
 };
 
 enum {
@@ -73,19 +73,19 @@ G_DEFINE_TYPE (EvRecentView, ev_recent_view, GTK_TYPE_SCROLLED_WINDOW)
 static void
 ev_recent_view_dispose (GObject *obj)
 {
-       EvRecentView *self = EV_RECENT_VIEW (obj);
+       EvRecentView *ev_recent_view = EV_RECENT_VIEW (obj);
 
-       if (self->priv->list_store) {
-               ev_recent_view_clear_model (self);
-               g_object_unref (self->priv->list_store);
-               self->priv->list_store = NULL;
+       if (ev_recent_view->priv->model) {
+               ev_recent_view_clear_model (ev_recent_view);
+               g_object_unref (ev_recent_view->priv->model);
+               ev_recent_view->priv->model = NULL;
        }
 
-       if (self->priv->recent_manager) {
-               g_signal_handlers_disconnect_by_func (self->priv->recent_manager,
+       if (ev_recent_view->priv->recent_manager) {
+               g_signal_handlers_disconnect_by_func (ev_recent_view->priv->recent_manager,
                                                      ev_recent_view_refresh,
-                                                     self);
-               self->priv->recent_manager = NULL;
+                                                     ev_recent_view);
+               ev_recent_view->priv->recent_manager = NULL;
        }
        G_OBJECT_CLASS (ev_recent_view_parent_class)->dispose (obj);
 }
@@ -174,8 +174,8 @@ ev_recent_view_clear_model (EvRecentView *ev_recent_view)
 {
        EvRecentViewPrivate *priv = ev_recent_view->priv;
 
-       gtk_tree_model_foreach (GTK_TREE_MODEL (priv->list_store), ev_recent_view_clear_job, ev_recent_view);
-       gtk_list_store_clear (priv->list_store);
+       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
@@ -205,10 +205,10 @@ compare_recent_items (GtkRecentInfo *a,
 }
 
 static GdMainViewGeneric *
-get_generic (EvRecentView *self)
+get_generic (EvRecentView *ev_recent_view)
 {
-       if (self->priv->view != NULL)
-               return GD_MAIN_VIEW_GENERIC (self->priv->view);
+       if (ev_recent_view->priv->view != NULL)
+               return GD_MAIN_VIEW_GENERIC (ev_recent_view->priv->view);
 
        return NULL;
 }
@@ -216,13 +216,11 @@ get_generic (EvRecentView *self)
 static gboolean
 on_button_release_event (GtkWidget      *view,
                          GdkEventButton *event,
-                         gpointer        user_data)
+                         EvRecentView   *ev_recent_view)
 {
-       EvRecentView      *self = user_data;
-       GdMainViewGeneric *generic = get_generic (self);
+       GdMainViewGeneric *generic = get_generic (ev_recent_view);
        GtkTreePath       *path;
-       gchar             *button_release_item_path;
-       gboolean           res, same_item = FALSE;
+       gboolean           result = FALSE;
 
        /* eat double/triple click events */
        if (event->type != GDK_BUTTON_RELEASE)
@@ -230,59 +228,54 @@ on_button_release_event (GtkWidget      *view,
 
        path = gd_main_view_generic_get_path_at_pos (generic, event->x, event->y);
 
-       if (path != NULL) {
-               button_release_item_path = gtk_tree_path_to_string (path);
-               if (g_strcmp0 (self->priv->button_press_item_path, button_release_item_path) == 0)
-                       same_item = TRUE;
+       if (path == NULL)
+               return result;
 
-               g_free (button_release_item_path);
+       if (ev_recent_view->priv->pressed_item_tree_path == NULL) {
+               gtk_tree_path_free (path);
+               return result;
        }
 
-       g_free (self->priv->button_press_item_path);
-       self->priv->button_press_item_path = NULL;
+       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 (!same_item)
-               res = FALSE;
-       else {
+       if (result) {
                GtkTreeIter iter;
                gchar      *uri;
 
-               if (self->priv->list_store == NULL)
-                       goto exit;
-
-               if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (self->priv->list_store), &iter, path))
-                       goto exit;
+               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 (self->priv->list_store), &iter,
+               gtk_tree_model_get (GTK_TREE_MODEL (ev_recent_view->priv->model), &iter,
                                    GD_MAIN_COLUMN_URI, &uri,
                                    -1);
-               gtk_list_store_set (self->priv->list_store,
+               gtk_list_store_set (ev_recent_view->priv->model,
                                    &iter,
                                    GD_MAIN_COLUMN_SELECTED, TRUE,
                                    -1);
-               g_signal_emit (self, signals[ITEM_ACTIVATED], 0, uri);
+               g_signal_emit (ev_recent_view, signals[ITEM_ACTIVATED], 0, uri);
        }
-    exit:
        gtk_tree_path_free (path);
-       return res;
+       return result;
 }
 
 static gboolean
-on_button_press_event (GtkWidget *view,
+on_button_press_event (GtkWidget      *view,
                        GdkEventButton *event,
-                       gpointer user_data)
+                       EvRecentView   *ev_recent_view)
 {
-       EvRecentView *self = user_data;
-       GdMainViewGeneric *generic = get_generic (self);
-       GtkTreePath       *path;
+       GdMainViewGeneric *generic = get_generic (ev_recent_view);
 
-       path = gd_main_view_generic_get_path_at_pos (generic, event->x, event->y);
+       if (ev_recent_view->priv->pressed_item_tree_path != NULL)
+               gtk_tree_path_free (ev_recent_view->priv->pressed_item_tree_path);
 
-       if (path != NULL)
-               self->priv->button_press_item_path = gtk_tree_path_to_string (path);
+       ev_recent_view->priv->pressed_item_tree_path =
+               gd_main_view_generic_get_path_at_pos (generic, event->x, event->y);
 
-       gtk_tree_path_free (path);
-       
        return FALSE;
 }
 
@@ -309,13 +302,13 @@ thumbnail_job_completed_callback (EvJobThumbnail *job,
                                          &border, &border);
        iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
 
-       gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
+       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->list_store,
+       gtk_list_store_set (priv->model,
                            iter,
                            GD_MAIN_COLUMN_ICON, pixbuf,
                            EV_RECENT_VIEW_THUMBNAILED_COLUMN, TRUE,
@@ -331,7 +324,7 @@ thumbnail_job_completed_callback (EvJobThumbnail *job,
 }
 
 static void
-document_load_job_completed_callback (EvJobLoad   *job_load,
+document_load_job_completed_callback (EvJobLoad    *job_load,
                                       EvRecentView *ev_recent_view)
 {
        EvRecentViewPrivate *priv = ev_recent_view->priv;
@@ -364,7 +357,7 @@ document_load_job_completed_callback (EvJobLoad   *job_load,
                                  G_CALLBACK (thumbnail_job_completed_callback),
                                  ev_recent_view);
 
-               gtk_list_store_set (priv->list_store,
+               gtk_list_store_set (priv->model,
                                    iter,
                                    EV_RECENT_VIEW_THUMBNAILED_COLUMN, FALSE,
                                    EV_RECENT_VIEW_JOB_COLUMN, job_thumbnail,
@@ -376,12 +369,12 @@ document_load_job_completed_callback (EvJobLoad   *job_load,
                g_object_unref (job_thumbnail);
 
        } else {
-               gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
+               gtk_tree_model_get (GTK_TREE_MODEL (priv->model),
                                    iter,
                                    EV_RECENT_VIEW_METADATA_COLUMN, &metadata,
                                    -1);
 
-               gtk_list_store_set (priv->list_store,
+               gtk_list_store_set (priv->model,
                                    iter,
                                    EV_RECENT_VIEW_THUMBNAILED_COLUMN, TRUE,
                                    EV_RECENT_VIEW_JOB_COLUMN, NULL,
@@ -390,7 +383,7 @@ document_load_job_completed_callback (EvJobLoad   *job_load,
                if (metadata) {
                        GdkPixbuf *thumbnail;
 
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->model),
                                            iter,
                                            GD_MAIN_COLUMN_ICON, &thumbnail,
                                            -1);
@@ -417,7 +410,7 @@ ev_recent_view_refresh (EvRecentView *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->list_store);
+       gtk_list_store_clear (ev_recent_view->priv->model);
 
        for (l = items; l && l->data; l = g_list_next (l)) {
                EvJob         *job_load = NULL;
@@ -465,9 +458,9 @@ ev_recent_view_refresh (EvRecentView *ev_recent_view)
                }
                access_time = gtk_recent_info_get_modified (info);
 
-               gtk_list_store_append (ev_recent_view->priv->list_store, &iter);
+               gtk_list_store_append (ev_recent_view->priv->model, &iter);
 
-               gtk_list_store_set (ev_recent_view->priv->list_store, &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,
@@ -498,7 +491,7 @@ ev_recent_view_refresh (EvRecentView *ev_recent_view)
        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->list_store));
+       gd_main_view_generic_set_model (generic, GTK_TREE_MODEL (ev_recent_view->priv->model));
 }
 
 static void
@@ -541,19 +534,19 @@ 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->list_store = gtk_list_store_new (11,
-                                                            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->list_store),
+       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);
 


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