[frogr] Add new option to sort by file size



commit c0c6141f856e140b6e9e1c5ecea1b0c1ca7d87e6
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Fri Nov 30 13:36:05 2012 +0100

    Add new option to sort by file size

 NEWS                               |    1 +
 data/gtkbuilder/frogr-menu-bar.xml |    5 +++++
 src/frogr-config.c                 |    2 ++
 src/frogr-config.h                 |    3 ++-
 src/frogr-main-view.c              |   11 +++++++++++
 5 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index 19eada3..e8ed503 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@
   * Added support for saving and loading 'projects'.
   * Added new items to the toolbar ('Open' and 'Save' for projects).
   * Ported to GtkApplication and GMenu (both the app menu and menu bar).
+  * Allow sorting elements in the icon view by size.
   * Don't give up on upload too early and retry some times when possible.
   * Report errors better, and more often (no more mysterious failures).
   * Make after-upload operations cancellable, repeatable and parallelizable.
diff --git a/data/gtkbuilder/frogr-menu-bar.xml b/data/gtkbuilder/frogr-menu-bar.xml
index e52676c..12008ee 100644
--- a/data/gtkbuilder/frogr-menu-bar.xml
+++ b/data/gtkbuilder/frogr-menu-bar.xml
@@ -103,6 +103,11 @@
               <attribute name="action">win.sort-by</attribute>
               <attribute name="target">title</attribute>
             </item>
+            <item>
+              <attribute name="label" translatable="yes">By _Size</attribute>
+              <attribute name="action">win.sort-by</attribute>
+              <attribute name="target">size</attribute>
+            </item>
           </section>
           <section>
             <item>
diff --git a/src/frogr-config.c b/src/frogr-config.c
index deeb10d..a3f7cec 100644
--- a/src/frogr-config.c
+++ b/src/frogr-config.c
@@ -425,6 +425,8 @@ _load_mainview_options_xml (FrogrConfig *self,
             priv->mainview_sorting_criteria = SORT_BY_TITLE;
           else if (!xmlStrcmp (content, (const xmlChar*) "2"))
             priv->mainview_sorting_criteria = SORT_BY_DATE;
+          else if (!xmlStrcmp (content, (const xmlChar*) "3"))
+            priv->mainview_sorting_criteria = SORT_BY_SIZE;
           else
             priv->mainview_sorting_criteria = SORT_AS_LOADED;
         }
diff --git a/src/frogr-config.h b/src/frogr-config.h
index c257acb..0e06bba 100644
--- a/src/frogr-config.h
+++ b/src/frogr-config.h
@@ -63,7 +63,8 @@ GType frogr_config_get_type (void) G_GNUC_CONST;
 typedef enum {
   SORT_AS_LOADED,
   SORT_BY_TITLE,
-  SORT_BY_DATE
+  SORT_BY_DATE,
+  SORT_BY_SIZE
 } SortingCriteria;
 
 FrogrConfig* frogr_config_get_instance (void);
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 3ddaa8c..ae8f593 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -76,6 +76,7 @@
 #define ACTION_SORT_BY_TARGET_AS_LOADED "as-loaded"
 #define ACTION_SORT_BY_TARGET_DATE_TAKEN "date-taken"
 #define ACTION_SORT_BY_TARGET_TITLE "title"
+#define ACTION_SORT_BY_TARGET_SIZE "size"
 #define ACTION_SORT_IN_REVERSE_ORDER "sort-in-reverse-order"
 #define ACTION_ENABLE_TOOLTIPS "enable-tooltips"
 
@@ -416,6 +417,8 @@ _initialize_ui (FrogrMainView *self)
     action_parameter = g_variant_new_string (ACTION_SORT_BY_TARGET_TITLE);
   else if (priv->sorting_criteria == SORT_BY_DATE)
     action_parameter = g_variant_new_string (ACTION_SORT_BY_TARGET_DATE_TAKEN);
+  else if (priv->sorting_criteria == SORT_BY_SIZE)
+    action_parameter = g_variant_new_string (ACTION_SORT_BY_TARGET_SIZE);
   else
     action_parameter = g_variant_new_string (ACTION_SORT_BY_TARGET_AS_LOADED);
   g_action_change_state (G_ACTION (action), action_parameter);
@@ -707,6 +710,8 @@ _on_radio_menu_item_changed (GSimpleAction *action, GVariant *parameter, gpointe
         criteria = SORT_BY_DATE;
       else if (!g_strcmp0 (target, ACTION_SORT_BY_TARGET_TITLE))
         criteria = SORT_BY_TITLE;
+      else if (!g_strcmp0 (target, ACTION_SORT_BY_TARGET_SIZE))
+        criteria = SORT_BY_SIZE;
       else
         g_assert_not_reached ();
 
@@ -1612,6 +1617,10 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
       property_name = g_strdup ("datetime");
       break;
 
+    case SORT_BY_SIZE:
+      property_name = g_strdup ("filesize");
+      break;
+
     default:
       g_assert_not_reached ();
     }
@@ -1684,6 +1693,8 @@ _compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
     result = g_value_get_boolean (&value1) - g_value_get_boolean (&value2);
   else if (G_VALUE_HOLDS_INT (&value1))
     result = g_value_get_int (&value1) - g_value_get_int (&value2);
+  else if (G_VALUE_HOLDS_UINT (&value1))
+    result = g_value_get_uint (&value1) - g_value_get_uint (&value2);
   else if (G_VALUE_HOLDS_LONG (&value1))
     result = g_value_get_long (&value1) - g_value_get_long (&value2);
   else if (G_VALUE_HOLDS_STRING (&value1))



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