diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/default.ui | 244 | ||||
-rw-r--r-- | src/experiment-player.h | 5 | ||||
-rw-r--r-- | src/format-selection.c | 171 | ||||
-rw-r--r-- | src/main.c | 14 |
5 files changed, 333 insertions, 103 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 0f469de..3b1a088 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ AM_CFLAGS = -Wall bin_PROGRAMS = experiment-player -experiment_player_SOURCES = main.c quickopen.c \ +experiment_player_SOURCES = main.c quickopen.c format-selection.c \ experiment-player.h experiment_player_CFLAGS = $(AM_CFLAGS) diff --git a/src/default.ui b/src/default.ui index 91b1fcc..ee9195e 100644 --- a/src/default.ui +++ b/src/default.ui @@ -15,7 +15,7 @@ <property name="visible">True</property> <property name="orientation">vertical</property> <child> - <object class="GtkMenuBar" id="menubar"> + <object class="GtkMenuBar" id="player_window_menubar"> <property name="visible">True</property> <child> <object class="GtkMenuItem" id="file_item"> @@ -263,123 +263,181 @@ audio-volume-medium</property> <property name="default_height">700</property> <property name="deletable">False</property> <child> - <object class="GtkHPaned" id="info_window_hpane"> + <object class="GtkVBox" id="info_window_vbox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="position">339</property> + <property name="orientation">vertical</property> <child> - <object class="GtkTable" id="transcript_table"> + <object class="GtkMenuBar" id="info_window_menubar"> <property name="visible">True</property> - <property name="sensitive">False</property> - <property name="n_rows">3</property> - <property name="n_columns">3</property> - <child> - <object class="GtkExperimentTranscript" id="transcript_wizard_widget"> - <property name="visible">True</property> - </object> - </child> - <child> - <object class="GtkExperimentTranscript" id="transcript_proband_widget"> - <property name="visible">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - </packing> - </child> - <child> - <object class="GtkVScrollbar" id="transcript_scroll_widget"> - <property name="visible">True</property> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="x_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkComboBox" id="transcript_wizard_combo"> - <property name="visible">True</property> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> <child> - <object class="GtkComboBox" id="transcript_proband_combo"> + <object class="GtkMenuItem" id="formats_item"> <property name="visible">True</property> + <property name="label" translatable="yes">_Formats</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="formats_menu"> + <property name="visible">True</property> + <child> + <object class="GtkImageMenuItem" id="formats_menu_choosedir_item"> + <property name="label" translatable="yes">Choose _Directory...</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="image">image5</property> + <property name="use_stock">False</property> + <signal name="activate" handler="formats_menu_choosedir_item_activate_cb" object="info_window"/> + </object> + </child> + <child> + <object class="GtkImageMenuItem" id="formats_menu_refresh_item"> + <property name="label">gtk-refresh</property> + <property name="visible">True</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + <signal name="activate" handler="formats_menu_refresh_item_activate_cb" object="transcript_wizard_combo"/> + </object> + </child> + </object> + </child> </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options">GTK_FILL</property> - </packing> </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHPaned" id="info_window_hpane"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="position">339</property> + <property name="position_set">True</property> <child> - <object class="GtkEntry" id="transcript_wizard_entry"> + <object class="GtkTable" id="transcript_table"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - <signal name="changed" handler="generic_transcript_entry_changed_cb" object="transcript_wizard_widget"/> + <property name="sensitive">False</property> + <property name="n_rows">3</property> + <property name="n_columns">3</property> + <child> + <object class="GtkExperimentTranscript" id="transcript_wizard_widget"> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkExperimentTranscript" id="transcript_proband_widget"> + <property name="visible">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + </packing> + </child> + <child> + <object class="GtkVScrollbar" id="transcript_scroll_widget"> + <property name="visible">True</property> + </object> + <packing> + <property name="left_attach">2</property> + <property name="right_attach">3</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="transcript_proband_combo"> + <property name="visible">True</property> + <signal name="changed" handler="generic_transcript_combo_changed_cb" object="transcript_proband_widget"/> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="transcript_wizard_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <signal name="changed" handler="generic_transcript_entry_changed_cb" object="transcript_wizard_widget"/> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="transcript_proband_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <signal name="changed" handler="generic_transcript_entry_changed_cb" object="transcript_proband_widget"/> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="transcript_wizard_combo"> + <property name="visible">True</property> + <signal name="changed" handler="generic_transcript_combo_changed_cb" object="transcript_wizard_widget"/> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> </object> <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="y_options">GTK_FILL</property> + <property name="resize">True</property> + <property name="shrink">True</property> </packing> </child> <child> - <object class="GtkEntry" id="transcript_proband_entry"> + <object class="GtkScrolledWindow" id="navigator_scrolledwindow"> <property name="visible">True</property> + <property name="sensitive">False</property> <property name="can_focus">True</property> - <property name="invisible_char">●</property> - <signal name="changed" handler="generic_transcript_entry_changed_cb" object="transcript_proband_widget"/> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <child> + <object class="GtkExperimentNavigator" id="navigator_widget"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> + <signal name="time_selected" handler="navigator_widget_time_selected_cb" object="player_widget"/> + </object> + </child> </object> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="y_options">GTK_FILL</property> + <property name="resize">True</property> + <property name="shrink">True</property> </packing> </child> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="resize">True</property> - <property name="shrink">True</property> - </packing> - </child> - <child> - <object class="GtkScrolledWindow" id="navigator_scrolledwindow"> - <property name="visible">True</property> - <property name="sensitive">False</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">automatic</property> - <property name="vscrollbar_policy">automatic</property> - <child> - <object class="GtkExperimentNavigator" id="navigator_widget"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <signal name="time_selected" handler="navigator_widget_time_selected_cb" object="player_widget"/> - </object> - </child> </object> <packing> - <property name="resize">True</property> - <property name="shrink">True</property> + <property name="position">1</property> </packing> </child> </object> </child> </object> + <object class="GtkImage" id="image5"> + <property name="visible">True</property> + <property name="stock">gtk-directory</property> + </object> </interface> diff --git a/src/experiment-player.h b/src/experiment-player.h index 01c6dce..a8f6e87 100644 --- a/src/experiment-player.h +++ b/src/experiment-player.h @@ -31,6 +31,11 @@ extern GtkWidget *quickopen_menu, extern gchar *quickopen_directory; +void format_selection_init(const gchar *dir); + +extern GtkWidget *transcript_wizard_combo, + *transcript_proband_combo; + #define BUILDER_INIT(BUILDER, VAR) do { \ VAR = GTK_WIDGET(gtk_builder_get_object(BUILDER, #VAR)); \ } while (0) diff --git a/src/format-selection.c b/src/format-selection.c new file mode 100644 index 0000000..f7c3c22 --- /dev/null +++ b/src/format-selection.c @@ -0,0 +1,171 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <assert.h> + +#include <glib.h> +#include <glib/gprintf.h> + +#include <gtk/gtk.h> + +#include <gtk-experiment-transcript.h> + +#include "experiment-player.h" + +static void refresh_formats_store(GtkListStore *store); + +GtkWidget *transcript_wizard_combo, + *transcript_proband_combo; + +static gchar *formats_directory; + +enum { + COL_NAME, + COL_FILENAME, + NUM_COLS +}; + +/* + * GtkBuilder signal callbacks + * NOTE: for some strange reason the parameters are switched + */ + +void +formats_menu_choosedir_item_activate_cb(GtkWidget *widget, + gpointer data __attribute__((unused))) +{ + GtkTreeModel *model = + gtk_combo_box_get_model(GTK_COMBO_BOX(transcript_wizard_combo)); + + GtkWidget *dialog; + + dialog = gtk_file_chooser_dialog_new("Choose Directory...", GTK_WINDOW(widget), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), + formats_directory); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + g_free(formats_directory); + formats_directory = + gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + refresh_formats_store(GTK_LIST_STORE(model)); + } + + gtk_widget_destroy(dialog); +} + +void +formats_menu_refresh_item_activate_cb(GtkWidget *widget, + gpointer data __attribute__((unused))) +{ + GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget)); + + refresh_formats_store(GTK_LIST_STORE(model)); +} + +void +generic_transcript_combo_changed_cb(gpointer user_data, GtkComboBox *combo) +{ + GtkExperimentTranscript *trans = GTK_EXPERIMENT_TRANSCRIPT(user_data); + + GtkTreeModel *model = gtk_combo_box_get_model(combo); + GtkTreeIter iter; + gchar *filename; + + if (!gtk_combo_box_get_active_iter(combo, &iter)) + return; + + gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1); + + /* + * filename may be empty (null-entry) in which case any active format + * will be reset + */ + gtk_experiment_transcript_load_formats(trans, filename); + g_free(filename); + + refresh_formats_store(GTK_LIST_STORE(model)); +} + +void +generic_transcript_entry_changed_cb(gpointer user_data, GtkEditable *editable) +{ + GtkExperimentTranscript *trans = GTK_EXPERIMENT_TRANSCRIPT(user_data); + const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable)); + + /** @todo enable/disable markup */ + gtk_experiment_transcript_set_interactive_format(trans, text, TRUE); +} + +static void +refresh_formats_store(GtkListStore *store) +{ + static GPatternSpec *pattern = NULL; + + GDir *dir; + const gchar *name; + GtkTreeIter iter; + + if (pattern == NULL) + pattern = g_pattern_spec_new(EXPERIMENT_FORMAT_FILTER); + + gtk_list_store_clear(store); + /* add null-entry */ + gtk_list_store_append(store, &iter); + + dir = g_dir_open(formats_directory, 0, NULL); + + while ((name = g_dir_read_name(dir)) != NULL) { + gchar *fullname; + + if (!g_pattern_match_string(pattern, name)) + continue; + + fullname = g_build_filename(formats_directory, name, NULL); + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + COL_NAME, name, + COL_FILENAME, fullname, + -1); + + g_free(fullname); + } + + g_dir_close(dir); +} + +void +format_selection_init(const gchar *dir) +{ + GtkListStore *formats_store; + GtkCellRenderer *renderer; + + formats_directory = g_strdup(dir); + + formats_store = gtk_list_store_new(NUM_COLS, + G_TYPE_STRING, G_TYPE_STRING); + gtk_combo_box_set_model(GTK_COMBO_BOX(transcript_wizard_combo), + GTK_TREE_MODEL(formats_store)); + gtk_combo_box_set_model(GTK_COMBO_BOX(transcript_proband_combo), + GTK_TREE_MODEL(formats_store)); + + renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(transcript_wizard_combo), + renderer, TRUE); + gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(transcript_wizard_combo), + renderer, "text", COL_NAME); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(transcript_proband_combo), + renderer, TRUE); + gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(transcript_proband_combo), + renderer, "text", COL_NAME); + + refresh_formats_store(formats_store); + + g_object_unref(formats_store); +} @@ -14,6 +14,7 @@ #endif #include <glib.h> +#include <glib/gprintf.h> #include <gtk/gtk.h> @@ -146,15 +147,6 @@ help_menu_manual_item_activate_cb(GtkWidget *widget __attribute__((unused)), } void -generic_transcript_entry_changed_cb(gpointer user_data, GtkEditable *editable) -{ - GtkExperimentTranscript *trans = GTK_EXPERIMENT_TRANSCRIPT(user_data); - const gchar *text = gtk_entry_get_text(GTK_ENTRY(editable)); - - gtk_experiment_transcript_set_interactive_format(trans, text, TRUE); -} - -void navigator_widget_time_selected_cb(GtkWidget *widget, gint64 selected_time, gpointer user_data __attribute__((unused))) { @@ -293,6 +285,9 @@ main(int argc, char *argv[]) BUILDER_INIT(builder, transcript_proband_widget); BUILDER_INIT(builder, transcript_scroll_widget); + BUILDER_INIT(builder, transcript_wizard_combo); + BUILDER_INIT(builder, transcript_proband_combo); + BUILDER_INIT(builder, navigator_scrolledwindow); BUILDER_INIT(builder, navigator_widget); @@ -314,6 +309,7 @@ main(int argc, char *argv[]) /* configure transcript widgets */ GTK_EXPERIMENT_TRANSCRIPT(transcript_wizard_widget)->speaker = g_strdup("Wizard"); GTK_EXPERIMENT_TRANSCRIPT(transcript_proband_widget)->speaker = g_strdup("Proband"); + format_selection_init(DEFAULT_FORMAT_DIR); quickopen_directory = g_strdup(DEFAULT_QUICKOPEN_DIR); refresh_quickopen_menu(GTK_MENU(quickopen_menu)); |