~ubuntu-branches/ubuntu/hoary/gkrellm-radio/hoary

« back to all changes in this revision

Viewing changes to gkrellm_radio.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons
  • Date: 2003-09-20 12:59:41 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20030920125941-38vpjxq1dgxufqqr
Tags: 2.0.4-1
* New upstream release
  - Only try to reopen the radio on first creation (closes: Bug#211116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * */
23
23
 
24
24
static gchar *info_text[] = {
25
 
  "<b>GKrellM Radio Plugin\n\n",
26
 
  "This plugin allow you to control the radio card of your Linux box,\
27
 
   if you have one installed.\n",
28
 
  "<b>\nUser Interface:\n",
29
 
  "\n\t* Clicking the right button will turn the radio on and off.\n",
30
 
  "\t* Clicking the left text will tune to the next channel configured",
31
 
  " under configuration.\n"
32
 
  "\t* Using your mousewheel will tune up or down.\n",
33
 
  "\t*Right mouse button will pop up a channel menu\n",
34
 
  "<b>\nThanks to:\n",
35
 
  "\n\tLars Christensen - Upstream author untill version 0.2.1\n",
36
 
  "\tGerd Knorr - borrowed some of the radio interface code from his Xawtv",
37
 
  " radio application.\n",
38
 
  "<b>\nHomepage:\n",
 
25
  N_("<b>GKrellM Radio Plugin\n\n"),
 
26
  N_("This plugin allow you to control the radio card of your Linux box," \
 
27
   "if you have one installed.\n"),
 
28
  N_("<b>\nUser Interface:\n"),
 
29
  N_("\n\t* Clicking the right button will turn the radio on and off.\n"),
 
30
  N_("\t* Clicking the left text will tune to the next channel configured" \
 
31
  " under configuration.\n"),
 
32
  N_("\t* Using your mousewheel will tune up or down.\n"),
 
33
  N_("\t*Right mouse button will pop up a channel menu\n"),
 
34
  N_("<b>\nThanks to:\n"),
 
35
  N_("\n\tLars Christensen - Upstream author untill version 0.2.1\n" \
 
36
  "\tGerd Knorr - borrowed some of the radio interface code from his Xawtv" \
 
37
  " radio application.\n"),
 
38
  N_("<b>\nHomepage:\n"),
39
39
  "\n\thttp://gkrellm.luon.net/gkrellm-radio.phtml\n"
40
40
};
41
41
 
42
 
static Panel    *panel;
43
 
static Monitor  *plugin_monitor;
44
 
 
45
 
static Decal *station_text, *decal_onoff_pix;
46
 
 
47
 
DecalButton *onoff_button;
 
42
static GkrellmPanel    *panel;
 
43
static GkrellmMonitor  *plugin_monitor;
 
44
 
 
45
static GkrellmDecal *station_text, *decal_onoff_pix;
 
46
 
 
47
GkrellmDecalbutton *onoff_button;
48
48
 
49
49
static gint     style_id;
50
50
 
112
112
 
113
113
void 
114
114
do_switch_station(int nr) {
 
115
  gchar *text_utf8 = NULL, *text_locale = NULL;
115
116
  nr %= nstations;
116
117
  currentstation = nr;
117
118
  start_mute_timer();
118
119
  radio_tune(stations[nr].freq);
 
120
  gkrellm_locale_dup_string(&text_utf8, stations[nr].station_name, &text_locale);
119
121
  gkrellm_draw_decal_text(panel, station_text, 
120
 
      stations[nr].station_name, -1);
121
 
  gkrellm_draw_layers_force(panel);
 
122
      text_locale, -1);
 
123
  gkrellm_draw_panel_layers(panel);
122
124
}
123
125
 
124
126
static void exit_func(void) {
139
141
  if (menu != NULL) {
140
142
    gtk_widget_destroy(menu);
141
143
  }
 
144
  if (!nstations) { 
 
145
    menu = NULL;
 
146
    return;
 
147
  }
142
148
    
143
149
  menu = gtk_menu_new();
144
150
 
171
177
  else
172
178
    imgid = D_MISC_BUTTON_OUT;
173
179
  gkrellm_set_decal_button_index(onoff_button, imgid);
 
180
  gkrellm_draw_panel_layers(panel);
174
181
}
175
182
 
