diff options
author | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-04-19 18:01:19 +0000 |
---|---|---|
committer | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-04-19 18:01:19 +0000 |
commit | e636aa59d86868039f39b0e39e944871cae5b9db (patch) | |
tree | f44f9f196ce7de52a2dacdff3588ec99e5d03e40 /mg_content.c | |
parent | 143d3397960c698935869cae65db8d8937e4d22a (diff) | |
download | vdr-plugin-muggle-e636aa59d86868039f39b0e39e944871cae5b9db.tar.gz vdr-plugin-muggle-e636aa59d86868039f39b0e39e944871cae5b9db.tar.bz2 |
Merged changes from 0.1.6-wr
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@637 e10066b5-e1e2-0310-b819-94efdf66514b
Diffstat (limited to 'mg_content.c')
-rw-r--r-- | mg_content.c | 171 |
1 files changed, 129 insertions, 42 deletions
diff --git a/mg_content.c b/mg_content.c index 74b9fce..5ab6874 100644 --- a/mg_content.c +++ b/mg_content.c @@ -9,14 +9,64 @@ * */ -#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "i18n.h" +#include <tools.h> #include "mg_selection.h" #include "mg_setup.h" #include "mg_tools.h" -mgSelItem* +mgListItem zeroitem; + +mgListItem::mgListItem() +{ + m_valid=false; + m_count=0; +} + +mgListItem::mgListItem(string v,string i,unsigned int c) +{ + set(v,i,c); +} + +void +mgListItem::set(string v,string i,unsigned int c) +{ + m_valid=true; + m_value=v; + m_id=i; + m_count=c; +} + +void +mgListItem::operator=(const mgListItem& from) +{ + m_valid=from.m_valid; + m_value=from.m_value; + m_id=from.m_id; + m_count=from.m_count; +} + +void +mgListItem::operator=(const mgListItem* from) +{ + m_valid=from->m_valid; + m_value=from->m_value; + m_id=from->m_id; + m_count=from->m_count; +} + +bool +mgListItem::operator==(const mgListItem& other) const +{ + return m_value == other.m_value + && m_id == other.m_id; +} + +mgListItem* mgContentItem::getKeyItem(mgKeyTypes kt) { string val; @@ -49,10 +99,10 @@ mgContentItem::getKeyItem(mgKeyTypes kt) free(fbuf); break; } - default: return new mgSelItem; + default: return new mgListItem; } } - return new mgSelItem(val,id); + return new mgListItem(val,id); } @@ -125,11 +175,15 @@ int mgContentItem::getChannels () const mgContentItem::mgContentItem () { + m_valid = true; + m_validated = false; m_trackid = -1; } mgContentItem::mgContentItem (const mgContentItem* c) { + m_valid = true; + m_validated = false; m_trackid = c->m_trackid; m_title = c->m_title; m_mp3file = c->m_mp3file; @@ -149,55 +203,88 @@ mgContentItem::mgContentItem (const mgContentItem* c) m_channels = c->m_channels; } -static char *mg_readline(FILE *f) -{ - static char buffer[10000]; - 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 ) +bool +mgContentItem::Valid() const { - string result = ""; - char *cmd = 0; - asprintf( &cmd, FINDCMD, tld, mp3file.c_str() ); - FILE *p = popen( cmd, "r" ); - if (p) + if (!m_validated) { - char *s; - if( (s = mg_readline(p) ) != 0) - result = string(s); - pclose(p); + getSourceFile(); // sets m_valid as a side effect + m_validated=true; } + return m_valid; +} - free( cmd ); +static bool music_dir_exists[100]; +static bool music_dirs_scanned=false; - return result; +bool +mgContentItem::readable(string filename) const +{ + return !access(filename.c_str(),R_OK); } 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; + string tld = the_setup.ToplevelDir; + string result = m_mp3file; + if (m_validated && !m_valid) + return m_mp3file; + if (!readable(tld+result)) + { + result.clear(); + if (!music_dirs_scanned) + { + for (unsigned int i =0 ; i < 100 ; i++) + { + struct stat stbuf; + char *dir; + asprintf(&dir,"%s%02d",tld.c_str(),i); + music_dir_exists[i]=!stat(dir,&stbuf); + free(dir); + } + music_dirs_scanned=true; + } + for (unsigned int i =0 ; i < 100 ; i++) + { + if (!music_dir_exists[i]) + continue; + char *file; + asprintf(&file,"%02d/%s",i,m_mp3file.c_str()); + if (readable(tld+file)) + { + m_mp3file = file; + result = m_mp3file; + } + free(file); + if (!result.empty()) + break; + } + } + if (result.empty()) + { + char *b=0; + int nsize = m_mp3file.size(); + if (nsize<30) + asprintf(&b,tr("%s not readable"),m_mp3file.c_str()); + else + asprintf(&b,tr("%s..%s not readable"),m_mp3file.substr(0,20).c_str(),m_mp3file.substr(nsize-20).c_str());; + extern void showmessage(const char*,int duration=0); + showmessage(b); + free(b); + esyslog ("ERROR: cannot stat %s. Meaning not found, not a valid file, or no access rights", m_mp3file.c_str ()); + m_valid = false; + return m_mp3file; + } + if (AbsolutePath) + result = tld + result; return result; } -mgContentItem::mgContentItem (const mgSelection* sel,const MYSQL_ROW row) +mgContentItem::mgContentItem (const MYSQL_ROW row) { + m_valid = true; + m_validated = false; m_trackid = atol (row[0]); if (row[1]) m_title = row[1]; @@ -218,14 +305,14 @@ mgContentItem::mgContentItem (const mgSelection* sel,const MYSQL_ROW row) if (row[5]) { m_genre1_id = row[5]; - m_genre1 = sel->value(keyGenres,row[5]); + m_genre1 = KeyMaps.value(keyGenres,row[5]); } else m_genre1 = "NULL"; if (row[6]) { m_genre2_id = row[6]; - m_genre2 = sel->value(keyGenres,row[6]); + m_genre2 = KeyMaps.value(keyGenres,row[6]); } else m_genre2 = "NULL"; @@ -256,7 +343,7 @@ mgContentItem::mgContentItem (const mgSelection* sel,const MYSQL_ROW row) if (row[13]) { m_language_id = row[13]; - m_language = sel->value(keyLanguage,row[13]); + m_language = KeyMaps.value(keyLanguage,row[13]); } else m_language_id = "NULL"; |