2004-02-13 19:09:12 +03:00
|
|
|
/*
|
|
|
|
* 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>
|
2005-12-01 05:59:55 +03:00
|
|
|
* Copyright 2005 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2004-02-13 19:09:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \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".
|
|
|
|
*/
|
|
|
|
|
2004-12-09 13:30:44 +03:00
|
|
|
#include <assert.h>
|
2004-02-13 19:09:12 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include <libxml/HTMLparser.h>
|
|
|
|
#include <libxml/HTMLtree.h>
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "desktop/tree.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2004-02-13 19:09:12 +03:00
|
|
|
|
2006-07-24 02:32:33 +04:00
|
|
|
#if defined(riscos)
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/options.h"
|
2006-07-24 02:32:33 +04:00
|
|
|
#elif defined(nsgtk)
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "gtk/options.h"
|
2004-02-13 19:09:12 +03:00
|
|
|
#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;
|
2004-07-27 19:49:28 +04:00
|
|
|
/** Proxy authentication method. */
|
|
|
|
int option_http_proxy_auth = OPTION_HTTP_PROXY_AUTH_NONE;
|
|
|
|
/** Proxy authentication user name */
|
|
|
|
char *option_http_proxy_auth_user = 0;
|
|
|
|
/** Proxy authentication password */
|
|
|
|
char *option_http_proxy_auth_pass = 0;
|
2004-02-14 02:07:42 +03:00
|
|
|
/** Default font size / 0.1pt. */
|
2007-12-09 14:13:25 +03:00
|
|
|
int option_font_size = 128;
|
2004-02-14 02:07:42 +03:00
|
|
|
/** Minimum font size. */
|
2007-12-09 14:13:25 +03:00
|
|
|
int option_font_min_size = 85;
|
2006-03-31 14:41:21 +04:00
|
|
|
/** Default sans serif font */
|
|
|
|
char *option_font_sans;
|
|
|
|
/** Default serif font */
|
|
|
|
char *option_font_serif;
|
|
|
|
/** Default monospace font */
|
|
|
|
char *option_font_mono;
|
|
|
|
/** Default cursive font */
|
|
|
|
char *option_font_cursive;
|
|
|
|
/** Default fantasy font */
|
|
|
|
char *option_font_fantasy;
|
2004-03-08 03:03:58 +03:00
|
|
|
/** Accept-Language header. */
|
|
|
|
char *option_accept_language = 0;
|
2006-12-28 03:42:14 +03:00
|
|
|
/** Accept-Charset header. */
|
|
|
|
char *option_accept_charset = 0;
|
2004-06-21 19:09:59 +04:00
|
|
|
/** Preferred maximum size of memory cache / bytes. */
|
|
|
|
int option_memory_cache_size = 2 * 1024 * 1024;
|
2006-01-07 03:39:14 +03:00
|
|
|
/** Preferred expiry age of disc cache / days. */
|
|
|
|
int option_disc_cache_age = 28;
|
2004-07-31 03:40:01 +04:00
|
|
|
/** Whether to block advertisements */
|
|
|
|
bool option_block_ads = false;
|
2004-10-05 03:54:42 +04:00
|
|
|
/** Minimum GIF animation delay */
|
|
|
|
int option_minimum_gif_delay = 10;
|
2004-10-02 01:31:55 +04:00
|
|
|
/** Whether to send the referer HTTP header */
|
|
|
|
bool option_send_referer = true;
|
2004-12-09 13:30:44 +03:00
|
|
|
/** Whether to animate images */
|
|
|
|
bool option_animate_images = true;
|
2005-12-30 02:18:17 +03:00
|
|
|
/** How many days to retain URL data for */
|
|
|
|
int option_expire_url = 28;
|
2006-01-03 02:31:29 +03:00
|
|
|
/** Default font family */
|
|
|
|
int option_font_default = CSS_FONT_FAMILY_SANS_SERIF;
|
2006-01-08 04:51:33 +03:00
|
|
|
/** ca-bundle location */
|
|
|
|
char *option_ca_bundle = 0;
|
2007-06-27 19:39:56 +04:00
|
|
|
/** ca-path location */
|
|
|
|
char *option_ca_path = 0;
|
2006-01-08 04:51:33 +03:00
|
|
|
/** Cookie file location */
|
|
|
|
char *option_cookie_file = 0;
|
|
|
|
/** Cookie jar loaction */
|
|
|
|
char *option_cookie_jar = 0;
|
2006-03-29 19:26:54 +04:00
|
|
|
/** Home page location */
|
|
|
|
char *option_homepage_url = 0;
|
2006-07-28 19:52:37 +04:00
|
|
|
/** URL completion in url bar */
|
|
|
|
bool option_url_suggestion = true;
|
2006-08-29 04:17:35 +04:00
|
|
|
/** default x position of new windows */
|
|
|
|
int option_window_x = 0;
|
|
|
|
/** default y position of new windows */
|
|
|
|
int option_window_y = 0;
|
|
|
|
/** default width of new windows */
|
|
|
|
int option_window_width = 0;
|
|
|
|
/** default height of new windows */
|
|
|
|
int option_window_height = 0;
|
|
|
|
/** width of screen when above options were saved */
|
|
|
|
int option_window_screen_width = 0;
|
|
|
|
/** height of screen when above options were saved */
|
|
|
|
int option_window_screen_height = 0;
|
|
|
|
/** default size of status bar vs. h scroll bar */
|
|
|
|
#ifdef nsgtk
|
2006-08-29 04:42:30 +04:00
|
|
|
int option_toolbar_status_width = 400;
|
2006-08-29 04:17:35 +04:00
|
|
|
#else
|
|
|
|
int option_toolbar_status_width = 6667;
|
|
|
|
#endif
|
2007-08-07 07:55:18 +04:00
|
|
|
/** default window scale */
|
|
|
|
int option_scale = 100;
|
2008-03-01 02:03:26 +03:00
|
|
|
/* Whether to reflow web pages while objects are fetching */
|
|
|
|
bool option_incremental_reflow = true;
|
|
|
|
/* Minimum time between HTML reflows while objects are fetching */
|
|
|
|
#ifdef riscos
|
2008-03-11 03:14:39 +03:00
|
|
|
unsigned int option_min_reflow_period = 100; /* time in cs */
|
2008-03-01 02:03:26 +03:00
|
|
|
#else
|
2008-03-11 03:14:39 +03:00
|
|
|
unsigned int option_min_reflow_period = 25; /* time in cs */
|
2008-03-01 02:03:26 +03:00
|
|
|
#endif
|
2006-08-29 04:17:35 +04:00
|
|
|
|
2006-03-14 17:21:01 +03:00
|
|
|
/* Fetcher configuration */
|
|
|
|
/** Maximum simultaneous active fetchers */
|
|
|
|
int option_max_fetchers = 24;
|
|
|
|
/** Maximum simultaneous active fetchers per host.
|
2008-07-18 13:52:18 +04:00
|
|
|
* (<=option_max_fetchers else it makes no sense)
|
|
|
|
* Note that rfc2616 section 8.1.4 says that there should be no more than
|
|
|
|
* two keepalive connections per host. None of the main browsers follow this
|
|
|
|
* as it slows page fetches down considerably.
|
|
|
|
* See https://bugzilla.mozilla.org/show_bug.cgi?id=423377#c4
|
2006-03-14 17:21:01 +03:00
|
|
|
*/
|
2008-07-18 13:52:18 +04:00
|
|
|
int option_max_fetchers_per_host = 5;
|
2006-03-14 17:21:01 +03:00
|
|
|
/** Maximum number of inactive fetchers cached.
|
|
|
|
* The total number of handles netsurf will therefore have open
|
|
|
|
* is this plus option_max_fetchers.
|
|
|
|
*/
|
|
|
|
int option_max_cached_fetch_handles = 6;
|
2007-06-27 20:27:52 +04:00
|
|
|
/** Suppress debug output from cURL. */
|
|
|
|
bool option_suppress_curl_debug = true;
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/** Whether to allow target="_blank" */
|
|
|
|
bool option_target_blank = true;
|
2006-03-14 17:21:01 +03:00
|
|
|
|
2004-02-13 19:09:12 +03:00
|
|
|
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 },
|
Merged revisions 4114-4265,4267-4272,4275-4285,4287-4325 via svnmerge from
svn://source.netsurf-browser.org/branches/mikeL/netsurf
........
r4116 | mikeL | 2008-05-01 22:15:12 +0100 (Thu, 01 May 2008) | 2 lines
Redesigned right-click menu: added back, forward, and reload, previously default menu items are now hidden unless view->toolbars->menu bar is disabled
........
r4117 | mikeL | 2008-05-02 03:54:10 +0100 (Fri, 02 May 2008) | 2 lines
Added a Current Page button to Preferences next to the url entry for setting the home page
........
r4118 | mikeL | 2008-05-02 04:27:37 +0100 (Fri, 02 May 2008) | 1 line
Cleanup
........
r4119 | mikeL | 2008-05-02 21:09:44 +0100 (Fri, 02 May 2008) | 1 line
Preferences window is now initialized the first time edit->preferences is clicked instead of during nsgtk initialization. Expedites start-up time because preferences is a non-essential dialog.
........
r4123 | mikeL | 2008-05-04 15:43:20 +0100 (Sun, 04 May 2008) | 1 line
Converted Preferences window to a dialog. Fixed spacing and naming in Preferences dialog. Split Preferences section of the Glade file into its own gtk_options.glade file. Moved all Preferences related files to gtk/dialogs.
........
r4127 | mikeL | 2008-05-05 20:45:44 +0100 (Mon, 05 May 2008) | 1 line
Fixed a glaring error in directory structure. All glade files are now stored in the res directory.
........
r4128 | mikeL | 2008-05-05 20:52:08 +0100 (Mon, 05 May 2008) | 1 line
Added directory 'dialogs' to revision control
........
r4129 | mikeL | 2008-05-05 20:58:53 +0100 (Mon, 05 May 2008) | 1 line
Cleaned up gtk folder by removing gtk_options.c and gtk_options.h (Moved to dialogs folder)
........
r4130 | mikeL | 2008-05-05 23:42:15 +0100 (Mon, 05 May 2008) | 1 line
Huzzah\! Preferences dialog is now instant apply\!
........
r4131 | mikeL | 2008-05-06 20:43:26 +0100 (Tue, 06 May 2008) | 1 line
nsgtk_reflow_all_windows() is now called whenever an option that requires redrawing of the current page is changed. Preferences dialog is now *completely* instant apply
........
r4132 | mikeL | 2008-05-06 20:55:05 +0100 (Tue, 06 May 2008) | 1 line
Renamed macros to better reflect their purpose
........
r4133 | mikeL | 2008-05-06 21:30:44 +0100 (Tue, 06 May 2008) | 1 line
Added gtk/res/options.glade to svn control
........
r4134 | mikeL | 2008-05-06 21:39:12 +0100 (Tue, 06 May 2008) | 1 line
Preferences window is now resizable
........
r4135 | mikeL | 2008-05-06 21:42:00 +0100 (Tue, 06 May 2008) | 1 line
Fixed reload menu item in popup menu
........
r4136 | mikeL | 2008-05-07 00:24:35 +0100 (Wed, 07 May 2008) | 1 line
Proxy configurations are now insensitive if proxy type is set to no proxy. Changing the home page with the Current Page button is now saved. Moved Current Page button in Preferences window and added Default Page.
........
r4137 | mikeL | 2008-05-07 00:41:29 +0100 (Wed, 07 May 2008) | 1 line
Solved a problem with all options being saved prematurely on initialization
........
r4145 | mikeL | 2008-05-11 18:07:06 +0100 (Sun, 11 May 2008) | 1 line
Optimized prefences window signal handling, entry signals are now caught on focus-out-event and checked for changes
........
r4146 | mikeL | 2008-05-11 18:16:04 +0100 (Sun, 11 May 2008) | 1 line
Fixed regression where 'Set Current Page' button stopped working
........
r4147 | mikeL | 2008-05-11 18:32:10 +0100 (Sun, 11 May 2008) | 1 line
Added 'Default Page' button functionality
........
r4148 | mikeL | 2008-05-11 18:33:03 +0100 (Sun, 11 May 2008) | 1 line
Updated TODO list
........
r4149 | mikeL | 2008-05-12 01:04:00 +0100 (Mon, 12 May 2008) | 1 line
Added 'Hide Advertisement' functionality
........
r4150 | mikeL | 2008-05-12 01:30:40 +0100 (Mon, 12 May 2008) | 1 line
Re-activated the option 'Disable Animation' and fixed bug where it would actually enable animation
........
r4151 | mikeL | 2008-05-12 01:42:43 +0100 (Mon, 12 May 2008) | 1 line
Added 'Send site referral information' functionality
........
r4152 | mikeL | 2008-05-12 02:01:00 +0100 (Mon, 12 May 2008) | 1 line
Added 'Disc cache age' functionality
........
r4154 | mikeL | 2008-05-13 20:35:29 +0100 (Tue, 13 May 2008) | 1 line
Fixed regression where preferences were not written to file in some cases and preferences dialog could not be reopened.
........
r4158 | mikeL | 2008-05-14 21:57:50 +0100 (Wed, 14 May 2008) | 1 line
Added 'preview' button to fonts tab of preferences dialog. nsgtk_reflow_all_windows is now called only when that button is clicked.
........
r4162 | mikeL | 2008-05-15 20:09:30 +0100 (Thu, 15 May 2008) | 1 line
Possible fix to segfault due to invalid test
........
r4163 | mikeL | 2008-05-15 20:25:28 +0100 (Thu, 15 May 2008) | 1 line
Fixed typo that caused preferences dialog to be unopenable
........
r4164 | mikeL | 2008-05-15 20:57:49 +0100 (Thu, 15 May 2008) | 1 line
Added initialization statement for preferences_dialog to make sure that
........
r4169 | mikeL | 2008-05-17 00:30:54 +0100 (Sat, 17 May 2008) | 1 line
Added a 'parent_window' initialization parameter to the preferences dialog so that it may center itself on parent. This also optimizes the closing code as destroy is now called on the dialog when the main window is closed
........
r4174 | mikeL | 2008-05-18 15:46:43 +0100 (Sun, 18 May 2008) | 1 line
Animation speed option is now insensitive when 'Disable animations' is true
........
r4175 | mikeL | 2008-05-18 15:50:06 +0100 (Sun, 18 May 2008) | 1 line
Added tooltip to preview button
........
r4176 | mikeL | 2008-05-18 16:04:05 +0100 (Sun, 18 May 2008) | 1 line
Animation speed is now always sensitive
........
r4177 | mikeL | 2008-05-19 02:32:21 +0100 (Mon, 19 May 2008) | 1 line
Redesigned about dialog as a GtkAboutDialog and removed the respective section from netsurf.glade (May need string revision)
........
r4178 | mikeL | 2008-05-19 02:36:15 +0100 (Mon, 19 May 2008) | 1 line
Fixed compile warning relating to improper cast of netsurf_version
........
r4180 | mikeL | 2008-05-19 21:42:04 +0100 (Mon, 19 May 2008) | 1 line
Updated credits
........
r4181 | mikeL | 2008-05-19 21:43:16 +0100 (Mon, 19 May 2008) | 1 line
launch_url is no longer static
........
r4182 | mikeL | 2008-05-19 21:50:03 +0100 (Mon, 19 May 2008) | 1 line
netsurf_version is now const in function which addresses jmb's concern
........
r4183 | mikeL | 2008-05-19 21:59:55 +0100 (Mon, 19 May 2008) | 1 line
Updated header
........
r4184 | mikeL | 2008-05-19 22:03:28 +0100 (Mon, 19 May 2008) | 1 line
local variables are now static
........
r4186 | mikeL | 2008-05-21 22:03:43 +0100 (Wed, 21 May 2008) | 1 line
Removed 'Main Development Team' from the beginning of all credits
........
r4219 | mikeL | 2008-05-28 18:17:12 +0100 (Wed, 28 May 2008) | 1 line
Removed wndOpenFile from glade file.
........
r4236 | mikeL | 2008-05-31 23:25:32 +0100 (Sat, 31 May 2008) | 1 line
Fixed proxy options for both riscos and gtk versions thanks to a tip from Leon Stringer
........
r4275 | mikeL | 2008-06-06 17:16:29 +0100 (Fri, 06 Jun 2008) | 1 line
Added support for dragging, clicks are now emited on button release
........
r4276 | mikeL | 2008-06-06 17:18:18 +0100 (Fri, 06 Jun 2008) | 1 line
gtk_window.c now sets the current_redraw_browser. Text selection now highlights properly
........
r4277 | mikeL | 2008-06-06 17:47:35 +0100 (Fri, 06 Jun 2008) | 1 line
Cleaned up the button detection code
........
r4278 | mikeL | 2008-06-06 17:58:51 +0100 (Fri, 06 Jun 2008) | 1 line
Removed leftover variables
........
r4279 | mikeL | 2008-06-06 18:13:58 +0100 (Fri, 06 Jun 2008) | 1 line
Enabled 'Select All'
........
r4280 | mikeL | 2008-06-06 18:31:56 +0100 (Fri, 06 Jun 2008) | 1 line
Fixed bug where mouse state would always remain as PRESS even if dragging
........
r4281 | mikeL | 2008-06-06 18:45:16 +0100 (Fri, 06 Jun 2008) | 1 line
Fixed regression where mouse state was cleared improperly
........
r4287 | mikeL | 2008-06-07 00:21:32 +0100 (Sat, 07 Jun 2008) | 1 line
Mouse code can now handle modifiers. Fixed bug where end of drag was not detected until mouse moved after being released. Improved mouse handling.
........
r4294 | mikeL | 2008-06-07 03:21:03 +0100 (Sat, 07 Jun 2008) | 1 line
Added ability to handle modifiers pressed during a drag event. Mouse movement handling now uses switch statements (Thanks tlsa)
........
r4295 | mikeL | 2008-06-07 03:40:11 +0100 (Sat, 07 Jun 2008) | 1 line
Fixed bug where modifier keys were being detected incorrectly
........
r4296 | mikeL | 2008-06-07 03:42:31 +0100 (Sat, 07 Jun 2008) | 1 line
Reversed accidental file modification
........
r4299 | mikeL | 2008-06-07 21:32:15 +0100 (Sat, 07 Jun 2008) | 1 line
Fixed inclusion of gtk_about source file instead of header
........
r4300 | mikeL | 2008-06-07 22:27:39 +0100 (Sat, 07 Jun 2008) | 1 line
Fixed problem with about.h not linking properly.
........
r4301 | mikeL | 2008-06-07 22:37:28 +0100 (Sat, 07 Jun 2008) | 1 line
Moved definitions of gui_window and browser_mouse to gtk_window.h. Moved all selection related functions to gtk_selection.c. Implemented copy functionality.
........
r4302 | mikeL | 2008-06-07 22:48:18 +0100 (Sat, 07 Jun 2008) | 1 line
Implemented paste functionality
........
r4303 | mikeL | 2008-06-07 22:48:40 +0100 (Sat, 07 Jun 2008) | 1 line
Removed old test case
........
r4304 | mikeL | 2008-06-07 22:53:56 +0100 (Sat, 07 Jun 2008) | 1 line
Fixed bug where click would be sent at the end of a button 2 drag (Thanks tlsa)
........
r4305 | mikeL | 2008-06-07 23:48:01 +0100 (Sat, 07 Jun 2008) | 1 line
Prevented gui_copy_to_clipboard from overwriting clipboard with a NULL string.
........
r4306 | mikeL | 2008-06-08 00:00:55 +0100 (Sun, 08 Jun 2008) | 1 line
Fixed regression where the state of the modifier keys would alternate as the mouse moved. Fixed bug that prevented drags from being registered if a modifier key was pressed
........
r4308 | mikeL | 2008-06-08 00:53:26 +0100 (Sun, 08 Jun 2008) | 1 line
Changed 'Select All' menu item to stock
........
r4314 | mikeL | 2008-06-09 19:09:23 +0100 (Mon, 09 Jun 2008) | 1 line
Added function nsgtk_scaffolding_set_sensitive
........
r4315 | mikeL | 2008-06-09 19:14:14 +0100 (Mon, 09 Jun 2008) | 1 line
Added function nsgtk_scaffolding_set_sensitive
........
r4316 | mikeL | 2008-06-09 19:20:16 +0100 (Mon, 09 Jun 2008) | 1 line
Removed option 'Use Cairo for anti-aliased rendering'
........
r4317 | mikeL | 2008-06-09 20:10:55 +0100 (Mon, 09 Jun 2008) | 1 line
Fixed bug where text would be selected in all windows instead of only the active one
........
r4318 | mikeL | 2008-06-09 20:29:42 +0100 (Mon, 09 Jun 2008) | 1 line
(Drastically) Improved redraw handling. (Thanks jmb)
........
r4319 | mikeL | 2008-06-09 21:10:17 +0100 (Mon, 09 Jun 2008) | 1 line
Removed old test case
........
r4320 | mikeL | 2008-06-10 07:27:32 +0100 (Tue, 10 Jun 2008) | 1 line
Implemented (almost) the rest of the clipboard functionality. Clipboard functions now handle the url bar correctly. Clipboard menu items are now appropriately sensitive.
........
r4321 | mikeL | 2008-06-10 19:08:05 +0100 (Tue, 10 Jun 2008) | 1 line
Added clipboard functions to contextual right click menu
........
r4323 | mikeL | 2008-06-10 23:57:43 +0100 (Tue, 10 Jun 2008) | 1 line
Fixed regression where modifiers key states would be cleared on button release. Modifier keys are now set only on button press and can only be removed during motion or upon release. Fixed spacing (thanks tlsa)
........
svn path=/trunk/netsurf/; revision=4326
2008-06-11 14:57:44 +04:00
|
|
|
{ "http_proxy_auth", OPTION_INTEGER, &option_http_proxy_auth },
|
2004-07-27 19:49:28 +04:00
|
|
|
{ "http_proxy_auth_user", OPTION_STRING, &option_http_proxy_auth_user },
|
|
|
|
{ "http_proxy_auth_pass", OPTION_STRING, &option_http_proxy_auth_pass },
|
2004-02-14 02:07:42 +03:00
|
|
|
{ "font_size", OPTION_INTEGER, &option_font_size },
|
|
|
|
{ "font_min_size", OPTION_INTEGER, &option_font_min_size },
|
2006-03-31 14:41:21 +04:00
|
|
|
{ "font_sans", OPTION_STRING, &option_font_sans },
|
|
|
|
{ "font_serif", OPTION_STRING, &option_font_serif },
|
|
|
|
{ "font_mono", OPTION_STRING, &option_font_mono },
|
|
|
|
{ "font_cursive", OPTION_STRING, &option_font_cursive },
|
|
|
|
{ "font_fantasy", OPTION_STRING, &option_font_fantasy },
|
2004-03-08 03:03:58 +03:00
|
|
|
{ "accept_language", OPTION_STRING, &option_accept_language },
|
2006-12-28 03:42:14 +03:00
|
|
|
{ "accept_charset", OPTION_STRING, &option_accept_charset },
|
2004-06-21 19:22:05 +04:00
|
|
|
{ "memory_cache_size", OPTION_INTEGER, &option_memory_cache_size },
|
2006-01-07 03:39:14 +03:00
|
|
|
{ "disc_cache_age", OPTION_INTEGER, &option_disc_cache_age },
|
2004-07-31 03:40:01 +04:00
|
|
|
{ "block_advertisements", OPTION_BOOL, &option_block_ads },
|
2004-10-05 03:54:42 +04:00
|
|
|
{ "minimum_gif_delay", OPTION_INTEGER, &option_minimum_gif_delay },
|
2004-10-02 01:31:55 +04:00
|
|
|
{ "send_referer", OPTION_BOOL, &option_send_referer },
|
2005-12-30 02:18:17 +03:00
|
|
|
{ "animate_images", OPTION_BOOL, &option_animate_images },
|
2006-01-08 04:51:33 +03:00
|
|
|
{ "expire_url", OPTION_INTEGER, &option_expire_url },
|
|
|
|
{ "font_default", OPTION_INTEGER, &option_font_default },
|
|
|
|
{ "ca_bundle", OPTION_STRING, &option_ca_bundle },
|
2007-06-27 19:39:56 +04:00
|
|
|
{ "ca_path", OPTION_STRING, &option_ca_path },
|
2006-01-08 04:51:33 +03:00
|
|
|
{ "cookie_file", OPTION_STRING, &option_cookie_file },
|
|
|
|
{ "cookie_jar", OPTION_STRING, &option_cookie_jar },
|
2006-03-29 19:26:54 +04:00
|
|
|
{ "homepage_url", OPTION_STRING, &option_homepage_url },
|
2006-07-28 19:52:37 +04:00
|
|
|
{ "url_suggestion", OPTION_BOOL, &option_url_suggestion },
|
2007-08-07 07:55:18 +04:00
|
|
|
{ "window_x", OPTION_INTEGER, &option_window_x },
|
|
|
|
{ "window_y", OPTION_INTEGER, &option_window_y },
|
|
|
|
{ "window_width", OPTION_INTEGER, &option_window_width },
|
|
|
|
{ "window_height", OPTION_INTEGER, &option_window_height },
|
|
|
|
{ "window_screen_width", OPTION_INTEGER, &option_window_screen_width },
|
|
|
|
{ "window_screen_height",OPTION_INTEGER, &option_window_screen_height },
|
|
|
|
{ "toolbar_status_size", OPTION_INTEGER, &option_toolbar_status_width },
|
2007-08-13 15:36:25 +04:00
|
|
|
{ "scale", OPTION_INTEGER, &option_scale },
|
2008-03-01 02:03:26 +03:00
|
|
|
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
|
|
|
|
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
|
2006-03-14 17:21:01 +03:00
|
|
|
/* Fetcher options */
|
|
|
|
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
|
|
|
|
{ "max_fetchers_per_host",
|
|
|
|
OPTION_INTEGER, &option_max_fetchers_per_host },
|
|
|
|
{ "max_cached_fetch_handles",
|
|
|
|
OPTION_INTEGER, &option_max_cached_fetch_handles },
|
2007-06-27 20:27:52 +04:00
|
|
|
{ "suppress_curl_debug", OPTION_BOOL, &option_suppress_curl_debug },
|
2006-09-02 19:52:41 +04:00
|
|
|
{ "target_blank",
|
|
|
|
OPTION_BOOL, &option_target_blank },
|
2004-02-13 19:09:12 +03:00
|
|
|
EXTRA_OPTION_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
#define option_table_entries (sizeof option_table / sizeof option_table[0])
|
|
|
|
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
static void options_load_tree_directory(xmlNode *ul, struct node *directory);
|
|
|
|
static void options_load_tree_entry(xmlNode *li, struct node *directory);
|
|
|
|
xmlNode *options_find_tree_element(xmlNode *node, const char *name);
|
|
|
|
bool options_save_tree_directory(struct node *directory, xmlNode *node);
|
|
|
|
bool options_save_tree_entry(struct node *entry, xmlNode *node);
|
2004-12-09 13:30:44 +03:00
|
|
|
|
|
|
|
|
2004-02-13 19:09:12 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
2004-02-14 02:07:42 +03:00
|
|
|
|
|
|
|
if (option_font_size < 50)
|
|
|
|
option_font_size = 50;
|
|
|
|
if (1000 < option_font_size)
|
|
|
|
option_font_size = 1000;
|
|
|
|
if (option_font_min_size < 10)
|
|
|
|
option_font_min_size = 10;
|
|
|
|
if (500 < option_font_min_size)
|
|
|
|
option_font_min_size = 500;
|
2004-06-21 19:09:59 +04:00
|
|
|
|
|
|
|
if (option_memory_cache_size < 0)
|
|
|
|
option_memory_cache_size = 0;
|
2004-02-13 19:09:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2006-01-01 21:52:30 +03:00
|
|
|
/**
|
|
|
|
* Dump user options to stderr
|
|
|
|
*/
|
|
|
|
void options_dump(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i != option_table_entries; i++) {
|
|
|
|
fprintf(stderr, "%s:", option_table[i].key);
|
|
|
|
switch (option_table[i].type) {
|
|
|
|
case OPTION_BOOL:
|
|
|
|
fprintf(stderr, "%c",
|
|
|
|
*((bool *) option_table[i].p) ?
|
|
|
|
'1' : '0');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_INTEGER:
|
|
|
|
fprintf(stderr, "%i",
|
|
|
|
*((int *) option_table[i].p));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_STRING:
|
|
|
|
if (*((char **) option_table[i].p))
|
|
|
|
fprintf(stderr, "%s",
|
|
|
|
*((char **) option_table[i].p));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a hotlist as a tree from a specified file.
|
|
|
|
*
|
|
|
|
* \param filename name of file to read
|
|
|
|
* \return the hotlist file represented as a tree, or NULL on failure
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
struct tree *options_load_tree(const char *filename) {
|
2004-12-09 13:30:44 +03:00
|
|
|
xmlDoc *doc;
|
|
|
|
xmlNode *html, *body, *ul;
|
|
|
|
struct tree *tree;
|
|
|
|
|
|
|
|
doc = htmlParseFile(filename, "iso-8859-1");
|
|
|
|
if (!doc) {
|
|
|
|
warn_user("HotlistLoadError", messages_get("ParsingFail"));
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-01-01 21:52:30 +03:00
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
html = options_find_tree_element((xmlNode *) doc, "html");
|
|
|
|
body = options_find_tree_element(html, "body");
|
|
|
|
ul = options_find_tree_element(body, "ul");
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!ul) {
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
warn_user("HotlistLoadError",
|
|
|
|
"(<html>...<body>...<ul> not found.)");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tree = calloc(sizeof(struct tree), 1);
|
|
|
|
if (!tree) {
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
tree->root = tree_create_folder_node(NULL, "Root");
|
|
|
|
if (!tree->root) return NULL;
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
options_load_tree_directory(ul, tree->root);
|
2004-12-09 13:30:44 +03:00
|
|
|
tree->root->expanded = true;
|
|
|
|
tree_initialise(tree);
|
|
|
|
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a directory represented as a ul.
|
|
|
|
*
|
|
|
|
* \param ul xmlNode for parsed ul
|
|
|
|
* \param directory directory to add this directory to
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
void options_load_tree_directory(xmlNode *ul, struct node *directory) {
|
2004-12-09 13:30:44 +03:00
|
|
|
char *title;
|
|
|
|
struct node *dir;
|
|
|
|
xmlNode *n;
|
2006-01-01 21:52:30 +03:00
|
|
|
|
2004-12-09 13:30:44 +03:00
|
|
|
assert(ul);
|
|
|
|
assert(directory);
|
|
|
|
|
|
|
|
for (n = ul->children; n; n = n->next) {
|
|
|
|
/* The ul may contain entries as a li, or directories as
|
|
|
|
* an h4 followed by a ul. Non-element nodes may be present
|
|
|
|
* (eg. text, comments), and are ignored. */
|
|
|
|
|
|
|
|
if (n->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcmp((const char *) n->name, "li") == 0) {
|
2004-12-09 13:30:44 +03:00
|
|
|
/* entry */
|
2005-02-07 17:28:43 +03:00
|
|
|
options_load_tree_entry(n, directory);
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
} else if (strcmp((const char *) n->name, "h4") == 0) {
|
2004-12-09 13:30:44 +03:00
|
|
|
/* directory */
|
|
|
|
title = (char *) xmlNodeGetContent(n);
|
|
|
|
if (!title) {
|
|
|
|
warn_user("HotlistLoadError", "(Empty <h4> "
|
|
|
|
"or memory exhausted.)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = n->next;
|
|
|
|
n && n->type != XML_ELEMENT_NODE;
|
|
|
|
n = n->next)
|
|
|
|
;
|
2008-02-25 20:58:00 +03:00
|
|
|
if (!n || strcmp((const char *) n->name, "ul") != 0) {
|
2004-12-09 13:30:44 +03:00
|
|
|
/* next element isn't expected ul */
|
|
|
|
free(title);
|
|
|
|
warn_user("HotlistLoadError", "(Expected "
|
|
|
|
"<ul> not present.)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = tree_create_folder_node(directory, title);
|
|
|
|
if (!dir)
|
|
|
|
return;
|
2005-02-07 17:28:43 +03:00
|
|
|
options_load_tree_directory(n, dir);
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an entry represented as a li.
|
|
|
|
*
|
|
|
|
* \param li xmlNode for parsed li
|
|
|
|
* \param directory directory to add this entry to
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
void options_load_tree_entry(xmlNode *li, struct node *directory) {
|
2004-12-09 13:30:44 +03:00
|
|
|
char *url = 0;
|
|
|
|
char *title = 0;
|
|
|
|
struct node *entry;
|
|
|
|
xmlNode *n;
|
2006-04-10 03:21:13 +04:00
|
|
|
const struct url_data *data;
|
2004-12-09 13:30:44 +03:00
|
|
|
|
|
|
|
for (n = li->children; n; n = n->next) {
|
2005-12-31 07:31:37 +03:00
|
|
|
/* The li must contain an "a" element */
|
2004-12-09 13:30:44 +03:00
|
|
|
if (n->type == XML_ELEMENT_NODE &&
|
2008-02-25 20:58:00 +03:00
|
|
|
strcmp((const char *) n->name, "a") == 0) {
|
2004-12-09 13:30:44 +03:00
|
|
|
url = (char *) xmlGetProp(n, (const xmlChar *) "href");
|
|
|
|
title = (char *) xmlNodeGetContent(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url || !title) {
|
|
|
|
warn_user("HotlistLoadError", "(Missing <a> in <li> or "
|
|
|
|
"memory exhausted.)");
|
|
|
|
return;
|
|
|
|
}
|
2006-01-01 21:52:30 +03:00
|
|
|
|
2006-04-10 03:21:13 +04:00
|
|
|
data = urldb_get_url_data(url);
|
2006-04-15 19:23:23 +04:00
|
|
|
if (!data) {
|
2006-04-10 03:21:13 +04:00
|
|
|
/* No entry in database, so add one */
|
|
|
|
urldb_add_url(url);
|
2006-04-15 19:23:23 +04:00
|
|
|
/* now attempt to get url data */
|
|
|
|
data = urldb_get_url_data(url);
|
|
|
|
}
|
2005-12-31 07:31:37 +03:00
|
|
|
if (!data)
|
|
|
|
return;
|
2006-04-15 19:23:23 +04:00
|
|
|
|
2006-06-15 02:46:12 +04:00
|
|
|
/* Make this URL persistent */
|
|
|
|
urldb_set_url_persistence(url, true);
|
|
|
|
|
2005-12-31 07:31:37 +03:00
|
|
|
if (!data->title)
|
2006-04-10 03:21:13 +04:00
|
|
|
urldb_set_url_title(url, title);
|
2006-04-15 19:23:23 +04:00
|
|
|
|
2006-04-10 03:21:13 +04:00
|
|
|
entry = tree_create_URL_node(directory, url, data, title);
|
2005-12-01 05:59:55 +03:00
|
|
|
xmlFree(url);
|
|
|
|
xmlFree(title);
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search the children of an xmlNode for an element.
|
|
|
|
*
|
|
|
|
* \param node xmlNode to search children of, or 0
|
|
|
|
* \param name name of element to find
|
|
|
|
* \return first child of node which is an element and matches name, or
|
|
|
|
* 0 if not found or parameter node is 0
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
xmlNode *options_find_tree_element(xmlNode *node, const char *name) {
|
2004-12-09 13:30:44 +03:00
|
|
|
xmlNode *n;
|
|
|
|
if (!node)
|
|
|
|
return 0;
|
|
|
|
for (n = node->children;
|
|
|
|
n && !(n->type == XML_ELEMENT_NODE &&
|
2008-02-25 20:58:00 +03:00
|
|
|
strcmp((const char *) n->name, name) == 0);
|
2004-12-09 13:30:44 +03:00
|
|
|
n = n->next)
|
|
|
|
;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform a save to a specified file
|
|
|
|
*
|
|
|
|
* /param filename the file to save to
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
bool options_save_tree(struct tree *tree, const char *filename, const char *page_title) {
|
2004-12-09 13:30:44 +03:00
|
|
|
int res;
|
|
|
|
xmlDoc *doc;
|
|
|
|
xmlNode *html, *head, *title, *body;
|
|
|
|
|
|
|
|
/* Unfortunately the Browse Hotlist format is invalid HTML,
|
|
|
|
* so this is a lie. */
|
2008-02-25 20:58:00 +03:00
|
|
|
doc = htmlNewDoc(
|
|
|
|
(const xmlChar *) "http://www.w3.org/TR/html4/strict.dtd",
|
|
|
|
(const xmlChar *) "-//W3C//DTD HTML 4.01//EN");
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!doc) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
html = xmlNewNode(NULL, (const xmlChar *) "html");
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!html) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
xmlDocSetRootElement(doc, html);
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
head = xmlNewChild(html, NULL, (const xmlChar *) "head", NULL);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!head) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-01 02:03:26 +03:00
|
|
|
title = xmlNewTextChild(head, NULL, (const xmlChar *) "title",
|
2008-02-25 20:58:00 +03:00
|
|
|
(const xmlChar *) page_title);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!title) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
body = xmlNewChild(html, NULL, (const xmlChar *) "body", NULL);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!body) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
if (!options_save_tree_directory(tree->root, body)) {
|
2004-12-09 13:30:44 +03:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->charset = XML_CHAR_ENCODING_UTF8;
|
|
|
|
res = htmlSaveFileEnc(filename, doc, "iso-8859-1");
|
|
|
|
if (res == -1) {
|
|
|
|
warn_user("HotlistSaveError", 0);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a directory to the HTML tree for saving.
|
|
|
|
*
|
|
|
|
* \param directory hotlist directory to add
|
|
|
|
* \param node node to add ul to
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
bool options_save_tree_directory(struct node *directory, xmlNode *node) {
|
2004-12-09 13:30:44 +03:00
|
|
|
struct node *child;
|
|
|
|
xmlNode *ul, *h4;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
ul = xmlNewChild(node, NULL, (const xmlChar *) "ul", NULL);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!ul)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (child = directory->child; child; child = child->next) {
|
|
|
|
if (!child->folder) {
|
|
|
|
/* entry */
|
2005-02-07 17:28:43 +03:00
|
|
|
if (!options_save_tree_entry(child, ul))
|
2004-12-09 13:30:44 +03:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
/* directory */
|
|
|
|
/* invalid HTML */
|
2008-03-01 02:03:26 +03:00
|
|
|
h4 = xmlNewTextChild(ul, NULL,
|
|
|
|
(const xmlChar *) "h4",
|
2008-02-25 20:58:00 +03:00
|
|
|
(const xmlChar *) child->data.text);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!h4)
|
|
|
|
return false;
|
|
|
|
|
2005-02-07 17:28:43 +03:00
|
|
|
if (!options_save_tree_directory(child, ul))
|
2004-12-09 13:30:44 +03:00
|
|
|
return false;
|
|
|
|
} }
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry to the HTML tree for saving.
|
|
|
|
*
|
|
|
|
* The node must contain a sequence of node_elements in the following order:
|
|
|
|
*
|
|
|
|
* \param entry hotlist entry to add
|
|
|
|
* \param node node to add li to
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
2005-02-07 17:28:43 +03:00
|
|
|
bool options_save_tree_entry(struct node *entry, xmlNode *node) {
|
2004-12-09 13:30:44 +03:00
|
|
|
xmlNode *li, *a;
|
|
|
|
xmlAttr *href;
|
|
|
|
struct node_element *element;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
li = xmlNewChild(node, NULL, (const xmlChar *) "li", NULL);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!li)
|
|
|
|
return false;
|
|
|
|
|
2008-03-01 02:03:26 +03:00
|
|
|
a = xmlNewTextChild(li, NULL, (const xmlChar *) "a",
|
2008-02-25 20:58:00 +03:00
|
|
|
(const xmlChar *) entry->data.text);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!a)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
element = tree_find_element(entry, TREE_ELEMENT_URL);
|
|
|
|
if (!element)
|
|
|
|
return false;
|
2008-03-01 02:03:26 +03:00
|
|
|
href = xmlNewProp(a, (const xmlChar *) "href",
|
2008-02-25 20:58:00 +03:00
|
|
|
(const xmlChar *) element->text);
|
2004-12-09 13:30:44 +03:00
|
|
|
if (!href)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|