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 <stdio.h>
00020 #include <string.h>
00021 #include <stdlib.h>
00022 #include <errno.h>
00023 
00024 #include <jutils.h>
00025 #include <playlist.h>
00026 #include <config.h>
00027 
00028 Url::Url(const char *file) : Entry() {
00029   path = strdup(file);
00030 }
00031 
00032 Url::~Url() {
00033   if(path) free(path);
00034 }
00035 
00036 Playlist::Playlist()
00037   : Linklist() {
00038 }
00039 
00040 Playlist::~Playlist() {
00041   cleanup();
00042 }
00043 
00044 void Playlist::cleanup() {
00045   Url *p = (Url*)begin();
00046   while(p!=NULL) {
00047     rem(1);
00048     delete p;
00049     p = (Url*) begin();
00050   }
00051   clear();
00052 }
00053 
00054 char *Playlist::addurl(const char *file) {
00055   Url *url = new Url(file);
00056   if(!url)
00057     error("%i:%s %s url is NULL",__LINE__,__FILE__,__FUNCTION__);
00058   append((Entry*)url);
00059   return(url->path);
00060 }
00061 
00062 char *Playlist::addurl(const char *file, int pos) {
00063   Url *url = new Url(file);
00064   insert((Entry*)url,pos);
00065   return(url->path);
00066 }
00067 
00068 char *Playlist::song(int pos) {
00069   Url *sel = (Url*) pick(pos);
00070   
00071   if(sel) return(sel->path);
00072   
00073   warning("Playlist::song(%i) : invalid song requested",pos);
00074   return NULL;
00075 }
00076 
00077 char *Playlist::selection() {
00078   Url *sel = (Url*) selected();
00079   if(sel) return(sel->path);
00080   warning("Playlist::selected() : no selection");
00081   return NULL;
00082 }
00083 
00084 /*
00085 bool Playlist::sel(int pos) {
00086   Url *sel = (Url*)pick(pos);
00087 
00088   if(sel) {
00089     selected = sel;
00090     return(true);
00091   }
00092   
00093   warning("Playlist::sel(%i) : invalid selection",pos);
00094   selected = NULL;
00095   return(false);
00096 }
00097 
00098 void Playlist::sel(Url *sel) {
00099   if(!sel) {
00100     warning("Playlist::sel(NULL *Entry) : misbehaviour",sel);
00101     return;
00102   }
00103   selected = sel;
00104 }
00105 
00106 int Playlist::sel() {
00107   if(!selected) {
00108     warning("Playlist::sel() : selected = %p",selected);
00109     return 1;
00110   }
00111   
00112   return pos((Entry*)selected);
00113 }
00114 */

Generated on Sat Apr 17 17:38:49 2004 for MuSE by doxygen1.3