~blackskad/gnomeradio/dev-vol-button

« back to all changes in this revision

Viewing changes to src/gui.c

  • Committer: mfcn
  • Date: 2006-02-26 17:05:36 UTC
  • Revision ID: svn-v3-trunk0:ba97a3d1-ec25-0410-b1c6-e06ad936ea6c:trunk:127
        * Add src/bacon-volume.c, src/bacon-volume.h from totem
        * src/Makfile.am: add src/bacon-volume.c, src/bacon-volume.h
        * configure.in: version 1.6.99
        * src/gui.c, src/gui.h, src/lirc.c: Remove volume-slider and
        mute-button and use bacon-volume-button instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <gconf/gconf-client.h>
26
26
#include <math.h>
27
27
#include "eggtrayicon.h"
 
28
#include "bacon-volume.h"
28
29
#include "gui.h"
29
30
#include "trayicon.h"
30
31
#include "tech.h"
35
36
#include "../pixmaps/digits.xpm"
36
37
#include "../pixmaps/signal.xpm"
37
38
#include "../pixmaps/stereo.xpm"
38
 
#include "../pixmaps/vol_up.xpm"
39
 
#include "../pixmaps/vol_down.xpm"
40
39
#include "../pixmaps/freq_up.xpm"
41
40
#include "../pixmaps/freq_down.xpm"
42
41
#include "../pixmaps/radio.xpm"
51
50
 
52
51
static GtkWidget *drawing_area;
53
52
static GdkPixmap *digits, *signal_s, *stereo;
54
 
static GtkWidget *freq_scale, *vol_scale;
 
53
static GtkWidget *freq_scale;
 
54
static GtkWidget *rec_pixmap;
55
55
 
56
56
static int timeout_id, bp_timeout_id = -1, bp_timeout_steps = 0;
57
 
static int mute_button_toggled_cb_id;
58
57
 
59
58
static gboolean is_first_start(void)
60
59
{
262
261
        }               
263
262
        vol = mixer_get_volume();
264
263
        if (vol >= 0) {
265
 
                gtk_adjustment_set_value(volume, (double)vol);
 
264
                bacon_volume_button_set_value(BACON_VOLUME_BUTTON(mute_button), vol);
 
265
                /*gtk_adjustment_set_value(volume, (double)vol);*/
266
266
        }
267
267
}
268
268
 
407
407
        radio_setfreq(adj->value/STEPS);
408
408
}
409
409
 
410
 
static void volume_value_changed_cb(GtkAdjustment* data, gpointer window)
 
410
static void volume_value_changed_cb(BaconVolumeButton *button, gpointer user_data)
411
411
{
412
412
        char *text;
413
 
        int vol = (int)volume->value;
 
413
        int vol = (int)(bacon_volume_button_get_value(BACON_VOLUME_BUTTON(mute_button)) + 0.5f);
414
414
        
415
415
        mixer_set_volume(vol);
416
416
        
417
 
        text = g_strdup_printf(_("Volume: %d%%"), vol);
 
417
/*      text = g_strdup_printf(_("Volume: %d%%"), vol);
418
418
        gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
419
 
        g_free(text);
 
419
        g_free(text);*/
420
420
        
421
421
        if (tray_menu) {
422
422
                g_signal_handler_block(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
423
423
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mute_menuitem), vol == 0);
424
424
                g_signal_handler_unblock(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
425
425
        }
426
 
        g_signal_handler_block(G_OBJECT(mute_button), mute_button_toggled_cb_id);
427
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_button), vol == 0);
428
 
        g_signal_handler_unblock(G_OBJECT(mute_button), mute_button_toggled_cb_id);
429
426
}
430
427
 
431
428
#if 0
699
696
                vol = old_vol;
700
697
        }       
701
698
        mixer_set_volume(vol);
702
 
        gtk_adjustment_set_value(volume, vol);
 
699
        bacon_volume_button_set_value(BACON_VOLUME_BUTTON(mute_button), vol);
 
700
        /*gtk_adjustment_set_value(volume, vol);*/
703
701
}       
704
702
 
705
703
static void mute_button_toggled_cb(GtkButton *button, gpointer data)
790
788
                gtk_window_present(GTK_WINDOW(app));
791
789
        }
792
790
}       
793
 
 
 
791
        
