[project @ 2004-02-13 16:09:12 by bursa]

Clean up and rewrite options code.

svn path=/import/netsurf/; revision=536
This commit is contained in:
James Bursa 2004-02-13 16:09:12 +00:00
parent add94ad038
commit 1319ff78c8
14 changed files with 336 additions and 396 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
*/
@ -291,11 +291,12 @@ struct fetch * fetch_start(char *url, char *referer,
assert(code == CURLE_OK);
/* use proxy if options dictate this */
if (OPTIONS.http)
{
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXY, OPTIONS.http_proxy);
if (option_http_proxy && option_http_proxy_host) {
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXY,
option_http_proxy_host);
assert(code == CURLE_OK);
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXYPORT, (long)OPTIONS.http_port);
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXYPORT,
(long) option_http_proxy_port);
assert(code == CURLE_OK);
}

View File

@ -2,7 +2,7 @@
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
#include <stdbool.h>
@ -12,6 +12,7 @@
#include "netsurf/content/cache.h"
#include "netsurf/content/content.h"
#include "netsurf/content/fetchcache.h"
#include "netsurf/desktop/options.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
@ -41,6 +42,7 @@ int main(int argc, char *argv[])
fetch_init();
cache_init();
fetchcache_init();
options_read("options");
while (1) {
puts("=== URL:");
@ -48,7 +50,7 @@ int main(int argc, char *argv[])
break;
url[strlen(url) - 1] = 0;
destroyed = 0;
c = fetchcache(url, 0, callback, 0, 0, 100, 1000, false
c = fetchcache(url, 0, callback, 0, 0, 1000, 1000, false
#ifdef WITH_POST
, 0, 0
#endif
@ -70,6 +72,7 @@ int main(int argc, char *argv[])
content_remove_user(c, callback, 0, 0);
}
options_write("options");
cache_quit();
fetch_quit();

View File

@ -1,28 +0,0 @@
/*
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
*/
#include "netsurf/desktop/options.h"
#include <stdio.h>
#include <string.h>
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
struct options OPTIONS;
void options_init(struct options* opt)
{
opt->http = 0;
opt->http_proxy = strdup("");
opt->http_port = 8080;
opt->use_mouse_gestures = 0;
opt->allow_text_selection = 1;
opt->use_riscos_elements = 1;
opt->show_toolbar = 1;
opt->show_print_preview = 0;
opt->theme = strdup("Default");
}

View File

@ -3,7 +3,7 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
#include <stdbool.h>
@ -50,8 +50,6 @@ int main(int argc, char** argv)
void netsurf_init(int argc, char** argv)
{
stdout = stderr;
options_init(&OPTIONS);
options_read(&OPTIONS, NULL);
gui_init(argc, argv);
fetch_init();
cache_init();

157
desktop/options.c Normal file
View File

@ -0,0 +1,157 @@
/*
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
/** \file
* Option reading and saving (implementation).
*
* Options are stored in the format key:value, one per line. For bool options,
* value is "0" or "1".
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "netsurf/desktop/options.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
#ifdef riscos
#include "netsurf/riscos/options.h"
#else
#define EXTRA_OPTION_DEFINE
#define EXTRA_OPTION_TABLE
#endif
/** An HTTP proxy should be used. */
bool option_http_proxy = false;
/** Hostname of proxy. */
char *option_http_proxy_host = 0;
/** Proxy port. */
int option_http_proxy_port = 8080;
EXTRA_OPTION_DEFINE
struct {
const char *key;
enum { OPTION_BOOL, OPTION_INTEGER, OPTION_STRING } type;
void *p;
} option_table[] = {
{ "http_proxy", OPTION_BOOL, &option_http_proxy },
{ "http_proxy_host", OPTION_STRING, &option_http_proxy_host },
{ "http_proxy_port", OPTION_INTEGER, &option_http_proxy_port },
EXTRA_OPTION_TABLE
};
#define option_table_entries (sizeof option_table / sizeof option_table[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 options_read(const char *path)
{
char s[100];
FILE *fp;
fp = fopen(path, "r");
if (!fp) {
LOG(("failed to open file '%s'", path));
return;
}
while (fgets(s, 100, fp)) {
char *colon, *value;
unsigned int i;
if (s[0] == 0 || s[0] == '#')
continue;
colon = strchr(s, ':');
if (colon == 0)
continue;
s[strlen(s) - 1] = 0; /* remove \n at end */
*colon = 0; /* terminate key */
value = colon + 1;
for (i = 0; i != option_table_entries; i++) {
if (strcasecmp(s, option_table[i].key) != 0)
continue;
switch (option_table[i].type) {
case OPTION_BOOL:
*((bool *) option_table[i].p) =
value[0] == '1';
break;
case OPTION_INTEGER:
*((int *) option_table[i].p) =
atoi(value);
break;
case OPTION_STRING:
free(*((char **) option_table[i].p));
*((char **) option_table[i].p) =
strdup(value);
break;
}
break;
}
}
fclose(fp);
}
/**
* Save options to a file.
*
* \param path name of file to write options to
*
* Errors are ignored.
*/
void options_write(const char *path)
{
unsigned int i;
FILE *fp;
fp = fopen(path, "w");
if (!fp) {
LOG(("failed to open file '%s' for writing", path));
return;
}
for (i = 0; i != option_table_entries; i++) {
fprintf(fp, "%s:", option_table[i].key);
switch (option_table[i].type) {
case OPTION_BOOL:
fprintf(fp, "%c", *((bool *) option_table[i].p) ?
'1' : '0');
break;
case OPTION_INTEGER:
fprintf(fp, "%i", *((int *) option_table[i].p));
break;
case OPTION_STRING:
if (*((char **) option_table[i].p))
fprintf(fp, "%s", *((char **) option_table[i].p));
break;
}
fprintf(fp, "\n");
}
fclose(fp);
}

View File

@ -3,32 +3,32 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
/** \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_
struct options;
extern bool option_http_proxy;
extern char *option_http_proxy_host;
extern int option_http_proxy_port;
#include "netsurf/riscos/options.h"
struct options
{
/* global options */
int http;
char* http_proxy;
int http_port;
/* platform specific options */
PLATFORM_OPTIONS
};
extern struct options OPTIONS;
void options_init(struct options* opt);
void options_write(struct options*, char* filename);
void options_read(struct options*, char* filename);
void options_read(const char *path);
void options_write(const char *path);
#endif

View File

@ -11,17 +11,17 @@ OBJECTS_COMMON = cache.o content.o fetch.o fetchcache.o other.o \
box.o form.o html.o layout.o textplain.o \
messages.o utils.o translit.o pool.o
OBJECTS = $(OBJECTS_COMMON) \
browser.o loginlist.o netsurf.o \
browser.o loginlist.o netsurf.o options.o \
htmlinstance.o htmlredraw.o \
401login.o constdata.o dialog.o download.o frames.o gui.o \
menus.o mouseactions.o \
options.o textselection.o theme.o window.o \
textselection.o theme.o window.o \
draw.o gif.o jpeg.o plugin.o png.o sprite.o \
about.o filetype.o font.o uri.o url.o history.o \
version.o
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
netsurfd.o \
optionsd.o filetyped.o fontd.o
options.o filetyped.o fontd.o
OBJECTS_DEBUGRO = $(OBJECTS_COMMON) \
netsurfd.o \
constdata.o \
@ -29,7 +29,7 @@ OBJECTS_DEBUGRO = $(OBJECTS_COMMON) \
draw.o gif.o jpeg.o png.o sprite.o \
about.o filetype.o \
version.o \
optionsd.o font.o
options.o font.o
VPATH = content:css:desktop:render:riscos:utils:debug
WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wbad-function-cast -Wcast-qual \
-Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes \

View File

@ -3,7 +3,7 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
*/
@ -32,29 +32,24 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
;
wimp_menu* theme_menu = NULL;
static struct ro_choices choices;
static struct browser_choices browser_choices;
static struct proxy_choices proxy_choices;
static struct theme_choices theme_choices;
static void ro_gui_dialog_click_config(wimp_pointer *pointer);
static void ro_gui_dialog_click_config_br(wimp_pointer *pointer);
static void ro_gui_dialog_click_config_prox(wimp_pointer *pointer);
static void ro_gui_dialog_click_config_th(wimp_pointer *pointer);
static void set_browser_choices(struct browser_choices* newchoices);
static void get_browser_choices(struct browser_choices* newchoices);
static void set_proxy_choices(struct proxy_choices* newchoices);
static void get_proxy_choices(struct proxy_choices* newchoices);
static void set_browser_choices(void);
static void get_browser_choices(void);
static void set_proxy_choices(void);
static void get_proxy_choices(void);
static void set_theme_choices(void);
static void get_theme_choices(void);
static void load_theme_preview(char* thname);
static void set_theme_choices(struct theme_choices* newchoices);
static void get_theme_choices(struct theme_choices* newchoices);
/*static void ro_gui_destroy_theme_menu(void);*/
static void ro_gui_build_theme_menu(void);
static int file_exists(const char* base, const char* dir, const char* leaf, bits ftype);
static void set_icon_state(wimp_w w, wimp_i i, int state);
static int get_icon_state(wimp_w w, wimp_i i);
static void set_icon_string(wimp_w w, wimp_i i, char* text);
static void set_icon_string(wimp_w w, wimp_i i, const char *text);
static char* get_icon_string(wimp_w w, wimp_i i);
static void set_icon_string_i(wimp_w w, wimp_i i, int num);
@ -75,10 +70,9 @@ void ro_gui_dialog_init(void)
dialog_config_prox = ro_gui_dialog_create("config_prox");
dialog_config_th = ro_gui_dialog_create("config_th");
options_to_ro(&OPTIONS, &choices);
set_browser_choices(&choices.browser);
set_proxy_choices(&choices.proxy);
set_theme_choices(&choices.theme);
set_browser_choices();
set_proxy_choices();
set_theme_choices();
}
@ -189,8 +183,12 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer)
{
switch (pointer->i) {
case ICON_CONFIG_SAVE:
ro_to_options(&choices, &OPTIONS);
options_write(&OPTIONS, NULL);
get_browser_choices();
get_proxy_choices();
get_theme_choices();
xosfile_create_dir("<Choices$Write>.WWW", 0);
xosfile_create_dir("<Choices$Write>.WWW.NetSurf", 0);
options_write("<Choices$Write>.WWW.NetSurf.Choices");
if (pointer->buttons == wimp_CLICK_SELECT) {
ro_gui_dialog_close(dialog_config_br);
ro_gui_dialog_close(dialog_config_prox);
@ -204,9 +202,10 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer)
ro_gui_dialog_close(dialog_config_prox);
ro_gui_dialog_close(dialog_config_th);
ro_gui_dialog_close(dialog_config);
} else {
options_to_ro(&OPTIONS, &choices);
}
set_browser_choices();
set_proxy_choices();
set_theme_choices();
break;
case ICON_CONFIG_BROWSER:
ro_gui_dialog_open(dialog_config_br);
@ -231,16 +230,13 @@ void ro_gui_dialog_click_config_br(wimp_pointer *pointer)
switch (pointer->i) {
case ICON_CONFIG_BR_OK:
get_browser_choices(&choices.browser);
get_browser_choices(&browser_choices);
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_br);
break;
case ICON_CONFIG_BR_CANCEL:
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_br);
else
set_browser_choices(&choices.browser);
set_browser_choices();
break;
case ICON_CONFIG_BR_EXPLAIN:
bw = create_browser_window(browser_TITLE | browser_TOOLBAR |
@ -264,16 +260,13 @@ void ro_gui_dialog_click_config_prox(wimp_pointer *pointer)
{
switch (pointer->i) {
case ICON_CONFIG_PROX_OK:
get_proxy_choices(&choices.proxy);
get_proxy_choices(&proxy_choices);
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_prox);
break;
case ICON_CONFIG_PROX_CANCEL:
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_prox);
else
set_proxy_choices(&choices.proxy);
set_proxy_choices();
break;
}
}
@ -289,16 +282,13 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer)
switch (pointer->i) {
case ICON_CONFIG_TH_OK:
get_theme_choices(&choices.theme);
get_theme_choices(&theme_choices);
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_th);
break;
case ICON_CONFIG_TH_CANCEL:
if (pointer->buttons == wimp_CLICK_SELECT)
ro_gui_dialog_close(dialog_config_th);
else
set_theme_choices(&choices.theme);
set_theme_choices();
break;
case ICON_CONFIG_TH_NAME:
case ICON_CONFIG_TH_PICK:
@ -333,41 +323,91 @@ void ro_gui_dialog_close(wimp_w close)
}
/**
* Update the browser choices dialog with the current options.
*/
void set_browser_choices(struct browser_choices* newchoices)
void set_browser_choices(void)
{
memcpy(&browser_choices, newchoices, sizeof(struct browser_choices));
set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES, browser_choices.use_mouse_gestures);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM, browser_choices.use_riscos_elements);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT, browser_choices.allow_text_selection);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR, browser_choices.show_toolbar);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW, browser_choices.show_print_preview);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES,
option_use_mouse_gestures);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT,
option_allow_text_selection);
set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR,
option_show_toolbar);
}
void get_browser_choices(struct browser_choices* newchoices)
/**
* Set the current options to the settings in the browser choices dialog.
*/
void get_browser_choices(void)
{
newchoices->use_mouse_gestures = get_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES);
newchoices->use_riscos_elements = get_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM);
newchoices->allow_text_selection = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT);
newchoices->show_toolbar = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR);
newchoices->show_print_preview = get_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW);
option_use_mouse_gestures = get_icon_state(dialog_config_br,
ICON_CONFIG_BR_GESTURES);
option_allow_text_selection = get_icon_state(dialog_config_br,
ICON_CONFIG_BR_TEXT);
option_show_toolbar = get_icon_state(dialog_config_br,
ICON_CONFIG_BR_TOOLBAR);
}
void set_proxy_choices(struct proxy_choices* newchoices)
/**
* Update the proxy choices dialog with the current options.
*/
void set_proxy_choices(void)
{
memcpy(&proxy_choices, newchoices, sizeof(struct proxy_choices));
set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP, proxy_choices.http);
set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST, proxy_choices.http_proxy);
set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT, proxy_choices.http_port);
set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP,
option_http_proxy);
set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST,
option_http_proxy_host);
set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT,
option_http_proxy_port);
}
void get_proxy_choices(struct proxy_choices* newchoices)
/**
* Set the current options to the settings in the proxy choices dialog.
*/
void get_proxy_choices(void)
{
newchoices->http = get_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP);
strncpy(newchoices->http_proxy, get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST), 255);
newchoices->http_port = atoi(get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT));
option_http_proxy = get_icon_state(dialog_config_prox,
ICON_CONFIG_PROX_HTTP);
free(option_http_proxy_host);
option_http_proxy_host = strdup(get_icon_string(dialog_config_prox,
ICON_CONFIG_PROX_HTTPHOST));
option_http_proxy_port = atoi(get_icon_string(dialog_config_prox,
ICON_CONFIG_PROX_HTTPPORT));
}
/**
* Update the theme choices dialog with the current options.
*/
void set_theme_choices(void)
{
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME,
option_theme ? option_theme : "Default");
load_theme_preview(option_theme ? option_theme : "Default");
}
/**
* Set the current options to the settings in the theme choices dialog.
*/
void get_theme_choices(void)
{
free(option_theme);
option_theme = strdup(get_icon_string(dialog_config_th,
ICON_CONFIG_TH_NAME));
}
osspriteop_area* theme_preview = NULL;
void load_theme_preview(char* thname)
@ -469,18 +509,6 @@ void ro_gui_redraw_config_th(wimp_draw* redraw)
}
void set_theme_choices(struct theme_choices* newchoices)
{
memcpy(&theme_choices, newchoices, sizeof(struct theme_choices));
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name);
load_theme_preview(theme_choices.name);
}
void get_theme_choices(struct theme_choices* newchoices)
{
strncpy(newchoices->name, get_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME), 255);
}
/**
* Construct or update theme_menu by scanning THEMES_DIR.
@ -527,7 +555,7 @@ void ro_gui_build_theme_menu(void)
theme_menu = xrealloc(theme_menu, wimp_SIZEOF_MENU(i + 1));
theme_menu->entries[i].menu_flags = 0;
if (strcmp(info.name, theme_choices.name) == 0)
if (option_theme && strcmp(info.name, option_theme) == 0)
theme_menu->entries[i].menu_flags |= wimp_MENU_TICKED;
theme_menu->entries[i].sub_menu = wimp_NO_SUB_MENU;
theme_menu->entries[i].icon_flags = wimp_ICON_TEXT |
@ -554,9 +582,8 @@ void ro_gui_build_theme_menu(void)
void ro_gui_theme_menu_selection(char *theme)
{
strcpy(theme_choices.name, theme);
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name);
load_theme_preview(theme_choices.name);
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme);
load_theme_preview(theme);
wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_NAME, 0, 0);
wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0);
@ -598,14 +625,23 @@ int get_icon_state(wimp_w w, wimp_i i)
return (ic.icon.flags & wimp_ICON_SELECTED) != 0;
}
void set_icon_string(wimp_w w, wimp_i i, char* text)
/**
* Set the contents of an icon to a string.
*
* \param w window handle
* \param i icon handle
* \param text string (copied)
*/
void set_icon_string(wimp_w w, wimp_i i, const char *text)
{
wimp_icon_state ic;
ic.w = w;
ic.i = i;
wimp_get_icon_state(&ic);
strncpy(ic.icon.data.indirected_text.text, text,
(unsigned int)ic.icon.data.indirected_text.size);
(unsigned int)ic.icon.data.indirected_text.size);
}
char* get_icon_string(wimp_w w, wimp_i i)

