]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/playlist.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / wince / playlist.cpp
index ae5f1cd278d45ffbc3adad1357b809fa44636951..08673ce1a78e686f64c8d10d6b1305ba288f9b9c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * playlist.cpp : WinCE gui plugin for VLC
  *****************************************************************************
- * Copyright (C) 2000-2004 VideoLAN
+ * Copyright (C) 2000-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                            /* strerror() */
-#include <stdio.h>
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
 
 #include "wince.h"
 
 #include <commctrl.h>
 #include <commdlg.h>
 
-#ifndef NMAXFILE
-#define NMAXFILE 512 // at least 256
-#endif
-
 #ifndef TEXTMAXBUF
 #define TEXTMAXBUF 512 // at least 500
 #endif
 
 #define LONG2POINT(l, pt)  ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
 
-#define NUMIMAGES     11   // Number of buttons in the toolbar           
-#define IMAGEWIDTH    16   // Width of the buttons in the toolbar  
-#define IMAGEHEIGHT   16   // Height of the buttons in the toolbar  
+#define NUMIMAGES     11   // Number of buttons in the toolbar
+#define IMAGEWIDTH    16   // Width of the buttons in the toolbar
+#define IMAGEHEIGHT   16   // Height of the buttons in the toolbar
 #define BUTTONWIDTH   0    // Width of the button images in the toolbar
 #define BUTTONHEIGHT  0    // Height of the button images in the toolbar
 #define ID_TOOLBAR    2000 // Identifier of the main tool bar
 
-enum      
+enum
 {
   Infos_Event = 1000,
   Up_Event,
@@ -64,7 +57,7 @@ enum
   PopupPlay_Event,
   PopupDel_Event,
   PopupEna_Event,
-  PopupInfo_Event  
+  PopupInfo_Event
 };
 
 // Help strings
@@ -101,7 +94,7 @@ static TBBUTTON tbButton2[] =
 };
 
 // Toolbar ToolTips
-TCHAR * szToolTips2[] = 
+TCHAR * szToolTips2[] =
 {
     HELP_OPENPL,
     HELP_SAVEPL,
@@ -123,13 +116,12 @@ TCHAR * szToolTips2[] =
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-Playlist::Playlist( intf_thread_t *_p_intf, HINSTANCE _hInst )
+Playlist::Playlist( intf_thread_t *p_intf, CBaseWindow *p_parent,
+                    HINSTANCE h_inst )
+  :  CBaseWindow( p_intf, p_parent, h_inst )
 {
     /* Initializations */
-    p_intf = _p_intf;
-        hInst = _hInst;
-        hListView = NULL;
-
+    hListView = NULL;
     i_title_sorted = 1;
     i_author_sorted = 1;
 
@@ -137,10 +129,10 @@ Playlist::Playlist( intf_thread_t *_p_intf, HINSTANCE _hInst )
 }
 
 /***********************************************************************
-FUNCTION: 
+FUNCTION:
   CreateMenuBar
 
-PURPOSE: 
+PURPOSE:
   Creates a menu bar.
 ***********************************************************************/
 static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
@@ -235,10 +227,10 @@ static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
 }
 
 /***********************************************************************
-FUNCTION: 
+FUNCTION:
   WndProc
 
-PURPOSE: 
+PURPOSE:
   Processes messages sent to the main window.
 ***********************************************************************/
 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
@@ -254,7 +246,7 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
 
     switch( msg )
     {
-    case WM_INITDIALOG: 
+    case WM_INITDIALOG:
         shidi.dwMask = SHIDIM_FLAGS;
         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
@@ -279,7 +271,7 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
                                   BUTTONWIDTH, BUTTONHEIGHT,
                                   IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
         if( !hwndTB ) break;
-  
         // Add ToolTips to the toolbar.
         SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
                      (LPARAM)szToolTips2 );
@@ -287,11 +279,11 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
         // Reposition the toolbar.
         GetClientRect( hwnd, &rect );
         GetWindowRect( hwndTB, &rectTB );
-        MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left, 
+        MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
                     MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
 
         // random, loop, repeat buttons states
-        vlc_value_t val; 
+        vlc_value_t val;
         p_playlist = (playlist_t *)
             vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
         if( !p_playlist ) break;