794
792
GtkWidget* gnome_radio_gui(void)
795
793
{
796
794
        GtkWidget *app;
797
795
        GtkWidget *prefs_button, *quit_button, *scfw_button, *scbw_button;
798
796
        GtkWidget *stfw_button, *stbw_button, *about_button, *rec_button;
799
797
        GtkWidget *prefs_pixmap, *quit_pixmap, *scfw_pixmap, *scbw_pixmap;
800
 
        GtkWidget *stfw_pixmap, *stbw_pixmap, *about_pixmap, *mute_pixmap, *rec_pixmap;
 
798
        GtkWidget *stfw_pixmap, *stbw_pixmap, *about_pixmap;
801
799
        GtkWidget *vol_up_pixmap, *vol_down_pixmap, *freq_up_pixmap, *freq_down_pixmap;
802
800
        GdkPixbuf *vol_up_pixbuf, *vol_down_pixbuf, *freq_up_pixbuf, *freq_down_pixbuf;
803
801
        GtkWidget *hbox1, *hbox2, *vbox, *menubox, *freq_vol_box;
804
 
        GtkWidget *vseparator1, *vseparator2, *vseparator3, *vseparator4;
 
802
        GtkWidget *vseparator1, *vseparator2, *vseparator4;
805
803
        GtkWidget *label;
806
804
        GtkWidget *frame;
807
805
        gchar *text;
821
819
        stfw_pixmap = gtk_image_new_from_stock(GTK_STOCK_MEDIA_NEXT, GTK_ICON_SIZE_LARGE_TOOLBAR);
822
820
        stbw_pixmap = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS, GTK_ICON_SIZE_LARGE_TOOLBAR);
823
821
        about_pixmap = gtk_image_new_from_stock(GTK_STOCK_ABOUT, GTK_ICON_SIZE_LARGE_TOOLBAR);
824
 
        mute_pixmap = gtk_image_new_from_stock(GNOME_STOCK_VOLUME, GTK_ICON_SIZE_LARGE_TOOLBAR);
 
822
        /*mute_pixmap = gtk_image_new_from_stock(GNOME_STOCK_VOLUME, GTK_ICON_SIZE_LARGE_TOOLBAR);*/
825
823
        rec_pixmap = gtk_image_new_from_stock(GTK_STOCK_MEDIA_RECORD, GTK_ICON_SIZE_LARGE_TOOLBAR);
826
824
        /*help_pixmap = gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_LARGE_TOOLBAR);*/
827
825
        
832
830
        stfw_button = gtk_button_new();
833
831
        stbw_button = gtk_button_new();
834
832
        about_button = gtk_button_new();
835
 
        mute_button = gtk_toggle_button_new();
 
833
        /*mute_button = gtk_toggle_button_new();*/
 
834
        mute_button = bacon_volume_button_new(GTK_ICON_SIZE_LARGE_TOOLBAR, 0, 100, 1);
 
835
        gtk_button_set_relief(GTK_BUTTON(mute_button), GTK_RELIEF_NORMAL);
836
836
        rec_button = gtk_button_new();
837
837
        /*help_button = gtk_button_new();*/
838
838
 
843
843
        gtk_container_add(GTK_CONTAINER(stfw_button), stfw_pixmap);
844
844
        gtk_container_add(GTK_CONTAINER(stbw_button), stbw_pixmap);
845
845
        gtk_container_add(GTK_CONTAINER(about_button), about_pixmap);
846
 
        gtk_container_add(GTK_CONTAINER(mute_button), mute_pixmap);
 
846
        /*gtk_container_add(GTK_CONTAINER(mute_button), mute_pixmap);*/
847
847
        gtk_container_add(GTK_CONTAINER(rec_button), rec_pixmap);
848
848
        /*gtk_container_add(GTK_CONTAINER(help_button), help_pixmap);*/
849
849
 
854
854
        freq_vol_box = gtk_hbox_new(FALSE, 0);
855
855
        
856
856
        adj = GTK_ADJUSTMENT(gtk_adjustment_new(SUNSHINE*STEPS, FREQ_MIN*STEPS, FREQ_MAX*STEPS+1, 1, STEPS, 1));
857
 
        volume = GTK_ADJUSTMENT(gtk_adjustment_new(100, 0, 101, 1, 10, 1));
 
857
/*      volume = GTK_ADJUSTMENT(gtk_adjustment_new(100, 0, 101, 1, 10, 1)); */
858
858
        
