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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <locale.h>
#ifdef HAVE_X11_XLIB_H
#include <X11/Xlib.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#include <shellapi.h>
#endif
#include <glib.h>
#include <glib/gprintf.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gtk-vlc-player.h>
#include <gtk-experiment-navigator.h>
#include <gtk-experiment-transcript.h>
#include <experiment-reader.h>
#include "experiment-player.h"
static inline void button_image_set_from_stock(GtkButton *widget, const gchar *name);
GtkWidget *player_widget,
*controls_hbox,
*scale_widget,
*playpause_button,
*volume_button;
GtkWidget *transcript_table,
*transcript_wizard_widget,
*transcript_proband_widget,
*transcript_scroll_widget;
GtkWidget *navigator_scrolledwindow,
*navigator_widget;
gchar *current_filename = NULL;
#define SPEAKER_WIZARD "Wizard"
#define SPEAKER_PROBAND "Proband"
/*
* GtkBuilder signal callbacks
* NOTE: for some strange reason the parameters are switched
*/
void
playpause_button_clicked_cb(GtkWidget *widget, gpointer data)
{
gboolean is_playing = gtk_vlc_player_toggle(GTK_VLC_PLAYER(widget));
button_image_set_from_stock(GTK_BUTTON(data),
is_playing ? GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE);
}
void
stop_button_clicked_cb(GtkWidget *widget,
gpointer data __attribute__((unused)))
{
gtk_vlc_player_stop(GTK_VLC_PLAYER(widget));
button_image_set_from_stock(GTK_BUTTON(playpause_button),
GTK_STOCK_MEDIA_PLAY);
}
void
file_menu_openmovie_item_activate_cb(GtkWidget *widget,
gpointer data __attribute__((unused)))
{
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new("Open Movie...", GTK_WINDOW(widget),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *file;
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (load_media_file(file)) {
/* TODO */
}
refresh_quickopen_menu(GTK_MENU(quickopen_menu));
g_free(file);
}
gtk_widget_destroy(dialog);
}
void
file_menu_opentranscript_item_activate_cb(GtkWidget *widget,
gpointer data __attribute__((unused)))
{
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new("Open Transcript...", GTK_WINDOW(widget),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *file;
file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (load_transcript_file(file)) {
/* TODO */
}
refresh_quickopen_menu(GTK_MENU(quickopen_menu));
g_free(file);
}
gtk_widget_destroy(dialog);
}
void
help_menu_manual_item_activate_cb(GtkWidget *widget __attribute__((unused)),
gpointer data __attribute__((unused)))
{
GError *err = NULL;
gboolean res;
#ifdef HAVE_WINDOWS_H
res = (int)ShellExecute(NULL, "open", HELP_URI,
NULL, NULL, SW_SHOWNORMAL) <= 32;
if (res)
err = g_error_new(g_quark_from_static_string("Cannot open!"), 0,
"Cannot open '%s'!", HELP_URI);
#else
res = !gtk_show_uri(NULL, HELP_URI, GDK_CURRENT_TIME, &err);
#endif
if (res) {
show_message_dialog_gerror(err);
g_error_free(err);
}
}
void
navigator_widget_time_selected_cb(GtkWidget *widget, gint64 selected_time,
gpointer user_data __attribute__((unused)))
{
gtk_vlc_player_seek(GTK_VLC_PLAYER(widget), selected_time);
}
void
generic_quit_cb(GtkWidget *widget __attribute__((unused)),
gpointer data __attribute__((unused)))
{
gtk_main_quit();
}
static inline void
button_image_set_from_stock(GtkButton *widget, const gchar *name)
{
GtkWidget *image = gtk_bin_get_child(GTK_BIN(widget));
gtk_image_set_from_stock(GTK_IMAGE(image), name,
GTK_ICON_SIZE_SMALL_TOOLBAR);
}
gboolean
load_media_file(const gchar *file)
{
if (gtk_vlc_player_load_filename(GTK_VLC_PLAYER(player_widget), file))
return TRUE;
g_free(current_filename);
current_filename = g_strdup(file);
gtk_widget_set_sensitive(controls_hbox, TRUE);
button_image_set_from_stock(GTK_BUTTON(playpause_button),
GTK_STOCK_MEDIA_PLAY);
return FALSE;
}
gboolean
load_transcript_file(const gchar *file)
{
ExperimentReader *reader;
gboolean res;
reader = experiment_reader_new(file);
if (reader == NULL)
return TRUE;
res = gtk_experiment_transcript_load(GTK_EXPERIMENT_TRANSCRIPT(transcript_wizard_widget),
reader);
if (res) {
g_object_unref(G_OBJECT(reader));
return TRUE;
}
res = gtk_experiment_transcript_load(GTK_EXPERIMENT_TRANSCRIPT(transcript_proband_widget),
reader);
if (res) {
g_object_unref(G_OBJECT(reader));
return TRUE;
}
res = gtk_experiment_navigator_load(GTK_EXPERIMENT_NAVIGATOR(navigator_widget),
reader);
if (res) {
g_object_unref(G_OBJECT(reader));
return TRUE;
}
g_object_unref(reader);
gtk_widget_set_sensitive(transcript_table, TRUE);
gtk_widget_set_sensitive(navigator_scrolledwindow, TRUE);
return FALSE;
}
void
show_message_dialog_gerror(GError *err)
{
GtkWidget *dialog;
if (err == NULL)
return;
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
"%s", err->message);
gtk_window_set_title(GTK_WINDOW(dialog), "Error");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
int
main(int argc, char *argv[])
{
GtkBuilder *builder;
GtkExperimentTranscript *transcript_wizard, *transcript_proband;
GtkAdjustment *adj;
PangoFontDescription *font_desc;
GdkColor color;
GtkRcStyle *modified_style;
/* FIXME: support internationalization instead of enforcing English */
#ifdef __WIN32__
g_setenv("LC_ALL", "English", TRUE);
#else
g_setenv("LC_ALL", "en", TRUE);
#endif
setlocale(LC_ALL, "");
/* init threads */
#ifdef HAVE_X11_XLIB_H
XInitThreads(); /* FIXME: really required??? */
#endif
g_thread_init(NULL);
gdk_threads_init();
gtk_init(&argc, &argv);
config_init_key_file();
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, DEFAULT_UI, NULL);
gtk_builder_connect_signals(builder, NULL);
BUILDER_INIT(builder, player_widget);
BUILDER_INIT(builder, controls_hbox);
BUILDER_INIT(builder, scale_widget);
BUILDER_INIT(builder, playpause_button);
BUILDER_INIT(builder, volume_button);
BUILDER_INIT(builder, quickopen_menu);
BUILDER_INIT(builder, quickopen_menu_empty_item);
BUILDER_INIT(builder, transcript_table);
BUILDER_INIT(builder, transcript_wizard_widget);
transcript_wizard = GTK_EXPERIMENT_TRANSCRIPT(transcript_wizard_widget);
BUILDER_INIT(builder, transcript_proband_widget);
transcript_proband = GTK_EXPERIMENT_TRANSCRIPT(transcript_proband_widget);
BUILDER_INIT(builder, transcript_scroll_widget);
BUILDER_INIT(builder, transcript_wizard_combo);
BUILDER_INIT(builder, transcript_proband_combo);
BUILDER_INIT(builder, transcript_wizard_entry_check);
BUILDER_INIT(builder, transcript_proband_entry_check);
BUILDER_INIT(builder, navigator_scrolledwindow);
BUILDER_INIT(builder, navigator_widget);
g_object_unref(G_OBJECT(builder));
/** @todo most of this could be done in Glade with proper catalog files */
/* connect timeline, volume button and other widgets with player widget */
adj = gtk_vlc_player_get_time_adjustment(GTK_VLC_PLAYER(player_widget));
gtk_range_set_adjustment(GTK_RANGE(scale_widget), adj);
gtk_experiment_transcript_set_time_adjustment(GTK_EXPERIMENT_TRANSCRIPT(transcript_wizard_widget),
adj);
gtk_experiment_transcript_set_time_adjustment(GTK_EXPERIMENT_TRANSCRIPT(transcript_proband_widget),
adj);
gtk_range_set_adjustment(GTK_RANGE(transcript_scroll_widget), adj);
adj = gtk_vlc_player_get_volume_adjustment(GTK_VLC_PLAYER(player_widget));
gtk_scale_button_set_adjustment(GTK_SCALE_BUTTON(volume_button), adj);
/* configure transcript widgets */
transcript_wizard->speaker = g_strdup(SPEAKER_WIZARD);
font_desc = config_get_transcript_font(SPEAKER_WIZARD);
if (font_desc != NULL) {
gtk_widget_modify_font(transcript_wizard_widget, font_desc);
pango_font_description_free(font_desc);
}
if (config_get_transcript_text_color(SPEAKER_WIZARD, &color))
gtk_widget_modify_text(transcript_wizard_widget,
GTK_STATE_NORMAL, &color);
if (config_get_transcript_bg_color(SPEAKER_WIZARD, &color))
gtk_widget_modify_bg(transcript_wizard_widget,
GTK_STATE_NORMAL, &color);
transcript_wizard->interactive_format.default_font =
config_get_transcript_default_format_font(SPEAKER_WIZARD);
if (config_get_transcript_default_format_text_color(SPEAKER_WIZARD, &color))
transcript_wizard->interactive_format.default_text_color = gdk_color_copy(&color);
if (config_get_transcript_default_format_bg_color(SPEAKER_WIZARD, &color))
transcript_wizard->interactive_format.default_bg_color = gdk_color_copy(&color);
transcript_proband->speaker = g_strdup(SPEAKER_PROBAND);
font_desc = config_get_transcript_font(SPEAKER_PROBAND);
if (font_desc != NULL) {
gtk_widget_modify_font(transcript_proband_widget, font_desc);
pango_font_description_free(font_desc);
}
if (config_get_transcript_text_color(SPEAKER_PROBAND, &color))
gtk_widget_modify_text(transcript_proband_widget,
GTK_STATE_NORMAL, &color);
if (config_get_transcript_bg_color(SPEAKER_PROBAND, &color))
gtk_widget_modify_bg(transcript_proband_widget,
GTK_STATE_NORMAL, &color);
transcript_proband->interactive_format.default_font =
config_get_transcript_default_format_font(SPEAKER_PROBAND);
if (config_get_transcript_default_format_text_color(SPEAKER_PROBAND, &color))
transcript_proband->interactive_format.default_text_color = gdk_color_copy(&color);
if (config_get_transcript_default_format_bg_color(SPEAKER_PROBAND, &color))
transcript_proband->interactive_format.default_bg_color = gdk_color_copy(&color);
format_selection_init();
refresh_quickopen_menu(GTK_MENU(quickopen_menu));
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
modified_style = gtk_widget_get_modifier_style(transcript_wizard_widget);
config_set_transcript_font(SPEAKER_WIZARD, modified_style->font_desc);
config_set_transcript_text_color(SPEAKER_WIZARD,
modified_style->color_flags[GTK_STATE_NORMAL] & GTK_RC_TEXT
? &modified_style->text[GTK_STATE_NORMAL]
: NULL);
config_set_transcript_bg_color(SPEAKER_WIZARD,
modified_style->color_flags[GTK_STATE_NORMAL] & GTK_RC_BG
? &modified_style->bg[GTK_STATE_NORMAL]
: NULL);
g_object_unref(modified_style);
config_set_transcript_default_format_font(SPEAKER_WIZARD,
transcript_wizard->interactive_format.default_font);
config_set_transcript_default_format_text_color(SPEAKER_WIZARD,
transcript_wizard->interactive_format.default_text_color);
config_set_transcript_default_format_bg_color(SPEAKER_WIZARD,
transcript_wizard->interactive_format.default_bg_color);
modified_style = gtk_widget_get_modifier_style(transcript_proband_widget);
config_set_transcript_font(SPEAKER_PROBAND, modified_style->font_desc);
config_set_transcript_text_color(SPEAKER_PROBAND,
modified_style->color_flags[GTK_STATE_NORMAL] & GTK_RC_TEXT
? &modified_style->text[GTK_STATE_NORMAL]
: NULL);
config_set_transcript_bg_color(SPEAKER_PROBAND,
modified_style->color_flags[GTK_STATE_NORMAL] & GTK_RC_BG
? &modified_style->bg[GTK_STATE_NORMAL]
: NULL);
g_object_unref(modified_style);
config_set_transcript_default_format_font(SPEAKER_PROBAND,
transcript_proband->interactive_format.default_font);
config_set_transcript_default_format_text_color(SPEAKER_PROBAND,
transcript_proband->interactive_format.default_text_color);
config_set_transcript_default_format_bg_color(SPEAKER_PROBAND,
transcript_proband->interactive_format.default_bg_color);
config_save_key_file();
return 0;
}
|