@@ -313,8 +305,8 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
         GetClientRect( hwnd, &rect );
         hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
             LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
-            rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left, 
-            rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT, 
+            rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
+            rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
             hwnd, NULL, hInst, NULL );
         ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
 
@@ -336,8 +328,6 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
         ListView_InsertColumn( hListView, 2, &lv);
 
         SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
-
-        SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
         break;
 
     case WM_TIMER:
@@ -348,7 +338,12 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
         EndDialog( hwnd, LOWORD( wp ) );
         break;
 
-    case WM_COMMAND:    
+    case WM_SETFOCUS:
+        SHSipPreference( hwnd, SIP_DOWN );
+        SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
+        break;
+
+    case WM_COMMAND:
         switch( LOWORD(wp) )
         {
         case IDOK:
@@ -361,29 +356,23 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
             break;
 
         case ID_MANAGE_SAVEPL:
-            SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
             OnSave();
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
             break;
 
         case ID_MANAGE_ADDFILE:
-            SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
-            OnAddFile( VLC_FALSE );
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
+            p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE,
+                                           0, 0 );
             b_need_update = VLC_TRUE;
             break;
 
         case ID_MANAGE_ADDDIRECTORY:
-            SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
-            OnAddFile( VLC_TRUE );
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
+            p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY,
+                                           0, 0 );
             b_need_update = VLC_TRUE;
             break;
 
         case ID_MANAGE_ADDMRL:
-            SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
-            OnAddMRL();
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
+            p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
             b_need_update = VLC_TRUE;
             break;
 
@@ -393,9 +382,7 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
             break;
 
         case Infos_Event:
-            SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
             OnPopupInfo( hwnd );
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
             b_need_update = VLC_TRUE;
             break;
 
@@ -474,7 +461,6 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
 
         case PopupInfo_Event:
             OnPopupInfo( hwnd );
-            SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
             b_need_update = VLC_TRUE;
             break;
 
@@ -492,7 +478,7 @@ LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
         }
         else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
                  ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU  ) )
-        {                       
+        {
             HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
         }
         else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
@@ -536,7 +522,7 @@ LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
             vlc_object_release(p_playlist);
             return CDRF_NEWFONT;
         }
-        
         playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
                                         (int)lplvcd->nmcd.dwItemSpec );
         if( !p_item )
@@ -579,6 +565,15 @@ void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
     DestroyMenu( hMenuTrackPopup );
 }
 
+/**********************************************************************
+ * Show the playlist
+ **********************************************************************/
+void Playlist::ShowPlaylist( bool b_show )
+{
+    if( b_show ) Rebuild();
+    Show( b_show );
+}
+
 /**********************************************************************
  * Update the playlist
  **********************************************************************/
@@ -589,11 +584,11 @@ void Playlist::UpdatePlaylist()
         Rebuild();
         b_need_update = VLC_FALSE;
     }
-        
     playlist_t *p_playlist = (playlist_t *)
         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
     if( p_playlist == NULL ) return;
-        
     /* Update the colour of items */
 
     vlc_mutex_lock( &p_playlist->object_lock );
