43 #include <glib/gi18n.h>
45 #include <glib/gprintf.h>
53 #define usleep(x) Sleep(x*1000)
56 #include <sys/socket.h>
57 #include <sys/types.h>
58 #include <netinet/in.h>
62 #include "snackamp_control.h"
67 gboolean connected = FALSE;
82 struct sockaddr_in host;
89 winsockinit = WSAStartup(0x0101,&winsock);
93 if((h = gethostbyname(
"localhost"))==NULL)
100 host.sin_family = AF_INET;
101 host.sin_addr.s_addr =
102 ((
struct in_addr *) (h->h_addr)) ->s_addr;
103 host.sin_port=htons(port);
109 if((socket_id=socket(AF_INET, SOCK_STREAM, 0))==-1)
120 if ((connect(socket_id,
121 (
void *)&host,
sizeof(host)))==-1)
136 if (NULL==(in=fdopen(socket_id,
"r")) ||
137 NULL==(out=fdopen(socket_id,
"w")))
149 setvbuf(out, NULL, _IOLBF, 0);
160 gchar *cut_begin_end(gchar *result)
165 if (strchr(result,
' ') != NULL)
167 test = strchr(result,
' ');
168 g_snprintf(result, strlen(result),
173 gint result_str = strlen(result);
175 result[result_str - 2] =
'\0';
188 return closesocket(socket_id);
190 return close(socket_id);
201 gchar *result = malloc(1024 *
sizeof(gchar *));
202 strcpy(result,
"disconnected");
208 send(socket_id, message, strlen(message), 0);
215 gint err = recv(socket_id, result, 1024, 0);
226 fgets(result, 1024, in);
233 if (strchr(result,
'\n') != NULL)
236 line_end = strchr(result,
'\n') + 1;
249 gint our_integer = 0;
251 gchar *number = NULL;
252 while ((isdigit(result[i])==0) &&
253 (result[i]!=
'\0') && (result[i]!=
'-'))
258 if (! (number == (result + strlen(result))))
260 our_integer = atoi (number);
275 gchar rate_str[32] = {
'\0' };
276 gchar freq_str[32] = {
'\0' };
277 gchar nch_str[32] = {
'\0' };
282 result = cut_begin_end(result);
285 char *a = strstr(result,
" ");
288 if (strstr(a+1,
" ") != NULL)
289 ptr = strstr(a+1,
" ")+1;
293 while (result[i] !=
' '
294 && isdigit(result[i])
298 "%s%c",rate_str,result[i]);
303 if (strchr(result,
' ') != NULL)
306 test = strchr(result,
' ');
307 g_snprintf(result, strlen(result),
313 while (result[i] !=
' '
314 && isdigit(result[i])
318 "%s%c",freq_str,result[i]);
328 snprintf(nch_str, 32,
"%s", _(
"stereo"));
332 snprintf(nch_str, 32,
"%s", _(
"mono"));
335 gchar *_Kbps = _(
"Kbps");
336 gchar *_Khz = _(
"Khz");
338 g_snprintf(total_infos, 512,
340 rate_str,_Kbps,freq_str, _Khz,nch_str);
344 g_snprintf(total_infos, 512,
364 g_snprintf(temp, 100,
366 "xmms_remote_get_playlist_file",playlist_pos);
369 result = cut_begin_end(result);
423 g_snprintf(temp, 100,
"%s %d\n",
424 "xmms_remote_get_playlist_title",playlist_pos);
426 result = cut_begin_end(result);
449 static gchar *exec_command;
450 exec_command =
"snackAmp";
451 gchar *exec_this = g_strdup_printf(
"%s &", exec_command);
456 ((time(<) - timer) < 8))
469 g_snprintf(temp, 100,
"%s %d\n",
470 "xmms_remote_set_playlist_pos",pos);
509 while ((song = g_list_nth_data(list, i)) != NULL)
511 malloc_int = strlen(song) + 30;
512 local = malloc(malloc_int *
sizeof(gchar *));
513 g_snprintf(local,malloc_int,
"%s {%s}\n",
514 "xmms_remote_playlist_add ", song);
528 g_snprintf(temp, 100,
"%s %d\n",
529 "xmms_remote_set_main_volume",volume);
598 if (playlist_pos > 0)
616 gint hundr_secs_pos = position / 10;
618 gint hundr_secs = hundr_secs_pos % 100;
624 gint secs = hundr_secs_pos / 100;
625 gfloat total_pos = hundr_secs + secs * 100;
630 g_snprintf(temp, 100,
"%s %f\n",
631 "xmms_remote_jump_to_time",
684 result = cut_begin_end(result);