comparison src/rcfile.c @ 372:8ce8d565c038

Add and use few new macros in rc file writing code.
author zas_
date Tue, 15 Apr 2008 20:00:27 +0000
parents 673d1eb5af73
children 61a3c8b05b24
comparison
equal deleted inserted replaced
371:7997b6704fdb 372:8ce8d565c038
276 276
277 g_free(rc_path); 277 g_free(rc_path);
278 return; 278 return;
279 } 279 }
280 280
281 #define WRITE_BOOL(_name_) write_bool_option(ssi, #_name_, options->_name_)
282 #define WRITE_INT(_name_) write_int_option(ssi, #_name_, options->_name_)
283 #define WRITE_INT_UNIT(_name_, _unit_) write_int_unit_option(ssi, #_name_, options->_name_, _unit_)
284 #define WRITE_CHAR(_name_) write_char_option(ssi, #_name_, options->_name_)
285 #define WRITE_COLOR(_name_) write_color_option(ssi, #_name_, &options->_name_)
286
287 #define WRITE_SEPARATOR() secure_fputc(ssi, '\n')
288 #define WRITE_SUBTITLE(_title_) secure_fprintf(ssi, "\n\n##### "_title_" #####\n\n")
289
281 secure_fprintf(ssi, "######################################################################\n"); 290 secure_fprintf(ssi, "######################################################################\n");
282 secure_fprintf(ssi, "# %30s config file version %7s #\n", GQ_APPNAME, VERSION); 291 secure_fprintf(ssi, "# %30s config file version %7s #\n", GQ_APPNAME, VERSION);
283 secure_fprintf(ssi, "######################################################################\n"); 292 secure_fprintf(ssi, "######################################################################\n");
284 secure_fputc(ssi, '\n'); 293 WRITE_SEPARATOR();
285 294
286 secure_fprintf(ssi, "# Note: This file is autogenerated. Options can be changed here,\n"); 295 secure_fprintf(ssi, "# Note: This file is autogenerated. Options can be changed here,\n");
287 secure_fprintf(ssi, "# but user comments and formatting will be lost.\n"); 296 secure_fprintf(ssi, "# but user comments and formatting will be lost.\n");
288 secure_fputc(ssi, '\n'); 297 WRITE_SEPARATOR();
289 298
290 secure_fprintf(ssi, "##### General Options #####\n\n"); 299 WRITE_SUBTITLE("General Options");
291 300
292 write_bool_option(ssi, "show_icon_names", options->show_icon_names); 301 WRITE_BOOL(show_icon_names);
293 secure_fputc(ssi, '\n'); 302 WRITE_SEPARATOR();
294 303
295 write_bool_option(ssi, "tree_descend_subdirs", options->tree_descend_subdirs); 304 WRITE_BOOL(tree_descend_subdirs);
296 write_bool_option(ssi, "lazy_image_sync", options->lazy_image_sync); 305 WRITE_BOOL(lazy_image_sync);
297 write_bool_option(ssi, "update_on_time_change", options->update_on_time_change); 306 WRITE_BOOL(update_on_time_change);
298 secure_fputc(ssi, '\n'); 307 WRITE_SEPARATOR();
299 308
300 write_bool_option(ssi, "startup_path_enable", options->startup_path_enable); 309 WRITE_BOOL(startup_path_enable);
301 write_char_option(ssi, "startup_path", options->startup_path); 310 WRITE_CHAR(startup_path);
302 311
303 write_bool_option(ssi, "progressive_key_scrolling", options->progressive_key_scrolling); 312 WRITE_BOOL(progressive_key_scrolling);
304 write_bool_option(ssi, "enable_metadata_dirs", options->enable_metadata_dirs); 313 WRITE_BOOL(enable_metadata_dirs);
305 314
306 write_int_option(ssi, "duplicates_similarity_threshold", options->duplicates_similarity_threshold); 315 WRITE_INT(duplicates_similarity_threshold);
307 secure_fputc(ssi, '\n'); 316 WRITE_SEPARATOR();
308 317
309 write_bool_option(ssi, "mousewheel_scrolls", options->mousewheel_scrolls); 318 WRITE_BOOL(mousewheel_scrolls);
310 write_int_option(ssi, "open_recent_list_maxsize", options->open_recent_list_maxsize); 319 WRITE_INT(open_recent_list_maxsize);
311 write_bool_option(ssi, "place_dialogs_under_mouse", options->place_dialogs_under_mouse); 320 WRITE_BOOL(place_dialogs_under_mouse);
312 321
313 322
314 secure_fprintf(ssi, "\n##### File operations Options #####\n\n"); 323 WRITE_SUBTITLE("File operations Options");
315 324
316 write_bool_option(ssi, "file_ops.enable_in_place_rename", options->file_ops.enable_in_place_rename); 325 WRITE_BOOL(file_ops.enable_in_place_rename);
317 write_bool_option(ssi, "file_ops.confirm_delete", options->file_ops.confirm_delete); 326 WRITE_BOOL(file_ops.confirm_delete);
318 write_bool_option(ssi, "file_ops.enable_delete_key", options->file_ops.enable_delete_key); 327 WRITE_BOOL(file_ops.enable_delete_key);
319 write_bool_option(ssi, "file_ops.safe_delete_enable", options->file_ops.safe_delete_enable); 328 WRITE_BOOL(file_ops.safe_delete_enable);
320 write_char_option(ssi, "file_ops.safe_delete_path", options->file_ops.safe_delete_path); 329 WRITE_CHAR(file_ops.safe_delete_path);
321 write_int_option(ssi, "file_ops.safe_delete_folder_maxsize", options->file_ops.safe_delete_folder_maxsize); 330 WRITE_INT(file_ops.safe_delete_folder_maxsize);
322 331
323 332
324 secure_fprintf(ssi, "\n##### Layout Options #####\n\n"); 333 WRITE_SUBTITLE("Layout Options");
325 334
326 write_int_option(ssi, "layout.style", options->layout.style); 335 WRITE_INT(layout.style);
327 write_char_option(ssi, "layout.order", options->layout.order); 336 WRITE_CHAR(layout.order);
328 write_bool_option(ssi, "layout.view_as_icons", options->layout.view_as_icons); 337 WRITE_BOOL(layout.view_as_icons);
329 write_bool_option(ssi, "layout.view_as_tree", options->layout.view_as_tree); 338 WRITE_BOOL(layout.view_as_tree);
330 write_bool_option(ssi, "layout.show_thumbnails", options->layout.show_thumbnails); 339 WRITE_BOOL(layout.show_thumbnails);
331 secure_fputc(ssi, '\n'); 340 WRITE_SEPARATOR();
332 341
333 write_bool_option(ssi, "layout.save_window_positions", options->layout.save_window_positions); 342 WRITE_BOOL(layout.save_window_positions);
334 secure_fputc(ssi, '\n'); 343 WRITE_SEPARATOR();
335 344
336 write_int_option(ssi, "layout.main_window.x", options->layout.main_window.x); 345 WRITE_INT(layout.main_window.x);
337 write_int_option(ssi, "layout.main_window.y", options->layout.main_window.y); 346 WRITE_INT(layout.main_window.y);
338 write_int_option(ssi, "layout.main_window.w", options->layout.main_window.w); 347 WRITE_INT(layout.main_window.w);
339 write_int_option(ssi, "layout.main_window.h", options->layout.main_window.h); 348 WRITE_INT(layout.main_window.h);
340 write_bool_option(ssi, "layout.main_window.maximized", options->layout.main_window.maximized); 349 WRITE_BOOL(layout.main_window.maximized);
341 write_int_option(ssi, "layout.main_window.hdivider_pos", options->layout.main_window.hdivider_pos); 350 WRITE_INT(layout.main_window.hdivider_pos);
342 write_int_option(ssi, "layout.main_window.vdivider_pos", options->layout.main_window.vdivider_pos); 351 WRITE_INT(layout.main_window.vdivider_pos);
343 secure_fputc(ssi, '\n'); 352 WRITE_SEPARATOR();
344 353
345 write_int_option(ssi, "layout.float_window.x", options->layout.float_window.x); 354 WRITE_INT(layout.float_window.x);
346 write_int_option(ssi, "layout.float_window.y", options->layout.float_window.y); 355 WRITE_INT(layout.float_window.y);
347 write_int_option(ssi, "layout.float_window.w", options->layout.float_window.w); 356 WRITE_INT(layout.float_window.w);
348 write_int_option(ssi, "layout.float_window.h", options->layout.float_window.h); 357 WRITE_INT(layout.float_window.h);
349 write_int_option(ssi, "layout.float_window.vdivider_pos", options->layout.float_window.vdivider_pos); 358 WRITE_INT(layout.float_window.vdivider_pos);
350 secure_fputc(ssi, '\n'); 359 WRITE_SEPARATOR();
351 360
352 write_bool_option(ssi, "layout.tools_float", options->layout.tools_float); 361 WRITE_BOOL(layout.tools_float);
353 write_bool_option(ssi, "layout.tools_hidden", options->layout.tools_hidden); 362 WRITE_BOOL(layout.tools_hidden);
354 write_bool_option(ssi, "layout.tools_restore_state", options->layout.tools_restore_state); 363 WRITE_BOOL(layout.tools_restore_state);
355 secure_fputc(ssi, '\n'); 364 WRITE_SEPARATOR();
356 365
357 write_bool_option(ssi, "layout.toolbar_hidden", options->layout.toolbar_hidden); 366 WRITE_BOOL(layout.toolbar_hidden);
358 367
359 368
360 secure_fprintf(ssi, "\n##### Image Options #####\n\n"); 369 WRITE_SUBTITLE("Image Options");
361 370
362 secure_fprintf(ssi, "image.zoom_mode: "); 371 secure_fprintf(ssi, "image.zoom_mode: ");
363 if (options->image.zoom_mode == ZOOM_RESET_ORIGINAL) secure_fprintf(ssi, "original\n"); 372 if (options->image.zoom_mode == ZOOM_RESET_ORIGINAL) secure_fprintf(ssi, "original\n");
364 if (options->image.zoom_mode == ZOOM_RESET_FIT_WINDOW) secure_fprintf(ssi, "fit\n"); 373 if (options->image.zoom_mode == ZOOM_RESET_FIT_WINDOW) secure_fprintf(ssi, "fit\n");
365 if (options->image.zoom_mode == ZOOM_RESET_NONE) secure_fprintf(ssi, "dont_change\n"); 374 if (options->image.zoom_mode == ZOOM_RESET_NONE) secure_fprintf(ssi, "dont_change\n");
366 write_bool_option(ssi, "image.zoom_2pass", options->image.zoom_2pass); 375 WRITE_BOOL(image.zoom_2pass);
367 write_bool_option(ssi, "image.zoom_to_fit_allow_expand", options->image.zoom_to_fit_allow_expand); 376 WRITE_BOOL(image.zoom_to_fit_allow_expand);
368 write_int_option(ssi, "image.zoom_quality", options->image.zoom_quality); 377 WRITE_INT(image.zoom_quality);
369 write_int_option(ssi, "image.zoom_increment", options->image.zoom_increment); 378 WRITE_INT(image.zoom_increment);
370 write_bool_option(ssi, "image.fit_window_to_image", options->image.fit_window_to_image); 379 WRITE_BOOL(image.fit_window_to_image);
371 write_bool_option(ssi, "image.limit_window_size", options->image.limit_window_size); 380 WRITE_BOOL(image.limit_window_size);
372 write_int_option(ssi, "image.max_window_size", options->image.max_window_size); 381 WRITE_INT(image.max_window_size);
373 write_bool_option(ssi, "image.limit_autofit_size", options->image.limit_autofit_size); 382 WRITE_BOOL(image.limit_autofit_size);
374 write_int_option(ssi, "image.max_autofit_size", options->image.max_autofit_size); 383 WRITE_INT(image.max_autofit_size);
375 write_int_option(ssi, "image.scroll_reset_method", options->image.scroll_reset_method); 384 WRITE_INT(image.scroll_reset_method);
376 write_int_option(ssi, "image.tile_cache_max", options->image.tile_cache_max); 385 WRITE_INT(image.tile_cache_max);
377 write_int_option(ssi, "image.dither_quality", options->image.dither_quality); 386 WRITE_INT(image.dither_quality);
378 write_bool_option(ssi, "image.enable_read_ahead", options->image.enable_read_ahead); 387 WRITE_BOOL(image.enable_read_ahead);
379 write_bool_option(ssi, "image.exif_rotate_enable", options->image.exif_rotate_enable); 388 WRITE_BOOL(image.exif_rotate_enable);
380 write_bool_option(ssi, "image.use_custom_border_color", options->image.use_custom_border_color); 389 WRITE_BOOL(image.use_custom_border_color);
381 write_color_option(ssi, "image.border_color", &options->image.border_color); 390 WRITE_COLOR(image.border_color);
382 391
383 392
384 secure_fprintf(ssi, "\n##### Thumbnails Options #####\n\n"); 393 WRITE_SUBTITLE("Thumbnails Options");
385 394
386 write_int_option(ssi, "thumbnails.max_width", options->thumbnails.max_width); 395 WRITE_INT(thumbnails.max_width);
387 write_int_option(ssi, "thumbnails.max_height", options->thumbnails.max_height); 396 WRITE_INT(thumbnails.max_height);
388 write_bool_option(ssi, "thumbnails.enable_caching", options->thumbnails.enable_caching); 397 WRITE_BOOL(thumbnails.enable_caching);
389 write_bool_option(ssi, "thumbnails.cache_into_dirs", options->thumbnails.cache_into_dirs); 398 WRITE_BOOL(thumbnails.cache_into_dirs);
390 write_bool_option(ssi, "thumbnails.fast", options->thumbnails.fast); 399 WRITE_BOOL(thumbnails.fast);
391 write_bool_option(ssi, "thumbnails.use_xvpics", options->thumbnails.use_xvpics); 400 WRITE_BOOL(thumbnails.use_xvpics);
392 write_bool_option(ssi, "thumbnails.spec_standard", options->thumbnails.spec_standard); 401 WRITE_BOOL(thumbnails.spec_standard);
393 write_int_option(ssi, "thumbnails.quality", options->thumbnails.quality); 402 WRITE_INT(thumbnails.quality);
394 403
395 404
396 secure_fprintf(ssi, "\n##### File sorting Options #####\n\n"); 405 WRITE_SUBTITLE("File sorting Options");
397 406
398 write_int_option(ssi, "file_sort.method", (gint)options->file_sort.method); 407 WRITE_INT(file_sort.method);
399 write_bool_option(ssi, "file_sort.ascending", options->file_sort.ascending); 408 WRITE_BOOL(file_sort.ascending);
400 write_bool_option(ssi, "file_sort.case_sensitive", options->file_sort.case_sensitive); 409 WRITE_BOOL(file_sort.case_sensitive);
401 410
402 411
403 secure_fprintf(ssi, "\n##### Fullscreen Options #####\n\n"); 412 WRITE_SUBTITLE("Fullscreen Options");
404 413
405 write_int_option(ssi, "fullscreen.screen", options->fullscreen.screen); 414 WRITE_INT(fullscreen.screen);
406 write_bool_option(ssi, "fullscreen.clean_flip", options->fullscreen.clean_flip); 415 WRITE_BOOL(fullscreen.clean_flip);
407 write_bool_option(ssi, "fullscreen.disable_saver", options->fullscreen.disable_saver); 416 WRITE_BOOL(fullscreen.disable_saver);
408 write_bool_option(ssi, "fullscreen.above", options->fullscreen.above); 417 WRITE_BOOL(fullscreen.above);
409 write_bool_option(ssi, "fullscreen.show_info", options->fullscreen.show_info); 418 WRITE_BOOL(fullscreen.show_info);
410 write_char_option(ssi, "fullscreen.info", options->fullscreen.info); 419 WRITE_CHAR(fullscreen.info);
411 420
412 secure_fprintf(ssi, "\n##### Slideshow Options #####\n\n"); 421 WRITE_SUBTITLE("Slideshow Options");
413 422
414 write_int_unit_option(ssi, "slideshow.delay", options->slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); 423 WRITE_INT_UNIT(slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION);
415 write_bool_option(ssi, "slideshow.random", options->slideshow.random); 424 WRITE_BOOL(slideshow.random);
416 write_bool_option(ssi, "slideshow.repeat", options->slideshow.repeat); 425 WRITE_BOOL(slideshow.repeat);
417 426
418 427
419 secure_fprintf(ssi, "\n##### Collection Options #####\n\n"); 428 WRITE_SUBTITLE("Collection Options");
420 429
421 write_bool_option(ssi, "collections.rectangular_selection", options->collections.rectangular_selection); 430 WRITE_BOOL(collections.rectangular_selection);
422 431
423 432
424 secure_fprintf(ssi, "\n##### Filtering Options #####\n\n"); 433 WRITE_SUBTITLE("Filtering Options");
425 434
426 write_bool_option(ssi, "file_filter.show_hidden_files", options->file_filter.show_hidden_files); 435 WRITE_BOOL(file_filter.show_hidden_files);
427 write_bool_option(ssi, "file_filter.disable", options->file_filter.disable); 436 WRITE_BOOL(file_filter.disable);
428 secure_fputc(ssi, '\n'); 437 WRITE_SEPARATOR();
429 438
430 filter_write_list(ssi); 439 filter_write_list(ssi);
431 440
432 441
433 secure_fprintf(ssi, "\n##### Sidecars Options #####\n\n"); 442 WRITE_SUBTITLE("Sidecars Options");
434 443
435 sidecar_ext_write(ssi); 444 sidecar_ext_write(ssi);
436 445
437 446
438 secure_fprintf(ssi, "\n##### Color Profiles #####\n\n"); 447 WRITE_SUBTITLE("Color Profiles");
439 448
440 #ifndef HAVE_LCMS 449 #ifndef HAVE_LCMS
441 secure_fprintf(ssi, "# NOTICE: %s was not built with support for color profiles,\n" 450 secure_fprintf(ssi, "# NOTICE: %s was not built with support for color profiles,\n"
442 "# color profile options will have no effect.\n\n", GQ_APPNAME); 451 "# color profile options will have no effect.\n\n", GQ_APPNAME);
443 #endif 452 #endif
444 453
445 write_bool_option(ssi, "color_profile.enabled", options->color_profile.enabled); 454 WRITE_BOOL(color_profile.enabled);
446 write_bool_option(ssi, "color_profile.use_image", options->color_profile.use_image); 455 WRITE_BOOL(color_profile.use_image);
447 write_int_option(ssi, "color_profile.input_type", options->color_profile.input_type); 456 WRITE_INT(color_profile.input_type);
448 secure_fputc(ssi, '\n'); 457 WRITE_SEPARATOR();
449 458
450 for (i = 0; i < COLOR_PROFILE_INPUTS; i++) 459 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
451 { 460 {
452 gchar *buf; 461 gchar *buf;
453 462
457 466
458 buf = g_strdup_printf("color_profile.input_name_%d", i + 1); 467 buf = g_strdup_printf("color_profile.input_name_%d", i + 1);
459 write_char_option(ssi, buf, options->color_profile.input_name[i]); 468 write_char_option(ssi, buf, options->color_profile.input_name[i]);
460 g_free(buf); 469 g_free(buf);
461 } 470 }
462 secure_fputc(ssi, '\n'); 471
463 write_int_option(ssi, "color_profile.screen_type", options->color_profile.screen_type); 472 WRITE_SEPARATOR();
464 write_char_option(ssi, "color_profile.screen_file", options->color_profile.screen_file); 473 WRITE_INT(color_profile.screen_type);
465 474 WRITE_CHAR(color_profile.screen_file);
466 secure_fprintf(ssi, "\n##### External Programs #####\n"); 475
476 WRITE_SUBTITLE("External Programs");
467 secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS); 477 secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS);
468 secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS); 478 secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS);
469 secure_fprintf(ssi, "# format: external_n: \"menu name\" \"command line\"\n\n"); 479 secure_fprintf(ssi, "# format: external_n: \"menu name\" \"command line\"\n\n");
470 480
471 for (i = 0; i < GQ_EDITOR_SLOTS; i++) 481 for (i = 0; i < GQ_EDITOR_SLOTS; i++)
477 g_free(qname); 487 g_free(qname);
478 g_free(qcommand); 488 g_free(qcommand);
479 } 489 }
480 490
481 491
482 secure_fprintf(ssi, "\n##### Exif Options #####\n# Display:\n# 0: never\n# 1: if set\n# 2: always\n\n"); 492 WRITE_SUBTITLE("Exif Options");
493 secure_fprintf(ssi, "# Display: 0: never\n"
494 "# 1: if set\n"
495 "# 2: always\n\n");
483 for (i = 0; ExifUIList[i].key; i++) 496 for (i = 0; ExifUIList[i].key; i++)
484 { 497 {
485 secure_fprintf(ssi, "exif.display."); 498 secure_fprintf(ssi, "exif.display.");
486 write_int_option(ssi, (gchar *)ExifUIList[i].key, ExifUIList[i].current); 499 write_int_option(ssi, (gchar *)ExifUIList[i].key, ExifUIList[i].current);
487 } 500 }
488 501
489 secure_fputc(ssi, '\n'); 502 WRITE_SEPARATOR();
503 WRITE_SEPARATOR();
504
490 secure_fprintf(ssi, "######################################################################\n"); 505 secure_fprintf(ssi, "######################################################################\n");
491 secure_fprintf(ssi, "# end of config file #\n"); 506 secure_fprintf(ssi, "# end of config file #\n");
492 secure_fprintf(ssi, "######################################################################\n"); 507 secure_fprintf(ssi, "######################################################################\n");
493 508
494 509