6 gchar
* checkpinyin(gchar
*pinyin
) {
8 g_ascii_strdown(pinyin
, -1);
9 g_strcanon(pinyin
, "012345abcdefghijklmnopqrstuvwxyz\n", '-');
10 result
= g_strsplit(pinyin
, "-", MAXTESTS
* 2);
12 pinyin
= g_strjoinv(NULL
, result
);
17 gtk_list_store_clear(GTK_LIST_STORE(liststore
));
18 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
22 void setBase(gchar
*newbase
) {
29 void setFile(gchar
*newfile
) {
36 void fileOpen(gchar
*filename
) {
37 gchar
**testList
= NULL
;
43 if (g_file_get_contents(filename
, &contents
, &length
, NULL
) != FALSE
) {
45 gchar
*processed
= checkpinyin(contents
);
47 testList
= g_strsplit(processed
, "\n", MAXTESTS
);
48 while ( testList
[i
] != NULL
) {
49 add_entry(testList
[i
]);
54 if (testList
== NULL
) {
55 testList
= g_strsplit("xu1\nci2", "\n", MAXTESTS
);
61 gtk_window_set_title(GTK_WINDOW(glade_xml_get_widget(xml
, "windowWordlist")), filename
);
63 setBase(g_path_get_dirname(filename
));
64 setFile(g_strdup(filename
));
66 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
71 void fileSave(gchar
*filename
) {
72 if (treevalid
== TRUE
&& filename
!= NULL
) {
76 /* Get first row in list store */
77 valid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &iter
);
80 GString
*contents
= g_string_new("");
81 if (contents
!= NULL
) {
85 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &iter
, COL_TEXT
, &string
, -1);
86 contents
= g_string_append(contents
, string
);
87 contents
= g_string_append(contents
, "\r\n");
89 valid
= gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore
), &iter
);
93 g_file_set_contents(filename
, contents
->str
, -1, NULL
);
95 g_string_free(contents
, true);