comparison 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
comparison
equal deleted inserted replaced
35349:60930e7347c6 35350:ee265b18d653
833 833
834 return True; 834 return True;
835 } 835 }
836 836
837 // This function adds/inserts one file into the gui playlist. 837 // This function adds/inserts one file into the gui playlist.
838 int import_file_into_gui(char *temp, int insert) 838 int add_to_gui_playlist(const char *what, int how)
839 { 839 {
840 char *filename, *pathname; 840 char *filename, *pathname;
841 plItem *item; 841 plItem *item;
842 842
843 filename = strdup(mp_basename(temp)); 843 if (!what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT))
844 pathname = strdup(temp); 844 return 0;
845
846 filename = strdup(mp_basename(what));
847 pathname = strdup(what);
845 848
846 if (strlen(pathname) - strlen(filename) > 0) 849 if (strlen(pathname) - strlen(filename) > 0)
847 pathname[strlen(pathname) - strlen(filename) - 1] = 0; // we have some path, so remove / at end 850 pathname[strlen(pathname) - strlen(filename) - 1] = 0; // we have some path, so remove / at end
848 else 851 else
849 pathname[strlen(pathname) - strlen(filename)] = 0; 852 pathname[strlen(pathname) - strlen(filename)] = 0;
850 853
851 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
852
853 item = calloc(1, sizeof(plItem)); 854 item = calloc(1, sizeof(plItem));
854 855
855 if (!item) 856 if (!item)
856 return 0; 857 return 0;
857 858
859 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
860
858 item->name = filename; 861 item->name = filename;
859 item->path = pathname; 862 item->path = pathname;
860 863
861 if (insert) 864 listMgr(how, item);
862 listMgr(PLAYLIST_ITEM_INSERT, item); // inserts the item after current, and makes current=item
863 else
864 listMgr(PLAYLIST_ITEM_APPEND, item);
865 865
866 return 1; 866 return 1;
867 } 867 }
868 868
869 // This function imports the initial playtree (based on cmd-line files) 869 // This function imports the initial playtree (based on cmd-line files)
879 listMgr(PLAYLIST_DELETE, 0); // delete playlist before "appending" 879 listMgr(PLAYLIST_DELETE, 0); // delete playlist before "appending"
880 880
881 if ((my_pt_iter = pt_iter_create(&my_playtree, config))) { 881 if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
882 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) 882 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
883 /* add it to end of list */ 883 /* add it to end of list */
884 if (import_file_into_gui(filename, 0)) 884 if (add_to_gui_playlist(filename, PLAYLIST_ITEM_APPEND))
885 result = 1; 885 result = 1;
886 } 886 }
887 887
888 uiCurr(); // update filename 888 uiCurr(); // update filename
889 uiGotoTheNext = 1; 889 uiGotoTheNext = 1;
908 save = (plItem *)listMgr(PLAYLIST_ITEM_GET_CURR, 0); // save current item 908 save = (plItem *)listMgr(PLAYLIST_ITEM_GET_CURR, 0); // save current item
909 909
910 if ((my_pt_iter = pt_iter_create(&my_playtree, config))) { 910 if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
911 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) 911 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
912 /* insert it into the list and set plCurrent=new item */ 912 /* insert it into the list and set plCurrent=new item */
913 if (import_file_into_gui(filename, 1)) 913 if (add_to_gui_playlist(filename, PLAYLIST_ITEM_INSERT))
914 result = 1; 914 result = 1;
915 915
916 pt_iter_destroy(&my_pt_iter); 916 pt_iter_destroy(&my_pt_iter);
917 } 917 }
918 918