changeset 34135:1d0544de6b6c

Add TranslateFilename() to the Win32 GUI. What the filename related dynamic labels show so far differs from the X11/GTK GUI. With no filename available, the even say "(null)". Improve this by adding TranslateFilename(). TranslateFilename() is basically the same function as used for the X11/GTK GUI.
author ib
date Thu, 20 Oct 2011 13:09:08 +0000
parents 1c4302df9dcf
children a7784f6008a7
files gui/win32/widgetrender.c
diffstat 1 files changed, 65 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gui/win32/widgetrender.c	Thu Oct 20 12:53:27 2011 +0000
+++ b/gui/win32/widgetrender.c	Thu Oct 20 13:09:08 2011 +0000
@@ -29,6 +29,8 @@
 #include "gui/interface.h"
 #include "gui.h"
 
+#include "libavutil/avstring.h"
+
 #define MAX_LABELSIZE 250
 
 static void render(int bitsperpixel, image *dst, image *src, int x, int y, int sx, int sy, int sw, int sh, int transparent)
@@ -114,6 +116,66 @@
     }
 }
 
+static char *TranslateFilename (int c, char *tmp, size_t tmplen)
+{
+    int i;
+    char *p;
+    size_t len;
+
+    switch (guiInfo.StreamType)
+    {
+        case STREAMTYPE_FILE:
+            if (guiInfo.Filename && guiInfo.Filename[0])
+            {
+                p = strrchr(guiInfo.Filename, '\\');
+
+                if (p) av_strlcpy(tmp, p + 1, tmplen);
+                else av_strlcpy(tmp, guiInfo.Filename, tmplen);
+
+                len = strlen(tmp);
+
+                if (len > 3 && tmp[len - 3] == '.') tmp[len - 3] = 0;
+                else if (len > 4 && tmp[len - 4] == '.') tmp[len - 4] = 0;
+                else if (len > 5 && tmp[len - 5] == '.') tmp[len - 5] = 0;
+            }
+            else av_strlcpy(tmp, "No file loaded.", tmplen);
+            break;
+
+        case STREAMTYPE_STREAM:
+            av_strlcpy(tmp, guiInfo.Filename, tmplen);
+            break;
+
+#ifdef CONFIG_DVDREAD
+        case STREAMTYPE_DVD:
+            if (guiInfo.Chapter) snprintf(tmp, tmplen, "Chapter %d", guiInfo.Chapter);
+            else av_strlcat(tmp, "No chapter", tmplen);
+            break;
+#endif
+
+        default:
+            av_strlcpy(tmp, "No media opened.", tmplen);
+            break;
+    }
+
+    if (c)
+    {
+        for (i = 0; tmp[i]; i++)
+        {
+            int t = 0;
+
+            if (c == 1)
+                if (tmp[i] >= 'A' && tmp[i] <= 'Z') t = 32;
+
+            if (c == 2)
+                if (tmp[i] >= 'a' && tmp[i] <= 'z') t = -32;
+
+            tmp[i] = (char) (tmp[i] + t);
+        }
+    }
+
+    return tmp;
+}
+
 /* replaces the chars with special meaning with the associated data from the player info struct */
 static char *generatetextfromlabel(widget *item)
 {
@@ -143,7 +205,7 @@
     stringreplace(text, "$b", "%3.2f", guiInfo.Balance);
     stringreplace(text, "$B", "%3.1f", guiInfo.Balance);
     stringreplace(text, "$t", "%.2i", guiInfo.Track);
-    stringreplace(text, "$o", "%s", guiInfo.Filename);
+    stringreplace(text, "$o", "%s", TranslateFilename(0, tmp, sizeof(tmp)));
     stringreplace(text, "$x", "%i", guiInfo.VideoWidth);
     stringreplace(text, "$y", "%i", guiInfo.VideoHeight);
     stringreplace(text, "$C", "%s", guiInfo.sh_video ? codecname : "");
@@ -168,16 +230,8 @@
 #endif
     else stringreplace(text, "$T", "u");
 
-    if(guiInfo.Filename)
-    {
-        for (i=0; i<strlen(guiInfo.Filename); i++)
-            tmp[i] = tolower(guiInfo.Filename[i]);
-        stringreplace(text, "$f", tmp);
-
-        for (i=0; i<strlen(guiInfo.Filename); i++)
-            tmp[i] = toupper(guiInfo.Filename[i]);
-        stringreplace(text, "$F", tmp);
-    }
+    stringreplace(text, "$f", TranslateFilename(1, tmp, sizeof(tmp)));
+    stringreplace(text, "$F", TranslateFilename(2, tmp, sizeof(tmp)));
 
     return text;
 }