[bijiben] mainView: list view : add type and where renderers



commit 9c731358cec75808ae245072482e8097b0f5fe6b
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sat Oct 19 13:39:17 2013 +0200

    mainView: list view : add type and where renderers

 src/bjb-main-view.c                        |   94 +++++++++++++++++++--------
 src/libbiji/biji-collection.c              |   11 +++
 src/libbiji/biji-item.c                    |    6 ++
 src/libbiji/biji-item.h                    |    8 ++-
 src/libbiji/biji-local-note.c              |   17 +++++
 src/libbiji/provider/biji-own-cloud-note.c |   17 +++++
 6 files changed, 124 insertions(+), 29 deletions(-)
---
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index d56acd8..f1bf410 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -433,7 +433,37 @@ __destroy_n_notify__ (gpointer data)
 }
 
 
-/*
+
+BijiItem *
+_get_item_for_tree_path (GtkTreeModel *tree_model,
+                         GtkTreeIter *iter,
+                         BjbMainView *self)
+{
+  BijiItem *retval;
+  gchar *uuid;
+
+
+  retval = NULL;
+  uuid = NULL;
+  gtk_tree_model_get (tree_model,
+                      iter,
+                      GD_MAIN_COLUMN_ID,
+                      &uuid,
+                      -1);
+
+
+  if (uuid != NULL)
+  {
+    retval = biji_note_book_get_item_at_path (
+               bjb_window_base_get_book (self->priv->window), uuid);
+    g_free (uuid);
+  }
+
+  return retval;
+}
+
+
+
 static void
 render_type     (GtkTreeViewColumn *tree_column,
                  GtkCellRenderer *cell,
@@ -441,11 +471,26 @@ render_type     (GtkTreeViewColumn *tree_column,
                  GtkTreeIter *iter,
                  gpointer data)
 {
+  BijiItem *item;
+  const gchar *str;
+  BjbMainView *self;
 
+  self = data;
+  str = NULL;
+  item = _get_item_for_tree_path (tree_model, iter, self);
 
-  g_object_set (cell, "text", "Local", NULL);
-}
+  if (item != NULL)
+  {
+    if BIJI_IS_COLLECTION (item)
+      str= _("Collection");
+
+    else if BIJI_IS_NOTE_OBJ (item)
+      str = _("Note");
+  }
 
+  if (str != NULL)
+    g_object_set (cell, "text", str, NULL);
+}
 
 
 
@@ -456,11 +501,20 @@ render_where    (GtkTreeViewColumn *tree_column,
                  GtkTreeIter *iter,
                  gpointer data)
 {
+  BijiItem *item;
+  const gchar *str;
+  BjbMainView *self;
 
+  self = data;
+  item = _get_item_for_tree_path (tree_model, iter, self);
 
-  g_object_set (cell, "text", "?", NULL);
+  if (item != NULL)
+  {
+    str = biji_item_get_place (item);
+    g_object_set (cell, "text", str, NULL);
+  }
 }
-*/
+
 
 
 static void
@@ -471,31 +525,17 @@ render_date     (GtkTreeViewColumn *tree_column,
                  gpointer data)
 {
   BijiItem *item;
-  gchar *uuid, *diff;
+  gchar *str;
   BjbMainView *self;
 
   self = data;
-  uuid = NULL;
-  gtk_tree_model_get (tree_model,
-                      iter,
-                      GD_MAIN_COLUMN_ID,
-                      &uuid,
-                      -1);
-
+  item = _get_item_for_tree_path (tree_model, iter, self);
 
-  if (uuid != NULL)
+  if (item != NULL)
   {
-    item = biji_note_book_get_item_at_path (
-             bjb_window_base_get_book (self->priv->window), uuid);
-
-    if (item != NULL)
-    {
-      diff = biji_get_time_diff_with_time (biji_item_get_mtime (item));
-      g_object_set (cell, "text", diff, NULL);
-    }
+    str = biji_get_time_diff_with_time (biji_item_get_mtime (item));
+    g_object_set (cell, "text", str, NULL);
   }
-
-  g_free (uuid);
 }
 
 
@@ -507,7 +547,7 @@ add_list_renderers (BjbMainView *self)
 
   generic =  gd_main_view_get_generic_view (self->priv->view);
 
-  /* Type Renderer
+  /* Type Renderer */
   cell = gd_styled_text_renderer_new ();
   gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (cell), "dim-label");
   gtk_cell_renderer_set_padding (cell, 16, 0);
@@ -517,10 +557,9 @@ add_list_renderers (BjbMainView *self)
                                   render_type,
                                   self,
                                   __destroy_n_notify__);
-  */
 
 
-  /* Where Renderer
+  /* Where Renderer */
   cell = gd_styled_text_renderer_new ();
   gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (cell), "dim-label");
   gtk_cell_renderer_set_padding (cell, 16, 0);
@@ -530,7 +569,6 @@ add_list_renderers (BjbMainView *self)
                                   render_where,
                                   self,
                                   __destroy_n_notify__);