176
183
void reopen_radio() {
177
184
  if (!attempt_reopen) return;
178
185
 
179
186
  if (open_radio() != -1) {
180
 
    if (radio_ismute()) {
181
 
      close_radio();
182
 
      onoff_state = 0;          /* off */
183
 
    } else {
184
187
      start_mute_timer();
 
188
      radio_tune(current_freq());
 
189
      set_text_freq(current_freq());
185
190
      onoff_state = 1;          /* on */
186
 
    }
187
191
  }
188
192
  set_onoff_button(onoff_state);
189
193
}
190
194
 
191
195
void gkrellm_radio_turn_onoff(void) {
192
 
    onoff_state = !onoff_state;
193
 
    if (onoff_state) {
 
196
    if (!onoff_state) {  
194
197
      if (open_radio() == -1) {
195
 
                gkrellm_message_window("GKrellM error",
196
 
                              "GKrellM radio plugin couldn't open /dev/radio", NULL);
 
198
                gkrellm_message_window("GKrellM radio plugin",
 
199
                              _("Couldn't open /dev/radio"), NULL);
197
200
      } else {
198
201
            /* radio was opened */
 
202
        onoff_state = 1; /* on */
199
203
        start_mute_timer();
200
204
        radio_tune(current_freq());
201
205
        set_text_freq(current_freq());
202
206
        set_onoff_button(onoff_state);
203
207
      }
204
208
    } else {
 
209
      onoff_state = 0; /* off */
205
210
      set_onoff_button(onoff_state);
206
211
      close_radio();
207
212
    }
208
213
}
209
214
 
210
215
void
211
 
cb_button(DecalButton *button)
 
216
cb_button(GkrellmDecalbutton *button)
212
217
{
213
218
  if (GPOINTER_TO_INT(button->data) == 1) { switch_station(); }
214
219
  if (GPOINTER_TO_INT(button->data) == 2) { gkrellm_radio_turn_onoff(); }
215
220
}
216
221
 
217
222
static void set_text_freq(float freq) {
218
 
  gkrellm_draw_decal_text(panel, station_text, station_name(freq), -1);
219
 
  gkrellm_draw_layers_force(panel);
 
223
  gchar *text_utf8 = NULL, *text_locale = NULL;
 
224
  gkrellm_locale_dup_string(&text_utf8, station_name(freq), &text_locale);
 
225
  gkrellm_draw_decal_text(panel, station_text, text_locale, -1);
 
226
  gkrellm_draw_panel_layers(panel);
220
227
}
221
228
 
222
229
static gint
223
 
panel_expose_event(GtkWidget *widget, GdkEventExpose *ev)
224
 
{
 
230
panel_expose_event(GtkWidget *widget, GdkEventExpose *ev) {
225
231
  gdk_draw_pixmap(widget->window,
226
232
                  widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
227
233
                  panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y,
238
244
static gint 
239
245
button_release_event(GtkWidget *widget, GdkEventButton *ev, void *N) {
240
246
 
241
 
  switch (ev->button) {
242
 
    case 3:
243
 
      gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
244
 
          ev->state, ev->time);
245
 
      break;
246
 
    case 4:
247
 
      gkrellm_radio_finetune_delta(+0.05);
248
 
      break;
249
 
    case 5:
250
 
      gkrellm_radio_finetune_delta(-0.05);
251
 
      break; 
 
247
  if  (ev->button == 3) {
 
248
    if (menu == NULL) gkrellm_message_window("GKrellM radio plugin",
 
249
        _("Please setup some channels in the configuration"),NULL);
 
250
    else gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
 
251
        ev->state, ev->time);
252
252
  }
253
253
  return TRUE;
254
254
}
255
255
 
256
 
static void
257
 
update_plugin()
258
 
{
259
 
  gkrellm_draw_layers(panel);
 
256
static gint scroll_event(GtkWidget *widget,GdkEventScroll *ev,gpointer data) {
 
257
  float delta = ev->direction == GDK_SCROLL_UP ? 0.05 : -0.05;
 
258
  gkrellm_radio_finetune_delta(delta);
 
259
  return TRUE;
260
260
}
261
261
 
262
262
static void
263
263
create_plugin(GtkWidget *vbox, gint first_create) {
264
 
  Style           *style;
265
 
  TextStyle       *ts, *ts_alt;
 
264
  GkrellmStyle     *style;
 
265
  GkrellmTextstyle *ts, *ts_alt;
 
266
  GkrellmMargin    *margin;
266
267
  GdkPixmap       *pixmap;
267
268
  GdkBitmap       *mask;
268
269
  gint            y;
269
270
  gint            x;
 
271
  gchar *text_utf8 = NULL, *text_locale = NULL;
270
272
 
271
273
  if (first_create) {
272
274
    panel = gkrellm_panel_new0();
278
280
 
279
281
  style = gkrellm_meter_style(style_id);
280
282
 
281
 
  /* Each Style has two text styles.  The theme designer has picked the
 
283
  /* Each GkrellmStyle has two text styles.  The theme designer has picked the
282
284
     |  colors and font sizes, presumably based on knowledge of what you draw
283
285
     |  on your panel.  You just do the drawing.  You probably could assume
284
286
     |  the ts font is larger than the ts_alt font, but again you can be
289
291
  panel->textstyle = ts;      /* would be used for a panel label */
290
292
 
291
293
  y = 2;                        /* some border */
292
 
  station_text = gkrellm_create_decal_text(panel, "Hello World", ts_alt, style, 2, y, 40);
 
294
  station_text = gkrellm_create_decal_text(panel, _("Hello World"), ts_alt, style, 2, y, 40);
293
295
 
294
296
  /* Create a pixmap decal and place it to the right of station_text.  Use
295
297
     |  decals from the builtin decal_misc.xpm.
304
306
  /* Configure the panel to hold the above created decals, add in a little
305
307
     |  bottom margin for looks, and create the panel.
306
308
  */
307
 
  gkrellm_configure_panel(panel, NULL, style);
308
 
  panel->label->h_panel += 2;     /* Some bottom margin */
309
 
  gkrellm_create_panel(vbox, panel, gkrellm_bg_meter_image(style_id));
310
 
  gkrellm_monitor_height_adjust(panel->h);
 
309
  gkrellm_panel_configure(panel, NULL, style);
 
310
  gkrellm_panel_create(vbox, plugin_monitor,panel);
311
311
 
312
312
  /* After the panel is created, the decals can be converted into buttons.
313
313
     |  First draw the initial text into the text decal button and then
316
316
     |  decal.  Just pass the frame we want to be the out image and the
317
317
     |  frame for the in or pressed image.
318
318
  */
319
 
  gkrellm_draw_decal_text(panel, station_text, station_name(current_freq()),
 
319
  gkrellm_locale_dup_string(&text_utf8, station_name(current_freq()), &text_locale);
 
320
  gkrellm_draw_decal_text(panel, station_text, text_locale,
320
321
                          button_state);
321
322
 
 
323
  margin = gkrellm_get_style_margins(style);
322
324
  gkrellm_put_decal_in_meter_button(panel, station_text, cb_button,
323
 
                                    GINT_TO_POINTER(1));
 
325
                                    GINT_TO_POINTER(1),margin);
324
326
  onoff_button = 
325
327
    gkrellm_make_decal_button(panel, decal_onoff_pix, cb_button,
326
328
                              GINT_TO_POINTER(2),
334
336
  */
335
337
 
336
338
  if (first_create) {
337
 
    gtk_signal_connect(GTK_OBJECT (panel->drawing_area), "expose_event",
 
339
    g_signal_connect(GTK_OBJECT (panel->drawing_area), "expose_event",
338
340
                       (GtkSignalFunc) panel_expose_event, NULL);
339
 
    gtk_signal_connect(GTK_OBJECT (panel->drawing_area), "button_release_event",
 
341
    g_signal_connect(GTK_OBJECT (panel->drawing_area), "button_release_event",
340
342
                       GTK_SIGNAL_FUNC(button_release_event), NULL);
 
343
    g_signal_connect(GTK_OBJECT (panel->drawing_area), "scroll_event",
 
344
                       GTK_SIGNAL_FUNC(scroll_event), NULL);
 
345
    reopen_radio();
341
346
  }
342
347
  
343
 
  reopen_radio();
 
348
  gkrellm_draw_panel_layers(panel);
344
349
}
345
350
 
346
351
static GtkWidget *gui_station_list = NULL;
365
370
  gfloat freq;
366
371
  gchar fstr[32];
367
372
 
368
 
  f[0] = gtk_entry_get_text(GTK_ENTRY(gui_station_name_input));
 
373
  f[0] = (gchar *) gtk_entry_get_text(GTK_ENTRY(gui_station_name_input));
369
374
  freq = gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(gui_freq_input));
370
375
  sprintf(fstr, "%.2f", freq);
371
376
  f[1] = fstr;
400
405
  
401
406
  table = gtk_table_new(2, 2, 0);
402
407
  
403
 
  label = gtk_label_new("Station Name:");
 
408
  label = gtk_label_new(_("Station Name:"));
404
409
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_EXPAND, GTK_FILL, 4, 4);
405
410
  
406
411
  gui_station_name_input = gtk_entry_new();
407
412
  gtk_table_attach(GTK_TABLE(table), gui_station_name_input, 1, 2, 0, 1, GTK_EXPAND, GTK_FILL, 4, 4);
408
413
 
409
 
  label = gtk_label_new("Frequency:");
 
414
  label = gtk_label_new(_("Frequency:"));
410
415
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_EXPAND, GTK_FILL, 4, 4);
411
416
  
412
417
  adj = gtk_adjustment_new(current_freq(), 0.05, 999.99, 0.05, 1, 1);
422
427
                            (gpointer)new_entry);
423
428
  gtk_container_add(action_area, button);
424
429
 
425
 
  /* Cancel Button */
426
 
  button = gtk_button_new_with_label("Cancel");
 
430
  /* Cancel button */
 
431
  button = gtk_button_new_with_label(_("Cancel"));
427
432
  gtk_signal_connect_object (GTK_OBJECT(button), "clicked",
428
433
                             GTK_SIGNAL_FUNC(close_station_editor), NULL);
429
434
 
494
499
  GtkWidget *text, *label, *panel, *button, *hbox, *scrolled, *frame, *vbox;
495
500
  GtkObject *adj;
496
501
  gchar *plugin_about_text;
497
 
  gchar *station_tab_titles[3] = { "Station", "Frequency", "" };
 
502
  gchar *station_tab_titles[3] = { _("Station"), _("Frequency"), "" };
498
503
  char *f[3];
499
504
  int i;
500
505
 
539
544
 
540
545
  hbox = gtk_hbox_new(0, 0);
541
546
 
542
 
  button = gtk_button_new_with_label("New");
 
547
  button = gtk_button_new_with_label(_("New"));
543
548
  gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gui_new_station, NULL);
544
549
 
545
550
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 2);
546
 
  button = gtk_button_new_with_label("Edit"); 
 
551
  button = gtk_button_new_with_label(_("Edit")); 
547
552
  gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gui_edit_station, NULL);
548
553
 
549
554
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 2);
550
 
  button = gtk_button_new_with_label("Delete"); 
 
