[Xfce4-commits] [apps/ristretto] 01/01: Implement sorting by file type option

noreply at xfce.org noreply at xfce.org
Fri Oct 7 17:21:51 CEST 2016


This is an automated email from the git hooks/post-receive script.

f2404 pushed a commit to branch master
in repository apps/ristretto.

commit f62089696d6a65b1fe6473bb6be2e4f28e99e0b4
Author: Igor <f2404 at yandex.ru>
Date:   Fri Oct 7 18:21:25 2016 +0300

    Implement sorting by file type option
    
    Resolves https://bugzilla.xfce.org/show_bug.cgi?id=12749
---
 src/image_list.c       | 25 +++++++++++++++++++++++++
 src/image_list.h       |  4 ++++
 src/main_window.c      | 31 +++++++++++++++++++++++++------
 src/main_window_ui.xml |  1 +
 src/util.h             |  1 +
 5 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/src/image_list.c b/src/image_list.c
index 66ebe49..f65a2ef 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -175,6 +175,8 @@ static RsttoImageListIter * rstto_image_list_iter_new ();
 static gint
 cb_rstto_image_list_image_name_compare_func (RsttoFile *a, RsttoFile *b);
 static gint
+cb_rstto_image_list_image_type_compare_func (RsttoFile *a, RsttoFile *b);
+static gint
 cb_rstto_image_list_exif_date_compare_func (RsttoFile *a, RsttoFile *b);
 
 static GObjectClass *parent_class = NULL;
@@ -1351,6 +1353,12 @@ rstto_image_list_set_sort_by_name (RsttoImageList *image_list)
 }
 
 void
+rstto_image_list_set_sort_by_type (RsttoImageList *image_list)
+{
+    rstto_image_list_set_compare_func (image_list, (GCompareFunc)cb_rstto_image_list_image_type_compare_func);
+}
+
+void
 rstto_image_list_set_sort_by_date (RsttoImageList *image_list)
 {
     rstto_image_list_set_compare_func (image_list, (GCompareFunc)cb_rstto_image_list_exif_date_compare_func);
@@ -1374,6 +1382,23 @@ cb_rstto_image_list_image_name_compare_func (RsttoFile *a, RsttoFile *b)
 }
 
 /**
+ * cb_rstto_image_list_image_type_compare_func:
+ * @a:
+ * @b:
+ *
+ *
+ * Return value: (see strcmp)
+ */
+static gint
+cb_rstto_image_list_image_type_compare_func (RsttoFile *a, RsttoFile *b)
+{
+    const gchar *a_content_type = rstto_file_get_content_type (a);
+    const gchar *b_content_type = rstto_file_get_content_type (b);
+
+    return g_strcmp0(a_content_type, b_content_type);
+}
+
+/**
  * cb_rstto_image_list_exif_date_compare_func:
  * @a:
  * @b:
diff --git a/src/image_list.h b/src/image_list.h
index 7357a52..ec0e0bf 100644
--- a/src/image_list.h
+++ b/src/image_list.h
@@ -134,6 +134,10 @@ rstto_image_list_set_sort_by_name (
         RsttoImageList *image_list);
 
 void
+rstto_image_list_set_sort_by_type (
+        RsttoImageList *image_list);
+
+void
 rstto_image_list_set_sort_by_date (
         RsttoImageList *image_list);
 
diff --git a/src/main_window.c b/src/main_window.c
index 3483f8c..69f4642 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -610,20 +610,24 @@ static const GtkToggleActionEntry toggle_action_entries[] =
 /** Image sorting options*/
 static const GtkRadioActionEntry radio_action_sort_entries[] = 
 {
-    /* Sort by Filename */
     {"sort-filename",
             NULL, /* Icon-name */
             N_("sort by filename"), /* Label-text */
             NULL, /* Keyboard shortcut */
             NULL, /* Tooltip text */
-            0},
-    /* Sort by Date*/
+            SORT_TYPE_NAME},
+    {"sort-filetype",
+            NULL, /* Icon-name */
+            N_("sort by filetype"), /* Label-text */
+            NULL, /* Keyboard shortcut */
+            NULL, /* Tooltip text */
+            SORT_TYPE_TYPE},
     {"sort-date",
             NULL, /* Icon-name */
             N_("sort by date"), /* Label-text */
             NULL, /* Keyboard shortcut */
             NULL, /* Tooltip text */
-            1},
+            SORT_TYPE_DATE},
 };
 
 /** Navigationbar+Thumbnailbar positioning options*/
@@ -1085,6 +1089,14 @@ rstto_main_window_init (RsttoMainWindow *window)
                                     "/main-menu/edit-menu/sorting-menu/sort-filename")),
                     TRUE);
             break;
+        case SORT_TYPE_TYPE:
+            gtk_check_menu_item_set_active (
+                    GTK_CHECK_MENU_ITEM (
+                            gtk_ui_manager_get_widget (
+                                    window->priv->ui_manager,
+                                    "/main-menu/edit-menu/sorting-menu/sort-filetype")),
+                    TRUE);
+            break;
         case SORT_TYPE_DATE:
             gtk_check_menu_item_set_active (
                     GTK_CHECK_MENU_ITEM (
@@ -2066,7 +2078,7 @@ cb_rstto_main_window_sorting_function_changed (GtkRadioAction *action, GtkRadioA
 {
     switch (gtk_radio_action_get_current_value (current))
     {
-        case 0:  /* Sort by filename */
+        case SORT_TYPE_NAME:
         default:
             if (window->priv->image_list != NULL)
             {
@@ -2074,7 +2086,14 @@ cb_rstto_main_window_sorting_function_changed (GtkRadioAction *action, GtkRadioA
                 rstto_settings_set_uint_property (window->priv->settings_manager, "sort-type", SORT_TYPE_NAME);
             }
             break;
-        case 1: /* Sort by date */
+        case SORT_TYPE_TYPE:
+            if (window->priv->image_list != NULL)
+            {
+                rstto_image_list_set_sort_by_type (window->priv->image_list);
+                rstto_settings_set_uint_property (window->priv->settings_manager, "sort-type", SORT_TYPE_TYPE);
+            }
+            break;
+        case SORT_TYPE_DATE:
             if (window->priv->image_list != NULL)
             {
                 rstto_image_list_set_sort_by_date (window->priv->image_list);
diff --git a/src/main_window_ui.xml b/src/main_window_ui.xml
index 5e8003b..435f2db 100644
--- a/src/main_window_ui.xml
+++ b/src/main_window_ui.xml
@@ -21,6 +21,7 @@
             <separator/>
             <menu action="sorting-menu">
                 <menuitem action="sort-filename"/>
+                <menuitem action="sort-filetype"/>
                 <menuitem action="sort-date"/>
             </menu>
             <menuitem action="delete"/>
diff --git a/src/util.h b/src/util.h
index 5a3a3f0..ec741cf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -44,6 +44,7 @@ typedef enum {
 
 typedef enum {
     SORT_TYPE_NAME = 0,
+    SORT_TYPE_TYPE,
     SORT_TYPE_DATE,
     SORT_TYPE_COUNT,
 } RsttoSortType;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list