summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-02-27 15:20:04 +0000
committerwr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b>2005-02-27 15:20:04 +0000
commit84aac6b2746599f6bf3680b7d34e5536c0da1e2d (patch)
treeb8c0eb90c79085097118bf7e2845eb4c89939ca3
parentf417207c314d09fe7ef2a5a332f2ee1ca7ef943d (diff)
downloadvdr-plugin-muggle-84aac6b2746599f6bf3680b7d34e5536c0da1e2d.tar.gz
vdr-plugin-muggle-84aac6b2746599f6bf3680b7d34e5536c0da1e2d.tar.bz2
split mg_db.[ch] into mg_content and mg_selection
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/branches/0.1.3-wr@516 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--Makefile2
-rw-r--r--mg_content.c244
-rw-r--r--mg_content.h112
-rw-r--r--mg_selection.c (renamed from mg_db.c)232
-rw-r--r--mg_selection.h (renamed from mg_db.h)91
-rw-r--r--muggle.c2
-rw-r--r--vdr_decoder.c2
-rw-r--r--vdr_decoder_flac.c2
-rw-r--r--vdr_decoder_mp3.c2
-rw-r--r--vdr_decoder_ogg.c2
-rw-r--r--vdr_player.c1
-rw-r--r--vdr_player.h2
12 files changed, 371 insertions, 323 deletions
diff --git a/Makefile b/Makefile
index 2f5ac30..2349694 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ MIFLAGS += -I/usr/include/taglib -lmysqlclient
### The object files (add further files here):
-OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_order.o mg_db.o mg_actions.o vdr_menu.o mg_tools.o \
+OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_order.o mg_content.o mg_selection.o mg_actions.o vdr_menu.o mg_tools.o \
vdr_decoder_mp3.o vdr_stream.o vdr_decoder.o vdr_player.o \
vdr_setup.o mg_setup.o
diff --git a/mg_content.c b/mg_content.c
new file mode 100644
index 0000000..8e2ca29
--- /dev/null
+++ b/mg_content.c
@@ -0,0 +1,244 @@
+/*!
+ * \file mg_selection.c
+ * \brief A general interface to data items, currently only GiantDisc
+ *
+ * \version $Revision: 1.0 $
+ * \date $Date: 2004-12-07 10:10:35 +0200 (Tue, 07 Dec 2004) $
+ * \author Wolfgang Rohdewald
+ * \author Responsible author: $Author: wr $
+ *
+ */
+
+#include <stdio.h>
+#include "mg_selection.h"
+#include "vdr_setup.h"
+#include "mg_tools.h"
+
+
+string
+mgContentItem::getKeyId(mgKeyTypes kt)
+{
+ if (m_id<0)
+ return "";
+ switch (kt) {
+ case keyGenres:
+ case keyGenre1:
+ case keyGenre2:
+ case keyGenre3: return m_genre1_id;
+ default: return getKeyValue(kt);
+ }
+}
+
+string
+mgContentItem::getKeyValue(mgKeyTypes kt)
+{
+ if (m_id<0)
+ return "";
+ switch (kt) {
+ case keyGenres:
+ case keyGenre1:
+ case keyGenre2:
+ case keyGenre3: return getGenre();
+ case keyArtist: return getArtist();
+ case keyAlbum: return getAlbum();
+ case keyYear: return string(ltos(getYear()));
+ case keyDecade: return string(ltos(int((getYear() % 100) / 10) * 10));
+ case keyTitle: return getTitle();
+ case keyTrack: return getTitle();
+ default: return "";
+ }
+}
+
+
+string mgContentItem::getGenre () const
+{
+ string result="";
+ if (m_genre1!="NULL")
+ result = m_genre1;
+ if (m_genre2!="NULL")
+ {
+ if (!result.empty())
+ result += "/";
+ result += m_genre2;
+ }
+ return result;
+}
+
+
+string mgContentItem::getBitrate () const
+{
+ return m_bitrate;
+}
+
+
+string mgContentItem::getImageFile () const
+{
+ return "Name of Imagefile";
+}
+
+
+string mgContentItem::getAlbum () const
+{
+ return m_albumtitle;
+}
+
+
+int mgContentItem::getYear () const
+{
+ return m_year;
+}
+
+
+int mgContentItem::getRating () const
+{
+ return m_rating;
+}
+
+
+int mgContentItem::getDuration () const
+{
+ return m_duration;
+}
+
+
+int mgContentItem::getSampleRate () const
+{
+ return m_samplerate;
+}
+
+
+int mgContentItem::getChannels () const
+{
+ return m_channels;
+}
+
+mgContentItem::mgContentItem ()
+{
+ m_id = -1;
+}
+
+mgContentItem::mgContentItem (const mgContentItem* c)
+{
+ m_id = c->m_id;
+ m_title = c->m_title;
+ m_mp3file = c->m_mp3file;
+ m_artist = c->m_artist;
+ m_albumtitle = c->m_albumtitle;
+ m_genre1_id = c->m_genre1_id;
+ m_genre2_id = c->m_genre2_id;
+ m_genre1 = c->m_genre1;
+ m_genre2 = c->m_genre2;
+ m_bitrate = c->m_bitrate;
+ m_year = c->m_year;
+ m_rating = c->m_rating;
+ m_duration = c->m_duration;
+ m_samplerate = c->m_samplerate;
+ m_channels = c->m_channels;
+}
+
+static char *mg_readline(FILE *f)
+{
+ static char buffer[MAXPARSEBUFFER];
+ if (fgets(buffer, sizeof(buffer), f) > 0) {
+ int l = strlen(buffer) - 1;
+ if (l >= 0 && buffer[l] == '\n')
+ buffer[l] = 0;
+ return buffer;
+ }
+ return 0;
+}
+
+static const char *FINDCMD = "cd '%s' 2>/dev/null && find -follow -name '%s' -print 2>/dev/null";
+
+static string
+GdFindFile( const char* tld, string mp3file )
+{
+ string result = "";
+ char *cmd = 0;
+ asprintf( &cmd, FINDCMD, tld, mp3file.c_str() );
+ FILE *p = popen( cmd, "r" );
+ if (p)
+ {
+ char *s;
+ if( (s = mg_readline(p) ) != 0)
+ result = string(s);
+ pclose(p);
+ }
+
+ free( cmd );
+
+ return result;
+}
+
+string
+mgContentItem::getSourceFile(bool AbsolutePath) const
+{
+ const char* tld = the_setup.ToplevelDir;
+ string result="";
+ if (AbsolutePath) result = tld;
+ if (the_setup.GdCompatibility)
+ result += GdFindFile(tld,m_mp3file);
+ else
+ result += m_mp3file;
+ return result;
+}
+
+mgContentItem::mgContentItem (const mgSelection* sel,const MYSQL_ROW row)
+{
+ m_id = atol (row[0]);
+ if (row[1])
+ m_title = row[1];
+ else
+ m_title = "NULL";
+ if (row[2])
+ m_mp3file = row[2];
+ else
+ m_mp3file = "NULL";
+ if (row[3])
+ m_artist = row[3];
+ else
+ m_artist = "NULL";
+ if (row[4])
+ m_albumtitle = row[4];
+ else
+ m_albumtitle = "NULL";
+ if (row[5])
+ {
+ m_genre1_id = row[5];
+ m_genre1 = sel->value(keyGenres,row[5]);
+ }
+ else
+ m_genre1 = "NULL";
+ if (row[6])
+ {
+ m_genre2_id = row[6];
+ m_genre2 = sel->value(keyGenres,row[6]);
+ }
+ else
+ m_genre2 = "NULL";
+ if (row[7])
+ m_bitrate = row[7];
+ else
+ m_bitrate = "NULL";
+ if (row[8])
+ m_year = atol (row[8]);
+ else
+ m_year = 0;
+ if (row[9])
+ m_rating = atol (row[9]);
+ else
+ m_rating = 0;
+ if (row[10])
+ m_duration = atol (row[10]);
+ else
+ m_duration = 0;
+ if (row[11])
+ m_samplerate = atol (row[11]);
+ else
+ m_samplerate = 0;
+ if (row[12])
+ m_channels = atol (row[12]);
+ else
+ m_channels = 0;
+};
+
diff --git a/mg_content.h b/mg_content.h
new file mode 100644
index 0000000..76d5869
--- /dev/null
+++ b/mg_content.h
@@ -0,0 +1,112 @@
+/*!
+ * \file mg_selection.h
+ * \brief A general interface to data items, currently only GiantDisc
+ *
+ * \version $Revision: 1.0 $
+ * \date $Date: 2004-12-07 10:10:35 +0200 (Tue, 07 Dec 2004) $
+ * \author Wolfgang Rohdewald
+ * \author Responsible author: $Author: wr $
+ *
+ */
+
+#ifndef _MG_CONTENT_H
+#define _MG_CONTENT_H
+#include <stdlib.h>
+#include <mysql/mysql.h>
+#include <string>
+#include <list>
+#include <vector>
+#include <map>
+#include <i18n.h>
+using namespace std;
+
+#include "mg_tools.h"
+#include "mg_valmap.h"
+#include "mg_order.h"
+
+typedef vector<string> strvector;
+
+
+class mgSelection;
+
+//! \brief represents a content item like an mp3 file.
+class mgContentItem
+{
+ public:
+ mgContentItem ();
+
+ string getKeyValue(mgKeyTypes kt);
+ string getKeyId(mgKeyTypes kt);
+
+ //! \brief copy constructor
+ mgContentItem(const mgContentItem* c);
+
+ //! \brief construct an item from an SQL row
+ mgContentItem (const mgSelection* sel, const MYSQL_ROW row);
+//! \brief returns track id
+ long getId () const
+ {
+ return m_id;
+ }
+
+//! \brief returns title
+ string getTitle () const
+ {
+ return m_title;
+ }
+
+//! \brief returns filename
+ string getSourceFile (bool AbsolutePath=true) const;
+
+//! \brief returns artist
+ string getArtist () const
+ {
+ return m_artist;
+ }
+
+//! \brief returns the name of the album
+ string getAlbum () const;
+
+//! \brief returns the name of genre
+ string getGenre () const;
+
+//! \brief returns the bitrate
+ string getBitrate () const;
+
+//! \brief returns the file name of the album image
+ string getImageFile () const;
+
+//! \brief returns year
+ int getYear () const;
+
+//! \brief returns rating
+ int getRating () const;
+
+//! \brief returns duration
+ int getDuration () const;
+
+//! \brief returns samplerate
+ int getSampleRate () const;
+
+//! \brief returns # of channels
+ int getChannels () const;
+
+ private:
+ long m_id;
+ string m_title;
+ string m_mp3file;
+ string m_artist;
+ string m_albumtitle;
+ string m_genre1_id;
+ string m_genre2_id;
+ string m_genre1;
+ string m_genre2;
+ string m_bitrate;
+ int m_year;
+ int m_rating;
+ int m_duration;
+ int m_samplerate;
+ int m_channels;
+};
+
+#endif
diff --git a/mg_db.c b/mg_selection.c
index f215e92..3bb79e1 100644
--- a/mg_db.c
+++ b/mg_selection.c
@@ -1,6 +1,6 @@
/*!
- * \file mg_db.c
- * \brief A database interface to the GiantDisc
+ * \file mg_selection.c
+ * \brief A general interface to data items, currently only GiantDisc
*
* \version $Revision: 1.0 $
* \date $Date: 2004-12-07 10:10:35 +0200 (Tue, 07 Dec 2004) $
@@ -10,7 +10,7 @@
*/
#include <stdio.h>
-#include "mg_db.h"
+#include "mg_selection.h"
#include "vdr_setup.h"
#include "mg_tools.h"
@@ -141,39 +141,6 @@ mgSelection::sql_string (const string s) const
return result;
}
-string
-mgContentItem::getKeyId(mgKeyTypes kt)
-{
- if (m_id<0)
- return "";
- switch (kt) {
- case keyGenres:
- case keyGenre1:
- case keyGenre2:
- case keyGenre3: return m_genre1_id;
- default: return getKeyValue(kt);
- }
-}
-
-string
-mgContentItem::getKeyValue(mgKeyTypes kt)
-{
- if (m_id<0)
- return "";
- switch (kt) {
- case keyGenres:
- case keyGenre1:
- case keyGenre2:
- case keyGenre3: return getGenre();
- case keyArtist: return getArtist();
- case keyAlbum: return getAlbum();
- case keyYear: return string(ltos(getYear()));
- case keyDecade: return string(ltos(int((getYear() % 100) / 10) * 10));
- case keyTitle: return getTitle();
- case keyTrack: return getTitle();
- default: return "";
- }
-}
mgContentItem *
mgSelection::getTrack (unsigned int position)
@@ -184,69 +151,6 @@ mgSelection::getTrack (unsigned int position)
}
-string mgContentItem::getGenre () const
-{
- string result="";
- if (m_genre1!="NULL")
- result = m_genre1;
- if (m_genre2!="NULL")
- {
- if (!result.empty())
- result += "/";
- result += m_genre2;
- }
- return result;
-}
-
-
-string mgContentItem::getBitrate () const
-{
- return m_bitrate;
-}
-
-
-string mgContentItem::getImageFile () const
-{
- return "Name of Imagefile";
-}
-
-
-string mgContentItem::getAlbum () const
-{
- return m_albumtitle;
-}
-
-
-int mgContentItem::getYear () const
-{
- return m_year;
-}
-
-
-int mgContentItem::getRating () const
-{
- return m_rating;
-}
-
-
-int mgContentItem::getDuration () const
-{
- return m_duration;
-}
-
-
-int mgContentItem::getSampleRate () const
-{
- return m_samplerate;
-}
-
-
-int mgContentItem::getChannels () const
-{
- return m_channels;
-}
-
-
mgSelection::ShuffleMode mgSelection::toggleShuffleMode ()
{
setShuffleMode((m_shuffle_mode == SM_PARTY) ? SM_NONE : ShuffleMode (m_shuffle_mode + 1));
@@ -636,136 +540,6 @@ mgSelection::tracks () const
}
-mgContentItem::mgContentItem ()
-{
- m_id = -1;
-}
-
-mgContentItem::mgContentItem (const mgContentItem* c)
-{
- m_id = c->m_id;
- m_title = c->m_title;
- m_mp3file = c->m_mp3file;
- m_artist = c->m_artist;
- m_albumtitle = c->m_albumtitle;
- m_genre1_id = c->m_genre1_id;
- m_genre2_id = c->m_genre2_id;
- m_genre1 = c->m_genre1;
- m_genre2 = c->m_genre2;
- m_bitrate = c->m_bitrate;
- m_year = c->m_year;
- m_rating = c->m_rating;
- m_duration = c->m_duration;
- m_samplerate = c->m_samplerate;
- m_channels = c->m_channels;
-}
-
-static char *mg_readline(FILE *f)
-{
- static char buffer[MAXPARSEBUFFER];
- if (fgets(buffer, sizeof(buffer), f) > 0) {
- int l = strlen(buffer) - 1;
- if (l >= 0 && buffer[l] == '\n')
- buffer[l] = 0;
- return buffer;
- }
- return 0;
-}
-
-static const char *FINDCMD = "cd '%s' 2>/dev/null && find -follow -name '%s' -print 2>/dev/null";
-
-static string
-GdFindFile( const char* tld, string mp3file )
-{
- string result = "";
- char *cmd = 0;
- asprintf( &cmd, FINDCMD, tld, mp3file.c_str() );
- FILE *p = popen( cmd, "r" );
- if (p)
- {
- char *s;
- if( (s = mg_readline(p) ) != 0)
- result = string(s);
- pclose(p);
- }
-
- free( cmd );
-
- return result;
-}
-
-string
-mgContentItem::getSourceFile(bool AbsolutePath) const
-{
- const char* tld = the_setup.ToplevelDir;
- string result="";
- if (AbsolutePath) result = tld;
- if (the_setup.GdCompatibility)
- result += GdFindFile(tld,m_mp3file);
- else
- result += m_mp3file;
- return result;
-}
-
-mgContentItem::mgContentItem (const mgSelection* sel,const MYSQL_ROW row)
-{
- m_id = atol (row[0]);
- if (row[1])
- m_title = row[1];
- else
- m_title = "NULL";
- if (row[2])
- m_mp3file = row[2];
- else
- m_mp3file = "NULL";
- if (row[3])
- m_artist = row[3];
- else
- m_artist = "NULL";
- if (row[4])
- m_albumtitle = row[4];
- else
- m_albumtitle = "NULL";
- if (row[5])
- {
- m_genre1_id = row[5];
- m_genre1 = sel->value(keyGenres,row[5]);
- }
- else
- m_genre1 = "NULL";
- if (row[6])
- {
- m_genre2_id = row[6];
- m_genre2 = sel->value(keyGenres,row[6]);
- }
- else
- m_genre2 = "NULL";
- if (row[7])
- m_bitrate = row[7];
- else
- m_bitrate = "NULL";
- if (row[8])
- m_year = atol (row[8]);
- else
- m_year = 0;
- if (row[9])
- m_rating = atol (row[9]);
- else
- m_rating = 0;
- if (row[10])
- m_duration = atol (row[10]);
- else
- m_duration = 0;
- if (row[11])
- m_samplerate = atol (row[11]);
- else
- m_samplerate = 0;
- if (row[12])
- m_channels = atol (row[12]);
- else
- m_channels = 0;
-};
-
void mgSelection::InitSelection() {
setDB(0);
m_Directory=".";
diff --git a/mg_db.h b/mg_selection.h
index a053757..4e10644 100644
--- a/mg_db.h
+++ b/mg_selection.h
@@ -1,6 +1,6 @@
/*!
- * \file mg_db.h
- * \brief A database interface to the GiantDisc
+ * \file mg_selection.h
+ * \brief A general interface to data items, currently only GiantDisc
*
* \version $Revision: 1.0 $
* \date $Date: 2004-12-07 10:10:35 +0200 (Tue, 07 Dec 2004) $
@@ -9,8 +9,8 @@
*
*/
-#ifndef _MG_DB_H
-#define _MG_DB_H
+#ifndef _MG_SELECTION_H
+#define _MG_SELECTION_H
#include <stdlib.h>
#include <mysql/mysql.h>
#include <string>
@@ -23,92 +23,11 @@ using namespace std;
#include "mg_tools.h"
#include "mg_valmap.h"
#include "mg_order.h"
+#include "mg_content.h"
typedef vector<string> strvector;
-class mgSelection;
-
-//! \brief represents a content item like an mp3 file.
-class mgContentItem
-{
- public:
- mgContentItem ();
-
- string getKeyValue(mgKeyTypes kt);
- string getKeyId(mgKeyTypes kt);
-
- //! \brief copy constructor
- mgContentItem(const mgContentItem* c);
-
- //! \brief construct an item from an SQL row
- mgContentItem (const mgSelection* sel, const MYSQL_ROW row);
-//! \brief returns track id
- long getId () const
- {
- return m_id;
- }
-
-//! \brief returns title
- string getTitle () const
- {
- return m_title;
- }
-
-//! \brief returns filename
- string getSourceFile (bool AbsolutePath=true) const;
-
-//! \brief returns artist
- string getArtist () const
- {
- return m_artist;
- }
-
-//! \brief returns the name of the album
- string getAlbum () const;
-
-//! \brief returns the name of genre
- string getGenre () const;
-
-//! \brief returns the bitrate
- string getBitrate () const;
-
-//! \brief returns the file name of the album image
- string getImageFile () const;
-
-//! \brief returns year
- int getYear () const;
-
-//! \brief returns rating
- int getRating () const;
-
-//! \brief returns duration
- int getDuration () const;
-
-//! \brief returns samplerate
- int getSampleRate () const;
-
-//! \brief returns # of channels
- int getChannels () const;
-
- private:
- long m_id;
- string m_title;
- string m_mp3file;
- string m_artist;
- string m_albumtitle;
- string m_genre1_id;
- string m_genre2_id;
- string m_genre1;
- string m_genre2;
- string m_bitrate;
- int m_year;
- int m_rating;
- int m_duration;
- int m_samplerate;
- int m_channels;
-};
-
/*!
* \brief the only interface to the database.
* Some member functions are declared const although they can modify the inner state of mgSelection.
diff --git a/muggle.c b/muggle.c
index 46fda32..9b22f80 100644
--- a/muggle.c
+++ b/muggle.c
@@ -15,7 +15,7 @@
#include "vdr_menu.h"
#include "vdr_setup.h"
#include "mg_tools.h"
-#include "mg_db.h"
+#include "mg_selection.h"
#include "i18n.h"
#include <getopt.h>
diff --git a/vdr_decoder.c b/vdr_decoder.c
index 62e6a6d..605b007 100644
--- a/vdr_decoder.c
+++ b/vdr_decoder.c
@@ -21,7 +21,7 @@
#include <sys/stat.h>
#include <sys/vfs.h>
-#include "mg_db.h"
+#include "mg_selection.h"
#include <videodir.h>
#include <interface.h>
diff --git a/vdr_decoder_flac.c b/vdr_decoder_flac.c
index 2861d4e..fd1ca53 100644
--- a/vdr_decoder_flac.c
+++ b/vdr_decoder_flac.c
@@ -17,7 +17,7 @@
#include <stdio.h>
#include "mg_tools.h"
-#include "mg_db.h"
+#include "mg_content.h"
#include "vdr_setup.h"
#include "vdr_decoder_flac.h"
diff --git a/vdr_decoder_mp3.c b/vdr_decoder_mp3.c
index 2ad6bc3..6569760 100644
--- a/vdr_decoder_mp3.c
+++ b/vdr_decoder_mp3.c
@@ -29,7 +29,7 @@
#include "vdr_setup.h"
#include "mg_tools.h"
-#include "mg_db.h"
+#include "mg_content.h"
#define d(x) x
diff --git a/vdr_decoder_ogg.c b/vdr_decoder_ogg.c
index f3ba8ef..47011eb 100644
--- a/vdr_decoder_ogg.c
+++ b/vdr_decoder_ogg.c
@@ -21,7 +21,7 @@
#include "vdr_setup.h"
-#include "mg_db.h"
+#include "mg_content.h"
// --- mgOggFile ----------------------------------------------------------------
diff --git a/vdr_player.c b/vdr_player.c
index bf0a504..3b3035f 100644
--- a/vdr_player.c
+++ b/vdr_player.c
@@ -41,7 +41,6 @@
#include "vdr_config.h"
#include "vdr_setup.h"
#include "i18n.h"
-#include "mg_db.h"
#include "mg_tools.h"
diff --git a/vdr_player.h b/vdr_player.h
index 5b8ea9f..5d60344 100644
--- a/vdr_player.h
+++ b/vdr_player.h
@@ -18,7 +18,7 @@
#define ___VDR_PLAYER_H
#include <player.h>
-#include "mg_db.h"
+#include "mg_selection.h"
#if VDRVERSNUM >= 10307
class cOsd;
#endif