~ubuntu-branches/ubuntu/raring/xfce4-volumed/raring

« back to all changes in this revision

Viewing changes to src/xvd_xfconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2009-09-05 22:17:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090905221715-rj1pmaf4ms4r9jvl
Tags: 0.1.4-0ubuntu1
New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
static void
24
24
_xvd_xfconf_reinit_card(XvdInstance *Inst)
25
25
{
26
 
        xvd_clean_card_name(Inst);
27
 
        Inst->card_name = xvd_get_xfconf_card (Inst);
28
 
        if (NULL == Inst->card_name) {
29
 
                g_warning ("The new active card defined in the xfce mixer seems to be wrong.\n");
30
 
                Inst->xvd_init_error = TRUE;
31
 
        }
32
 
        else {
33
 
                
34
 
                xvd_get_xfconf_card_from_mixer (Inst);
35
 
                #ifndef NDEBUG
36
 
                g_print ("New card : %s \n", Inst->card_name);
37
 
                #endif
38
 
        }
 
26
        gchar *previous_card = NULL;
 
27
        
 
28
        if (!xvd_xfconf_get_card (Inst)) {
 
29
                // If we fail to get an xfconf card, we save the current one in xfconf
 
30
                if (Inst->card_name != NULL) {
 
31
                        xvd_xfconf_set_card (Inst, Inst->card_name);
 
32
                        Inst->xfconf_card_name = g_strdup (Inst->card_name);
 
33
                }
 
34
                // If the current card is NULL too, we do nothing
 
35
                return;
 
36
        }
 
37
        
 
38
        // If the card set in xfconf is the same as the currently used one, we do nothing
 
39
        if ((Inst->card_name != NULL) && (g_strcmp0 (Inst->xfconf_card_name, Inst->card_name) == 0)) {
 
40
                return;
 
41
        }
 
42
        
 
43
        // We now try to replace it with the one set in xfconf
 
44
        previous_card = g_strdup (Inst->card_name);
 
45
        xvd_get_card_from_mixer (Inst, Inst->xfconf_card_name, previous_card);
 
46
        
 
47
        // At this stage the track grabbed is wrong, but we expect the user to also update the track key
 
48
        
 
49
        // We check if the card has been correctly set
 
50
        if ((Inst->card_name == NULL) || (g_strcmp0 (Inst->xfconf_card_name, Inst->card_name) != 0)) {
 
51
                g_debug ("The card chosen in xfconf could not be set, another one was set instead\nChosen: %s\nSet: %s\n",
 
52
                                                                                                                Inst->xfconf_card_name,
 
53
                                                                                                                Inst->card_name);
 
54
                // If not, we save the valid card in xfconf instead of the user chosen
 
55
                // TODO we should actually refresh the mixers prior to finding the new card
 
56
                xvd_xfconf_set_card (Inst, Inst->card_name);
 
57
                g_free (Inst->xfconf_card_name);
 
58
                Inst->xfconf_card_name = g_strdup (Inst->card_name);
 
59
        }
 
60
        else {
 
61
                g_debug ("The card change succeeded with the new xfconf card %s.\n", Inst->xfconf_card_name);
 
62
        }
 
63
        
 
64
        g_free (previous_card);
 
65
        
 
66
        // If an xfconf track has failed to be applied before, it's probably that the user chosed his new track before the card to which it belongs.
 
67
        // So we check if the track belongs to our new card.
 
68
        if (Inst->previously_set_track_label) {
 
69
                xvd_get_track_from_mixer (Inst, Inst->previously_set_track_label, Inst->track_label);
 
70
                if (g_strcmp0 (Inst->previously_set_track_label, Inst->track_label) == 0) {
 
71
                        xvd_xfconf_set_track (Inst, Inst->previously_set_track_label);
 
72
                        g_free (Inst->previously_set_track_label);
 
73
                        g_debug ("The previously set xfconf track was a track from the newly set sound card.\n");
 
74
                }
 
75
        }
 
76
        // Else, we can still try to see if the current track applies
 
77
        else {
 
78
                xvd_get_track_from_mixer (Inst, Inst->track_label, NULL);
 
79
        }
 
80
        
 
81
        xvd_mixer_init_volume (Inst);
 
82
 
 
83
        g_debug ("Xfconf reinit: the card is now %s, the track is %s and the volume is %d\n", Inst->card_name, Inst->track_label, Inst->current_vol);
39
84
}
40
85
 