555
  button = gtk_button_new_with_label(_("Delete")); 
551
556
  gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gui_delete_station, NULL);
552
557
 
553
558
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 2);
554
 
  button = gtk_button_new_with_label("Up");
 
559
  button = gtk_button_new_with_label(_("Up"));
555
560
  gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gui_moveup_station, NULL);
556
561
 
557
562
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 2);
558
563
 
559
 
  button = gtk_button_new_with_label("Down");
 
564
  button = gtk_button_new_with_label(_("Down"));
560
565
  gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)gui_movedown_station, NULL);
561
566
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 2);
562
567
  
563
 
  label = gtk_label_new("Stations");
 
568
  label = gtk_label_new(_("Stations"));
564
569
 
565
570
  gtk_box_pack_start(GTK_BOX(panel), hbox, FALSE, FALSE, 4);
566
571
 
577
582
    hbox = gtk_hbox_new(0, 0);
578
583
    gtk_box_pack_start(GTK_BOX(vbox), hbox, 0, 0, 2);
579
584
    
580
 
    label = gtk_label_new("Time to mute on channel jump (seconds):");
 
585
    label = gtk_label_new(_("Time to mute on channel jump (seconds):"));
581
586
    gtk_box_pack_start(GTK_BOX(hbox), label, 0, 0, 2);
