示例#1
0
文件: gui.c 项目: pcwalton/NetSurf
static void check_options(char **respath)
{
	char *hdir = getenv("HOME");
	char buf[PATH_MAX];

	nsoption_set_bool(core_select_menu, true);

	/* Attempt to handle nonsense status bar widths.  These may exist
	 * in people's Choices as the GTK front end used to abuse the
	 * status bar width option by using it for an absolute value in px.
	 * The GTK front end now correctly uses it as a proportion of window
	 * width.  Here we assume that a value of less than 15% is wrong
	 * and set to the default two thirds. */
	if (nsoption_int(toolbar_status_width) < 1500) {
		nsoption_set_int(toolbar_status_width, 6667);
	}

	/* user options should be stored in the users home directory */
	snprintf(buf, PATH_MAX, "%s/.netsurf/Choices", hdir);      
	options_file_location = strdup(buf);

        /* VRS - I do not beleive these setting should search the
	 * resource path, they should just be set to the default
	 * values! 
	 */
	if (nsoption_charp(cookie_file) == NULL) {
		filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/");
		LOG(("Using '%s' as Cookies file", buf));
		nsoption_set_charp(cookie_file, strdup(buf));
	}
	if (nsoption_charp(cookie_jar) == NULL) {
		filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/");
		LOG(("Using '%s' as Cookie Jar file", buf));
		nsoption_set_charp(cookie_jar, strdup(buf));
	}
	if (nsoption_charp(cookie_file) == NULL || 
	    nsoption_charp(cookie_jar) == NULL)
		die("Failed initialising cookie options");

	if (nsoption_charp(url_file) == NULL) {
		filepath_sfinddef(respath, buf, "URLs", "~/.netsurf/");
		LOG(("Using '%s' as URL file", buf));
		nsoption_set_charp(url_file, strdup(buf));
	}

        if (nsoption_charp(ca_path) == NULL) {
		filepath_sfinddef(respath, buf, "certs", "/etc/ssl/");
                LOG(("Using '%s' as certificate path", buf));
                nsoption_set_charp(ca_path, strdup(buf));
        }

        if (nsoption_charp(downloads_directory) == NULL) {
        	LOG(("Using '%s' as download directory", hdir));
        	nsoption_set_charp(downloads_directory, strdup(hdir));
	}
	
	filepath_sfinddef(respath, buf, "icons/", "~/.netsurf/");
	LOG(("Using '%s' as Tree icons dir", buf));
	tree_set_icon_dir(strdup(buf));

	if (nsoption_charp(hotlist_path) == NULL) {
		filepath_sfinddef(respath, buf, "Hotlist", "~/.netsurf/");
		LOG(("Using '%s' as Hotlist file", buf));
		nsoption_set_charp(hotlist_path, strdup(buf));	
	}
	if (nsoption_charp(hotlist_path) == NULL)
		die("Failed initialising hotlist option");	
	

	filepath_sfinddef(respath, buf, "Print", "~/.netsurf/");
	LOG(("Using '%s' as Print Settings file", buf));
	print_options_file_location = strdup(buf);

	/* check what the font settings are, setting them to a default font
	 * if they're not set - stops Pango whinging
	 */
#define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y)))
	SETFONTDEFAULT(font_sans, "Sans");
	SETFONTDEFAULT(font_serif, "Serif");
	SETFONTDEFAULT(font_mono, "Monospace");
	SETFONTDEFAULT(font_cursive, "Serif");
	SETFONTDEFAULT(font_fantasy, "Serif");

}
示例#2
0
文件: gui.c 项目: pcwalton/NetSurf
/**
 * Initialize GTK interface.
 */
