Update of /cvsroot/gtkpod/gtkpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv19009/src

Modified Files:
        misc.c prefs.c prefs.h prefs_window.c 
Log Message:

sort_ign_string_ list now fully uses new prefs interfaces.


Index: misc.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc.c,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- misc.c      13 Jun 2006 02:57:38 -0000      1.204
+++ misc.c      14 Jun 2006 23:26:31 -0000      1.205
@@ -459,7 +459,9 @@
 void compare_string_fuzzy_generate_keys (void)
 {
     GList *gl;
-    gint i;
+    GList *sort_ign_strings;
+    GList *current;
+
     /* remove old keys */
     for (gl=csfk_list; gl; gl=gl->next)
     {
@@ -472,33 +474,25 @@
     csfk_list = NULL;
 
     /* create new keys */
-    for (i=0; ;++i)
+    sort_ign_strings = prefs_get_list("sort_ign_string_");
+    current = sort_ign_strings;
+    while (current)
     {
-       gchar *buf = g_strdup_printf ("sort_ign_string_%d", i);
-       gchar *str = prefs_get_string (buf);
+       gchar *str = current->data;
        struct csfk *csfk;
        gchar *tempStr;
-
-       g_free (buf);
-
-       /* end loop if no string is set or if the the string
-        * corresponds to the end marker */
-       if (!str)  break;  
-       if (strcmp (str, LIST_END_MARKER) == 0)
-       {
-           g_free (str);
-           break;
-       }
+       
+       current = g_list_next(current);
 
        csfk = g_malloc (sizeof (struct csfk));
        tempStr = g_utf8_casefold (str, -1 );
        csfk->length = g_utf8_strlen (tempStr, -1 );
        csfk->key = g_utf8_collate_key (tempStr, -1 );
        g_free (tempStr);
-       g_free (str);
 
        csfk_list = g_list_append (csfk_list, csfk);
     }
+    prefs_free_list(sort_ign_strings);
 }
 
 

Index: prefs.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs.c,v
retrieving revision 1.244
retrieving revision 1.245
diff -u -d -r1.244 -r1.245
--- prefs.c     14 Jun 2006 02:52:55 -0000      1.244
+++ prefs.c     14 Jun 2006 23:26:31 -0000      1.245
@@ -1920,39 +1920,14 @@
 }
 
 
-/* default ignore strings -- must end with a space */
-static char* sort_ign_strings[] =
-{
-    "the ",
-    "a ",
-/*    "le ", 
-    "la ", 
-    "les ", 
-    "lo ", 
-    "los ",
-    "der ",
-    "die ",
-    "das ",*/ /* will make sorting very slow -- only add the words you
-                 really want to skip */
-   LIST_END_MARKER,  /* end marker */
-    NULL,
-};
-
 
 static void
 read_prefs_from_file_desc(FILE *fp)
 {
     gchar buf[PATH_MAX];
     gchar *line, *arg, *bufp;
-    gint len, i;
+    gint len;
 
-    /* set ignore strings */
-    for (i=0; sort_ign_strings[i]; ++i)
-    {
-       bufp = g_strdup_printf ("sort_ign_string_%d", i);
-       prefs_set_string (bufp, sort_ign_strings[i]);
-       g_free (bufp);
-    }
     /* set ignore fields (ignore above words for artist) */
     bufp = g_strdup_printf ("sort_ign_field_%d", T_ARTIST);
     prefs_set_int (bufp, 1);
@@ -2315,7 +2290,6 @@
 {
     g_return_if_fail (c);
     g_list_free (c->tmp_sort_ign_fields);
-    g_free (c->tmp_sort_ign_strings);
     g_free (c);
 }
 
@@ -2422,7 +2396,6 @@
     }
     /* GLists are not copied */
     result->tmp_sort_ign_fields = NULL;
-    result->tmp_sort_ign_strings = NULL;
     return(result);
 }
 

Index: prefs.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs.h,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- prefs.h     14 Jun 2006 16:12:10 -0000      1.172
+++ prefs.h     14 Jun 2006 23:26:31 -0000      1.173
@@ -69,7 +69,6 @@
   struct sortcfg
   {         /* sort type: SORT_ASCENDING, SORT_DESCENDING, SORT_NONE */
     GList *tmp_sort_ign_fields; /* used in prefs_window.c only     */
-    gchar *tmp_sort_ign_strings;/* used in prefs_window.c only     */
   } sortcfg;
   gboolean offline;       /* are we working offline, i.e. without iPod? */
 

Index: prefs_window.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs_window.c,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- prefs_window.c      14 Jun 2006 02:52:56 -0000      1.166
+++ prefs_window.c      14 Jun 2006 23:26:32 -0000      1.167
@@ -1427,9 +1427,11 @@
 static void sort_window_read_sort_ign (struct sortcfg *scfg)
 {
     gint i;
-    GtkTextIter ts, te;
     GtkTextView *tv;
     GtkTextBuffer *tb;
+    GList *sort_ign_strings;
+    GList *current;
+    gchar *buf;
 
     g_return_if_fail (scfg);
 
@@ -1440,7 +1442,7 @@
     /* read sort field states */
     for (i=0; sort_ign_fields[i] != -1; ++i)
     {
-       gchar *buf = g_strdup_printf ("sort_ign_field_%d",
+       buf = g_strdup_printf ("sort_ign_field_%d",
                                      sort_ign_fields[i]);
        GtkWidget *w = gtkpod_xml_get_widget (sort_window_xml, buf);
        g_return_if_fail (w);
@@ -1450,22 +1452,33 @@
                GTK_TOGGLE_BUTTON (w))));
        g_free (buf);
     }
