OSDN Git Service

save font name to ~/.kp123
[kp123/kp123.git] / src / kp123.c
index 17f2faa..4259c08 100644 (file)
@@ -3,6 +3,7 @@
 #include "intl.h"
 #include "padarea.h"
 #include <fcntl.h>
+#include <glib/gstdio.h>
 
 #include "recognize_kanji.h"
 
@@ -98,21 +99,25 @@ static int load_glade_xml(GtkBuilder *b, gchar *dir)
     return res;
 }
 
-const gchar* query_fontstr(const gchar* fontstr)
+gchar* query_fontstr(gchar* fontstr)
 {
-#if 0
+#if 1
     gchar *home_dir = getenv("HOME");
     gchar *filename = g_strdup_printf("%s%s.%s", home_dir, G_DIR_SEPARATOR_S, PACKAGE_NAME);
     if(fontstr)
     {
-       gint fd = open(filename, O_CREAT | O_WRONLY | O_SYNC);
+       g_remove(filename);
+       gint fd = g_open(filename, O_CREAT | O_RDWR | O_SYNC);
        write(fd, fontstr, strlen(fontstr));
        close(fd);
+       g_chmod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
     }
     else
     {
-       fontstr = (const gchar*)calloc(100, sizeof(char));
-       gint fd = open(filename, O_RDONLY | O_SYNC);
+       if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+           return NULL;
+       fontstr = (gchar*)calloc(100, sizeof(char));
+       gint fd = g_open(filename, O_RDONLY | O_SYNC);
        read(fd, fontstr, 100);
        close(fd);
     }
@@ -127,7 +132,7 @@ void fontbtn_font_set_cb(GtkFontButton *btn, gpointer data)
     PangoFontDescription *desc = pango_font_description_from_string(fontstr);
     GtkWidget *kanji = GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(data), "treeview"));
     gtk_widget_modify_font(kanji, desc);
-    query_fontstr(fontstr);
+    query_fontstr((gchar*)fontstr);
 }
 
 int main (int argc, char *argv[])