| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "xjukebox.h" |
| 20 |
|
| 21 |
extern XtAppContext app_context; |
| 22 |
|
| 23 |
#ifdef __STDC__ |
| 24 |
extern void rptp_connect(char *hostname); |
| 25 |
extern void rptp_get_sound_list(); |
| 26 |
extern void init_application(char *app_name, int argc, char *argv[]); |
| 27 |
#else |
| 28 |
extern void rptp_connect(); |
| 29 |
extern void rptp_get_sound_list(); |
| 30 |
extern void init_application(); |
| 31 |
#endif |
| 32 |
|
| 33 |
String *sound_names; |
| 34 |
int sound_count; |
| 35 |
String *queue_names; |
| 36 |
int queue_count; |
| 37 |
String *spool_names; |
| 38 |
int spool_count; |
| 39 |
static String empty_list[] = { "< No sounds >", NULL }; |
| 40 |
char *program_name; |
| 41 |
int return_code; |
| 42 |
|
| 43 |
|
| 44 |
#ifdef __STDC__ |
| 45 |
void add_item(String new_item, String **list, int *items_count) |
| 46 |
#else |
| 47 |
void add_item(new_item, list, items_count) |
| 48 |
String new_item; |
| 49 |
String **list; |
| 50 |
int *items_count; |
| 51 |
#endif |
| 52 |
{ |
| 53 |
if ((*list != NULL) && (*list != empty_list)) |
| 54 |
*list = (String *)realloc(*list, (*items_count + 1) * sizeof(String)); |
| 55 |
else |
| 56 |
{ |
| 57 |
*items_count = 0; |
| 58 |
*list = (String *)malloc(sizeof(String)); |
| 59 |
} |
| 60 |
(*list)[*items_count] = |
| 61 |
(String)malloc((strlen(new_item) + 1) * sizeof(char)); |
| 62 |
strcpy((*list)[*items_count], new_item); |
| 63 |
(*items_count)++; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
#ifdef __STDC__ |
| 68 |
void delete_item(int list_index, String **list, int *items_count) |
| 69 |
#else |
| 70 |
void delete_item(list_index, list, items_count) |
| 71 |
int list_index; |
| 72 |
String **list; |
| 73 |
int *items_count; |
| 74 |
#endif |
| 75 |
{ |
| 76 |
int i; |
| 77 |
|
| 78 |
free((*list)[list_index]); |
| 79 |
if (*items_count > 1) |
| 80 |
{ |
| 81 |
for (i = list_index; i < *items_count - 1; i++) |
| 82 |
(*list)[i] = (*list)[i + 1]; |
| 83 |
*list = (String *)realloc(*list, (*items_count - 1) * sizeof(String)); |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
free(*list); |
| 88 |
*list = empty_list; |
| 89 |
*items_count = 0; |
| 90 |
} |
| 91 |
(*items_count)--; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
#ifdef __STDC__ |
| 96 |
void move_item(int old_index, int new_index, String **list) |
| 97 |
#else |
| 98 |
void move_item(old_index, new_index, list) |
| 99 |
int old_index; |
| 100 |
int new_index; |
| 101 |
String **list; |
| 102 |
#endif |
| 103 |
{ |
| 104 |
int i; |
| 105 |
String tmp_s; |
| 106 |
|
| 107 |
tmp_s = (*list)[old_index]; |
| 108 |
if (new_index < old_index) |
| 109 |
{ |
| 110 |
for (i = old_index; i > new_index; i--) |
| 111 |
(*list)[i] = (*list)[i - 1]; |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
for (i = old_index; i < new_index; i++) |
| 116 |
(*list)[i] = (*list)[i + 1]; |
| 117 |
} |
| 118 |
(*list)[new_index] = tmp_s; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
#ifdef __STDC__ |
| 124 |
void load_list(String file_name, String **list, int *items_count) |
| 125 |
#else |
| 126 |
void load_list(file_name, list, items_count) |
| 127 |
String file_name; |
| 128 |
String **list; |
| 129 |
int *items_count; |
| 130 |
#endif |
| 131 |
{ |
| 132 |
FILE *list_file; |
| 133 |
char buffer[1024]; |
| 134 |
|
| 135 |
list_file = fopen(file_name, "r"); |
| 136 |
if (list_file == NULL) |
| 137 |
{ |
| 138 |
|
| 139 |
return; |
| 140 |
} |
| 141 |
*list = empty_list; |
| 142 |
while (fscanf(list_file, "%1023s", buffer) > 0) |
| 143 |
add_item(buffer, list, items_count); |
| 144 |
fclose(list_file); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
#ifdef __STDC__ |
| 150 |
void save_list(String file_name, String *list, int items_count) |
| 151 |
#else |
| 152 |
void save_list(file_name, list, items_count) |
| 153 |
String file_name; |
| 154 |
String *list; |
| 155 |
int items_count; |
| 156 |
#endif |
| 157 |
{ |
| 158 |
FILE *list_file; |
| 159 |
int i; |
| 160 |
|
| 161 |
list_file = fopen(file_name, "w"); |
| 162 |
if (list_file == NULL) |
| 163 |
{ |
| 164 |
|
| 165 |
return; |
| 166 |
} |
| 167 |
for (i = 0; i < items_count; i++) |
| 168 |
fprintf(list_file, "%s\n", list[i]); |
| 169 |
fclose(list_file); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
#ifdef __STDC__ |
| 175 |
int alphacompare(char **i, char **j) |
| 176 |
#else |
| 177 |
int alphacompare(i, j) |
| 178 |
char **i; |
| 179 |
char **j; |
| 180 |
#endif |
| 181 |
{ |
| 182 |
return strcmp(*i, *j); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
#ifdef __STDC__ |
| 188 |
void add_spool_item(String new_info, spool_info ***list, String **nlist, int *items_count) |
| 189 |
#else |
| 190 |
void add_spool_item(new_info, list, nlist, items_count) |
| 191 |
String new_info; |
| 192 |
spool_info ***list; |
| 193 |
String **nlist; |
| 194 |
int *items_count; |
| 195 |
#endif |
| 196 |
{ |
| 197 |
spool_info *new_item; |
| 198 |
char state_buf[10]; |
| 199 |
char name_buf[1024]; |
| 200 |
int n; |
| 201 |
|
| 202 |
new_item = (spool_info *)malloc(sizeof(spool_info)); |
| 203 |
|
| 204 |
new_item->sid = atoi (1 + rptp_parse (new_info, "id")); |
| 205 |
new_item->vol = atoi (rptp_parse (NULL, "volume")); |
| 206 |
new_item->pri = atoi (rptp_parse (NULL, "priority")); |
| 207 |
new_item->count = atoi (rptp_parse (NULL, "count")); |
| 208 |
new_item->seconds = atoi (rptp_parse (NULL, "seconds")); |
| 209 |
new_item->remain = atoi (rptp_parse (NULL, "remain")); |
| 210 |
strcpy (new_item->host, rptp_parse (NULL, "host")); |
| 211 |
strcpy (state_buf, rptp_parse (NULL, "state")); |
| 212 |
strcpy (name_buf, rptp_parse (NULL, "sound")); |
| 213 |
|
| 214 |
if (!strcmp(state_buf, "play")) |
| 215 |
new_item->state = SPOOL_PLAY; |
| 216 |
else |
| 217 |
if (!strcmp(state_buf, "pause")) |
| 218 |
new_item->state = SPOOL_PAUSE; |
| 219 |
else |
| 220 |
if (!strcmp(state_buf, "(wait)")) |
| 221 |
new_item->state = SPOOL_WAIT; |
| 222 |
else |
| 223 |
new_item->state = SPOOL_UNKNOWN; |
| 224 |
|
| 225 |
new_item->sound = (char *)malloc((20 + strlen(name_buf)) * sizeof(char)); |
| 226 |
if ((new_item->seconds > 0) && (new_item->remain > 0)) |
| 227 |
sprintf(new_item->sound, "%6s %3d%% %s", state_buf, |
| 228 |
100 - ((new_item->remain * 100) / new_item->seconds), name_buf); |
| 229 |
else |
| 230 |
sprintf(new_item->sound, "%6s 100%% %s", state_buf, name_buf); |
| 231 |
|
| 232 |
if (*list != NULL) |
| 233 |
*list = (spool_info **)realloc(*list, (*items_count + 1) * |
| 234 |
sizeof(spool_info *)); |
| 235 |
else |
| 236 |
{ |
| 237 |
*items_count = 0; |
| 238 |
*list = (spool_info **)malloc(sizeof(spool_info *)); |
| 239 |
} |
| 240 |
(*list)[*items_count] = new_item; |
| 241 |
if ((*nlist != NULL) && (*nlist != empty_list)) |
| 242 |
*nlist = (String *)realloc(*nlist, (*items_count + 1) * sizeof(String)); |
| 243 |
else |
| 244 |
*nlist = (String *)malloc(sizeof(String)); |
| 245 |
(*nlist)[*items_count] = new_item->sound; |
| 246 |
(*items_count)++; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
#ifdef __STDC__ |
| 251 |
void free_spool_items(spool_info ***list, String **nlist, int *items_count) |
| 252 |
#else |
| 253 |
void free_spool_items(list, nlist, items_count) |
| 254 |
spool_info ***list; |
| 255 |
String **nlist; |
| 256 |
int *items_count; |
| 257 |
#endif |
| 258 |
{ |
| 259 |
int i; |
| 260 |
|
| 261 |
for (i = 0; i < *items_count; i++) |
| 262 |
{ |
| 263 |
free((*nlist)[i]); |
| 264 |
free((*list)[i]); |
| 265 |
} |
| 266 |
*list = NULL; |
| 267 |
*nlist = NULL; |
| 268 |
*items_count = 0; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
#ifdef __STDC__ |
| 274 |
void main(int argc, char *argv[]) |
| 275 |
#else |
| 276 |
void main(argc, argv) |
| 277 |
int argc; |
| 278 |
char *argv[]; |
| 279 |
#endif |
| 280 |
{ |
| 281 |
if ((program_name = strrchr(argv[0], (int) '/')) == NULL) |
| 282 |
program_name = argv[0]; |
| 283 |
else |
| 284 |
program_name++; |
| 285 |
return_code = 0; |
| 286 |
sound_names = empty_list; |
| 287 |
spool_names = empty_list; |
| 288 |
queue_names = empty_list; |
| 289 |
init_application("XJukebox", argc, argv); |
| 290 |
rptp_connect(NULL); |
| 291 |
rptp_get_sound_list(); |
| 292 |
XtAppMainLoop(app_context); |
| 293 |
} |