156
|
1 /* Lirc plugin
|
|
2
|
|
3 Copyright (C) 2005 Audacious development team
|
|
4
|
|
5 Copyright (c) 1998-1999 Carl van Schaik (carl@leg.uct.ac.za)
|
|
6
|
|
7 Copyright (C) 2000 Christoph Bartelmus (xmms@bartelmus.de)
|
|
8
|
|
9 some code was stolen from:
|
|
10 IRman plugin for xmms by Charles Sielski (stray@teklabs.net)
|
|
11
|
|
12 This program is free software; you can redistribute it and/or modify
|
|
13 it under the terms of the GNU General Public License as published by
|
|
14 the Free Software Foundation; either version 2 of the License, or
|
|
15 (at your option) any later version.
|
|
16
|
|
17 This program is distributed in the hope that it will be useful,
|
|
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 GNU General Public License for more details.
|
|
21
|
|
22 You should have received a copy of the GNU General Public License
|
|
23 along with this program; if not, write to the Free Software
|
|
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25 */
|
|
26
|
|
27 #ifdef HAVE_CONFIG_H
|
|
28 # include "config.h"
|
|
29 #endif
|
|
30
|
|
31 #include <stdio.h>
|
|
32 #include <unistd.h>
|
|
33 #include <fcntl.h>
|
|
34 #include <string.h>
|
|
35 #include <signal.h>
|
|
36 #include <stdlib.h>
|
|
37 #include <ctype.h>
|
|
38
|
|
39 #include <gtk/gtk.h>
|
|
40
|
|
41 #include <glib.h>
|
554
|
42 #include <glib/gi18n.h>
|
156
|
43
|
|
44 #include "audacious/plugin.h"
|
307
|
45 #include "libaudacious/configdb.h"
|
156
|
46 #include "libaudacious/beepctrl.h"
|
|
47
|
|
48 #include <lirc/lirc_client.h>
|
|
49
|
|
50 #include "lirc.h"
|
|
51
|
|
52 const char *plugin_name="LIRC Plugin " VERSION;
|
|
53
|
|
54 GeneralPlugin lirc_plugin = {
|
|
55 NULL,
|
|
56 NULL,
|
|
57 -1,
|
|
58 NULL,
|
|
59 init,
|
|
60 about,
|
|
61 configure,
|
|
62 cleanup,
|
|
63 };
|
|
64
|
|
65 GeneralPlugin *get_gplugin_info(void)
|
|
66 {
|
554
|
67 lirc_plugin.description = g_strdup_printf(_("LIRC Plugin"));
|
156
|
68 return(&lirc_plugin);
|
|
69 }
|
|
70
|
|
71 int lirc_fd=-1;
|
|
72 struct lirc_config *config=NULL;
|
|
73 gint tracknr=0;
|
|
74 gint mute=0; /* mute flag */
|
|
75 gint mute_vol=0; /* holds volume before mute */
|
|
76
|
|
77 gint input_tag;
|
|
78
|
|
79 int select_tag=0;
|
|
80 GtkWidget *select_popup=NULL;
|
|
81 GtkStyle *popup_style=NULL;
|
|
82 GList *select_list=NULL;
|
|
83 GtkWidget *fsd;
|
|
84 gchar *fontname;
|
|
85
|
|
86 struct select_info
|
|
87 {
|
|
88 char *s;
|
|
89 size_t common;
|
|
90 };
|
|
91
|
|
92 struct title_info
|
|
93 {
|
|
94 char *s;
|
|
95 int pos;
|
|
96 };
|
|
97
|
|
98 void clear_select_list(GList **list)
|
|
99 {
|
|
100 GList *l;
|
|
101
|
|
102 l=*list;
|
|
103 while(l!=NULL)
|
|
104 {
|
|
105 free(((struct select_info *) (l->data))->s);
|
|
106 free(l->data);
|
|
107 l=g_list_remove_link(l,l);
|
|
108 }
|
|
109 *list=NULL;
|
|
110 }
|
|
111
|
|
112 void clear_title_list(GList **list)
|
|
113 {
|
|
114 GList *l;
|
|
115
|
|
116 l=*list;
|
|
117 while(l!=NULL)
|
|
118 {
|
|
119 free(((struct title_info *) (l->data))->s);
|
|
120 free(l->data);
|
|
121 l=g_list_remove_link(l,l);
|
|
122 }
|
|
123 *list=NULL;
|
|
124 }
|
|
125
|
|
126 gchar *get_title_postfix(gchar *title)
|
|
127 {
|
|
128 gchar *match;
|
|
129 GList *scan_list;
|
|
130 struct select_info *si;
|
|
131 size_t skip;
|
|
132
|
|
133 match=title;
|
|
134 scan_list=select_list;
|
|
135 si=(struct select_info *) (scan_list->data);
|
|
136 while(*match)
|
|
137 {
|
|
138 if(!isalnum(*match))
|
|
139 {
|
|
140 match++;
|
|
141 }
|
|
142 else
|
|
143 {
|
|
144 if(strchr(si->s,toupper(*match))!=NULL)
|
|
145 {
|
|
146 skip=si->common;
|
|
147 while(skip>0)
|
|
148 {
|
|
149 if(isalnum(*match))
|
|
150 {
|
|
151 skip--;
|
|
152 }
|
|
153 match++;
|
|
154 if(!*match)
|
|
155 {
|
|
156 break;
|
|
157 }
|
|
158 }
|
|
159 scan_list=g_list_next(scan_list);
|
|
160 if(scan_list==NULL)
|
|
161 {
|
|
162 while(!isalnum(*match) && *match)
|
|
163 {
|
|
164 match++;
|
|
165 }
|
|
166 return(match);
|
|
167 }
|
|
168 si=(struct select_info *) (scan_list->data);
|
|
169 }
|
|
170 else
|
|
171 {
|
|
172 break;
|
|
173 }
|
|
174 }
|
|
175 }
|
|
176 return(NULL);
|
|
177 }
|
|
178
|
|
179 #define SELECT_BORDER 8
|
|
180
|
|
181 gint remove_select_popup(GtkWidget **select_popup)
|
|
182 {
|
|
183 gtk_widget_destroy(*select_popup);
|
|
184 *select_popup=NULL;
|
|
185 select_tag=0;
|
|
186 return(FALSE);
|
|
187 }
|
|
188
|
|
189 /*void select_title(char *s,int num)
|
|
190 {
|
|
191 GdkFont *font;
|
|
192 GtkStyle *style;
|
|
193 int gap,baseline_skip;
|
|
194 int width,height,x,y;
|
|
195 GList *new_list,*scan_list;
|
|
196 GList *title_list=NULL;
|
|
197 int length,i;
|
|
198 gchar *title;
|
|
199 struct select_info *si;
|
|
200 struct title_info *ti;
|
|
201
|
|
202 if(select_tag!=0)
|
|
203 {
|
|
204 gtk_timeout_remove(select_tag);
|
|
205 remove_select_popup(&select_popup);
|
|
206 }
|
|
207 if(s!=NULL)
|
|
208 {
|
|
209 si=malloc(sizeof(*si));
|
|
210 if(si==NULL)
|
|
211 {
|
|
212 return;
|
|
213 }
|
|
214 si->s=strdup(s);
|
|
215 si->common=1;
|
|
216 if(si->s==NULL)
|
|
217 {
|
|
218 free(si);
|
|
219 return;
|
|
220 }
|
|
221 new_list=g_list_append(select_list,si);
|
|
222 if(new_list==NULL)
|
|
223 {
|
|
224 free(si->s);
|
|
225 free(si);
|
|
226 return;
|
|
227 }
|
|
228
|
|
229 select_list=new_list;
|
|
230 }
|
|
231
|
|
232 scan_list=select_list;
|
|
233 while(scan_list)
|
|
234 {
|
|
235 scan_list=g_list_next(scan_list);
|
|
236 }
|
|
237
|
|
238 length=xmms_remote_get_playlist_length
|
|
239 (lirc_plugin.xmms_session);
|
|
240 for(i=0;i<length;i++)
|
|
241 {
|
|
242 title=xmms_remote_get_playlist_title
|
|
243 (lirc_plugin.xmms_session,i);
|
|
244 if(get_title_postfix(title)!=NULL)
|
|
245 {
|
|
246 ti=malloc(sizeof(*ti));
|
|
247 if(ti==NULL) break;
|
|
248 ti->s=strdup(title);
|
|
249 if(ti->s==NULL)
|
|
250 {
|
|
251 free(ti);
|
|
252 break;
|
|
253 }
|
|
254 ti->pos=i;
|
|
255 new_list=g_list_append(title_list,ti);
|
|
256 if(new_list==NULL)
|
|
257 {
|
|
258 free(ti->s);
|
|
259 free(ti);
|
|
260 break;
|
|
261 }
|
|
262 title_list=new_list;
|
|
263 }
|
|
264 }
|
|
265 select_popup=gtk_window_new(GTK_WINDOW_POPUP);
|
|
266 if(popup_style)
|
|
267 {
|
|
268 if(fontname!=NULL)
|
|
269 {
|
|
270 font=gdk_font_load(fontname);
|
|
271 }
|
|
272 else
|
|
273 {
|
|
274 font=gdk_font_load
|
|
275 ("-xxl-*-medium-r-semicondensed-*-*-*-75-75-*-*-*-*");
|
|
276 }
|
|
277 if(font) popup_style->font=font;
|
|
278 gtk_widget_set_style(select_popup,popup_style);
|
|
279 }
|
|
280 gtk_widget_set_app_paintable(select_popup,TRUE);
|
|
281 gtk_window_set_policy(GTK_WINDOW(select_popup),FALSE,FALSE,TRUE);
|
|
282 gtk_widget_set_name(select_popup,"LIRC select list");
|
|
283 style=select_popup->style;
|
|
284 font=style->font;
|
|
285 gap=(font->ascent+font->descent)/4;
|
|
286 if(gap<2) gap=2;
|
|
287 baseline_skip=font->ascent+font->descent+gap;
|
|
288
|
|
289 if(title_list==NULL)
|
|
290 {
|
|
291 gchar *text="No match.";
|
|
292
|
|
293 x=gdk_string_width(font,text);
|
|
294 width=SELECT_BORDER*2+x;
|
|
295 height=SELECT_BORDER*2+baseline_skip-gap;
|
|
296 gtk_widget_set_usize(select_popup,width,height);
|
|
297 x=(gdk_screen_width()-width)/2;
|
|
298 if(x<0) x=0;
|
|
299 y=(gdk_screen_height()-height)/2;
|
|
300 if(y<0) y=0;
|
|
301 gtk_widget_popup(select_popup,x,y);
|
|
302 gtk_paint_box(select_popup->style,select_popup->window,
|
|
303 GTK_STATE_NORMAL,GTK_SHADOW_OUT,
|
|
304 NULL,GTK_WIDGET(select_popup),
|
|
305 "LIRC select list",0,0,-1,-1);
|
|
306
|
|
307 gtk_paint_string(style,select_popup->window,
|
|
308 GTK_STATE_NORMAL,NULL,
|
|
309 GTK_WIDGET(select_popup),
|
|
310 "LIRC select item",
|
|
311 SELECT_BORDER,
|
|
312 SELECT_BORDER+font->ascent,
|
|
313 "No match.");
|
|
314
|
|
315 clear_select_list(&select_list);
|
|
316 }
|
|
317 else
|
|
318 {
|
|
319 int count;
|
|
320 int common;
|
|
321 int pass;
|
|
322 int x1,x2,x3;
|
|
323
|
|
324 if(s==NULL && num>0)
|
|
325 {
|
|
326 scan_list=title_list;
|
|
327 while(scan_list!=NULL)
|
|
328 {
|
|
329 num--;
|
|
330 if(num==0)
|
|
331 {
|
|
332 clear_select_list(&select_list);
|
|
333 xmms_remote_set_playlist_pos
|
|
334 (lirc_plugin.xmms_session,
|
|
335 ((struct title_info *) (scan_list->data))->pos);
|
|
336 break;
|
|
337 }
|
|
338 scan_list=g_list_next(scan_list);
|
|
339 }
|
|
340 clear_title_list(&title_list);
|
|
341 return;
|
|
342 }
|
|
343
|
|
344 check how many chars are common
|
|
345 scan_list=title_list;
|
|
346 title=get_title_postfix
|
|
347 (((struct title_info *) scan_list->data)->s);
|
|
348 common=0;
|
|
349 count=strlen(title);
|
|
350 for(i=0;i<count;i++)
|
|
351 {
|
|
352 if(isalnum(title[i])) common++;
|
|
353 }
|
|
354 scan_list=g_list_next(scan_list);
|
|
355 while(scan_list!=NULL)
|
|
356 {
|
|
357 gchar *title1,*title2;
|
|
358
|
|
359 count=0;
|
|
360 title1=title;
|
|
361 title2=get_title_postfix
|
|
362 (((struct title_info *) scan_list->data)->s);
|
|
363 while(*title1 && *title2)
|
|
364 {
|
|
365 if(!isalnum(*title1)) {title1++;continue;}
|
|
366 if(!isalnum(*title2)) {title2++;continue;}
|
|
367 if(toupper(*title1)==toupper(*title2))
|
|
368 {
|
|
369 count++;
|
|
370 title1++;
|
|
371 title2++;
|
|
372 }
|
|
373 else
|
|
374 {
|
|
375 break;
|
|
376 }
|
|
377 }
|
|
378 if(count<common) common=count;
|
|
379 scan_list=g_list_next(scan_list);
|
|
380 }
|
|
381 scan_list=select_list;
|
|
382 while(g_list_next(scan_list)!=NULL)
|
|
383 {
|
|
384 scan_list=g_list_next(scan_list);
|
|
385 }
|
|
386 ((struct select_info *) (scan_list->data))->common=common+1;
|
|
387
|
|
388 print out selected titles
|
|
389 x1=x2=x3=0;
|
|
390 count=0;
|
|
391 pass=1;
|
|
392 scan_list=title_list;
|
|
393 while(scan_list!=NULL || pass==1)
|
|
394 {
|
|
395 gchar *title,*postfix,help;
|
|
396 char buffer[20];
|
|
397
|
|
398 count++;
|
|
399 title=((struct title_info *) scan_list->data)->s;
|
|
400 postfix=get_title_postfix(title);
|
|
401 help=postfix[0];
|
|
402 postfix[0]=0;
|
|
403
|
|
404 snprintf(buffer,20,"%2d:",count);
|
|
405 if(pass==1)
|
|
406 {
|
|
407 x=gdk_string_width
|
|
408 (select_popup->style->font,buffer);
|
|
409 if(x>x1) x1=x;
|
|
410 x2=gdk_string_width
|
|
411 (select_popup->style->font,title);
|
|
412 postfix[0]=help;
|
|
413 x=gdk_string_width(select_popup->style->font,
|
|
414 postfix);
|
|
415 if(x>x3) x3=x;
|
|
416 }
|
|
417 else
|
|
418 {
|
|
419 gtk_paint_string(style,select_popup->window,
|
|
420 GTK_STATE_NORMAL,NULL,
|
|
421 GTK_WIDGET(select_popup),
|
|
422 "LIRC select item",
|
|
423 SELECT_BORDER,
|
|
424 SELECT_BORDER+font->ascent+
|
|
425 (count-1)*baseline_skip,
|
|
426 buffer);
|
|
427 gtk_paint_string(style,select_popup->window,
|
|
428 GTK_STATE_NORMAL,NULL,
|
|
429 GTK_WIDGET(select_popup),
|
|
430 "LIRC select item",
|
|
431 SELECT_BORDER+x1,
|
|
432 SELECT_BORDER+font->ascent+
|
|
433 (count-1)*baseline_skip,
|
|
434 title);
|
|
435 postfix[0]=help;
|
|
436 gtk_paint_string(style,select_popup->window,
|
|
437 GTK_STATE_NORMAL,NULL,
|
|
438 GTK_WIDGET(select_popup),
|
|
439 "LIRC select item",
|
|
440 SELECT_BORDER+x1+x2+10,
|
|
441 SELECT_BORDER+font->ascent+
|
|
442 (count-1)*baseline_skip,
|
|
443 postfix);
|
|
444
|
|
445 }
|
|
446 scan_list=g_list_next(scan_list);
|
|
447 if(scan_list==NULL)
|
|
448 {
|
|
449 if(pass==1)
|
|
450 {
|
|
451 int x,y;
|
|
452
|
|
453 width=SELECT_BORDER*2+x1+x2+10+x3;
|
|
454 height=SELECT_BORDER*2+count*baseline_skip-gap;
|
|
455
|
|
456 gtk_widget_set_usize(select_popup,
|
|
457 width,
|
|
458 height);
|
|
459 x=(gdk_screen_width()-width)/2;
|
|
460 if(x<0) x=0;
|
|
461 y=(gdk_screen_height()-height)/2;
|
|
462 if(y<0) y=0;
|
|
463 gtk_widget_popup(select_popup,x,y);
|
|
464 gtk_paint_box(style,select_popup->window,
|
|
465 GTK_STATE_NORMAL,
|
|
466 GTK_SHADOW_OUT,
|
|
467 NULL,GTK_WIDGET(select_popup),
|
|
468 "LIRC select list",
|
|
469 0,0,-1,-1);
|
|
470 scan_list=title_list;
|
|
471 count=0;
|
|
472 }
|
|
473 pass++;
|
|
474 }
|
|
475 }
|
|
476 if(count==1)
|
|
477 {
|
|
478 clear_select_list(&select_list);
|
|
479 xmms_remote_set_playlist_pos
|
|
480 (lirc_plugin.xmms_session,
|
|
481 ((struct title_info *) title_list->data)
|
|
482 ->pos);
|
|
483 }
|
|
484 clear_title_list(&title_list);
|
|
485
|
|
486 }
|
|
487 select_tag=gtk_timeout_add(3000,(GtkFunction) remove_select_popup,
|
|
488 (gpointer) &select_popup);
|
|
489 }
|
|
490 */
|
|
491 void init(void)
|
|
492 {
|
|
493 int flags;
|
307
|
494 ConfigDb *db;
|
156
|
495
|
|
496 if((lirc_fd=lirc_init("audacious",1))==-1)
|
|
497 {
|
554
|
498 fprintf(stderr,_("%s: could not init LIRC support\n"),
|
156
|
499 plugin_name);
|
|
500 return;
|
|
501 }
|
|
502 if(lirc_readconfig(NULL,&config,NULL)==-1)
|
|
503 {
|
|
504 lirc_deinit();
|
|
505 fprintf(stderr,
|
554
|
506 _("%s: could not read LIRC config file\n"
|
|
507 "%s: please read the documentation of LIRC\n"
|
|
508 "%s: how to create a proper config file\n"),
|
156
|
509 plugin_name,plugin_name,plugin_name);
|
|
510 return;
|
|
511 }
|
|
512 input_tag=gdk_input_add(lirc_fd,GDK_INPUT_READ,
|
|
513 lirc_input_callback,NULL);
|
|
514 fcntl(lirc_fd,F_SETOWN,getpid());
|
|
515 flags=fcntl(lirc_fd,F_GETFL,0);
|
|
516 if(flags!=-1)
|
|
517 {
|
|
518 fcntl(lirc_fd,F_SETFL,flags|O_NONBLOCK);
|
|
519 }
|
|
520 fflush(stdout);
|
307
|
521 db = bmp_cfg_db_open();
|
|
522 bmp_cfg_db_get_string(db,"LIRC","font",&fontname);
|
|
523 bmp_cfg_db_close(db);
|
156
|
524 popup_style=gtk_style_new();
|
|
525 }
|
|
526
|
|
527 void lirc_input_callback(gpointer data,gint source,
|
|
528 GdkInputCondition condition)
|
|
529 {
|
|
530 char *code;
|
|
531 char *c;
|
|
532 gint playlist_time,playlist_pos,output_time,v;
|
|
533 int ret;
|
|
534 char *ptr;
|
|
535 gint balance;
|
|
536 gboolean show_pl;
|
|
537 int n;
|
|
538
|
|
539 while((ret=lirc_nextcode(&code))==0 && code!=NULL)
|
|
540 {
|
|
541 while((ret=lirc_code2char(config,code,&c))==0 && c!=NULL)
|
|
542 {
|
|
543 if(strcasecmp("PLAY",c)==0)
|
|
544 {
|
|
545 xmms_remote_play(lirc_plugin.xmms_session);
|
|
546 }
|
|
547 else if(strcasecmp("STOP",c)==0)
|
|
548 {
|
|
549 xmms_remote_stop(lirc_plugin.xmms_session);
|
|
550 }
|
|
551 else if(strcasecmp("PAUSE",c)==0)
|
|
552 {
|
|
553 xmms_remote_pause(lirc_plugin.xmms_session);
|
|
554 }
|
|
555 else if(strcasecmp("PLAYPAUSE",c) == 0)
|
|
556 {
|
|
557 if(xmms_remote_is_playing(lirc_plugin.
|
|
558 xmms_session))
|
|
559 xmms_remote_pause
|
|
560 (lirc_plugin.xmms_session);
|
|
561 else
|
|
562 xmms_remote_play
|
|
563 (lirc_plugin.xmms_session);
|
|
564 }
|
|
565 else if(strncasecmp("NEXT",c,4)==0)
|
|
566 {
|
|
567 ptr=c+4;
|
|
568 while(isspace(*ptr)) ptr++;
|
|
569 n=atoi(ptr);
|
|
570
|
|
571 if(n<=0) n=1;
|
|
572 for(;n>0;n--)
|
|
573 {
|
|
574 xmms_remote_playlist_next
|
|
575 (lirc_plugin.xmms_session);
|
|
576 }
|
|
577 }
|
|
578 else if(strncasecmp("PREV",c,4)==0)
|
|
579 {
|
|
580 ptr=c+4;
|
|
581 while(isspace(*ptr)) ptr++;
|
|
582 n=atoi(ptr);
|
|
583
|
|
584 if(n<=0) n=1;
|
|
585 for(;n>0;n--)
|
|
586 {
|
|
587 xmms_remote_playlist_prev
|
|
588 (lirc_plugin.xmms_session);
|
|
589 }
|
|
590 }
|
|
591 else if(strcasecmp("SHUFFLE",c)==0)
|
|
592 {
|
|
593 xmms_remote_toggle_shuffle(lirc_plugin.xmms_session);
|
|
594 }
|
|
595 else if(strcasecmp("REPEAT",c)==0)
|
|
596 {
|
|
597 xmms_remote_toggle_repeat(lirc_plugin.xmms_session);
|
|
598 }
|
|
599 else if(strncasecmp("FWD",c,3)==0)
|
|
600 {
|
|
601 ptr=c+3;
|
|
602 while(isspace(*ptr)) ptr++;
|
|
603 n=atoi(ptr)*1000;
|
|
604
|
|
605 if(n<=0) n=5000;
|
|
606 output_time=xmms_remote_get_output_time
|
|
607 (lirc_plugin.xmms_session);
|
|
608 playlist_pos=xmms_remote_get_playlist_pos
|
|
609 (lirc_plugin.xmms_session);
|
|
610 playlist_time=xmms_remote_get_playlist_time
|
|
611 (lirc_plugin.xmms_session,
|
|
612 playlist_pos);
|
|
613 if(playlist_time-output_time<n)
|
|
614 output_time=playlist_time-n;
|
|
615 xmms_remote_jump_to_time
|
|
616 (lirc_plugin.xmms_session,
|
|
617 output_time+n);
|
|
618 }
|
|
619 else if(strncasecmp("BWD",c,3)==0)
|
|
620 {
|
|
621 ptr=c+3;
|
|
622 while(isspace(*ptr)) ptr++;
|
|
623 n=atoi(ptr)*1000;
|
|
624
|
|
625 if(n<=0) n=5000;
|
|
626 output_time=xmms_remote_get_output_time
|
|
627 (lirc_plugin.xmms_session);
|
|
628 if(output_time<n)
|
|
629 output_time=n;
|
|
630 xmms_remote_jump_to_time
|
|
631 (lirc_plugin.xmms_session,
|
|
632 output_time-n);
|
|
633 }
|
|
634 else if(strncasecmp("VOL_UP",c,6)==0)
|
|
635 {
|
|
636 ptr=c+6;
|
|
637 while(isspace(*ptr)) ptr++;
|
|
638 n=atoi(ptr);
|
|
639 if(n<=0) n=5;
|
|
640
|
|
641 v = xmms_remote_get_main_volume
|
|
642 (lirc_plugin.xmms_session);
|
|
643 if(v > (100-n)) v=100-n;
|
|
644 xmms_remote_set_main_volume
|
|
645 (lirc_plugin.xmms_session,v+n);
|
|
646 }
|
|
647 else if(strncasecmp("VOL_DOWN",c,8)==0)
|
|
648 {
|
|
649 ptr=c+8;
|
|
650 while (isspace(*ptr)) ptr++;
|
|
651 n=atoi(ptr);
|
|
652 if(n<=0) n=5;
|
|
653
|
|
654 v = xmms_remote_get_main_volume
|
|
655 (lirc_plugin.xmms_session);
|
|
656 if(v<n) v=n;
|
|
657 xmms_remote_set_main_volume
|
|
658 (lirc_plugin.xmms_session,v-n);
|
|
659 }
|
|
660 else if(strcasecmp("QUIT",c)==0)
|
|
661 {
|
|
662 #ifdef HAVE_XMMS_REMOTE_QUIT
|
|
663 xmms_remote_quit(lirc_plugin.xmms_session);
|
|
664 #else
|
|
665 raise(SIGTERM);
|
|
666 #endif
|
|
667 }
|
|
668 else if(strcasecmp("SETPOS",c)==0)
|
|
669 {
|
|
670 xmms_remote_set_playlist_pos(lirc_plugin.xmms_session,tracknr-1);
|
|
671 xmms_remote_play(lirc_plugin.xmms_session);
|
|
672 tracknr=0;
|
|
673 }
|
|
674 else if(strcasecmp("ONE",c)==0)
|
|
675 {
|
|
676 if(select_list!=NULL)
|
|
677 {
|
|
678 /* select_title(NULL,1); */
|
|
679 }
|
|
680 else
|
|
681 {
|
|
682 tracknr=tracknr*10+1;
|
|
683 }
|
|
684 }
|
|
685 else if(strcasecmp("TWO",c)==0)
|
|
686 {
|
|
687 if(select_list!=NULL)
|
|
688 {
|
|
689 /* select_title(NULL,2); */
|
|
690 }
|
|
691 else
|
|
692 {
|
|
693 tracknr=tracknr*10+2;
|
|
694 }
|
|
695 }
|
|
696 else if(strcasecmp("THREE",c)==0)
|
|
697 {
|
|
698 if(select_list!=NULL)
|
|
699 {
|
|
700 /* select_title(NULL,3);*/
|
|
701 }
|
|
702 else
|
|
703 {
|
|
704 tracknr=tracknr*10+3;
|
|
705 }
|
|
706 }
|
|
707 else if(strcasecmp("FOUR",c)==0)
|
|
708 {
|
|
709 if(select_list!=NULL)
|
|
710 {
|
|
711 /* select_title(NULL,4);*/
|
|
712 }
|
|
713 else
|
|
714 {
|
|
715 tracknr=tracknr*10+4;
|
|
716 }
|
|
717 }
|
|
718 else if(strcasecmp("FIVE",c)==0)
|
|
719 {
|
|
720 if(select_list!=NULL)
|
|
721 {
|
|
722 /*select_title(NULL,5);*/
|
|
723 }
|
|
724 else
|
|
725 {
|
|
726 tracknr=tracknr*10+5;
|
|
727 }
|
|
728 }
|
|
729 else if(strcasecmp("SIX",c)==0)
|
|
730 {
|
|
731 if(select_list!=NULL)
|
|
732 {
|
|
733 /*select_title(NULL,6);*/
|
|
734 }
|
|
735 else
|
|
736 {
|
|
737 tracknr=tracknr*10+6;
|
|
738 }
|
|
739 }
|
|
740 else if(strcasecmp("SEVEN",c)==0)
|
|
741 {
|
|
742 if(select_list!=NULL)
|
|
743 {
|
|
744 /*select_title(NULL,7);*/
|
|
745 }
|
|
746 else
|
|
747 {
|
|
748 tracknr=tracknr*10+7;
|
|
749 }
|
|
750 }
|
|
751 else if(strcasecmp("EIGHT",c)==0)
|
|
752 {
|
|
753 if(select_list!=NULL)
|
|
754 {
|
|
755 /*select_title(NULL,8);*/
|
|
756 }
|
|
757 else
|
|
758 {
|
|
759 tracknr=tracknr*10+8;
|
|
760 }
|
|
761 }
|
|
762 else if(strcasecmp("NINE",c)==0)
|
|
763 {
|
|
764 if(select_list!=NULL)
|
|
765 {
|
|
766 /*select_title(NULL,9);*/
|
|
767 }
|
|
768 else
|
|
769 {
|
|
770 tracknr=tracknr*10+9;
|
|
771 }
|
|
772 }
|
|
773 else if(strcasecmp("ZERO",c)==0)
|
|
774 {
|
|
775 if(select_list!=NULL)
|
|
776 {
|
|
777 /*select_title(NULL,10);*/
|
|
778 }
|
|
779 else
|
|
780 {
|
|
781 tracknr=tracknr*10;
|
|
782 }
|
|
783 }
|
|
784 else if(strcasecmp("MUTE",c)==0)
|
|
785 {
|
|
786 if(mute==0)
|
|
787 {
|
|
788 mute=1;
|
|
789 /* store the master volume so
|
|
790 we can restore it on unmute. */
|
|
791 mute_vol = xmms_remote_get_main_volume
|
|
792 (lirc_plugin.xmms_session);
|
|
793 xmms_remote_set_main_volume
|
|
794 (lirc_plugin.xmms_session, 0);
|
|
795 }
|
|
796 else
|
|
797 {
|
|
798 mute=0;
|
|
799 xmms_remote_set_main_volume
|
|
800 (lirc_plugin.xmms_session,
|
|
801 mute_vol);
|
|
802 }
|
|
803 }
|
|
804 else if(strncasecmp("BAL_LEFT",c,8)==0)
|
|
805 {
|
|
806 ptr=c+8;
|
|
807 while(isspace(*ptr)) ptr++;
|
|
808 n=atoi(ptr);
|
|
809 if(n<=0) n=5;
|
|
810
|
|
811 balance=xmms_remote_get_balance
|
|
812 (lirc_plugin.xmms_session);
|
|
813 balance-=n;
|
|
814 if(balance<-100) balance=-100;
|
|
815 xmms_remote_set_balance
|
|
816 (lirc_plugin.xmms_session,balance);
|
|
817 }
|
|
818 else if(strncasecmp("BAL_RIGHT",c,9)==0)
|
|
819 {
|
|
820 ptr=c+9;
|
|
821 while(isspace(*ptr)) ptr++;
|
|
822 n=atoi(ptr);
|
|
823 if(n<=0) n=5;
|
|
824
|
|
825 balance=xmms_remote_get_balance
|
|
826 (lirc_plugin.xmms_session);
|
|
827 balance+=n;
|
|
828 if(balance>100) balance=100;
|
|
829 xmms_remote_set_balance
|
|
830 (lirc_plugin.xmms_session,balance);
|
|
831 }
|
|
832 else if(strcasecmp("BAL_CENTER",c)==0)
|
|
833 {
|
|
834 balance=0;
|
|
835 xmms_remote_set_balance
|
|
836 (lirc_plugin.xmms_session,balance);
|
|
837 }
|
|
838 else if(strcasecmp("LIST",c)==0)
|
|
839 {
|
|
840 show_pl=xmms_remote_is_pl_win
|
|
841 (lirc_plugin.xmms_session);
|
|
842 show_pl=(show_pl) ? 0:1;
|
|
843 xmms_remote_pl_win_toggle
|
|
844 (lirc_plugin.xmms_session,show_pl);
|
|
845 }
|
|
846 else if(strcasecmp("PLAYLIST_CLEAR",c)==0)
|
|
847 {
|
|
848 gboolean pl_visible;
|
|
849
|
|
850 pl_visible=xmms_remote_is_pl_win
|
|
851 (lirc_plugin.xmms_session);
|
|
852 xmms_remote_stop(lirc_plugin.xmms_session);
|
|
853 xmms_remote_playlist_clear
|
|
854 (lirc_plugin.xmms_session);
|
|
855 /* This is to refresh window content */
|
|
856 xmms_remote_pl_win_toggle
|
|
857 (lirc_plugin.xmms_session,pl_visible);
|
|
858 }
|
|
859 else if(strncasecmp("PLAYLIST_ADD ",c,13)==0)
|
|
860 {
|
|
861 gboolean pl_visible;
|
|
862 GList list;
|
|
863
|
|
864 pl_visible=xmms_remote_is_pl_win
|
|
865 (lirc_plugin.xmms_session);
|
|
866 list.prev=list.next=NULL;
|
|
867 list.data=c+13;
|
|
868 xmms_remote_playlist_add
|
|
869 (lirc_plugin.xmms_session,&list);
|
|
870 /* This is to refresh window content */
|
|
871 xmms_remote_pl_win_toggle
|
|
872 (lirc_plugin.xmms_session,pl_visible);
|
|
873 }
|
|
874 else if(strncasecmp("SELECT",c,6)==0)
|
|
875 {
|
|
876 char *sel;
|
|
877 int i;
|
|
878
|
|
879 ptr=c+6;
|
|
880 while(isspace(*ptr)) ptr++;
|
|
881
|
|
882 sel=ptr;
|
|
883 for(i=0;*ptr;ptr++)
|
|
884 {
|
|
885 if(isalnum(*ptr))
|
|
886 {
|
|
887 sel[i]=toupper(*ptr);
|
|
888 i++;
|
|
889 }
|
|
890 }
|
|
891 sel[i]=0;
|
|
892
|
|
893 if(strlen(sel)>0)
|
|
894 {
|
|
895 /*select_title(sel,0);*/
|
|
896 }
|
|
897 }
|
|
898 else
|
|
899 {
|
554
|
900 fprintf(stderr,_("%s: unknown command \"%s\"\n"),
|
156
|
901 plugin_name,c);
|
|
902 }
|
|
903 }
|
|
904 free(code);
|
|
905 if(ret==-1) break;
|
|
906 }
|
|
907 if(ret==-1)
|
|
908 {
|
|
909 /* something went badly wrong */
|
554
|
910 fprintf(stderr,_("%s: disconnected from LIRC\n"),plugin_name);
|
156
|
911 cleanup();
|
|
912 return;
|
|
913 }
|
|
914 }
|
|
915
|
|
916 void configure(void)
|
|
917 {
|
|
918 if(!fsd)
|
|
919 {
|
|
920 GtkWidget *window;
|
|
921
|
|
922 window=gtk_font_selection_dialog_new
|
554
|
923 (_("Please choose font for SELECT popup."));
|
156
|
924 g_return_if_fail(GTK_IS_FONT_SELECTION_DIALOG(window));
|
|
925
|
|
926 fsd=window;
|
|
927 gtk_window_position(GTK_WINDOW(fsd),GTK_WIN_POS_MOUSE);
|
|
928 gtk_signal_connect(GTK_OBJECT(fsd), "destroy",
|
|
929 GTK_SIGNAL_FUNC(gtk_widget_destroyed),
|
|
930 &fsd);
|
|
931 gtk_signal_connect(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG
|
|
932 (fsd)->ok_button),
|
|
933 "clicked",
|
|
934 GTK_SIGNAL_FUNC(font_selection_ok),
|
|
935 NULL);
|
|
936 gtk_signal_connect_object(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fsd)->cancel_button),
|
|
937 "clicked",
|
|
938 GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
|
939 GTK_OBJECT(fsd));
|
|
940 }
|
|
941 if(!GTK_WIDGET_VISIBLE(fsd))
|
|
942 gtk_widget_show(fsd);
|
|
943 else
|
|
944 gtk_widget_destroy(fsd);
|
|
945 }
|
|
946
|
|
947 void font_selection_ok(GtkWidget *button,gpointer *data)
|
|
948 {
|
|
949 gchar *new_fontname;
|
|
950
|
|
951 new_fontname=gtk_font_selection_dialog_get_font_name
|
|
952 (GTK_FONT_SELECTION_DIALOG(fsd));
|
|
953 if(new_fontname)
|
|
954 {
|
|
955 if(fontname) free(fontname);
|
|
956 fontname=new_fontname;
|
|
957 }
|
|
958 gtk_widget_destroy(fsd);
|
|
959 fsd=NULL;
|
|
960 }
|
|
961
|
|
962 void cleanup()
|
|
963 {
|
307
|
964 ConfigDb *db;
|
156
|
965
|
|
966 if(config)
|
|
967 {
|
|
968 gtk_input_remove(input_tag);
|
|
969 lirc_freeconfig(config);
|
|
970 config=NULL;
|
|
971 }
|
|
972 if(lirc_fd!=-1)
|
|
973 {
|
|
974 lirc_deinit();
|
|
975 lirc_fd=-1;
|
|
976 }
|
|
977 clear_select_list(&select_list);
|
|
978 if(fontname)
|
|
979 {
|
307
|
980 db = bmp_cfg_db_open();
|
|
981 bmp_cfg_db_set_string(db,"LIRC","font",fontname);
|
|
982 bmp_cfg_db_close(db);
|
156
|
983 free(fontname);
|
|
984 }
|
|
985 }
|