Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

playlist.cpp

00001 /* MuSE - Multiple Streaming Engine
00002  * Copyright (C) 2000-2002 Denis Roio aka jaromil <jaromil@dyne.org>
00003  *
00004  * This source code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Public License as published 
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * This source code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00012  * Please refer to the GNU Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Public License along with
00015  * this source code; if not, write to:
00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 bool Playlist::sel(int pos) {
00135   Url *sel = (Url*)pick(pos);
00136 
00137   if(sel) {
00138     selected = sel;
00139     return(true);
00140   }
00141   
00142   warning("Playlist::sel(%i) : invalid selection",pos);
00143   selected = NULL;
00144   return(false);
00145 }
00146 
00147 void Playlist::sel(Url *sel) {
00148   if(!sel) {
00149     warning("Playlist::sel(NULL *Entry) : misbehaviour",sel);
00150     return;
00151   }
00152   selected = sel;
00153 }
00154 
00155 int Playlist::sel() {
00156   if(!selected) {
00157     warning("Playlist::sel() : selected = %p",selected);
00158     return 1;
00159   }
00160   
00161   return pos((Entry*)selected);
00162 }
00163 */

Generated on Thu Dec 16 12:28:21 2004 for MuSE by doxygen1.3