home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wvis0626.zip / warpvision_20020626.zip / gui / playlist.h < prev    next >
C/C++ Source or Header  |  2002-06-24  |  20KB  |  655 lines

  1. /*
  2.  * WarpVision GUI. Playlist
  3.  *
  4.  * CopyRight Vlad Stelmahovsky
  5.  *
  6.  * WarpVision is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * WarpVision is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20. */
  21.  
  22. #include "mclb\mclb.h"
  23. #define szPlayListClass "PlayListClass"
  24. #define ID_APP_PLAYLIST 1018
  25. #define ID_PLAYLIST 1019
  26. #define szPlayListTitle "Playlist"
  27. int plrows = 0;
  28.  
  29. void fillPlayList(pplayItem); // adds item to playlist
  30. MRESULT APIENTRY PlayListWndProc(HWND, ULONG, MPARAM, MPARAM);
  31.  
  32. HWND hWndPlayList,hWndPlayListClient,hwndList;
  33.  
  34. ULONG flPlayListWinFlags =  FCF_TITLEBAR | FCF_MINMAX | FCF_SYSMENU | FCF_BORDER | FCF_SIZEBORDER |FCF_NOBYTEALIGN | FCF_SHELLPOSITION | FCF_TASKLIST;
  35. char delim = '!';
  36.  
  37. void get_colsizes()
  38. {
  39.     int i;
  40.     WinSendMsg(hwndList,MCLB_QUERYCOLSIZES,MPFROMLONG(&colsizes),NULL);
  41.     conf.w_fps=colsizes[0];
  42.     conf.w_abr=colsizes[1];
  43.     conf.w_freq=colsizes[2];
  44.     conf.w_acod=colsizes[3];
  45.     conf.w_vcod=colsizes[4];
  46.     conf.w_res=colsizes[5];
  47.     conf.w_time=colsizes[6];
  48.     conf.w_file=colsizes[7];
  49.     conf.w_status=colsizes[8];
  50. //    for (i=0; i < 9;i++) printf("%u\n",colsizes[i]);
  51.  }
  52. void set_colsizes()
  53. {
  54.     colsizes[0]=conf.w_fps;
  55.     colsizes[1]=conf.w_abr;
  56.     colsizes[2]=conf.w_freq;
  57.     colsizes[3]=conf.w_acod;
  58.     colsizes[4]=conf.w_vcod;
  59.     colsizes[5]=conf.w_res;
  60.     colsizes[6]=conf.w_time;
  61.     colsizes[7]=conf.w_file;
  62.     colsizes[8]=conf.w_status;
  63.     WinSendMsg(hwndList,MCLB_SETCOLSIZES,MPFROMLONG(&colsizes),NULL);
  64. }
  65.  
  66. void add_playlist()
  67. {
  68.  
  69.     BOOL fRc;
  70.     if (hWndPlayList) {
  71.        get_coords(hWndPlayList,&conf.playlx,&conf.playly,&conf.playlcx, &conf.playlcy);
  72.        get_colsizes();
  73.        save_ini();
  74.        WinDestroyWindow(hWndPlayList);
  75.        hWndPlayList = NULL;
  76.        return;
  77.      }
  78.   fRc = WinRegisterClass (hab, szPlayListClass,(PFNWP)PlayListWndProc, CS_SYNCPAINT,  0);
  79.   if(fRc == FALSE)
  80.   {
  81.     WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  82.       "ÄΦ¿í¬á »α¿ αÑú¿ßΓαᵿ¿ ¬½áßßá «¬¡á ß»¿ß¬á",
  83.       "ÄΦ¿í¬á", 0, MB_ICONHAND | MB_OK);
  84.  
  85.     // ÅÑαÑñ áóáα¿⌐¡δ¼ ºáóÑαΦÑ¡¿Ñ¼ »α¿½«ªÑ¡¿∩
  86.     // π¡¿τΓ«ªáѼ ß«ºñá¡¡πε αá¡ÑÑ «τÑαÑñ∞ ß««íΘÑ¡¿⌐ ¿
  87.     // óδºδóáѼ Σπ¡¬µ¿ε WinTerminate
  88.     WinDestroyMsgQueue (hmq);
  89.     WinTerminate (hab);
  90.     return;
  91.   }
  92.  
  93.   hWndPlayList = WinCreateStdWindow (HWND_DESKTOP,
  94.     0,
  95.     &flPlayListWinFlags, szPlayListClass, szPlayListTitle,
  96.                                  0, 0, ID_APP_PLAYLIST, &hWndPlayListClient);
  97.   if(hWndPlayList == NULLHANDLE)
  98.   {
  99.     WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
  100.       "ÄΦ¿í¬á »α¿ ß«ºñá¡¿¿ ú½áó¡«ú« «¬¡á",
  101.       "ÄΦ¿í¬á", 0, MB_ICONHAND | MB_OK);
  102.     WinDestroyMsgQueue (hmq);
  103.     WinTerminate (hab);
  104.     return;  }
  105.  
  106.   //  WinSetWindowPos (hWndPlayList, HWND_TOP,10, 10, 200, 200, SWP_SIZE | SWP_MOVE | SWP_ACTIVATE |SWP_SHOW);
  107. // set_colsizes();
  108.  WinSetFocus(HWND_DESKTOP,hWndPlayList);
  109.  
  110. //  tb=WinWindowFromID(hWndShow,(USHORT) FID_TITLEBAR);
  111. //  oldTBProc = WinSubclassWindow(tb, (PFNWP)TBWndProc);
  112. }
  113.  
  114.  
  115. void measure_playlist()
  116. {
  117.     WinSetWindowPos (hWndPlayList, HWND_TOP,conf.playlx, conf.playly, conf.playlcx, conf.playlcy, SWP_SIZE | SWP_MOVE | SWP_ACTIVATE |SWP_SHOW);
  118.     set_colsizes();
  119.  return;
  120. }
  121.  
  122. /*
  123. MRESULT APIENTRY TBWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  124. {
  125.   CHAR szMsg[100];
  126.    switch(msg)
  127.    {
  128.    case WM_WINDOWPOSCHANGED:
  129.    case WM_SIZE:
  130.    case WM_MOVE:
  131.        {
  132.            WinQueryWindowPos(hwnd, &tbswp);
  133.            break;
  134.         }
  135.    case WM_PAINT:
  136.        {
  137.            HPS hps;
  138.            RECTL rcl;
  139.            rcl.xLeft=0;
  140.            rcl.yBottom=0;
  141.            rcl.yTop=tbswp.cy;
  142.            rcl.xRight=tbswp.cx;
  143.            hps=WinBeginPaint(hwnd,NULLHANDLE,NULL);
  144.  
  145.            WinDrawBitmap (hps, skn->title_backgr.hbm, NULL, (PPOINTL)&rcl,CLR_BACKGROUND, CLR_NEUTRAL, DBM_STRETCH) ;
  146.            //           oldTBProc(hwnd, msg, mp1, mp2);
  147.            rcl.yTop=skn->title_left.heigth;
  148.            rcl.xRight=skn->title_left.width;
  149.  
  150.            WinDrawBitmap (hps, skn->title_left.hbm, NULL, (PPOINTL)&rcl,CLR_BACKGROUND, CLR_NEUTRAL, DBM_STRETCH) ;
  151. //             WinFillRect(hps, &rcl, CLR_GREEN);
  152.            WinEndPaint(hps);
  153.            return (MRESULT)FALSE;
  154.           // break;
  155.        }
  156.    case TBM_SETHILITE:
  157.        {
  158. //           WinInvalidateRect(hwnd,NULLHANDLE,TRUE);
  159.            return (MRESULT)FALSE;
  160.         }
  161. //       oldTBProc(hwnd, msg, mp1, mp2);
  162.    }
  163.   return (MRESULT)oldTBProc(hwnd, msg, mp1, mp2);
  164. }
  165. */
  166.  
  167. MRESULT APIENTRY PlayListWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  168. {
  169.   CHAR szMsg[100];
  170.    switch(msg)
  171.    {
  172.    case WM_PAINT:
  173.        {
  174.            break;
  175.        }
  176.       case WM_CREATE:
  177.           {
  178.       MCLBINFO InitData;
  179.       LONG InitSizeList[9]= {1L,4L,1L,1L,1L,1L,1L,1L,1L};  // Make col 1 twice as big as 2 and 3
  180.  
  181.       /* Initialize MCLB create data structure */
  182.  
  183.       memset(&InitData, 0x00, sizeof(MCLBINFO));
  184.       // These are the only required initialization values:
  185.       InitData.Size = sizeof(MCLBINFO);
  186.       InitData.Cols = 9;
  187.       InitData.TabChar = delim;
  188.       InitData.Titles = "Status!Media file!Time!Resolution!Video codec!Audio codec!Freq!Audio bit rate!FPS";
  189.       InitData.InitSizes= InitSizeList;  // Initial sizes (proportions)
  190.  
  191.       // Play with these for colors and fonts:
  192.        InitData.TitleBColor = skn->playlist.TitleBColor;
  193.        InitData.TitleFColor = skn->playlist.TitleFColor;
  194.        InitData.ListBColor = skn->playlist.ListBColor;
  195.        InitData.ListFColor = skn->playlist.ListFColor;
  196.        strcpy(InitData.ListFont, skn->playlist.ListFont);
  197.        strcpy(InitData.TitleFont, skn->playlist.TitleFont);
  198.  
  199.       hwndList = MCLBCreateWindow(
  200.                  hwnd,            // Parent window
  201.                  hwnd,                    // Owner to recv messages
  202.                  WS_VISIBLE|              // Styles: Make it visible
  203.                  WS_TABSTOP|              // Let user TAB to it
  204.                  MCLBS_SIZEMETHOD_PROP|   // Proportional sizing when window is sized
  205.                  LS_HORZSCROLL,           // Give each column a horizontal scroll bar
  206.                  0,0,100,100,             // Will set size later, but must have large horz size now
  207.                  HWND_TOP,                // Put on top of any sibling windows
  208.                  ID_PLAYLIST,             // Window ID
  209.                  &InitData);              // MCLB create structure
  210.  
  211.        hWndPLMenu = WinLoadMenu(hwndList, NULLHANDLE, ID_PLSTMENU);
  212.       fillPlayList(playLst);
  213.       return FALSE;                                                             
  214.           }
  215.  
  216.    case WM_CLOSE:
  217.        {
  218.            //                      DosBeep(2000,100);
  219.            WinDestroyWindow(hWndPlayList);
  220.            return MRESULT(TRUE);
  221.                      //           break;
  222.        }
  223.    case WM_BUTTON2UP:
  224.        {
  225.            POINTL ptl;
  226.            WinQueryPointerPos(HWND_DESKTOP, &ptl);
  227.            WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1L);
  228.                WinPopupMenu(hwnd, hwnd, hWndPLMenu, ptl.x,ptl.y,0,
  229.                PU_MOUSEBUTTON1 | PU_KEYBOARD | PU_HCONSTRAIN | PU_VCONSTRAIN);
  230.                return 0;
  231.            break;
  232.        }
  233.    case WM_CONTROL:
  234.        {
  235.            SHORT Item;   // Item index
  236.            char buf[255];
  237.            char name1[255];
  238.            char *name;
  239.            pplayItem p;
  240.  
  241.            if (SHORT1FROMMP(mp1) == ID_PLAYLIST)
  242.            {
  243.              switch SHORT2FROMMP(mp1) {
  244.              case LN_ENTER: // User double-clicked or pressed ENTER in the MCLB.
  245.                  {
  246.                      Item = SHORT1FROMMR(WinSendMsg(hwndList, LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), MPVOID));
  247.                      p = search_item(Item);
  248.                      if (p != NULL)
  249.                      {
  250.                       if (playonce != NULL) // we played only one media not from list
  251.                       { free(playonce);
  252.                         playonce = NULL;
  253.                         }
  254. //                         printf("will play: %s\n",p->fName);
  255.                          playonce = p;
  256.                          WinPostMsg(hWndClient,WM_COMMAND,MPFROM2SHORT(IDM_PLAYONE,0),NULL);
  257.                       }
  258.                  } // case lm_enter
  259.              }
  260.            } // if playlist
  261.            break;
  262.         } // case wm_control
  263.      case WM_CONTEXTMENU:
  264.           {
  265.            POINTL ptl;
  266.            WinQueryPointerPos(HWND_DESKTOP, &ptl);
  267.            WinMapWindowPoints(HWND_DESKTOP, hwnd, &ptl, 1L);
  268.                WinPopupMenu(hwnd, hwnd, hWndPLMenu, ptl.x,ptl.y,0,
  269.                PU_MOUSEBUTTON1 | PU_KEYBOARD | PU_HCONSTRAIN | PU_VCONSTRAIN);
  270.                return 0;
  271.           } // case ALN_
  272.  
  273.    case WM_COMMAND:
  274.        {
  275.           switch (COMMANDMSG(&msg)->cmd)
  276.           {
  277.           case IDM_LOADPLLST:
  278.               {
  279. //                  DosBeep(2000,200);
  280.                   sl_playlist(hwnd,TRUE); // save/load playlist
  281.                   break;
  282.               }
  283.           case IDM_SAVEPLLST:
  284.               {
  285. //                  DosBeep(2000,200);
  286.                   sl_playlist(hwnd,FALSE); // save/load playlist
  287.                   break;
  288.               }
  289.  
  290.           case IDM_PLAY:
  291.               {
  292.                   //                  add_playlist();
  293.                   int item;
  294.                   item = (int)WinSendMsg(hwndList,LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),NULL);
  295.                   playonce = search_item(item);
  296.                   WinPostMsg(hWndClient,WM_COMMAND,MPFROM2SHORT(IDM_PLAYONE,0),NULL);
  297.                   break;
  298.               }
  299.           case IDM_ADDTOLIST:
  300.               {
  301.                   WinPostMsg(hWndClient,WM_COMMAND,MPFROM2SHORT(IDM_ADDTOLIST,0),NULL);
  302.                   break;
  303.               }
  304.           case IDM_REMOVE:
  305.               {
  306.                   int item;
  307.                   item = (int)WinSendMsg(hwndList,LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),NULL);
  308.                   remove_row(item);
  309.                     fillPlayList(playLst);
  310. //                  if (playLst != NULL) set_button_state(&skn->play_butt, MBS_RELEASED,FALSE);
  311.                   break;
  312.               }
  313.  
  314.           case IDM_LOADMEDIA:
  315.               {
  316.                 WinPostMsg(hWndClient,WM_COMMAND,MPFROM2SHORT(IDM_LOADMEDIA,0),NULL);
  317.                   break;
  318.               }
  319.  
  320.           case IDM_EXIT:
  321.               {
  322.              WinDestroyWindow(hWndPlayList);
  323.              hWndPlayList=NULL;
  324.              break;
  325.               }
  326.            } //switch
  327.          return 0;
  328.         }  // case wm command
  329.    case WM_SIZE:
  330.        {
  331.          WinSetWindowPos (WinWindowFromID (hwnd, ID_PLAYLIST), HWND_TOP,
  332.                        0, 0, SHORT1FROMMP (mp2), SHORT2FROMMP (mp2),
  333.                        SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ACTIVATE);
  334.        break;
  335.        }
  336.  
  337.    case WM_DESTROY:
  338.        {
  339.        get_coords(hWndPlayList,&conf.playlx,&conf.playly,&conf.playlcx, &conf.playlcy);
  340.        get_colsizes();
  341.        save_ini();
  342. //           WinDestroyWindow(hWndPlayList);
  343.             hWndPlayList=NULL;
  344. //           DosBeep(2000,100);
  345.            plrows=0;
  346.            break;
  347.        }
  348.    }
  349.    
  350.    return WinDefWindowProc(hwnd, msg, mp1, mp2);
  351. }
  352.  
  353. void insert_row(pplayItem ppl, int row)
  354. {
  355.     char itemRow[255];
  356.     strcpy(itemRow," !");
  357.     strcat(itemRow,ppl->fName);
  358.     strcat(itemRow,"!");
  359.     strcat(itemRow,ppl->time);
  360.     strcat(itemRow,"!");
  361.     strcat(itemRow,ppl->res);
  362.     strcat(itemRow,"!");
  363.     strcat(itemRow,ppl->vCodec);
  364.     strcat(itemRow,"!");
  365.     strcat(itemRow,ppl->aCodec);
  366.     strcat(itemRow,"!");
  367.     strcat(itemRow,ppl->freq);
  368.     strcat(itemRow,"!");
  369.     strcat(itemRow,ppl->abitrate);
  370.     strcat(itemRow,"!");
  371.     strcat(itemRow,ppl->fps);
  372. //    printf("Inserting row:\n%s\n",itemRow);
  373.     ppl->row=(int)WinSendMsg(hwndList, LM_INSERTITEM, MPFROM2SHORT(LIT_END, 0), MPFROMP(itemRow));
  374.  
  375. }
  376.  
  377. void remove_item(pplayItem ppl)
  378. {
  379.     if (ppl == NULL || playLst == NULL) return;
  380.     if (ppl == playLst) // first item
  381.     {
  382.         if (playLst->next != NULL) // more than 2 elements
  383.         {
  384.             playLst = playLst->next; // next stays first
  385.             playLst->prev = NULL; // have not previous
  386.             free(ppl);  // free current
  387.             ppl = NULL;
  388.             return;
  389.         }
  390.         else
  391.         {
  392.          free(ppl);
  393.          ppl = playLst = NULL;
  394.          return;
  395.         }
  396.      }
  397.     if (ppl->prev != NULL) ppl->prev->next = ppl->next; // removing row from chain
  398.     if (ppl->next != NULL) ppl->next->prev = ppl->prev;
  399.     free(ppl);
  400.     ppl = NULL;
  401. }
  402.  
  403. void remove_row(int item)
  404. {
  405.     pplayItem p;
  406.     p = search_item(item);
  407.     remove_item(p);
  408.     WinSendMsg(hwndList, LM_DELETEITEM, MPFROMSHORT(item), NULL);
  409. }
  410.  
  411.  
  412. pplayItem search_item(int item)
  413. {
  414.     pplayItem pp;
  415.     if (playLst == NULL) return NULL;
  416.     pp = playLst;
  417.     while(pp->row != item)
  418.     {
  419.         if (pp->next != NULL) // not last
  420.             pp = pp->next;
  421.         else return NULL; // not found
  422.     }     //while
  423.   return pp;
  424. }
  425.  
  426.  
  427. void fillPlayList(pplayItem ppl) //
  428. {
  429.     pplayItem pp;
  430.     int i; // row in playlist
  431.     if (ppl == NULL) return;
  432.     WinEnableWindowUpdate(hwndList, FALSE);
  433.     WinSendMsg(hwndList,LM_DELETEALL,NULL,NULL);
  434.      if (plrows > 0 ) { // not empty
  435.          // clear all playlist
  436.     }
  437.     pp = ppl;
  438.     i = plrows = 0;
  439.     do {
  440.            insert_row(pp,i+1);
  441.             i++;
  442.             pp = pp->next;
  443.     } while(pp != NULL);    //while
  444.  
  445.     plrows=i;
  446.     //    printf("rows=%i\n",plrows);
  447.     WinShowWindow(hwndList, TRUE);
  448.    if (hwndList != NULL) WinInvalidateRect(hwndList,NULLHANDLE,TRUE);
  449. }
  450. // moving elements in item up (step < 0) or down (step >0)
  451. void move_item(pplayItem ppl,pplayItem ppi, int step)
  452. {
  453.     if (ppl == NULL || ppi == NULL || step == 0) return; // dont try to fuck me!
  454.     pplayItem pp,next;
  455.  
  456. }
  457.  
  458. void addNewItem(pplayItem ppl)
  459. {
  460.     pplayItem pp,p_prev;
  461.  
  462.     if (ppl == NULL) return; // nothing to add
  463.     if (playLst == NULL) // playlist is empty
  464.     {
  465.         playLst = ppl;
  466.         ppl->prev = ppl->next = NULL;
  467.         fillPlayList(playLst);
  468.         return;
  469.      }
  470.     pp = playLst;
  471.  
  472.     do {
  473.         p_prev = pp;
  474.         pp=pp->next;
  475.     } while (pp != NULL); //skip to end of playlist
  476.  
  477.     pp = ppl; // set current;
  478.     p_prev->next = ppl;
  479.     pp->prev = p_prev; // previous point to the last
  480.     pp->next=NULL;
  481.     fillPlayList(playLst);
  482.     pp = playLst;
  483.     do {
  484.         pp=pp->next;
  485.     } while (pp != NULL); //skip to end of playlist
  486.  
  487.     return;
  488. }
  489.  
  490. int read_playlist(char *cName, pplayItem ppi)
  491. {
  492.     FILE *fin;
  493.     char *pline;
  494.     char fname[_MAX_PATH];
  495.     char *ptr;
  496.     static char line[2048];
  497.     int errors = 0;
  498.     BOOL ispl;
  499.     line[0] = 0;
  500.     int cnt;
  501.     int i;
  502.  
  503.     fin = fopen(cName, "r");
  504.  
  505.     if (!fin)
  506.     {
  507.         //syslog(LOG_WARNING, "Unable to load file %s\n", cName);
  508.         return 1;
  509.     }
  510.     ispl = FALSE;
  511.     i = 0;
  512.     do 
  513.     {
  514.         i++;
  515.         pline = fgets(line, sizeof(line), fin);
  516.         if (pline == NULL) break;
  517.         if(!*pline         ||
  518.             *pline == '\r' ||
  519.             *pline == '\n' ||
  520.             *pline == '#'  ||
  521.             *pline == ';')
  522.             continue;
  523.         if (!ispl) // still no playlist label
  524.         {
  525.           if(strnicmp(line,"[playlist]",10) == 0)
  526.            {
  527.             ispl = TRUE; // no playlists
  528.             continue;
  529.            }
  530.         }
  531.         if (ispl) // has playlist label
  532.         {
  533.          if(strnicmp(line,"file",4) == 0)    // seek for file
  534.              {
  535.                  do { *pline++; } while(*pline != '=');  // skip after '='
  536.                  *pline++;
  537.                // count file name length
  538.                 cnt = 0;
  539.                 ptr = strchr(pline, '\n');
  540.                 *ptr = '\0';
  541.                 strcpy(fname,pline);
  542.                // add filename to playlist
  543.                if ((fname != NULL) && (fname[0] != '\0'))
  544.                {
  545.                    printf("%s\n",fname); fflush(stdout);
  546.                    addNewItem(load_media(NULL, fname));
  547.                }
  548.             } // get file name
  549.         } // if ispl
  550.     } while (!feof(fin)); // feof
  551.     fclose(fin);
  552.     return 0;
  553. }
  554.  
  555. int save_playlist(char *cName, pplayItem ppi)
  556. {
  557.     FILE *fin;
  558.     char *pline;
  559.     char fname[_MAX_PATH];
  560.     char *ptr;
  561.     static char line[2048];
  562.     char buf[60];
  563.     int errors = 0;
  564.     BOOL ispl;
  565.     line[0] = 0;
  566.     int cnt;
  567.     int i;
  568.     pplayItem pp;
  569.  
  570.  
  571.     if (ppi == NULL) return -2;
  572.     pp = ppi;
  573.     fin = fopen(cName, "w");
  574.     if (!fin)
  575.     {
  576.         //syslog(LOG_WARNING, "Unable to load file %s\n", cName);
  577.         return 1;
  578.     }
  579.     strcpy(line,"[playlist]");
  580.     if (fputs(line,fin) == EOF)
  581.     {
  582.         fclose(fin);
  583.         return -1;
  584.     }
  585.     fputc('\n',fin);
  586.     i = 0;
  587.     do {
  588.        i++;
  589.        strcpy(line,"File");
  590.        _itoa(i, buf, 10);
  591.        strcat(line,buf);
  592.        strcat(line,"=");
  593.        strcat(line,pp->fName);
  594.       if (fputs(line,fin) == EOF)
  595.       {
  596.          fclose(fin);
  597.         return -1;
  598.       }
  599.       fputc('\n',fin);
  600.             pp = pp->next;
  601.     } while(pp != NULL);    //while
  602.  
  603.     fclose(fin);
  604.     return 0;
  605. }
  606.  
  607. int sl_playlist(HWND fd_hwnd,BOOL load_fl) // save/load playlist
  608. {
  609.    FILEDLG pfdFiledlg;
  610.    HWND hwndD;
  611.    char *pszFullFile;
  612.    int plrc;
  613.  
  614.    memset(&pfdFiledlg, 0, sizeof(FILEDLG));
  615.    if (load_fl)
  616.        pfdFiledlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
  617.     else pfdFiledlg.fl = FDS_CENTER | FDS_SAVEAS_DIALOG | FDS_ENABLEFILELB;
  618.        pfdFiledlg.cbSize = sizeof(FILEDLG);
  619.        pfdFiledlg.pszTitle= "Choose playlist file:";
  620. //       strcat(pfdFiledlg.szFullFile,conf.mediapath); // last saved path if any
  621.        strcpy(pfdFiledlg.szFullFile,"*");
  622.        hwndD = WinFileDlg(HWND_DESKTOP, fd_hwnd, &pfdFiledlg);
  623.       if (hwndD && (pfdFiledlg.lReturn == DID_OK))
  624.       {
  625.        pszFullFile=pfdFiledlg.szFullFile;
  626.        if (load_fl) plrc=read_playlist(pszFullFile, NULL);
  627.        else plrc=save_playlist(pszFullFile, playLst);
  628.        if (plrc == 0) // playlist save/load successfully
  629.             {
  630.              strcpy(conf.playlstfile,pszFullFile);
  631.              save_ini();
  632.             }
  633.        }
  634.        else
  635.        {
  636.            printf("Error creating file dialog\n");fflush(stdout);
  637. //           pszFullFile=SkinFileDlg(fd_hwnd);
  638.            return -1;
  639.        }
  640.     return 0;
  641. }
  642.  
  643. void check_playlist()
  644. {
  645.     if (conf.LoadLastPlaylist) // if load last playlist?
  646.     {
  647.         if (conf.playlstfile != NULL &&
  648.             conf.playlstfile != "" &&
  649.             conf.playlstfile[0] != '\0')
  650.         {
  651.           read_playlist(conf.playlstfile, NULL);
  652.          }
  653.      }
  654.  }
  655.