41
86
static void
42
87
_xvd_xfconf_reinit_track(XvdInstance *Inst)
43
88
{
44
 
        xvd_clean_track (Inst);
45
 
        
46
 
        gchar *tmp_track = xvd_get_xfconf_track (Inst);
47
 
        xvd_get_xfconf_track_from_mixer (Inst, tmp_track);
48
 
        g_free (tmp_track);
 
89
        gchar *previous_track = NULL;
 
90
        
 
91
        if (!xvd_xfconf_get_track (Inst)) {
 
92
                // If we fail to get an xfconf track, we save the current one in xfconf
 
93
                if (Inst->track_label != NULL) {
 
94
                        xvd_xfconf_set_track (Inst, Inst->track_label);
 
95
                        Inst->xfconf_track_label = g_strdup (Inst->track_label);
 
96
                }
 
97
                // If the current track is NULL too, we do nothing
 
98
                return;
 
99
        }
 
100
        
 
101
        // If the track set in xfconf is the same as the currently used one, we do nothing
 
102
        if ((Inst->track_label != NULL) && (g_strcmp0 (Inst->xfconf_track_label, Inst->track_label) == 0)) {
 
103
                return;
 
104
        }
 
105
        
 
106
        // We now try to replace it with the one set in xfconf
 
107
        previous_track = g_strdup (Inst->track_label);
 
108
        xvd_get_track_from_mixer (Inst, Inst->xfconf_track_label, previous_track);
49
109
 
 
110
        // We check if the track has been correctly set
 
111
        if ((Inst->track_label == NULL) || (g_strcmp0 (Inst->xfconf_track_label, Inst->track_label) != 0)) {
 
112
                // If not, we save the valid track in xfconf instead of the user chosen
 
113
                Inst->previously_set_track_label = g_strdup (Inst->xfconf_track_label);
 
114
                g_debug ("The track chosen in xfconf (%s) doesn't exist in the current card. It'll be tried again after a sound card change.\nNow using %s.\n",
 
115
                                        Inst->xfconf_track_label,
 
116
                                        Inst->track_label);
 
117
                xvd_xfconf_set_track (Inst, Inst->track_label);
 
118
                g_free (Inst->xfconf_track_label);
 
119
                Inst->xfconf_track_label = g_strdup (Inst->track_label);
 
120
        }
 
121
        else {
 
122
                g_free (Inst->previously_set_track_label);
 
123
        }
 
124
        
50
125
        xvd_mixer_init_volume (Inst);
51
 
        #ifndef NDEBUG
52
 
        g_print ("New track : %s with volume %d\n", Inst->track_label, Inst->current_vol);
53
 
        #endif
 
126
        g_free (previous_track);
 
127
 
 
128
        g_debug ("Xfconf reinit: the track is now %s and the volume is %d\n", Inst->track_label, Inst->current_vol);
54
129
}
55
130
 
56
131
 
57
132
static void
58
133
_xvd_xfconf_reinit_vol_step(XvdInstance *Inst)
59
134
{
60
 
                xvd_load_xfconf_vol_step (Inst);
61
 
                #ifndef NDEBUG
62
 
                g_print ("New volume step : %u\n", Inst->vol_step);
63
 
                #endif
 
135
                xvd_xfconf_get_vol_step (Inst);
 
136
                g_debug ("Xfconf reinit: volume step is now %u\n", Inst->vol_step);
64
137
}
65
138
 
66
139
static void 
70
143
                                                   gpointer       *ptr)
