[MPlayer-cvslog] r34263 - in trunk/gui: ui/render.c util/string.c util/string.h win32/widgetrender.c
ib
subversion at mplayerhq.hu
Wed Oct 26 17:14:06 CEST 2011
Author: ib
Date: Wed Oct 26 17:14:06 2011
New Revision: 34263
Log:
Move TranslateFilename() to util/string.c.
Now that the Win32 GUI uses symbolic constants for its messages,
the code of TranslateFilename() both GUIs use is almost identical.
So, share the code.
Modified:
trunk/gui/ui/render.c
trunk/gui/util/string.c
trunk/gui/util/string.h
trunk/gui/win32/widgetrender.c
Modified: trunk/gui/ui/render.c
==============================================================================
--- trunk/gui/ui/render.c Wed Oct 26 17:12:35 2011 (r34262)
+++ trunk/gui/ui/render.c Wed Oct 26 17:14:06 2011 (r34263)
@@ -24,11 +24,11 @@
#include "render.h"
#include "gui/interface.h"
#include "gui/skin/font.h"
+#include "gui/util/string.h"
#include "access_mpcontext.h"
#include "codec-cfg.h"
#include "config.h"
-#include "help_mp.h"
#include "libavutil/avstring.h"
#include "libmpdemux/stheader.h"
#include "mixer.h"
@@ -40,75 +40,6 @@
static char *image_buffer;
static int image_width;
-static void 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, MSGTR_NoFileLoaded, tmplen);
- break;
-
- case STREAMTYPE_STREAM:
- av_strlcpy(tmp, guiInfo.Filename, tmplen);
- break;
-
-#ifdef CONFIG_VCD
- case STREAMTYPE_VCD:
- snprintf(tmp, tmplen, MSGTR_Title, guiInfo.Track - 1);
- break;
-#endif
-
-#ifdef CONFIG_DVDREAD
- case STREAMTYPE_DVD:
- if (guiInfo.Chapter)
- snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter);
- else
- av_strlcat(tmp, MSGTR_NoChapter, tmplen);
- break;
-#endif
-
- default:
- av_strlcpy(tmp, MSGTR_NoMediaOpened, 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);
- }
- }
-}
-
static char *Translate(char *str)
{
static char trbuf[512];
Modified: trunk/gui/util/string.c
==============================================================================
--- trunk/gui/util/string.c Wed Oct 26 17:12:35 2011 (r34262)
+++ trunk/gui/util/string.c Wed Oct 26 17:14:06 2011 (r34263)
@@ -21,6 +21,12 @@
#include <string.h>
#include "string.h"
+#include "gui/interface.h"
+
+#include "config.h"
+#include "help_mp.h"
+#include "libavutil/avstring.h"
+#include "stream/stream.h"
/**
* @brief Convert a string to lower case.
@@ -229,3 +235,79 @@ void setddup(char **old, const char *dir
if (*old)
sprintf(*old, "%s/%s", dir, name);
}
+
+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 HAVE_DOS_PATHS
+ '\\');
+#else
+ '/');
+#endif
+
+ 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, MSGTR_NoFileLoaded, tmplen);
+ break;
+
+ case STREAMTYPE_STREAM:
+ av_strlcpy(tmp, guiInfo.Filename, tmplen);
+ break;
+
+#ifdef CONFIG_VCD
+ case STREAMTYPE_VCD:
+ snprintf(tmp, tmplen, MSGTR_Title, guiInfo.Track - 1);
+ break;
+#endif
+
+#ifdef CONFIG_DVDREAD
+ case STREAMTYPE_DVD:
+ if (guiInfo.Chapter)
+ snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter);
+ else
+ av_strlcat(tmp, MSGTR_NoChapter, tmplen);
+ break;
+#endif
+
+ default:
+ av_strlcpy(tmp, MSGTR_NoMediaOpened, 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;
+}
Modified: trunk/gui/util/string.h
==============================================================================
--- trunk/gui/util/string.h Wed Oct 26 17:12:35 2011 (r34262)
+++ trunk/gui/util/string.h Wed Oct 26 17:14:06 2011 (r34263)
@@ -29,6 +29,7 @@ void setddup(char **old, const char *dir
void setdup(char **old, const char *str);
char *strlower(char *in);
char *strswap(char *in, char from, char to);
+char *TranslateFilename(int c, char *tmp, size_t tmplen);
char *trim(char *in);
#endif /* MPLAYER_GUI_STRING_H */
Modified: trunk/gui/win32/widgetrender.c
==============================================================================
--- trunk/gui/win32/widgetrender.c Wed Oct 26 17:12:35 2011 (r34262)
+++ trunk/gui/win32/widgetrender.c Wed Oct 26 17:14:06 2011 (r34263)
@@ -26,12 +26,10 @@
#include <windows.h>
#include "gui/util/bitmap.h"
+#include "gui/util/string.h"
#include "gui/interface.h"
#include "gui.h"
-#include "help_mp.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)
@@ -117,66 +115,6 @@ static void stringreplace(char *dest, co
}
}
-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, MSGTR_NoFileLoaded, tmplen);
- break;
-
- case STREAMTYPE_STREAM:
- av_strlcpy(tmp, guiInfo.Filename, tmplen);
- break;
-
-#ifdef CONFIG_DVDREAD
- case STREAMTYPE_DVD:
- if (guiInfo.Chapter) snprintf(tmp, tmplen, MSGTR_Chapter, guiInfo.Chapter);
- else av_strlcat(tmp, MSGTR_NoChapter, tmplen);
- break;
-#endif
-
- default:
- av_strlcpy(tmp, MSGTR_NoMediaOpened, 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)
{
More information about the MPlayer-cvslog
mailing list