-  */
 
 
   /* Date renderer */
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index 33960b2..057925f 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -254,6 +254,16 @@ biji_collection_get_mtime (BijiItem *coll)
 }
 
 
+/* As of today, collections are only local
+ * We'll need to override this */
+
+static const gchar *
+biji_collection_get_place (BijiItem *coll)
+{
+  return "Local";
+}
+
+
 static gboolean
 biji_collection_trash (BijiItem *item)
 {
@@ -495,6 +505,7 @@ biji_collection_class_init (BijiCollectionClass *klass)
   item_class->get_emblem = biji_collection_get_emblem;
   item_class->get_pristine = biji_collection_get_emblem;
   item_class->get_mtime = biji_collection_get_mtime;
+  item_class->get_place = biji_collection_get_place;
   item_class->has_color = say_no;
   item_class->trash = biji_collection_trash;
   item_class->is_collectable = say_no;
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 59e6a63..e3ac18d 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -160,6 +160,12 @@ biji_item_get_pristine        (BijiItem *item)
 }
 
 
+const gchar *
+biji_item_get_place           (BijiItem *item)
+{
+  return BIJI_ITEM_GET_CLASS (item)->get_place (item);
+}
+
 
 gint64
 biji_item_get_mtime           (BijiItem *item)
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 8ae068b..5bfa26f 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -62,12 +62,15 @@ struct BijiItemClass_
   GdkPixbuf *   (*get_icon)             (BijiItem *item);
   GdkPixbuf *   (*get_emblem)           (BijiItem *item);
   GdkPixbuf *   (*get_pristine)         (BijiItem *item);
+
+  /* Just return some provider information */
+  const gchar * (*get_place)            (BijiItem *item);
+
   gint64        (*get_mtime)            (BijiItem *item);
   gboolean      (*has_color)            (BijiItem *item);
 
   gboolean      (*trash)                (BijiItem *item);
 
-
   gboolean      (*is_collectable)       (BijiItem *item);
   gboolean      (*has_collection)       (BijiItem *item, gchar *coll);
   gboolean      (*add_collection)       (BijiItem *item, BijiItem *coll, gchar *title);
@@ -105,6 +108,9 @@ GdkPixbuf *      biji_item_get_emblem          (BijiItem *item);
 GdkPixbuf *      biji_item_get_pristine        (BijiItem *item);
 
 
+const gchar *    biji_item_get_place           (BijiItem *item);
+
+
 gint64           biji_item_get_mtime           (BijiItem *item);
 
 
diff --git a/src/libbiji/biji-local-note.c b/src/libbiji/biji-local-note.c
index 2b7c4a0..d7b9e83 100644
--- a/src/libbiji/biji-local-note.c
+++ b/src/libbiji/biji-local-note.c
@@ -33,6 +33,22 @@ G_DEFINE_TYPE (BijiLocalNote, biji_local_note, BIJI_TYPE_NOTE_OBJ)
 
 /* Iface */
 
+
+const gchar *
+local_note_get_place (BijiItem *local)
+{
+  BijiLocalNote *self;
+  const BijiProviderInfo *info;
+
+  g_return_if_fail (BIJI_IS_LOCAL_NOTE (local));
+
+  self = BIJI_LOCAL_NOTE (local);
+  info = biji_provider_get_info (self->priv->provider);
+
+  return info->name;
+}
+
+
 gchar *
 local_note_get_html (BijiNoteObj *note)
 {
@@ -202,6 +218,7 @@ biji_local_note_class_init (BijiLocalNoteClass *klass)
 
   item_class->is_collectable = item_yes;
   item_class->has_color = item_yes;
+  item_class->get_place = local_note_get_place;
 
   note_class->get_basename = local_note_get_basename;
   note_class->get_html = local_note_get_html;
diff --git a/src/libbiji/provider/biji-own-cloud-note.c b/src/libbiji/provider/biji-own-cloud-note.c
index 49ef51a..1fd5a23 100644
--- a/src/libbiji/provider/biji-own-cloud-note.c
+++ b/src/libbiji/provider/biji-own-cloud-note.c
@@ -44,6 +44,22 @@ struct BijiOwnCloudNotePrivate_
 G_DEFINE_TYPE (BijiOwnCloudNote, biji_own_cloud_note, BIJI_TYPE_NOTE_OBJ)
 
 
+
+const gchar *
+ocloud_note_get_place (BijiItem *local)
+{
+  BijiOwnCloudNote *self;
+  const BijiProviderInfo *info;
+
+  g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (local));
+
+  self = BIJI_OWN_CLOUD_NOTE (local);
+  info = biji_provider_get_info (BIJI_PROVIDER (self->priv->prov));
+
+  return info->name;
+}
+
+
 /* Better not to keep any cache here
  * We just want cache for overview,
  * not for actual content
@@ -341,6 +357,7 @@ biji_own_cloud_note_class_init (BijiOwnCloudNoteClass *klass)
 
   item_class->is_collectable = item_no;
   item_class->has_color = item_no;
+  item_class->get_place = ocloud_note_get_place;
 
   note_class->get_basename = ocloud_note_get_basename;
   note_class->get_html = ocloud_note_get_html;


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