summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b>2004-09-28 13:08:14 +0000
committerlvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b>2004-09-28 13:08:14 +0000
commit24a870f6c1824281711afbc75ed30128353fa6c7 (patch)
tree5a9c6b6aa2301bff508cb7e0b84b2fc58885780b
parentf8aa2ddee993d8873d0baf66c256e06db817d9ea (diff)
downloadvdr-plugin-muggle-24a870f6c1824281711afbc75ed30128353fa6c7.tar.gz
vdr-plugin-muggle-24a870f6c1824281711afbc75ed30128353fa6c7.tar.bz2
Formatting and documentation issues
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@190 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--gd_content_interface.c197
-rw-r--r--mg_filters.h59
-rw-r--r--mg_tools.c26
-rw-r--r--mg_tools.h29
-rwxr-xr-xmugglei.c63
5 files changed, 177 insertions, 197 deletions
diff --git a/gd_content_interface.c b/gd_content_interface.c
index 01e71b2..b805500 100644
--- a/gd_content_interface.c
+++ b/gd_content_interface.c
@@ -65,10 +65,10 @@ vector<string> *GdGetStoredPlaylists(MYSQL db)
result = mgSqlReadQuery(&db, "SELECT title FROM playlist");
- while((row = mysql_fetch_row(result)) != NULL)
- {
+ while( (row = mysql_fetch_row(result) ) != NULL )
+ {
list->push_back(row[0]);
- }
+ }
return list;
}
@@ -311,24 +311,24 @@ bool mgGdTrack::readData()
nfields = mysql_num_fields(result);
if( nrows == 0 )
- {
- mgWarning( "No entries found \n" );
- return false;
- }
+ {
+ mgWarning( "No entries found \n" );
+ return false;
+ }
else
- {
- if( nrows > 1 )
- {
- mgWarning("mgGdTrack::readData: More than one entry found. Using first entry.");
- }
+ {
+ if( nrows > 1 )
+ {
+ mgWarning("mgGdTrack::readData: More than one entry found. Using first entry.");
+ }
MYSQL_ROW row = mysql_fetch_row(result);
-
+
m_artist = row[0];
m_album = row[1];
m_title = row[2];
m_mp3file = string( the_setup.ToplevelDir ) + row[3];
m_genre = row[4];
-
+
if( sscanf( row[5], "%d", &m_year) != 1 )
{
mgError("Invalid year '%s' in database", row [5]);
@@ -542,22 +542,23 @@ GdTracklist::GdTracklist(MYSQL db_handle, string restrictions)
MYSQL_ROW row;
int trackid;
- result = mgSqlReadQuery(&db_handle,
- "SELECT tracks.id "
- " FROM tracks, album, genre WHERE %s"
- " AND album.cddbid=tracks.sourceid "
- " AND genre.id=tracks.genre1",
- restrictions.c_str());
+ result = mgSqlReadQuery( &db_handle,
+ "SELECT tracks.id "
+ " FROM tracks, album, genre WHERE %s"
+ " AND album.cddbid=tracks.sourceid "
+ " AND genre.id=tracks.genre1",
+ restrictions.c_str() );
+
while((row = mysql_fetch_row(result)) != NULL)
- {
- // row[0] is the trackid
- if(sscanf(row[0], "%d", &trackid) != 1)
- {
- mgError("Can not extract integer track id from '%s'",
- row[0]);
- }
- m_list.push_back(new mgGdTrack(trackid, db_handle));
- }
+ {
+ // row[0] is the trackid
+ if(sscanf(row[0], "%d", &trackid) != 1)
+ {
+ mgError("Can not extract integer track id from '%s'",
+ row[0]);
+ }
+ m_list.push_back( new mgGdTrack(trackid, db_handle) );
+ }
}
GdPlaylist::GdPlaylist(string listname, MYSQL db_handle)
@@ -602,8 +603,8 @@ GdPlaylist::GdPlaylist(string listname, MYSQL db_handle)
}
}
- else // playlist exists, read data
- {
+ else
+ { // playlist exists, read data
row = mysql_fetch_row(result);
if(sscanf(row [0], "%d", & m_sqlId) !=1)
@@ -612,10 +613,12 @@ GdPlaylist::GdPlaylist(string listname, MYSQL db_handle)
}
m_author = row[1];
m_listname = listname;
+
// now read allentries of the playlist and
// write them into the tracklist
insertDataFromSQL();
- }// end 'else (playlist exists)
+
+ } // end 'else (playlist exists)
m_listtype = GD_PLAYLIST_TYPE; // GiantDB list type for playlists
}
@@ -643,20 +646,21 @@ int GdPlaylist::insertDataFromSQL()
"SELECT tracknumber, trackid FROM playlistitem "
"WHERE playlist = %d ORDER BY tracknumber",
m_sqlId);
+
nrows = mysql_num_rows(result);
- while((row = mysql_fetch_row(result)) != NULL)
- {
+ while( (row = mysql_fetch_row(result) ) != NULL )
+ {
// add antry to tracklist
if(sscanf(row[1], "%d", &id) !=1)
- {
+ {
mgWarning("Track id '%s' is not an integer. Ignoring \n", row[1]);
- }
+ }
else
- {
+ {
trackptr = new mgGdTrack(id, m_db);
m_list.push_back(trackptr);
- }
- }
+ }
+ }
return nrows;
}
@@ -670,44 +674,44 @@ bool GdPlaylist::storePlaylist()
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);
- }
+ {
+ // 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";
+ {
+ // 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);
+ // 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]);
+ 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++)
@@ -719,11 +723,10 @@ bool GdPlaylist::storePlaylist()
}
return true;
}
+
/*!
- *****************************************************************************
* \brief returns the total duration of all songs in the list in seconds
- *
- ****************************************************************************/
+ */
int GdPlaylist::getPlayTime()
{
//DUMMY
@@ -733,10 +736,8 @@ int GdPlaylist::getPlayTime()
}
/*!
- *****************************************************************************
* \brief returns the duration of all remaining songs in the list in seconds
- *
- ****************************************************************************/
+ */
int GdPlaylist::getPlayTimeRemaining()
{
//DUMMY
@@ -746,19 +747,9 @@ int GdPlaylist::getPlayTimeRemaining()
return 0; // dummy
}
-//------------------------------------------------------------------
-//------------------------------------------------------------------
-//
-// class GdTreeNode
-//
-//------------------------------------------------------------------
-//------------------------------------------------------------------
-
/*!
- *****************************************************************************
* \brief constructor
- *
- ****************************************************************************/
+ */
GdTreeNode::GdTreeNode(MYSQL db, int view, string filters)
: mgSelectionTreeNode(db, view)
{
@@ -777,10 +768,8 @@ GdTreeNode::GdTreeNode(mgSelectionTreeNode* parent,
}
/*!
- *****************************************************************************
* \brief destructor
- *
- ****************************************************************************/
+ */
GdTreeNode::~GdTreeNode()
{
// _children.clear();
@@ -789,11 +778,9 @@ GdTreeNode::~GdTreeNode()
/*!
- *****************************************************************************
* \brief checks if this node can be further expandded or not
* \true, if node ia leaf node, false if node can be expanded
- *
- ****************************************************************************/
+ */
bool GdTreeNode::isLeafNode()
{
if( m_level == 0 )
@@ -887,12 +874,12 @@ bool GdTreeNode::expand()
string tables; // stores the db tables used
#define FROMJOIN " FROM tracks, genre as genre1, genre as genre2, album WHERE tracks.sourceid=album.cddbid AND genre1.id=tracks.genre1 AND genre2.id=tracks.genre2 AND %s "
-
+
if( m_expanded )
- {
- mgWarning("Node already expanded\n");
- return true;
- }
+ {
+ mgWarning("Node already expanded\n");
+ return true;
+ }
if( m_level == 1 && m_view < 100 )
{
@@ -1091,7 +1078,7 @@ bool GdTreeNode::expand()
}
else
{
- mgWarning("View #%d level %d' not yet implemented", m_view, m_level);
+ mgWarning( "View #%d level %d' not yet implemented", m_view, m_level );
m_expanded = false;
return false;
}
@@ -1167,22 +1154,22 @@ bool GdTreeNode::expand()
}
}
- // now get all childrean ofthe current node fromthe database
- result = mgSqlReadQuery(&m_db, sqlbuff);
- nrows = mysql_num_rows(result);
+ // now get all childrean of the current node fromthe database
+ result = mgSqlReadQuery( &m_db, sqlbuff );
+ nrows = mysql_num_rows( result );
nfields = mysql_num_fields(result);
- numchild=1;
- while((row = mysql_fetch_row(result)) != NULL)
+ numchild = 1;
+ while( (row = mysql_fetch_row(result) ) != NULL )
{
// row[0] is the printable label for the new child
// row[1] is the unique id for the new child
- sprintf(idbuf, "%s_%03d", m_id.c_str(), numchild);
+ sprintf( idbuf, "%s_%03d", m_id.c_str(), numchild );
// Zweite ebene zeigt alle Tracks des Albums und nicht nur
// diese die den Filterkriterien entsprechen.
// das betrifft nur die Search Views!
- if(m_view < 100)
+ if( m_view < 100 )
{
new_restriction = m_restriction + " AND "
+ idfield + "='" + row[1] + "'";
diff --git a/mg_filters.h b/mg_filters.h
index 5501d63..658d943 100644
--- a/mg_filters.h
+++ b/mg_filters.h
@@ -1,14 +1,12 @@
-/*******************************************************************/
/*! \file mg_filters.h
* \brief Top level access to media in vdr plugin muggle
* for the vdr muggle plugindatabase
- ********************************************************************
+ *
* \version $Revision: 1.2 $
- * \date $Date: 2004/05/28 15:29:18 $
+ * \date $Date$
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author file owner: $Author: lvw $
+ * \author file owner: $Author$
*/
-/*******************************************************************/
#ifndef _MG_FILTERS_H
#define _MG_FILTERS_H
@@ -17,40 +15,52 @@
#include <vector>
/*!
- *******************************************************************
- * \class mgFilter
- *
- * Abstract base class for representation of filter values with boundaries
- ********************************************************************/
+ * \brief abstract base class for representation of filter values with boundaries
+ */
class mgFilter
{
public:
+
typedef enum filterType
{
- UNDEF=0, INT, STRING, BOOL, CHOICE
+ UNDEF = 0,
+ INT,
+ STRING,
+ BOOL,
+ CHOICE
} filterType;
-
+
protected:
filterType m_type;
char* m_name;
public:
+
mgFilter(const char* name);
+
virtual ~mgFilter();
+
filterType getType();
+
const char* getName();
- virtual std::string getStrVal()=0;
- virtual int getIntVal(){return 0;}
- virtual void store()=0;
- virtual void restore()=0;
- virtual void clear()=0;
- virtual bool isSet()=0;
+
+ virtual std::string getStrVal() = 0;
+
+ virtual int getIntVal()
+ { return 0; }
+
+ virtual void store() = 0;
+
+ virtual void restore() = 0;
+
+ virtual void clear() = 0;
+
+ virtual bool isSet() = 0;
};
/*!
- *******************************************************************
* \class mgFilterInt
- ********************************************************************/
+ */
class mgFilterInt : public mgFilter
{
private:
@@ -77,9 +87,8 @@ class mgFilterInt : public mgFilter
};
/*!
- *******************************************************************
* \class mgFilterString
- ********************************************************************/
+ */
class mgFilterString : public mgFilter
{
private:
@@ -106,9 +115,8 @@ class mgFilterString : public mgFilter
};
/*!
- *******************************************************************
* \class mgFilterBool
- ********************************************************************/
+ */
class mgFilterBool : public mgFilter
{
private:
@@ -136,9 +144,8 @@ class mgFilterBool : public mgFilter
};
/*!
- *******************************************************************
* \class mgFilterChoice
- ********************************************************************/
+ */
class mgFilterChoice : public mgFilter
{
private:
diff --git a/mg_tools.c b/mg_tools.c
index b581396..5b20d70 100644
--- a/mg_tools.c
+++ b/mg_tools.c
@@ -1,10 +1,11 @@
-/*! \file mg_tools.c
- * \brief A few util functions for standalone and plugin messaging for the vdr muggle plugindatabase
+/*!
+ * \file mg_tools.c
+ * \brief A few util functions for standalone and plugin messaging for the vdr muggle plugindatabase
*
* \version $Revision: 1.4 $
- * \date $Date: 2004/08/29 14:39:33 $
+ * \date $Date$
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
- * \author file owner: $Author: lvw $
+ * \author file owner: $Author$
*/
#include "mg_tools.h"
@@ -109,7 +110,7 @@ MYSQL_RES* mgSqlReadQuery(MYSQL *db, const char *fmt, ...)
va_list ap;
va_start( ap, fmt );
vsnprintf( querybuf, MAX_QUERY_BUFLEN-1, fmt, ap );
-
+
if( mysql_query(db, querybuf) )
{
mgError( "SQL error in MUGGLE:\n%s\n", querybuf );
@@ -134,18 +135,3 @@ void mgSqlWriteQuery(MYSQL *db, const char *fmt, ...)
va_end(ap);
}
-
-/* -------------------- begin CVS log ---------------------------------
- * $Log: mg_tools.c,v $
- * Revision 1.4 2004/08/29 14:39:33 lvw
- * Import running in basic version
- *
- * Revision 1.3 2004/07/25 21:33:35 lvw
- * Removed bugs in finding track files and playlist indexing.
- *
- * Revision 1.2 2004/02/02 22:48:04 MountainMan
- * added CVS $Log
- *
- *
- * --------------------- end CVS log ----------------------------------
- */
diff --git a/mg_tools.h b/mg_tools.h
index 3307e3e..7785ece 100644
--- a/mg_tools.h
+++ b/mg_tools.h
@@ -32,10 +32,15 @@ MYSQL_RES* mgSqlReadQuery( MYSQL *db, const char *fmt, ... );
*
* \todo Could be a member of mgDatabase?
*/
-void mgSqlWriteQuery( MYSQL *db, const char *fmt, ... );
+void mgSqlWriteQuery( MYSQL *db, const char *fmt, ... );
-/*! \brief Logging utilities */
+/*!
+ * \brief Logging utilities
+ *
+ * \todo these could be static members in the mgLog class
+ * \todo code of these functions should be compiled conditionally
+ */
//@{
void mgSetDebugLevel(int new_level);
void mgDebug(int level, const char *fmt, ...);
@@ -92,24 +97,4 @@ class mgLog
};
-/* -------------------- begin CVS log ---------------------------------
- * $Log: mg_tools.h,v $
- * Revision 1.4 2004/08/30 14:31:43 LarsAC
- * Documentation added
- *
- * Revision 1.3 2004/05/28 15:29:18 lvw
- * Merged player branch back on HEAD branch.
- *
- * Revision 1.2.2.2 2004/04/18 14:08:41 lvw
- * Added some more logging/debugging code
- *
- * Revision 1.2.2.1 2004/04/09 16:14:48 lvw
- * Added further code for logging/debugging.
- *
- * Revision 1.2 2004/02/02 22:48:04 MountainMan
- * added CVS $Log
- *
- *
- * --------------------- end CVS log ----------------------------------
- */
#endif /* _MUGGLE_TOOLS_H */
diff --git a/mugglei.c b/mugglei.c
index c7206bd..4d8477b 100755
--- a/mugglei.c
+++ b/mugglei.c
@@ -1,3 +1,9 @@
+/*!
+ * \file mugglei.c
+ * \brief implement a small utility for importing files
+ *
+ * \author Lars von Wedel
+ */
#include <string>
using namespace std;
@@ -176,10 +182,18 @@ void update_db( long uid, string filename )
if( import_assorted )
{ // in this case, the album author is "Various Artists"
- mgSqlWriteQuery( db, "INSERT INTO album (artist,title,cddbid) VALUES (\"Various Artists\", \"%s\", \"%s\")", album.toCString(), cddbid.toCString() ); }
+ mgSqlWriteQuery( db,
+ "INSERT INTO album (artist,title,cddbid) "
+ "VALUES (\"Various Artists\", \"%s\", \"%s\")",
+ album.toCString(), cddbid.toCString() );
+ }
else
{
- mgSqlWriteQuery( db, "INSERT INTO album (artist,title,cddbid) VALUES (\"%s\", \"%s\", \"%s\")", artist.toCString(), album.toCString(), cddbid.toCString() ); }
+ mgSqlWriteQuery( db,
+ "INSERT INTO album (artist,title,cddbid) "
+ "VALUES (\"%s\", \"%s\", \"%s\")",
+ artist.toCString(), album.toCString(), cddbid.toCString() );
+ }
}
else
{ // use first album found as source id for the track
@@ -187,34 +201,35 @@ void update_db( long uid, string filename )
}
}
- // update tracks table
+ // update tracks table
if( uid > 0 )
{ // the entry is known to exist already, hence update it
-
+
mgSqlWriteQuery( db, "UPDATE tracks SET artist=\"%s\", title=\"%s\", year=\"%s\","
- "sourceid=\"%s\", mp3file=\"%s\", length=%d, bitrate=\"%d\","
- "samplerate=%d, channels=%d WHERE id=%d",
- artist.toCString(), title.toCString(), year,
- cddbid.toCString(), filename.c_str(), len, bitrate,
- sample, channels, uid );
+ "sourceid=\"%s\", mp3file=\"%s\", length=%d, bitrate=\"%d\","
+ "samplerate=%d, channels=%d WHERE id=%d",
+ artist.toCString(), title.toCString(), year,
+ cddbid.toCString(), filename.c_str(), len, bitrate,
+ sample, channels, uid );
}
else
{ // the entry does not exist, create it
- mgSqlWriteQuery( db,"INSERT INTO tracks (artist,title,genre1,genre2,year,"
- "sourceid,tracknb,mp3file,length,bitrate,samplerate,channels)"
- " VALUES (\"%s\", \"%s\", \"\", \"\", %d, \"%s\", %d, \"%s\", %d, \"%d\", %d, %d)",
- artist.toCString(), title.toCString(), year, cddbid.toCString(),
- trackno, filename.c_str(), len, bitrate, sample, channels );
- /*
- cout << "-- TAG --" << endl;
- cout << "title - \"" << tag->title() << "\"" << endl;
- cout << "artist - \"" << tag->artist() << "\"" << endl;
- cout << "album - \"" << tag->album() << "\"" << endl;
- cout << "year - \"" << tag->year() << "\"" << endl;
- cout << "comment - \"" << tag->comment() << "\"" << endl;
- cout << "track - \"" << tag->track() << "\"" << endl;
- cout << "genre - \"" << tag->genre() << "\"" << endl;
- */
+ mgSqlWriteQuery( db,"INSERT INTO tracks (artist,title,genre1,genre2,year,"
+ "sourceid,tracknb,mp3file,length,bitrate,samplerate,channels)"
+ " VALUES (\"%s\", \"%s\", \"\", \"\", %d, \"%s\", %d, \"%s\", %d, \"%d\", %d, %d)",
+ artist.toCString(), title.toCString(), year, cddbid.toCString(),
+ trackno, filename.c_str(), len, bitrate, sample, channels );
+
+#ifdef VERBOSE
+ cout << "-- TAG --" << endl;
+ cout << "title - \"" << tag->title() << "\"" << endl;
+ cout << "artist - \"" << tag->artist() << "\"" << endl;
+ cout << "album - \"" << tag->album() << "\"" << endl;
+ cout << "year - \"" << tag->year() << "\"" << endl;
+ cout << "comment - \"" << tag->comment() << "\"" << endl;
+ cout << "track - \"" << tag->track() << "\"" << endl;
+ cout << "genre - \"" << tag->genre() << "\"" << endl;
+#endif
}
}
}