@@ -672,11 +667,11 @@ void Playlist::UpdateItem( int i )
 
     ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
     ListView_SetItemText( hListView, i, 1,
-                          _FROMMB( vlc_input_item_GetInfo( &p_item->input,
+                          _FROMMB( input_ItemGetInfo( &p_item->input,
                                    _("General") , _("Author") ) ) );
 
     char psz_duration[MSTRTIME_MAX_SIZE];
-    mtime_t dur = p_item->input.i_duration;
+    mtime_t dur = input_item_GetDuration( p_item );
     if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
     else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
 
@@ -703,150 +698,81 @@ void Playlist::DeleteItem( int item )
 /**********************************************************************
  * I/O functions
  **********************************************************************/
-void Playlist::OnOpen()
+static void OnOpenCB( intf_dialog_args_t *p_arg )
 {
-    OPENFILENAME ofn;
-    TCHAR DateiName[80+1] = _T("\0");
-    static TCHAR szFilter[] = _T("All playlists (*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u)\0*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u\0");
-
-    playlist_t *p_playlist = (playlist_t *)
-        vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_playlist == NULL ) return;
+    intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
 
-    memset( &ofn, 0, sizeof(OPENFILENAME) );
-    ofn.lStructSize = sizeof (OPENFILENAME);
-    ofn.hwndOwner = NULL;
-    ofn.hInstance = hInst;
-    ofn.lpstrFilter = szFilter;
-    ofn.lpstrCustomFilter = NULL;
-    ofn.nMaxCustFilter = 0;
-    ofn.nFilterIndex = 1;     
-    ofn.lpstrFile = (LPTSTR) DateiName; 
-    ofn.nMaxFile = 80;
-    ofn.lpstrFileTitle = NULL; 
-    ofn.nMaxFileTitle = 40;
-    ofn.lpstrInitialDir = NULL;
-    ofn.lpstrTitle = _T("Open playlist");
-    ofn.Flags = 0; 
-    ofn.nFileOffset = 0;
-    ofn.nFileExtension = 0;
-    ofn.lpstrDefExt = NULL;
-    ofn.lCustData = 0L;
-    ofn.lpfnHook = NULL;
-    ofn.lpTemplateName = NULL;
-
-    if( GetOpenFileName((LPOPENFILENAME)&ofn) )
+    if( p_arg->i_results && p_arg->psz_results[0] )
     {
-        playlist_Import( p_playlist, _TOMB(ofn.lpstrFile) );
-    }
+        playlist_t * p_playlist = (playlist_t *)
+            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
 
-    vlc_object_release( p_playlist );
+        if( p_playlist )
+        {
+            playlist_Import( p_playlist, p_arg->psz_results[0] );
+        }
+
+        if( p_playlist ) vlc_object_release( p_playlist );
+    }
 }
 
-void Playlist::OnSave()
+void Playlist::OnOpen()
 {
-    TCHAR szFile[NMAXFILE] = _T("\0");
-    OPENFILENAME ofn;
-    TCHAR psz_filters[1000];
+    char *psz_filters ="All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u";
 
-    struct
-    {
-        char *psz_desc;
-        char *psz_filter;
-        char *psz_module;
+    intf_dialog_args_t *p_arg =
+        (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
+    memset( p_arg, 0, sizeof(intf_dialog_args_t) );
 
-    } formats[] =
-    { { "M3U file", "*.m3u", "export-m3u" },       
-      { "PLS file", "*.pls", "export-pls" }
-    };
+    p_arg->psz_title = strdup( "Open playlist" );
+    p_arg->psz_extensions = strdup( psz_filters );
+    p_arg->p_arg = p_intf;
+    p_arg->pf_callback = OnOpenCB;
 
-    for( int i_len = 0, i = 0; i < sizeof(formats)/sizeof(formats[0]); i++ )
-    {
-        _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_desc) );
-        i_len = i_len + _tcslen( psz_filters + i_len );
-        psz_filters[i_len++] = '\0';
-        _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_filter) );
-        i_len = i_len + _tcslen( psz_filters + i_len );
-        psz_filters[i_len++] = '\0';
-        if( i == sizeof(formats)/sizeof(formats[0]) -1 )
-            psz_filters[i_len] = '\0';
-    }
+    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
+}
 
-    memset( &(ofn), 0, sizeof(ofn));
-    ofn.lStructSize     = sizeof(ofn);
-    ofn.hwndOwner = NULL;
-    ofn.lpstrFile = szFile;
-    ofn.nMaxFile = NMAXFILE;    
-    ofn.lpstrFilter = psz_filters;
-    ofn.lpstrTitle = _T("Save playlist");
-    ofn.Flags = OFN_HIDEREADONLY; 
+static void OnSaveCB( intf_dialog_args_t *p_arg )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
 
-    if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
+    if( p_arg->i_results && p_arg->psz_results[0] )
     {
         playlist_t * p_playlist = (playlist_t *)
             vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
 
-        if( p_playlist && ofn.lpstrFile )
+        if( p_playlist )
         {
-            playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
-                             formats[ofn.nFilterIndex ?
-                                     ofn.nFilterIndex - 1 : 0].psz_module );
+            char *psz_export;
+            char *psz_ext = strrchr( p_arg->psz_results[0], '.' );
+
+            if( psz_ext && !strcmp( psz_ext, ".pls") )
+                psz_export = "export-pls";
+            else psz_export = "export-m3u";
+
+            playlist_Export( p_playlist, p_arg->psz_results[0], psz_export );
         }
 
         if( p_playlist ) vlc_object_release( p_playlist );
     }
 }
 
