Back to index

lightning-sunbird  0.9+nobinonly
minimo_preference.cpp
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 
00051 #include "minimo_preference.h"
00052 
00053 extern gchar *gMinimoUserHomePath;
00054 
00055 ConfigData gPreferenceConfigStruct;
00056 PrefWindow *gPreferenceWinStruct;
00057 
00058 /* Variable to enable pango settings */
00059 static PangoFontDescription* gDefaultMinimoFont = NULL;
00060 
00061 PrefWindow * build_pref_window (GtkWidget *topLevelWindow) {
00062   
00063   gPreferenceWinStruct = g_new0(PrefWindow,1);
00064   
00065   gPreferenceWinStruct->dialog = gtk_dialog_new ();
00066   
00067   gtk_window_set_title (GTK_WINDOW (gPreferenceWinStruct->dialog), ("Prefs Window"));
00068   gtk_window_set_position (GTK_WINDOW (gPreferenceWinStruct->dialog), GTK_WIN_POS_CENTER_ON_PARENT);
00069   gtk_window_set_modal (GTK_WINDOW (gPreferenceWinStruct->dialog), TRUE);
00070   gtk_window_set_resizable (GTK_WINDOW (gPreferenceWinStruct->dialog), FALSE);
00071   gtk_window_set_decorated (GTK_WINDOW (gPreferenceWinStruct->dialog), TRUE);
00072   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (gPreferenceWinStruct->dialog), TRUE);
00073   gtk_window_set_skip_pager_hint (GTK_WINDOW (gPreferenceWinStruct->dialog), TRUE);
00074   gtk_window_set_type_hint (GTK_WINDOW (gPreferenceWinStruct->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00075   gtk_window_set_gravity (GTK_WINDOW (gPreferenceWinStruct->dialog), GDK_GRAVITY_NORTH_EAST);
00076   gtk_window_set_transient_for(GTK_WINDOW(gPreferenceWinStruct->dialog), GTK_WINDOW(topLevelWindow));
00077   gtk_widget_set_size_request (gPreferenceWinStruct->dialog, 240, 220);
00078   
00079   /* Creating "Connection Frame" */
00080   gPreferenceWinStruct->fr_connection = gtk_frame_new (NULL);
00081   gtk_widget_show (gPreferenceWinStruct->fr_connection);
00082   gtk_container_add (GTK_CONTAINER(GTK_DIALOG (gPreferenceWinStruct->dialog)->vbox), gPreferenceWinStruct->fr_connection);
00083   
00084   /* Connection Frame's VBOX */
00085   gPreferenceWinStruct->vbox_connection = gtk_vbox_new (FALSE, 0);
00086   gtk_widget_show (gPreferenceWinStruct->vbox_connection);
00087   gtk_container_add (GTK_CONTAINER (gPreferenceWinStruct->fr_connection), gPreferenceWinStruct->vbox_connection);
00088   
00089   gPreferenceWinStruct->hbox_direct_connection = gtk_hbox_new (FALSE, 0);
00090   gtk_widget_show (gPreferenceWinStruct->hbox_direct_connection);
00091   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_connection), gPreferenceWinStruct->hbox_direct_connection, TRUE, TRUE, 0);
00092   
00093   /* Radio Buttons - Direct/Manual Connetion */
00094   gPreferenceWinStruct->rb_direct_connection = gtk_radio_button_new_with_mnemonic (NULL, "Direct connection to the Internet");
00095   gtk_widget_show (gPreferenceWinStruct->rb_direct_connection);
00096   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_direct_connection), gPreferenceWinStruct->rb_direct_connection, FALSE, FALSE, 0);
00097   gPreferenceWinStruct->rb_direct_connection_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gPreferenceWinStruct->rb_direct_connection));
00098   
00099   gPreferenceWinStruct->hbox_manual_connection = gtk_hbox_new (FALSE, 0);
00100   gtk_widget_show (gPreferenceWinStruct->hbox_manual_connection);
00101   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_connection), gPreferenceWinStruct->hbox_manual_connection, TRUE, TRUE, 0);
00102   
00103   gPreferenceWinStruct->vbox_manual = gtk_vbox_new (FALSE, 0);
00104   gtk_widget_show (gPreferenceWinStruct->vbox_manual);
00105   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_manual_connection), gPreferenceWinStruct->vbox_manual, TRUE, TRUE, 0);
00106   
00107   gPreferenceWinStruct->rb_manual_connection = gtk_radio_button_new_with_mnemonic (NULL, "Manual proxy configuration");
00108   gtk_widget_show (gPreferenceWinStruct->rb_manual_connection);
00109   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_manual), gPreferenceWinStruct->rb_manual_connection, FALSE, FALSE, 0);
00110   
00111   gPreferenceWinStruct->rb_manual_connection_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gPreferenceWinStruct->rb_manual_connection));
00112   gtk_radio_button_set_group (GTK_RADIO_BUTTON (gPreferenceWinStruct->rb_manual_connection), gPreferenceWinStruct->rb_direct_connection_group);
00113   
00114   gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_direct_connection));
00115   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_direct_connection), gPreferenceConfigStruct.direct_connection);
00116   
00117   /* HTTP Widget HBOX */
00118   gPreferenceWinStruct->hbox_http = gtk_hbox_new (FALSE, 0);
00119   gtk_widget_show (gPreferenceWinStruct->hbox_http);
00120   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_manual), gPreferenceWinStruct->hbox_http, TRUE, TRUE, 0);
00121   
00122   gPreferenceWinStruct->lb_http = gtk_label_new ("HTTP Proxy:  ");
00123   gtk_widget_show (gPreferenceWinStruct->lb_http);
00124   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_http), gPreferenceWinStruct->lb_http, FALSE, FALSE, 0);
00125   
00126   gPreferenceWinStruct->en_http_proxy = gtk_entry_new ();
00127   gtk_widget_show (gPreferenceWinStruct->en_http_proxy);
00128   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_http), gPreferenceWinStruct->en_http_proxy, TRUE, TRUE, 0);
00129   gtk_widget_modify_font(gPreferenceWinStruct->en_http_proxy, getOrCreateDefaultMinimoFont());
00130   gtk_widget_set_size_request (gPreferenceWinStruct->en_http_proxy, 60, -1);
00131   
00132   gPreferenceWinStruct->lb_port_http = gtk_label_new (" Port: ");
00133   gtk_widget_show (gPreferenceWinStruct->lb_port_http);
00134   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_http), gPreferenceWinStruct->lb_port_http, FALSE, FALSE, 0);
00135   
00136   gPreferenceWinStruct->en_http_port = gtk_entry_new ();
00137   gtk_widget_show (gPreferenceWinStruct->en_http_port);
00138   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_http), gPreferenceWinStruct->en_http_port, TRUE, TRUE, 0);
00139   gtk_widget_set_size_request (gPreferenceWinStruct->en_http_port, 30, -1);
00140   
00141   /* SSL Widget HBOX */
00142   gPreferenceWinStruct->hbox_ssl = gtk_hbox_new (FALSE, 0);
00143   gtk_widget_show (gPreferenceWinStruct->hbox_ssl);
00144   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_manual), gPreferenceWinStruct->hbox_ssl, TRUE, TRUE, 0);
00145   
00146   gPreferenceWinStruct->lb_ssl = gtk_label_new ("SSL Proxy:    ");
00147   gtk_widget_show (gPreferenceWinStruct->lb_ssl);
00148   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ssl), gPreferenceWinStruct->lb_ssl, FALSE, FALSE, 0);
00149   
00150   gPreferenceWinStruct->en_ssl = gtk_entry_new ();
00151   gtk_widget_show (gPreferenceWinStruct->en_ssl);
00152   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ssl), gPreferenceWinStruct->en_ssl, TRUE, TRUE, 0);
00153   gtk_widget_set_size_request (gPreferenceWinStruct->en_ssl, 60, -1);
00154   
00155   gPreferenceWinStruct->lb_ssl_port = gtk_label_new (" Port: ");
00156   gtk_widget_show (gPreferenceWinStruct->lb_ssl_port);
00157   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ssl), gPreferenceWinStruct->lb_ssl_port, FALSE, FALSE, 0);
00158   
00159   gPreferenceWinStruct->en_ssl_port = gtk_entry_new ();
00160   gtk_widget_show (gPreferenceWinStruct->en_ssl_port);
00161   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ssl), gPreferenceWinStruct->en_ssl_port, TRUE, TRUE, 0);
00162   gtk_widget_modify_font(gPreferenceWinStruct->en_ssl, getOrCreateDefaultMinimoFont());
00163   gtk_widget_set_size_request (gPreferenceWinStruct->en_ssl_port, 30, -1);
00164   
00165   /* FTP Widgets HBOX */
00166   gPreferenceWinStruct->hbox_ftp = gtk_hbox_new (FALSE, 0);
00167   gtk_widget_show (gPreferenceWinStruct->hbox_ftp);
00168   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_manual), gPreferenceWinStruct->hbox_ftp, TRUE, TRUE, 0);
00169   
00170   gPreferenceWinStruct->lb_ftp = gtk_label_new ("FTP Proxy:    ");
00171   gtk_widget_show (gPreferenceWinStruct->lb_ftp);
00172   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ftp), gPreferenceWinStruct->lb_ftp, FALSE, FALSE, 0);
00173   
00174   gPreferenceWinStruct->en_ftp_proxy = gtk_entry_new ();
00175   gtk_widget_show (gPreferenceWinStruct->en_ftp_proxy);
00176   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ftp), gPreferenceWinStruct->en_ftp_proxy, TRUE, TRUE, 0);
00177   gtk_widget_set_size_request (gPreferenceWinStruct->en_ftp_proxy, 60, -1);
00178   
00179   gPreferenceWinStruct->lb_ftp_port = gtk_label_new (" Port: ");
00180   gtk_widget_show (gPreferenceWinStruct->lb_ftp_port);
00181   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ftp), gPreferenceWinStruct->lb_ftp_port, FALSE, FALSE, 0);
00182   
00183   gPreferenceWinStruct->en_ftp_port = gtk_entry_new ();
00184   gtk_widget_show (gPreferenceWinStruct->en_ftp_port);
00185   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->hbox_ftp), gPreferenceWinStruct->en_ftp_port, TRUE, TRUE, 0);
00186   gtk_widget_modify_font(gPreferenceWinStruct->en_ftp_proxy, getOrCreateDefaultMinimoFont());
00187   gtk_widget_set_size_request (gPreferenceWinStruct->en_ftp_port, 30, -1);
00188   
00189   gPreferenceWinStruct->hbox_noproxy = gtk_hbox_new (FALSE, 0);
00190   gtk_widget_show (gPreferenceWinStruct->hbox_noproxy);
00191   gtk_box_pack_start (GTK_BOX (gPreferenceWinStruct->vbox_connection), gPreferenceWinStruct->hbox_noproxy, TRUE, TRUE, 0);
00192   
00193   if (gPreferenceConfigStruct.direct_connection == 0) {        
00194     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_direct_connection), FALSE);
00195     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_manual_connection), TRUE);
00196     
00197   } else if (gPreferenceConfigStruct.direct_connection == 1) {
00198     
00199     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_direct_connection), TRUE);
00200     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_manual_connection), FALSE);
00201   }
00202   
00203   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_http_proxy), gPreferenceConfigStruct.http_proxy);
00204   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_http_port), gPreferenceConfigStruct.http_proxy_port);
00205   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_ssl), gPreferenceConfigStruct.ssl_proxy);
00206   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_ssl_port), gPreferenceConfigStruct.ssl_proxy_port);
00207   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_ftp_proxy), gPreferenceConfigStruct.ftp_proxy);
00208   gtk_entry_set_text (GTK_ENTRY (gPreferenceWinStruct->en_ftp_port), gPreferenceConfigStruct.ftp_proxy_port);
00209   
00210   /* Creating "Popup Frame" */
00211   gPreferenceWinStruct->fr_popup = gtk_frame_new (NULL);
00212   gtk_widget_show (gPreferenceWinStruct->fr_popup);
00213   gtk_container_add (GTK_CONTAINER(GTK_DIALOG (gPreferenceWinStruct->dialog)->vbox), gPreferenceWinStruct->fr_popup);
00214   
00215   /* Proxy Frame's label */
00216   gPreferenceWinStruct->lb_connection = gtk_label_new ("Configure Proxies:");
00217   gtk_widget_show (gPreferenceWinStruct->lb_connection);
00218   gtk_frame_set_label_widget (GTK_FRAME (gPreferenceWinStruct->fr_connection), gPreferenceWinStruct->lb_connection);
00219   
00220   gPreferenceWinStruct->vbox_popup = gtk_vbox_new (FALSE, 0);
00221   gtk_widget_show (gPreferenceWinStruct->vbox_popup);
00222   gtk_container_add (GTK_CONTAINER (gPreferenceWinStruct->fr_popup), gPreferenceWinStruct->vbox_popup);
00223   
00224   gPreferenceWinStruct->block_popup = gtk_check_button_new_with_label ("Block Popup Windows");
00225   if (gPreferenceConfigStruct.disable_popups == 1) {
00226     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gPreferenceWinStruct->block_popup), TRUE);
00227   } else gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(gPreferenceWinStruct->block_popup), FALSE);
00228   
00229   gtk_container_add(GTK_CONTAINER(gPreferenceWinStruct->vbox_popup), gPreferenceWinStruct->block_popup);
00230   
00231   gPreferenceWinStruct->lb_popup = gtk_label_new ("Block Popups");
00232   gtk_widget_show (gPreferenceWinStruct->lb_popup);
00233   gtk_frame_set_label_widget (GTK_FRAME (gPreferenceWinStruct->fr_popup), gPreferenceWinStruct->lb_popup);
00234   
00235   /* Ok and Cancel Button */
00236   gPreferenceWinStruct->cancelbutton = gtk_button_new_with_label("Cancel");
00237   gtk_widget_modify_font(GTK_BIN(gPreferenceWinStruct->cancelbutton)->child, getOrCreateDefaultMinimoFont());
00238   gtk_widget_show (gPreferenceWinStruct->cancelbutton);
00239   gtk_dialog_add_action_widget (GTK_DIALOG (gPreferenceWinStruct->dialog), gPreferenceWinStruct->cancelbutton, GTK_RESPONSE_CANCEL);
00240   gtk_widget_set_size_request (gPreferenceWinStruct->cancelbutton, 10, -1);
00241   
00242   gPreferenceWinStruct->okbutton = gtk_button_new_with_label("Ok");
00243   gtk_widget_modify_font(GTK_BIN(gPreferenceWinStruct->okbutton)->child, getOrCreateDefaultMinimoFont());
00244   gtk_widget_show (gPreferenceWinStruct->okbutton);
00245   gtk_dialog_add_action_widget (GTK_DIALOG (gPreferenceWinStruct->dialog), gPreferenceWinStruct->okbutton, GTK_RESPONSE_OK);
00246   gtk_widget_set_size_request (gPreferenceWinStruct->okbutton, 10, -1);
00247   
00248   /* Setting font styles */
00249   gtk_widget_modify_font(gPreferenceWinStruct->rb_manual_connection, getOrCreateDefaultMinimoFont());
00250   gtk_widget_modify_font(gPreferenceWinStruct->rb_direct_connection, getOrCreateDefaultMinimoFont());
00251   gtk_widget_modify_font(gPreferenceWinStruct->lb_http, getOrCreateDefaultMinimoFont());  
00252   gtk_widget_modify_font(gPreferenceWinStruct->lb_port_http, getOrCreateDefaultMinimoFont());
00253   gtk_widget_modify_font(gPreferenceWinStruct->en_http_port, getOrCreateDefaultMinimoFont());
00254   gtk_widget_modify_font(gPreferenceWinStruct->lb_ssl, getOrCreateDefaultMinimoFont());  
00255   gtk_widget_modify_font(gPreferenceWinStruct->en_ssl, getOrCreateDefaultMinimoFont());
00256   gtk_widget_modify_font(gPreferenceWinStruct->en_ssl_port, getOrCreateDefaultMinimoFont());
00257   gtk_widget_modify_font(gPreferenceWinStruct->lb_ssl_port, getOrCreateDefaultMinimoFont());
00258   gtk_widget_modify_font(gPreferenceWinStruct->lb_ftp, getOrCreateDefaultMinimoFont());
00259   gtk_widget_modify_font(gPreferenceWinStruct->en_ftp_proxy, getOrCreateDefaultMinimoFont());
00260   gtk_widget_modify_font(gPreferenceWinStruct->lb_ftp_port, getOrCreateDefaultMinimoFont());
00261   gtk_widget_modify_font(gPreferenceWinStruct->en_ftp_port, getOrCreateDefaultMinimoFont());
00262   gtk_widget_modify_font(gPreferenceWinStruct->lb_connection, getOrCreateDefaultMinimoFont());
00263   gtk_widget_modify_font(gPreferenceWinStruct->lb_popup, getOrCreateDefaultMinimoFont());
00264   gtk_widget_modify_font(gPreferenceWinStruct->block_popup, getOrCreateDefaultMinimoFont());
00265   
00266   gtk_widget_show_all(gPreferenceWinStruct->dialog);
00267   
00268   /* connection singnals to buttons */
00269   gtk_signal_connect_object(GTK_OBJECT(gPreferenceWinStruct->cancelbutton), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), gPreferenceWinStruct->dialog);
00270   gtk_signal_connect_object(GTK_OBJECT(gPreferenceWinStruct->okbutton), "clicked", GTK_SIGNAL_FUNC(ok_preferences_cb), gPreferenceWinStruct);
00271   
00272   return gPreferenceWinStruct;
00273 }
00274 
00275 void save_preferences_cb (GtkButton *button, PrefWindow *pref) {
00276   
00277   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->rb_direct_connection)) == TRUE) 
00278     gPreferenceConfigStruct.direct_connection = 1;
00279   else gPreferenceConfigStruct.direct_connection = 0;
00280   
00281   gPreferenceConfigStruct.http_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_http_proxy)));
00282   gPreferenceConfigStruct.http_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_http_port)));
00283   gPreferenceConfigStruct.ftp_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_ftp_proxy)));
00284   gPreferenceConfigStruct.ftp_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_ftp_port)));
00285   gPreferenceConfigStruct.ssl_proxy = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_ssl)));
00286   gPreferenceConfigStruct.ssl_proxy_port = g_strdup (gtk_entry_get_text (GTK_ENTRY (gPreferenceWinStruct->en_ssl_port)));
00287   gPreferenceConfigStruct.disable_popups = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gPreferenceWinStruct->block_popup));
00288   
00289   write_minimo_config ();
00290 }
00291 
00292 void ok_preferences_cb (GtkButton *button, PrefWindow *pref) {
00293   
00294   save_preferences_cb (button, pref);
00295   close_preferences_cb (button, pref);
00296 }
00297 
00298 void close_preferences_cb (GtkButton *button, PrefWindow *pref) {
00299   gtk_widget_destroy (gPreferenceWinStruct->dialog);
00300   g_free (pref);
00301 }
00302 
00303 /* Read the current 'minimo's preferences and configs' into his file: $home/.Minimo/config */
00304 void read_minimo_config (void) 
00305 {
00306   FILE *config_file;
00307   gchar *file, *oldfile;
00308   gchar *line, tmpstr[1024];
00309   
00310   gint i, temp;
00311   
00312   gMinimoUserHomePath = g_strconcat(g_get_home_dir(),NULL);
00313   
00314   oldfile = g_strconcat(gMinimoUserHomePath,"/.minimorc", NULL);
00315   file = g_strconcat(gMinimoUserHomePath,"/.Minimo/config", NULL);
00316   if (access(oldfile, F_OK) == 0 && access(file, F_OK) == -1 && errno == ENOENT) {
00317     if (rename(oldfile, file) == 0) {
00318       g_print("Note: .minimorc was moved to %s\n", file);
00319       g_free(oldfile);
00320     } else {
00321       g_warning("Error moving .minimorc to %s: %s\n", file, strerror(errno));
00322       /* we can still read the old file  */
00323       g_free(file); file = oldfile;
00324     }
00325   } else {
00326     g_free(oldfile);
00327   }
00328   
00329   /* defaults */     
00330   gPreferenceConfigStruct.home = g_strdup("http://www.minimo.org");
00331   gPreferenceConfigStruct.xsize = 700;
00332   gPreferenceConfigStruct.ysize = 500;
00333   gPreferenceConfigStruct.layout = 0;
00334   gPreferenceConfigStruct.mailer = g_strdup("pronto %t %s %c");
00335   gPreferenceConfigStruct.max_go = 15;
00336   gPreferenceConfigStruct.maxpopupitems = 15;
00337   gPreferenceConfigStruct.java = TRUE;
00338   gPreferenceConfigStruct.javascript = TRUE;
00339   gPreferenceConfigStruct.http_proxy = g_strdup("");
00340   gPreferenceConfigStruct.ftp_proxy = g_strdup("");
00341   gPreferenceConfigStruct.ftp_proxy_port = g_strdup("");
00342   gPreferenceConfigStruct.http_proxy_port = g_strdup("");
00343   gPreferenceConfigStruct.ssl_proxy = g_strdup("");
00344   gPreferenceConfigStruct.ssl_proxy_port = g_strdup("");
00345   gPreferenceConfigStruct.no_proxy_for = g_strdup("localhost");
00346   gPreferenceConfigStruct.direct_connection = 1;
00347   gPreferenceConfigStruct.popup_in_new_window = 0;
00348   gPreferenceConfigStruct.disable_popups = 0;
00349   gPreferenceConfigStruct.current_font_size = DEFAULT_FONT_SIZE;
00350   for (i=0; i < LANG_FONT_NUM; i++) {
00351     gPreferenceConfigStruct.min_font_size [i]= DEFAULT_MIN_FONT_SIZE;
00352   }
00353   
00354   config_file = fopen(file,"r");
00355   if (config_file == NULL) {
00356     write_minimo_config ();
00357   }
00358   
00359   config_file = fopen(file,"r");
00360   
00361   line = (gchar *)g_malloc(1024);
00362   
00363   while(fgets(line,1024,config_file) != NULL) { 
00364     line[strlen(line)-1] = '\0';
00365     if (g_strncasecmp(line,"home=",5) == 0) {
00366       gPreferenceConfigStruct.home = g_strdup(line+5);
00367       if (g_strcasecmp(gPreferenceConfigStruct.home,"") == 0) {
00368         g_free(gPreferenceConfigStruct.home);
00369         gPreferenceConfigStruct.home = g_strdup("about:blank");
00370       }
00371     } else if (g_strncasecmp(line,"xsize=",6) == 0) {
00372       gPreferenceConfigStruct.xsize = atoi(line+6);
00373     } else if (g_strncasecmp(line,"ysize=",6) == 0) {
00374       gPreferenceConfigStruct.ysize = atoi(line+6);
00375     } else if (g_strncasecmp(line,"layout=",7) == 0) {
00376       gPreferenceConfigStruct.layout = atoi(line+7);
00377     } else if (g_strncasecmp(line,"mailer=",7) == 0) {
00378       g_free(gPreferenceConfigStruct.mailer);
00379       gPreferenceConfigStruct.mailer = g_strdup(line+7);
00380     } else if (g_strncasecmp(line,"maxpopup=",9) == 0) {
00381       gPreferenceConfigStruct.maxpopupitems = atoi(line+9);
00382     } else if (g_strncasecmp(line,"http_proxy=",11) == 0) {
00383       g_free(gPreferenceConfigStruct.http_proxy);
00384       gPreferenceConfigStruct.http_proxy = g_strdup(line+11);
00385     } else if (g_strncasecmp(line,"http_proxy_port=",16) == 0) {
00386       g_free(gPreferenceConfigStruct.http_proxy_port);
00387       gPreferenceConfigStruct.http_proxy_port = g_strdup(line+16);
00388     } else if (g_strncasecmp(line,"ftp_proxy=",10) == 0) {
00389       g_free(gPreferenceConfigStruct.ftp_proxy);
00390       gPreferenceConfigStruct.ftp_proxy = g_strdup(line+10);
00391     } else if (g_strncasecmp(line,"ftp_proxy_port=",15) == 0) {
00392       g_free(gPreferenceConfigStruct.ftp_proxy_port);
00393       gPreferenceConfigStruct.ftp_proxy_port = g_strdup(line+15);            
00394     } else if (g_strncasecmp(line,"no_proxy_for=",13) == 0) {
00395       g_free(gPreferenceConfigStruct.no_proxy_for);
00396       gPreferenceConfigStruct.no_proxy_for = g_strdup(line+13);
00397     } else if (g_strncasecmp(line,"ssl_proxy=",10) == 0) {
00398       g_free(gPreferenceConfigStruct.ssl_proxy);
00399       gPreferenceConfigStruct.ssl_proxy = g_strdup(line+10);
00400     } else if (g_strncasecmp(line,"ssl_proxy_port=",15) == 0) {
00401       g_free(gPreferenceConfigStruct.ssl_proxy_port);
00402       gPreferenceConfigStruct.ssl_proxy_port = g_strdup(line+15);
00403     } else if (g_strncasecmp(line,"direct_connection=",18) == 0) {
00404       gPreferenceConfigStruct.direct_connection = atoi(line+18);
00405     } else if (g_strncasecmp(line,"max_go=",7) == 0) {
00406       gPreferenceConfigStruct.max_go = atoi(line+7);
00407     } else if (g_strncasecmp(line,"popup_in_new_window=",20) == 0) {
00408       gPreferenceConfigStruct.popup_in_new_window = atoi (line + 20);
00409     } else if (g_strncasecmp(line,"disable_popups=",15) == 0) {
00410       gPreferenceConfigStruct.disable_popups = atoi(line+15);
00411     } else if (g_strncasecmp(line,"fontsize_",9) == 0) {
00412       for (i = 0; i < LANG_FONT_NUM; i++) {
00413         g_snprintf (tmpstr, 1024, "%s=", lang_font_item[i]);
00414         if (g_strncasecmp(line+9,tmpstr,strlen(tmpstr)))
00415           continue;
00416         gPreferenceConfigStruct.font_size[i] = atoi(line+9+strlen(tmpstr));
00417       };
00418     } else if (g_strncasecmp(line,"min_fontsize_",13) == 0) {
00419       for (i=0; i < LANG_FONT_NUM; i++) {
00420         g_snprintf(tmpstr,1024,"%s=",lang_font_item[i]);
00421         if (g_strncasecmp(line+13,tmpstr,strlen(tmpstr)))
00422           continue;
00423         gPreferenceConfigStruct.min_font_size[i] = atoi(line+13+strlen(tmpstr));
00424       }
00425     } else if (g_strncasecmp(line,"java=",5) == 0) {
00426       temp = atoi(line+5);
00427       if (temp) {
00428         gPreferenceConfigStruct.java = TRUE;
00429       } else {
00430         gPreferenceConfigStruct.java = FALSE;
00431       }
00432     } else if (g_strncasecmp(line,"javascript=",11) == 0) {
00433       temp = atoi(line+11);
00434       if (temp) {
00435         gPreferenceConfigStruct.javascript = TRUE;
00436       } else {
00437         gPreferenceConfigStruct.javascript = FALSE;
00438       }
00439     }
00440   }
00441   fflush (config_file);
00442   fclose(config_file);
00443   g_free(line);
00444   g_free(file);
00445 }
00446 
00447 /* Write the current 'minimo's configs' into his file: $home/.Minimo/config */
00448 void write_minimo_config () 
00449 {
00450   FILE *config_file;
00451   gchar *file;
00452   
00453   file = g_strconcat(gMinimoUserHomePath,"/.Minimo/config",NULL);
00454   config_file = fopen(file,"w");
00455   if (config_file == NULL) {
00456     g_error ("Cannot write history file!");
00457     return ;
00458   }
00459   
00460   fprintf(config_file,"home=%s\n",gPreferenceConfigStruct.home);
00461   fprintf(config_file,"xsize=%d\n",gPreferenceConfigStruct.xsize);
00462   fprintf(config_file,"ysize=%d\n",gPreferenceConfigStruct.ysize);
00463   fprintf(config_file,"layout=%d\n",gPreferenceConfigStruct.layout);
00464   fprintf(config_file,"mailer=%s\n",gPreferenceConfigStruct.mailer);
00465   fprintf(config_file,"maxpopup=%d\n",gPreferenceConfigStruct.maxpopupitems);
00466   fprintf(config_file,"http_proxy=%s\n",gPreferenceConfigStruct.http_proxy);
00467   fprintf(config_file,"http_proxy_port=%s\n",gPreferenceConfigStruct.http_proxy_port);
00468   fprintf(config_file,"ftp_proxy=%s\n",gPreferenceConfigStruct.ftp_proxy);
00469   fprintf(config_file,"ftp_proxy_port=%s\n",gPreferenceConfigStruct.ftp_proxy_port);
00470   fprintf(config_file,"ssl_proxy=%s\n",gPreferenceConfigStruct.ssl_proxy);
00471   fprintf(config_file,"ssl_proxy_port=%s\n",gPreferenceConfigStruct.ssl_proxy_port);
00472   fprintf(config_file,"no_proxy_for=%s\n",gPreferenceConfigStruct.no_proxy_for);
00473   fprintf(config_file,"direct_connection=%d\n",gPreferenceConfigStruct.direct_connection);
00474   fprintf(config_file,"max_go=%d\n",gPreferenceConfigStruct.max_go);
00475   fprintf(config_file,"popup_in_new_window=%d\n",gPreferenceConfigStruct.popup_in_new_window);
00476   fprintf(config_file,"disable_popups=%d\n",gPreferenceConfigStruct.disable_popups);
00477   
00478   if (gPreferenceConfigStruct.javascript == TRUE) {      
00479     fprintf(config_file,"javascript=1\n");
00480   } else {
00481     fprintf(config_file,"javascript=0\n");
00482   } 
00483   
00484   if (gPreferenceConfigStruct.java == TRUE) {
00485     fprintf(config_file,"java=1\n");
00486   } else {
00487     fprintf(config_file,"java=0\n");
00488   }
00489   
00490   fclose(config_file);
00491   g_free(file);
00492   set_mozilla_prefs ();
00493 }
00494 
00495 void set_mozilla_prefs(void)
00496 {
00497   gint disk_cache= 0, mem_cache= 0;
00498   gchar *cachedir;
00499   
00500   mozilla_preference_set_boolean ("security.warn_entering_secure", FALSE);
00501   mozilla_preference_set_boolean ("security.warn_leaving_secure", FALSE);
00502   mozilla_preference_set_boolean ("security.warn_submit_insecure", FALSE);
00503   mozilla_preference_set_boolean ("security.warn_viewing_mixed", FALSE);
00504   
00505   if (gPreferenceConfigStruct.disable_popups) 
00506     mozilla_preference_set_boolean ("dom.disable_open_during_load", TRUE);
00507   else 
00508     mozilla_preference_set_boolean ("dom.disable_open_during_load", FALSE);
00509   
00510   mozilla_preference_set_boolean("nglayout.widget.gfxscrollbars", TRUE);
00511   
00512   /*   for (i = 0; i < LANG_FONT_NUM; i++) {
00513         
00514   g_snprintf(tmpstr, 1024, "font.min-size.variable.", "");
00515   mozilla_preference_set_int(tmpstr, gPreferenceConfigStruct.current_font_size);
00516   
00517   g_snprintf(tmpstr, 1024, "font.min-size.variable.x-western", "");
00518   mozilla_preference_set_int(tmpstr, 2);
00519   
00520   g_snprintf(tmpstr, 1024, "font.min-size.fixed.x-western", "");
00521   mozilla_preference_set_int(tmpstr, 2);
00522   
00523   g_snprintf (tmpstr, 1024, "font.size.variable.%s", lang_font_item[i]);
00524   mozilla_preference_set_int(tmpstr,gPreferenceConfigStruct.current_font_size);
00525   
00526   g_snprintf(tmpstr, 1024, "font.min-size.variable.%s", lang_font_item[i]);
00527   mozilla_preference_set_int(tmpstr, gPreferenceConfigStruct.current_font_size);
00528   //mozilla_preference_set_int(tmpstr, DEFAULT_MIN_FONT_SIZE);
00529   }
00530   */
00531   mozilla_preference_set_boolean ("security.enable_java", gPreferenceConfigStruct.java);
00532   mozilla_preference_set_boolean ("javascript.enabled", gPreferenceConfigStruct.javascript);
00533   mozilla_preference_set_boolean ("browser.view_source.syntax_highlight", TRUE);
00534   cachedir = g_strconcat(gMinimoUserHomePath,"/.Minimo/cache",NULL);
00535   mkdir(cachedir,0755);
00536   mozilla_preference_set("browser.cache.directory",cachedir);
00537   g_free(cachedir);
00538   if ((disk_cache > 0) || (mem_cache > 0)) {
00539     mozilla_preference_set_boolean("browser.cache.disk.enable",TRUE);
00540     mozilla_preference_set_boolean("browser.cache.enable", TRUE);
00541   }
00542   else
00543   {
00544     mozilla_preference_set_boolean("browser.cache.disk.enable",FALSE);
00545     mozilla_preference_set_boolean("browser.cache.enable", FALSE);
00546   }
00547   if (disk_cache > 0) {
00548     mozilla_preference_set_boolean("browser.cache.disk.enable",TRUE);
00549     mozilla_preference_set_int("browser.cache.disk_cache_size",disk_cache);
00550     mozilla_preference_set_int("browser.cache.disk.capacity",disk_cache);
00551   }
00552   else 
00553   {
00554     mozilla_preference_set_boolean("browser.cache.disk.enable",FALSE);
00555     mozilla_preference_set_int("browser.cache.disk_cache_size", 0);
00556     mozilla_preference_set_int("browser.cache.disk.capacity",0);
00557   }
00558   
00559   if (mem_cache > 0)  {
00560     mozilla_preference_set_int("browser.cache.memory_cache_size",mem_cache);
00561     mozilla_preference_set_int("browser.cache.memory.capacity",mem_cache);
00562   } else {
00563     mozilla_preference_set_int("browser.cache.memory_cache_size", 0);   
00564     mozilla_preference_set_int("browser.cache.memory.capacity",0);
00565   }
00566   
00567   /* set proxy stuff */
00568   minimo_set_proxy_prefs();
00569   
00570   mozilla_save_prefs ();
00571 }
00572 
00573 void minimo_set_proxy_prefs(void)
00574 {
00575   gint network_type = 0;
00576   
00577   if (gPreferenceConfigStruct.direct_connection) {
00578     mozilla_preference_set("network.proxy.http","");
00579     mozilla_preference_set("network.proxy.ssl","");
00580     mozilla_preference_set("network.proxy.ftp","");
00581     mozilla_preference_set("network.proxy.no_proxies_on", " ");
00582     mozilla_preference_set_int("network.proxy.type",network_type);
00583   } else {
00584     
00585     if (strlen(gPreferenceConfigStruct.http_proxy) != 0 && strcmp(gPreferenceConfigStruct.http_proxy,"") != 0 && strlen(gPreferenceConfigStruct.http_proxy_port) > 0 && strcmp(gPreferenceConfigStruct.http_proxy_port,"") != 0) {
00586       
00587       mozilla_preference_set_int ("network.proxy.type", 1);
00588       network_type=1;
00589       mozilla_preference_set ("network.proxy.http", gPreferenceConfigStruct.http_proxy);
00590       mozilla_preference_set_int ("network.proxy.http_port", atoi(gPreferenceConfigStruct.http_proxy_port));           
00591     }
00592     
00593     if (strlen(gPreferenceConfigStruct.ftp_proxy) != 0 && strcmp(gPreferenceConfigStruct.ftp_proxy,"") != 0 && strlen(gPreferenceConfigStruct.ftp_proxy_port) > 0 && strcmp(gPreferenceConfigStruct.http_proxy_port,"") != 0) {
00594       if (!network_type)
00595         mozilla_preference_set_int("network.proxy.type", 1);
00596       mozilla_preference_set ("network.proxy.ftp", gPreferenceConfigStruct.ftp_proxy);
00597       mozilla_preference_set_int ("network.proxy.ftp_port", atoi(gPreferenceConfigStruct.ftp_proxy_port));
00598     }
00599     
00600     if (strlen(gPreferenceConfigStruct.ssl_proxy) != 0 && strcmp(gPreferenceConfigStruct.ssl_proxy,"") != 0 && strlen(gPreferenceConfigStruct.ssl_proxy_port) > 0 && strcmp    (gPreferenceConfigStruct.ssl_proxy_port,"") != 0) {
00601       if (!network_type)
00602         mozilla_preference_set_int("network.proxy.type", 1);
00603       mozilla_preference_set ("network.proxy.ssl", gPreferenceConfigStruct.ssl_proxy);
00604       mozilla_preference_set_int ("network.proxy.ssl_port", atoi(gPreferenceConfigStruct.ssl_proxy_port));
00605     }
00606        
00607     if (strlen(gPreferenceConfigStruct.no_proxy_for) != 0)
00608       mozilla_preference_set("network.proxy.no_proxies_on", gPreferenceConfigStruct.no_proxy_for);
00609     else
00610       mozilla_preference_set("network.proxy.no_proxies_on", " ");
00611   }
00612 }
00613 
00614 PangoFontDescription* getOrCreateDefaultMinimoFont()
00615 {
00616   if (gDefaultMinimoFont)
00617     return gDefaultMinimoFont;
00618   
00619   gDefaultMinimoFont = pango_font_description_from_string("sans 8");
00620   return gDefaultMinimoFont;
00621 }