Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
  3.  * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * NetSurf is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; version 2 of the License.
  10.  *
  11.  * NetSurf is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. /** \file
  21.  * Option reading and saving (interface).
  22.  *
  23.  * Non-platform specific options can be added by editing this file and
  24.  * netsurf/desktop/options.c
  25.  *
  26.  * Platform specific options should be added in the platform options.h.
  27.  *
  28.  * The following types of options are supported:
  29.  *  - bool (OPTION_BOOL)
  30.  *  - int (OPTION_INTEGER)
  31.  *  - char* (OPTION_STRING) (must be allocated on heap, may be 0, free before
  32.  *                           assigning a new value)
  33.  */
  34.  
  35. #ifndef _NETSURF_DESKTOP_OPTIONS_H_
  36. #define _NETSURF_DESKTOP_OPTIONS_H_
  37.  
  38. #define _NETSURF_DESKTOP_OPTIONS_INCLUDING_
  39.  
  40. #include <stdbool.h>
  41. #include <stdio.h>
  42.  
  43. #include "desktop/plot_style.h"
  44. #include "desktop/options_main.h"
  45.  
  46. #if defined(riscos)
  47. #include "riscos/options.h"
  48. #elif defined(nsgtk)
  49. #include "gtk/options.h"
  50. #elif defined(nsbeos)
  51. #include "beos/options.h"
  52. #elif defined(nsamiga)
  53. #include "amiga/options.h"
  54. #elif defined(nsframebuffer)
  55. #include "framebuffer/options.h"
  56. #elif defined(nsatari)
  57. #include "atari/options.h"
  58. #elif defined(nsmonkey)
  59. #include "monkey/options.h"
  60. #else
  61. #define NSOPTION_EXTRA_DEFINE
  62. #define NSOPTION_EXTRA_DEFAULTS
  63. #define NSOPTION_EXTRA_TABLE
  64. #endif
  65.  
  66. /* allow the colour defaults to be overidden by the frontends */
  67. #ifndef NSOPTION_SYS_COLOUR_DEFAULTS
  68. #define NSOPTION_SYS_COLOUR_DEFAULTS NSOPTION_MAIN_SYS_COLOUR_DEFAULTS
  69. #endif
  70.  
  71. #undef _NETSURF_DESKTOP_OPTIONS_INCLUDING_
  72.  
  73.  
  74. enum { OPTION_HTTP_PROXY_AUTH_NONE = 0,
  75.        OPTION_HTTP_PROXY_AUTH_BASIC = 1,
  76.        OPTION_HTTP_PROXY_AUTH_NTLM = 2 };
  77.  
  78. #define DEFAULT_MARGIN_TOP_MM 10
  79. #define DEFAULT_MARGIN_BOTTOM_MM 10
  80. #define DEFAULT_MARGIN_LEFT_MM 10
  81. #define DEFAULT_MARGIN_RIGHT_MM 10
  82. #define DEFAULT_EXPORT_SCALE 0.7
  83. #ifdef riscos
  84. #define DEFAULT_REFLOW_PERIOD 100 /* time in cs */
  85. #else
  86. #define DEFAULT_REFLOW_PERIOD 25 /* time in cs */
  87. #endif
  88.  
  89. struct ns_options {
  90.         NSOPTION_MAIN_DEFINE;
  91.         NSOPTION_EXTRA_DEFINE;
  92. };
  93.  
  94. /* global option struct */
  95. extern struct ns_options nsoptions;
  96.  
  97. /* acessors */
  98. #define nsoption_bool(OPTION) (nsoptions.OPTION)
  99. #define nsoption_int(OPTION) (nsoptions.OPTION)
  100. #define nsoption_charp(OPTION) (nsoptions.OPTION)
  101. #define nsoption_colour(OPTION) (nsoptions.OPTION)
  102.  
  103. #define nsoption_set_bool(OPTION, VALUE) nsoptions.OPTION = VALUE
  104. #define nsoption_set_int(OPTION, VALUE) nsoptions.OPTION = VALUE
  105. #define nsoption_set_colour(OPTION, VALUE) nsoptions.OPTION = VALUE
  106. #define nsoption_set_charp(OPTION, VALUE) do {  \
  107.         if (nsoptions.OPTION != NULL) {         \
  108.                 free(nsoptions.OPTION);         \
  109.         }                                       \
  110.         nsoptions.OPTION = VALUE;               \
  111.         if ((nsoptions.OPTION != NULL) &&       \
  112.             (*nsoptions.OPTION == 0)) {         \
  113.             free(nsoptions.OPTION);             \
  114.             nsoptions.OPTION = NULL;            \
  115.         }                                       \
  116.     } while (0)
  117.  
  118. #define nsoption_setnull_charp(OPTION, VALUE)           \
  119.     do {                                                \
  120.         if (nsoptions.OPTION == NULL) {                 \
  121.             nsoptions.OPTION = VALUE;                   \
  122.             if (*nsoptions.OPTION == 0) {               \
  123.                 free(nsoptions.OPTION);                 \
  124.                 nsoptions.OPTION = NULL;                \
  125.             }                                           \
  126.         } else {                                        \
  127.             free(VALUE);                                \
  128.         }                                               \
  129.     } while (0)
  130.  
  131.  
  132. /**
  133.  * Read options from a file.
  134.  *
  135.  * \param  path  name of file to read options from
  136.  *
  137.  * Option variables corresponding to lines in the file are updated. Missing
  138.  * options are unchanged. If the file fails to open, options are unchanged.
  139.  */
  140. void nsoption_read(const char *path);
  141.  
  142. /**
  143.  * Save options to a file.
  144.  *
  145.  * \param  path  name of file to write options to
  146.  *
  147.  * Errors are ignored.
  148.  */
  149. void nsoption_write(const char *path);
  150.  
  151. /**
  152.  * Dump user options to stream
  153.  *
  154.  * \param outf output stream to dump options to.
  155.  */
  156. void nsoption_dump(FILE *outf);
  157.  
  158. /**
  159.  * Fill a buffer with an option using a format.
  160.  *
  161.  * The format string is copied into the output buffer with the
  162.  * following replaced:
  163.  * %k - The options key
  164.  * %t - The options type
  165.  * %V - value - HTML type formatting
  166.  * %v - value - plain formatting
  167.  *
  168.  * \param string  The buffer in which to place the results.
  169.  * \param size    The size of the string buffer.
  170.  * \param option  The opaque option number.
  171.  * \param fmt     The format string.
  172.  * \return The number of bytes written to \a string or -1 on error
  173.  */
  174. int nsoption_snoptionf(char *string, size_t size, unsigned int option,
  175.                 const char *fmt);
  176.  
  177. /**
  178.  * Process commandline and set options approriately.
  179.  */
  180. void nsoption_commandline(int *pargc, char **argv);
  181.  
  182. /**
  183.  * Set default values for unset front-end specific options
  184.  */
  185. void gui_options_init_defaults(void);
  186.  
  187. #endif
  188.  
  189.