changeset 35376:02006c5b3b30

Move add_to_gui_playlist() to util/list.c. It's not an interface related function, but a playlist utility one. Additionally, add doxygen comments and change debug message. As a result, the different implementation of add_to_gui_playlist() of the Win32 GUI - the GUI uses code from util/list.c - can't have the same name and thus will be renamed to import_file_into_gui() again, reverting the r35467 and r35444 changes which were premature.
author ib
date Sun, 25 Nov 2012 11:51:35 +0000
parents 15b6ae10180a
children 6e07bbde3e46
files gui/interface.c gui/interface.h gui/util/list.c gui/util/list.h gui/win32/interface.c
diffstat 5 files changed, 55 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Sun Nov 25 11:37:52 2012 +0000
+++ b/gui/interface.c	Sun Nov 25 11:51:35 2012 +0000
@@ -834,38 +834,6 @@
     return True;
 }
 
-// This function adds/inserts one file into the gui playlist.
-int add_to_gui_playlist(const char *what, int how)
-{
-    char *filename, *pathname;
-    plItem *item;
-
-    if (!what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT))
-        return 0;
-
-    filename = strdup(mp_basename(what));
-    pathname = strdup(what);
-
-    if (strlen(pathname) - strlen(filename) > 0)
-        pathname[strlen(pathname) - strlen(filename) - 1] = 0;                                            // we have some path, so remove / at end
-    else
-        pathname[strlen(pathname) - strlen(filename)] = 0;
-
-    item = calloc(1, sizeof(plItem));
-
-    if (!item)
-        return 0;
-
-    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
-
-    item->name = filename;
-    item->path = pathname;
-
-    listMgr(how, item);
-
-    return 1;
-}
-
 // This function imports the initial playtree (based on cmd-line files)
 // into the gui playlist by either:
 // - overwriting gui pl (enqueue=0)
--- a/gui/interface.h	Sun Nov 25 11:37:52 2012 +0000
+++ b/gui/interface.h	Sun Nov 25 11:51:35 2012 +0000
@@ -150,6 +150,4 @@
 void gmp_msg(int mod, int lev, const char *format, ...);
 //@}
 
-int add_to_gui_playlist(const char *what, int how);
-
 #endif /* MPLAYER_GUI_INTERFACE_H */
--- a/gui/util/list.c	Sun Nov 25 11:37:52 2012 +0000
+++ b/gui/util/list.c	Sun Nov 25 11:51:35 2012 +0000
@@ -27,6 +27,9 @@
 #include "list.h"
 #include "string.h"
 
+#include "mp_msg.h"
+#include "path.h"
+
 static plItem *plList;
 static plItem *plCurrent;
 
@@ -275,3 +278,42 @@
     (*list)[i]     = strdup(replace);
     (*list)[i + 1] = NULL;
 }
+
+/**
+ * @brief Append or insert a file to the playlist.
+ *
+ * @param what file to be added
+ * @param how command (#PLAYLIST_ITEM_APPEND or #PLAYLIST_ITEM_INSERT) to be performed
+ *
+ * @return 1 (ok) or 0 (error)
+ */
+int add_to_gui_playlist(const char *what, int how)
+{
+    char *filename, *pathname;
+    plItem *item;
+
+    if (!what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT))
+        return 0;
+
+    filename = strdup(mp_basename(what));
+    pathname = strdup(what);
+
+    if (strlen(pathname) - strlen(filename) > 0)
+        pathname[strlen(pathname) - strlen(filename) - 1] = 0;                                            // we have some path, so remove / at end
+    else
+        pathname[strlen(pathname) - strlen(filename)] = 0;
+
+    item = calloc(1, sizeof(plItem));
+
+    if (!item)
+        return 0;
+
+    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", pathname, filename);
+
+    item->name = filename;
+    item->path = pathname;
+
+    listMgr(how, item);
+
+    return 1;
+}
--- a/gui/util/list.h	Sun Nov 25 11:37:52 2012 +0000
+++ b/gui/util/list.h	Sun Nov 25 11:51:35 2012 +0000
@@ -55,4 +55,9 @@
 void listSet(char ***list, const char *entry);
 //@}
 
+/// @name high-level list operations
+//@{
+int add_to_gui_playlist(const char *what, int how);
+//@}
+
 #endif /* MPLAYER_GUI_LIST_H */
--- a/gui/win32/interface.c	Sun Nov 25 11:37:52 2012 +0000
+++ b/gui/win32/interface.c	Sun Nov 25 11:51:35 2012 +0000
@@ -459,7 +459,7 @@
     filename = guiInfo.Filename;
 #ifdef __WINE__
     // When the GUI receives the files to be played in guiPlaylistInitialize()
-    // and guiPlaylistAdd(), it calls add_to_gui_playlist() where the call of
+    // and guiPlaylistAdd(), it calls import_file_into_gui() where the call of
     // Wine's GetFullPathName() converts each file name into the Windows style
     // (C:\path\to\file), which needs to be reconverted for MPlayer, so that
     // it will find the filename in the Linux filesystem.
@@ -817,18 +817,18 @@
 }
 
 /* This function adds/inserts one file into the gui playlist */
-int add_to_gui_playlist(const char *what, int how)
+static int import_file_into_gui(char *pathname, int insert)
 {
     char filename[MAX_PATH];
     char *filepart = filename;
 
-    if (strstr(what, "://"))
+    if (strstr(pathname, "://"))
     {
-        mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", what);
-        mygui->playlist->add_track(mygui->playlist, what, NULL, NULL, 0);
+        mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname);
+        mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0);
         return 1;
     }
-    if (GetFullPathName(what, MAX_PATH, filename, &filepart))
+    if (GetFullPathName(pathname, MAX_PATH, filename, &filepart))
     {
         if (!(GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY))
         {
@@ -860,7 +860,7 @@
         {
             if (parse_filename(filename, my_playtree, config, 0))
                 result = 1;
-            else if (add_to_gui_playlist(filename, PLAYLIST_ITEM_APPEND)) /* Add it to end of list */
+            else if (import_file_into_gui(filename, 0)) /* Add it to end of list */
                 result = 1;
         }
     }
@@ -889,7 +889,7 @@
     if((my_pt_iter = pt_iter_create(&my_playtree, config)))
     {
         while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
-            if (add_to_gui_playlist(filename, PLAYLIST_ITEM_INSERT)) /* insert it into the list and set plCurrent = new item */
+            if (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */
                 result = 1;
         pt_iter_destroy(&my_pt_iter);
     }