Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[6b8ec8]: src / settings.c Maximize Restore History

Download this file

settings.c    336 lines (292 with data), 9.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Copyright (C) 2002-2007 the xine-project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*
* settings implementation
*/
#include "globals.h"
#include <X11/Xlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "settings.h"
#include "ui.h"
#include "utils.h"
struct slider_s {
const char *label, *icon;
control_adjustment_t type;
};
struct slider_group_s {
const char *label;
const struct slider_s *sliders;
};
struct slider_tab_s {
const gchar *title;
const struct slider_s *sliders;
GtkWidget *tabbox;
};
static const struct slider_s settings_video[] = {
{ N_("A/V sync"), "gxine-settings-av-sync", Control_AV_SYNC },
{ N_("SPU sync"), "gxine-settings-spu", Control_SPU_SYNC },
{ N_("Hue"), "gxine-settings-hue", Control_HUE },
{ N_("Saturation"), "gxine-settings-saturation", Control_SATURATION },
{ N_("Contrast"), "gxine-settings-contrast", Control_CONTRAST },
{ N_("Brightness"), "gxine-settings-brightness", Control_BRIGHTNESS },
{ NULL }
};
static const struct slider_s settings_audio[] = {
{ N_("Volume"), "gxine-settings-volume", Control_VOLUME },
{ N_("Compressor"), "gxine-settings-compressor", Control_COMPRESSOR },
{ N_("Amplifier"), "gxine-settings-amplifier", Control_AMPLIFIER },
{ NULL }
};
static const struct slider_s settings_equaliser[] = {
{ N_("30Hz"), NULL, Control_EQ_30 },
{ N_("60Hz"), NULL, Control_EQ_60 },
{ N_("125Hz"), NULL, Control_EQ_125 },
{ N_("250Hz"), NULL, Control_EQ_250 },
{ N_("500Hz"), NULL, Control_EQ_500 },
{ N_("1kHz"), NULL, Control_EQ_1K },
{ N_("2kHz"), NULL, Control_EQ_2K },
{ N_("4kHz"), NULL, Control_EQ_4K },
{ N_("8kHz"), NULL, Control_EQ_8K },
{ N_("16kHz"), NULL, Control_EQ_16K },
{ NULL }
};
static const struct slider_group_s settings_page[] = {
{ N_("Video"), settings_video },
{ N_("Audio"), settings_audio },
{ N_("Equaliser"), settings_equaliser },
{ NULL }
};
#define NUM_PAGES (G_N_ELEMENTS (settings_page) - 1)
struct slider_window_s {
const gchar *title;
const struct slider_group_s *sliders;
GtkWidget *window, *tabbox;
gboolean is_visible;
};
static struct slider_window_s settings_window = {
N_("Controls"), settings_page, NULL, FALSE
};
static const struct slider_s *
get_sliders (const struct slider_window_s *window, guint page)
{
if (page >= NUM_PAGES)
{
page = (guint) gtk_notebook_get_current_page (GTK_NOTEBOOK(window->tabbox));
if (page >= NUM_PAGES)
return NULL;
}
return window->sliders[page].sliders;
}
#define SLIDERS_SET(FUNC) \
static gboolean sliders_##FUNC (const struct slider_window_s *window, \
guint page, gboolean allow_vol) \
{ \
const struct slider_s *slider = get_sliders (window, page); \
if (slider) \
for (; slider->label; ++slider) \
{ \
if (slider->type != Control_VOLUME || allow_vol) \
ui_##FUNC##_control_adjustment (slider->type); \
} \
else \
for (page = 0; page < NUM_PAGES; ++page) \
sliders_##FUNC (window, page, allow_vol); \
return FALSE; \
}
#define JSFUNC(OBJ,FUNC) \
static JSBool js_##OBJ##_##FUNC (JSContext *cx, JSObject *obj, uintN argc, \
jsval *argv, jsval *rval) \
{ \
int page = -1; \
se_log_fncall_checkinit (#OBJ"_"#FUNC); \
se_argc_check_max (1, #OBJ"_"#FUNC); \
if (argc) \
{ \
se_arg_is_int_or_bool (0, #OBJ"_"#FUNC); \
JS_ValueToInt32 (cx, argv[0], &page); \
} \
sliders_##FUNC (&OBJ##_window, page, TRUE); \
return JS_TRUE; \
}
#define JSDECL(OBJ,FUNC) \
{ #OBJ"_"#FUNC, js_##OBJ##_##FUNC, 0, 0,SE_GROUP_DIALOGUE, NULL, NULL }
static void sliders_show (struct slider_window_s *window, guint page,
gboolean unused)
{
guint current =
(guint) gtk_notebook_get_current_page (GTK_NOTEBOOK(window->tabbox));
window->is_visible = (page != (guint) -1 && page != current)
? TRUE : !window->is_visible;
if (window->is_visible)
{
window_show (window->window, NULL);
if (page < NUM_PAGES)
gtk_notebook_set_current_page (GTK_NOTEBOOK(window->tabbox), page);
}
else
gtk_widget_hide (window->window);
}
SLIDERS_SET(revert)
SLIDERS_SET(reset)
SLIDERS_SET(clear)
static void response_cb (GtkDialog *dbox, gint response, gpointer data)
{
struct slider_window_s *window = data;
switch (response)
{
case GTK_RESPONSE_REJECT:
sliders_revert (window, -1, TRUE);
break;
case 1:
sliders_reset (window, -1, TRUE);
break;
default:
window->is_visible = FALSE;
gtk_widget_hide (window->window);
}
}
JSFUNC (settings, show)
JSFUNC (settings, revert)
JSFUNC (settings, reset)
JSFUNC (settings, clear)
struct slider_data_s {
GtkLabel *label;
gdouble value;
uintptr_t sequence;
};
static gboolean slider_set_text (struct slider_data_s *data)
{
if (data->sequence >= (intptr_t) g_object_get_data ((GObject *)data->label, "slider_seq"))
{
char n[12];
sprintf (n, "%.0f", data->value);
gtk_label_set_text (data->label, n);
}
free (data);
return FALSE;
}
static gchar *slider_format_value (GtkScale *scale, gdouble value,
gpointer data)
{
struct slider_data_s *slider = malloc (sizeof (struct slider_data_s));
slider->sequence = (intptr_t) g_object_get_data (data, "slider_seq");
g_object_set_data (data, "slider_seq", (gpointer) (++slider->sequence));
slider->label = data;
slider->value = scale->range.adjustment->value; /* don't trust the input value */
g_idle_add ((GSourceFunc) slider_set_text, slider);
return g_strdup ("");
}
static void sliders_create (struct slider_window_s *window)
{
unsigned int page;
int lock;
xine_cfg_entry_t entry;
/* window */
window->window = gtk_dialog_new_with_buttons (gettext (window->title),
NULL, 0, NULL);
GtkDialog *dbox = GTK_DIALOG (window->window);
gtk_dialog_add_action_widget (dbox,
ui_button_new_stock_mnemonic
(GTK_STOCK_CLEAR, _("_Default")),
1);
gtk_dialog_add_buttons (dbox,
GTK_STOCK_UNDO, GTK_RESPONSE_REJECT,
GTK_STOCK_CLOSE, GTK_RESPONSE_DELETE_EVENT,
NULL);
gtk_window_set_default_size (GTK_WINDOW (dbox), 500, 150);
hide_on_delete (window->window, &window->is_visible);
ui_add_undo_response (window->window, NULL);
g_signal_connect (G_OBJECT(window->window), "response",
G_CALLBACK(response_cb), window);
window->tabbox = gtk_notebook_new ();
/* sliders */
for (page = 0; page < NUM_PAGES; ++page)
{
GtkWidget *table = gtk_table_new (3, 2, FALSE);
const struct slider_s *sliders = window->sliders[page].sliders;
int i;
gdouble min = INT_MAX, max = INT_MIN;
for (i = 0; sliders[i].label; ++i)
{
GtkAdjustment *adj;
GtkWidget *w, *v;
gtk_table_attach (GTK_TABLE(table),
ui_label_new_with_xalign (gettext (sliders[i].label), 1),
0, 1, i, i+1, GTK_FILL, GTK_FILL, 2, 2);
v = ui_label_new_with_xalign ("", 1);
gtk_table_attach (GTK_TABLE(table), v, 1, 2, i, i+1, GTK_FILL, GTK_FILL, 2, 2);
if (sliders[i].icon)
gtk_table_attach (GTK_TABLE(table), gtk_image_new_from_stock (sliders[i].icon, GTK_ICON_SIZE_MENU),
2, 3, i, i+1, GTK_FILL, GTK_FILL, 2, 2);
adj = (GtkAdjustment *) ui_register_control_adjustment (sliders[i].type);
if (adj->lower < min)
min = adj->lower;
if (adj->upper > max)
max = adj->upper;
w = ui_hscale_new ((GtkObject *)adj, GTK_POS_LEFT, 0);
ui_register_adjustment_widget (sliders[i].type, w);
g_signal_connect (G_OBJECT(w), "format-value",
G_CALLBACK(slider_format_value), v);
gtk_table_attach (GTK_TABLE(table), w,
3, 4, i, i+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
}
min = min ? floor (log10 (fabs (min))) + 1 + (min < 0) : 1;
max = max ? floor (log10 (fabs (max))) + 1 + (max < 0) : 1;
if (min > max)
max = min;
{ /* create an 'invisible' label to set the width of the second column */
static const char pad[] = "9999999999999";
GtkWidget *w =
gtk_label_new (pad + sizeof (pad) - 1 -
(max > (int) sizeof (pad) ? (int) sizeof (pad)
: (int) max));
gtk_widget_set_size_request (w, -1, 1);
gtk_table_attach (GTK_TABLE(table), w,
1, 2, i, i+1, GTK_FILL, GTK_FILL, 2, 0);
/* add the table to the notebook */
w = gtk_label_new (gettext (window->sliders[page].label));
gtk_notebook_insert_page (GTK_NOTEBOOK(window->tabbox), table, w, -1);
}
}
gtk_box_pack_start (GTK_BOX(dbox->vbox), window->tabbox, TRUE, TRUE, 2);
lock = xine_config_lookup_entry (xine, "audio.volume.remember_volume", &entry)
&& !entry.num_value;
for (page = 0; page < NUM_PAGES; ++page)
sliders_revert (window, page, lock);
}
void settings_init (void)
{
static const se_f_def_t defs[] = {
JSDECL (settings, show),
JSDECL (settings, revert),
JSDECL (settings, reset),
JSDECL (settings, clear),
{ NULL }
};
sliders_create (&settings_window);
se_defuns (gse, NULL, defs);
}
void settings_clear (void)
{
js_settings_clear (gse->cx, NULL, 0, NULL, NULL);
}