1 /* Gnome Music Player (GMPC)
2 * Copyright (C) 2004-2009 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpcwiki.sarine.nl/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "bacon-message-connection.h"
27 int main ( int argc
, char **argv
)
29 BaconMessageConnection
*bacon_connection
= NULL
;
34 GOptionContext
*context
;
45 gboolean toggle_view
= FALSE
;
46 gboolean hide_view
= FALSE
;
47 gboolean show_view
= FALSE
;
48 gboolean spawn
= FALSE
;
51 GOptionEntry entries
[] = {
53 "version", 0, 0, G_OPTION_ARG_NONE
, &version
,
54 "Print the version number and exit", NULL
57 "quit", 'q', 0, G_OPTION_ARG_NONE
, &quit
,
58 "Quit the running gmpc", NULL
61 "play", 'c', 0, G_OPTION_ARG_NONE
, &play
,
62 "Give the running gmpc the play command", NULL
65 "pause", 'v', 0, G_OPTION_ARG_NONE
, &pause
,
66 "Give the running gmpc the pause command", NULL
69 "next", 'b', 0, G_OPTION_ARG_NONE
, &next
,
70 "Give the running gmpc the next command", NULL
73 "prev", 'z', 0, G_OPTION_ARG_NONE
, &prev
,
74 "Give the running gmpc the prev command", NULL
77 "stop", 'x', 0, G_OPTION_ARG_NONE
, &stop
,
78 "Give the running gmpc the stop command", NULL
82 "stream", 's', 0, G_OPTION_ARG_STRING
, &stream
,
83 "Give the running gmpc a stream to play", NULL
87 "toggle-view", 't', 0, G_OPTION_ARG_NONE
, &toggle_view
,
88 "Give the running gmpc the command to toggle the window visibility", NULL
92 "hide-view", 'h', 0, G_OPTION_ARG_NONE
, &hide_view
,
93 "Give the running gmpc the command to hide the window.", NULL
96 "show-view", 'k', 0, G_OPTION_ARG_NONE
, &show_view
,
97 "Give the running gmpc the command to show the window.", NULL
100 "spawn", 's', 0, G_OPTION_ARG_NONE
, &spawn
,
101 "Spawn gmpc if not running", NULL
106 gtk_init(&argc
, &argv
);
107 /*Create the commandline option parser */
108 context
= g_option_context_new("GMPC remote program");
109 g_option_context_add_main_entries(context
, entries
, NULL
);
111 /*Time to parse the options */
112 g_option_context_parse(context
, &argc
, &argv
, &error
);
113 g_option_context_free(context
);
115 g_error("Failed to parse command line options: '%s'", error
->message
);
118 bacon_connection
= bacon_message_connection_new("gmpc");
119 while(bacon_connection
)
121 if (!bacon_message_connection_get_is_server (bacon_connection
))
125 printf("send play\n");
126 bacon_message_connection_send(bacon_connection
, "PLAY");
130 printf("send prev\n");
131 bacon_message_connection_send(bacon_connection
, "PREV");
135 printf("send next\n");
136 bacon_message_connection_send(bacon_connection
, "NEXT");
140 printf("send stop\n");
141 bacon_message_connection_send(bacon_connection
, "STOP");
145 printf("send toggle view\n");
146 bacon_message_connection_send(bacon_connection
, "TOGGLE_VIEW");
150 printf("send hide view\n");
151 bacon_message_connection_send(bacon_connection
, "HIDE_VIEW");
155 printf("send show view\n");
156 bacon_message_connection_send(bacon_connection
, "SHOW_VIEW");
160 gchar
*str
= g_strdup_printf("STREAM %s", stream
);
161 printf("Send stream: %s\n", stream
);
162 bacon_message_connection_send(bacon_connection
, str
);
168 printf("send quit\n");
169 bacon_message_connection_send(bacon_connection
, "QUIT");
171 bacon_message_connection_free (bacon_connection
);
176 printf("starting gmpc\n");
178 bacon_message_connection_free (bacon_connection
);
179 bacon_connection
= NULL
;
181 g_spawn_command_line_async("gmpc",&error
);
183 g_error("Failed to spawn gmpc: '%s'", error
->message
);
187 printf("waiting for gmpc to come up\n");
189 bacon_message_connection_free (bacon_connection
);
190 bacon_connection
= bacon_message_connection_new("gmpc");
191 }while(bacon_message_connection_get_is_server (bacon_connection
) && (--count
> 0));
193 g_error("Failed to get gmpc to respond");
196 bacon_message_connection_send(bacon_connection
, "CONNECT");
199 printf("GMPC is not running\n");
200 bacon_message_connection_free (bacon_connection
);
204 g_error("Failed to create IPC connection\n");