Label troep
[sgc.git] / signals-editor.c
blob387beccd1ed117c92822287a6c7e02d1b5647e06
1 #include "sgc.h"
2 #include "signals-editor.h"
4 gchar * checkPinyin(gchar *pinyin) {
5 gchar **result;
6 g_ascii_strdown(pinyin, -1);
7 g_strcanon(pinyin, "#012345abcdefghijklmnopqrstuvwxyz\n", '-');
8 result = g_strsplit(pinyin, "-", MAXTESTS * 2);
9 g_free(pinyin);
10 pinyin = g_strjoinv(NULL, result);
11 return pinyin;
14 void on_buttonAddAdd_clicked (GtkWidget *entry, gpointer data)
16 gchar *processed = checkPinyin(g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))));
17 add_entry(processed);
20 void add_entry(gchar *txt) {
21 /* ignore if entry is empty */
22 if (txt && *txt)
24 GtkTreeIter newrow;
26 gtk_list_store_append(GTK_LIST_STORE(liststore), &newrow);
28 gtk_list_store_set(GTK_LIST_STORE(liststore), &newrow, COL_TEXT, txt, -1);
29 // g_free(txt);
31 if (treevalid == FALSE) {
32 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
33 updateWidgets();
38 void remove_entry (GtkWidget *treeview, gpointer data)
40 GtkTreeSelection *sel;
41 GtkTreeIter selected_row;
43 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
45 if (gtk_tree_selection_get_selected(sel, &liststore, &selected_row))
47 gtk_list_store_remove(GTK_LIST_STORE(liststore), &selected_row);
48 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
49 updateWidgets();
53 void on_treeview_edited (GtkCellRendererText *celltext,
54 const gchar *string_path, const gchar *new_text, gpointer data) {
56 GtkTreeModel *model = GTK_TREE_MODEL(data);
57 GtkTreeIter iter;
58 gtk_tree_model_get_iter_from_string(model, &iter, string_path);
59 gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_TEXT, new_text, -1);
60 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
61 updateWidgets();
64 gboolean on_treeother() {
65 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
66 updateWidgets();
67 return false;
70 void on_buttonOpen2_clicked(GtkWidget *filechooser, gpointer data) {
71 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser));
72 fileSave(filename);
73 g_free(filename);
77 void on_buttonOpen_clicked(GtkWidget *filechooser, gpointer data) {
78 /* Eerst vragen oude op te slaan ? */
80 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser));
82 if (g_str_has_suffix(filename, ".sgc") || g_str_has_suffix(filename, ".SGC")) {
83 if (openSGC(filename)) {
84 gchar *basename = g_path_get_basename(filename);
85 int end = strlen(basename)-3;
86 gchar *basenamenoext = g_malloc(end * sizeof(gchar));
87 gchar *currentDir = g_get_current_dir();
88 g_strlcpy(basenamenoext, basename, end);
89 g_free(filename);
90 filename = g_strjoin(NULL, currentDir, G_DIR_SEPARATOR_S, WORDLISTS, G_DIR_SEPARATOR_S, basenamenoext, G_DIR_SEPARATOR_S, "wordlist.txt", NULL);
91 g_free(currentDir);
92 g_free(basename);
93 g_free(basenamenoext);
94 gtk_widget_unrealize(glade_xml_get_widget(xml, "menuWordlists"));
97 fileOpen(filename);
98 g_free(filename);
101 void on_buttonSaveDistribution_clicked(GtkWidget *entry, gpointer data) {
102 if (GTK_ENTRY(entry)) {
103 saveSGC(gtk_entry_get_text(GTK_ENTRY(entry)), base);
106 void on_buttonSaveNew_clicked(GtkWidget *entry, gpointer data) {
107 if (GTK_ENTRY(entry)) {
108 gchar *currentDir = g_get_current_dir();
109 gchar *filename = g_strjoin(NULL, currentDir, G_DIR_SEPARATOR_S, WORDLISTS, G_DIR_SEPARATOR_S, gtk_entry_get_text(GTK_ENTRY(entry)), G_DIR_SEPARATOR_S, "wordlist.txt", NULL);
110 clear(NULL);
111 setBase(g_path_get_dirname(filename));
112 setFile(filename);
113 if (g_access(base, F_OK) != 0) {
114 g_mkdir_with_parents(base, 0755);
117 if (g_access(file, F_OK) == 0) {
118 fileOpen(file);
119 } else {
120 gtk_window_set_title(GTK_WINDOW(glade_xml_get_widget(xml, "windowWordlist")), file);
121 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "filechooserdialogWordlist")), file);
122 fclose(g_fopen(file, "w"));
123 gtk_widget_unrealize(glade_xml_get_widget(xml, "menuWordlists"));