582
587
    
583
588
    adj = gtk_adjustment_new(mutetime, 0.0, 9.99, 0.01, 0.1, 1);
589
594
 
590
595
  /* reopenoption */ {
591
596
 
592
 
    gui_reopen_toggle = gtk_check_button_new_with_label("Attempt to reopen radio on startup");
 
597
    gui_reopen_toggle = gtk_check_button_new_with_label(_("Attempt to reopen radio on startup"));
593
598
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_reopen_toggle), attempt_reopen);
594
599
    gtk_box_pack_start(GTK_BOX(vbox), gui_reopen_toggle, 0, 0, 2);
595
600
  /* close radio on exit toggle */
596
601
    gui_close_toggle = 
597
 
      gtk_check_button_new_with_label("Turn radio off when exiting gkrellm");
 
602
      gtk_check_button_new_with_label(_("Turn radio off when exiting gkrellm"));
598
603
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_close_toggle), 
599
604
        close_atexit);
600
605
    gtk_box_pack_start(GTK_BOX(vbox), gui_close_toggle, 0, 0, 2);
601
606
 
602
607
  }
603
608
  
604
 
  label = gtk_label_new("Options");
 
609
  label = gtk_label_new(_("Options"));
605
610
  gtk_notebook_append_page(GTK_NOTEBOOK(tabs), vbox, label);
