Back to index

lightning-sunbird  0.9+nobinonly
preference.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *   Doug Turner <dougt@meer.net>  Branched from TestGtkEmbed.cpp
00024  *
00025  *   The 10LE Team (in alphabetical order)
00026  *   -------------------------------------
00027  *
00028  *    Ilias Biris       <ext-ilias.biris@indt.org.br> - Coordinator
00029  *    Afonso Costa      <afonso.costa@indt.org.br>
00030  *    Antonio Gomes     <antonio.gomes@indt.org.br>
00031  *    Diego Gonzalez    <diego.gonzalez@indt.org.br>
00032  *    Raoni Novellino   <raoni.novellino@indt.org.br>
00033  *    Andre Pedralho    <andre.pedralho@indt.org.br>
00034  *
00035  *
00036  * Alternatively, the contents of this file may be used under the terms of
00037  * either the GNU General Public License Version 2 or later (the "GPL"), or
00038  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00039  * in which case the provisions of the GPL or the LGPL are applicable instead
00040  * of those above. If you wish to allow use of your version of this file only
00041  * under the terms of either the GPL or the LGPL, and not to allow others to
00042  * use your version of this file under the terms of the MPL, indicate your
00043  * decision by deleting the provisions above and replace them with the notice
00044  * and other provisions required by the GPL or the LGPL. If you do not delete
00045  * the provisions above, a recipient may use your version of this file under
00046  * the terms of any one of the MPL, the GPL or the LGPL.
00047  *
00048  * ***** END LICENSE BLOCK ***** */
00049 
00050 #include "mozilla_api.h"
00051 
00052 typedef struct _PrefWindow         /* configuration data struct */
00053 {
00054   GtkWidget *dialog;
00055   GtkWidget *okbutton;
00056   GtkWidget *cancelbutton;
00057   GtkWidget *applybutton;
00058   GtkWidget *block_popup;
00059   GtkWidget *vbox_popup;
00060   GtkWidget *fr_connection;
00061   GtkWidget *vbox_connection;
00062   GtkWidget *hbox_connection;
00063   GtkWidget *hbox_direct_connection;
00064   GtkWidget *fr_popup;
00065   GtkWidget *lb_popup;
00066   
00067   GtkWidget *vbox_manual;
00068   GtkWidget *rb_manual_connection;
00069   GtkWidget *hbox_http;
00070   GtkWidget *lb_http;
00071   GtkWidget *en_http_proxy;
00072   GtkWidget *box_popup;
00073   
00074   GtkWidget *lb_port_http;
00075   GtkWidget *en_http_port;
00076   GtkWidget *hbox_ssl;
00077   GtkWidget *lb_ssl;
00078   GtkWidget *en_ssl;
00079   GtkWidget *lb_ssl_port;
00080   GtkWidget *en_ssl_port;
00081   GtkWidget *hbox_ftp;
00082   
00083   GtkWidget *lb_ftp;
00084   GtkWidget *en_ftp_proxy;
00085   GtkWidget *lb_ftp_port;
00086   GtkWidget *en_ftp_port;
00087   GtkWidget *hbox_noproxy;
00088   GtkWidget *lb_connection;
00089   
00090   GSList *rb_direct_connection_group;
00091   GSList *rb_manual_connection_group;
00092   GtkWidget *hbox_manual_connection;
00093   GtkWidget *rb_direct_connection;
00094   
00095 } PrefWindow;
00096 
00097 ConfigData config;
00098 PrefWindow *prefWindow;
00099 
00100 /* Callbacks */
00101 void close_preferences_cb (GtkButton *button, PrefWindow *pref);
00102 void ok_preferences_cb (GtkButton *button, PrefWindow *pref);
00103 
00104 /* Support methods */
00105 void read_minimo_config(void);
00106 void write_minimo_config(void);
00107 void set_mozilla_prefs(void);
00108 void minimo_set_proxy_prefs(void);
00109 
00110 /* UI Methods */
00111 PrefWindow * build_pref_window (GtkWidget *topLevelWindow);
00112 
00113 PrefWindow * build_pref_window (GtkWidget *topLevelWindow) {
00114   
00115   prefWindow = g_new0(PrefWindow,1);
00116   
00117   prefWindow->dialog = gtk_dialog_new ();
00118   
00119   gtk_window_set_title (GTK_WINDOW (prefWindow->dialog), ("Prefs Window"));
00120   gtk_window_set_position (GTK_WINDOW (prefWindow->dialog), GTK_WIN_POS_CENTER_ON_PARENT);
00121   gtk_window_set_modal (GTK_WINDOW (prefWindow->dialog), TRUE);
00122   gtk_window_set_resizable (GTK_WINDOW (prefWindow->dialog), FALSE);
00123   gtk_window_set_decorated (GTK_WINDOW (prefWindow->dialog), TRUE);
00124   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (prefWindow->dialog), TRUE);
00125   gtk_window_set_skip_pager_hint (GTK_WINDOW (prefWindow->dialog), TRUE);
00126   gtk_window_set_type_hint (GTK_WINDOW (prefWindow->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00127   gtk_window_set_gravity (GTK_WINDOW (prefWindow->dialog), GDK_GRAVITY_NORTH_EAST);
00128   gtk_window_set_transient_for(GTK_WINDOW(prefWindow->dialog), GTK_WINDOW(topLevelWindow));
00129   gtk_widget_set_size_request (prefWindow->dialog, 240, 220);
00130   
00131   /* Creating "Connection Frame" */
00132   prefWindow->fr_connection = gtk_frame_new (NULL);
00133   gtk_widget_show (prefWindow->fr_connection);
00134   gtk_container_add (GTK_CONTAINER(GTK_DIALOG (prefWindow->dialog)->vbox), prefWindow->fr_connection);
00135   
00136   /* Connection Frame's VBOX */
00137   prefWindow->vbox_connection = gtk_vbox_new (FALSE, 0);
00138   gtk_widget_show (prefWindow->vbox_connection);
00139   gtk_container_add (GTK_CONTAINER (prefWindow->fr_connection), prefWindow->vbox_connection);
00140   
00141   prefWindow->hbox_direct_connection = gtk_hbox_new (FALSE, 0);
00142   gtk_widget_show (prefWindow->hbox_direct_connection);
00143   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_connection), prefWindow->hbox_direct_connection, TRUE, TRUE, 0);
00144   
00145   /* Radio Buttons - Direct/Manual Connetion */
00146   prefWindow->rb_direct_connection = gtk_radio_button_new_with_mnemonic (NULL, "Direct connection to the Internet");
00147   gtk_widget_show (prefWindow->rb_direct_connection);
00148   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_direct_connection), prefWindow->rb_direct_connection, FALSE, FALSE, 0);
00149   prefWindow->rb_direct_connection_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (prefWindow->rb_direct_connection));
00150   
00151   prefWindow->hbox_manual_connection = gtk_hbox_new (FALSE, 0);
00152   gtk_widget_show (prefWindow->hbox_manual_connection);
00153   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_connection), prefWindow->hbox_manual_connection, TRUE, TRUE, 0);
00154   
00155   prefWindow->vbox_manual = gtk_vbox_new (FALSE, 0);
00156   gtk_widget_show (prefWindow->vbox_manual);
00157   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_manual_connection), prefWindow->vbox_manual, TRUE, TRUE, 0);
00158   
00159   prefWindow->rb_manual_connection = gtk_radio_button_new_with_mnemonic (NULL, "Manual proxy configuration");
00160   gtk_widget_show (prefWindow->rb_manual_connection);
00161   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_manual), prefWindow->rb_manual_connection, FALSE, FALSE, 0);
00162   
00163   prefWindow->rb_manual_connection_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (prefWindow->rb_manual_connection));
00164   gtk_radio_button_set_group (GTK_RADIO_BUTTON (prefWindow->rb_manual_connection), prefWindow->rb_direct_connection_group);
00165   
00166   gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefWindow->rb_direct_connection));
00167   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefWindow->rb_direct_connection), config.direct_connection);
00168   
00169   /* HTTP Widget HBOX */
00170   prefWindow->hbox_http = gtk_hbox_new (FALSE, 0);
00171   gtk_widget_show (prefWindow->hbox_http);
00172   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_manual), prefWindow->hbox_http, TRUE, TRUE, 0);
00173   
00174   prefWindow->lb_http = gtk_label_new ("HTTP Proxy:  ");
00175   gtk_widget_show (prefWindow->lb_http);
00176   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_http), prefWindow->lb_http, FALSE, FALSE, 0);
00177   
00178   prefWindow->en_http_proxy = gtk_entry_new ();
00179   gtk_widget_show (prefWindow->en_http_proxy);
00180   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_http), prefWindow->en_http_proxy, TRUE, TRUE, 0);
00181   gtk_widget_modify_font(prefWindow->en_http_proxy, getOrCreateDefaultMinimoFont());
00182   gtk_widget_set_size_request (prefWindow->en_http_proxy, 60, -1);
00183   
00184   prefWindow->lb_port_http = gtk_label_new (" Port: ");
00185   gtk_widget_show (prefWindow->lb_port_http);
00186   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_http), prefWindow->lb_port_http, FALSE, FALSE, 0);
00187   
00188   prefWindow->en_http_port = gtk_entry_new ();
00189   gtk_widget_show (prefWindow->en_http_port);
00190   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_http), prefWindow->en_http_port, TRUE, TRUE, 0);
00191   gtk_widget_set_size_request (prefWindow->en_http_port, 30, -1);
00192   
00193   /* SSL Widget HBOX */
00194   prefWindow->hbox_ssl = gtk_hbox_new (FALSE, 0);
00195   gtk_widget_show (prefWindow->hbox_ssl);
00196   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_manual), prefWindow->hbox_ssl, TRUE, TRUE, 0);
00197   
00198   prefWindow->lb_ssl = gtk_label_new ("SSL Proxy:    ");
00199   gtk_widget_show (prefWindow->lb_ssl);
00200   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ssl), prefWindow->lb_ssl, FALSE, FALSE, 0);
00201   
00202   prefWindow->en_ssl = gtk_entry_new ();
00203   gtk_widget_show (prefWindow->en_ssl);
00204   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ssl), prefWindow->en_ssl, TRUE, TRUE, 0);
00205   gtk_widget_set_size_request (prefWindow->en_ssl, 60, -1);
00206   
00207   prefWindow->lb_ssl_port = gtk_label_new (" Port: ");
00208   gtk_widget_show (prefWindow->lb_ssl_port);
00209   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ssl), prefWindow->lb_ssl_port, FALSE, FALSE, 0);
00210   
00211   prefWindow->en_ssl_port = gtk_entry_new ();
00212   gtk_widget_show (prefWindow->en_ssl_port);
00213   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ssl), prefWindow->en_ssl_port, TRUE, TRUE, 0);
00214   gtk_widget_modify_font(prefWindow->en_ssl, getOrCreateDefaultMinimoFont());
00215   gtk_widget_set_size_request (prefWindow->en_ssl_port, 30, -1);
00216   
00217   /* FTP Widgets HBOX */
00218   prefWindow->hbox_ftp = gtk_hbox_new (FALSE, 0);
00219   gtk_widget_show (prefWindow->hbox_ftp);
00220   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_manual), prefWindow->hbox_ftp, TRUE, TRUE, 0);
00221   
00222   prefWindow->lb_ftp = gtk_label_new ("FTP Proxy:    ");
00223   gtk_widget_show (prefWindow->lb_ftp);
00224   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ftp), prefWindow->lb_ftp, FALSE, FALSE, 0);
00225   
00226   prefWindow->en_ftp_proxy = gtk_entry_new ();
00227   gtk_widget_show (prefWindow->en_ftp_proxy);
00228   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ftp), prefWindow->en_ftp_proxy, TRUE, TRUE, 0);
00229   gtk_widget_set_size_request (prefWindow->en_ftp_proxy, 60, -1);
00230   
00231   prefWindow->lb_ftp_port = gtk_label_new (" Port: ");
00232   gtk_widget_show (prefWindow->lb_ftp_port);
00233   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ftp), prefWindow->lb_ftp_port, FALSE, FALSE, 0);
00234   
00235   prefWindow->en_ftp_port = gtk_entry_new ();
00236   gtk_widget_show (prefWindow->en_ftp_port);
00237   gtk_box_pack_start (GTK_BOX (prefWindow->hbox_ftp), prefWindow->en_ftp_port, TRUE, TRUE, 0);
00238   gtk_widget_modify_font(prefWindow->en_ftp_proxy, getOrCreateDefaultMinimoFont());
00239   gtk_widget_set_size_request (prefWindow->en_ftp_port, 30, -1);
00240   
00241   prefWindow->hbox_noproxy = gtk_hbox_new (FALSE, 0);
00242   gtk_widget_show (prefWindow->hbox_noproxy);
00243   gtk_box_pack_start (GTK_BOX (prefWindow->vbox_connection), prefWindow->hbox_noproxy, TRUE, TRUE, 0);
00244   
00245   if (config.direct_connection == 0) {           
00246     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefWindow->rb_direct_connection), FALSE);
00247     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefWindow->rb_manual_connection), TRUE);
00248     
00249   } else if (config.direct_connection == 1) {
00250     
00251     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefWindow->rb_direct_connection), TRUE);
00252     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefWindow->rb_manual_connection), FALSE);
00253   }
00254   
00255   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_http_proxy), config.http_proxy);
00256   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_http_port), config.http_proxy_port);
00257   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_ssl), config.ssl_proxy);
00258   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_ssl_port), config.ssl_proxy_port);
00259   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_ftp_proxy), config.ftp_proxy);
00260   gtk_entry_set_text (GTK_ENTRY (prefWindow->en_ftp_port), config.ftp_proxy_port);
00261   
00262   /* Creating "Popup Frame" */
00263   prefWindow->fr_popup = gtk_frame_new (NULL);
00264   gtk_widget_show (prefWindow->fr_popup);
00265   gtk_container_add (GTK_CONTAINER(GTK_DIALOG (prefWindow->dialog)->vbox), prefWindow->fr_popup);
00266   
00267   /* Proxy Frame's label */
00268   prefWindow->lb_connection = gtk_label_new ("Configure Proxies:");
00269   gtk_widget_show (prefWindow->lb_connection);
00270   gtk_frame_set_label_widget (GTK_FRAME (prefWindow->fr_connection), prefWindow->lb_connection);
00271   
00272   prefWindow->vbox_popup = gtk_vbox_new (FALSE, 0);
00273   gtk_widget_show (prefWindow->vbox_popup);
00274   gtk_container_add (GTK_CONTAINER (prefWindow->fr_popup), prefWindow->vbox_popup);
00275   
00276   prefWindow->block_popup = gtk_check_button_new_with_label ("Block Popup Windows");
00277   if (config.disable_popups == 1) {
00278     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(prefWindow->block_popup), TRUE);
00279   } else gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(prefWindow->block_popup), FALSE);
00280   
00281   gtk_container_add(GTK_CONTAINER(prefWindow->vbox_popup), prefWindow->block_popup);
00282   
00283   prefWindow->lb_popup = gtk_label_new ("Block Popups");
00284   gtk_widget_show (prefWindow->lb_popup);
00285   gtk_frame_set_label_widget (GTK_FRAME (prefWindow->fr_popup), prefWindow->lb_popup);
00286   
00287   /* Ok and Cancel Button */
00288   prefWindow->cancelbutton = gtk_button_new_with_label("Cancel");
00289   gtk_widget_modify_font(GTK_BIN(prefWindow->cancelbutton)->child, getOrCreateDefaultMinimoFont());
00290   gtk_widget_show (prefWindow->cancelbutton);
00291   gtk_dialog_add_action_widget (GTK_DIALOG (prefWindow->dialog), prefWindow->cancelbutton, GTK_RESPONSE_CANCEL);
00292   gtk_widget_set_size_request (prefWindow->cancelbutton, 10, -1);
00293   
00294   prefWindow->okbutton = gtk_button_new_with_label("Ok");
00295   gtk_widget_modify_font(GTK_BIN(prefWindow->okbutton)->child, getOrCreateDefaultMinimoFont());
00296   gtk_widget_show (prefWindow->okbutton);
00297   gtk_dialog_add_action_widget (GTK_DIALOG (prefWindow->dialog), prefWindow->okbutton, GTK_RESPONSE_OK);
00298   gtk_widget_set_size_request (prefWindow->okbutton, 10, -1);
00299   
00300   /* Setting font styles */
00301   gtk_widget_modify_font(prefWindow->rb_manual_connection, getOrCreateDefaultMinimoFont());
00302   gtk_widget_modify_font(prefWindow->rb_direct_connection, getOrCreateDefaultMinimoFont());
00303   gtk_widget_modify_font(prefWindow->lb_http, getOrCreateDefaultMinimoFont());  
00304   gtk_widget_modify_font(prefWindow->lb_port_http, getOrCreateDefaultMinimoFont());
00305   gtk_widget_modify_font(prefWindow->en_http_port, getOrCreateDefaultMinimoFont());
00306   gtk_widget_modify_font(prefWindow->lb_ssl, getOrCreateDefaultMinimoFont());  
00307   gtk_widget_modify_font(prefWindow->en_ssl, getOrCreateDefaultMinimoFont());
00308   gtk_widget_modify_font(prefWindow->en_ssl_port, getOrCreateDefaultMinimoFont());
00309   gtk_widget_modify_font(prefWindow->lb_ssl_port, getOrCreateDefaultMinimoFont());
00310   gtk_widget_modify_font(prefWindow->lb_ftp, getOrCreateDefaultMinimoFont());
00311   gtk_widget_modify_font(prefWindow->en_ftp_proxy, getOrCreateDefaultMinimoFont());
00312   gtk_widget_modify_font(prefWindow->lb_ftp_port, getOrCreateDefaultMinimoFont());
00313   gtk_widget_modify_font(prefWindow->en_ftp_port, getOrCreateDefaultMinimoFont());
00314   gtk_widget_modify_font(prefWindow->lb_connection, getOrCreateDefaultMinimoFont());
00315   gtk_widget_modify_font(prefWindow->lb_popup, getOrCreateDefaultMinimoFont());
00316   gtk_widget_modify_font(prefWindow->block_popup, getOrCreateDefaultMinimoFont());
00317   
00318   gtk_widget_show_all(prefWindow->dialog);
00319   
00320   /* connection singnals to buttons */
00321   gtk_signal_connect_object(GTK_OBJECT(prefWindow->cancelbutton), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), prefWindow->dialog);
00322   gtk_signal_connect_object(GTK_OBJECT(prefWindow->okbutton), "clicked", GTK_SIGNAL_FUNC(ok_preferences_cb), prefWindow);
00323   
00324   return prefWindow;
00325 }
00326 
00327 void save_preferences_cb (GtkButton *button, PrefWindow *pref) {
00328   
00329   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefWindow->rb_direct_connection)) == TRUE) 
00330     config.direct_connection = 1;
00331   else config.direct_connection = 0;
00332   
00333   config.http_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_http_proxy)));
00334   config.http_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_http_port)));
00335   config.ftp_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_ftp_proxy)));
00336   config.ftp_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_ftp_port)));
00337   config.ssl_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_ssl)));
00338   config.ssl_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (prefWindow->en_ssl_port)));
00339   config.disable_popups = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefWindow->block_popup));
00340   
00341   write_minimo_config();
00342 }
00343 
00344 void ok_preferences_cb (GtkButton *button, PrefWindow *pref) {
00345   
00346   save_preferences_cb (button, pref);
00347   close_preferences_cb (button, pref);
00348 }
00349 
00350 void close_preferences_cb (GtkButton *button, PrefWindow *pref) {
00351   gtk_widget_destroy (prefWindow->dialog);
00352   g_free (pref);
00353 }
00354 
00355 /* Read the current 'minimo config' into his file: $home/.Minimo/config */
00356 void read_minimo_config(void) 
00357 {
00358   FILE *config_file;
00359   gchar *file, *oldfile;
00360   gchar *line, tmpstr[1024];
00361   
00362   gint i, temp;
00363   
00364   user_home = g_strconcat(g_get_home_dir(),NULL);
00365   
00366   oldfile = g_strconcat(user_home,"/.minimorc", NULL);
00367   file = g_strconcat(user_home,"/.Minimo/config", NULL);
00368   if (access(oldfile, F_OK) == 0 && access(file, F_OK) == -1 && errno == ENOENT) {
00369     if (rename(oldfile, file) == 0) {
00370       g_print("Note: .minimorc was moved to %s\n", file);
00371       g_free(oldfile);
00372     } else {
00373       g_warning("Error moving .minimorc to %s: %s\n", file, strerror(errno));
00374       /* we can still read the old file  */
00375       g_free(file); file = oldfile;
00376     }
00377   } else {
00378     g_free(oldfile);
00379   }
00380   
00381   /* defaults */     
00382   config.home = g_strdup("http://www.minimo.org");
00383   config.xsize = 700;
00384   config.ysize = 500;
00385   config.layout = 0;
00386   config.mailer = g_strdup("pronto %t %s %c");
00387   config.max_go = 15;
00388   config.maxpopupitems = 15;
00389   config.java = TRUE;
00390   config.javascript = TRUE;
00391   config.http_proxy = g_strdup("");
00392   config.ftp_proxy = g_strdup("");
00393   config.ftp_proxy_port = g_strdup("");
00394   config.http_proxy_port = g_strdup("");
00395   config.ssl_proxy = g_strdup("");
00396   config.ssl_proxy_port = g_strdup("");
00397   config.no_proxy_for = g_strdup("localhost");
00398   config.direct_connection = 1;
00399   config.popup_in_new_window = 0;
00400   config.disable_popups = 0;
00401   config.current_font_size = DEFAULT_FONT_SIZE;
00402   
00403   config_file = fopen(file,"r");
00404   if (config_file == NULL) {
00405     write_minimo_config();
00406   }
00407   
00408   config_file = fopen(file,"r");
00409   
00410   line = (gchar *)g_malloc(1024);
00411   
00412   while(fgets(line,1024,config_file) != NULL) { 
00413     line[strlen(line)-1] = '\0';
00414     if (g_strncasecmp(line,"home=",5) == 0) {
00415       config.home = g_strdup(line+5);
00416       if (g_strcasecmp(config.home,"") == 0) {
00417         g_free(config.home);
00418         config.home = g_strdup("about:blank");
00419       }
00420     } else if (g_strncasecmp(line,"xsize=",6) == 0) {
00421       config.xsize = atoi(line+6);
00422     } else if (g_strncasecmp(line,"ysize=",6) == 0) {
00423       config.ysize = atoi(line+6);
00424     } else if (g_strncasecmp(line,"layout=",7) == 0) {
00425       config.layout = atoi(line+7);
00426     } else if (g_strncasecmp(line,"mailer=",7) == 0) {
00427       g_free(config.mailer);
00428       config.mailer = g_strdup(line+7);
00429     } else if (g_strncasecmp(line,"maxpopup=",9) == 0) {
00430       config.maxpopupitems = atoi(line+9);
00431     } else if (g_strncasecmp(line,"http_proxy=",11) == 0) {
00432       g_free(config.http_proxy);
00433       config.http_proxy = g_strdup(line+11);
00434     } else if (g_strncasecmp(line,"http_proxy_port=",16) == 0) {
00435       g_free(config.http_proxy_port);
00436       config.http_proxy_port = g_strdup(line+16);
00437     } else if (g_strncasecmp(line,"ftp_proxy=",10) == 0) {
00438       g_free(config.ftp_proxy);
00439       config.ftp_proxy = g_strdup(line+10);
00440     } else if (g_strncasecmp(line,"ftp_proxy_port=",15) == 0) {
00441       g_free(config.ftp_proxy_port);
00442       config.ftp_proxy_port = g_strdup(line+15);        
00443     } else if (g_strncasecmp(line,"no_proxy_for=",13) == 0) {
00444       g_free(config.no_proxy_for);
00445       config.no_proxy_for = g_strdup(line+13);
00446     } else if (g_strncasecmp(line,"ssl_proxy=",10) == 0) {
00447       g_free(config.ssl_proxy);
00448       config.ssl_proxy = g_strdup(line+10);
00449     } else if (g_strncasecmp(line,"ssl_proxy_port=",15) == 0) {
00450       g_free(config.ssl_proxy_port);
00451       config.ssl_proxy_port = g_strdup(line+15);
00452     } else if (g_strncasecmp(line,"no_proxy_for=",13) == 0) {
00453       g_free(config.no_proxy_for);
00454       config.no_proxy_for = g_strdup(line+13);
00455     } else if (g_strncasecmp(line,"direct_connection=",18) == 0) {
00456       config.direct_connection = atoi(line+18);
00457     } else if (g_strncasecmp(line,"max_go=",7) == 0) {
00458       config.max_go = atoi(line+7);
00459     } else if (g_strncasecmp(line,"popup_in_new_window=",20) == 0) {
00460       config.popup_in_new_window = atoi (line + 20);
00461     } else if (g_strncasecmp(line,"disable_popups=",15) == 0) {
00462       config.disable_popups = atoi(line+15);
00463     } else if (g_strncasecmp(line,"fontsize_",9) == 0) {
00464       for (i = 0; i < LANG_FONT_NUM; i++) {
00465         g_snprintf (tmpstr, 1024, "%s=", lang_font_item[i]);
00466         if (g_strncasecmp(line+9,tmpstr,strlen(tmpstr)))
00467           continue;
00468         config.font_size[i] = atoi(line+9+strlen(tmpstr));
00469       };
00470     } else if (g_strncasecmp(line,"min_fontsize_",13) == 0) {
00471       for (i=0; i < LANG_FONT_NUM; i++) {
00472         g_snprintf(tmpstr,1024,"%s=",lang_font_item[i]);
00473         if (g_strncasecmp(line+13,tmpstr,strlen(tmpstr)))
00474           continue;
00475         config.min_font_size[i] = atoi(line+13+strlen(tmpstr));
00476       }
00477     } else if (g_strncasecmp(line,"java=",5) == 0) {
00478       temp = atoi(line+5);
00479       if (temp) {
00480         config.java = TRUE;
00481       } else {
00482         config.java = FALSE;
00483       }
00484     } else if (g_strncasecmp(line,"javascript=",11) == 0) {
00485       temp = atoi(line+11);
00486       if (temp) {
00487         config.javascript = TRUE;
00488       } else {
00489         config.javascript = FALSE;
00490       }
00491     }
00492   }
00493   fflush (config_file);
00494   fclose(config_file);
00495   g_free(line);
00496   g_free(file);
00497 }
00498 
00499 /* Write the current 'minimo config' into his file: $home/.Minimo/config */
00500 void write_minimo_config() 
00501 {
00502   FILE *config_file;
00503   gchar *file;
00504   
00505   file = g_strconcat(user_home,"/.Minimo/config",NULL);
00506   config_file = fopen(file,"w");
00507   if (config_file == NULL) {
00508     g_error ("Cannot write config file!");
00509     return ;
00510   }
00511   
00512   fprintf(config_file,"home=%s\n",config.home);
00513   fprintf(config_file,"xsize=%d\n",config.xsize);
00514   fprintf(config_file,"ysize=%d\n",config.ysize);
00515   fprintf(config_file,"layout=%d\n",config.layout);
00516   fprintf(config_file,"mailer=%s\n",config.mailer);
00517   fprintf(config_file,"maxpopup=%d\n",config.maxpopupitems);
00518   fprintf(config_file,"http_proxy=%s\n",config.http_proxy);
00519   fprintf(config_file,"http_proxy_port=%s\n",config.http_proxy_port);
00520   fprintf(config_file,"ftp_proxy=%s\n",config.ftp_proxy);
00521   fprintf(config_file,"ftp_proxy_port=%s\n",config.ftp_proxy_port);
00522   fprintf(config_file,"ssl_proxy=%s\n",config.ssl_proxy);
00523   fprintf(config_file,"ssl_proxy_port=%s\n",config.ssl_proxy_port);
00524   fprintf(config_file,"no_proxy_for=%s\n",config.no_proxy_for);
00525   fprintf(config_file,"direct_connection=%d\n",config.direct_connection);
00526   fprintf(config_file,"max_go=%d\n",config.max_go);
00527   fprintf(config_file,"popup_in_new_window=%d\n",config.popup_in_new_window);
00528   fprintf(config_file,"disable_popups=%d\n",config.disable_popups);
00529   
00530   if (config.javascript == TRUE) {      
00531     fprintf(config_file,"javascript=1\n");
00532   } else {
00533     fprintf(config_file,"javascript=0\n");
00534   } 
00535   
00536   if (config.java == TRUE) {
00537     fprintf(config_file,"java=1\n");
00538   } else {
00539     fprintf(config_file,"java=0\n");
00540   }
00541   
00542   fclose(config_file);
00543   g_free(file);
00544   set_mozilla_prefs ();
00545 }
00546 
00547 void set_mozilla_prefs(void)
00548 {
00549   gint i, disk_cache= 0, mem_cache= 0;
00550   gchar *cachedir, tmpstr[1024];
00551   
00552   mozilla_preference_set_boolean ("security.warn_entering_secure", FALSE);
00553   mozilla_preference_set_boolean ("security.warn_leaving_secure", FALSE);
00554   mozilla_preference_set_boolean ("security.warn_submit_insecure", FALSE);
00555   mozilla_preference_set_boolean ("security.warn_viewing_mixed", FALSE);
00556   
00557   if (config.disable_popups)
00558     mozilla_preference_set_boolean ("dom.disable_open_during_load", TRUE);
00559   else 
00560     mozilla_preference_set_boolean ("dom.disable_open_during_load", FALSE);
00561   
00562   mozilla_preference_set_boolean("nglayout.widget.gfxscrollbars", TRUE);
00563   
00564   for (i = 0; i < LANG_FONT_NUM; i++) {
00565     g_snprintf (tmpstr, 1024, "font.size.variable.%s", lang_font_item[i]);
00566     mozilla_preference_set_int(tmpstr,DEFAULT_FONT_SIZE);
00567     
00568     g_snprintf(tmpstr, 1024, "font.min-size.variable.%s", lang_font_item[i]);
00569     mozilla_preference_set_int(tmpstr, DEFAULT_MIN_FONT_SIZE);
00570   }
00571   
00572   mozilla_preference_set_boolean ("security.enable_java", config.java);
00573   mozilla_preference_set_boolean ("javascript.enabled", config.javascript);
00574   mozilla_preference_set_boolean ("browser.view_source.syntax_highlight", TRUE);
00575   cachedir = g_strconcat(user_home,"/.Minimo/cache",NULL);
00576   mkdir(cachedir,0755);
00577   mozilla_preference_set("browser.cache.directory",cachedir);
00578   g_free(cachedir);
00579   if ((disk_cache > 0) || (mem_cache > 0)) {
00580     mozilla_preference_set_boolean("browser.cache.disk.enable",TRUE);
00581     mozilla_preference_set_boolean("browser.cache.enable", TRUE);
00582   }
00583   else
00584   {
00585     mozilla_preference_set_boolean("browser.cache.disk.enable",FALSE);
00586     mozilla_preference_set_boolean("browser.cache.enable", FALSE);
00587   }
00588   if (disk_cache > 0) {
00589     mozilla_preference_set_boolean("browser.cache.disk.enable",TRUE);
00590     mozilla_preference_set_int("browser.cache.disk_cache_size",disk_cache);
00591     mozilla_preference_set_int("browser.cache.disk.capacity",disk_cache);
00592   }
00593   else 
00594   {
00595     mozilla_preference_set_boolean("browser.cache.disk.enable",FALSE);
00596     mozilla_preference_set_int("browser.cache.disk_cache_size", 0);
00597     mozilla_preference_set_int("browser.cache.disk.capacity",0);
00598   }
00599   
00600   if (mem_cache > 0)  {
00601     mozilla_preference_set_int("browser.cache.memory_cache_size",mem_cache);
00602     mozilla_preference_set_int("browser.cache.memory.capacity",mem_cache);
00603   } else {
00604     mozilla_preference_set_int("browser.cache.memory_cache_size", 0);   
00605     mozilla_preference_set_int("browser.cache.memory.capacity",0);
00606   }
00607   
00608   /* set proxy stuff */
00609   minimo_set_proxy_prefs();
00610   
00611   mozilla_save_prefs ();
00612 }
00613 
00614 void minimo_set_proxy_prefs(void)
00615 {
00616   gint network_type = 0;
00617   
00618   if (config.direct_connection) {
00619     mozilla_preference_set("network.proxy.http","");
00620     mozilla_preference_set("network.proxy.ssl","");
00621     mozilla_preference_set("network.proxy.ftp","");
00622     mozilla_preference_set("network.proxy.no_proxies_on", " ");
00623     mozilla_preference_set_int("network.proxy.type",network_type);
00624   } else {
00625     
00626     if (strlen(config.http_proxy) != 0 && strcmp(config.http_proxy,"") != 0 && strlen(config.http_proxy_port) > 0 && strcmp(config.http_proxy_port,"") != 0) {
00627       
00628       mozilla_preference_set_int ("network.proxy.type", 1);
00629       network_type=1;
00630       mozilla_preference_set ("network.proxy.http", config.http_proxy);
00631       mozilla_preference_set_int ("network.proxy.http_port", atoi(config.http_proxy_port));              
00632     }
00633     
00634     if (strlen(config.ftp_proxy) != 0 && strcmp(config.ftp_proxy,"") != 0 && strlen(config.ftp_proxy_port) > 0 && strcmp(config.http_proxy_port,"") != 0) {
00635       if (!network_type)
00636         mozilla_preference_set_int("network.proxy.type", 1);
00637       mozilla_preference_set ("network.proxy.ftp", config.ftp_proxy);
00638       mozilla_preference_set_int ("network.proxy.ftp_port", atoi(config.ftp_proxy_port));
00639     }
00640     
00641     if (strlen(config.ssl_proxy) != 0 && strcmp(config.ssl_proxy,"") != 0 && strlen(config.ssl_proxy_port) > 0 && strcmp      (config.ssl_proxy_port,"") != 0) {
00642       if (!network_type)
00643         mozilla_preference_set_int("network.proxy.type", 1);
00644       mozilla_preference_set ("network.proxy.ssl", config.ssl_proxy);
00645       mozilla_preference_set_int ("network.proxy.ssl_port", atoi(config.ssl_proxy_port));
00646     }
00647        
00648     if (strlen(config.no_proxy_for) != 0)
00649       mozilla_preference_set("network.proxy.no_proxies_on", config.no_proxy_for);
00650     else
00651       mozilla_preference_set("network.proxy.no_proxies_on", " ");
00652   }
00653 }