View File

@ -3,7 +3,7 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
*/
@ -33,6 +33,7 @@
#endif
#include "netsurf/riscos/constdata.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/options.h"
#ifdef WITH_PLUGIN
#include "netsurf/riscos/plugin.h"
#endif
@ -140,18 +141,19 @@ void gui_init(int argc, char** argv)
if (getenv("NetSurf$Start_URI_Handler"))
xwimp_start_task("Desktop", 0);
if (OPTIONS.theme) {
options_read("Choices:WWW.NetSurf.Choices");
if (option_theme) {
snprintf(theme_fname, sizeof(theme_fname),
"<NetSurf$Dir>.Themes.%s", OPTIONS.theme);
"<NetSurf$Dir>.Themes.%s", option_theme);
/* check if theme directory exists */
if (!is_dir(theme_fname)) {
free(OPTIONS.theme);
OPTIONS.theme = strdup("Default");
free(option_theme);
option_theme = 0;
sprintf(theme_fname, "<NetSurf$Dir>.Themes.Default");
}
} else {
OPTIONS.theme = strdup("Default");
sprintf(theme_fname, "<NetSurf$Dir>.Themes.Default");
strcpy(theme_fname, "<NetSurf$Dir>.Themes.Default");
}
ro_theme_load(theme_fname);

