diff options
author | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-07-09 12:22:00 +0000 |
---|---|---|
committer | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-07-09 12:22:00 +0000 |
commit | e6ea7cc8e5a2af383f6e90c700dd3a00aa8c84ed (patch) | |
tree | 8740575ffa70fe058623374ebbae464ad940b552 | |
parent | 3a022772f759a5db8100bb04393c6aef5c1579bb (diff) | |
download | vdr-plugin-muggle-e6ea7cc8e5a2af383f6e90c700dd3a00aa8c84ed.tar.gz vdr-plugin-muggle-e6ea7cc8e5a2af383f6e90c700dd3a00aa8c84ed.tar.bz2 |
Untested extensions for exporting plalists
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@102 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | mg_playlist.c | 31 | ||||
-rw-r--r-- | mg_playlist.h | 9 | ||||
-rw-r--r-- | muggle.c | 30 | ||||
-rw-r--r-- | muggle.h | 13 | ||||
-rw-r--r-- | vdr_menu.c | 117 | ||||
-rw-r--r-- | vdr_menu.h | 21 |
6 files changed, 183 insertions, 38 deletions
diff --git a/mg_playlist.c b/mg_playlist.c index f6387b0..19e24d5 100644 --- a/mg_playlist.c +++ b/mg_playlist.c @@ -2,10 +2,10 @@ * \file mg_playlist.c * \brief defines functions to be executed on playlists for the vdr muggle plugindatabase * - * \version $Revision: 1.2 $ - * \date $Date: 2004/05/28 15:29:18 $ + * \version $Revision: 1.3 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: lvw $ + * \author Responsible author: $Author: LarsAC $ * * This file implements the class mgPlaylist which maintains a playlist * and supports editing (e.g. adding or moving tracks), navigating it @@ -207,3 +207,28 @@ mgContentItem* mgPlaylist::sneakNext() } } +bool mgPlaylist::exportM3U( const char *m3u_file ) +{ + vector<mgContentItem*>::iterator iter; + bool result = true; + + // open a file for writing + FILE *listfile = fopen( m3u_file, "w" ); + + if( !listfile ) + { + return false; + } + + fprintf( listfile, "#EXTM3U" ); + + for( iter = m_list.begin(); iter != m_list.end(); iter++ ) + { // each item in the list + fprintf( listfile, "#EXTINF:0,%s", (*iter)->getLabel().c_str() ); + fprintf( listfile, "%s", (*iter)->getSourceFile().c_str() ); + } + + fclose( listfile ); + + return result; +} diff --git a/mg_playlist.h b/mg_playlist.h index caf3cdc..aaac699 100644 --- a/mg_playlist.h +++ b/mg_playlist.h @@ -2,10 +2,10 @@ * \file mg_playlist.c * \brief defines functions to be executed on playlists for the vdr muggle plugindatabase * - * \version $Revision: 1.3 $ - * \date $Date: 2004/07/06 00:20:51 $ + * \version $Revision: 1.4 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: MountainMan $ + * \author Responsible author: $Author: LarsAC $ * * This file implements the class mgPlaylist which maintains a playlist * and supports editing (e.g. adding or moving tracks), navigating it @@ -139,6 +139,9 @@ public: //! \brief obtain the next item without skipping the current position virtual mgContentItem* sneakNext(); virtual bool storePlaylist()=0; + + //! \brief export the playlist in m3u format + virtual void exportM3U( const char *m3u_file ); }; #endif @@ -2,16 +2,18 @@ * \file muggle.c * \brief Implements a plugin for browsing media libraries within VDR * - * \version $Revision: 1.7 $ - * \date $Date: 2004/05/28 15:29:18 $ + * \version $Revision: 1.8 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: lvw $ + * \author Responsible author: $Author: LarsAC $ * - * $Id: muggle.c,v 1.7 2004/05/28 15:29:18 lvw Exp $ + * $Id: muggle.c,v 1.8 2004/07/09 12:22:00 LarsAC Exp $ */ #include <getopt.h> +#include <config.h> + #include "muggle.h" #include "vdr_menu.h" @@ -140,12 +142,27 @@ bool mgMuggle::Start(void) { // Start any background activities the plugin shall perform. mgSetDebugLevel( 99 ); - RegisterI18n( Phrases ); + + // Database initialization m_media = new mgMedia( mgMedia::GD_MP3 ); m_root = m_media->getSelectionRoot(); m_playlist = m_media->createTemporaryPlaylist(); m_media->initFilterSet(); + + // Read commands for playlists in etc. /video/muggle/playlist_commands.conf + m_playlist_cmds = new cCommands(); + + char *cmd_file = AddDirectory( cPlugin::ConfigDirectory("muggle"), "playlist_commands.conf" ); + bool have_cmd_file = m_playlist_cmds->Load( cmd_file ); + free( cmd_file ); + + if( !have_cmd_file ) + { + delete m_playlist_cmds; + m_playlist_cmds = NULL; + } + return true; } @@ -157,7 +174,8 @@ void mgMuggle::Housekeeping(void) cOsdObject *mgMuggle::MainMenuAction(void) { // Perform the action when selected from the main VDR menu. - cOsdObject* osd = new mgMainMenu( m_media, m_root, m_playlist ); + cOsdObject* osd = new mgMainMenu( m_media, m_root, m_playlist, + m_playlist_commands ); return osd; } @@ -2,12 +2,12 @@ * \file muggle.h * \brief Implements a plugin for browsing media libraries within VDR * - * \version $Revision: 1.5 $ - * \date $Date: 2004/05/28 15:29:18 $ + * \version $Revision: 1.6 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author file owner: $Author: lvw $ + * \author file owner: $Author: LarsAC $ * - * $Id: muggle.h,v 1.5 2004/05/28 15:29:18 lvw Exp $ + * $Id: muggle.h,v 1.6 2004/07/09 12:22:00 LarsAC Exp $ */ #ifndef _MUGGLE_H @@ -19,6 +19,8 @@ class mgMedia; class mgSelectionTreeNode; class mgPlaylist; +class cCommands; + class mgMuggle : public cPlugin { public: @@ -54,7 +56,8 @@ private: mgMedia *m_media; mgSelectionTreeNode *m_root; mgPlaylist *m_playlist; - + cCommands *m_playlist_commands; + }; #endif @@ -2,12 +2,12 @@ * \file vdr_menu.c * \brief Implements menu handling for browsing media libraries within VDR * - * \version $Revision: 1.22 $ - * \date $Date: 2004/07/06 00:20:51 $ + * \version $Revision: 1.23 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: MountainMan $ + * \author Responsible author: $Author: LarsAC $ * - * $Id: vdr_menu.c,v 1.22 2004/07/06 00:20:51 MountainMan Exp $ + * $Id: vdr_menu.c,v 1.23 2004/07/09 12:22:00 LarsAC Exp $ */ #include <string> @@ -55,8 +55,10 @@ void mgMenuTreeItem::Set() // ----------------------- mgMainMenu ---------------------- -mgMainMenu::mgMainMenu(mgMedia *media, mgSelectionTreeNode *root, mgPlaylist *playlist) - : cOsdMenu( "" ), m_media(media), m_root(root), m_current_playlist(playlist) +mgMainMenu::mgMainMenu(mgMedia *media, mgSelectionTreeNode *root, + mgPlaylist *playlist, cCommands playlist_commands) + : cOsdMenu( "" ), m_media(media), m_root(root), + m_current_playlist(playlist), m_playlist_commands(playlist_commands) { mgDebug( 1, "Creating Muggle Main Menu" ); @@ -324,8 +326,9 @@ eOSState mgMainMenu::ProcessKey(eKeys key) // load the selected playlist m_current_playlist -> clear(); - string selected = (*m_plists)[Current()]; - m_current_playlist = m_media->loadPlaylist(selected.c_str()); + string selected = (*m_plists)[ Current() ]; + m_current_playlist = m_media->loadPlaylist( selected.c_str() ); + // clean the list of playlist m_plists->clear(); m_last_osd_index =0; @@ -372,6 +375,19 @@ eOSState mgMainMenu::ProcessKey(eKeys key) state = osContinue; } break; } + else if( m_state == PLAYLIST_COMMANDS ) + { + if( state == osUnknown ) + { + switch( key ) + { + kOk: + { + state = Execute(); + } + } + } + } } else if( state == osBack ) { @@ -603,11 +619,9 @@ void mgMainMenu::LoadPlaylist() for(vector<string>::iterator iter = m_plists->begin(); iter != m_plists->end() ; iter++) - { - + { Add( new cOsdItem( iter->c_str() ) ); } - Display(); } @@ -644,10 +658,73 @@ void mgMainMenu::DisplayPlaylistSubmenu() Add( new cOsdItem( "3 - Rename playlist" ) ); Add( new cOsdItem( "4 - Clear playlist" ) ); Add( new cOsdItem( "5 - Remove entry from list" ) ); + Add( new cOsdItem( "6 - Export playlist" ) ); + + if( m_playlist_commands ) + { + Add( new cOsdItem( "7 - External playlist commands" ) ); + } Display(); } +void mgMainMenu::DisplayPlaylistCommands() +{ + m_state = PLAYLIST_COMMANDS; + + cCommand *command; + int i = 0; + + Clear(); + SetTitle( "Muggle - External Playlist Commands" ); + + while( ( command = m_playlist_commands->Get(i) ) != NULL ) + { + Add( new cOsdItem( hk( command->Title() ) ) ); + i++; + } + + Display(); +} + +eOSState cMenuCommands::ExecutePlaylistCommand( int current, char *parameters ) +{ + cCommand *command = m_playlist_commands->Get( current ); + if( command ) + { + char *buffer = NULL; + bool confirmed = true; + if( command->Confirm() ) + { + asprintf( &buffer, "%s?", command->Title() ); + confirmed = Interface->Confirm( buffer ); + free( buffer ); + } + if( confirmed ) + { + asprintf( &buffer, "%s...", command->Title() ); + Interface->Status( buffer ); + Interface->Flush(); + free( buffer ); + + char *tmp_m3u_file = AddDirectory( cPlugin::ConfigDirectory("muggle"), "current.m3u" ); + m_current_playlist->exportM3U( tmp_m3u_file ); + free( tmp_m3u_file ); + + const char *result = command->Execute( tmp_m3u_file ); + + /* What to do? Recode cMenuText (not much)? + if( result ) + { + return AddSubMenu( new cMenuText( command->Title(), result ) ); + } + */ + return osEnd; + } + } + return osContinue; +} + eOSState mgMainMenu::PlaylistSubmenuAction( int n ) { cout << "mgMainMenu::PlaylistSubmenuAction: " << n << endl << flush; @@ -659,10 +736,11 @@ eOSState mgMainMenu::PlaylistSubmenuAction( int n ) { LoadPlaylist(); Interface->Flush(); + + // jump to playlist view from here? } break; case 1: - { - + { SavePlaylist(); Interface->Status( "Playlist saved"); Interface->Flush(); @@ -700,6 +778,16 @@ eOSState mgMainMenu::PlaylistSubmenuAction( int n ) Interface->Status( "Entry removed" ); Interface->Flush(); } + case 5: + { + char *m3u_file = AddDirectory( cPlugin::ConfigDirectory("muggle"), m_current_playlist->getListname() ); + m_current_playlist->exportM3U( m3u_file ); + free( m3u_file ); + } + case 6: + { + DisplayPlaylistCommands(); + } default: { // undefined action @@ -818,6 +906,9 @@ void mgMainMenu::Play(mgPlaylist *plist) /************************************************************ * * $Log: vdr_menu.c,v $ + * Revision 1.23 2004/07/09 12:22:00 LarsAC + * Untested extensions for exporting plalists + * * Revision 1.22 2004/07/06 00:20:51 MountainMan * loading and saving playlists * @@ -2,12 +2,12 @@ * \file vdr_menu.h * \brief Implements menu handling for broswing media libraries within VDR * - * \version $Revision: 1.11 $ - * \date $Date: 2004/07/06 00:20:51 $ + * \version $Revision: 1.12 $ + * \date $Date: 2004/07/09 12:22:00 $ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: MountainMan $ + * \author Responsible author: $Author: LarsAC $ * - * $Id: vdr_menu.h,v 1.11 2004/07/06 00:20:51 MountainMan Exp $ + * $Id: vdr_menu.h,v 1.12 2004/07/09 12:22:00 LarsAC Exp $ */ #ifndef _VDR_MENU_H @@ -17,8 +17,7 @@ #include <vector> #include <osd.h> - -#include "i18n.h" +#include <config.h> #include "i18n.h" @@ -53,7 +52,8 @@ class mgMainMenu : public cOsdMenu { public: - mgMainMenu(mgMedia *media, mgSelectionTreeNode *root, mgPlaylist *playlist); + mgMainMenu(mgMedia *media, mgSelectionTreeNode *root, + mgPlaylist *playlist, cCommands playlist_commands ); mgSelectionTreeNode *CurrentNode(); mgMenuTreeItem *CurrentItem(); @@ -66,7 +66,7 @@ class mgMainMenu : public cOsdMenu { TREE, TREE_SUBMENU, PLAYLIST, LOAD_PLAYLIST, SAVE_PLAYLIST, - PLAYLIST_SUBMENU, + PLAYLIST_SUBMENU, PLAYLIST_COMMANDS, FILTER, FILTER_SUBMENU }; @@ -108,6 +108,8 @@ class mgMainMenu : public cOsdMenu MuggleStatus m_state; std::list<int> m_history; + cCommands m_playlist_commands; + int m_last_osd_index; }; @@ -116,6 +118,9 @@ class mgMainMenu : public cOsdMenu /************************************************************ * * $Log: vdr_menu.h,v $ + * Revision 1.12 2004/07/09 12:22:00 LarsAC + * Untested extensions for exporting plalists + * * Revision 1.11 2004/07/06 00:20:51 MountainMan * loading and saving playlists * |