Revision: 1631
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1631&view=rev
Author:   mow
Date:     2009-04-10 13:44:37 +0000 (Fri, 10 Apr 2009)

Log Message:
-----------
Implement random sort method for collections

This patch allows to randomize the collections. (Closes: #2497413)
https://sourceforge.net/tracker/?func=detail&aid=2497413&group_id=222125&atid=1054683

Modified Paths:
--------------
    trunk/src/collect-table.c
    trunk/src/collect.c
    trunk/src/collect.h

Modified: trunk/src/collect-table.c
===================================================================
--- trunk/src/collect-table.c   2009-04-10 10:18:42 UTC (rev 1630)
+++ trunk/src/collect-table.c   2009-04-10 13:44:37 UTC (rev 1631)
@@ -720,6 +720,17 @@
        collection_set_sort_method(ct->cd, type);
 }
 
+static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer 
data)
+{
+       CollectTable *ct;
+
+       ct = submenu_item_get_data(widget);
+
+       if (!ct) return;
+
+       collection_randomize(ct->cd);
+}
+
 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer 
data)
 {
        CollectTable *ct = data;
@@ -902,7 +913,13 @@
                                
G_CALLBACK(collection_table_popup_copy_path_cb), ct);
        menu_item_add_divider(menu);
 
-       submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, 
FALSE, TRUE, FALSE, 0);
+       submenu = submenu_add_sort(NULL, 
G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
+       menu_item_add_divider(submenu);
+       menu_item_add(submenu, _("Randomize"),
+                       G_CALLBACK(collection_table_popup_randomize_cb), ct);
+       item = menu_item_add(menu, _("_Sort"), NULL, NULL);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+
        menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
                        G_CALLBACK(collection_table_popup_show_names_cb), ct);
        menu_item_add_divider(menu);

Modified: trunk/src/collect.c
===================================================================
--- trunk/src/collect.c 2009-04-10 10:18:42 UTC (rev 1630)
+++ trunk/src/collect.c 2009-04-10 13:44:37 UTC (rev 1631)
@@ -176,6 +176,30 @@
        return g_list_sort(list, collection_list_sort_cb);
 }
 
+GList *collection_list_randomize(GList *list)
+{
+       guint random, length, i;
+       gpointer tmp;
+       GList *nlist, *olist;
+
+       length = g_list_length(list);
+       if (!length) return NULL;
+
+       srand((unsigned int)time(NULL)); // Initialize random generator (hasn't 
to be that much strong)
+
+       for (i = 0; i < length; i++)
+               {
+               random = (guint) (1.0 * length * rand()/(RAND_MAX + 1.0));
+               olist = g_list_nth(list, i);
+               nlist = g_list_nth(list, random);
+               tmp = olist->data;
+               olist->data = nlist->data;
+               nlist->data = tmp;
+               }
+
+       return list;
+}
+
 GList *collection_list_add(GList *list, CollectInfo *ci, SortType method)
 {
        if (method != SORT_NONE)
@@ -577,6 +601,16 @@
        collection_window_refresh(collection_window_find(cd));
 }
 
+void collection_randomize(CollectionData *cd)
+{
+       if (!cd) return;
+
+       cd->list = collection_list_randomize(cd->list);
+       if (cd->list) cd->changed = TRUE;
+
+       collection_window_refresh(collection_window_find(cd));
+}
+
 void collection_set_update_info_func(CollectionData *cd,
                                     void (*func)(CollectionData *, CollectInfo 
*, gpointer), gpointer data)
 {

Modified: trunk/src/collect.h
===================================================================
--- trunk/src/collect.h 2009-04-10 10:18:42 UTC (rev 1630)
+++ trunk/src/collect.h 2009-04-10 13:44:37 UTC (rev 1631)
@@ -59,6 +59,7 @@
 CollectInfo *collection_get_last(CollectionData *cd);
 
 void collection_set_sort_method(CollectionData *cd, SortType method);
+void collection_randomize(CollectionData *cd);
 void collection_set_update_info_func(CollectionData *cd,
                                     void (*func)(CollectionData *, CollectInfo 
*, gpointer), gpointer data);
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to