859
859
        preset_combo = gtk_combo_box_new_text();
860
860
        g_signal_connect(GTK_OBJECT(preset_combo), "changed", GTK_SIGNAL_FUNC(preset_combo_change_cb), NULL);
864
864
        
865
865
        freq_scale = gtk_hscale_new(adj);
866
866
        /*gtk_range_set_update_policy(GTK_RANGE(freq_scale), GTK_UPDATE_DELAYED);*/
867
 
        vol_scale = gtk_hscale_new(volume);
 
867
        /*vol_scale = gtk_hscale_new(volume);*/
868
868
        
869
 
        vol_up_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_up_xpm);
870
 
        vol_down_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_down_xpm);
 
869
        /*vol_up_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_up_xpm);
 
870
        vol_down_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_down_xpm);*/
871
871
        freq_up_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)freq_up_xpm);
872
872
        freq_down_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)freq_down_xpm);
873
873
 
874
 
        vol_up_pixmap = gtk_image_new_from_pixbuf(vol_up_pixbuf);
875
 
        vol_down_pixmap = gtk_image_new_from_pixbuf(vol_down_pixbuf);
 
874
        /*vol_up_pixmap = gtk_image_new_from_pixbuf(vol_up_pixbuf);
 
875
        vol_down_pixmap = gtk_image_new_from_pixbuf(vol_down_pixbuf);*/
876
876
        freq_up_pixmap = gtk_image_new_from_pixbuf(freq_up_pixbuf);
877
877
        freq_down_pixmap = gtk_image_new_from_pixbuf(freq_down_pixbuf);
878
878
 
879
879
        /*gtk_widget_set_usize(freq_scale, 160, 10);*/
880
 
        gtk_widget_set_size_request(freq_scale, 160, -1);
 
880
        /*gtk_widget_set_size_request(freq_scale, 160, -1);*/
881
881
 
882
882
        gtk_widget_realize(app);
883
883
        drawing_area = gtk_drawing_area_new();
887
887
        
888
888
        vseparator1 = gtk_vseparator_new();
889
889
        vseparator2 = gtk_vseparator_new();
890
 
        vseparator3 = gtk_vseparator_new();
 
890
        /*vseparator3 = gtk_vseparator_new();*/
891
891
        vseparator4 = gtk_vseparator_new();
892
892
        
893
893
        gtk_scale_set_digits(GTK_SCALE(freq_scale), 0);
894
894
        gtk_scale_set_draw_value(GTK_SCALE(freq_scale), FALSE);
895
 
        gtk_scale_set_digits(GTK_SCALE(vol_scale), 0);
 
895
/*      gtk_scale_set_digits(GTK_SCALE(vol_scale), 0);
896
896
        gtk_scale_set_draw_value(GTK_SCALE(vol_scale), FALSE);
897
897
 
898
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_button), mixer_get_volume() == 0);
 
898
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_button), mixer_get_volume() == 0);*/
899
899
 
900
900
        gtk_widget_set_size_request(drawing_area, DIGIT_WIDTH*6+10+SIGNAL_WIDTH+STEREO_WIDTH, DIGIT_HEIGTH+10);
901
901
 
922
922
        gtk_box_pack_start(GTK_BOX(menubox), preset_combo, TRUE, TRUE, 0);
923
923
 
924
924
        gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_down_pixmap, FALSE, FALSE, 2);
925
 
        gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_scale, FALSE, FALSE, 0);
 
925
        gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_scale, TRUE, TRUE, 0);
926
926
        gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_up_pixmap, FALSE, FALSE, 2);
927
 
        gtk_box_pack_start(GTK_BOX(freq_vol_box), vseparator3, FALSE, FALSE, 2);
 
927
        /*gtk_box_pack_start(GTK_BOX(freq_vol_box), vseparator3, FALSE, FALSE, 2);
928
928
        gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_down_pixmap, FALSE, FALSE, 2);
929
929
        gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_scale, TRUE, TRUE, 0);
930
 
        gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_up_pixmap, FALSE, FALSE, 2);
 
930
        gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_up_pixmap, FALSE, FALSE, 2);*/
931
931
 
932
932
        gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 4);
933
933
        gtk_box_pack_start(GTK_BOX(vbox), freq_vol_box, TRUE, TRUE, 2);
