about summary refs log tree commit diff stats
path: root/src/plugins/settings.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-24 21:35:12 +0100
committerJames Booth <boothj5@gmail.com>2016-07-24 21:49:35 +0100
commita3a73cf0031fef7b4012b27bc1955c406175f0fe (patch)
treea9bfba0b9899eff139a9a8e5436468e35d6b7e91 /src/plugins/settings.c
parent29452f8f1b8f7a61773905169b3883f1b494c786 (diff)
downloadprofani-tty-a3a73cf0031fef7b4012b27bc1955c406175f0fe.tar.gz
Move all filepath handling to files.c
Diffstat (limited to 'src/plugins/settings.c')
-rw-r--r--src/plugins/settings.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/plugins/settings.c b/src/plugins/settings.c
index 418451ff..992390cf 100644
--- a/src/plugins/settings.c
+++ b/src/plugins/settings.c
@@ -49,24 +49,21 @@ static void _save_settings(void);
 void
 plugin_settings_init(void)
 {
-    gchar *xdg_data = files_get_xdg_data_home();
-    GString *fileloc = g_string_new(xdg_data);
-    g_string_append(fileloc, "/profanity/plugin_settings");
-    g_free(xdg_data);
+    char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
 
-    if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
-        g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
+    if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) {
+        g_chmod(settings_file, S_IRUSR | S_IWUSR);
     }
 
     settings = g_key_file_new();
-    g_key_file_load_from_file(settings, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
+    g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
 
     gsize g_data_size;
     gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
-    g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
-    g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
+    g_file_set_contents(settings_file, g_data, g_data_size, NULL);
+    g_chmod(settings_file, S_IRUSR | S_IWUSR);
     g_free(g_data);
-    g_string_free(fileloc, TRUE);
+    free(settings_file);
 }
 
 void
@@ -135,19 +132,13 @@ _save_settings(void)
     gsize g_data_size;
     gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
 
-    gchar *xdg_data = files_get_xdg_data_home();
-    GString *fileloc = g_string_new(xdg_data);
-    g_free(xdg_data);
-
-    g_string_append(fileloc, "/profanity/");
-    char *base = strdup(fileloc->str);
-    g_string_append(fileloc, "plugin_settings");
-
-    gchar *true_loc = get_file_or_linked(fileloc->str, base);
-    free(base);
+    char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
+    gchar *base = g_path_get_basename(fileloc);
+    gchar *true_loc = get_file_or_linked(fileloc, base);
+    g_free(base);
     g_file_set_contents(true_loc, g_data, g_data_size, NULL);
     free(true_loc);
     g_free(g_data);
-    g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
-    g_string_free(fileloc, TRUE);
+    g_chmod(fileloc, S_IRUSR | S_IWUSR);
+    free(fileloc);
 }
Agaram <vc@akkartik.com> 2016-03-27 17:43:41 -0700 2812' href='/akkartik/mu/commit/html/044space_surround.cc.html?h=main&id=a654e4ecace2d506d1b10f1dde2c287ebe84ef37'>a654e4ec ^
e5c11a51 ^
70f4e9b6 ^
4a39d12d ^
9e751bb8 ^

672e3e50 ^

a654e4ec ^



e5c11a51 ^






















a654e4ec ^

672e3e50 ^
e5c11a51 ^
a654e4ec ^
204dae92 ^







201458e3 ^
204dae92 ^






















201458e3 ^
204dae92 ^






bfa3f5ba ^
201458e3 ^
204dae92 ^

201458e3 ^

9e751bb8 ^
2c678a4e ^
204dae92 ^


201458e3 ^
2c678a4e ^
9e751bb8 ^

1c2d788b ^
51728d93 ^
9e751bb8 ^
204dae92 ^




201458e3 ^
204dae92 ^

672e3e50 ^


a654e4ec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133