Mercurial > mplayer.hg
changeset 36984:3f3a415d605b
Move most of TranslateFilename() back to the renderer files.
Although it would be nice to share the code (which was the reason
for r34263), most of it really doesn't belong to string.c.
author | ib |
---|---|
date | Thu, 27 Mar 2014 01:49:01 +0000 |
parents | c17e58ec1e65 |
children | 20710ce09985 |
files | gui/ui/render.c gui/util/string.c gui/util/string.h gui/win32/widgetrender.c |
diffstat | 4 files changed, 206 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/ui/render.c Wed Mar 26 23:19:13 2014 +0000 +++ b/gui/ui/render.c Thu Mar 27 01:49:01 2014 +0000 @@ -26,6 +26,8 @@ #include "gui/skin/font.h" #include "gui/util/string.h" +#include "access_mpcontext.h" +#include "help_mp.h" #include "libavutil/avstring.h" #include "osdep/timer.h" #include "stream/stream.h" @@ -36,6 +38,108 @@ static int image_width; /** + * @brief Convert #guiInfo member Filename. + * + * @param how 0 (cut file path and extension), + * 1 (additionally, convert lower case) or + * 2 (additionally, convert upper case) + * @param fname pointer to a buffer to receive the converted Filename + * @param maxlen size of @a fname buffer + * + * @return pointer to @a fname buffer + */ +static char *TranslateFilename(int how, char *fname, size_t maxlen) +{ + char *p; + size_t len; + stream_t *stream; + + switch (guiInfo.StreamType) { + case STREAMTYPE_FILE: + + if (guiInfo.Filename && *guiInfo.Filename) { + p = strrchr(guiInfo.Filename, '/'); + + if (p) + av_strlcpy(fname, p + 1, maxlen); + else + av_strlcpy(fname, guiInfo.Filename, maxlen); + + len = strlen(fname); + + if (len > 3 && fname[len - 3] == '.') + fname[len - 3] = 0; + else if (len > 4 && fname[len - 4] == '.') + fname[len - 4] = 0; + else if (len > 5 && fname[len - 5] == '.') + fname[len - 5] = 0; + } else + av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen); + + break; + + case STREAMTYPE_STREAM: + + av_strlcpy(fname, guiInfo.Filename, maxlen); + break; + + case STREAMTYPE_CDDA: + + snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track); + break; + + case STREAMTYPE_VCD: + + snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1); + break; + + case STREAMTYPE_DVD: + + if (guiInfo.Chapter) + snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter); + else + av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen); + + break; + + case STREAMTYPE_TV: + case STREAMTYPE_DVB: + + p = MSGTR_GUI_NoChannelName; + stream = mpctx_get_stream(guiInfo.mpcontext); + + if (stream) + stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p); + + av_strlcpy(fname, p, maxlen); + break; + + default: + + av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen); + break; + } + + if (how) { + p = fname; + + while (*p) { + char t = 0; + + if (how == 1 && *p >= 'A' && *p <= 'Z') + t = 32; + if (how == 2 && *p >= 'a' && *p <= 'z') + t = -32; + + *p = *p + t; + p++; + } + } + + return fname; +} + +/** * @brief Translate all variables in the @a text. * * @param text text containing variables
--- a/gui/util/string.c Wed Mar 26 23:19:13 2014 +0000 +++ b/gui/util/string.c Thu Mar 27 01:49:01 2014 +0000 @@ -25,15 +25,8 @@ #include <string.h> #include "string.h" -#include "gui/interface.h" #include "gui/app/gui.h" -#include "access_mpcontext.h" -#include "config.h" -#include "help_mp.h" -#include "libavutil/avstring.h" -#include "stream/stream.h" - /** * @brief Convert a string to lower case. * @@ -258,113 +251,6 @@ } /** - * @brief Convert #guiInfo member Filename. - * - * @param how 0 (cut file path and extension), - * 1 (additionally, convert lower case) or - * 2 (additionally, convert upper case) - * @param fname pointer to a buffer to receive the converted Filename - * @param maxlen size of @a fname buffer - * - * @return pointer to @a fname buffer - */ -char *TranslateFilename(int how, char *fname, size_t maxlen) -{ - char *p; - size_t len; - stream_t *stream; - - switch (guiInfo.StreamType) { - case STREAMTYPE_FILE: - - if (guiInfo.Filename && *guiInfo.Filename) { - p = strrchr(guiInfo.Filename, -#if HAVE_DOS_PATHS - '\\'); -#else - '/'); -#endif - - if (p) - av_strlcpy(fname, p + 1, maxlen); - else - av_strlcpy(fname, guiInfo.Filename, maxlen); - - len = strlen(fname); - - if (len > 3 && fname[len - 3] == '.') - fname[len - 3] = 0; - else if (len > 4 && fname[len - 4] == '.') - fname[len - 4] = 0; - else if (len > 5 && fname[len - 5] == '.') - fname[len - 5] = 0; - } else - av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen); - - break; - - case STREAMTYPE_STREAM: - - av_strlcpy(fname, guiInfo.Filename, maxlen); - break; - - case STREAMTYPE_CDDA: - - snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track); - break; - - case STREAMTYPE_VCD: - - snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1); - break; - - case STREAMTYPE_DVD: - - if (guiInfo.Chapter) - snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter); - else - av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen); - - break; - - case STREAMTYPE_TV: - case STREAMTYPE_DVB: - - p = MSGTR_GUI_NoChannelName; - stream = mpctx_get_stream(guiInfo.mpcontext); - - if (stream) - stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p); - - av_strlcpy(fname, p, maxlen); - break; - - default: - - av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen); - break; - } - - if (how) { - p = fname; - - while (*p) { - char t = 0; - - if (how == 1 && *p >= 'A' && *p <= 'Z') - t = 32; - if (how == 2 && *p >= 'a' && *p <= 'z') - t = -32; - - *p = *p + t; - p++; - } - } - - return fname; -} - -/** * @brief Read characters from @a file. * * @param str pointer to a buffer to receive the read characters
--- a/gui/util/string.h Wed Mar 26 23:19:13 2014 +0000 +++ b/gui/util/string.h Thu Mar 27 01:49:01 2014 +0000 @@ -31,7 +31,6 @@ void setdup(char **old, const char *str); char *strlower(char *in); char *strswap(char *in, char from, char to); -char *TranslateFilename(int how, char *fname, size_t maxlen); char *trim(char *in); #endif /* MPLAYER_GUI_STRING_H */
--- a/gui/win32/widgetrender.c Wed Mar 26 23:19:13 2014 +0000 +++ b/gui/win32/widgetrender.c Thu Mar 27 01:49:01 2014 +0000 @@ -22,6 +22,7 @@ */ #include <stdio.h> +#include <string.h> #include <ctype.h> #include <windows.h> @@ -30,6 +31,11 @@ #include "gui/interface.h" #include "gui.h" +#include "access_mpcontext.h" +#include "help_mp.h" +#include "libavutil/avstring.h" +#include "stream/stream.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) @@ -115,6 +121,102 @@ } } +/** + * @brief Convert #guiInfo member Filename. + * + * @param how 0 (cut file path and extension), + * 1 (additionally, convert lower case) or + * 2 (additionally, convert upper case) + * @param fname pointer to a buffer to receive the converted Filename + * @param maxlen size of @a fname buffer + * + * @return pointer to @a fname buffer + */ +char *TranslateFilename (int how, char *fname, size_t maxlen) +{ + char *p; + size_t len; + stream_t *stream; + + switch (guiInfo.StreamType) + { + case STREAMTYPE_FILE: + + if (guiInfo.Filename && *guiInfo.Filename) + { + p = strrchr(guiInfo.Filename, '\\'); + + if (p) av_strlcpy(fname, p + 1, maxlen); + else av_strlcpy(fname, guiInfo.Filename, maxlen); + + len = strlen(fname); + + if (len > 3 && fname[len - 3] == '.') fname[len - 3] = 0; + else if (len > 4 && fname[len - 4] == '.') fname[len - 4] = 0; + else if (len > 5 && fname[len - 5] == '.') fname[len - 5] = 0; + } + else av_strlcpy(fname, MSGTR_GUI_MSG_NoFileLoaded, maxlen); + + break; + + case STREAMTYPE_STREAM: + + av_strlcpy(fname, guiInfo.Filename, maxlen); + break; + + case STREAMTYPE_CDDA: + + snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track); + break; + + case STREAMTYPE_VCD: + + snprintf(fname, maxlen, MSGTR_GUI_TitleN, guiInfo.Track - 1); + break; + + case STREAMTYPE_DVD: + + if (guiInfo.Chapter) snprintf(fname, maxlen, MSGTR_GUI_ChapterN, guiInfo.Chapter); + else av_strlcpy(fname, MSGTR_GUI_NoChapter, maxlen); + + break; + + case STREAMTYPE_TV: + case STREAMTYPE_DVB: + + p = MSGTR_GUI_NoChannelName; + stream = mpctx_get_stream(guiInfo.mpcontext); + + if (stream) stream_control(stream, STREAM_CTRL_GET_CURRENT_CHANNEL, &p); + + av_strlcpy(fname, p, maxlen); + break; + + default: + + av_strlcpy(fname, MSGTR_GUI_MSG_NoMediaOpened, maxlen); + break; + } + + if (how) + { + p = fname; + + while (*p) + { + char t = 0; + + if (how == 1 && *p >= 'A' && *p <= 'Z') t = 32; + if (how == 2 && *p >= 'a' && *p <= 'z') t = -32; + + *p = *p + t; + p++; + } + } + + return fname; +} + /* replaces the chars with special meaning with the associated data from the player info struct */ static char *generatetextfromlabel(widget *item) {