diff gui/interface.c @ 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 11408d97de7a
children 80fe9ad7f318
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);