00001 /* 00002 * Copyright (c) 2006-2009 Ed Schouten <ed@80386.nl> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00017 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00018 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00019 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00020 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00021 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00022 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00023 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00024 * SUCH DAMAGE. 00025 */ 00031 #include "stdinc.h" 00032 00033 #include "gui.h" 00034 #include "playq.h" 00035 #include "playq_modules.h" 00036 #include "vfs.h" 00037 00041 static struct vfsref *cursong = NULL; 00045 static struct vfsref *selectsong = NULL; 00046 00047 struct vfsref * 00048 playq_xmms_give(void) 00049 { 00050 struct vfsref *vr = NULL; 00051 00052 if (cursong != NULL) 00053 /* Unmark it */ 00054 vfs_unmark(cursong); 00055 00056 if (selectsong != NULL) { 00057 /* Selected song has the highest priority */ 00058 cursong = selectsong; 00059 selectsong = NULL; 00060 } else if (cursong != NULL) { 00061 /* Song after current song */ 00062 cursong = vfs_list_next(cursong); 00063 /* We've reached the end */ 00064 if (cursong == NULL && playq_repeat) 00065 cursong = vfs_list_first(&playq_list); 00066 } else { 00067 cursong = vfs_list_first(&playq_list); 00068 } 00069 00070 if (cursong != NULL) { 00071 vfs_mark(cursong); 00072 vr = vfs_dup(cursong); 00073 } 00074 00075 /* Update markers */ 00076 gui_playq_notify_done(); 00077 00078 return (vr); 00079 } 00080 00081 void 00082 playq_xmms_idle(void) 00083 { 00084 if (cursong != NULL) { 00085 /* Remove left-over marking */ 00086 vfs_unmark(cursong); 00087 gui_playq_notify_done(); 00088 } 00089 } 00090 00091 int 00092 playq_xmms_select(struct vfsref *vr) 00093 { 00094 selectsong = vr; 00095 00096 return (0); 00097 } 00098 00099 int 00100 playq_xmms_next(void) 00101 { 00102 if (cursong != NULL) { 00103 selectsong = vfs_list_next(cursong); 00104 if (selectsong == NULL) 00105 selectsong = vfs_list_first(&playq_list); 00106 } 00107 00108 return (selectsong == NULL); 00109 } 00110 00111 int 00112 playq_xmms_prev(void) 00113 { 00114 if (cursong != NULL) { 00115 selectsong = vfs_list_prev(cursong); 00116 if (selectsong == NULL) 00117 selectsong = vfs_list_last(&playq_list); 00118 } 00119 00120 return (selectsong == NULL); 00121 } 00122 00123 void 00124 playq_xmms_notify_pre_removal(struct vfsref *vr) 00125 { 00126 /* Remove dangling pointers */ 00127 if (cursong == vr) 00128 cursong = NULL; 00129 00130 g_assert(selectsong != vr); 00131 }
1.6.3