[Xfce4-commits] <midori:master> Put number in front of download filename extension

Christian Dywan noreply at xfce.org
Wed Jun 30 21:18:01 CEST 2010


Updating branch refs/heads/master
         to d1694c6d5fa70ba044e5996abcf420fe830e6453 (commit)
       from e7e2181858186561d9a3ebd4e4cacd964e421b14 (commit)

commit d1694c6d5fa70ba044e5996abcf420fe830e6453
Author: Peter de Ridder <peter at xfce.org>
Date:   Wed Jun 30 21:15:11 2010 +0200

    Put number in front of download filename extension

 midori/midori-browser.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 65eaca8..3d75ab5 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -1464,17 +1464,32 @@ midori_view_download_requested_cb (GtkWidget*      view,
             /* If the filename exists, choose a different name  */
             if (g_access (filename, F_OK) == 0)
             {
-                /* FIXME: Put the number in front of the extension */
-                gsize length = strlen (filename);
+                /* Put the number in front of the extension */
+                gchar* extension = strrchr (filename, '.');
+                gsize length = extension ? (gsize)(extension - filename) : strlen (filename);
                 do
                 {
                     if (g_ascii_isdigit (filename[length - 1]))
-                        filename[length - 1] += 1;
+                        filename[length - 1] += 1; /* FIXME: This will increment '9' to ':' */
                     else
                     {
-                        gchar* new_filename = g_strconcat (filename, "0", NULL);
+                        gchar* new_filename;
+                        if (extension)
+                        {
+                            /* Change the '.' to a '\0' to put the 0 in between */
+                            *extension++ = '\0';
+                            new_filename= g_strconcat (filename, "0.", extension, NULL);
+                        }
+                        else
+                            new_filename = g_strconcat (filename, "0", NULL);
                         katze_assign (filename, new_filename);
-                        length = strlen (filename);
+                        if (extension)
+                        {
+                            extension = strrchr (filename, '.');
+                            length = extension - filename;
+                        }
+                        else
+                            length = strlen (filename);
                     }
                 }
                 while (g_access (filename, F_OK) == 0);



More information about the Xfce4-commits mailing list