View File

@ -3,7 +3,7 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
#ifndef _NETSURF_RISCOS_GUI_H_
@ -184,12 +184,9 @@ void ro_gui_history_click(wimp_pointer *pointer);
#define ICON_CONFIG_BR_OK 0
#define ICON_CONFIG_BR_CANCEL 1
#define ICON_CONFIG_BR_EXPLAIN 2
#define ICON_CONFIG_BR_DEFAULT 3
#define ICON_CONFIG_BR_FORM 4
#define ICON_CONFIG_BR_GESTURES 5
#define ICON_CONFIG_BR_TEXT 6
#define ICON_CONFIG_BR_TOOLBAR 7
#define ICON_CONFIG_BR_PREVIEW 8
#define ICON_CONFIG_BR_GESTURES 3
#define ICON_CONFIG_BR_TEXT 4
#define ICON_CONFIG_BR_TOOLBAR 5
#define ICON_CONFIG_PROX_OK 0
#define ICON_CONFIG_PROX_CANCEL 1

View File

@ -11,8 +11,8 @@
#include "netsurf/utils/config.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/desktop/options.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/options.h"
#include "netsurf/utils/log.h"
typedef enum {
@ -34,7 +34,7 @@ void ro_gui_mouse_action(gui_window *g) {
int x, y;
mouseaction ma = mouseaction_NONE;
if (OPTIONS.use_mouse_gestures)
if (option_use_mouse_gestures)
ma = ro_gui_try_mouse_action();
if (ma == mouseaction_NONE) {

View File

@ -1,204 +0,0 @@
/*
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
*/
#include "netsurf/desktop/options.h"
#include <stdio.h>
#include <string.h>
#include "oslib/messagetrans.h"
#include "oslib/osfile.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
struct options OPTIONS;
static char* lookup(messagetrans_control_block* cb, const char* token, const char* deflt);
static int lookup_yesno(messagetrans_control_block* cb, const char* token, const char* deflt);
static int lookup_i(messagetrans_control_block* cb, const char* token, const char* deflt);
static const char* yesno(int q);
char* lookup(messagetrans_control_block* cb, const char* token, const char* deflt)
{
int used;
char buffer[256];
LOG(("Looking up token '%s'",token));
messagetrans_lookup(cb, token, buffer, 256, 0,0,0,0, &used);
if (used > 0)
{
return strdup(buffer);
}
else
return strdup(deflt);
}
int lookup_yesno(messagetrans_control_block* cb, const char* token, const char* deflt)
{
char* find;
LOG(("yesno token '%s' (default '%s')", token, deflt));
find = lookup(cb, token, deflt);
if (strcmp(find, "Y") == 0)
{
xfree(find);
return -1;
}
xfree(find);
return 0;
}
int lookup_i(messagetrans_control_block* cb, const char* token, const char* deflt)
{
char* find = lookup(cb, token, deflt);
int ret = atoi(find);
xfree(find);
return ret;
}
const char* yesno(int q)
{
if (q)
return "Y";
else
return "N";
}
static const char * const WRITE_DIR = "<Choices$Write>.WWW.NetSurf";
void options_write(struct options* opt, char* filename)
{
char* fn;
FILE* f;
fn = xcalloc(strlen(WRITE_DIR) + (filename == 0 ? 7 : strlen(filename)) + 10,
sizeof(char));
sprintf(fn, "%s.%s", WRITE_DIR, filename == 0 ? "Choices" : filename);
xosfile_create_dir("<Choices$Write>.WWW", 0);
xosfile_create_dir(WRITE_DIR, 0);
LOG(("filename: %s", fn));
f = fopen(fn, "w");
if (f != NULL)
{
fprintf(f, "# General options - for any platform\n# Proxy\n");
fprintf(f, "USE_HTTP:%s\n", yesno(opt->http));
fprintf(f, "HTTP_PROXY:%s\n", opt->http_proxy);
fprintf(f, "HTTP_PORT:%d\n", opt->http_port);
fprintf(f, "\n# RISC OS specific options\n# Browser\n");
fprintf(f, "RO_MOUSE_GESTURES:%s\n", yesno(opt->use_mouse_gestures));
fprintf(f, "RO_TEXT_SELECTION:%s\n", yesno(opt->allow_text_selection));
fprintf(f, "RO_FORM_ELEMENTS:%s\n", yesno(opt->use_riscos_elements));
fprintf(f, "RO_SHOW_TOOLBAR:%s\n", yesno(opt->show_toolbar));
fprintf(f, "RO_SHOW_PRINT:%s\n", yesno(opt->show_print_preview));
fprintf(f, "\n# Theme\n");
fprintf(f, "RO_THEME:%s\n", opt->theme);
}
else
LOG(("Couldn't open Choices file"));
fclose(f);
xfree(fn);
}
void options_init(struct options* opt)
{
opt->http = 0;
opt->http_proxy = strdup("");
opt->http_port = 8080;
opt->use_mouse_gestures = 0;
opt->allow_text_selection = 1;
opt->use_riscos_elements = 1;
opt->show_toolbar = 1;
opt->show_print_preview = 0;
opt->theme = strdup("Default");
}
void options_read(struct options* opt, char* filename)
{
messagetrans_control_block cb;
messagetrans_file_flags flags;
char* data;
char* fn;
int size;
fn = xcalloc(20 + (filename == 0 ? 7 : strlen(filename)), sizeof(char));
sprintf(fn, "Choices:WWW.NetSurf.%s", filename == 0 ? "Choices" : filename);
LOG(("Getting file info"));
if (xmessagetrans_file_info(fn, &flags, &size) != NULL)
return;
/* catch empty choices file - this is a kludge but should work */
if (size <= 10) {
LOG(("Empty Choices file - using defaults"));
options_init(opt);
return;
}
LOG(("Allocating %d bytes", size));
data = xcalloc((unsigned int)size, sizeof(char));
messagetrans_open_file(&cb, fn, data);
opt->http = lookup_yesno(&cb, "USE_HTTP", "N");
xfree(opt->http_proxy);
opt->http_proxy = lookup(&cb, "HTTP_PROXY", "");
opt->http_port = lookup_i(&cb, "HTTP_PORT", "8080");
opt->use_mouse_gestures = lookup_yesno(&cb, "RO_MOUSE_GESTURES", "N");
opt->allow_text_selection = lookup_yesno(&cb, "RO_TEXT_SELECTION", "Y");
opt->use_riscos_elements = lookup_yesno(&cb, "RO_FORM_ELEMENTS", "Y");
opt->show_toolbar = lookup_yesno(&cb, "RO_SHOW_TOOLBAR", "Y");
opt->show_print_preview = lookup_yesno(&cb, "RO_SHOW_PRINT", "N");
xfree(opt->theme);
opt->theme = lookup(&cb, "RO_THEME", "Default");
messagetrans_close_file(&cb);
xfree(data);
xfree(fn);
}
void options_to_ro(struct options* opt, struct ro_choices* ro)
{
ro->browser.use_mouse_gestures = opt->use_mouse_gestures;
ro->browser.allow_text_selection = opt->allow_text_selection;
ro->browser.use_riscos_elements = opt->use_riscos_elements;
ro->browser.show_toolbar = opt->show_toolbar;
ro->browser.show_print_preview = opt->show_print_preview;
ro->proxy.http = opt->http;
if (opt->http_proxy != NULL)
strcpy(ro->proxy.http_proxy, opt->http_proxy);
else
strcpy(ro->proxy.http_proxy, "");
ro->proxy.http_port = opt->http_port;
if (opt->theme != NULL)
strcpy(ro->theme.name, opt->theme);
else
strcpy(ro->theme.name, "Default");
}
void ro_to_options(struct ro_choices* ro, struct options* opt)
{
opt->use_mouse_gestures = ro->browser.use_mouse_gestures;
opt->allow_text_selection = ro->browser.allow_text_selection;
opt->use_riscos_elements = ro->browser.use_riscos_elements;
opt->show_toolbar = ro->browser.show_toolbar;
opt->show_print_preview = ro->browser.show_print_preview;
opt->http = ro->proxy.http;
xfree(opt->http_proxy);
opt->http_proxy = strdup(ro->proxy.http_proxy);
opt->http_port = ro->proxy.http_port;
xfree(opt->theme);
opt->theme = strdup(ro->theme.name);
}

View File

@ -3,6 +3,11 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
*/
/** \file
* RISC OS specific options.
*/
#ifndef _NETSURF_RISCOS_OPTIONS_H_
@ -10,48 +15,21 @@
#include "netsurf/desktop/options.h"
#define PLATFORM_OPTIONS \
int use_mouse_gestures;\
int allow_text_selection;\
int use_riscos_elements;\
int show_toolbar;\
int show_print_preview;\
\
char* theme;
extern int option_use_mouse_gestures;
extern int option_allow_text_selection;
extern int option_show_toolbar;
extern char *option_theme;
/* choices made easier for the dialogue boxes. only used by the interface */
#define EXTRA_OPTION_DEFINE \
int option_use_mouse_gestures = false;\
int option_allow_text_selection = true;\
int option_show_toolbar = true;\
char *option_theme = 0;
struct browser_choices
{
int use_mouse_gestures;
int allow_text_selection;
int use_riscos_elements;
int show_toolbar;
int show_print_preview;
} ;
struct proxy_choices
{
int http;
char http_proxy[256];
int http_port;
} ;
struct theme_choices
{
char name[256];
};
struct ro_choices
{
struct browser_choices browser;
struct proxy_choices proxy;
struct theme_choices theme;
};
void options_to_ro(struct options* opt, struct ro_choices* ro);
void ro_to_options(struct ro_choices* ro, struct options* opt);
#define EXTRA_OPTION_TABLE \
{ "use_mouse_gestures", OPTION_BOOL, &option_use_mouse_gestures },\
{ "allow_text_selection", OPTION_BOOL, &option_allow_text_selection },\
{ "show_toolbar", OPTION_BOOL, &option_show_toolbar },\
{ "theme", OPTION_STRING, &option_theme }
#endif