]> git.sesse.net Git - vlc/commitdiff
* skins2: new "playlist.load()" and "playlist.save()" actions
authorOlivier Teulière <ipkiss@videolan.org>
Wed, 25 Aug 2004 21:32:15 +0000 (21:32 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Wed, 25 Aug 2004 21:32:15 +0000 (21:32 +0000)
modules/gui/skins2/commands/cmd_change_skin.cpp
modules/gui/skins2/commands/cmd_change_skin.hpp
modules/gui/skins2/commands/cmd_dialogs.hpp
modules/gui/skins2/commands/cmd_playlist.cpp
modules/gui/skins2/commands/cmd_playlist.hpp
modules/gui/skins2/parser/interpreter.cpp
modules/gui/skins2/src/dialogs.cpp
modules/gui/skins2/src/dialogs.hpp
modules/gui/skins2/src/skin_main.cpp
modules/gui/skins2/src/top_window.cpp

index 65a487298ce54e86cfabccff0652c75cec87817f..bf83d545b7d4377b83ea10897ad4d72fdfd74831 100644 (file)
@@ -2,7 +2,7 @@
  * cmd_change_skin.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: cmd_change_skin.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -28,6 +28,7 @@
 #include "../src/os_loop.hpp"
 #include "../src/theme.hpp"
 #include "../src/theme_loader.hpp"
+#include "../src/window_manager.hpp"
 
 
 void CmdChangeSkin::execute()
index 8be56c308096e41dc16ff35d5797aa7c9323cef5..0e0b4fdf51fff06a86c695a05c486f81dfbb0f9d 100644 (file)
@@ -2,7 +2,7 @@
  * cmd_change_skin.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: cmd_change_skin.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -28,9 +28,6 @@
 #include "cmd_generic.hpp"
 
 
-class WindowManager;
-
-
 /// "Change Skin" command
 class CmdChangeSkin: public CmdGeneric
 {
index 716fa856748c6f1852f2d8901b992337d1bfc672..23552e32a076c8ed24bfd5be8c1a9b50ae89a8e2 100755 (executable)
@@ -2,7 +2,7 @@
  * cmd_dialogs.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: cmd_dialogs.hpp,v 1.2 2004/02/01 14:44:11 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -44,6 +44,8 @@ typedef CmdDialogs<8> CmdDlgFileInfo;
 typedef CmdDialogs<9> CmdDlgShowPopupMenu;
 typedef CmdDialogs<10> CmdDlgHidePopupMenu;
 typedef CmdDialogs<11> CmdDlgAdd;
+typedef CmdDialogs<12> CmdDlgPlaylistLoad;
+typedef CmdDialogs<13> CmdDlgPlaylistSave;
 
 
 /// Generic "Open dialog" command
@@ -99,6 +101,12 @@ class CmdDialogs: public CmdGeneric
                 case 11:
                     pDialogs->showFile( false );
                     break;
+                case 12:
+                    pDialogs->showPlaylistLoad();
+                    break;
+                case 13:
+                    pDialogs->showPlaylistSave();
+                    break;
                 default:
                     msg_Warn( getIntf(), "Unknown dialog type" );
                     break;
index 04a9afb6987de5e321f2f5e4b85cf28020e9fe0e..781243eef901795ec33e45a7ef3c635699d78400 100755 (executable)
@@ -100,3 +100,25 @@ void CmdPlaylistRepeat::execute()
     }
 }
 
+
+void CmdPlaylistLoad::execute()
+{
+    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
+    if( pPlaylist != NULL )
+    {
+        playlist_Import( pPlaylist, m_file.c_str() );
+    }
+}
+
+
+void CmdPlaylistSave::execute()
+{
+    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
+    if( pPlaylist != NULL )
+    {
+        // FIXME: when the PLS export will be working, we'll need to remove
+        // this hardcoding...
+        playlist_Export( pPlaylist, m_file.c_str(), "export-m3u" );
+    }
+}
+
index 2f567217140ab6178571960e5d065b2e43c42bc2..1d5ff74f30b225bfe7025c3c8d5d444d16fc4474 100755 (executable)
@@ -119,4 +119,44 @@ class CmdPlaylistRepeat: public CmdGeneric
 };
 
 
