11 static gchar *quoted_value(gchar *text);
12 static void write_char_option(FILE *f, gchar *label, gchar *text);
13 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text);
14 static void write_int_option(FILE *f, gchar *label, gint n);
15 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n);
16 static void write_bool_option(FILE *f, gchar *label, gint n);
17 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n);
20 *-----------------------------------------------------------------------------
21 * line write/parse routines (private)
22 *-----------------------------------------------------------------------------
25 static gchar *quoted_value(gchar *text)
29 gint l = strlen(text);
31 if (l == 0) return NULL;
33 while (c < l && text[c] !='"') c++;
38 while (c < l && text[c] !='"') c++;
49 /* for compatibility with older formats (<0.3.7)
50 * read a line without quotes too */
53 while (c < l && text[c] !=' ' && text[c] !=8 && text[c] != '\n') c++;
57 return g_strdup(text);
64 static void write_char_option(FILE *f, gchar *label, gchar *text)
67 fprintf(f,"%s: \"%s\"\n", label, text);
69 fprintf(f,"%s: \n", label);
72 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text)
74 if (!strcasecmp(option, label))
77 text = quoted_value(value);
82 static void write_int_option(FILE *f, gchar *label, gint n)
84 fprintf(f,"%s: %d\n\n", label, n);
87 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
89 if (!strcasecmp(option, label))
91 n = strtol(value,NULL,0);
96 static void write_bool_option(FILE *f, gchar *label, gint n)
98 fprintf(f,"%s: ", label);
99 if (n) fprintf(f,"true\n"); else fprintf(f,"false\n");
103 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
105 if (!strcasecmp(option, label))
107 if (!strcasecmp(value, "true"))
116 *-----------------------------------------------------------------------------
117 * save configuration (public)
118 *-----------------------------------------------------------------------------
127 rc_path = g_strconcat(homedir(), "/", RC_FILE_NAME, NULL);
129 f = fopen(rc_path,"w");
132 printf(_("error saving config file: %s\n"), rc_path);
137 fprintf(f,"######################################################################\n");
138 fprintf(f,"# GQview config file version %7s #\n", VERSION);
140 fprintf(f,"# Everything in this file can be changed in the option dialogs. #\n");
141 fprintf(f,"# (so there should be no need to edit this file by hand) #\n");
143 fprintf(f,"######################################################################\n");
145 fprintf(f,"##### General Options #####\n\n");
147 write_bool_option(f, "enable_startup_path", startup_path_enable);
148 write_char_option(f, "startup_path", startup_path);
151 fprintf(f,"zoom_mode: ");
152 if (zoom_mode == ZOOM_RESET_ORIGINAL) fprintf(f,"original\n");
153 if (zoom_mode == ZOOM_RESET_FIT_WINDOW) fprintf(f,"fit\n");
154 if (zoom_mode == ZOOM_RESET_NONE) fprintf(f,"dont_change\n");
157 write_bool_option(f, "fit_window_to_image", fit_window);
158 write_bool_option(f, "limit_window_size", limit_window_size);
159 write_int_option(f, "max_window_size", max_window_size);
162 write_bool_option(f, "progressive_keyboard_scrolling", progressive_key_scrolling);
165 write_bool_option(f, "enable_thumbnails", thumbnails_enabled);
166 write_int_option(f, "thumbnail_width", thumb_max_width);
167 write_int_option(f, "thumbnail_height", thumb_max_height);
168 write_bool_option(f, "cache_thumbnails", enable_thumb_caching);
169 write_bool_option(f, "use_xvpics_thumbnails", use_xvpics_thumbnails);
172 write_bool_option(f, "confirm_delete", confirm_delete);
174 write_bool_option(f, "tools_float", tools_float);
175 write_bool_option(f, "tools_hidden", tools_hidden);
176 write_bool_option(f, "restore_tool_state", restore_tool);
178 fprintf(f,"\n##### Slideshow Options #####\n\n");
180 write_int_option(f, "slideshow_delay", slideshow_delay);
182 write_bool_option(f, "slideshow_random", slideshow_random);
183 write_bool_option(f, "slideshow_repeat", slideshow_repeat);
185 fprintf(f,"\n##### Filtering Options #####\n\n");
187 write_bool_option(f, "show_dotfiles", show_dot_files);
188 write_bool_option(f, "disable_filtering", file_filter_disable);
190 write_bool_option(f, "filter_ppm", filter_include_ppm);
191 write_bool_option(f, "filter_png", filter_include_png);
192 write_bool_option(f, "filter_jpg", filter_include_jpg);
193 write_bool_option(f, "filter_tif", filter_include_tif);
194 write_bool_option(f, "filter_pgm", filter_include_pgm);
195 write_bool_option(f, "filter_xpm", filter_include_xpm);
196 write_bool_option(f, "filter_gif", filter_include_gif);
197 write_bool_option(f, "filter_pcx", filter_include_pcx);
198 write_bool_option(f, "filter_bmp", filter_include_bmp);
200 write_char_option(f, "custom_filter", custom_filter);
202 fprintf(f,"\n##### External Programs #####\n");
203 fprintf(f,"# Maximum of 8 programs (external_1 through external 8)\n");
204 fprintf(f,"# format: external_n: \"menu name\" \"command line\"\n\n");
208 fprintf(f,"external_%d: \"", i+1);
209 if (editor_name[i]) fprintf(f, editor_name[i]);
211 if (editor_command[i]) fprintf(f, editor_command[i]);
215 fprintf(f,"\n##### Window Positions #####\n\n");
217 write_bool_option(f, "restore_window_positions", save_window_positions);
219 write_int_option(f, "main_window_x", main_window_x);
220 write_int_option(f, "main_window_y", main_window_y);
221 write_int_option(f, "main_window_width", main_window_w);
222 write_int_option(f, "main_window_height", main_window_h);
223 write_int_option(f, "float_window_x", float_window_x);
224 write_int_option(f, "float_window_y", float_window_y);
225 write_int_option(f, "float_window_width", float_window_w);
226 write_int_option(f, "float_window_height", float_window_h);
228 fprintf(f,"######################################################################\n");
229 fprintf(f,"# end of GQview config file #\n");
230 fprintf(f,"######################################################################\n");
238 *-----------------------------------------------------------------------------
239 * load configuration (public)
240 *-----------------------------------------------------------------------------
251 gchar value_all[1024];
253 rc_path = g_strconcat(homedir(), "/", RC_FILE_NAME, NULL);
255 f = fopen(rc_path,"r");
262 while (fgets(s_buf,1024,f))
264 if (s_buf[0]=='#') continue;
265 if (s_buf[0]=='\n') continue;
268 while (s_buf[c] != ':' && c < l) c++;
269 if (c >= l) continue;
272 while (s_buf[c] == ' ' && c < l) c++;
273 while (s_buf[c] == 8 && c < l) c++;
274 while (s_buf[c] == ' ' && c < l) c++;
275 s_buf_ptr = s_buf + c;
276 strcpy(value_all,s_buf_ptr);
277 while (s_buf[c] != 8 && s_buf[c] != ' ' && s_buf[c] != '\n' && c < l) c++;
279 strcpy(option,s_buf);
280 strcpy(value,s_buf_ptr);
282 /* general options */
284 startup_path_enable = read_bool_option(f, option,
285 "enable_startup_path", value, startup_path_enable);
286 startup_path = read_char_option(f, option,
287 "startup_path", value_all, startup_path);
289 if (!strcasecmp(option,"zoom_mode"))
291 if (!strcasecmp(value,"original")) zoom_mode = ZOOM_RESET_ORIGINAL;
292 if (!strcasecmp(value,"fit")) zoom_mode = ZOOM_RESET_FIT_WINDOW;
293 if (!strcasecmp(value,"dont_change")) zoom_mode = ZOOM_RESET_NONE;
296 fit_window = read_bool_option(f, option,
297 "fit_window_to_image", value, fit_window);
298 limit_window_size = read_bool_option(f, option,
299 "limit_window_size", value, limit_window_size);
300 max_window_size = read_int_option(f, option,
301 "max_window_size", value, max_window_size);
302 progressive_key_scrolling = read_bool_option(f, option,
303 "progressive_keyboard_scrolling", value, progressive_key_scrolling);
305 thumbnails_enabled = read_bool_option(f, option,
306 "enable_thumbnails", value, thumbnails_enabled);
307 thumb_max_width = read_int_option(f, option,
308 "thumbnail_width", value, thumb_max_width);
309 thumb_max_height = read_int_option(f, option,
310 "thumbnail_height", value, thumb_max_height);
311 enable_thumb_caching = read_bool_option(f, option,
312 "cache_thumbnails", value, enable_thumb_caching);
313 use_xvpics_thumbnails = read_bool_option(f, option,
314 "use_xvpics_thumbnails", value, use_xvpics_thumbnails);
316 confirm_delete = read_bool_option(f, option,
317 "confirm_delete", value, confirm_delete);
319 tools_float = read_bool_option(f, option,
320 "tools_float", value, tools_float);
321 tools_hidden = read_bool_option(f, option,
322 "tools_hidden", value, tools_hidden);
323 restore_tool = read_bool_option(f, option,
324 "restore_tool_state", value, restore_tool);
326 /* slideshow opitons */
328 slideshow_delay = read_int_option(f, option,
329 "slideshow_delay", value, slideshow_delay);
330 slideshow_random = read_bool_option(f, option,
331 "slideshow_random", value, slideshow_random);
332 slideshow_repeat = read_bool_option(f, option,
333 "slideshow_repeat", value, slideshow_repeat);
335 /* filtering options */
337 show_dot_files = read_bool_option(f, option,
338 "show_dotfiles", value, show_dot_files);
339 file_filter_disable = read_bool_option(f, option,
340 "disable_filtering", value, file_filter_disable);
342 filter_include_ppm = read_bool_option(f, option,
343 "filter_ppm", value, filter_include_ppm);
344 filter_include_png = read_bool_option(f, option,
345 "filter_png", value, filter_include_png);
346 filter_include_jpg = read_bool_option(f, option,
347 "filter_jpg", value, filter_include_jpg);
348 filter_include_tif = read_bool_option(f, option,
349 "filter_tif", value, filter_include_tif);
350 filter_include_pgm = read_bool_option(f, option,
351 "filter_pgm", value, filter_include_pgm);
352 filter_include_xpm = read_bool_option(f, option,
353 "filter_xpm", value, filter_include_xpm);
354 filter_include_gif = read_bool_option(f, option,
355 "filter_gif", value, filter_include_gif);
356 filter_include_pcx = read_bool_option(f, option,
357 "filter_pcx", value, filter_include_pcx);
358 filter_include_bmp = read_bool_option(f, option,
359 "filter_bmp", value, filter_include_bmp);
361 custom_filter = read_char_option(f, option,
362 "custom_filter", value_all, custom_filter);
364 /* External Programs */
366 if (!strncasecmp(option,"external_",9))
368 i = strtol(option + 9, NULL, 0);
374 l = strlen(value_all);
377 g_free(editor_name[i]);
378 editor_name[i] = NULL;
379 g_free(editor_command[i]);
380 editor_command[i] = NULL;
382 while (c<l && value_all[c] !='"') c++;
387 while (c<l && value_all[c] !='"') c++;
391 if (ptr1 + c - 1 != ptr2)
392 editor_name[i] = g_strdup(ptr2);
394 while (c<l && value_all[c] !='"') c++;
399 while (c<l && value_all[c] !='"') c++;
400 if (ptr1[c] == '"' && ptr1 + c - 1 != ptr2)
403 editor_command[i] = g_strdup(ptr2);
411 /* window positions */
413 save_window_positions = read_bool_option(f, option,
414 "restore_window_positions", value, save_window_positions);
416 main_window_x = read_int_option(f, option,
417 "main_window_x", value, main_window_x);
418 main_window_y = read_int_option(f, option,
419 "main_window_y", value, main_window_y);
420 main_window_w = read_int_option(f, option,
421 "main_window_width", value, main_window_w);
422 main_window_h = read_int_option(f, option,
423 "main_window_height", value, main_window_h);
424 float_window_x = read_int_option(f, option,
425 "float_window_x", value, float_window_x);
426 float_window_y = read_int_option(f, option,
427 "float_window_y", value, float_window_y);
428 float_window_w = read_int_option(f, option,
429 "float_window_width", value, float_window_w);
430 float_window_h = read_int_option(f, option,
431 "float_window_height", value, float_window_h);