1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * based on indicator-messages.c written by :
6 * Ted Gould <ted@canonical.com>
7 * Cody Russell <cody.russell@canonical.com>
8 * E-mail : see the 'copyright' file.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include <stdlib.h>
24
25 #include "applet-struct.h"
26 #include "applet-backend-alsamixer.h"
27 #ifdef INDICATOR_SOUNDMENU_WITH_IND3
28 #include "applet-backend-sound-menu.h"
29 #elif defined SOUND_SERVICE_SUPPORT // OLD
30 #include "applet-backend-sound-menu-old.h"
31 #endif
32 #include "applet-generic.h"
33
34
cd_get_volume(void)35 int cd_get_volume (void)
36 {
37 if (myData.ctl.get_volume)
38 return myData.ctl.get_volume ();
39 return 0;
40 }
41
cd_set_volume(int iVolume)42 void cd_set_volume (int iVolume)
43 {
44 if (myData.ctl.set_volume)
45 myData.ctl.set_volume (iVolume);
46 }
47
cd_toggle_mute(void)48 void cd_toggle_mute (void)
49 {
50 if (myData.ctl.toggle_mute)
51 myData.ctl.toggle_mute ();
52 }
53
cd_show_hide(void)54 void cd_show_hide (void)
55 {
56 if (myData.ctl.show_hide)
57 myData.ctl.show_hide ();
58 }
59
cd_stop(void)60 void cd_stop (void)
61 {
62 if (myData.ctl.stop)
63 myData.ctl.stop ();
64 }
65
cd_reload(void)66 void cd_reload (void)
67 {
68 if (myData.ctl.reload)
69 myData.ctl.reload ();
70 }
71
cd_start(void)72 void cd_start (void)
73 {
74 #if defined INDICATOR_SOUNDMENU_WITH_IND3 || defined SOUND_SERVICE_SUPPORT
75 cd_mixer_connect_to_sound_service (); // connect to the sound service, it will fall back to alsa if it's not available.
76 #else
77 cd_mixer_init_alsa ();
78 #endif
79
80 }
81
82
83 /// SCALE ///
84
on_change_volume(GtkRange * range,gpointer data)85 static void on_change_volume (GtkRange *range, gpointer data)
86 {
87 CD_APPLET_ENTER;
88 int iNewVolume = (int) gtk_range_get_value (GTK_RANGE (range));
89 cd_debug ("%s (%d)", __func__, iNewVolume);
90 cd_set_volume (iNewVolume);
91 CD_APPLET_LEAVE();
92 }
mixer_build_widget(gboolean bHorizontal)93 GtkWidget *mixer_build_widget (gboolean bHorizontal)
94 {
95 g_return_val_if_fail (myData.pControledElement != NULL, NULL);
96 GtkWidget *pScale = gtk_scale_new_with_range (bHorizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, 0., 100., .5*myConfig.iScrollVariation);
97 if (! bHorizontal)
98 gtk_range_set_inverted (GTK_RANGE (pScale), TRUE); // de bas en haut.
99
100 myData.iCurrentVolume = cd_get_volume ();
101 gtk_range_set_value (GTK_RANGE (pScale), myData.iCurrentVolume);
102
103 g_signal_connect (G_OBJECT (pScale),
104 "value-changed",
105 G_CALLBACK (on_change_volume),
106 NULL);
107
108 gldi_dialog_set_widget_text_color (pScale);
109 return pScale;
110 }
111
112
cd_mixer_set_volume_with_no_callback(GtkWidget * pScale,int iVolume)113 void cd_mixer_set_volume_with_no_callback (GtkWidget *pScale, int iVolume)
114 {
115 g_signal_handlers_block_matched (GTK_WIDGET(pScale),
116 G_SIGNAL_MATCH_FUNC,
117 0, 0, NULL, (void*)on_change_volume, NULL);
118 gtk_range_set_value (GTK_RANGE (pScale), (double) iVolume);
119 g_signal_handlers_unblock_matched (GTK_WIDGET(pScale),
120 G_SIGNAL_MATCH_FUNC,
121 0, 0, NULL, (void*)on_change_volume, NULL);
122 }
123