+/// Command to load a playlist
+class CmdPlaylistLoad: public CmdGeneric
+{
+    public:
+        CmdPlaylistLoad( intf_thread_t *pIntf, const string& rFile ):
+            CmdGeneric( pIntf ), m_file( rFile ) {}
+        virtual ~CmdPlaylistLoad() {}
+
+        /// This method does the real job of the command
+        virtual void execute();
+
+        /// Return the type of the command
+        virtual string getType() const { return "playlist load"; }
+
+    private:
+        /// Playlist file to load
+        string m_file;
+};
+
+
+/// Command to save a playlist
+class CmdPlaylistSave: public CmdGeneric
+{
+    public:
+        CmdPlaylistSave( intf_thread_t *pIntf, const string& rFile ):
+            CmdGeneric( pIntf ), m_file( rFile ) {}
+        virtual ~CmdPlaylistSave() {}
+
+        /// This method does the real job of the command
+        virtual void execute();
+
+        /// Return the type of the command
+        virtual string getType() const { return "playlist save"; }
+
+    private:
+        /// Playlist file to save
+        string m_file;
+};
+
+
 #endif
index ddf65f77a536c05f69fe75fce0551ff6f3a9e832..5f75b8ebae7dc6299e9853db2f3cce868088883b 100644 (file)
@@ -55,6 +55,8 @@ Interpreter::Interpreter( intf_thread_t *pIntf ): SkinObject( pIntf )
     REGISTER_CMD( "dialogs.prefs()", CmdDlgPrefs )
     REGISTER_CMD( "dialogs.fileInfo()", CmdDlgFileInfo )
     REGISTER_CMD( "dialogs.popup()", CmdDlgShowPopupMenu )
+    REGISTER_CMD( "playlist.load()", CmdDlgPlaylistLoad )
+    REGISTER_CMD( "playlist.save()", CmdDlgPlaylistSave )
     REGISTER_CMD( "playlist.add()", CmdDlgAdd )
     VarList &rVar = VlcProc::instance( getIntf() )->getPlaylistVar();
     m_commandMap["playlist.del()"] =
index c6900ed7ea54c1bed80698807fabe7875cd2efd6..3d4f1c46a41ec30d8b7ab6c4f8971beea9b03fc0 100644 (file)
 #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,8 +39,8 @@ 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 );
@@ -57,6 +58,42 @@ 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 )
@@ -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,12 +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->psz_title = strdup( _("Open a skin file") );
-        p_arg->psz_extensions =
-            strdup( _("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|") );
+        p_arg->psz_title = strdup( rTitle.c_str() );
+        p_arg->psz_extensions = strdup( rExtensions.c_str() );
+
+        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 );
@@ -180,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 )
index e8ffcbdf453448e0afd91713cda48a5876050b8e..30f8d4adc75e50810e97a616355adc3a5354fbea 100644 (file)
@@ -2,7 +2,7 @@
  * dialogs.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: dialogs.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
 class Dialogs: public SkinObject
 {
     public:
-        /// Get the instance of Dialogs.
+        /// Get the instance of Dialogs
         /// Returns NULL if initialization failed
         static Dialogs *instance( intf_thread_t *pIntf );
 
         /// Delete the instance of Dialogs
         static void destroy( intf_thread_t *pIntf );
 
-        /// Show the Change Skin dialog.
+        /// Show the Change Skin dialog
         void showChangeSkin();
 
+        /// Show the Load Playlist dialog
+        void showPlaylistLoad();
+
+        /// Show the Save Playlist dialog
+        void showPlaylistSave();
+
         /// Show the Quick Open File dialog.
         /// If play is false, just add the item in the playlist
         void showFileSimple( bool play );
 
-        /// Show the Open File dialog.
+        /// Show the Open File dialog
         /// If play is false, just add the item in the playlist
         void showFile( bool play );
 
@@ -71,28 +77,43 @@ class Dialogs: public SkinObject
         /// Show the popup menu
         void showPopupMenu( bool bShow );
 
-        // XXX: This is a kludge! In fact, the file name retrieved when
-        // changing the skin should be returned directly to the command, but
-        // the dialog provider mechanism doesn't allow it.
-        /// Store temporarily a file name
-        void setThemeFile( const string &themeFile ) { m_theme = themeFile; }
-        /// Get a previously saved file name
-        const string &getThemeFile() const { return m_theme; }
-
     private:
         // Private because it's a singleton
         Dialogs( intf_thread_t *pIntf );
         ~Dialogs();
 
+        /// DlgCallback is the type of the callbacks of the open/save dialog
+        typedef void DlgCallback( intf_dialog_args_t *pArg );
+
+        /// Possible flags for the open/save dialog
+        typedef enum
+        {
+            kOPEN     = 0x01,
+            kSAVE     = 0x02,
+            kMULTIPLE = 0x04
+        } flags_t;
+
         /// Initialization method
         bool init();
 
+        /// Show a generic open/save dialog, initialized with the given
+        /// parameters
+        /// The 'flags' parameter is a logical or of the flags_t values
+        void showFileGeneric( const string &rTitle, const string &rExtensions,
+                              DlgCallback callback, int flags );
+
+        /// Callback for the Change Skin dialog
+        static void showChangeSkinCB( intf_dialog_args_t *pArg );
+
+        /// Callback for the Load Playlist dialog
+        static void showPlaylistLoadCB( intf_dialog_args_t *pArg );
+
+        /// Callback for the Save Playlist dialog
+        static void showPlaylistSaveCB( intf_dialog_args_t *pArg );
+
         /// Dialogs provider module
         intf_thread_t *m_pProvider;
         module_t *m_pModule;
-
-        /// Name of a theme file, obtained via the ChangeSkin dialog
-        string m_theme;
 };
 
 
