[gnome-control-center] background: Sort Pictures in order of most recently modified



commit c3446cccdcf3c3ae3a321d1f65536e6e97a98a71
Author: Michael Wood <michael g wood intel com>
Date:   Fri Jan 25 11:56:58 2013 +0000

    background: Sort Pictures in order of most recently modified
    
    In the picture browser you see the most recently modified pictures
    first.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691800

 panels/background/bg-pictures-source.c |   10 +++++-----
 panels/background/cc-background-item.c |   28 +++++++++++++++++++++++++++-
 panels/background/cc-background-item.h |    2 +-
 3 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/panels/background/bg-pictures-source.c b/panels/background/bg-pictures-source.c
index 67dd07b..9b8d39d 100644
--- a/panels/background/bg-pictures-source.c
+++ b/panels/background/bg-pictures-source.c
@@ -144,8 +144,8 @@ sort_func (GtkTreeModel *model,
 {
   CcBackgroundItem *item_a;
   CcBackgroundItem *item_b;
-  const char *name_a;
-  const char *name_b;
+  guint64 modified_a;
+  guint64 modified_b;
   int retval;
 
   gtk_tree_model_get (model, a,
@@ -155,10 +155,10 @@ sort_func (GtkTreeModel *model,
                       1, &item_b,
                       -1);
 
-  name_a = cc_background_item_get_name (item_a);
-  name_b = cc_background_item_get_name (item_b);
+  modified_a = cc_background_item_get_modified (item_a);
+  modified_b = cc_background_item_get_modified (item_b);
 
-  retval = g_utf8_collate (name_a, name_b);
+  retval = modified_b - modified_a;
 
   g_object_unref (item_a);
   g_object_unref (item_b);
diff --git a/panels/background/cc-background-item.c b/panels/background/cc-background-item.c
index a29a126..d61aa0e 100644
--- a/panels/background/cc-background-item.c
+++ b/panels/background/cc-background-item.c
@@ -50,6 +50,7 @@ struct CcBackgroundItemPrivate
         gboolean         is_deleted;
         gboolean         needs_download;
         CcBackgroundItemFlags flags;
+        guint64          modified;
 
         /* internal */
         GnomeBG         *bg;
@@ -71,7 +72,8 @@ enum {
         PROP_SOURCE_XML,
         PROP_FLAGS,
         PROP_SIZE,
-        PROP_NEEDS_DOWNLOAD
+        PROP_NEEDS_DOWNLOAD,
+        PROP_MODIFIED
 };
 
 static void     cc_background_item_class_init     (CcBackgroundItemClass *klass);
@@ -285,6 +287,7 @@ update_info (CcBackgroundItem *item,
                         item->priv->name = g_strdup (g_file_info_get_display_name (info));
 
                 item->priv->mime_type = g_strdup (g_file_info_get_content_type (info));
+                item->priv->modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
         }
 
         if (info != NULL)
@@ -503,6 +506,14 @@ cc_background_item_get_needs_download (CcBackgroundItem *item)
 	return item->priv->needs_download;
 }
 
+guint64
+cc_background_item_get_modified (CcBackgroundItem *item)
+{
+	g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
+
+	return item->priv->modified;
+}
+
 static void
 cc_background_item_set_property (GObject      *object,
                                  guint         prop_id,
@@ -600,6 +611,9 @@ cc_background_item_get_property (GObject    *object,
 	case PROP_NEEDS_DOWNLOAD:
 		g_value_set_boolean (value, self->priv->needs_download);
 		break;
+	case PROP_MODIFIED:
+		g_value_set_uint64 (value, self->priv->modified);
+		break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -725,6 +739,16 @@ cc_background_item_class_init (CcBackgroundItemClass *klass)
                                                                TRUE,
                                                                G_PARAM_READWRITE));
 
+        g_object_class_install_property (object_class,
+                                         PROP_MODIFIED,
+                                         g_param_spec_uint64 ("modified",
+                                                              "modified",
+                                                              NULL,
+                                                              0,
+                                                              G_MAXUINT64,
+                                                              0,
+                                                              G_PARAM_READABLE));
+
 
         g_type_class_add_private (klass, sizeof (CcBackgroundItemPrivate));
 }
@@ -742,6 +766,7 @@ cc_background_item_init (CcBackgroundItem *item)
         item->priv->secondary_color = g_strdup ("#000000000000");
         item->priv->needs_download = TRUE;
         item->priv->flags = 0;
+        item->priv->modified = 0;
 }
 
 static void
@@ -871,6 +896,7 @@ cc_background_item_dump (CcBackgroundItem *item)
 	if (priv->mime_type)
 		g_debug ("mime-type:\t\t%s", priv->mime_type);
 	g_debug ("dimensions:\t\t%d x %d", priv->width, priv->height);
+        g_debug ("modified: %u", priv->modified);
 	g_debug (" ");
 }
 
diff --git a/panels/background/cc-background-item.h b/panels/background/cc-background-item.h
index dc91703..265e662 100644
--- a/panels/background/cc-background-item.h
+++ b/panels/background/cc-background-item.h
@@ -93,10 +93,10 @@ const char *              cc_background_item_get_scolor     (CcBackgroundItem *i
 const char *              cc_background_item_get_name       (CcBackgroundItem *item);
 const char *              cc_background_item_get_size       (CcBackgroundItem *item);
 gboolean                  cc_background_item_get_needs_download (CcBackgroundItem *item);
+guint64                   cc_background_item_get_modified   (CcBackgroundItem *item);
 
 gboolean                  cc_background_item_compare        (CcBackgroundItem *saved,
 							     CcBackgroundItem *configured);
-
 void                      cc_background_item_dump           (CcBackgroundItem *item);
 
 G_END_DECLS



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