-void Playlist::OnAddFile( vlc_bool_t b_directory )
+void Playlist::OnSave()
 {
-    // Same code as in Interface
-    OPENFILENAME ofn;
-    TCHAR DateiName[80+1] = _T("\0");
-    static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
-
-    memset( &ofn, 0, sizeof(OPENFILENAME) );
-    ofn.lStructSize = sizeof(OPENFILENAME);
-    ofn.hwndOwner = NULL;
-    ofn.hInstance = hInst;
-    ofn.lpstrFilter = szFilter;
-    ofn.lpstrCustomFilter = NULL;
-    ofn.nMaxCustFilter = 0;
-    ofn.nFilterIndex = 1;     
-    ofn.lpstrFile = (LPTSTR)DateiName; 
-    ofn.nMaxFile = 80;
-    ofn.lpstrFileTitle = NULL; 
-    ofn.nMaxFileTitle = 40;
-    ofn.lpstrInitialDir = NULL;
-    ofn.lpstrTitle = _T("Add File");
-    ofn.Flags = 0; 
-    ofn.nFileOffset = 0;
-    ofn.nFileExtension = 0;
-    ofn.lpstrDefExt = NULL;
-    ofn.lCustData = 0L;
-    ofn.lpfnHook = NULL;
-    ofn.lpTemplateName = NULL;
-
-#if 0//def UNDER_CE
-    if( b_directory ) ofn.Flags |= OFN_PROJECT;
-#endif
-
-    SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
+    char *psz_filters ="M3U file|*.m3u|PLS file|*.pls";
 
-    if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
-    {
-        playlist_t *p_playlist = (playlist_t *)
-           vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-       if( p_playlist == NULL ) return;
+    intf_dialog_args_t *p_arg =
+        (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
+    memset( p_arg, 0, sizeof(intf_dialog_args_t) );
 
-        char *psz_filename = _TOMB(ofn.lpstrFile);
-        playlist_Add( p_playlist, psz_filename, psz_filename,
-                      PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
-       vlc_object_release( p_playlist );
-    }
-}
+    p_arg->psz_title = strdup( "Save playlist" );
+    p_arg->psz_extensions = strdup( psz_filters );
+    p_arg->b_save = VLC_TRUE;
+    p_arg->p_arg = p_intf;
+    p_arg->pf_callback = OnSaveCB;
 
-void Playlist::OnAddMRL()
-{
+    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC,
+                                   0, p_arg );
 }
 
 /**********************************************************************
@@ -951,8 +877,8 @@ void Playlist::ShowInfos( HWND hwnd, int i_item )
     if( p_item )
     {
         ItemInfoDialog *iteminfo_dialog =
-            new ItemInfoDialog( p_intf, hInst, p_item );
-        CreateDialogBox( hwnd, iteminfo_dialog );                
+            new ItemInfoDialog( p_intf, this, hInst, p_item );
+        CreateDialogBox( hwnd, iteminfo_dialog );
         UpdateItem( i_item );
         delete iteminfo_dialog;
     }
@@ -1019,7 +945,7 @@ void Playlist::OnDown()
 void Playlist::OnRandom()
 {
     vlc_value_t val;
-    int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 ); 
+    int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
     val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
 
     playlist_t *p_playlist = (playlist_t *)
@@ -1033,7 +959,7 @@ void Playlist::OnRandom()
 void Playlist::OnLoop ()
 {
     vlc_value_t val;
-    int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 ); 
+    int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
     val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
 
     playlist_t *p_playlist = (playlist_t *)
@@ -1047,7 +973,7 @@ void Playlist::OnLoop ()
 void Playlist::OnRepeat ()
 {
     vlc_value_t val;
-    int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );  
+    int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
     val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
 
     playlist_t *p_playlist = (playlist_t *)