summaryrefslogtreecommitdiff
path: root/desktop/options.h
blob: 53c025c180404efae951c9527162fbbba9ffb905 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** \file
 * Option reading and saving (interface).
 *
 * Non-platform specific options can be added by editing this file and
 * netsurf/desktop/options.c
 *
 * Platform specific options should be added in the platform options.h.
 *
 * The following types of options are supported:
 *  - bool (OPTION_BOOL)
 *  - int (OPTION_INTEGER)
 *  - char* (OPTION_STRING) (must be allocated on heap, may be 0, free before
 *                           assigning a new value)
 */

#ifndef _NETSURF_DESKTOP_OPTIONS_H_
#define _NETSURF_DESKTOP_OPTIONS_H_

#define _NETSURF_DESKTOP_OPTIONS_INCLUDING_

#include <stdbool.h>
#include <stdio.h>

#include "desktop/plot_style.h"
#include "desktop/options_main.h"

#if defined(riscos)
#include "riscos/options.h"
#elif defined(nsgtk)
#include "gtk/options.h"
#elif defined(nsbeos)
#include "beos/options.h"
#elif defined(nsamiga)
#include "amiga/options.h"
#elif defined(nsframebuffer)
#include "framebuffer/options.h"
#elif defined(nsatari)
#include "atari/options.h"
#elif defined(nsmonkey)
#include "monkey/options.h"
#else
#define NSOPTION_EXTRA_DEFINE
#define NSOPTION_EXTRA_DEFAULTS
#define NSOPTION_EXTRA_TABLE
#endif

/* allow the colour defaults to be overidden by the frontends */
#ifndef NSOPTION_SYS_COLOUR_DEFAULTS
#define NSOPTION_SYS_COLOUR_DEFAULTS NSOPTION_MAIN_SYS_COLOUR_DEFAULTS
#endif

#undef _NETSURF_DESKTOP_OPTIONS_INCLUDING_


enum { OPTION_HTTP_PROXY_AUTH_NONE = 0,
       OPTION_HTTP_PROXY_AUTH_BASIC = 1,
       OPTION_HTTP_PROXY_AUTH_NTLM = 2 };

#define DEFAULT_MARGIN_TOP_MM 10
#define DEFAULT_MARGIN_BOTTOM_MM 10
#define DEFAULT_MARGIN_LEFT_MM 10
#define DEFAULT_MARGIN_RIGHT_MM 10
#define DEFAULT_EXPORT_SCALE 0.7
#ifdef riscos
#define DEFAULT_REFLOW_PERIOD 100 /* time in cs */
#else
#define DEFAULT_REFLOW_PERIOD 25 /* time in cs */
#endif

struct ns_options {
	NSOPTION_MAIN_DEFINE;
	NSOPTION_EXTRA_DEFINE;
};

/* global option struct */
extern struct ns_options nsoptions;

/* acessors */
#define nsoption_bool(OPTION) (nsoptions.OPTION)
#define nsoption_int(OPTION) (nsoptions.OPTION)
#define nsoption_charp(OPTION) (nsoptions.OPTION)
#define nsoption_colour(OPTION) (nsoptions.OPTION)

#define nsoption_set_bool(OPTION, VALUE) nsoptions.OPTION = VALUE
#define nsoption_set_int(OPTION, VALUE) nsoptions.OPTION = VALUE
#define nsoption_set_colour(OPTION, VALUE) nsoptions.OPTION = VALUE
#define nsoption_set_charp(OPTION, VALUE) do {	\
	if (nsoptions.OPTION != NULL) {		\
		free(nsoptions.OPTION);		\
	}					\
	nsoptions.OPTION = VALUE;               \
        if (*nsoptions.OPTION == 0) {           \
            free(nsoptions.OPTION);             \
            nsoptions.OPTION = NULL;            \
        }                                       \
    } while (0)

#define nsoption_setnull_charp(OPTION, VALUE)           \
    do {                                                \
        if (nsoptions.OPTION == NULL) {                 \
            nsoptions.OPTION = VALUE;                   \
            if (*nsoptions.OPTION == 0) {               \
                free(nsoptions.OPTION);                 \
                nsoptions.OPTION = NULL;                \
            }                                           \
        } else {                                        \
            free(VALUE);                                \
        }                                               \
    } while (0)


/**
 * Read options from a file.
 *
 * \param  path  name of file to read options from
 *
 * Option variables corresponding to lines in the file are updated. Missing
 * options are unchanged. If the file fails to open, options are unchanged.
 */
void nsoption_read(const char *path);

/**
 * Save options to a file.
 *
 * \param  path  name of file to write options to
 *
 * Errors are ignored.
 */
void nsoption_write(const char *path);

/**
 * Dump user options to stream
 *
 * \param outf output stream to dump options to.
 */
void nsoption_dump(FILE *outf);

/**
 * Fill a buffer with an option using a format.
 *
 * The format string is copied into the output buffer with the
 * following replaced:
 * %k - The options key
 * %t - The options type
 * %V - value - HTML type formatting
 * %v - value - plain formatting
 *
 * \param string  The buffer in which to place the results.
 * \param size    The size of the string buffer.
 * \param option  The opaque option number.
 * \param fmt     The format string.
 * \return The number of bytes written to \a string or -1 on error
 */
int nsoption_snoptionf(char *string, size_t size, unsigned int option,
		const char *fmt);

/**
 * Process commandline and set options approriately.
 */
void nsoption_commandline(int *pargc, char **argv);

/**
 * Set default values for unset front-end specific options
 */
void gui_options_init_defaults(void);

#endif