]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/dialogs.cpp
* dialogs.cpp: fixed an assert failure in open skins dialog
[vlc] / modules / gui / skins2 / src / dialogs.cpp
index 04a9b084877601e6ba68033685ade70ee8a9ba57..347fd9c689338d573e92f316eb5f433fca806939 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * dialogs.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: dialogs.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * Copyright (C) 2003 the VideoLAN team
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
 #include "../commands/async_queue.hpp"
 #include "../commands/cmd_change_skin.hpp"
 #include "../commands/cmd_quit.hpp"
+#include "../commands/cmd_playlist.hpp"
 
 
 /// Callback called when a new skin is chosen
-static void showChangeSkinCB( intf_dialog_args_t *pArg )
+void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
 {
     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
 
@@ -38,12 +39,12 @@ static void showChangeSkinCB( intf_dialog_args_t *pArg )
         if( pArg->psz_results[0] )
         {
             // Create a change skin command
-            CmdChangeSkin *pCmd = new CmdChangeSkin( pIntf,
-                                                     pArg->psz_results[0] );
+            CmdChangeSkin *pCmd =
+                new CmdChangeSkin( pIntf, pArg->psz_results[0] );
 
             // Push the command in the asynchronous command queue
             AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
-            pQueue->remove( "resize" );
+            pQueue->remove( "change skin" );
             pQueue->push( CmdGenericPtr( pCmd ) );
         }
     }
@@ -57,12 +58,48 @@ static void showChangeSkinCB( intf_dialog_args_t *pArg )
 }
 
 
+void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
+{
+    intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
+
+    if( pArg->i_results && pArg->psz_results[0] )
+    {
+        // Create a Playlist Load command
+        CmdPlaylistLoad *pCmd =
+            new CmdPlaylistLoad( pIntf, pArg->psz_results[0] );
+
+        // Push the command in the asynchronous command queue
+        AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+        pQueue->remove( "load playlist" );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+}
+
+
+void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
+{
+    intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
+
+    if( pArg->i_results && pArg->psz_results[0] )
+    {
+        // Create a Playlist Save command
+        CmdPlaylistSave *pCmd =
+            new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
+
+        // Push the command in the asynchronous command queue
+        AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+        pQueue->remove( "load playlist" );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+}
+
+
 /// Callback called when the popup menu is requested
 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     Dialogs *p_dialogs = (Dialogs *)param;
-    p_dialogs->showPopupMenu( new_val.b_bool );
+    p_dialogs->showPopupMenu( new_val.b_bool != 0 );
 
     return VLC_SUCCESS;
 }
@@ -125,14 +162,14 @@ bool Dialogs::init()
 {
     // Allocate descriptor
     m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
-                                                      VLC_OBJECT_INTF );
+                                                      VLC_OBJECT_DIALOGS );
     if( m_pProvider == NULL )
     {
         msg_Err( getIntf(), "out of memory" );
         return false;
     }
 
-    m_pModule = module_Need( m_pProvider, "dialogs provider", NULL );
+    m_pModule = module_Need( m_pProvider, "dialogs provider", NULL, 0 );
     if( m_pModule == NULL )
     {
         msg_Err( getIntf(), "No suitable dialogs provider found" );
@@ -159,7 +196,8 @@ bool Dialogs::init()
 }
 
 
-void Dialogs::showChangeSkin()
+void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
+                               DlgCallback callback, int flags )
 {
     if( m_pProvider && m_pProvider->pf_show_dialog )
     {
@@ -167,14 +205,14 @@ void Dialogs::showChangeSkin()
             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
         memset( p_arg, 0, sizeof(intf_dialog_args_t) );
 
-        p_arg->b_blocking = false;
+        p_arg->psz_title = strdup( rTitle.c_str() );
+        p_arg->psz_extensions = strdup( rExtensions.c_str() );
 
-        p_arg->psz_title = strdup( _("Open a skin file") );
-        p_arg->psz_extensions =
-            strdup( "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|" );
+        p_arg->b_save = flags & kSAVE;
+        p_arg->b_multiple = flags & kMULTIPLE;
 
         p_arg->p_arg = getIntf();
-        p_arg->pf_callback = showChangeSkinCB;
+        p_arg->pf_callback = callback;
 
         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
                                      0, p_arg );
@@ -182,6 +220,29 @@ void Dialogs::showChangeSkin()
 }
 
 
+void Dialogs::showChangeSkin()
+{
+    showFileGeneric( _("Open a skin file"),
+                     _("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml"),
+                     showChangeSkinCB, kOPEN );
+}
+
+
+void Dialogs::showPlaylistLoad()
+{
+    showFileGeneric( _("Open playlist"),
+                     _("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"),
+                     showPlaylistLoadCB, kOPEN );
+}
+
+
+void Dialogs::showPlaylistSave()
+{
+    showFileGeneric( _("Save playlist"), _("M3U file|*.m3u"),
+                     showPlaylistSaveCB, kSAVE );
+}
+
+
 void Dialogs::showFileSimple( bool play )
 {
     if( m_pProvider && m_pProvider->pf_show_dialog )