Esempio n. 1
0
void nsgtk_options_load(void) 
{
	GtkBox *box;
	const char *default_accept_language = "en";
	const char *default_homepage_url = "";
	const char *default_http_proxy_host = "";
	const char *default_http_proxy_auth_user = "";
	const char *default_http_proxy_auth_pass = "";
	int combo_row_count = 0;
	int active_language = 0;
	int proxytype = 0;
	FILE *fp;
	char buf[50];

	/* get widget text */
	if (nsoption_charp(accept_language) != NULL) {
		default_accept_language = nsoption_charp(accept_language);
	}

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

	if (nsoption_charp(http_proxy_host) != NULL) {
		default_http_proxy_host = nsoption_charp(http_proxy_host);
	}

	if (nsoption_charp(http_proxy_auth_user) != NULL) {
		default_http_proxy_auth_user = nsoption_charp(http_proxy_auth_user);
	}

	if (nsoption_charp(http_proxy_auth_pass) != NULL) {
		default_http_proxy_auth_pass = nsoption_charp(http_proxy_auth_pass);
	}

	if (nsoption_bool(http_proxy) == true) {
		proxytype = nsoption_int(http_proxy_auth) + 1;
	}

	/* Create combobox */
	box = GTK_BOX(gtk_builder_get_object(gladeFile, "combolanguagevbox"));
	comboLanguage = nsgtk_combo_box_text_new();

	/* Populate combobox from languages file */
	if ((languages_file_location != NULL) && 
	    ((fp = fopen(languages_file_location, "r")) != NULL)) {
		LOG(("Used %s for languages", languages_file_location));
		while (fgets(buf, sizeof(buf), fp)) {
			/* Ignore blank lines */
			if (buf[0] == '\0')
				continue;

			/* Remove trailing \n */
			buf[strlen(buf) - 1] = '\0';

			nsgtk_combo_box_text_append_text(comboLanguage, buf);

			if (strcmp(buf, default_accept_language) == 0)
				active_language = combo_row_count;

			combo_row_count++;
		}

		fclose(fp);
	} else {
		LOG(("Failed opening languages file"));
		warn_user("FileError", languages_file_location);
		nsgtk_combo_box_text_append_text(comboLanguage, "en");
	}


	gtk_combo_box_set_active(GTK_COMBO_BOX(comboLanguage), active_language);
	/** \todo localisation */
	gtk_widget_set_tooltip_text(GTK_WIDGET(comboLanguage), 
			"set preferred language for web pages");
	gtk_box_pack_start(box, comboLanguage, FALSE, FALSE, 0);
	gtk_widget_show(comboLanguage);
	
	nsgtk_options_theme_combo();
	
	SET_ENTRY(entryHomePageURL, default_homepage_url);
	SET_BUTTON(setCurrentPage);
	SET_BUTTON(setDefaultPage);
	SET_CHECK(checkHideAdverts, nsoption_bool(block_ads));
	
	SET_CHECK(checkDisablePopups, nsoption_bool(disable_popups));
	SET_CHECK(checkDisablePlugins, nsoption_bool(disable_plugins));
	SET_SPIN(spinHistoryAge, nsoption_int(history_age));
	SET_CHECK(checkHoverURLs, nsoption_bool(hover_urls));
	
	SET_CHECK(checkDisplayRecentURLs, nsoption_bool(url_suggestion));
	SET_CHECK(checkSendReferer, nsoption_bool(send_referer));
        SET_CHECK(checkShowSingleTab, nsoption_bool(show_single_tab));
	
	SET_COMBO(comboProxyType, proxytype);
	SET_ENTRY(entryProxyHost, default_http_proxy_host);

	gtk_widget_set_sensitive(entryProxyHost, proxytype != 0);

	snprintf(buf, sizeof(buf), "%d", nsoption_int(http_proxy_port));	

	SET_ENTRY(entryProxyPort, buf);
	gtk_widget_set_sensitive(entryProxyPort, proxytype != 0);

	SET_ENTRY(entryProxyUser, default_http_proxy_auth_user);

	gtk_widget_set_sensitive(entryProxyUser, proxytype != 0);

	SET_ENTRY(entryProxyPassword, default_http_proxy_auth_pass);

	gtk_widget_set_sensitive(entryProxyPassword, proxytype != 0);

	SET_SPIN(spinMaxFetchers, nsoption_int(max_fetchers));
	SET_SPIN(spinFetchesPerHost, nsoption_int(max_fetchers_per_host));
	SET_SPIN(spinCachedConnections, nsoption_int(max_cached_fetch_handles));

	SET_CHECK(checkResampleImages, nsoption_bool(render_resample));
	SET_SPIN(spinAnimationSpeed, nsoption_int(minimum_gif_delay) / 100.0);
	SET_CHECK(checkDisableAnimations, !nsoption_bool(animate_images));

	SET_FONT(fontSansSerif, nsoption_charp(font_sans));
	SET_FONT(fontSerif, nsoption_charp(font_serif));
	SET_FONT(fontMonospace, nsoption_charp(font_mono));
	SET_FONT(fontCursive, nsoption_charp(font_cursive));
	SET_FONT(fontFantasy, nsoption_charp(font_fantasy));
	SET_COMBO(comboDefault, nsoption_int(font_default));
	SET_SPIN(spinDefaultSize, nsoption_int(font_size) / 10);
	SET_SPIN(spinMinimumSize, nsoption_bool(font_min_size) / 10);
	SET_BUTTON(fontPreview);
	
	SET_COMBO(comboButtonType, nsoption_int(button_type) -1);

	SET_COMBO(comboTabPosition, nsoption_int(position_tab));

	SET_SPIN(spinMemoryCacheSize, nsoption_int(memory_cache_size) >> 20);
	SET_SPIN(spinDiscCacheAge, nsoption_int(disc_cache_age));
	
	SET_CHECK(checkClearDownloads, nsoption_bool(downloads_clear));
	SET_CHECK(checkRequestOverwrite, nsoption_bool(request_overwrite));
	SET_FILE_CHOOSER(fileChooserDownloads, nsoption_charp(downloads_directory));
	
	SET_CHECK(checkFocusNew, nsoption_bool(focus_new));
	SET_CHECK(checkNewBlank, nsoption_bool(new_blank));
	SET_CHECK(checkUrlSearch, nsoption_bool(search_url_bar));
	SET_COMBO(comboSearch, nsoption_int(search_provider));
	
	SET_BUTTON(buttonaddtheme);
	SET_CHECK(sourceButtonTab, nsoption_bool(source_tab));
		
	SET_SPIN(spinMarginTop, nsoption_int(margin_top));
	SET_SPIN(spinMarginBottom, nsoption_int(margin_bottom));
	SET_SPIN(spinMarginLeft, nsoption_int(margin_left));
	SET_SPIN(spinMarginRight, nsoption_int(margin_right));
	SET_SPIN(spinExportScale, nsoption_int(export_scale));
	SET_CHECK(checkSuppressImages, nsoption_bool(suppress_images));
	SET_CHECK(checkRemoveBackgrounds, nsoption_bool(remove_backgrounds));
	SET_CHECK(checkFitPage, nsoption_bool(enable_loosening));
	SET_CHECK(checkCompressPDF, nsoption_bool(enable_PDF_compression));
	SET_CHECK(checkPasswordPDF, nsoption_bool(enable_PDF_password));
	SET_BUTTON(setDefaultExportOptions);
}
Esempio n. 2
0
void nsgtk_options_load(void) 
{
	GtkBox *box;
	char languagefile[strlen(res_dir_location) + SLEN("languages") + 1];
	const char *default_accept_language = 
			option_accept_language ? option_accept_language : "en";
	int combo_row_count = 0;
	int active_language = 0;
	int proxytype = 0;
	FILE *fp;
	char buf[50];

	/* Create combobox */
	box = GTK_BOX(glade_xml_get_widget(gladeFile, "combolanguagevbox"));
	comboLanguage = gtk_combo_box_new_text();

	sprintf(languagefile, "%slanguages", res_dir_location);

	/* Populate combobox from languages file */
	fp = fopen((const char *) languagefile, "r");
	if (fp == NULL) {
		LOG(("Failed opening languages file"));
		warn_user("FileError", (const char *) languagefile);
		return;
	}

	while (fgets(buf, sizeof(buf), fp)) {
		/* Ignore blank lines */
		if (buf[0] == '\0')
			continue;

		/* Remove trailing \n */
		buf[strlen(buf) - 1] = '\0';

		gtk_combo_box_append_text(GTK_COMBO_BOX(comboLanguage), buf);

		if (strcmp(buf, default_accept_language) == 0)
			active_language = combo_row_count;

		combo_row_count++;
	}

	fclose(fp);

	gtk_combo_box_set_active(GTK_COMBO_BOX(comboLanguage), active_language);
	/** \todo localisation */
	gtk_widget_set_tooltip_text(GTK_WIDGET(comboLanguage), 
			"set preferred language for web pages");
	gtk_box_pack_start(box, comboLanguage, FALSE, FALSE, 0);
	gtk_widget_show(comboLanguage);
	
	nsgtk_options_theme_combo();
	
	SET_ENTRY(entryHomePageURL,
			option_homepage_url ? option_homepage_url : "");
	SET_BUTTON(setCurrentPage);
	SET_BUTTON(setDefaultPage);
	SET_CHECK(checkHideAdverts, option_block_ads);
	
	SET_CHECK(checkDisablePopups, option_disable_popups);
	SET_CHECK(checkDisablePlugins, option_disable_plugins);
	SET_SPIN(spinHistoryAge, option_history_age);
	SET_CHECK(checkHoverURLs, option_hover_urls);
	
	SET_CHECK(checkDisplayRecentURLs, option_url_suggestion);
	SET_CHECK(checkSendReferer, option_send_referer);
        SET_CHECK(checkShowSingleTab, option_show_single_tab);
	
	if (option_http_proxy == false)
		proxytype = 0;
	else
		proxytype = option_http_proxy_auth + 1;

	SET_COMBO(comboProxyType, proxytype);
	SET_ENTRY(entryProxyHost,
			option_http_proxy_host ? option_http_proxy_host : "");
	gtk_widget_set_sensitive(entryProxyHost, proxytype != 0);

	snprintf(buf, sizeof(buf), "%d", option_http_proxy_port);	

	SET_ENTRY(entryProxyPort, buf);
	gtk_widget_set_sensitive(entryProxyPort, proxytype != 0);

	SET_ENTRY(entryProxyUser, option_http_proxy_auth_user ?
			option_http_proxy_auth_user : "");
	gtk_widget_set_sensitive(entryProxyUser, proxytype != 0);

	SET_ENTRY(entryProxyPassword, option_http_proxy_auth_pass ?
			option_http_proxy_auth_pass : "");
	gtk_widget_set_sensitive(entryProxyPassword, proxytype != 0);

	SET_SPIN(spinMaxFetchers, option_max_fetchers);
	SET_SPIN(spinFetchesPerHost, option_max_fetchers_per_host);
	SET_SPIN(spinCachedConnections, option_max_cached_fetch_handles);

	SET_CHECK(checkResampleImages, option_render_resample);
	SET_SPIN(spinAnimationSpeed, option_minimum_gif_delay / 100.0);
	SET_CHECK(checkDisableAnimations, !option_animate_images);

	SET_FONT(fontSansSerif, option_font_sans);
	SET_FONT(fontSerif, option_font_serif);
	SET_FONT(fontMonospace, option_font_mono);
	SET_FONT(fontCursive, option_font_cursive);
	SET_FONT(fontFantasy, option_font_fantasy);
	SET_COMBO(comboDefault, option_font_default);
	SET_SPIN(spinDefaultSize, option_font_size / 10);
	SET_SPIN(spinMinimumSize, option_font_min_size / 10);
	SET_BUTTON(fontPreview);
	
	SET_COMBO(comboButtonType, option_button_type -1);

	SET_SPIN(spinMemoryCacheSize, option_memory_cache_size >> 20);
	SET_SPIN(spinDiscCacheAge, option_disc_cache_age);
	
	SET_CHECK(checkClearDownloads, option_downloads_clear);
	SET_CHECK(checkRequestOverwrite, option_request_overwrite);
	SET_FILE_CHOOSER(fileChooserDownloads, option_downloads_directory);
	
	SET_CHECK(checkFocusNew, option_focus_new);
	SET_CHECK(checkNewBlank, option_new_blank);
	SET_CHECK(checkUrlSearch, option_search_url_bar);
	SET_COMBO(comboSearch, option_search_provider);
	
	SET_BUTTON(buttonaddtheme);
	SET_CHECK(sourceButtonTab, option_source_tab);
		
	SET_SPIN(spinMarginTop, option_margin_top);
	SET_SPIN(spinMarginBottom, option_margin_bottom);
	SET_SPIN(spinMarginLeft, option_margin_left);
	SET_SPIN(spinMarginRight, option_margin_right);
	SET_SPIN(spinExportScale, option_export_scale);
	SET_CHECK(checkSuppressImages, option_suppress_images);
	SET_CHECK(checkRemoveBackgrounds, option_remove_backgrounds);
	SET_CHECK(checkFitPage, option_enable_loosening);
	SET_CHECK(checkCompressPDF, option_enable_PDF_compression);
	SET_CHECK(checkPasswordPDF, option_enable_PDF_password);
	SET_BUTTON(setDefaultExportOptions);
}