erbrowser/src/browserSettings.cpp File Reference

browser - read/write the browser settings and configure mozilla with these settings More...

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "gtkmozembed.h"
#include "gtkmozembed_internal.h"
#include "browserTypes.h"
#include "browserSettings.h"
#include "mozillaPreferences.h"
#include "nsCOMPtr.h"
#include "prenv.h"
#include "nsNetUtil.h"
#include "nsIWebBrowser.h"
#include "nsIScrollable.h"
#include "browserLog.h"

Go to the source code of this file.

Functions

static gboolean browser_settings_get_defaults (BrowserSettings *theBrowserSettings)
static void browser_set_proxy_prefs (ProxySettings *theProxySettings)
static void browser_display_settings (BrowserSettings *theBrowserSettings)
gboolean browser_settings_init (GtkMozEmbed *b)
gboolean browser_settings_get (BrowserSettings *theBrowserSettings)
gboolean browser_settings_store (BrowserSettings *theBrowserSettings)
gboolean browser_settings_set_mozilla_settings (BrowserSettings *theBrowserSettings)
float browser_settings_get_zoom_factor (void)
void browser_settings_set_zoom_factor (float zoom_factor)

Variables

static gchar gBrowserSettingsPath [MAX_SETTINGSPATH_LENGTH]
static BrowserSettings gBrowserSettings


Detailed Description

browser - read/write the browser settings and configure mozilla with these settings

Todo:
  • link this with the setup application entries in the future
<File description>="">

Definition in file browserSettings.cpp.


Function Documentation

static void browser_display_settings ( BrowserSettings theBrowserSettings  )  [static]

Definition at line 185 of file browserSettings.cpp.

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 }

static void browser_set_proxy_prefs ( ProxySettings theProxySettings  )  [static]

Definition at line 296 of file browserSettings.cpp.

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 }

Here is the call graph for this function:

gboolean browser_settings_get ( BrowserSettings theBrowserSettings  ) 

retrieve the current content of the settingsfile

Parameters:
theBrowserSettings where the retreived values should be stored
Returns:
TRUE in case of succes

Definition at line 137 of file browserSettings.cpp.

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 }

static gboolean browser_settings_get_defaults ( BrowserSettings theBrowserSettings  )  [static]

Definition at line 212 of file browserSettings.cpp.

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 }

float browser_settings_get_zoom_factor ( void   ) 

Method used to retrieve the zoomfactor used by the browser .

Returns:
zoomfactor

Definition at line 362 of file browserSettings.cpp.

00363 {
00364     return gBrowserSettings.zoom_factor;
00365 }

gboolean browser_settings_init ( GtkMozEmbed *  b  ) 

creates (if needed) the directory on the system used to store the settings files retrieve the current browser settings and use these to configure mozilla/Gecko.

Parameters:
b reference to the MozEmbed widget
Returns:
TRUE in case of succes

Definition at line 66 of file browserSettings.cpp.

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     // create directory [g_strconcat alllocates memory]
00085     directory = g_strconcat(browserUserHomePath, "/.Browser", NULL);
00086     mkdir(directory, 0755);
00087 
00088     // store the path value
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         //retrieve the current content of the settingsfile 
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     //only for debug reasons
00115     browser_display_settings(&gBrowserSettings);
00116 
00117     browser_settings_set_mozilla_settings(theBrowserSettings);
00118     
00119     // MvdW: Quick hack to allow XHTML navigation with hardkeys:
00120     //  made focus_ring visible, so links are outlined
00121     //  this needs to be moved to more generic settings functions
00122     //  which also need to read the registry for proxy settings and such
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 }

Here is the call graph for this function:

gboolean browser_settings_set_mozilla_settings ( BrowserSettings theBrowserSettings  ) 

configure mozilla with the current settings

Parameters:
theBrowserSettings the current settings
Returns:
TRUE in case of succes

Definition at line 282 of file browserSettings.cpp.

00283 {
00284     // set proxy preferences 
00285     browser_set_proxy_prefs(&theBrowserSettings->theProxySettings);
00286     mozilla_save_prefs();
00287     return TRUE;
00288 }

Here is the call graph for this function:

void browser_settings_set_zoom_factor ( float  zoom_factor  ) 

Method used to set the the zoomfactor used by the browser .

Returns:
void

Definition at line 367 of file browserSettings.cpp.

00368 {
00369     if (zoom_factor >= 0)
00370     {
00371         gBrowserSettings.zoom_factor = zoom_factor;
00372     }
00373 }

gboolean browser_settings_store ( BrowserSettings theBrowserSettings  ) 

Definition at line 239 of file browserSettings.cpp.

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 }

Here is the call graph for this function:


Variable Documentation

Definition at line 53 of file browserSettings.cpp.

gchar gBrowserSettingsPath[MAX_SETTINGSPATH_LENGTH] [static]

Definition at line 52 of file browserSettings.cpp.


Generated on Sun Dec 14 17:14:47 2008 by  doxygen 1.5.6