static void gui_init(int argc, char** argv, char **respath)
{
	char buf[PATH_MAX];
	const char *addr = NETSURF_HOMEPAGE;
	char *resource_filename;

	/* check user options */
	check_options(respath);

	/* find the languages file */	
	languages_file_location = filepath_find(respath, "languages");
	if ((languages_file_location == NULL) || 
	    (strlen(languages_file_location) < 10)) {
		die("Unable to find resources.\n");		
	}

	/* Obtain resources path location. 
	 *
	 * Uses the directory the languages file was found in,
	 * @todo find and slaughter all references to this!
	 */
	res_dir_location = calloc(1, strlen(languages_file_location) - 8);
	memcpy(res_dir_location, 
	       languages_file_location, 
	       strlen(languages_file_location) - 9);
	LOG(("Using '%s' for resource path", res_dir_location));

	/* initialise the glade templates */
	nsgtk_init_glade(respath);

	/* set default icon if its available */
	resource_filename = filepath_find(respath, "netsurf.xpm");
	if (resource_filename != NULL) {
		gtk_window_set_default_icon_from_file(resource_filename, NULL);
		free(resource_filename);
	}

	/* Search engine sources */
	search_engines_file_location = filepath_find(respath, "SearchEngines");
	LOG(("Using '%s' as Search Engines file", search_engines_file_location));

	/* Default Icon */
	search_default_ico_location = filepath_find(respath, "default.ico");
	LOG(("Using '%s' as default search ico", search_default_ico_location));

	/* Default favicon */
	resource_filename = filepath_find(respath, "favicon.png");
	if (resource_filename != NULL) {
		favicon_pixbuf = gdk_pixbuf_new_from_file(resource_filename, NULL);
		free(resource_filename);
		if (favicon_pixbuf == NULL) {
			favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16);
			
		}
	}

	/* Toolbar inicies file */
	toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
	LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location));

        /* load throbber images */
	if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
		die("Unable to load throbber image.\n");

	/* Initialise completions - cannot fail */
	nsgtk_completion_init();

	filepath_sfinddef(respath, buf, "mime.types", "/etc/");
	gtk_fetch_filetype_init(buf);

	urldb_load(nsoption_charp(url_file));
	urldb_load_cookies(nsoption_charp(cookie_file));

	/* The tree view system needs to know the screen's DPI, so we
	 * find that out here, rather than when we create a first browser
	 * window.
	 */

	nscss_screen_dpi = FLTTOFIX(gdk_screen_get_resolution(
					    gdk_screen_get_default()));
	LOG(("Set CSS DPI to %f", FIXTOFLT(nscss_screen_dpi)));

	if (nsgtk_history_init(glade_file_location->history) == false)
		die("Unable to initialise history window.\n");

	if (nsgtk_download_init(glade_file_location->downloads) == false)
		die("Unable to initialise download window.\n");

	if (nsgtk_cookies_init(glade_file_location->cookies) == false)
		die("Unable to initialise cookies window.\n");

	if (nsgtk_hotlist_init(glade_file_location->hotlist) == false)
		die("Unable to initialise hotlist window.\n");

	sslcert_init(tree_content_icon_name);

        if (nsoption_charp(homepage_url) != NULL) {
                addr = nsoption_charp(homepage_url);
	}

	if (2 <= argc)
		addr = argv[1];

        /* Last step of initialization. Opens the main browser window. */
	browser_window_create(addr, 0, 0, true, false);
}
示例#3
0
文件: gui.c 项目: mmuman/NetSurf
/**
 * Initialize GTK interface.
 */
static nserror nsgtk_init(int argc, char** argv, char **respath)
{
	char buf[PATH_MAX];
	char *resource_filename;
	char *addr = NULL;
	nsurl *url;
	nserror error;

	error = nsgtk_builder_new_from_resname("warning", &warning_builder);
	if (error != NSERROR_OK) {
		LOG("Unable to initialise warning dialog");
		return error;
	}

	gtk_builder_connect_signals(warning_builder, NULL);

	/* set default icon if its available */
	error = nsgdk_pixbuf_new_from_resname("netsurf.xpm",
					      &win_default_icon_pixbuf);
	if (error == NSERROR_OK) {
		LOG("Seting default window icon");
		gtk_window_set_default_icon(win_default_icon_pixbuf);
	}

	/* Search engine sources */
	resource_filename = filepath_find(respath, "SearchEngines");
	search_web_init(resource_filename);
	if (resource_filename != NULL) {
		LOG("Using '%s' as Search Engines file", resource_filename);
		free(resource_filename);
	}

	/* Default favicon */
	error = nsgdk_pixbuf_new_from_resname("favicon.png", &favicon_pixbuf);
	if (error != NSERROR_OK) {
		favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
						false, 8, 16, 16);
	}

	/* arrow down icon */
	error = nsgdk_pixbuf_new_from_resname("arrow_down_8x32.png",
					      &arrow_down_pixbuf);
	if (error != NSERROR_OK) {
		arrow_down_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
						   false, 8, 8, 32);
	}

	/* initialise throbber */
	error = nsgtk_throbber_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise throbber.");
		return error;
	}

	/* Initialise completions - cannot fail */
	nsgtk_completion_init();

	filepath_sfinddef(respath, buf, "mime.types", "/etc/");
	gtk_fetch_filetype_init(buf);

	save_complete_init();

	urldb_load(nsoption_charp(url_file));
	urldb_load_cookies(nsoption_charp(cookie_file));

	/* The tree view system needs to know the screen's DPI, so we
	 * find that out here, rather than when we create a first browser
	 * window.
	 */
	browser_set_dpi(gdk_screen_get_resolution(gdk_screen_get_default()));
	LOG("Set CSS DPI to %d", browser_get_dpi());

	/* Initialise top level UI elements */
	error = nsgtk_download_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise download window.");
		return error;
	}

	/* If there is a url specified on the command line use it */
	if (argc > 1) {
		struct stat fs;
		if (stat(argv[1], &fs) == 0) {
			size_t addrlen;
			char *rp = realpath(argv[1], NULL);
			assert(rp != NULL);

			/* calculate file url length including terminator */
			addrlen = SLEN("file://") + strlen(rp) + 1;
			addr = malloc(addrlen);
			assert(addr != NULL);
			snprintf(addr, addrlen, "file://%s", rp);
			free(rp);
		} else {
			addr = strdup(argv[1]);
		}
	}
	if (addr != NULL) {
		/* managed to set up based on local launch */
	} else if (nsoption_charp(homepage_url) != NULL) {
		addr = strdup(nsoption_charp(homepage_url));
	} else {
		addr = strdup(NETSURF_HOMEPAGE);
	}

	/* create an initial browser window */
	error = nsurl_create(addr, &url);
	if (error == NSERROR_OK) {
		error = browser_window_create(BW_CREATE_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);
	}

	free(addr);

	return error;
}