-
-    /* remove old strings */
-    g_free (scfg->tmp_sort_ign_strings);
-    scfg->tmp_sort_ign_strings = NULL;
-
-    /* read new ignore strings */
+    
+    /* Read sort ignore strings */
     tv = GTK_TEXT_VIEW (gtkpod_xml_get_widget (sort_window_xml,
                                              "sort_ign_strings"));
     g_return_if_fail (tv);
     tb = gtk_text_view_get_buffer (tv);
     g_return_if_fail (tb);
 
-    gtk_text_buffer_get_bounds (tb, &ts, &te);
-    scfg->tmp_sort_ign_strings = gtk_text_buffer_get_text (tb,
-                                                          &ts, &te,
-                                                          TRUE);
+    sort_ign_strings = get_list_from_buffer(tb);
+    current = sort_ign_strings;
+    
+    /* Add a trailing whitespace to strings */
+    while (current)
+    {
+       g_strstrip(current->data);
+       
+        if (strlen(current->data) != 0)
+       {
+           buf = g_strdup_printf("%s ",(gchar *) current->data);
+           g_free(current->data);
+           current->data = buf;
+       }
+
+       current = g_list_next(current);
+    }
+       
+    temp_list_add(sort_temp_lists, "sort_ign_string_", sort_ign_strings);
 }
 
 /**
@@ -1482,10 +1495,14 @@
     else
     {
        GList *collist = NULL;
+       GList *sort_ign_strings;
+       GList *current;  /* current sort ignore item */
        GtkWidget *w;
        GtkTextView *tv;
        GtkTextBuffer *tb;
        gint i;
+       GtkTextIter ti;
+       gchar *str;
 
        if(!tmpsortcfg && !origsortcfg)
        {
@@ -1539,22 +1556,13 @@
            gtk_text_view_set_editable(tv, FALSE);
            gtk_text_view_set_cursor_visible(tv, FALSE);
        }
-       for (i=0; ; ++i)
+       
+       sort_ign_strings = prefs_get_list("sort_ign_string_");
+       current = sort_ign_strings;
+       while (current)
        {
-           GtkTextIter ti;
-           gchar *buf = g_strdup_printf ("sort_ign_string_%d", i);
-           gchar *str = prefs_get_string (buf);
-
-           g_free (buf);
-
-           /* end loop if no string is set or if the the string
-           * corresponds to the end marker */
-           if (!str)  break;  
-           if (strcmp (str, LIST_END_MARKER) == 0)
-           {
-               g_free (str);
-               break;
-           }
+           str = (gchar *)current->data;
+           current = g_list_next(current);
 
            /* append new text to the end */
            gtk_text_buffer_get_end_iter (tb, &ti);
@@ -1562,8 +1570,10 @@
            /* append newline */
            gtk_text_buffer_get_end_iter (tb, &ti);
            gtk_text_buffer_insert (tb, &ti, "\n", -1);
-           g_free (str);
        }
+       
+       prefs_free_list(sort_ign_strings);
+
        /* update the origsortcfg with the original settings (ignore
         * fields and ignore strings) */
        sort_window_read_sort_ign (origsortcfg);
@@ -1750,7 +1760,6 @@
 static void sort_window_set (struct sortcfg *scfg)
 {
     struct sortcfg *tsc;
-    gchar *buf;
     gint i;
     gint val; /* A value from temp prefs */
     TM_item sortcol_new;
@@ -1775,48 +1784,6 @@
                scfg->tmp_sort_ign_fields, i)));
        g_free (buf);
     }
-    /* clean up old sort strings */
-    for (i=0; i>=0; ++i)
-    {
-       gchar *buf = g_strdup_printf ("sort_ign_string_%d", i);
-       if (prefs_get_string (buf))
-       {
-           prefs_set_string (buf, NULL);
-       }
-       else
-       {
-           i=-2;  /* end loop */
-       }
-       g_free (buf);
-    }
-    /* set new sort strings */
-    i=0;
-    if (scfg->tmp_sort_ign_strings)
-    {
-       gchar **strings = g_strsplit(scfg->tmp_sort_ign_strings,
-                                    "\n", -1);
-       gchar **strp = strings;
-       while (*strp)
-       {
-           g_strstrip (*strp);
-           if (strlen (*strp) != 0)
-           {
-               /* add space to the ignore string */
-               gchar *str = g_strdup_printf ("%s ", *strp);
-               buf = g_strdup_printf ("sort_ign_string_%d", i);
-               prefs_set_string (buf, str);
-               g_free (str);
-               g_free (buf);
-               ++i;
-           }
-           ++strp;
-       }
-       g_strfreev (strings);
-    }
-    /* set end marker */
-    buf = g_strdup_printf ("sort_ign_string_%d", i);
-    prefs_set_string (buf, LIST_END_MARKER);
-    g_free (buf);
     /* update compare string keys */
     compare_string_fuzzy_generate_keys ();
 



_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to