2 * Copyright (C) 2004-2005 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
8 //#define PRINTF printf
11 #include <gkrellm2/gkrellm.h>
19 static void create_para_ctrl(GtkWidget *, gint);
20 static void update_para_ctrl(void);
21 static void create_tab(GtkWidget *);
22 static void apply_config(void);
23 static void load_config(gchar *);
24 static void save_config(FILE *);
26 static GkrellmMonitor monitor = {
27 "Parakrell", /* Name, for config tab. */
28 0, /* Id, 0 if a plugin */
29 create_para_ctrl, /* The create function */
30 update_para_ctrl, /* The update function */
31 create_tab, /* The config tab create function */
32 apply_config, /* Apply the config function */
33 save_config, /* Save user config */
34 load_config, /* Load user config */
35 "para_krell", /* config keyword */
36 NULL, /* Undefined 2 */
37 NULL, /* Undefined 1 */
38 NULL, /* Undefined 0 */
39 MON_APM, /* Insert plugin before this monitor */
40 NULL, /* Handle if a plugin, filled in by GKrellM */
41 NULL /* path if a plugin, filled in by GKrellM */
45 GkrellmPiximage *image;
46 GkrellmDecalbutton *button;
48 double x_scale,y_scale;
51 static ControlButton prev_button = {
62 GkrellmPiximage *piximage;
64 GtkWidget *fileread_vbox;
66 gint song_change_input_id;
68 GIOChannel *song_change_channel;
70 static struct timeval sc_open_time;
72 static gchar *info_text =
73 "Parakrell displays an image corresponding to the soundfile\n"
74 "currently played by paraslash.\n\n"
76 "The plugin's panel is divided in 9 small squares, like \n"
77 "the numpad on a PC keyboard. For each square there is an \n"
78 "associated button and a number between 1 and 9.\n \n"
80 "Each button is bound to three different commands for left, \n"
81 "middle and right mouse button. Middle and right button are \n"
82 "reserved for setting volume and jumping around in the song, \n"
83 "respectively. Left button works as follows:\n \n"
85 "7 8 9 7: slider, 8: sdl_gui, 9: next \n"
86 "4 5 6 4: ps, 5: play, 6: dbadm \n"
87 "1 2 3 1: stop, 2: gui, 3: pause\n"
90 "Andre Noll <maan@systemlinux.org>\n"
91 "Copyright (C) 2004-2005\n"
92 "Distributed under the GNU General Public License.\n";
96 static gboolean launch_cmd(char *cmd)
103 PRINTF("%s: \n", __func__);
104 if (!cmd || *cmd == '\0')
107 g_shell_parse_argv(cmd, NULL, &argv, NULL);
112 G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
119 gkrellm_message_dialog(NULL, err->message);
126 static gboolean cb_in_button(GkrellmDecalbutton *b,
127 GdkEventButton *ev, ControlButton *cbut)
129 gint x, y, area, width = gkrellm_chart_width();
130 x = (int) (3 * ev->x / width);
131 y = (int) (3 - 3 * ev->y / width);
132 area = 3 * y + x + 1;
135 PRINTF("%s: button %i pressed on area %i\n", __func__,
137 if (ev->button == 1) {
140 launch_cmd("para_client stop");
143 launch_cmd("xterm -e para_gui -a");
146 launch_cmd("para_client pause");
149 launch_cmd("para_client ps");
152 launch_cmd("para_client play");
155 launch_cmd("xterm -e para_dbadm");
158 launch_cmd("para_slider");
161 launch_cmd("para_sdl_gui -f");
164 launch_cmd("para_client next");
169 sprintf(buf, "%s %i", ev->button == 2? "aumix -v" : "para_client jmp",
171 return launch_cmd(buf);
174 static void make_button(ControlButton *cbut, gint fn_id)
176 PRINTF("%s: gkrellm_make_scaled_button\n", __func__);
177 cbut->button = gkrellm_make_scaled_button(
181 GINT_TO_POINTER(fn_id),
192 PRINTF("%s: making botton\n", __func__);
193 gkrellm_set_in_button_callback(cbut->button, cb_in_button, cbut);
197 static void load_img(void)
199 gint width = gkrellm_chart_width();
204 gchar *filename = gkrellm_make_data_file_name("para", "pic.jpg");
206 PRINTF("%s: Opening %s\n", __func__, filename);
207 if ((out = creat(filename, S_IRUSR | S_IWUSR)) < 0) {
211 pipe = popen("para_client pic", "r");
214 while ((ret = read(fileno(pipe), buf, sizeof(buf) - 1)) > 0) {
215 if (write(out, buf, ret) < 0) {
222 PRINTF("%s: Read Error\n", __func__);
225 PRINTF("%s: new pic created (%i bytes)\n", __func__, num_read);
230 gkrellm_destroy_piximage(piximage);
233 PRINTF("%s: creating new piximage\n", __func__);
234 piximage = gkrellm_piximage_new_from_file(filename);
236 PRINTF("%s: can not load image\n", __func__);
239 pixbuf = gkrellm_scale_piximage_to_pixbuf(piximage, width, width);
248 static void create_tab(GtkWidget *tab_vbox)
250 GtkTextBuffer *textbuf;
252 GtkWidget *scrolled, *vbox = tab_vbox;
254 PRINTF("%s: \n", __func__);
256 scrolled = gtk_scrolled_window_new(NULL, NULL);
257 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
258 GTK_POLICY_AUTOMATIC,
259 GTK_POLICY_AUTOMATIC);
260 textbuf = gtk_text_buffer_new(NULL);
261 gtk_text_buffer_set_text(textbuf, info_text, -1);
262 text = gtk_text_view_new_with_buffer(textbuf);
263 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
264 gtk_container_add(GTK_CONTAINER(scrolled), text);
265 gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0);
268 static gboolean song_change(GIOChannel *channel, GIOCondition condition,
274 PRINTF("%s: input condition %i "
275 "(song_change channel fd = %i)\n", __func__, condition,
276 g_io_channel_unix_get_fd(song_change_channel));
277 if (!song_change_fd) {
278 PRINTF("%s: no song_change_fd\n", __func__);
281 if (!(condition & (G_IO_IN | G_IO_PRI))) {
282 PRINTF("%s: song change pipe died\n", __func__);
283 song_change_fd = NULL;
288 if (!channel->is_readable) {
289 PRINTF("%s: fd not readable\n", __func__);
292 PRINTF("%s: reading data\n", __func__);
293 if (g_io_channel_read_line(channel, &str_return,
294 &length, NULL, NULL) == G_IO_STATUS_NORMAL) {
295 PRINTF("%s: next song: %s", __func__, str_return);
297 if (channel != song_change_channel)
303 g_io_channel_unref(channel);
304 g_io_channel_shutdown(channel, TRUE, NULL);
308 static void create_song_change(void)
312 gettimeofday(&sc_open_time, NULL);
313 PRINTF("%s: para_client sc\n", __func__);
314 song_change_fd = popen("para_client sc", "r");
315 if (!song_change_fd) {
316 PRINTF("%s: para_client sc failed\n", __func__);
319 song_change_channel = g_io_channel_unix_new(fileno(song_change_fd));
320 g_io_channel_set_close_on_unref(song_change_channel, TRUE);
321 g_io_add_watch(song_change_channel,
322 G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
323 &song_change, panel);
326 static void update_para_ctrl(void)
328 GdkDrawable *drawable = panel->drawing_area->window;
329 gint width = gkrellm_chart_width();
332 PRINTF("%s: No drawable\n", __func__);
334 gkrellm_paste_pixbuf(pixbuf, drawable, 0, 0, width, width);
335 if (!song_change_fd) {
337 PRINTF("%s: no song_change_fd\n", __func__);
339 gettimeofday(&now, NULL);
340 if (now.tv_sec > sc_open_time.tv_sec + 5)
341 create_song_change();
345 static void destroy_panel(void)
347 PRINTF("%s: \n", __func__);
350 PRINTF("%s: destroying panel\n", __func__);
351 gkrellm_panel_destroy(panel);
356 static void destroy_song_change(void)
358 PRINTF("%s: \n", __func__);
363 static void destroy_all(void)
365 // destroy_song_change();
369 static void create_para_ctrl(GtkWidget *vbox, gint first_create)
371 gint style_id = gkrellm_lookup_meter_style_id(UPTIME_STYLE_NAME);
372 GkrellmStyle *style = gkrellm_meter_style(style_id);
373 gint width = gkrellm_chart_width();
376 create_song_change();
377 panel = gkrellm_panel_new0();
378 gkrellm_panel_configure(panel, NULL, style);
379 gkrellm_panel_configure_set_height(panel, width);
380 PRINTF("%s: creating panel\n", __func__);
381 gkrellm_panel_create(vbox, &monitor, panel);
382 make_button(&prev_button, 1);
385 static void apply_config(void)
387 PRINTF("%s: \n", __func__);
390 static void load_config(gchar * arg)
392 PRINTF("%s: \n", __func__);
396 static void save_config(FILE * f)
398 PRINTF("%s: \n", __func__);
401 GkrellmMonitor *gkrellm_init_plugin(void)