summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b>2004-10-26 14:39:20 +0000
committerlvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b>2004-10-26 14:39:20 +0000
commit3da32e2a7187e9a842f4b6d5299d621db1855f68 (patch)
tree69538a34082686e54c02801054e89ff8de8f7126
parentc0be06a6d528738699a41bcf5fd7ee9fb68a78fd (diff)
downloadvdr-plugin-muggle-3da32e2a7187e9a842f4b6d5299d621db1855f68.tar.gz
vdr-plugin-muggle-3da32e2a7187e9a842f4b6d5299d621db1855f68.tar.bz2
Added a function to store a plalist under a different name
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@247 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--gd_content_interface.c161
-rw-r--r--gd_content_interface.h5
-rw-r--r--mg_playlist.h3
3 files changed, 114 insertions, 55 deletions
diff --git a/gd_content_interface.c b/gd_content_interface.c
index 57a3f67..987bd70 100644
--- a/gd_content_interface.c
+++ b/gd_content_interface.c
@@ -26,7 +26,6 @@
#include "i18n.h"
-
#define GD_PLAYLIST_TYPE 0 //< listtype for giant disc db
// some dummies to keep the compiler happy
@@ -706,63 +705,115 @@ int GdPlaylist::insertDataFromSQL()
bool GdPlaylist::storePlaylist()
{
- std::vector<mgContentItem*>::iterator iter;
- int num;
- MYSQL_RES *result;
- MYSQL_ROW row;
- int nrows;
+ std::vector<mgContentItem*>::iterator iter;
+ int num;
+ MYSQL_RES *result;
+ MYSQL_ROW row;
+ int nrows;
+
+ if( m_listname == " " )
+ {
+ mgWarning("Can not store Tracklist without name");
+ return false;
+ }
+
+ 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 the new 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]);
+ }
+ }
- if( m_listname == " " )
- {
- mgWarning("Can not store Tracklist without name");
- return false;
- }
+ // 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=\"%d\", trackid=\"%d\", playlist=%d",
+ num, (*iter)->getId(), m_sqlId);
+ }
+ return true;
+}
- if(m_sqlId >= 0)
- {
- // playlist alreay exists in SQL database
- // remove old items first
- // cout << " GdPlaylist::storePlaylist: removing items from " << m_sqlId << flush;
+bool GdPlaylist::storeAs( std::string name )
+{
+ int id;
- // 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=\"%d\", trackid=\"%d\", playlist=%d",
- num, (*iter)->getId(), m_sqlId);
- }
- return true;
+ result = mgSqlReadQuery( &m_db,
+ "SELECT id FROM playlist WHERE title=\"current\"" );
+
+ if( mysql_num_rows(result) )
+ {
+ MYSQL row = mysql_fetch_row( result );
+ }
+ else
+ {
+ // otherwise create a new database entry
+ mgSqlWriteQuery( &m_db, "INSERT into playlist SET "
+ "title=\"%s\", author=\"VDR\"",
+ name.c_str() )
+
+ // now read the new list to get the id
+ result = mgSqlReadQuery( &m_db,
+ "SELECT id,author FROM playlist where title=\"current\"");
+
+ nrows = mysql_num_rows(result);
+ row = mysql_fetch_row(result);
+ }
+
+ if( sscanf( row [0], "%d", &id ) !=1 )
+ {
+ mgError("Invalid id '%s' in database", row [5]);
+ }
+ else
+ {
+ // now we know that the playlist 'name' has identifier id
+
+ // remove old playlist items from db
+ mgSqlWriteQuery( &m_db,
+ "DELETE FROM playlistitem WHERE playlist = %d",
+ id );
+
+ // 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=\"%d\", trackid=\"%d\", playlist=%d",
+ num, (*iter)->getId(), m_sqlId);
+ }
+ }
}
/*!
diff --git a/gd_content_interface.h b/gd_content_interface.h
index 921f8d7..8823799 100644
--- a/gd_content_interface.h
+++ b/gd_content_interface.h
@@ -435,6 +435,11 @@ class GdPlaylist : public mgPlaylist
*/
bool storePlaylist();
+ /*!
+ * \brief store playlist under a different name
+ */
+ bool storeAs( std::string name );
+
private:
/*!
diff --git a/mg_playlist.h b/mg_playlist.h
index bdffd0c..060ebfa 100644
--- a/mg_playlist.h
+++ b/mg_playlist.h
@@ -142,6 +142,9 @@ public:
//! \brief make playlist persistent
virtual bool storePlaylist() = 0;
+ //! \brief make playlist persistent under a different name
+ virtual bool storeAs( std::string name ) = 0;
+
//! \brief obtain length of content already played
unsigned long getCompletedLength();