changeset 35350:ee265b18d653

Rename import_file_into_gui() add_to_gui_playlist(). This seems to be a more appropriate name. Additionally, use self-explanatory enum constants instead of numeric ones, change the parameter names and a declaration to const, check the parameters and print the debug message only if the item will really be added. (For the sake of consistency, adjust the Win32 code as well.)
author ib
date Thu, 22 Nov 2012 13:57:40 +0000
parents 60930e7347c6
children 92f6fc87ddc8
files gui/interface.c gui/interface.h gui/ui/gtk/fileselect.c gui/ui/gtk/url.c gui/win32/interface.c
diffstat 5 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Thu Nov 22 13:13:29 2012 +0000
+++ b/gui/interface.c	Thu Nov 22 13:57:40 2012 +0000
@@ -835,33 +835,33 @@
 }
 
 // This function adds/inserts one file into the gui playlist.
-int import_file_into_gui(char *temp, int insert)
+int add_to_gui_playlist(const char *what, int how)
 {
     char *filename, *pathname;
     plItem *item;
 
-    filename = strdup(mp_basename(temp));
-    pathname = strdup(temp);
+    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;
 
-    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
-
     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;
 
-    if (insert)
-        listMgr(PLAYLIST_ITEM_INSERT, item);           // inserts the item after current, and makes current=item
-    else
-        listMgr(PLAYLIST_ITEM_APPEND, item);
+    listMgr(how, item);
 
     return 1;
 }
@@ -881,7 +881,7 @@
     if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
         while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
             /* add it to end of list */
-            if (import_file_into_gui(filename, 0))
+            if (add_to_gui_playlist(filename, PLAYLIST_ITEM_APPEND))
                 result = 1;
     }
 
@@ -910,7 +910,7 @@
     if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
         while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
             /* insert it into the list and set plCurrent=new item */
-            if (import_file_into_gui(filename, 1))
+            if (add_to_gui_playlist(filename, PLAYLIST_ITEM_INSERT))
                 result = 1;
 
         pt_iter_destroy(&my_pt_iter);
--- a/gui/interface.h	Thu Nov 22 13:13:29 2012 +0000
+++ b/gui/interface.h	Thu Nov 22 13:57:40 2012 +0000
@@ -150,6 +150,6 @@
 void gmp_msg(int mod, int lev, const char *format, ...);
 //@}
 
-int import_file_into_gui(char *temp, int insert);
+int add_to_gui_playlist(const char *what, int how);
 
 #endif /* MPLAYER_GUI_INTERFACE_H */
--- a/gui/ui/gtk/fileselect.c	Thu Nov 22 13:13:29 2012 +0000
+++ b/gui/ui/gtk/fileselect.c	Thu Nov 22 13:57:40 2012 +0000
@@ -32,6 +32,7 @@
 
 #include "gui/app.h"
 #include "gui/interface.h"
+#include "gui/util/list.h"
 #include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "help_mp.h"
@@ -510,7 +511,7 @@
           selected = g_strconcat(fsSelectedDirectory, "/", fsSelectedFile, NULL);
           if (selected)
           {
-            import_file_into_gui(selected, 0);
+            add_to_gui_playlist(selected, PLAYLIST_ITEM_APPEND);
             g_free(selected);
           }
           guiInfo.NewPlay=GUI_FILE_NEW; sub_fps=0;
--- a/gui/ui/gtk/url.c	Thu Nov 22 13:13:29 2012 +0000
+++ b/gui/ui/gtk/url.c	Thu Nov 22 13:57:40 2012 +0000
@@ -103,7 +103,7 @@
      listMgr( URLLIST_ITEM_ADD,item );
 
      uiSetFileName( NULL,str,STREAMTYPE_STREAM ); guiInfo.NewPlay=GUI_FILE_NEW;
-     import_file_into_gui(str, 0);
+     add_to_gui_playlist(str, PLAYLIST_ITEM_APPEND);
      uiEventHandling( evPlay,0 );
     }
   }
--- a/gui/win32/interface.c	Thu Nov 22 13:13:29 2012 +0000
+++ b/gui/win32/interface.c	Thu Nov 22 13:57:40 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 import_file_into_gui() where the call of
+    // and guiPlaylistAdd(), it calls add_to_gui_playlist() 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 */
-static int import_file_into_gui(char *pathname, int insert)
+static int add_to_gui_playlist(const char *what, int how)
 {
     char filename[MAX_PATH];
     char *filepart = filename;
 
-    if (strstr(pathname, "://"))
+    if (strstr(what, "://"))
     {
-        mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname);
-        mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0);
+        mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", what);
+        mygui->playlist->add_track(mygui->playlist, what, NULL, NULL, 0);
         return 1;
     }
-    if (GetFullPathName(pathname, MAX_PATH, filename, &filepart))
+    if (GetFullPathName(what, 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 (import_file_into_gui(filename, 0)) /* Add it to end of list */
+            else if (add_to_gui_playlist(filename, PLAYLIST_ITEM_APPEND)) /* 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 (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */
+            if (add_to_gui_playlist(filename, PLAYLIST_ITEM_INSERT)) /* insert it into the list and set plCurrent = new item */
                 result = 1;
         pt_iter_destroy(&my_pt_iter);
     }