71
144
{
72
145
        XvdInstance *Inst = (XvdInstance *)ptr;
73
 
        #ifndef NDEBUG
74
 
        g_print ("Xfconf event on %s\n", re_property_name);
75
 
        #endif
 
146
        g_debug ("Xfconf event on %s\n", re_property_name);
76
147
        
77
148
        if (g_strcmp0 (re_property_name, XFCONF_MIXER_ACTIVECARD) == 0) {
78
149
                _xvd_xfconf_reinit_card(Inst);
99
170
        g_signal_connect (G_OBJECT (Inst->chan), "property-changed", G_CALLBACK (_xvd_xfconf_handle_changes), Inst);
100
171
}
101
172
 
102
 
gchar *
103
 
xvd_get_xfconf_card(XvdInstance *Inst)
 
173
gboolean 
 
174
xvd_xfconf_get_card(XvdInstance *Inst)
104
175
{
 
176
        if (Inst->xfconf_card_name) {
 
177
                g_debug ("%s\n", "Cleaning the current card name stored in xfconf");
 
178
                g_free (Inst->xfconf_card_name);
 
179
        }
 
180
        
105
181
        if (FALSE == xfconf_channel_has_property (Inst->chan, XFCONF_MIXER_ACTIVECARD)) {
106
182
                // Transition purpose - we dont watch changes on the legacy property afterwards
107
183
                if (FALSE == xfconf_channel_has_property (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY)) {
108
 
                        g_warning ("%s\n", "Error while trying to retrieve the mixer channel's active card");
109
 
                        return NULL;
 
184
                        g_debug ("%s\n", "There is no card name stored in xfconf");
 
185
                        return FALSE;
110
186
                }
111
187
                else {
112
 
                        g_warning ("%s\n", "Using the legacy xfconf property for the active card");
113
 
                        gchar *legacy_value = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY, NULL);
114
 
                        xvd_xfconf_set_card (Inst, legacy_value);
115
 
                        return legacy_value;
 
188
                        g_debug ("%s\n", "Using the legacy xfconf property for the card name, and saving its value into the new xfconf property");
 
189
                        Inst->xfconf_card_name = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY, NULL);
 
190
                        xvd_xfconf_set_card (Inst, Inst->xfconf_card_name);
 
191
                        g_debug ("%s %s\n", "Xfconf card name:", Inst->xfconf_card_name);
 
192
                        return Inst->xfconf_card_name != NULL;
116
193
                }
117
194
        }
118
195
        
119
 
        return xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, NULL);
120
 
}
121
 
 
122
 
gchar *
123
 
xvd_get_xfconf_track(XvdInstance *Inst)
124
 
{
125
 
        return xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, NULL);
126
 
}
127
 
 
128
 
void 
129
 
xvd_load_xfconf_vol_step(XvdInstance *Inst)
 
196
        Inst->xfconf_card_name = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, NULL);
 
197
        return Inst->xfconf_card_name != NULL;
 
198
}
 
199
 
 
200
void 
 
201
xvd_xfconf_set_card(XvdInstance *Inst, gchar *value)
 
202
{
 
203
        g_debug ("%s %s\n", "Setting the xfconf card name to", value);
 
204
        xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, value);
 
205
}
 
206
 
 
207
gboolean
 
208
xvd_xfconf_get_track(XvdInstance *Inst)
 
209
{
 
210
        if (Inst->xfconf_track_label) {
 
211
                g_debug ("%s\n", "Cleaning the current track label stored in xfconf");
 
212
                g_free (Inst->xfconf_track_label);
 
213
        }
 
214
        
 
215
        Inst->xfconf_track_label = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, NULL);
 
216
        if (Inst->xfconf_track_label != NULL) {
 
217
                g_debug ("%s %s\n", "Xfconf track label:", Inst->xfconf_track_label);
 
218
                return TRUE;
 
219
        }
 
220
        else {
 
221
                g_debug ("%s\n", "There is no track label stored in xfconf");
 
222
                return FALSE;
 
223
        }
 
224
}
 
225
 
 
226
void 
 
227
xvd_xfconf_set_track(XvdInstance *Inst, gchar *value)
 
228
{
 
229
        g_debug("%s %s\n", "Setting the xfconf card name to", value);
 
230
        xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, value);
 
231
}
 
232
 
 
233
void 
 
234
xvd_xfconf_get_vol_step(XvdInstance *Inst)
130
235
{
131
236
        Inst->vol_step = xfconf_channel_get_uint (Inst->chan, XFCONF_MIXER_VOL_STEP, -1);
132
237
        if ((Inst->vol_step < 0) || (Inst->vol_step > 100)) {
 
238
                g_debug ("%s\n", "The volume step xfconf property is out of range, setting back to default");
133
239
                Inst->vol_step = VOL_STEP_DEFAULT_VAL;
134
240
                xfconf_channel_set_uint (Inst->chan, XFCONF_MIXER_VOL_STEP, VOL_STEP_DEFAULT_VAL);
135
241
        }
 
242
        g_debug("%s %u\n", "Xfconf volume step:", Inst->vol_step);
136
243
}
137
244
 
138
245
void 
140
247
{
141
248
        xfconf_shutdown ();
142
249
}
143
 
 
144
 
void 
145
 
xvd_xfconf_set_card(XvdInstance *Inst, gchar *value)
146
 
{
147
 
        xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, value);
148
 
}