Lets try it...
[sgc.git] / signals-realize.c
blob163c1a0aab740a6e35578cd8a8d0b05d0e53b870
1 #include "sgc.h"
3 /* This file contains all code that is required to initiate the widgets.
4 * And should be linked to from Glade
5 */
7 void on_filechooserdialog_realize(GtkWidget *widget, gpointer user_data){
8 GtkFileFilter *filter;
10 filter = gtk_file_filter_new ();
11 gtk_file_filter_add_pattern (filter, "*.sgc");
12 gtk_file_filter_add_pattern (filter, "*.txt");
13 gtk_file_filter_set_name (filter, _("All Loadable Files"));
14 gtk_file_chooser_add_filter (GTK_WIDGET(widget), filter);
16 filter = gtk_file_filter_new ();
17 gtk_file_filter_add_pattern (filter, "*.sgc");
18 gtk_file_filter_set_name (filter, _("SGC Distribution (*.sgc)"));
19 gtk_file_chooser_add_filter (GTK_WIDGET(widget), filter);
21 filter = gtk_file_filter_new ();
22 gtk_file_filter_add_pattern (filter, "*.txt");
23 gtk_file_filter_set_name (filter, _("Plain Text (*.txt)"));
24 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
28 void on_menuWordlists_realize(GtkWidget *menu, gpointer user_data) {
29 GDir *dirExamples = g_dir_open(WORDLISTS, 0, NULL);
30 if (dirExamples != NULL) {
31 gchar *current;
32 gchar *currentDir = g_get_current_dir();
33 while ((current = g_dir_read_name (dirExamples)) != NULL) {
34 gchar *path = g_strjoin(NULL, currentDir, G_DIR_SEPARATOR_S, WORDLISTS, G_DIR_SEPARATOR_S, current, G_DIR_SEPARATOR_S, "wordlist.txt", NULL);
35 if (g_file_test(path, G_FILE_TEST_EXISTS) == TRUE) {
36 GtkWidget *item = gtk_image_menu_item_new_with_label(g_strdup(current));
37 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
38 g_signal_connect_data(item, "activate", G_CALLBACK(fileOpen), path, g_free, G_CONNECT_SWAPPED);
39 gtk_menu_shell_prepend (GTK_MENU_SHELL(menu), item);
42 g_free(currentDir);
43 gtk_widget_show_all(GTK_WIDGET(menu));
47 void on_windowMain_realize(GtkWidget *widget, gpointer user_data) {
48 GtkCellRenderer *renderer;
49 GtkTreeViewColumn *col;
50 GtkTreeSelection *sel;
51 GtkWidget *view = glade_xml_get_widget(xml, "treeviewWords");
53 liststore = gtk_list_store_new(NUM_COLS, G_TYPE_STRING); /* NUM_COLS = 1 */
55 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(liststore));
57 renderer = gtk_cell_renderer_text_new();
59 g_object_set(renderer, "editable", TRUE, NULL);
60 g_signal_connect(renderer, "edited", G_CALLBACK(on_treeview_edited), GTK_TREE_MODEL(liststore));
62 col = gtk_tree_view_column_new();
64 gtk_tree_view_column_pack_start(col, renderer, TRUE);
65 gtk_tree_view_column_add_attribute(col, renderer, "text", COL_TEXT);
66 gtk_tree_view_column_set_title(col, _(" Mandarin "));
68 gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
70 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
71 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
73 configOpen();
76 void removeRecordings() {
77 GDir *record;
78 gchar *file = g_build_filename(SCRIPTPATH, "lastExample.wav", NULL);
79 g_unlink(file);
80 g_free(file);
81 if ((record = g_dir_open(RECORDPATH, 0, NULL)) != NULL) {
82 gchar *name;
83 while ((name = g_dir_read_name(record)) != NULL) {
84 if (g_str_has_suffix(name, ".wav") || g_str_has_suffix(name, ".Pitch") || g_str_has_suffix(name, ".PitchTier")) {
85 file = g_build_filename(RECORDPATH, name, NULL);
86 g_unlink(file);
87 g_free(file);
90 g_dir_close(record);