summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMountainMan <MountainMan@e10066b5-e1e2-0310-b819-94efdf66514b>2004-07-06 00:20:51 +0000
committerMountainMan <MountainMan@e10066b5-e1e2-0310-b819-94efdf66514b>2004-07-06 00:20:51 +0000
commit3a022772f759a5db8100bb04393c6aef5c1579bb (patch)
treed324f1c481643118cdfee146764cdab079582dfc
parentb75e54f2120bd2def70ba18ee4b79f147dcda4dc (diff)
downloadvdr-plugin-muggle-3a022772f759a5db8100bb04393c6aef5c1579bb.tar.gz
vdr-plugin-muggle-3a022772f759a5db8100bb04393c6aef5c1579bb.tar.bz2
loading and saving playlists
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@101 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--gd_content_interface.c118
-rw-r--r--gd_content_interface.h18
-rw-r--r--mg_playlist.h9
-rw-r--r--vdr_menu.c103
-rw-r--r--vdr_menu.h19
5 files changed, 184 insertions, 83 deletions
diff --git a/gd_content_interface.c b/gd_content_interface.c
index 9c339d6..874159e 100644
--- a/gd_content_interface.c
+++ b/gd_content_interface.c
@@ -1,10 +1,10 @@
/*! \file content_interface.cpp
* \brief Data Objects for content (e.g. mp3 files, movies) for the vdr muggle plugindatabase
*
- * \version $Revision: 1.22 $
- * \date $Date: 2004/05/28 15:29:18 $
+ * \version $Revision: 1.23 $
+ * \date $Date: 2004/07/06 00:20:51 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author Responsible author: $Author: lvw $
+ * \author Responsible author: $Author: MountainMan $
*
* Implements main classes of for content items and interfaces to SQL databases
*
@@ -709,6 +709,19 @@ GdPlaylist::GdPlaylist(string listname, MYSQL db_handle)
""); // creates current time as timestamp
m_author = "VDR";
m_listname = listname;
+
+ // now read thenew list to get the id
+ result=mgSqlReadQuery(&m_db,
+ "SELECT id,author FROM playlist where title=\"%s\"",
+ listname.c_str());
+ nrows = mysql_num_rows(result);
+ row = mysql_fetch_row(result);
+
+ if(sscanf(row [0], "%d", & m_sqlId) !=1)
+ {
+ mgError("Invalid id '%s' in database", row [5]);
+ }
+
}
else // playlist exists, read data
{
@@ -730,51 +743,6 @@ GdPlaylist::GdPlaylist(string listname, MYSQL db_handle)
/*!
*****************************************************************************
- * \brief Constructor: construct playlist object from existing sql playlist
- *
- * \param sql_identifier: sql internal identifier for the playlist
- * \param db_handl database which stores the playlist
- *
- * This constructor is typically used when a playlist is selected from an
- * internal list of playlists
- ****************************************************************************/
-GdPlaylist::GdPlaylist(unsigned int sql_identifier, MYSQL db_handle)
-{
- MYSQL_RES *result;
- int nrows;
-
- m_db = db_handle;
-
- // check, if the database really exists
- result = mgSqlReadQuery(&m_db,
- "SELECT title,author FROM playlist where id=%d",
- sql_identifier);
- nrows = mysql_num_rows(result);
- if(nrows == 0)
- {
- mgDebug(3, "No playlist with id %d found. Creating new playlist\n",
- sql_identifier);
-
- // create new database entry
- // DUMMY
- }
- else // playlist exists, read data
- {
- MYSQL_ROW row;
- row = mysql_fetch_row(result);
-
- m_listname = row[0];
- m_author = row[1];
- m_sqlId = sql_identifier;
- // now read all entries of the playlist and
- // write them into the tracklist
- insertDataFromSQL();
- }
- m_listtype = GD_PLAYLIST_TYPE; // GiantDB list type for playlists
-}
-
-/*!
- *****************************************************************************
* \brief empty destructor
*
* Nothing to be done. Constructor of parent class takes care
@@ -783,7 +751,11 @@ GdPlaylist::~GdPlaylist()
{
}
-
+void GdPlaylist::setListname(std::string name)
+{
+ m_listname = name;
+ m_sqlId = -1;
+}
/*!
*****************************************************************************
* \brief reads the track list from the sql database into a locallist
@@ -820,26 +792,55 @@ bool GdPlaylist::storePlaylist()
{
vector<mgContentItem*>::iterator iter;
int num;
+ MYSQL_RES *result;
+ MYSQL_ROW row;
+ int nrows;
- if(m_listname =="")
+ if(m_listname ==" ")
{
mgWarning("Can not store Tracklist without name");
return false;
}
- // remove old playlist items from db
- mgSqlWriteQuery(&m_db,
- "DELETE FROM playlistitem WHERE playlist = %d",
- m_sqlId);
-
+ if(m_sqlId >= 0)
+ {
+ // playlist alreay exists in SQL database
+ // remove old items first
+ cout << " GdPlaylist::storePlaylist: removing items from " << m_sqlId << flush;
+ // remove old playlist items from db
+ mgSqlWriteQuery(&m_db,
+ "DELETE FROM playlistitem WHERE playlist = %d",
+ m_sqlId);
+ }
+ else
+ {
+ // create new database entry
+ mgSqlWriteQuery(&m_db, "INSERT into playlist "
+ "SET title=\"%s\", author=\"%s\"",
+ m_listname.c_str(),
+ "VDR", // default author
+ ""); // creates current time as timestamp
+ m_author = "VDR";
+
+ // now read thenew list to get the id
+ result=mgSqlReadQuery(&m_db,
+ "SELECT id,author FROM playlist where title=\"%s\"",
+ m_listname.c_str());
+ nrows = mysql_num_rows(result);
+ row = mysql_fetch_row(result);
+
+ if(sscanf(row [0], "%d", & m_sqlId) !=1)
+ {
+ mgError("Invalid id '%s' in database", row [5]);
+ }
+ }
// add new playlist items to db
for(iter= m_list.begin(), num=0; iter != m_list.end(); iter++, num++)
{
-
mgSqlWriteQuery(&m_db,
"INSERT into playlistitem "
- "SET tracknumber=\"%s\", trackid=\"%s\", playlist=%d",
+ "SET tracknumber=\"%d\", trackid=\"%d\", playlist=%d",
num, (*iter)->getId(), m_sqlId);
}
return true;
@@ -1391,6 +1392,9 @@ mgContentItem* GdTreeNode::getSingleTrack()
/* -------------------- begin CVS log ---------------------------------
* $Log: gd_content_interface.c,v $
+ * Revision 1.23 2004/07/06 00:20:51 MountainMan
+ * loading and saving playlists
+ *
* Revision 1.22 2004/05/28 15:29:18 lvw
* Merged player branch back on HEAD branch.
*
diff --git a/gd_content_interface.h b/gd_content_interface.h
index 8e95267..491e4b9 100644
--- a/gd_content_interface.h
+++ b/gd_content_interface.h
@@ -3,10 +3,10 @@
* \brief Data objects for content (e.g. mp3 files, movies)
* for the vdr muggle plugin database
*
- * \version $Revision: 1.7 $
- * \date $Date: 2004/05/28 15:29:18 $
+ * \version $Revision: 1.8 $
+ * \date $Date: 2004/07/06 00:20:51 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author Responsible author: $Author: lvw $
+ * \author Responsible author: $Author: MountainMan $
*
* Declares main classes for content items and interfaces to SQL databases
*
@@ -250,15 +250,14 @@ class GdPlaylist : public mgPlaylist
/*==== constructors ====*/
GdPlaylist(std::string listname, MYSQL db_handle);
/* opens existing or creates empty playlist */
-
- GdPlaylist(unsigned int sql_identifier, MYSQL db_handle);
- /* construct from the db by internal id*/
-
+
/*==== destructor ====*/
virtual ~GdPlaylist();
-
+ virtual void setListname(std::string name);
+ /* changes the listname of the playlist (and unset the sql id */
+
int getPlayTime();
/* returns the total duration of all songs in the list in seconds */
@@ -307,6 +306,9 @@ public:
/* -------------------- begin CVS log ---------------------------------
* $Log: gd_content_interface.h,v $
+ * Revision 1.8 2004/07/06 00:20:51 MountainMan
+ * loading and saving playlists
+ *
* Revision 1.7 2004/05/28 15:29:18 lvw
* Merged player branch back on HEAD branch.
*
diff --git a/mg_playlist.h b/mg_playlist.h
index dcec71c..caf3cdc 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.2 $
- * \date $Date: 2004/05/28 15:29:18 $
+ * \version $Revision: 1.3 $
+ * \date $Date: 2004/07/06 00:20:51 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author Responsible author: $Author: lvw $
+ * \author Responsible author: $Author: MountainMan $
*
* This file implements the class mgPlaylist which maintains a playlist
* and supports editing (e.g. adding or moving tracks), navigating it
@@ -116,7 +116,7 @@ public:
*
* \param name - the new name of this list
*/
- void setListname(std::string name);
+ virtual void setListname(std::string name);
//! \brief returns the count of items in the list
int count();
@@ -138,6 +138,7 @@ public:
//! \brief obtain the next item without skipping the current position
virtual mgContentItem* sneakNext();
+ virtual bool storePlaylist()=0;
};
#endif
diff --git a/vdr_menu.c b/vdr_menu.c
index 4545deb..018cbb5 100644
--- a/vdr_menu.c
+++ b/vdr_menu.c
@@ -2,12 +2,12 @@
* \file vdr_menu.c
* \brief Implements menu handling for browsing media libraries within VDR
*
- * \version $Revision: 1.21 $
- * \date $Date: 2004/06/02 19:29:22 $
+ * \version $Revision: 1.22 $
+ * \date $Date: 2004/07/06 00:20:51 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author Responsible author: $Author: lvw $
+ * \author Responsible author: $Author: MountainMan $
*
- * $Id: vdr_menu.c,v 1.21 2004/06/02 19:29:22 lvw Exp $
+ * $Id: vdr_menu.c,v 1.22 2004/07/06 00:20:51 MountainMan Exp $
*/
#include <string>
@@ -313,6 +313,32 @@ eOSState mgMainMenu::ProcessKey(eKeys key)
}
}
}
+ else if( m_state == LOAD_PLAYLIST )
+ {
+ if( state == osUnknown )
+ {
+ switch( key )
+ {
+ case kOk:
+ {
+ // load the selected playlist
+
+ m_current_playlist -> clear();
+ 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;
+ DisplayPlaylist(0);
+ state = osContinue;
+ } break;
+ default:
+ {
+ state = osContinue;
+ };
+ }
+ }
+ }
else if( m_state == PLAYLIST_SUBMENU )
{
if( state == osUnknown )
@@ -561,6 +587,49 @@ void mgMainMenu::DisplayPlaylist( int index_current )
Display();
}
+void mgMainMenu::LoadPlaylist()
+{
+ m_state = LOAD_PLAYLIST;
+ static char titlestr[80];
+
+ // make sure we have a current playlist
+ Clear();
+ SetButtons();
+ sprintf( titlestr, "Muggle - %s %s ",tr("load"), tr("Playlist"));
+ SetTitle( titlestr );
+
+ // retrieve list of available playlists
+ m_plists = m_media->getStoredPlaylists();
+
+ for(vector<string>::iterator iter = m_plists->begin();
+ iter != m_plists->end() ; iter++)
+ {
+
+ Add( new cOsdItem( iter->c_str() ) );
+ }
+
+
+ Display();
+}
+
+void mgMainMenu::SavePlaylist()
+{
+ if(m_current_playlist->getListname() == "")
+ {
+ // create dummy listname with current date and time
+ time_t currentTime = time(NULL);
+ m_current_playlist->setListname(ctime(&currentTime));
+ }
+ m_current_playlist->storePlaylist();
+}
+
+void mgMainMenu::RenamePlaylist()
+{
+ // dummy function. USes current date as name
+ time_t currentTime = time(NULL);
+ m_current_playlist->setListname(ctime(&currentTime));
+}
+
void mgMainMenu::DisplayPlaylistSubmenu()
{
m_state = PLAYLIST_SUBMENU;
@@ -572,8 +641,9 @@ void mgMainMenu::DisplayPlaylistSubmenu()
// Add items
Add( new cOsdItem( "1 - Load playlist" ) );
Add( new cOsdItem( "2 - Save playlist" ) );
- Add( new cOsdItem( "3 - Clear playlist" ) );
- Add( new cOsdItem( "4 - Remove entry from list" ) );
+ Add( new cOsdItem( "3 - Rename playlist" ) );
+ Add( new cOsdItem( "4 - Clear playlist" ) );
+ Add( new cOsdItem( "5 - Remove entry from list" ) );
Display();
}
@@ -587,15 +657,27 @@ eOSState mgMainMenu::PlaylistSubmenuAction( int n )
{
case 0:
{
- Interface->Status( "Load not yet implemented" );
+ LoadPlaylist();
Interface->Flush();
} break;
case 1:
{
- Interface->Status( "Save not yet implemented" );
+
+ SavePlaylist();
+ Interface->Status( "Playlist saved");
Interface->Flush();
} break;
case 2:
+ { // renamer playlist
+ RenamePlaylist();
+
+ // confirmation
+ Interface->Status( "Playlist renamed (dummy)" );
+ Interface->Flush();
+
+ state = osContinue;
+ } break;
+ case 3:
{ // clear playlist
m_current_playlist->clear();
@@ -605,7 +687,7 @@ eOSState mgMainMenu::PlaylistSubmenuAction( int n )
state = osContinue;
} break;
- case 3:
+ case 4:
{ // remove selected title
m_current_playlist->remove( m_last_osd_index );
if( m_last_osd_index > 0 )
@@ -736,6 +818,9 @@ void mgMainMenu::Play(mgPlaylist *plist)
/************************************************************
*
* $Log: vdr_menu.c,v $
+ * Revision 1.22 2004/07/06 00:20:51 MountainMan
+ * loading and saving playlists
+ *
* Revision 1.21 2004/06/02 19:29:22 lvw
* Use asprintf to create messages
*
diff --git a/vdr_menu.h b/vdr_menu.h
index a4a1f7c..43f29d4 100644
--- a/vdr_menu.h
+++ b/vdr_menu.h
@@ -2,18 +2,19 @@
* \file vdr_menu.h
* \brief Implements menu handling for broswing media libraries within VDR
*
- * \version $Revision: 1.10 $
- * \date $Date: 2004/05/28 15:29:19 $
+ * \version $Revision: 1.11 $
+ * \date $Date: 2004/07/06 00:20:51 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author Responsible author: $Author: lvw $
+ * \author Responsible author: $Author: MountainMan $
*
- * $Id: vdr_menu.h,v 1.10 2004/05/28 15:29:19 lvw Exp $
+ * $Id: vdr_menu.h,v 1.11 2004/07/06 00:20:51 MountainMan Exp $
*/
#ifndef _VDR_MENU_H
#define _VDR_MENU_H
#include <list>
+#include <vector>
#include <osd.h>
@@ -64,7 +65,8 @@ class mgMainMenu : public cOsdMenu
enum MuggleStatus
{
TREE, TREE_SUBMENU,
- PLAYLIST, PLAYLIST_SUBMENU,
+ PLAYLIST, LOAD_PLAYLIST, SAVE_PLAYLIST,
+ PLAYLIST_SUBMENU,
FILTER, FILTER_SUBMENU
};
@@ -83,6 +85,9 @@ class mgMainMenu : public cOsdMenu
void DisplayTrackInfo();
void DisplayAlbumInfo();
+ void LoadPlaylist();
+ void SavePlaylist();
+ void RenamePlaylist();
void DisplayPlaylistSubmenu();
eOSState PlaylistSubmenuAction( int n );
@@ -98,6 +103,7 @@ class mgMainMenu : public cOsdMenu
mgSelectionTreeNode *m_root;
mgSelectionTreeNode *m_node;
mgPlaylist *m_current_playlist;
+ std::vector<std::string> *m_plists;
MuggleStatus m_state;
std::list<int> m_history;
@@ -110,6 +116,9 @@ class mgMainMenu : public cOsdMenu
/************************************************************
*
* $Log: vdr_menu.h,v $
+ * Revision 1.11 2004/07/06 00:20:51 MountainMan
+ * loading and saving playlists
+ *
* Revision 1.10 2004/05/28 15:29:19 lvw
* Merged player branch back on HEAD branch.
*