606
611
 
607
612
  /* INFO TAB */
608
613
  
609
614
  frame = gtk_frame_new(NULL);
610
 
  gtk_container_border_width(GTK_CONTAINER(frame), 3);
611
 
  scrolled = gtk_scrolled_window_new(NULL, NULL);
612
 
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
613
 
                                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
614
 
  gtk_container_add(GTK_CONTAINER(frame), scrolled);
615
 
  label = gtk_label_new("Info");
616
 
  gtk_notebook_append_page(GTK_NOTEBOOK(tabs), frame, label);
617
 
  
618
 
  text = gtk_text_new(NULL, NULL);
619
 
  gtk_text_set_editable(GTK_TEXT(text), FALSE);
620
 
 
621
 
  gkrellm_add_info_text(text,info_text,sizeof(info_text)/sizeof(gchar *));
622
 
  gtk_container_add(GTK_CONTAINER(scrolled), text);
623
 
 
 
615
  scrolled = gkrellm_gtk_notebook_page(tabs,_("Info"));
 
616
  text = gkrellm_gtk_scrolled_text_view(scrolled,NULL,
 
617
                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
618
 
 
619
  for (i=0; i < sizeof(info_text)/sizeof(gchar *); ++i)
 
620
     gkrellm_gtk_text_view_append(text, _(info_text[i]));
624
621
  /* ABOUT TAB */
625
622
 
626
623
  plugin_about_text = g_strdup_printf(
627
 
   "Radio Plugin " VERSION "\n" \
 
624
   _("Radio Plugin %s\n" \
628
625
   "GKrellM radio Plugin\n\n" \
629
626
   "Copyright (C) 2001-2002 Sjoerd Simons\n" \
630
627
   "sjoerd@luon.net\n" \
631
628
   "http://gkrellm.luon.net/gkrellm-radio.phtml\n\n" \
632
 
   "Released under the GNU General Public Licence");
 
629
   "Released under the GNU General Public Licence"), VERSION);
633
630
 
634
631
  text = gtk_label_new(plugin_about_text); 
635
 
  label = gtk_label_new("About");
 
632
  label = gtk_label_new(_("About"));
636
633
  gtk_notebook_append_page(GTK_NOTEBOOK(tabs),text,label);
637
634
  g_free(plugin_about_text);
638
635
}
728
725
 
729
726
/* The monitor structure tells GKrellM how to call the plugin routines.
730
727
*/
731
 
static Monitor  plugin_mon  =
 
728
static GkrellmMonitor  plugin_mon  =
732
729
{
733
730
  CONFIG_NAME,                  /* Name, for config tab.    */
734
731
  0,                            /* Id,  0 if a plugin       */
735
732
  create_plugin,                /* The create function      */
736
 
  update_plugin,                /* The update function      */
 
733
  NULL,         /* The update function      */
737
734
  create_config,                /* The config tab create function   */
738
735
  apply_config,                 /* Apply the config function        */
739
736
 
755
752
/* All GKrellM plugins must have one global routine named init_plugin()
756
753
|  which returns a pointer to a filled in monitor structure.
757
754
*/
758
 
Monitor *
759
 
init_plugin()
760
 
{
 
755
GkrellmMonitor *
 
756
gkrellm_init_plugin() {
 
757
 
 
758
#ifdef ENABLE_NLS
 
759
   bind_textdomain_codeset(PACKAGE, "UTF-8");
 
760
#endif /* ENABLE_NLS */
 
761
 
761
762
  style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
762
763
  plugin_monitor = &plugin_mon;
763
764
#ifdef HAVE_LIRC