annotate src/rcfile.c @ 2:0591360d4e38

More po.
author gqview
date Thu, 13 Apr 2000 12:53:03 +0000
parents b3e0e515fabf
children c0e337a01cb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
2 * GQview image viewer
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
3 * (C)1999 John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
4 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
7 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
8
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
9 #include "gqview.h"
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
10
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11 static gchar *quoted_value(gchar *text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
12 static void write_char_option(FILE *f, gchar *label, gchar *text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
13 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
14 static void write_int_option(FILE *f, gchar *label, gint n);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
15 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
16 static void write_bool_option(FILE *f, gchar *label, gint n);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
17 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
18
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
19 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
20 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
21 * line write/parse routines (private)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
22 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
23 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
24
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
25 static gchar *quoted_value(gchar *text)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
26 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
27 gchar *ptr;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
28 gint c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
29 gint l = strlen(text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
30
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
31 if (l == 0) return NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
32
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
33 while (c < l && text[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
34 if (text[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
35 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
36 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
37 ptr = text + c;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
38 while (c < l && text[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
39 if (text[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
40 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
41 text[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
42 if (strlen(ptr) > 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
43 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
44 return g_strdup(ptr);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
45 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
46 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
47 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
48 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
49 /* for compatibility with older formats (<0.3.7)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
50 * read a line without quotes too */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
51 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
52 c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
53 while (c < l && text[c] !=' ' && text[c] !=8 && text[c] != '\n') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
54 if (c != 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
55 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
56 text[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
57 return g_strdup(text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
58 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
59 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
60
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
61 return NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
62 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
63
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
64 static void write_char_option(FILE *f, gchar *label, gchar *text)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
65 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
66 if (text)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
67 fprintf(f,"%s: \"%s\"\n", label, text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
68 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
69 fprintf(f,"%s: \n", label);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
70 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
71
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
72 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
73 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
74 if (!strcasecmp(option, label))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
75 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
76 g_free(text);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
77 text = quoted_value(value);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
78 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
79 return text;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
80 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
81
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
82 static void write_int_option(FILE *f, gchar *label, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
83 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
84 fprintf(f,"%s: %d\n\n", label, n);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
85 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
86
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
87 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
88 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
89 if (!strcasecmp(option, label))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
90 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
91 n = strtol(value,NULL,0);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
92 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
93 return n;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
94 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
95
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
96 static void write_bool_option(FILE *f, gchar *label, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
97 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
98 fprintf(f,"%s: ", label);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
99 if (n) fprintf(f,"true\n"); else fprintf(f,"false\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
100 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
101 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
102
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
103 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
104 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
105 if (!strcasecmp(option, label))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
106 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
107 if (!strcasecmp(value, "true"))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
108 n = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
109 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
110 n = FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
111 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
112 return n;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
113 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
114
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
115 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
116 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
117 * save configuration (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
118 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
119 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
120
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
121 void save_options()
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
122 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
123 FILE *f;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
124 gchar *rc_path;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
125 gint i;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
126
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
127 rc_path = g_strconcat(homedir(), "/", RC_FILE_NAME, NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
128
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
129 f = fopen(rc_path,"w");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
130 if (!f)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
131 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
132 printf(_("error saving config file: %s\n"), rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
133 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
134 return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
135 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
136
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
137 fprintf(f,"######################################################################\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
138 fprintf(f,"# GQview config file version %7s #\n", VERSION);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
139 fprintf(f,"# #\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
140 fprintf(f,"# Everything in this file can be changed in the option dialogs. #\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
141 fprintf(f,"# (so there should be no need to edit this file by hand) #\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
142 fprintf(f,"# #\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
143 fprintf(f,"######################################################################\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
144 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
145 fprintf(f,"##### General Options #####\n\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
146
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
147 write_bool_option(f, "enable_startup_path", startup_path_enable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
148 write_char_option(f, "startup_path", startup_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
149 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
150
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
151 fprintf(f,"zoom_mode: ");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
152 if (zoom_mode == ZOOM_RESET_ORIGINAL) fprintf(f,"original\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
153 if (zoom_mode == ZOOM_RESET_FIT_WINDOW) fprintf(f,"fit\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
154 if (zoom_mode == ZOOM_RESET_NONE) fprintf(f,"dont_change\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
155 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
156
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
157 write_bool_option(f, "fit_window_to_image", fit_window);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
158 write_bool_option(f, "limit_window_size", limit_window_size);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
159 write_int_option(f, "max_window_size", max_window_size);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
160 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
161
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
162 write_bool_option(f, "progressive_keyboard_scrolling", progressive_key_scrolling);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
163 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
164
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
165 write_int_option(f, "thumbnail_width", thumb_max_width);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
166 write_int_option(f, "thumbnail_height", thumb_max_height);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
167 write_bool_option(f, "cache_thumbnails", enable_thumb_caching);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
168 write_bool_option(f, "use_xvpics_thumbnails", use_xvpics_thumbnails);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
169 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
170
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
171 write_bool_option(f, "confirm_delete", confirm_delete);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
172 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
173 write_bool_option(f, "tools_float", tools_float);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
174 write_bool_option(f, "tools_hidden", tools_hidden);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
175 write_bool_option(f, "restore_tool_state", restore_tool);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
176
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
177 fprintf(f,"\n##### Slideshow Options #####\n\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
178
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
179 write_int_option(f, "slideshow_delay", slideshow_delay);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
180
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
181 write_bool_option(f, "slideshow_random", slideshow_random);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
182 write_bool_option(f, "slideshow_repeat", slideshow_repeat);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
183
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
184 fprintf(f,"\n##### Filtering Options #####\n\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
185
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
186 write_bool_option(f, "show_dotfiles", show_dot_files);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
187 write_bool_option(f, "disable_filtering", file_filter_disable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
188 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
189 write_bool_option(f, "filter_ppm", filter_include_ppm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
190 write_bool_option(f, "filter_png", filter_include_png);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
191 write_bool_option(f, "filter_jpg", filter_include_jpg);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
192 write_bool_option(f, "filter_tif", filter_include_tif);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
193 write_bool_option(f, "filter_pgm", filter_include_pgm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
194 write_bool_option(f, "filter_xpm", filter_include_xpm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
195 write_bool_option(f, "filter_gif", filter_include_gif);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
196 write_bool_option(f, "filter_pcx", filter_include_pcx);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
197 write_bool_option(f, "filter_bmp", filter_include_bmp);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
198 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
199 write_char_option(f, "custom_filter", custom_filter);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
200
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
201 fprintf(f,"\n##### External Programs #####\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
202 fprintf(f,"# Maximum of 8 programs (external_1 through external 8)\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
203 fprintf(f,"# format: external_n: \"menu name\" \"command line\"\n\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
204
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
205 for (i=0; i<8; i++)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
206 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
207 fprintf(f,"external_%d: \"", i+1);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
208 if (editor_name[i]) fprintf(f, editor_name[i]);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
209 fprintf(f, "\" \"");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
210 if (editor_command[i]) fprintf(f, editor_command[i]);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
211 fprintf(f, "\"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
212 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
213
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
214 fprintf(f,"\n##### Window Positions #####\n\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
215
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
216 write_bool_option(f, "restore_window_positions", save_window_positions);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
217 fprintf(f,"\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
218 write_int_option(f, "main_window_x", main_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
219 write_int_option(f, "main_window_y", main_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
220 write_int_option(f, "main_window_width", main_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
221 write_int_option(f, "main_window_height", main_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
222 write_int_option(f, "float_window_x", float_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
223 write_int_option(f, "float_window_y", float_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
224 write_int_option(f, "float_window_width", float_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
225 write_int_option(f, "float_window_height", float_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
226
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
227 fprintf(f,"######################################################################\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
228 fprintf(f,"# end of GQview config file #\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
229 fprintf(f,"######################################################################\n");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
230
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
231 fclose(f);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
232
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
233 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
234 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
235
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
236 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
237 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
238 * load configuration (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
239 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
240 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
241
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
242 void load_options()
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
243 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
244 FILE *f;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
245 gchar *rc_path;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
246 gchar s_buf[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
247 gchar *s_buf_ptr;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
248 gchar option[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
249 gchar value[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
250 gchar value_all[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
251 gint c,l,i;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
252 rc_path = g_strconcat(homedir(), "/", RC_FILE_NAME, NULL);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
253
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
254 f = fopen(rc_path,"r");
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
255 if (!f)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
256 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
257 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
258 return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
259 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
260
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
261 while (fgets(s_buf,1024,f))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
262 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
263 if (s_buf[0]=='#') continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
264 if (s_buf[0]=='\n') continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
265 c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
266 l = strlen(s_buf);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
267 while (s_buf[c] != ':' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
268 if (c >= l) continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
269 s_buf[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
270 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
271 while (s_buf[c] == ' ' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
272 while (s_buf[c] == 8 && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
273 while (s_buf[c] == ' ' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
274 s_buf_ptr = s_buf + c;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
275 strcpy(value_all,s_buf_ptr);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
276 while (s_buf[c] != 8 && s_buf[c] != ' ' && s_buf[c] != '\n' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
277 s_buf[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
278 strcpy(option,s_buf);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
279 strcpy(value,s_buf_ptr);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
280
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
281 /* general options */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
282
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
283 startup_path_enable = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
284 "enable_startup_path", value, startup_path_enable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
285 startup_path = read_char_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
286 "startup_path", value_all, startup_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
287
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
288 if (!strcasecmp(option,"zoom_mode"))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
289 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
290 if (!strcasecmp(value,"original")) zoom_mode = ZOOM_RESET_ORIGINAL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
291 if (!strcasecmp(value,"fit")) zoom_mode = ZOOM_RESET_FIT_WINDOW;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
292 if (!strcasecmp(value,"dont_change")) zoom_mode = ZOOM_RESET_NONE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
293 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
294
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
295 fit_window = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
296 "fit_window_to_image", value, fit_window);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
297 limit_window_size = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
298 "limit_window_size", value, limit_window_size);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
299 max_window_size = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
300 "max_window_size", value, max_window_size);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
301 progressive_key_scrolling = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
302 "progressive_keyboard_scrolling", value, progressive_key_scrolling);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
303
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
304 thumb_max_width = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
305 "thumbnail_width", value, thumb_max_width);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
306 thumb_max_height = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
307 "thumbnail_height", value, thumb_max_height);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
308 enable_thumb_caching = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
309 "cache_thumbnails", value, enable_thumb_caching);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
310 use_xvpics_thumbnails = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
311 "use_xvpics_thumbnails", value, use_xvpics_thumbnails);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
312
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
313 confirm_delete = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
314 "confirm_delete", value, confirm_delete);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
315
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
316 tools_float = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
317 "tools_float", value, tools_float);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
318 tools_hidden = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
319 "tools_hidden", value, tools_hidden);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
320 restore_tool = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
321 "restore_tool_state", value, restore_tool);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
322
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
323 /* slideshow opitons */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
324
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
325 slideshow_delay = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
326 "slideshow_delay", value, slideshow_delay);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
327 slideshow_random = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
328 "slideshow_random", value, slideshow_random);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
329 slideshow_repeat = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
330 "slideshow_repeat", value, slideshow_repeat);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
331
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
332 /* filtering options */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
333
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
334 show_dot_files = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
335 "show_dotfiles", value, show_dot_files);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
336 file_filter_disable = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
337 "disable_filtering", value, file_filter_disable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
338
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
339 filter_include_ppm = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
340 "filter_ppm", value, filter_include_ppm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
341 filter_include_png = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
342 "filter_png", value, filter_include_png);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
343 filter_include_jpg = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
344 "filter_jpg", value, filter_include_jpg);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
345 filter_include_tif = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
346 "filter_tif", value, filter_include_tif);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
347 filter_include_pgm = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
348 "filter_pgm", value, filter_include_pgm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
349 filter_include_xpm = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
350 "filter_xpm", value, filter_include_xpm);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
351 filter_include_gif = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
352 "filter_gif", value, filter_include_gif);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
353 filter_include_pcx = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
354 "filter_pcx", value, filter_include_pcx);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
355 filter_include_bmp = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
356 "filter_bmp", value, filter_include_bmp);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
357
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
358 custom_filter = read_char_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
359 "custom_filter", value_all, custom_filter);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
360
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
361 /* External Programs */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
362
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
363 if (!strncasecmp(option,"external_",9))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
364 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
365 i = strtol(option + 9, NULL, 0);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
366 if (i>0 && i<9)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
367 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
368 gchar *ptr1, *ptr2;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
369 i--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
370 c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
371 l = strlen(value_all);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
372 ptr1 = value_all;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
373
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
374 g_free(editor_name[i]);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
375 editor_name[i] = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
376 g_free(editor_command[i]);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
377 editor_command[i] = NULL;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
378
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
379 while (c<l && value_all[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
380 if (ptr1[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
381 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
382 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
383 ptr2 = ptr1 + c;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
384 while (c<l && value_all[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
385 if (ptr1[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
386 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
387 ptr1[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
388 if (ptr1 + c - 1 != ptr2)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
389 editor_name[i] = g_strdup(ptr2);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
390 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
391 while (c<l && value_all[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
392 if (ptr1[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
393 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
394 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
395 ptr2 = ptr1 + c;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
396 while (c<l && value_all[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
397 if (ptr1[c] == '"' && ptr1 + c - 1 != ptr2)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
398 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
399 ptr1[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
400 editor_command[i] = g_strdup(ptr2);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
401 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
402 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
403 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
404 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
405 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
406 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
407
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
408 /* window positions */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
409
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
410 save_window_positions = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
411 "restore_window_positions", value, save_window_positions);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
412
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
413 main_window_x = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
414 "main_window_x", value, main_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
415 main_window_y = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
416 "main_window_y", value, main_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
417 main_window_w = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
418 "main_window_width", value, main_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
419 main_window_h = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
420 "main_window_height", value, main_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
421 float_window_x = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
422 "float_window_x", value, float_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
423 float_window_y = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
424 "float_window_y", value, float_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
425 float_window_w = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
426 "float_window_width", value, float_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
427 float_window_h = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
428 "float_window_height", value, float_window_h);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
429 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
430
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
431 fclose(f);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
432 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
433 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
434