Пример #1
0
/**
 * 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);
}
Пример #2
0
/**
 * 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);
	}

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

	/* 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_history_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise global history window.");
		return error;
	}

	error = nsgtk_download_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise download window.");
		return error;
	}

	error = nsgtk_cookies_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise cookies window.");
		return error;
	}

	error = nsgtk_hotlist_init();
	if (error != NSERROR_OK) {
		LOG("Unable to initialise hotlist 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;
}