00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028
00029
00030
00031
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <glib.h>
00035 #include <glib/gstdio.h>
00036
00037 #include "gtkmozembed.h"
00038 #include "gtkmozembed_internal.h"
00039
00040 #include "browserTypes.h"
00041 #include "browserSettings.h"
00042 #include "mozillaPreferences.h"
00043
00044 #include "nsCOMPtr.h"
00045 #include "prenv.h"
00046 #include "nsNetUtil.h"
00047 #include "nsIWebBrowser.h"
00048 #include "nsIScrollable.h"
00049 #include "browserLog.h"
00050
00051
00052 static gchar gBrowserSettingsPath[MAX_SETTINGSPATH_LENGTH];
00053 static BrowserSettings gBrowserSettings;
00054
00055
00056 static gboolean browser_settings_get_defaults(BrowserSettings * theBrowserSettings);
00057 static void browser_set_proxy_prefs(ProxySettings * theProxySettings);
00058 static void browser_display_settings(BrowserSettings * theBrowserSettings);
00059
00060
00061
00062
00063
00064
00065
00066 gboolean browser_settings_init(GtkMozEmbed * b)
00067 {
00068 gboolean returnValue = FALSE;
00069 gchar *directory;
00070 gchar *browserUserHomePath;
00071 gchar *filename;
00072 BrowserSettings *theBrowserSettings;
00073
00074 BR_LOGPRINTF("entry");
00075
00076 browserUserHomePath = PR_GetEnv("HOME");
00077
00078 if (!browserUserHomePath)
00079 {
00080 BR_ERRORPRINTF("Failed to get HOME");
00081 return returnValue;
00082 }
00083
00084
00085 directory = g_strconcat(browserUserHomePath, "/.Browser", NULL);
00086 mkdir(directory, 0755);
00087
00088
00089 if (strlen(directory) < MAX_SETTINGSPATH_LENGTH)
00090 {
00091 g_strlcpy(gBrowserSettingsPath, directory, MAX_SETTINGSPATH_LENGTH);
00092 }
00093
00094 g_free(directory);
00095
00096 BR_LOGPRINTF("path %s", gBrowserSettingsPath);
00097
00098 filename = g_strconcat(gBrowserSettingsPath, CONFIG_FILE_NAME, NULL);
00099
00100 theBrowserSettings = &gBrowserSettings;
00101
00102 if (g_file_test(filename, G_FILE_TEST_EXISTS) == TRUE)
00103 {
00104
00105 returnValue = browser_settings_get(theBrowserSettings);
00106 }
00107 else
00108 {
00109 browser_settings_get_defaults(theBrowserSettings);
00110 theBrowserSettings->zoom_factor = 1.0;
00111 returnValue = TRUE;
00112 }
00113
00114
00115 browser_display_settings(&gBrowserSettings);
00116
00117 browser_settings_set_mozilla_settings(theBrowserSettings);
00118
00119
00120
00121
00122
00123 mozilla_pref_set_int("browser.display.focus_ring_width", 3);
00124 mozilla_pref_set_boolean("browser.display.focus_ring_on_anything", TRUE);
00125
00126 g_free(filename);
00127
00128 return returnValue;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 gboolean browser_settings_get(BrowserSettings * theBrowserSettings)
00138 {
00139 FILE *settings_file = NULL;
00140 gchar *filename = NULL;
00141
00142 BR_LOGPRINTF("entry");
00143
00144 if (theBrowserSettings)
00145 {
00146 filename = g_strconcat(gBrowserSettingsPath, CONFIG_FILE_NAME, NULL);
00147 settings_file = fopen(filename, "r");
00148
00149 if (settings_file)
00150 {
00151 fscanf(settings_file, "directconnection=%d\n", &theBrowserSettings->theProxySettings.direct_connection);
00152 fscanf(settings_file, "http_proxy=%s\n", &theBrowserSettings->theProxySettings.http_proxy);
00153 fscanf(settings_file, "http_proxy_port=%s\n", &theBrowserSettings->theProxySettings.http_proxy_port);
00154 fscanf(settings_file, "ftp_proxy=%s\n", &theBrowserSettings->theProxySettings.ftp_proxy);
00155 fscanf(settings_file, "ftp_proxy_port=%s\n", &theBrowserSettings->theProxySettings.ftp_proxy_port);
00156 fscanf(settings_file, "ssl_proxy=%s\n", &theBrowserSettings->theProxySettings.ssl_proxy);
00157 fscanf(settings_file, "ssl_proxy_port=%s\n", &theBrowserSettings->theProxySettings.ssl_proxy_port);
00158 fscanf(settings_file, "no_proxy_for=%s\n", &theBrowserSettings->theProxySettings.no_proxy_for);
00159 fscanf(settings_file, "zoom_factor=%f\n", &theBrowserSettings->zoom_factor);
00160
00161 fclose(settings_file);
00162 }
00163 else
00164 {
00165 BR_ERRORPRINTF("could not open settings file %s", filename);
00166 }
00167
00168 g_free(filename);
00169 return TRUE;
00170
00171 }
00172 else
00173 {
00174 BR_ERRORPRINTF("input parameter == NULL");
00175 return FALSE;
00176 }
00177 }
00178
00179
00180
00181
00182
00183
00184
00185 static void browser_display_settings(BrowserSettings * theBrowserSettings)
00186 {
00187 if (theBrowserSettings)
00188 {
00189 BR_LOGPRINTF("\n------------------theBrowserSettings---------------------");
00190 BR_LOGPRINTF("direct_connection= %sn", (theBrowserSettings->theProxySettings.direct_connection) ? "TRUE" : "FALSE");
00191 BR_LOGPRINTF("http_proxy= %s", theBrowserSettings->theProxySettings.http_proxy);
00192 BR_LOGPRINTF("http_proxy_port= %s", theBrowserSettings->theProxySettings.http_proxy_port);
00193 BR_LOGPRINTF("ftp_proxy= %s", theBrowserSettings->theProxySettings.ftp_proxy);
00194 BR_LOGPRINTF("ftp_proxy_port= %s", theBrowserSettings->theProxySettings.ftp_proxy_port);
00195 BR_LOGPRINTF("ssl_proxy= %s", theBrowserSettings->theProxySettings.ssl_proxy);
00196 BR_LOGPRINTF("ssl_proxy_port= %s", theBrowserSettings->theProxySettings.ssl_proxy_port);
00197 BR_LOGPRINTF("zoom_factor= %f", theBrowserSettings->zoom_factor);
00198 BR_LOGPRINTF("---------------------------------------------------");
00199 }
00200 else
00201 {
00202 BR_ERRORPRINTF("input parameter == NULL");
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 static gboolean browser_settings_get_defaults(BrowserSettings * theBrowserSettings)
00213 {
00214 if (theBrowserSettings)
00215 {
00216 theBrowserSettings->theProxySettings.direct_connection = 1;
00217 strcpy(theBrowserSettings->theProxySettings.http_proxy, "");
00218 strcpy(theBrowserSettings->theProxySettings.http_proxy_port, "");
00219 strcpy(theBrowserSettings->theProxySettings.ftp_proxy, "");
00220 strcpy(theBrowserSettings->theProxySettings.ftp_proxy_port, "");
00221 strcpy(theBrowserSettings->theProxySettings.ssl_proxy, "");
00222 strcpy(theBrowserSettings->theProxySettings.ssl_proxy_port, "");
00223 strcpy(theBrowserSettings->theProxySettings.no_proxy_for, "");
00224 return TRUE;
00225 }
00226 else
00227 {
00228 BR_ERRORPRINTF("input parameter == NULL");
00229 return FALSE;
00230 }
00231 }
00232
00233
00234
00235
00236
00237
00238
00239 gboolean browser_settings_store(BrowserSettings * theBrowserSettings)
00240 {
00241 FILE *settings_file;
00242 gchar *file;
00243
00244 BR_LOGPRINTF("entry");
00245
00246 file = g_strconcat(gBrowserSettingsPath, CONFIG_FILE_NAME, NULL);
00247 settings_file = fopen(file, "w");
00248
00249 if (settings_file == NULL)
00250 {
00251 BR_ERRORPRINTF("cannot open config file %s!", CONFIG_FILE_NAME);
00252 return FALSE;
00253 }
00254
00255 BR_LOGPRINTF("file %s", file);
00256 fprintf(settings_file, "directconnection=%d\n", theBrowserSettings->theProxySettings.direct_connection);
00257 fprintf(settings_file, "http_proxy=%s\n", theBrowserSettings->theProxySettings.http_proxy);
00258 fprintf(settings_file, "http_proxy_port=%s\n", theBrowserSettings->theProxySettings.http_proxy_port);
00259 fprintf(settings_file, "ftp_proxy=%s\n", theBrowserSettings->theProxySettings.ftp_proxy);
00260 fprintf(settings_file, "ftp_proxy_port=%s\n", theBrowserSettings->theProxySettings.ftp_proxy_port);
00261 fprintf(settings_file, "ssl_proxy=%s\n", theBrowserSettings->theProxySettings.ssl_proxy);
00262 fprintf(settings_file, "ssl_proxy_port=%s\n", theBrowserSettings->theProxySettings.ssl_proxy_port);
00263 fprintf(settings_file, "no_proxy_for=%s\n", theBrowserSettings->theProxySettings.no_proxy_for);
00264
00265 fprintf(settings_file, "zoom_factor=%f\n", theBrowserSettings->zoom_factor);
00266
00267 fclose(settings_file);
00268 g_free(file);
00269
00270 browser_settings_set_mozilla_settings(theBrowserSettings);
00271
00272 return TRUE;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282 gboolean browser_settings_set_mozilla_settings(BrowserSettings * theBrowserSettings)
00283 {
00284
00285 browser_set_proxy_prefs(&theBrowserSettings->theProxySettings);
00286 mozilla_save_prefs();
00287 return TRUE;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 static void browser_set_proxy_prefs(ProxySettings * theProxySettings)
00297 {
00298 gint network_type = 0;
00299
00300 BR_LOGPRINTF("entry");
00301
00302 if (theProxySettings)
00303 {
00304 if (theProxySettings->direct_connection)
00305 {
00306 mozilla_pref_set_char("network.proxy.http", "");
00307 mozilla_pref_set_char("network.proxy.ssl", "");
00308 mozilla_pref_set_char("network.proxy.ftp", "");
00309 mozilla_pref_set_char("network.proxy.no_proxies_on", "");
00310 mozilla_pref_set_int("network.proxy.type", network_type);
00311 }
00312 else
00313 {
00314 if (strlen(theProxySettings->http_proxy) != 0
00315 && strcmp(theProxySettings->http_proxy, "") != 0
00316 && strlen(theProxySettings->http_proxy_port) > 0 && strcmp(theProxySettings->http_proxy_port, "") != 0)
00317 {
00318 mozilla_pref_set_int("network.proxy.type", 1);
00319 network_type = 1;
00320 mozilla_pref_set_char("network.proxy.http", theProxySettings->http_proxy);
00321 mozilla_pref_set_int("network.proxy.http_port", atoi(theProxySettings->http_proxy_port));
00322 }
00323
00324 if (strlen(theProxySettings->ftp_proxy) != 0
00325 && strcmp(theProxySettings->ftp_proxy, "") != 0
00326 && strlen(theProxySettings->ftp_proxy_port) > 0 && strcmp(theProxySettings->http_proxy_port, "") != 0)
00327 {
00328 if (!network_type)
00329 {
00330 mozilla_pref_set_int("network.proxy.type", 1);
00331 }
00332 mozilla_pref_set_char("network.proxy.ftp", theProxySettings->ftp_proxy);
00333 mozilla_pref_set_int("network.proxy.ftp_port", atoi(theProxySettings->ftp_proxy_port));
00334 }
00335
00336 if (strlen(theProxySettings->ssl_proxy) != 0
00337 && strcmp(theProxySettings->ssl_proxy, "") != 0
00338 && strlen(theProxySettings->ssl_proxy_port) > 0 && strcmp(theProxySettings->ssl_proxy_port, "") != 0)
00339 {
00340 if (!network_type)
00341 {
00342 mozilla_pref_set_int("network.proxy.type", 1);
00343 }
00344 mozilla_pref_set_char("network.proxy.ssl", theProxySettings->ssl_proxy);
00345 mozilla_pref_set_int("network.proxy.ssl_port", atoi(theProxySettings->ssl_proxy_port));
00346 }
00347
00348 if (strlen(theProxySettings->no_proxy_for) != 0)
00349 {
00350 mozilla_pref_set_char("network.proxy.no_proxies_on", theProxySettings->no_proxy_for);
00351 }
00352 else
00353 mozilla_pref_set_char("network.proxy.no_proxies_on", "127.0.0.1");
00354 }
00355 }
00356 else
00357 {
00358 BR_ERRORPRINTF("input parameter == NULL");
00359 }
00360 }
00361
00362 float browser_settings_get_zoom_factor(void)
00363 {
00364 return gBrowserSettings.zoom_factor;
00365 }
00366
00367 void browser_settings_set_zoom_factor(float zoom_factor)
00368 {
00369 if (zoom_factor >= 0)
00370 {
00371 gBrowserSettings.zoom_factor = zoom_factor;
00372 }
00373 }