949
949
        g_signal_connect(GTK_OBJECT(app), "delete_event", GTK_SIGNAL_FUNC(delete_event_cb), NULL);
950
950
        g_signal_connect(GTK_OBJECT(quit_button), "clicked", GTK_SIGNAL_FUNC(quit_button_clicked_cb), NULL);
951
951
        g_signal_connect(GTK_OBJECT(adj), "value-changed", GTK_SIGNAL_FUNC(adj_value_changed_cb), (gpointer) app);
952
 
        g_signal_connect(GTK_OBJECT(volume), "value-changed", GTK_SIGNAL_FUNC(volume_value_changed_cb), NULL);
 
952
        g_signal_connect(GTK_OBJECT(mute_button), "value-changed", GTK_SIGNAL_FUNC(volume_value_changed_cb), NULL);
953
953
        g_signal_connect(GTK_OBJECT(stfw_button), "pressed", GTK_SIGNAL_FUNC(step_button_pressed_cb), (gpointer)TRUE);
954
954
        g_signal_connect(GTK_OBJECT(stbw_button), "pressed", GTK_SIGNAL_FUNC(step_button_pressed_cb), (gpointer)FALSE);
955
955
        g_signal_connect(GTK_OBJECT(stfw_button), "clicked", GTK_SIGNAL_FUNC(step_button_clicked_cb), (gpointer)TRUE);
959
959
        g_signal_connect(GTK_OBJECT(scfw_button), "clicked", GTK_SIGNAL_FUNC(scfw_button_clicked_cb), NULL);
960
960
        g_signal_connect(GTK_OBJECT(scbw_button), "clicked", GTK_SIGNAL_FUNC(scbw_button_clicked_cb), NULL);
961
961
        g_signal_connect(GTK_OBJECT(about_button), "clicked", GTK_SIGNAL_FUNC(about_button_clicked_cb), NULL);
962
 
        mute_button_toggled_cb_id =
963
 
                g_signal_connect(GTK_OBJECT(mute_button), "toggled", GTK_SIGNAL_FUNC(mute_button_toggled_cb), NULL);
964
962
        g_signal_connect(GTK_OBJECT(rec_button), "clicked", GTK_SIGNAL_FUNC(rec_button_clicked_cb), (gpointer) app);
965
963
        g_signal_connect(GTK_OBJECT(prefs_button), "clicked", GTK_SIGNAL_FUNC(prefs_button_clicked_cb), (gpointer) app);
966
964
        g_signal_connect(GTK_OBJECT(drawing_area), "expose-event", GTK_SIGNAL_FUNC(expose_event_cb), NULL);
977
975
        text = g_strdup_printf(_("Frequency: %.2f MHz"), adj->value/STEPS);
978
976
        gtk_tooltips_set_tip(tooltips, freq_scale, text, NULL);
979
977
        g_free(text);
980
 
        text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
 
978
/*      text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
981
979
        gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
982
 
        g_free(text);
 
980
        g_free(text);*/
983
981
        
984
982
        return app;
985
983
}
1017
1015
        GtkToggleButton *tb = GTK_TOGGLE_BUTTON(mute_button);
1018
1016
        gboolean state = gtk_toggle_button_get_active(tb);
1019
1017
        /*g_print("%s key pressed: %d\n",  gdk_keyval_name(event->keyval), event->keyval);*/
 
1018
 
 
1019
        int vol = (int)(bacon_volume_button_get_value(BACON_VOLUME_BUTTON(mute_button)) + 0.5f);
1020
1020
        
1021
1021
        switch (event->keyval)
1022
1022
        {
1045
1045
                                break;
1046
1046
                case GDK_KP_Add:
1047
1047
                case GDK_plus:  
1048
 
                                gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);
 
1048
                                bacon_volume_button_set_value(BACON_VOLUME_BUTTON(mute_button), vol > 95 ? 100 : vol + 5);
 
1049
                                /*gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);*/
1049
1050
                                break;
1050
1051
                case GDK_minus:
1051
1052
                case GDK_KP_Subtract: 
1052
 
                                gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);
 
1053
                                bacon_volume_button_set_value(BACON_VOLUME_BUTTON(mute_button), vol < 5 ? 0 : vol - 5);
 
1054
                                /*gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);*/
1053
1055
                                break;
1054
1056
        }
1055
1057
        return FALSE;