Mercurial > audlegacy
annotate audacious/controlsocket.c @ 1267:d5361c48bb18 trunk
[svn] - more fun
author | nenolod |
---|---|
date | Thu, 15 Jun 2006 22:13:55 -0700 |
parents | bcd1ebd0a7c1 |
children | 2f714bee0645 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include "controlsocket.h" | |
23 | |
24 #include <glib.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 | |
28 #include <unistd.h> | |
29 #include <errno.h> | |
30 #include <sys/time.h> | |
31 #include <sys/types.h> | |
32 #include <sys/socket.h> | |
33 #include <sys/un.h> | |
34 | |
35 #include "main.h" | |
36 #include "equalizer.h" | |
37 #include "mainwin.h" | |
38 #include "input.h" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
383
diff
changeset
|
39 #include "playback.h" |
0 | 40 #include "playlist.h" |
383 | 41 #include "ui_playlist.h" |
0 | 42 #include "prefswin.h" |
43 #include "skin.h" | |
44 #include "libaudacious/beepctrl.h" | |
45 | |
46 | |
47 #define CTRLSOCKET_BACKLOG 100 | |
48 #define CTRLSOCKET_TIMEOUT 100000 | |
49 | |
50 | |
51 static gint session_id = 0; | |
52 | |
53 static gint ctrl_fd = 0; | |
54 static gchar *socket_name = NULL; | |
55 | |
56 static gpointer ctrlsocket_func(gpointer); | |
57 static GThread *ctrlsocket_thread; | |
58 | |
59 static GList *packet_list = NULL; | |
60 static GMutex *packet_list_mutex = NULL; | |
61 | |
62 static gboolean started = FALSE; | |
63 static gboolean going = TRUE; | |
64 static GCond *start_cond = NULL; | |
65 static GMutex *status_mutex = NULL; | |
66 | |
67 | |
68 static void | |
69 ctrlsocket_start_thread(void) | |
70 { | |
71 start_cond = g_cond_new(); | |
72 status_mutex = g_mutex_new(); | |
73 packet_list_mutex = g_mutex_new(); | |
74 | |
75 ctrlsocket_thread = g_thread_create(ctrlsocket_func, NULL, TRUE, NULL); | |
76 } | |
77 | |
78 gboolean | |
79 ctrlsocket_setup(void) | |
80 { | |
81 struct sockaddr_un saddr; | |
82 gint i; | |
83 gint fd; | |
84 | |
85 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { | |
86 g_critical("ctrlsocket_setup(): Failed to open socket: %s", | |
87 strerror(errno)); | |
88 return FALSE; | |
89 } | |
90 | |
91 for (i = 0;; i++) { | |
92 saddr.sun_family = AF_UNIX; | |
93 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), | |
94 "%s/%s_%s.%d", g_get_tmp_dir(), | |
95 CTRLSOCKET_NAME, g_get_user_name(), i); | |
96 | |
97 if (xmms_remote_is_running(i)) { | |
98 if (cfg.allow_multiple_instances) | |
99 continue; | |
100 break; | |
101 } | |
102 | |
103 if ((unlink(saddr.sun_path) == -1) && errno != ENOENT) { | |
104 g_critical | |
105 ("ctrlsocket_setup(): Failed to unlink %s (Error: %s)", | |
106 saddr.sun_path, strerror(errno)); | |
107 break; | |
108 } | |
109 | |
110 if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) { | |
111 g_critical | |
112 ("ctrlsocket_setup(): Failed to assign %s to a socket (Error: %s)", | |
113 saddr.sun_path, strerror(errno)); | |
114 break; | |
115 } | |
116 | |
117 listen(fd, CTRLSOCKET_BACKLOG); | |
118 | |
119 socket_name = g_strdup(saddr.sun_path); | |
120 ctrl_fd = fd; | |
121 session_id = i; | |
122 going = TRUE; | |
123 | |
124 ctrlsocket_start_thread(); | |
125 | |
126 return TRUE; | |
127 } | |
128 | |
129 close(fd); | |
130 | |
131 return FALSE; | |
132 } | |
133 | |
134 gint | |
135 ctrlsocket_get_session_id(void) | |
136 { | |
137 return session_id; | |
138 } | |
139 | |
140 void | |
141 ctrlsocket_cleanup(void) | |
142 { | |
143 if (ctrl_fd) { | |
144 g_mutex_lock(status_mutex); | |
145 going = FALSE; | |
146 g_cond_signal(start_cond); | |
147 g_mutex_unlock(status_mutex); | |
148 | |
149 /* wait for ctrlsocket_thread to terminate */ | |
150 g_thread_join(ctrlsocket_thread); | |
151 | |
152 /* close and remove socket */ | |
153 close(ctrl_fd); | |
154 ctrl_fd = 0; | |
155 unlink(socket_name); | |
156 g_free(socket_name); | |
157 | |
158 g_cond_free(start_cond); | |
159 g_mutex_free(status_mutex); | |
160 g_mutex_free(packet_list_mutex); | |
161 } | |
162 } | |
163 | |
164 void | |
165 ctrlsocket_start(void) | |
166 { | |
167 /* tell control socket thread to go 'live' i.e. start handling | |
168 * packets */ | |
169 g_mutex_lock(status_mutex); | |
170 started = TRUE; | |
171 g_cond_signal(start_cond); | |
172 g_mutex_unlock(status_mutex); | |
173 } | |
174 | |
175 static gint | |
176 write_all(gint fd, gconstpointer buf, size_t count) | |
177 { | |
178 size_t left = count; | |
179 GTimer *timer; | |
180 gulong usec; | |
181 gint written; | |
182 | |
183 timer = g_timer_new(); | |
184 | |
185 do { | |
186 if ((written = write(fd, buf, left)) < 0) { | |
187 count = -1; | |
188 break; | |
189 } | |
190 left -= written; | |
191 buf = (gchar *) buf + written; | |
192 g_timer_elapsed(timer, &usec); | |
193 } | |
194 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
195 | |
196 g_timer_destroy(timer); | |
197 return count - left; | |
198 } | |
199 | |
200 static void | |
201 ctrl_write_packet(gint fd, gpointer data, gint length) | |
202 { | |
203 ServerPktHeader pkthdr; | |
204 | |
205 pkthdr.version = XMMS_PROTOCOL_VERSION; | |
206 pkthdr.data_length = length; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
207 if ((size_t)write_all(fd, &pkthdr, sizeof(ServerPktHeader)) < sizeof(pkthdr)) |
0 | 208 return; |
209 if (data && length > 0) | |
210 write_all(fd, data, length); | |
211 } | |
212 | |
213 static void | |
214 ctrl_write_gint(gint fd, gint val) | |
215 { | |
216 ctrl_write_packet(fd, &val, sizeof(gint)); | |
217 } | |
218 | |
219 static void | |
220 ctrl_write_gfloat(gint fd, gfloat val) | |
221 { | |
222 ctrl_write_packet(fd, &val, sizeof(gfloat)); | |
223 } | |
224 | |
225 static void | |
226 ctrl_write_gboolean(gint fd, gboolean bool) | |
227 { | |
228 ctrl_write_packet(fd, &bool, sizeof(gboolean)); | |
229 } | |
230 | |
231 static void | |
232 ctrl_write_string(gint fd, gchar * string) | |
233 { | |
234 ctrl_write_packet(fd, string, string ? strlen(string) + 1 : 0); | |
235 } | |
236 | |
237 static void | |
238 ctrl_ack_packet(PacketNode * pkt) | |
239 { | |
240 ctrl_write_packet(pkt->fd, NULL, 0); | |
241 close(pkt->fd); | |
242 if (pkt->data) | |
243 g_free(pkt->data); | |
244 g_free(pkt); | |
245 } | |
246 | |
247 static gint | |
248 read_all(gint fd, gpointer buf, size_t count) | |
249 { | |
250 size_t left = count; | |
251 GTimer *timer; | |
252 gulong usec; | |
253 gint r; | |
254 | |
255 timer = g_timer_new(); | |
256 | |
257 do { | |
258 if ((r = read(fd, buf, left)) < 0) { | |
259 count = -1; | |
260 break; | |
261 } | |
262 left -= r; | |
263 buf = (gchar *) buf + r; | |
264 g_timer_elapsed(timer, &usec); | |
265 } | |
266 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
267 | |
268 g_timer_destroy(timer); | |
269 return count - left; | |
270 } | |
271 | |
272 static gboolean | |
273 ctrlsocket_is_going(void) | |
274 { | |
275 gboolean result; | |
276 | |
277 g_mutex_lock(status_mutex); | |
278 result = going; | |
279 g_mutex_unlock(status_mutex); | |
280 | |
281 return result; | |
282 } | |
283 | |
284 static gpointer | |
285 ctrlsocket_func(gpointer arg) | |
286 { | |
287 fd_set set; | |
288 struct timeval tv; | |
289 struct sockaddr_un saddr; | |
290 gint fd, b, i; | |
377 | 291 gint info[3]; |
0 | 292 gint32 v[2]; |
293 PacketNode *pkt; | |
294 socklen_t len; | |
295 gfloat fval[11]; | |
296 | |
297 g_mutex_lock(status_mutex); | |
298 while (!started && going) | |
299 g_cond_wait(start_cond, status_mutex); | |
300 g_mutex_unlock(status_mutex); | |
301 | |
302 while (ctrlsocket_is_going()) { | |
303 FD_ZERO(&set); | |
304 FD_SET(ctrl_fd, &set); | |
305 tv.tv_sec = 0; | |
306 tv.tv_usec = CTRLSOCKET_TIMEOUT; | |
307 len = sizeof(saddr); | |
308 if (select(ctrl_fd + 1, &set, NULL, NULL, &tv) <= 0) | |
309 continue; | |
310 if ((fd = accept(ctrl_fd, (struct sockaddr *) &saddr, &len)) == -1) | |
311 continue; | |
312 | |
313 pkt = g_new0(PacketNode, 1); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
314 if ((size_t)read_all(fd, &pkt->hdr, sizeof(ClientPktHeader)) |
0 | 315 < sizeof(ClientPktHeader)) { |
316 g_free(pkt); | |
317 continue; | |
318 } | |
319 | |
320 if (pkt->hdr.data_length) { | |
321 size_t data_length = pkt->hdr.data_length; | |
322 pkt->data = g_malloc0(data_length); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
323 if ((size_t)read_all(fd, pkt->data, data_length) < data_length) { |
0 | 324 g_free(pkt->data); |
325 g_free(pkt); | |
326 g_warning("ctrlsocket_func(): Incomplete data packet dropped"); | |
327 continue; | |
328 } | |
329 } | |
330 | |
331 pkt->fd = fd; | |
332 switch (pkt->hdr.command) { | |
333 case CMD_GET_VERSION: | |
334 ctrl_write_gint(pkt->fd, 0x09a3); | |
335 ctrl_ack_packet(pkt); | |
336 break; | |
337 case CMD_IS_PLAYING: | |
338 ctrl_write_gboolean(pkt->fd, bmp_playback_get_playing()); | |
339 ctrl_ack_packet(pkt); | |
340 break; | |
341 case CMD_IS_PAUSED: | |
342 ctrl_write_gboolean(pkt->fd, bmp_playback_get_paused()); | |
343 ctrl_ack_packet(pkt); | |
344 break; | |
345 case CMD_GET_PLAYLIST_POS: | |
346 ctrl_write_gint(pkt->fd, playlist_get_position()); | |
347 ctrl_ack_packet(pkt); | |
348 break; | |
349 case CMD_GET_PLAYLIST_LENGTH: | |
350 ctrl_write_gint(pkt->fd, playlist_get_length()); | |
351 ctrl_ack_packet(pkt); | |
352 break; | |
353 case CMD_GET_PLAYQUEUE_LENGTH: | |
354 ctrl_write_gint(pkt->fd, playlist_queue_get_length()); | |
355 ctrl_ack_packet(pkt); | |
356 break; | |
984 | 357 case CMD_PLAYQUEUE_IS_QUEUED: |
358 ctrl_write_gboolean(pkt->fd, | |
359 playlist_is_position_queued(*((guint32 *) pkt->data))); | |
360 ctrl_ack_packet(pkt); | |
361 break; | |
362 case CMD_PLAYQUEUE_GET_POS: | |
363 if (pkt->data) | |
364 ctrl_write_gint(pkt->fd, | |
365 playlist_get_queue_position_number(* | |
366 ((guint32 *) pkt-> | |
367 data))); | |
368 else | |
369 ctrl_write_gint(pkt->fd, 0); | |
370 | |
371 ctrl_ack_packet(pkt); | |
372 break; | |
373 case CMD_PLAYQUEUE_GET_QPOS: | |
374 if (pkt->data) | |
375 ctrl_write_gint(pkt->fd, | |
376 playlist_get_queue_qposition_number(* | |
377 ((guint32 *) pkt-> | |
378 data))); | |
379 else | |
380 ctrl_write_gint(pkt->fd, 0); | |
381 | |
382 ctrl_ack_packet(pkt); | |
383 break; | |
0 | 384 case CMD_GET_OUTPUT_TIME: |
385 if (bmp_playback_get_playing()) | |
386 ctrl_write_gint(pkt->fd, bmp_playback_get_time()); | |
387 else | |
388 ctrl_write_gint(pkt->fd, 0); | |
389 ctrl_ack_packet(pkt); | |
390 break; | |
391 case CMD_GET_VOLUME: | |
392 input_get_volume(&v[0], &v[1]); | |
393 ctrl_write_packet(pkt->fd, v, sizeof(v)); | |
394 ctrl_ack_packet(pkt); | |
395 break; | |
396 case CMD_GET_BALANCE: | |
397 input_get_volume(&v[0], &v[1]); | |
398 if (v[0] < 0 || v[1] < 0) | |
399 b = 0; | |
400 else if (v[0] > v[1]) | |
401 b = -100 + ((v[1] * 100) / v[0]); | |
402 else if (v[1] > v[0]) | |
403 b = 100 - ((v[0] * 100) / v[1]); | |
404 else | |
405 b = 0; | |
406 ctrl_write_gint(pkt->fd, b); | |
407 ctrl_ack_packet(pkt); | |
408 break; | |
409 case CMD_GET_SKIN: | |
410 ctrl_write_string(pkt->fd, bmp_active_skin->path); | |
411 ctrl_ack_packet(pkt); | |
412 break; | |
413 case CMD_GET_PLAYLIST_FILE: | |
414 if (pkt->data) { | |
415 gchar *filename; | |
416 filename = playlist_get_filename(*((guint32 *) pkt->data)); | |
417 ctrl_write_string(pkt->fd, filename); | |
418 g_free(filename); | |
419 } | |
420 else | |
421 ctrl_write_string(pkt->fd, NULL); | |
422 ctrl_ack_packet(pkt); | |
423 break; | |
424 case CMD_GET_PLAYLIST_TITLE: | |
425 if (pkt->data) { | |
426 gchar *title; | |
427 title = playlist_get_songtitle(*((guint32 *) pkt->data)); | |
428 ctrl_write_string(pkt->fd, title); | |
429 g_free(title); | |
430 } | |
431 else | |
432 ctrl_write_string(pkt->fd, NULL); | |
433 ctrl_ack_packet(pkt); | |
434 break; | |
435 case CMD_GET_PLAYLIST_TIME: | |
436 if (pkt->data) | |
437 ctrl_write_gint(pkt->fd, | |
438 playlist_get_songtime(* | |
439 ((guint32 *) pkt-> | |
440 data))); | |
441 else | |
442 ctrl_write_gint(pkt->fd, -1); | |
443 | |
444 ctrl_ack_packet(pkt); | |
445 break; | |
446 case CMD_GET_INFO: | |
447 playback_get_sample_params(&info[0], &info[1], &info[2]); | |
448 ctrl_write_packet(pkt->fd, info, 3 * sizeof(gint)); | |
449 ctrl_ack_packet(pkt); | |
450 break; | |
451 case CMD_GET_EQ_DATA: | |
452 case CMD_SET_EQ_DATA: | |
453 /* obsolete */ | |
454 ctrl_ack_packet(pkt); | |
455 break; | |
456 case CMD_PING: | |
457 ctrl_ack_packet(pkt); | |
458 break; | |
459 case CMD_PLAYLIST_ADD: | |
460 if (pkt->data) { | |
461 guint32 *dataptr = pkt->data; | |
462 while ((len = *dataptr) > 0) { | |
463 gchar *filename; | |
464 | |
465 dataptr++; | |
466 filename = g_malloc0(len); | |
467 memcpy(filename, dataptr, len); | |
468 | |
469 GDK_THREADS_ENTER(); | |
470 playlist_add_url(filename); | |
471 GDK_THREADS_LEAVE(); | |
472 | |
473 g_free(filename); | |
474 dataptr += (len + 3) / 4; | |
475 } | |
476 } | |
477 ctrl_ack_packet(pkt); | |
478 break; | |
479 case CMD_PLAYLIST_ADD_URL_STRING: | |
480 GDK_THREADS_ENTER(); | |
481 playlist_add_url(pkt->data); | |
482 GDK_THREADS_LEAVE(); | |
483 | |
484 ctrl_ack_packet(pkt); | |
485 break; | |
486 case CMD_PLAYLIST_INS_URL_STRING: | |
487 if (pkt->data) { | |
488 gint pos = *(gint *) pkt->data; | |
489 gchar *ptr = pkt->data; | |
490 ptr += sizeof(gint); | |
491 playlist_ins_url(ptr, pos); | |
492 } | |
493 ctrl_ack_packet(pkt); | |
494 break; | |
495 case CMD_PLAYLIST_DELETE: | |
496 GDK_THREADS_ENTER(); | |
497 playlist_delete_index(*((guint32 *) pkt->data)); | |
498 GDK_THREADS_LEAVE(); | |
499 ctrl_ack_packet(pkt); | |
500 break; | |
501 case CMD_PLAYLIST_CLEAR: | |
502 GDK_THREADS_ENTER(); | |
503 playlist_clear(); | |
504 mainwin_clear_song_info(); | |
505 mainwin_set_info_text(); | |
506 GDK_THREADS_LEAVE(); | |
507 ctrl_ack_packet(pkt); | |
508 break; | |
509 case CMD_IS_MAIN_WIN: | |
510 ctrl_write_gboolean(pkt->fd, cfg.player_visible); | |
511 ctrl_ack_packet(pkt); | |
512 break; | |
513 case CMD_IS_PL_WIN: | |
514 ctrl_write_gboolean(pkt->fd, cfg.playlist_visible); | |
515 ctrl_ack_packet(pkt); | |
516 break; | |
517 case CMD_IS_EQ_WIN: | |
518 ctrl_write_gboolean(pkt->fd, cfg.equalizer_visible); | |
519 ctrl_ack_packet(pkt); | |
520 break; | |
521 case CMD_IS_REPEAT: | |
522 ctrl_write_gboolean(pkt->fd, cfg.repeat); | |
523 ctrl_ack_packet(pkt); | |
524 break; | |
525 case CMD_IS_SHUFFLE: | |
526 ctrl_write_gboolean(pkt->fd, cfg.shuffle); | |
527 ctrl_ack_packet(pkt); | |
528 break; | |
529 case CMD_IS_ADVANCE: | |
530 ctrl_write_gboolean(pkt->fd, !cfg.no_playlist_advance); | |
531 ctrl_ack_packet(pkt); | |
532 break; | |
533 case CMD_GET_EQ: | |
534 fval[0] = equalizerwin_get_preamp(); | |
535 for (i = 0; i < 10; i++) | |
536 fval[i + 1] = equalizerwin_get_band(i); | |
537 ctrl_write_packet(pkt->fd, fval, 11 * sizeof(gfloat)); | |
538 ctrl_ack_packet(pkt); | |
539 break; | |
540 case CMD_GET_EQ_PREAMP: | |
541 ctrl_write_gfloat(pkt->fd, equalizerwin_get_preamp()); | |
542 ctrl_ack_packet(pkt); | |
543 break; | |
544 case CMD_GET_EQ_BAND: | |
545 i = *((guint32 *) pkt->data); | |
546 ctrl_write_gfloat(pkt->fd, equalizerwin_get_band(i)); | |
547 ctrl_ack_packet(pkt); | |
548 break; | |
549 default: | |
550 g_mutex_lock(packet_list_mutex); | |
551 packet_list = g_list_append(packet_list, pkt); | |
552 ctrl_write_packet(pkt->fd, NULL, 0); | |
553 close(pkt->fd); | |
554 g_mutex_unlock(packet_list_mutex); | |
555 break; | |
556 } | |
557 } | |
558 g_thread_exit(NULL); | |
559 | |
560 /* Used to suppress GCC warnings. Sometimes you'd wish C has | |
561 native threading support :p */ | |
562 return NULL; | |
563 } | |
564 | |
565 void | |
566 ctrlsocket_check(void) | |
567 { | |
568 GList *pkt_list, *next; | |
569 PacketNode *pkt; | |
570 gpointer data; | |
571 guint32 v[2], i, num; | |
572 gboolean tbool; | |
573 gfloat *fval, f; | |
574 | |
575 g_mutex_lock(packet_list_mutex); | |
576 for (pkt_list = packet_list; pkt_list; pkt_list = next) { | |
577 pkt = pkt_list->data; | |
578 data = pkt->data; | |
579 | |
580 switch (pkt->hdr.command) { | |
581 case CMD_PLAY: | |
582 if (bmp_playback_get_paused()) | |
583 bmp_playback_pause(); | |
584 else if (playlist_get_length()) | |
585 bmp_playback_initiate(); | |
586 else | |
587 mainwin_eject_pushed(); | |
588 break; | |
589 case CMD_PAUSE: | |
590 bmp_playback_pause(); | |
591 break; | |
592 case CMD_STOP: | |
906 | 593 ip_data.stop = TRUE; |
0 | 594 bmp_playback_stop(); |
906 | 595 ip_data.stop = FALSE; |
0 | 596 mainwin_clear_song_info(); |
597 break; | |
598 case CMD_PLAY_PAUSE: | |
599 if (bmp_playback_get_playing()) | |
600 bmp_playback_pause(); | |
601 else | |
602 bmp_playback_initiate(); | |
603 break; | |
604 case CMD_PLAYQUEUE_ADD: | |
605 num = *((guint32 *) data); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
606 if (num < (guint)playlist_get_length()) |
0 | 607 playlist_queue_position(num); |
608 break; | |
609 case CMD_PLAYQUEUE_REMOVE: | |
610 num = *((guint32 *) data); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
611 if (num < (guint)playlist_get_length()) |
0 | 612 playlist_queue_remove(num); |
613 break; | |
984 | 614 case CMD_PLAYQUEUE_CLEAR: |
615 playlist_clear_queue(); | |
616 break; | |
0 | 617 case CMD_SET_PLAYLIST_POS: |
618 num = *((guint32 *) data); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
619 if (num < (guint)playlist_get_length()) |
0 | 620 playlist_set_position(num); |
621 break; | |
622 case CMD_JUMP_TO_TIME: | |
623 num = *((guint32 *) data); | |
624 if (playlist_get_current_length() > 0 && | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
625 num < (guint)playlist_get_current_length()) |
0 | 626 bmp_playback_seek(num / 1000); |
627 break; | |
628 case CMD_SET_VOLUME: | |
629 v[0] = ((guint32 *) data)[0]; | |
630 v[1] = ((guint32 *) data)[1]; | |
631 for (i = 0; i < 2; i++) { | |
632 if (v[i] > 100) | |
633 v[i] = 100; | |
634 } | |
635 input_set_volume(v[0], v[1]); | |
636 break; | |
637 case CMD_SET_SKIN: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
638 if (has_x11_connection == TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
639 bmp_active_skin_load(data); |
0 | 640 break; |
641 case CMD_PL_WIN_TOGGLE: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
642 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
643 break; |
0 | 644 tbool = *((gboolean *) data); |
645 if (tbool) | |
646 playlistwin_show(); | |
647 else | |
648 playlistwin_hide(); | |
649 break; | |
650 case CMD_EQ_WIN_TOGGLE: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
651 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
652 break; |
0 | 653 tbool = *((gboolean *) data); |
654 equalizerwin_show(!!tbool); | |
655 break; | |
656 case CMD_SHOW_PREFS_BOX: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
657 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
658 break; |
0 | 659 show_prefs_window(); |
660 break; | |
984 | 661 case CMD_SHOW_JTF_BOX: |
662 if (has_x11_connection != TRUE) | |
663 break; | |
664 mainwin_jump_to_file(); | |
665 break; | |
0 | 666 case CMD_TOGGLE_AOT: |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
667 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
668 break; |
0 | 669 tbool = *((gboolean *) data); |
670 mainwin_set_always_on_top(tbool); | |
671 break; | |
672 case CMD_SHOW_ABOUT_BOX: | |
673 break; | |
674 case CMD_EJECT: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
675 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
676 break; |
0 | 677 mainwin_eject_pushed(); |
678 break; | |
679 case CMD_PLAYLIST_PREV: | |
680 playlist_prev(); | |
681 break; | |
682 case CMD_PLAYLIST_NEXT: | |
683 playlist_next(); | |
684 break; | |
685 case CMD_TOGGLE_REPEAT: | |
686 mainwin_repeat_pushed(!cfg.repeat); | |
687 break; | |
688 case CMD_TOGGLE_SHUFFLE: | |
689 mainwin_shuffle_pushed(!cfg.shuffle); | |
690 break; | |
691 case CMD_TOGGLE_ADVANCE: | |
692 /* FIXME: to be implemented */ | |
693 break; | |
694 case CMD_MAIN_WIN_TOGGLE: | |
680
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
695 if (has_x11_connection != TRUE) |
8282b365f6cb
[svn] - Add some sanity checking to make sure we can't do X11 stuff when running headless.
nenolod
parents:
625
diff
changeset
|
696 break; |
0 | 697 tbool = *((gboolean *) data); |
698 mainwin_show(!!tbool); | |
699 break; | |
700 case CMD_SET_EQ: | |
701 if (pkt->hdr.data_length >= 11 * sizeof(gfloat)) { | |
702 fval = (gfloat *) data; | |
703 equalizerwin_set_preamp(fval[0]); | |
704 for (i = 0; i < 10; i++) | |
705 equalizerwin_set_band(i, fval[i + 1]); | |
706 } | |
707 break; | |
708 case CMD_SET_EQ_PREAMP: | |
709 f = *((gfloat *) data); | |
710 equalizerwin_set_preamp(f); | |
711 break; | |
712 case CMD_SET_EQ_BAND: | |
713 if (pkt->hdr.data_length >= sizeof(gint) + sizeof(gfloat)) { | |
714 i = *((gint *) data); | |
715 f = *((gfloat *) ((gchar *) data + sizeof(gint))); | |
716 equalizerwin_set_band(i, f); | |
717 } | |
718 break; | |
719 case CMD_QUIT: | |
720 /* | |
721 * We unlock the packet_list_mutex to | |
722 * avoid that cleanup_ctrlsocket() can | |
723 * deadlock, mainwin_quit_cb() will | |
724 * never return anyway, so this will | |
725 * work ok. | |
726 */ | |
727 g_mutex_unlock(packet_list_mutex); | |
728 mainwin_quit_cb(); | |
729 break; | |
730 case CMD_ACTIVATE: | |
731 gtk_window_present(GTK_WINDOW(mainwin)); | |
732 break; | |
733 default: | |
734 g_message("Unknown socket command received"); | |
735 break; | |
736 } | |
737 next = g_list_next(pkt_list); | |
738 packet_list = g_list_remove_link(packet_list, pkt_list); | |
739 g_list_free_1(pkt_list); | |
740 if (pkt->data) | |
741 g_free(pkt->data); | |
742 g_free(pkt); | |
743 } | |
744 g_mutex_unlock(packet_list_mutex); | |
745 } |