00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <config.h>
00020
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include <errno.h>
00025
00026 #include <jutils.h>
00027 #include <playlist.h>
00028
00029 Url::Url(const char *file) : Entry() {
00030 path = strdup(file);
00031 #ifdef HAVE_SCHEDULER
00032 mn=NULL; hr=NULL;
00033 day=NULL; mon=NULL;
00034 wkd=NULL; cmnplay=NULL;
00035 comment=NULL;
00036 csecs=NULL;
00037 #endif
00038 }
00039
00040 Url::~Url() {
00041 if(path) free(path);
00042 #ifdef HAVE_SCHEDULER
00043 if(mn) free((char*)mn);
00044 if(hr) free((char*)hr);
00045 if(day) free((char*)day);
00046 if(mon) free((char*)mon);
00047 if(wkd) free((char*)wkd);
00048 if(cmnplay) free((char*)cmnplay);
00049 if(comment) free((char*)comment);
00050 if(csecs) free((char*)csecs);
00051 #endif
00052 }
00053
00054 Playlist::Playlist()
00055 : Linklist() {
00056 }
00057
00058 Playlist::~Playlist() {
00059 cleanup();
00060 }
00061
00062 void Playlist::cleanup() {
00063 Url *p = (Url*)begin();
00064 while(p!=NULL) {
00065 rem(1);
00066 delete p;
00067 p = (Url*) begin();
00068 }
00069 clear();
00070 }
00071
00072 char *Playlist::addurl(const char *file) {
00073 Url *url = new Url(file);
00074 if(!url)
00075 error("%i:%s %s url is NULL",__LINE__,__FILE__,__FUNCTION__);
00076 append((Entry*)url);
00077 return(url->path);
00078 }
00079
00080 char *Playlist::addurl(const char *file, int pos) {
00081 Url *url = new Url(file);
00082 insert((Entry*)url,pos);
00083 return(url->path);
00084 }
00085
00086 #ifdef HAVE_SCHEDULER
00087 #define SAFE(x) (x?x:"")
00088 void Playlist::addurl(Url *url) {
00089 append((Entry*)url);
00090 }
00091
00092 Url *Playlist::addurl(const char *file, const char *mn, const char *hr,
00093 const char *day, const char *mon, const char *wkd,
00094 const char *cmnplay, const char *comment )
00095 {
00096 Url *url = new Url(file);
00097 if(!url)
00098 error("%i:%s %s url is NULL",__LINE__,__FILE__,__FUNCTION__);
00099 append((Entry*)url);
00100 url->mn = strdup(SAFE(mn));
00101 url->hr = strdup(SAFE(hr));
00102 url->day = strdup(SAFE(day));
00103 url->mon = strdup(SAFE(mon));
00104 url->wkd = strdup(SAFE(wkd));
00105 url->cmnplay = strdup(SAFE(cmnplay));
00106 if (cmnplay) {
00107 url->mnplay = atoi(cmnplay);
00108 } else {
00109 url->mnplay = 0;
00110 }
00111 url->mnleft = 0;
00112 url->comment = strdup(SAFE(comment));
00113 return(url);
00114 }
00115 #endif
00116
00117 char *Playlist::song(int pos) {
00118 Url *sel = (Url*) pick(pos);
00119
00120 if(sel) return(sel->path);
00121
00122 warning("Playlist::song(%i) : invalid song requested",pos);
00123 return NULL;
00124 }
00125
00126 char *Playlist::selection() {
00127 Url *sel = (Url*) selected();
00128 if(sel) return(sel->path);
00129 warning("Playlist::selected() : no selection");
00130 return NULL;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163