summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2004-11-07 19:19:11 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2004-11-07 19:19:11 +0000
commit5e41fb8a121c441a8765a1962a892e93906cde83 (patch)
tree0fd0a6aa6adbd7275b7a2fd9216d1e063a968ad0 /desktop
downloadnstheme-5e41fb8a121c441a8765a1962a892e93906cde83.tar.gz
nstheme-5e41fb8a121c441a8765a1962a892e93906cde83.tar.bz2
[project @ 2004-11-07 19:19:11 by rjw]
Initial import. svn path=/import/nstheme/; revision=2436
Diffstat (limited to 'desktop')
-rw-r--r--desktop/gui.h22
-rw-r--r--desktop/nstheme.c44
-rw-r--r--desktop/nstheme.h16
-rw-r--r--desktop/options.c149
-rw-r--r--desktop/options.h46
5 files changed, 277 insertions, 0 deletions
diff --git a/desktop/gui.h b/desktop/gui.h
new file mode 100644
index 0000000..f4069c1
--- /dev/null
+++ b/desktop/gui.h
@@ -0,0 +1,22 @@
+/*
+ * 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 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
+ */
+
+/** \file
+ * Interface to platform-specific gui functions.
+ */
+
+#ifndef _NSTHEME_DESKTOP_GUI_H_
+#define _NSTHEME_DESKTOP_GUI_H_
+
+#include <stdbool.h>
+
+void gui_init(void);
+void gui_multitask(void);
+void gui_poll(void);
+void gui_exit(void);
+
+#endif
diff --git a/desktop/nstheme.c b/desktop/nstheme.c
new file mode 100644
index 0000000..d4e5a19
--- /dev/null
+++ b/desktop/nstheme.c
@@ -0,0 +1,44 @@
+/*
+ * 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 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
+ */
+
+#include <stdbool.h>
+#include "nstheme/desktop/gui.h"
+#include "nstheme/desktop/nstheme.h"
+#include "nstheme/utils/utils.h"
+
+bool application_quit = false;
+
+static void application_init(void);
+static void application_exit(void);
+
+
+/**
+ * NSTheme main().
+ */
+int main(int argc, char** argv) {
+ application_init();
+ while (!application_quit) gui_poll();
+ application_exit();
+ return EXIT_SUCCESS;
+}
+
+
+/**
+ * Initialise application.
+ */
+void application_init(void) {
+ stdout = stderr;
+ gui_init();
+}
+
+
+/**
+ * Finalise application.
+ */
+void application_exit(void) {
+ gui_exit();
+}
diff --git a/desktop/nstheme.h b/desktop/nstheme.h
new file mode 100644
index 0000000..fab28d3
--- /dev/null
+++ b/desktop/nstheme.h
@@ -0,0 +1,16 @@
+/*
+ * 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 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
+ */
+
+#ifndef _NSTHEME_DESKTOP_NSTHEME_H_
+#define _NSTHEME_DESKTOP_NSTHEME_H_
+
+#include <stdbool.h>
+
+extern bool application_quit;
+
+#endif
+
diff --git a/desktop/options.c b/desktop/options.c
new file mode 100644
index 0000000..b43291b
--- /dev/null
+++ b/desktop/options.c
@@ -0,0 +1,149 @@
+/*
+ * 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>
+ * Copyright 2004 Richard Wilson <not_ginger_matt@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 "nstheme/desktop/options.h"
+#include "nstheme/utils/log.h"
+#include "nstheme/utils/utils.h"
+
+#ifdef riscos
+#include "nstheme/riscos/options.h"
+#else
+#define EXTRA_OPTION_DEFINE
+#define EXTRA_OPTION_TABLE
+#endif
+
+
+EXTRA_OPTION_DEFINE
+
+
+struct {
+ const char *key;
+ enum { OPTION_BOOL, OPTION_INTEGER, OPTION_STRING } type;
+ void *p;
+} option_table[] = {
+ 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);
+}
diff --git a/desktop/options.h b/desktop/options.h
new file mode 100644
index 0000000..ae35cda
--- /dev/null
+++ b/desktop/options.h
@@ -0,0 +1,46 @@
+/*
+ * 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 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_
+
+enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, OPTION_HTTP_PROXY_AUTH_BASIC = 1,
+ OPTION_HTTP_PROXY_AUTH_NTLM = 2 };
+
+extern bool option_http_proxy;
+extern char *option_http_proxy_host;
+extern int option_http_proxy_port;
+extern int option_http_proxy_auth;
+extern char *option_http_proxy_auth_user;
+extern char *option_http_proxy_auth_pass;
+extern int option_font_size;
+extern int option_font_min_size;
+extern char *option_accept_language;
+extern bool option_ssl_verify_certificates;
+extern int option_memory_cache_size;
+extern bool option_block_ads;
+
+void options_read(const char *path);
+void options_write(const char *path);
+
+#endif