index c28ba1bf105524681a2b61c62b981d4a0d8a1e95..5283b60e205cdc5c559c21ccbeac8250603c0059 100644 (file)
@@ -35,6 +35,7 @@
 #include "../parser/interpreter.hpp"
 #include "../commands/async_queue.hpp"
 #include "../commands/cmd_quit.hpp"
+#include "../commands/cmd_dialogs.hpp"
 
 
 //---------------------------------------------------------------------------
@@ -198,10 +199,11 @@ static void Run( intf_thread_t *p_intf )
         if( it == resPath.end() )
         {
             // Last chance: the user can select a new theme file
-            Dialogs *pDialogs = Dialogs::instance( p_intf );
-            if( pDialogs )
+            if( Dialogs::instance( p_intf ) )
             {
-                pDialogs->showChangeSkin();
+                CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
+                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
+                pQueue->push( CmdGenericPtr( pCmd ) );
             }
             else
             {
index 10f1145fa4da17aa838d10ac9a52c5c972a9302c..f1627c90004c225c0b4683fdf9f2c7e10dd3e97e 100644 (file)
@@ -28,9 +28,9 @@
 #include "os_window.hpp"
 #include "os_factory.hpp"
 #include "theme.hpp"
-#include "dialogs.hpp"
 #include "var_manager.hpp"
 #include "../commands/cmd_on_top.hpp"
+#include "../commands/cmd_dialogs.hpp"
 #include "../controls/ctrl_generic.hpp"
 #include "../events/evt_enter.hpp"
 #include "../events/evt_focus.hpp"
@@ -183,20 +183,17 @@ void TopWindow::processEvent( EvtKey &rEvtKey )
     // Only do the action when the key is down
     if( rEvtKey.getAsString().find( "key:down") != string::npos )
     {
-        //XXX not to be hardcoded !
+        //XXX not to be hardcoded!
         // Ctrl-S = Change skin
         if( (rEvtKey.getMod() & EvtInput::kModCtrl) &&
             rEvtKey.getKey() == 's' )
         {
-            Dialogs *pDialogs = Dialogs::instance( getIntf() );
-            if( pDialogs != NULL )
-            {
-                pDialogs->showChangeSkin();
-            }
+            CmdDlgChangeSkin cmd( getIntf() );
+            cmd.execute();
             return;
         }
 
-        //XXX not to be hardcoded !
+        //XXX not to be hardcoded!
         // Ctrl-T = Toggle on top
         if( (rEvtKey.getMod() & EvtInput::kModCtrl) &&
             rEvtKey.getKey() == 't' )