2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
28 Media::Media(int type, const char * filename, int time){
31 int len=strlen(filename)+1;
32 _filename=new char[len];
33 strcpy(_filename,filename);
44 const char * Media::getFilename() {
48 int Media::getType() {
51 int Media::getTime() {
57 const char* extension;
60 {".mp3",MEDIA_TYPE_AUDIO},
61 {".MP3",MEDIA_TYPE_AUDIO},
62 {".jpg",MEDIA_TYPE_PICTURE},
63 {".JPG",MEDIA_TYPE_PICTURE},
64 {".jpeg",MEDIA_TYPE_PICTURE},
65 {".JPEG",MEDIA_TYPE_PICTURE}
67 //#define NUMTYPES (sizeof(mediatypes)/sizeof(mtype))
70 MediaList * MediaList::readList(Config * cfg,const char * dirname, int type) {
72 if (dirname == NULL) {
73 //the configured Media List
74 //for the moment up to 10 entries [Media] Dir.1 ...Dir.10
75 for (int nr=1;nr<=10;nr++){
77 sprintf(buffer,"Dir.%d",nr);
78 const char * dn=cfg->getValueString("Media",buffer);
80 if (rt == NULL) rt=new MediaList();
81 Media *m=new Media(MEDIA_TYPE_DIR,dn,0);
83 Log::getInstance()->log("Media",Log::DEBUG,"added base dir %s",dn);
87 if (rt != NULL) return rt;
88 //if nothing is configured, we start at /
89 if (dirname == NULL) dirname="/";
91 //open the directory and read out the entries
94 while ((e=d.Next()) != NULL) {
96 const char * fname=e->d_name;
97 if ( fname == NULL) continue;
98 if (strcmp(fname,".") == 0) continue;
100 asprintf(&buffer, "%s/%s", dirname, e->d_name);
102 int mtype=MEDIA_TYPE_UNKNOWN;
103 if (stat(buffer, &st) == 0) {
104 if (S_ISDIR(st.st_mode)) {
105 mtype=MEDIA_TYPE_DIR;
108 for (int i=0;i<NUMTYPES;i++) {
109 if (endswith(fname,mediatypes[i].extension)) {
110 mtype=mediatypes[i].type;
117 //only consider entries we accept by type here
119 Media * m =new Media(mtype,fname,(int)(st.st_mtime));
121 Log::getInstance()->log("Media",Log::DEBUG,"added entry %s, type=%d",fname,mtype);
126 //Media *m=new Media(MEDIA_TYPE_DIR,"testMedia1",0);