Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

prefs.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 /*
00023  * prefs.c
00024  *
00025  */
00026 
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include "intl.h"
00033 #include <gdk/gdkkeysyms.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 
00037 #include "util.h"
00038 #include "libproxy/libproxy.h"
00039 #include "sound.h"
00040 #include "defaults.h"
00041 #include "value_pair.h"
00042 #include "gtk_globals.h"
00043 #include "status.h"
00044 #include "gtkspell.h"
00045 #include "plugin.h"
00046 #include "file_select.h"
00047 #include "dialog.h"
00048 
00049 #include "pixmaps/ok.xpm"
00050 #include "pixmaps/cancel.xpm"
00051 
00052 #ifdef __MINGW32__
00053 #define rindex(a,b) strrchr(a,b)
00054 #endif
00055 
00056 static gint is_prefs_open = 0;
00057 static GList *GLOBAL_PREFS=NULL;
00058 
00059 extern void update_contact_window_length ();
00060 
00061 /*
00062  * Preferences Dialog
00063  */
00064 
00065 void build_general_prefs(GtkWidget *); /* Sat Apr 28 2001 S. K. Mandal*/
00066 void build_sound_tab(GtkWidget *);
00067 void build_sound_prefs(GtkWidget *);
00068 void build_logs_prefs(GtkWidget *);
00069 void build_proxy_prefs(GtkWidget *);
00070 void build_layout_prefs(GtkWidget *);
00071 void build_chat_prefs(GtkWidget *);
00072 void build_encoding_prefs(GtkWidget *);
00073 void build_modules_prefs(GtkWidget *);
00074 static void ok_callback(GtkWidget * widget, gpointer data);
00075 static void cancel_callback(GtkWidget * widget, gpointer data);
00076 static void destroy(GtkWidget * widget, gpointer data);
00077 
00078 /*
00079  * Global preference handling functions 
00080  */
00081 
00082 void AddPref(char *key, void *data);
00083 void *SetPref(char *key, void *data);
00084 void *GetPref(char *key);
00085 void iSetLocalPref(char *key, int data);
00086 void fSetLocalPref(char *key, float data);
00087 void cSetLocalPref(char *key, char * data);
00088 char *cGetLocalPref(char *key);
00089 int iGetLocalPref(char *key);
00090 
00091 void build_prefs()
00092 {
00093      if(!is_prefs_open)
00094      {
00095       GtkWidget *hbox;
00096       GtkWidget *label;
00097       GtkWidget *button;
00098       GtkWidget *hbox2;
00099       GtkWidget *prefs_vbox;
00100       GtkWidget *iconwid;
00101       GdkPixmap *icon;
00102       GdkBitmap *mask;
00103       GtkWidget *prefs_window;
00104 
00105       prefs_vbox = gtk_vbox_new(FALSE, 5);
00106       prefs_window = gtk_window_new(GTK_WINDOW_DIALOG);
00107       gtk_window_set_position(GTK_WINDOW(prefs_window), GTK_WIN_POS_MOUSE);
00108       /* set current parent to prefs so error dialogs know who real
00109        * parent is */
00110       current_parent_widget = prefs_window;
00111       gtk_widget_realize(prefs_window);
00112       gtk_window_set_title(GTK_WINDOW(prefs_window), _("Yattm Preferences"));
00113       eb_icon(prefs_window->window);
00114       gtk_signal_connect(GTK_OBJECT(prefs_window), "destroy",
00115                   GTK_SIGNAL_FUNC(destroy), NULL);
00116 
00117       /*
00118        ************************************************************
00119        Below the different tabs are defined for the preferences
00120        window.  In which the user can make yattm work more
00121        the way he/she wants it too.
00122        ************************************************************
00123        */
00124 
00125       {
00126            GtkWidget *prefs_note = gtk_notebook_new();
00127                SetPref("widget::prefs_note", prefs_note);
00128            build_general_prefs(prefs_note);
00129            build_logs_prefs(prefs_note);
00130            build_sound_prefs(prefs_note);
00131            build_layout_prefs(prefs_note);
00132            build_chat_prefs(prefs_note);
00133 //         build_connections_prefs(prefs_note);
00134            gtk_box_pack_start(GTK_BOX(prefs_vbox), prefs_note, FALSE, FALSE, 0);
00135            build_proxy_prefs(prefs_note);
00136 #ifdef HAVE_ICONV_H
00137            build_encoding_prefs(prefs_note);
00138 #endif
00139            build_modules_prefs(prefs_note);
00140       }
00141    
00142       /*Okay Button*/
00143       hbox = gtk_hbox_new(FALSE, 5);
00144       hbox2 = gtk_hbox_new(TRUE, 5);
00145       gtk_widget_set_usize(hbox2, 200,25);
00146    
00147       icon = gdk_pixmap_create_from_xpm_d(prefs_window->window, &mask, NULL, ok_xpm);
00148       iconwid = gtk_pixmap_new(icon, mask);
00149       label = gtk_label_new(_("Ok"));
00150    
00151       gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00152       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00153    
00154       gtk_widget_show(iconwid);
00155       gtk_widget_show(label);
00156    
00157       button = gtk_button_new();
00158    
00159       gtk_signal_connect(GTK_OBJECT(button), "clicked", 
00160                  ok_callback, prefs_window);
00161 
00162       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
00163                      GTK_SIGNAL_FUNC (gtk_widget_destroy),
00164                      GTK_OBJECT (prefs_window));
00165       gtk_widget_show(hbox);
00166    
00167       gtk_container_add (GTK_CONTAINER (button), hbox);
00168    
00169       gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 5);
00170       gtk_widget_show(button);
00171    
00172       /*Cancel Button*/
00173       hbox = gtk_hbox_new(FALSE, 5);
00174       icon = gdk_pixmap_create_from_xpm_d(prefs_window->window, &mask, NULL, cancel_xpm);
00175       iconwid = gtk_pixmap_new(icon, mask);
00176       label = gtk_label_new(_("Cancel"));
00177    
00178       gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, FALSE, 2);
00179       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
00180       
00181       gtk_widget_show(iconwid);
00182       gtk_widget_show(label);
00183    
00184       button = gtk_button_new();
00185    
00186       gtk_signal_connect(GTK_OBJECT(button), "clicked", 
00187                  cancel_callback, prefs_window);
00188 
00189       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
00190                      GTK_SIGNAL_FUNC (gtk_widget_destroy),
00191                      GTK_OBJECT (prefs_window));
00192       gtk_widget_show(hbox);
00193    
00194       gtk_container_add (GTK_CONTAINER (button), hbox);
00195    
00196       gtk_box_pack_start(GTK_BOX(hbox2), button, TRUE, TRUE, 5);
00197       gtk_widget_show(button);
00198    
00199       /*End Buttons*/
00200       hbox = gtk_hbox_new(FALSE, 5);
00201     
00202       gtk_box_pack_end(GTK_BOX(hbox), hbox2, FALSE, FALSE, 5);
00203       gtk_widget_show(hbox2);
00204    
00205       gtk_box_pack_start(GTK_BOX(prefs_vbox), hbox, FALSE, FALSE, 5);
00206       gtk_widget_show(hbox);
00207       gtk_widget_show(prefs_vbox);
00208       gtk_container_add(GTK_CONTAINER(prefs_window), prefs_vbox);
00209 
00210       gtk_widget_show(prefs_window);
00211       is_prefs_open = 1;
00212      }
00213 }
00214 
00215 /*
00216  * General Preferences Dialog
00217  * Sat Apr 28 2001 Sourav K. Mandal <Sourav.Mandal@ikaran.com>
00218  *
00219  */
00220 
00221 static GtkWidget *plugin_prefs_win;
00222 static GtkWidget * length_contact_window_entry = NULL;
00223 static GtkWidget * font_size_entry = NULL;
00224 static GtkWidget * alternate_browser_entry = NULL;
00225 const gint length_contact_window_def = 256;
00226 const gint width_contact_window_def = 150;
00227 #ifdef HAVE_LIBXFT
00228 const gint font_size_def = 5;
00229 #else
00230 const gint font_size_def = 2;
00231 #endif
00232 gint length_contact_window_old = 0;
00233 
00234 gint do_login_on_startup = 0;
00235 gint do_login_on_startup_old = 0 ;
00236 
00237 gint do_applet_show_on_startup = 1 ;
00238 gint do_applet_show_on_startup_old = 1 ;
00239 
00240 gint do_yattm_debug = 0;
00241 gint do_yattm_debug_old = 0;
00242 
00243 gint do_yattm_debug_html = 0;
00244 gint do_yattm_debug_html_old = 0;
00245 
00246 gint do_plugin_debug = 0;
00247 gint do_plugin_debug_old = 0;
00248 
00249 #ifdef HAVE_ISPELL
00250 gint do_spell_checking = 0;
00251 gint do_spell_checking_old = 0;
00252 #endif
00253 
00254 gint do_noautoresize = 0;
00255 gint do_noautoresize_old = 0;
00256 
00257 gint use_alternate_browser = 0;
00258 gint use_alternate_browser_old = 0;
00259 
00260 void set_use_alternate_browser(GtkWidget * w, int * data);
00261 
00262 void build_general_prefs(GtkWidget *prefs_note) {
00263     GtkWidget *vbox;
00264     GtkWidget *brbutton;
00265     GtkWidget *label;
00266     GtkWidget *hbox;
00267 
00268     char buff [10];
00269     char buff2 [256];
00270     buff [0] = '\0';
00271     buff2[0] = '\0';
00272 
00273     length_contact_window_entry = gtk_entry_new ();
00274     length_contact_window_old = iGetLocalPref("length_contact_window");
00275 
00276     vbox = gtk_vbox_new(FALSE, 0);
00277     hbox = gtk_hbox_new(FALSE, 0);
00278 
00279     g_snprintf(buff2, 256, _("Length of Contact List (num. lines, 1 -> %d):"),
00280            0);
00281     label = gtk_label_new(buff2);
00282     //gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00283     //gtk_widget_show(label);
00284     
00285     g_snprintf(buff, 10, "%d", iGetLocalPref("length_contact_window"));
00286     //gtk_entry_set_text(GTK_ENTRY(length_contact_window_entry), buff);
00287     //gtk_box_pack_start(GTK_BOX(hbox), length_contact_window_entry,
00288 //             FALSE, FALSE, 0);
00289 //    gtk_widget_show(length_contact_window_entry);
00290     gtk_widget_show(hbox);
00291     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00292 
00293     do_login_on_startup_old = do_login_on_startup;
00294     eb_button(_("Log in on startup"), &do_login_on_startup, vbox);
00295 
00296     do_applet_show_on_startup_old = do_applet_show_on_startup ;
00297 #ifdef HAVE_ISPELL
00298     do_spell_checking_old = do_spell_checking;
00299     eb_button(_("Use spell checking"), &do_spell_checking, vbox);
00300 #endif
00301 
00302     do_yattm_debug_old = do_yattm_debug;
00303     eb_button(_("Enable Debug Messages"), &do_yattm_debug, vbox);
00304     do_yattm_debug_html_old = do_yattm_debug_html;
00305  //   eb_button(_("Enable HTML Debug Messages"), &do_yattm_debug_html, vbox);
00306     do_plugin_debug_old = do_plugin_debug;
00307  //   eb_button(_("Enable Plugin Debug Messages"), &do_plugin_debug, vbox);
00308 
00309     do_noautoresize_old = do_noautoresize;
00310  //   eb_button(_("Don\'t Automatically Resize Contact List"), &do_noautoresize, vbox);
00311 
00312     use_alternate_browser_old = use_alternate_browser;
00313     alternate_browser_entry = gtk_entry_new();
00314 
00315     if (cGetLocalPref("alternate_browser")) {
00316     gtk_entry_set_text(GTK_ENTRY(alternate_browser_entry), cGetLocalPref("alternate_browser"));
00317     } else {
00318     gtk_entry_set_text(GTK_ENTRY(alternate_browser_entry), "");
00319     }
00320 
00321     brbutton = eb_button(_("Use alternate browser"), &use_alternate_browser, vbox);
00322     gtk_signal_connect(GTK_OBJECT(brbutton), "clicked",
00323         GTK_SIGNAL_FUNC(set_use_alternate_browser), (gpointer)brbutton);
00324 
00325     hbox = gtk_hbox_new(FALSE, 0);
00326     label = gtk_label_new(_("Full path to alternate browser:"));
00327     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00328     gtk_widget_show(label);
00329 
00330     gtk_box_pack_start(GTK_BOX(hbox), alternate_browser_entry, TRUE, TRUE, 10);
00331     gtk_widget_show(alternate_browser_entry);
00332     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00333     gtk_widget_show(hbox);
00334 
00335     gtk_widget_show(vbox);
00336 
00337     if(use_alternate_browser == 0)
00338     {
00339     gtk_widget_set_sensitive(alternate_browser_entry, FALSE);
00340     }
00341 
00342     gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox,
00343         gtk_label_new(_("General")));
00344 }
00345 
00346 void cancel_general_prefs() {
00347   char buff [10];
00348   buff [0] = '\0';
00349 
00350     do_login_on_startup = do_login_on_startup_old;
00351     do_yattm_debug = do_yattm_debug_old;
00352     do_yattm_debug_html = do_yattm_debug_html_old;
00353     do_plugin_debug = do_plugin_debug_old;
00354     
00355     do_applet_show_on_startup = do_applet_show_on_startup_old;
00356 #ifdef HAVE_ISPELL
00357     do_spell_checking = do_spell_checking_old ;
00358 #endif
00359 
00360     do_noautoresize = do_noautoresize ;
00361 
00362     use_alternate_browser = use_alternate_browser_old;
00363     if (cGetLocalPref("alternate_browser")) {
00364     gtk_entry_set_text(GTK_ENTRY(alternate_browser_entry), cGetLocalPref("alternate_browser"));
00365     } else {
00366     gtk_entry_set_text(GTK_ENTRY(alternate_browser_entry), "");
00367     }
00368 }
00369 
00370 void write_general_prefs(FILE *fp) {
00371     fprintf(fp,"do_login_on_startup=%d\n", do_login_on_startup) ;
00372     fprintf(fp,"do_yattm_debug=%d\n", do_yattm_debug) ;
00373     fprintf(fp,"do_yattm_debug_html=%d\n", do_yattm_debug) ;
00374     fprintf(fp,"do_plugin_debug=%d\n", do_yattm_debug) ;
00375     do_plugin_debug=do_yattm_debug_html=do_yattm_debug;
00376     eb_debug (DBG_CORE, "length_contact_window=%d\n", iGetLocalPref("length_contact_window"));
00377     fprintf(fp,"length_contact_window=%d\n", iGetLocalPref("length_contact_window"));
00378     fprintf(fp,"width_contact_window=%d\n", iGetLocalPref("width_contact_window"));
00379 #ifdef HAVE_ISPELL
00380     fprintf(fp,"do_spell_checking=%d\n", do_spell_checking) ;
00381 #endif
00382     fprintf(fp,"do_noautoresize=%d\n", do_noautoresize) ;
00383     fprintf(fp,"use_alternate_browser=%d\n", use_alternate_browser);
00384     if(alternate_browser_entry!=NULL)
00385         cSetLocalPref("alternate_browser", gtk_entry_get_text(GTK_ENTRY(alternate_browser_entry)));
00386     if (strlen(cGetLocalPref("alternate_browser")) > 0) {
00387     fprintf(fp,"alternate_browser=%s\n", cGetLocalPref("alternate_browser"));
00388     }
00389 }
00390 
00391 void set_use_alternate_browser(GtkWidget * w, int * data)
00392 {
00393      if(use_alternate_browser == 0)
00394      {
00395       gtk_widget_set_sensitive(alternate_browser_entry, FALSE);
00396      }
00397      else
00398      {
00399       gtk_widget_set_sensitive(alternate_browser_entry, TRUE);
00400      }
00401 }
00402 
00403 void destroy_general_prefs()
00404 {
00405     if(alternate_browser_entry==NULL) return;
00406     cSetLocalPref("alternate_browser", gtk_entry_get_text(GTK_ENTRY(alternate_browser_entry)));
00407     gtk_widget_destroy(length_contact_window_entry);
00408     gtk_widget_destroy(alternate_browser_entry);
00409     length_contact_window_entry = NULL;
00410     alternate_browser_entry = NULL;
00411 }
00412 
00413 
00414 /*
00415  * Logs Preferences Dialog
00416  */
00417 
00418 gint do_logging = 1;
00419 gint do_logging_old = 1;
00420 gint do_strip_html = 0;
00421 gint do_strip_html_old = 0;
00422 gint do_restore_last_conv = 0;
00423 gint do_restore_last_conv_old = 0;
00424 
00425 void build_logs_prefs(GtkWidget *prefs_note)
00426 {
00427      GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
00428 
00429      do_logging_old = do_logging;
00430      do_strip_html_old = do_strip_html;
00431      do_restore_last_conv_old = do_restore_last_conv;
00432 
00433      eb_button(_("Log all conversations"), &do_logging, vbox);
00434      eb_button(_("Restore last Conversation"), &do_restore_last_conv, vbox);
00435      eb_button(_("Strip HTML tags"), &do_strip_html, vbox);
00436      gtk_widget_show(vbox);
00437      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Logs")));
00438 }
00439 
00440 void cancel_logs_prefs() 
00441 {
00442      /* Values */
00443      do_logging = do_logging_old;
00444      do_strip_html = do_strip_html_old;
00445      do_restore_last_conv = do_restore_last_conv_old;
00446 }
00447 
00448 void write_logs_prefs(FILE *fp)
00449 {
00450      fprintf(fp,"do_logging=%d\n", do_logging);
00451      fprintf(fp,"do_strip_html=%d\n", do_strip_html);
00452      fprintf(fp,"do_restore_last_conv=%d\n", do_restore_last_conv);
00453 }
00454 
00455 
00456 /*
00457  * Chat Preferences Dialog
00458  */
00459 
00460 gint do_typing_notify = 1;
00461 gint do_typing_notify_old = 1;
00462 gint do_send_typing_notify = 1;
00463 gint do_send_typing_notify_old = 1;
00464 gint do_escape_close = 1;
00465 gint do_escape_close_old = 1;
00466 gint do_convo_timestamp = 1;
00467 gint do_convo_timestamp_old = 1;
00468 gint do_enter_send = 1;
00469 gint do_enter_send_old = 1;
00470 gint do_ignore_unknown = 0;
00471 gint do_ignore_unknown_old = 0;
00472 #ifdef HAVE_LIBXFT
00473 gint font_size_old = 5;
00474 gint font_size = 5;
00475 #else
00476 gint font_size_old = 2;
00477 gint font_size = 2;
00478 #endif
00479 gint do_multi_line = 1;
00480 gint do_multi_line_old = 1;
00481 gint do_raise_window = 0;
00482 gint do_raise_window_old = 0;
00483 gint do_send_idle_time = 0;
00484 gint do_send_idle_time_old = 0;
00485 gint do_timestamp = 1;
00486 gint do_timestamp_old = 1;
00487 gint do_tabbed_chat = 0;
00488 gint do_tabbed_chat_old = 0;
00489 /* Orientation:  0 => bottom, 1 => top, 2=> left, 3 => right */
00490 gint do_tabbed_chat_orient = 0;
00491 gint do_tabbed_chat_orient_old = 0;
00492 gint do_ignore_fore = 1;
00493 gint do_ignore_fore_old = 1;
00494 gint do_ignore_back = 1;
00495 gint do_ignore_back_old = 1;
00496 gint do_ignore_font = 1;
00497 gint do_ignore_font_old = 1;
00498 gint do_smiley = 1;
00499 gint do_smiley_old = 1;
00500 
00501 
00502 GdkDeviceKey accel_prev_tab =     { GDK_Left, GDK_CONTROL_MASK };
00503 GdkDeviceKey accel_prev_tab_old = { GDK_Left, GDK_CONTROL_MASK };
00504 GdkDeviceKey accel_next_tab =     { GDK_Right, GDK_CONTROL_MASK };
00505 GdkDeviceKey accel_next_tab_old = { GDK_Right, GDK_CONTROL_MASK };
00506 guint accel_change_handler_id = 0;
00507 
00508 /*
00509   Callback function for setting element of Tabbed Chat Orientation radio
00510   button group.  Ignores w and sets global to variable
00511 */
00512 void set_tco_element (GtkWidget * w, int data)
00513 {
00514   do_tabbed_chat_orient = data;
00515 }
00516 
00517 /* apparently all signal handlers are supposed to be boolean... */
00518 static gboolean newkey_callback (GtkWidget *keybutton, GdkEventKey *event, gint *userdata) {
00519     GtkWidget *label = GTK_BIN(keybutton)->child;
00520     /* remove stupid things like.. numlock scrolllock and capslock
00521      * mod1 = alt, mod2 = numlock, mod3 = modeshift/altgr, mod4 = meta, mod5 = scrolllock */
00522     
00523     gint state = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_MOD4_MASK);
00524     if (state != 0) {
00525             /* this unfortunately was the only way I could do this without using
00526              * a key release event
00527              */
00528         switch(event->keyval) {
00529                 case GDK_Shift_L:
00530                 case GDK_Shift_R:
00531                 case GDK_Control_L:
00532                 case GDK_Control_R:
00533                 case GDK_Caps_Lock:
00534                 case GDK_Shift_Lock:
00535                 case GDK_Meta_L:
00536                 case GDK_Meta_R:
00537                 case GDK_Alt_L:
00538                 case GDK_Alt_R:
00539                 case GDK_Super_L:
00540                 case GDK_Super_R:
00541                 case GDK_Hyper_L:
00542                 case GDK_Hyper_R:
00543                         /* don't let the user set a modifier as a hotkey */
00544                         break;
00545                 default:
00546                     userdata[0] = event->keyval;
00547                     userdata[1] = state;
00548                     gtk_label_set_text(GTK_LABEL(label), gtk_accelerator_name(userdata[0], userdata[1]));
00549                     gtk_signal_disconnect(GTK_OBJECT(keybutton), accel_change_handler_id);
00550                     gtk_grab_remove(keybutton);
00551                     accel_change_handler_id = 0;
00552         }
00553     }
00554     /* eat the event and make focus keys (arrows) not change the focus */
00555     return gtk_true();
00556 }
00557 
00558 static void getnewkey (GtkWidget * keybutton, gpointer userdata) {
00559     GtkWidget *label = GTK_BIN(keybutton)->child;
00560 
00561     if(accel_change_handler_id == 0) {
00562         gtk_label_set_text(GTK_LABEL(label), _("Please press new key and modifier now."));
00563     
00564         gtk_object_set_data(GTK_OBJECT(keybutton), "accel", userdata);
00565         
00566         /* it's sad how this works: It grabs the events in the event mask
00567          * of the widget the mouse is over, NOT the grabbed widget.
00568          * Oh, and persistantly clicking makes the grab go away...
00569          */
00570         gtk_grab_add(keybutton);
00571         
00572         accel_change_handler_id = gtk_signal_connect_after (GTK_OBJECT(keybutton),
00573                     "key_press_event",
00574                     GTK_SIGNAL_FUNC (newkey_callback),
00575                     userdata);
00576     }
00577 }
00578 
00579 static void add_key_set(gchar *labelString,
00580                     GdkDeviceKey *keydata,
00581                     GtkWidget *vbox)
00582 {
00583      GtkWidget *hbox;
00584      GtkWidget *label;
00585      GtkWidget *button;
00586      char *clabel=NULL;
00587      hbox = gtk_hbox_new(FALSE, 2);
00588      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00589 
00590      label = gtk_label_new (labelString);
00591      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 3);
00592      gtk_widget_set_usize(label, 255, 10);
00593      gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
00594      gtk_widget_show (label);
00595 
00596      clabel=gtk_accelerator_name(keydata->keyval, keydata->modifiers);
00597      button = gtk_button_new_with_label(clabel);
00598      g_free(clabel);
00599      
00600      gtk_signal_connect(GTK_OBJECT(button), "clicked", 
00601             GTK_SIGNAL_FUNC(getnewkey), 
00602             (gpointer)keydata);
00603      gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
00604      gtk_widget_show (button);
00605 
00606      gtk_widget_show(hbox);
00607 }
00609 void build_layout_prefs(GtkWidget *prefs_note) 
00610 {
00611      GtkWidget *vbox;
00612      GtkWidget *hbox;
00613      GSList *group;
00614      GtkWidget *label;
00615      
00616      vbox = gtk_vbox_new(FALSE, 5);
00617 
00618      /* Values */
00619      do_tabbed_chat_old = do_tabbed_chat;
00620      do_tabbed_chat_orient_old = do_tabbed_chat_orient = iGetLocalPref("do_tabbed_chat_orient");
00621      eb_button(_("Use tabbed chat windows"), &do_tabbed_chat, vbox);
00622 
00623      /*
00624        Radio button group for tabbed chat orientation
00625      */
00626 
00627      /* Setup box to hold it */
00628      hbox = gtk_hbox_new(FALSE, 5);
00629 
00630      /* setup intro label */
00631      label = gtk_label_new (_("Tabbed Chat Orientation:"));
00632      gtk_widget_show (label);
00633      gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 5);
00634 
00635      /* Setup group -- set to NULL to create new group */
00636      group = NULL;
00637 
00638      /* Create buttons */
00639      group = eb_radio (group, _("Bottom"), do_tabbed_chat_orient, 0, hbox,
00640                set_tco_element);
00641      group = eb_radio (group, _("Top"),    do_tabbed_chat_orient, 1, hbox,
00642                set_tco_element);
00643      group = eb_radio (group, _("Left"),   do_tabbed_chat_orient, 2, hbox,
00644                set_tco_element);
00645      group = eb_radio (group, _("Right"),  do_tabbed_chat_orient, 3, hbox,
00646                set_tco_element);
00647     
00648      /* bug here , var gets messed up. why ? */
00649      do_tabbed_chat_orient = do_tabbed_chat_orient_old;
00650      /* Put it in the vbox and make it visible */
00651      gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00652      gtk_widget_show (hbox);
00653 
00654      gtk_widget_show(vbox);
00655      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Layout")));
00656 }
00657 
00658 void cancel_layout_prefs()
00659 {
00660      do_tabbed_chat = do_tabbed_chat_old;
00661      do_tabbed_chat_orient = do_tabbed_chat_orient_old;
00662 }
00663 
00664 void write_layout_prefs(FILE *fp)
00665 {
00666      fprintf(fp,"do_tabbed_chat=%d\n", do_tabbed_chat);
00667      fprintf(fp,"do_tabbed_chat_orient=%d\n", do_tabbed_chat_orient);
00668      iSetLocalPref("do_tabbed_chat_orient",do_tabbed_chat_orient);
00669 }
00670 
00671 void destroy_layout_prefs (void) {
00672 }
00673 
00675 void build_chat_prefs(GtkWidget *prefs_note) 
00676 {
00677      GtkWidget *vbox;
00678      GtkWidget *hbox;
00679      GtkWidget *label;
00680      char buff[10];   
00681      vbox = gtk_vbox_new(FALSE, 5);
00682 
00683      /* Values */
00684      do_ignore_unknown_old = do_ignore_unknown;
00685      do_send_idle_time_old = do_send_idle_time;
00686      do_raise_window_old = do_raise_window;
00687      do_timestamp_old = do_timestamp;
00688      do_multi_line_old = do_multi_line;
00689      do_enter_send_old = do_enter_send;
00690      do_smiley_old = do_smiley;
00691      do_convo_timestamp_old = do_convo_timestamp;
00692      do_escape_close_old = do_escape_close;
00693      do_typing_notify_old = do_typing_notify;
00694      do_send_typing_notify_old = do_send_typing_notify;
00695      font_size = iGetLocalPref("FontSize");
00696      do_ignore_fore_old = do_ignore_fore;
00697      do_ignore_back_old = do_ignore_back;
00698      do_ignore_font_old = do_ignore_font;
00699 
00700      accel_next_tab_old = accel_next_tab;
00701      accel_prev_tab_old = accel_prev_tab;
00702      accel_change_handler_id = 0;
00703 
00704      eb_button(_("Send idle/away status to servers"), &do_send_idle_time, vbox);
00705      eb_button(_("Raise window on incoming message"), &do_raise_window, vbox);
00706 //     eb_button(_("Timestamp when a user logs on/off"), &do_timestamp, vbox);
00707      eb_button(_("Ignore unknown users"), &do_ignore_unknown, vbox);
00708 //     eb_button(_("Enable multi-line chat"), &do_multi_line, vbox);
00709 //     eb_button(_("Press enter to send"), &do_enter_send, vbox);
00710 //     eb_button(_("Timestamps on Messages"), &do_convo_timestamp, vbox);
00711 //     eb_button(_("Show typing... status"), &do_typing_notify, vbox);
00712 //     eb_button(_("Send typing... status"), &do_send_typing_notify, vbox);
00713 //     eb_button(_("Draw Smilies"), &do_smiley, vbox);
00714 //     eb_button(_("Escape Closes Chat"), &do_escape_close, vbox);
00715 
00716      eb_button(_("Ignore Foreground Colors"), &do_ignore_fore, vbox);
00717      eb_button(_("Ignore Background Colors"), &do_ignore_back, vbox);
00718      eb_button(_("Ignore Fonts"), &do_ignore_font, vbox);
00719 
00720     hbox = gtk_hbox_new(FALSE, 0);
00721 
00722     label = gtk_label_new(_("Font size: "));
00723     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00724     gtk_widget_show(label);
00725     
00726     font_size_entry = gtk_entry_new();
00727 #ifdef HAVE_LIBXFT
00728     g_snprintf(buff, 10, "%d", iGetLocalPref("FontSize")==0?5:iGetLocalPref("FontSize"));
00729 #else
00730     g_snprintf(buff, 10, "%d", iGetLocalPref("FontSize")==0?2:iGetLocalPref("FontSize"));
00731 #endif
00732     gtk_entry_set_text(GTK_ENTRY(font_size_entry), buff);
00733     gtk_box_pack_start(GTK_BOX(hbox), font_size_entry,
00734                FALSE, FALSE, 0);
00735     gtk_widget_show(font_size_entry);
00736     gtk_widget_show(hbox);
00737     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00738 
00739      add_key_set(_("Previous Tab Hotkey (requires a modifier)"), &accel_prev_tab, vbox);
00740      add_key_set(_("Next Tab Hotkey (requires a modifier)"), &accel_next_tab, vbox);
00741 
00742      gtk_widget_show(vbox);
00743      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Chat")));
00744 }
00745 
00746 void cancel_chat_prefs()
00747 {
00748      do_ignore_unknown = do_ignore_unknown_old;
00749      do_send_idle_time = do_send_idle_time_old;
00750      do_raise_window = do_raise_window_old;
00751      do_timestamp = do_timestamp_old;
00752      do_multi_line = do_multi_line_old;
00753      do_enter_send = do_enter_send_old;
00754      do_convo_timestamp = do_convo_timestamp_old;
00755      do_escape_close = do_escape_close_old;
00756      do_typing_notify = do_typing_notify_old;
00757      do_send_typing_notify = do_send_typing_notify_old;
00758      do_smiley = do_smiley_old;
00759      font_size = font_size_old;
00760      do_ignore_fore = do_ignore_fore_old;
00761      do_ignore_back = do_ignore_back_old;
00762      do_ignore_font = do_ignore_font_old;    
00763      
00764      accel_next_tab = accel_next_tab_old;
00765      accel_prev_tab = accel_prev_tab_old;
00766 }
00767 
00768 void write_chat_prefs(FILE *fp)
00769 {
00770     char *ptr=NULL;
00771      fprintf(fp,"do_ignore_unknown=%d\n", do_ignore_unknown);
00772      fprintf(fp,"do_send_idle_time=%d\n", do_send_idle_time);
00773      fprintf(fp,"do_raise_window=%d\n", do_raise_window);
00774      fprintf(fp,"do_timestamp=%d\n", do_timestamp);
00775      fprintf(fp,"do_multi_line=%d\n", do_multi_line);
00776      fprintf(fp,"do_enter_send=%d\n", do_enter_send);
00777      fprintf(fp,"do_convo_timestamp=%d\n", do_convo_timestamp);
00778      fprintf(fp,"do_typing_notify=%d\n", do_typing_notify);
00779      fprintf(fp,"do_send_typing_notify=%d\n", do_send_typing_notify);
00780      fprintf(fp,"do_smiley=%d\n", do_smiley);
00781      fprintf(fp,"do_escape_close=%d\n", do_escape_close);
00782      if (font_size_entry != NULL)
00783          ptr = gtk_entry_get_text(GTK_ENTRY(font_size_entry));
00784      if (!ptr) 
00785 #ifdef HAVE_LIBXFT
00786          font_size = 5;
00787 #else
00788          font_size = 2;
00789 #endif
00790      else
00791          font_size = atoi(ptr);
00792 
00793      fprintf(fp,"FontSize=%d\n", font_size);
00794      iSetLocalPref("FontSize",font_size);
00795      fprintf(fp,"do_ignore_fore=%d\n", do_ignore_fore);
00796      fprintf(fp,"do_ignore_back=%d\n", do_ignore_back);
00797      fprintf(fp,"do_ignore_font=%d\n", do_ignore_font);
00798      ptr=gtk_accelerator_name(accel_next_tab.keyval, accel_next_tab.modifiers);
00799      fprintf(fp,"accel_next_tab=%s\n", ptr);
00800      g_free(ptr);
00801      ptr=gtk_accelerator_name(accel_prev_tab.keyval, accel_prev_tab.modifiers);
00802      fprintf(fp,"accel_prev_tab=%s\n", ptr);
00803      g_free(ptr);
00804 }
00805 
00806 void destroy_chat_prefs (void) {
00807     gtk_widget_destroy(font_size_entry);
00808     font_size_entry=NULL;
00809 }
00810 /*
00811  * Proxies Preferences Dialog
00812  */
00813 static GtkWidget * proxy_server_entry = NULL;
00814 static GtkWidget * proxy_port_entry = NULL;
00815 static GtkWidget * proxy_user_entry = NULL;
00816 static GtkWidget * proxy_password_entry = NULL;
00817 static gint new_proxy_type;
00818 static gint do_proxy_auth;
00819 static gint do_proxy_auth_old;
00820 
00821 static void set_proxy_type(GtkWidget *w, int *data);
00822 
00823 void build_proxy_prefs(GtkWidget *prefs_note)
00824 {
00825      GtkWidget *label;
00826      GtkWidget *button;
00827      GtkWidget *hbox;
00828      GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
00829      char buff[10];   
00830 
00831      proxy_server_entry = gtk_entry_new();
00832      proxy_port_entry = gtk_entry_new();
00833      proxy_user_entry = gtk_entry_new();
00834      proxy_password_entry = gtk_entry_new();
00835 
00836      label = gtk_label_new(_("Warning: Not all services are available through\nproxy, please see the README for details."));
00837      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00838      gtk_widget_show(label);
00839      button = gtk_radio_button_new_with_label(NULL, _("Direct Connection"));
00840      gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00841      gtk_widget_show(button);
00842      gtk_signal_connect(GTK_OBJECT(button), "clicked", 
00843             GTK_SIGNAL_FUNC(set_proxy_type), (gpointer)PROXY_NONE);
00844     
00845      if(proxy_type == PROXY_NONE)
00846      {
00847       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
00848      }
00849 
00850      button = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
00851                            _("Use HTTP Proxy"));
00852      gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00853      gtk_widget_show(button);
00854      gtk_signal_connect(GTK_OBJECT(button), "clicked",
00855             GTK_SIGNAL_FUNC(set_proxy_type), (gpointer)PROXY_HTTP);
00856 
00857      if(proxy_type == PROXY_HTTP)
00858      {
00859       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
00860      }
00861 
00862     
00863      button = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
00864                            _("Use SOCKS4 Proxy"));
00865      gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00866      gtk_widget_show(button);
00867      gtk_signal_connect(GTK_OBJECT(button), "clicked",
00868             GTK_SIGNAL_FUNC(set_proxy_type), (gpointer)PROXY_SOCKS4);
00869 
00870      if(proxy_type == PROXY_SOCKS4)
00871      {
00872       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
00873      }
00874 
00875      button = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
00876                            _("Use SOCKS5 Proxy"));
00877      gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00878      gtk_widget_show(button);
00879      gtk_signal_connect(GTK_OBJECT(button), "clicked",
00880             GTK_SIGNAL_FUNC(set_proxy_type), (gpointer)PROXY_SOCKS5);
00881 
00882      if(proxy_type == PROXY_SOCKS5)
00883      {
00884       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
00885      }
00886 
00887      hbox = gtk_hbox_new(FALSE, 0);
00888      label = gtk_label_new(_("Proxy Server:"));
00889      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00890      gtk_widget_show(label);
00891 
00892      if(proxy_host)
00893      {
00894       gtk_entry_set_text(GTK_ENTRY(proxy_server_entry), proxy_host);
00895      }
00896      else
00897      {
00898       gtk_entry_set_text(GTK_ENTRY(proxy_server_entry), "");
00899      }
00900 
00901      gtk_box_pack_start(GTK_BOX(hbox), proxy_server_entry, TRUE, TRUE, 10);
00902      gtk_widget_show(proxy_server_entry);
00903 
00904      label = gtk_label_new(_("Proxy Port:"));
00905      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00906      gtk_widget_show(label);
00907 
00908      g_snprintf(buff, 10, "%d", proxy_port);
00909      gtk_entry_set_text(GTK_ENTRY(proxy_port_entry), buff);
00910      gtk_box_pack_start(GTK_BOX(hbox), proxy_port_entry, FALSE, FALSE, 0);
00911      gtk_widget_show(proxy_port_entry);
00912 
00913      gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
00914      gtk_widget_show(hbox);
00915 
00916      do_proxy_auth_old = do_proxy_auth ;
00917      eb_button(_("Proxy requires authentication"), &do_proxy_auth, vbox);
00918 
00919      hbox = gtk_hbox_new(FALSE, 0);
00920      label = gtk_label_new(_("Proxy User ID:"));
00921      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00922      gtk_widget_show(label);
00923 
00924      if(proxy_user)
00925      {
00926       gtk_entry_set_text(GTK_ENTRY(proxy_user_entry), proxy_user);
00927      }
00928      else
00929      {
00930       gtk_entry_set_text(GTK_ENTRY(proxy_user_entry), "");
00931      }
00932 
00933      gtk_box_pack_start(GTK_BOX(hbox), proxy_user_entry, TRUE, TRUE, 10);
00934      gtk_widget_show(proxy_user_entry);
00935 
00936      label = gtk_label_new(_("Proxy Password:"));
00937      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
00938      gtk_widget_show(label);
00939 
00940      if(proxy_password)
00941      {
00942       gtk_entry_set_text(GTK_ENTRY(proxy_password_entry), proxy_password);
00943      }
00944      else
00945      {
00946       gtk_entry_set_text(GTK_ENTRY(proxy_password_entry), "");
00947      }
00948 
00949      gtk_entry_set_visibility(GTK_ENTRY(proxy_password_entry), FALSE);
00950 
00951      gtk_box_pack_start(GTK_BOX(hbox), proxy_password_entry, FALSE, FALSE, 0);
00952      gtk_widget_show(proxy_password_entry);
00953 
00954      gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
00955      gtk_widget_show(hbox);
00956 
00957      if(proxy_type == PROXY_NONE)
00958      {
00959       gtk_widget_set_sensitive(proxy_server_entry, FALSE);
00960       gtk_widget_set_sensitive(proxy_port_entry, FALSE);
00961       gtk_widget_set_sensitive(proxy_user_entry, FALSE);
00962       gtk_widget_set_sensitive(proxy_password_entry, FALSE);
00963      }
00964 
00965      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Proxy")));
00966      gtk_widget_show(vbox);
00967 }
00968 
00969 void cancel_proxy_prefs()
00970 {
00971      char buff[10];
00972 
00973      new_proxy_type = proxy_type;
00974     
00975      if(proxy_host)
00976      {
00977       gtk_entry_set_text(GTK_ENTRY(proxy_server_entry), proxy_host);
00978      }
00979      else
00980      {
00981       gtk_entry_set_text(GTK_ENTRY(proxy_server_entry), "");
00982      }
00983 
00984      g_snprintf(buff, 10, "%d", proxy_port);
00985      gtk_entry_set_text(GTK_ENTRY(proxy_port_entry), buff);
00986 
00987      do_proxy_auth = do_proxy_auth_old ;
00988 
00989      if(proxy_user)
00990      {
00991       gtk_entry_set_text(GTK_ENTRY(proxy_user_entry), proxy_user);
00992      }
00993      else
00994      {
00995       gtk_entry_set_text(GTK_ENTRY(proxy_user_entry), "");
00996      }
00997 
00998      if(proxy_password)
00999      {
01000       gtk_entry_set_text(GTK_ENTRY(proxy_password_entry), proxy_password);
01001      }
01002      else
01003      {
01004       gtk_entry_set_text(GTK_ENTRY(proxy_password_entry), "");
01005      }
01006 
01007 }
01008 
01009 void destroy_proxy()
01010 {
01011     if(proxy_server_entry == NULL) return;
01012      proxy_set_proxy(new_proxy_type,
01013              gtk_entry_get_text(GTK_ENTRY(proxy_server_entry)),
01014              atol(gtk_entry_get_text(GTK_ENTRY(proxy_port_entry))));
01015      proxy_set_auth(do_proxy_auth,
01016          gtk_entry_get_text(GTK_ENTRY(proxy_user_entry)),
01017          gtk_entry_get_text(GTK_ENTRY(proxy_password_entry)));
01018     gtk_widget_destroy(proxy_server_entry);
01019     gtk_widget_destroy(proxy_port_entry);
01020     gtk_widget_destroy(proxy_user_entry);
01021     gtk_widget_destroy(proxy_password_entry);
01022 
01023     proxy_server_entry=NULL;
01024     proxy_port_entry=NULL;
01025     proxy_user_entry=NULL;
01026     proxy_password_entry=NULL;
01027 }
01028 
01029 void write_proxy_prefs(FILE *fp)
01030 {
01031      fprintf(fp,"proxy_type=%d\n", proxy_type);
01032      if(proxy_host)
01033      {
01034       fprintf(fp,"proxy_host=%s\n", proxy_host);
01035      }
01036      fprintf(fp,"proxy_port=%d\n", proxy_port);
01037      fprintf(fp,"do_proxy_auth=%d\n", do_proxy_auth);
01038      if (proxy_user)
01039      {
01040       fprintf(fp,"proxy_user=%s\n", proxy_user);
01041      }
01042      if (proxy_password)
01043      {
01044       fprintf(fp,"proxy_password=%s\n", proxy_password);
01045      }
01046 }
01047 
01048 
01049 static void set_proxy_type(GtkWidget * w, int * data)
01050 {
01051      new_proxy_type = (int)data;
01052      if(new_proxy_type == PROXY_NONE)
01053      {
01054       gtk_widget_set_sensitive(proxy_server_entry, FALSE);
01055       gtk_widget_set_sensitive(proxy_port_entry, FALSE);
01056      }
01057      else
01058      {
01059       gtk_widget_set_sensitive(proxy_server_entry, TRUE);
01060       gtk_widget_set_sensitive(proxy_port_entry, TRUE);
01061      }
01062 }
01063 
01064 
01065 /*
01066  * Encoding Preferences Dialog
01067  */
01068 
01069 
01070 #ifdef HAVE_ICONV_H
01071 #define ENCODE_LEN 64
01072 gint use_recoding = 0;
01073 
01074 static GtkWidget * modules_path_text = NULL;
01075 static GtkWidget * local_encoding_entry = NULL;
01076 static GtkWidget * remote_encoding_entry = NULL;
01077 
01078 void set_use_of_recoding(GtkWidget * w, int * data);
01079 
01080 /* Encoding conversion Configuration tabs */
01081 void build_encoding_prefs(GtkWidget * prefs_note)
01082 {
01083      GtkWidget * hbox;
01084      GtkWidget * label;
01085      GtkWidget * button;
01086      GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
01087 
01088      local_encoding_entry = gtk_entry_new();
01089      remote_encoding_entry = gtk_entry_new();
01090 
01091      label = gtk_label_new(_("Warning: conversion is made using iconv() wich is UNIX98 standard and we hope you have it :-)\nFor list of possible encodings run 'iconv --list'."));
01092      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
01093      gtk_widget_show(label);
01094 
01095      button = eb_button(_("Use recoding in conversations"), &use_recoding, vbox);
01096 
01097      gtk_signal_connect(GTK_OBJECT(button), "clicked",
01098             GTK_SIGNAL_FUNC(set_use_of_recoding), (gpointer)button);
01099 
01100      hbox = gtk_hbox_new(FALSE, 0);
01101      label = gtk_label_new(_("Local encoding:"));
01102      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
01103      gtk_widget_show(label);
01104 
01105      gtk_entry_set_text(GTK_ENTRY(local_encoding_entry), cGetLocalPref("local_encoding"));
01106      gtk_box_pack_start(GTK_BOX(hbox), local_encoding_entry, TRUE, TRUE, 10);
01107      gtk_widget_show(local_encoding_entry);
01108      gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 10);
01109      gtk_widget_show(hbox);
01110 
01111 
01112      hbox = gtk_hbox_new(FALSE, 0);
01113      label = gtk_label_new(_("Remote encoding:"));
01114      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
01115      gtk_widget_show(label);
01116 
01117      gtk_entry_set_text(GTK_ENTRY(remote_encoding_entry), cGetLocalPref("remote_encoding"));
01118      gtk_box_pack_start(GTK_BOX(hbox), remote_encoding_entry, TRUE, TRUE, 10);
01119      gtk_widget_show(remote_encoding_entry);
01120      gtk_widget_show(hbox);
01121 
01122      gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 10);
01123      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Recoding")));
01124      gtk_widget_show(vbox);
01125 
01126      if(use_recoding == 0)
01127      {
01128       gtk_widget_set_sensitive(local_encoding_entry, FALSE);
01129       gtk_widget_set_sensitive(remote_encoding_entry, FALSE);
01130      }
01131 
01132 }
01133 
01134 void destroy_encodings() 
01135 {
01136      if(local_encoding_entry==NULL) return;
01137      cSetLocalPref("local_encoding", gtk_entry_get_text(GTK_ENTRY(local_encoding_entry)));
01138      cSetLocalPref("remote_encoding", gtk_entry_get_text(GTK_ENTRY(remote_encoding_entry)));
01139      gtk_widget_destroy(local_encoding_entry);
01140      gtk_widget_destroy(remote_encoding_entry);
01141      local_encoding_entry=NULL;
01142      remote_encoding_entry=NULL;
01143 
01144 }
01145 
01146 void set_use_of_recoding(GtkWidget * w, int * data)
01147 {
01148      //new_proxy_type = (int)data;
01149      if(use_recoding == 0)
01150      {
01151       gtk_widget_set_sensitive(local_encoding_entry, FALSE);
01152       gtk_widget_set_sensitive(remote_encoding_entry, FALSE);
01153      }
01154      else
01155      {
01156       gtk_widget_set_sensitive(local_encoding_entry, TRUE);
01157       gtk_widget_set_sensitive(remote_encoding_entry, TRUE);
01158      }
01159 }
01160 
01161 void write_encoding_prefs(FILE *fp)
01162 {
01163      char *enc=NULL;
01164 
01165      fprintf(fp,"use_recoding=%d\n", use_recoding);
01166      enc = cGetLocalPref("local_encoding");
01167      if(strlen(enc) > 0)
01168       fprintf(fp,"local_encoding=%s\n", enc);
01169      enc = cGetLocalPref("remote_encoding");
01170      if(strlen(enc) > 0)
01171       fprintf(fp,"remote_encoding=%s\n", enc);
01172 }
01173 
01174 #endif
01175 
01176 /* Used when loading service modules later, so passwords and user names are still available
01177  * as service:username */
01178 void save_account_info(char *service, GList *pairs)
01179 {
01180     char buff[256];
01181     char *val = value_pair_get_value(pairs, "SCREEN_NAME");
01182     g_snprintf(buff, 256, "%s:%s", service, val);
01183     g_free(val);
01184     SetPref(buff, pairs);
01185 }
01186 
01187 void reload_service_accounts(int service_id)
01188 {
01189     GList * node = accounts;
01190     GList * account_pairs;
01191     eb_local_account *oela=NULL, *nela=NULL;
01192     char buff[256], buff2[1024];
01193 
01194     while(node)
01195     {
01196         oela=node->data;
01197         if(oela->service_id != service_id || oela->connected) {
01198             node = node->next;
01199             continue;
01200         }
01201         eb_debug(DBG_CORE, "Account: handle:%s service: %s\n", oela->handle, get_service_name(oela->service_id));
01202         g_snprintf(buff, 256, "%s:%s", get_service_name(oela->service_id), oela->handle);
01203         account_pairs = GetPref(buff);
01204         nela = eb_services[oela->service_id].sc->read_local_account_config(account_pairs);
01205         if(!nela) {
01206             g_snprintf(buff2, 256, _("Unable to create account for %s, check config file\n"), buff);
01207             do_error_dialog(buff2, _("Invalid account"));
01208             oela->service_id=get_service_id("NO SERVICE");
01209         }
01210         else {
01211             nela->service_id = oela->service_id;
01212             node->data=nela;
01213             //FIXME: This should probably be left to the service to clean up, though at this point, it may not exist
01214             g_free(oela->handle);
01215             g_free(oela->protocol_local_account_data);
01216             g_free(oela);
01217         }
01218         node = node->next;
01219     }
01220 }
01221 
01222 void build_modules_list(GtkWidget * module_list)
01223 {
01224     char *module_info[7];
01225     GList *plugins=NULL;
01226     eb_PLUGIN_INFO *epi=NULL;
01227 
01228     for(plugins=GetPref(EB_PLUGIN_LIST); plugins; plugins=plugins->next) {
01229         epi=plugins->data;
01230         eb_debug(DBG_CORE, "Adding plugin %s\n", epi->name);
01231         module_info[0]=PLUGIN_TYPE_TXT[epi->pi.type-1];
01232         module_info[1]=epi->pi.brief_desc;
01233         module_info[2]=PLUGIN_STATUS_TXT[epi->status];
01234         module_info[3]=epi->pi.version;
01235         module_info[4]=epi->pi.date;
01236         module_info[5]=epi->name;
01237         if(epi->status_desc)
01238             module_info[6]=(char *)epi->status_desc;
01239         else
01240             module_info[6]="";
01241         gtk_clist_append(GTK_CLIST(module_list), module_info);
01242     }
01243 }
01244 
01245 void rebuild_set_status_menu()
01246 {
01247     GtkWidget *set_status_submenuitem;
01248 
01249     set_status_submenuitem = GetPref("widget::set_status_submenuitem");
01250     gtk_menu_item_remove_submenu(GTK_MENU_ITEM(set_status_submenuitem));
01251     eb_set_status_window(set_status_submenuitem);
01252     gtk_widget_draw(GTK_WIDGET(set_status_submenuitem), NULL);
01253 }
01254 
01255 void rebuild_import_menu()
01256 {
01257     GtkWidget *import_submenuitem;
01258 
01259     import_submenuitem = GetPref("widget::import_submenuitem");
01260     if(!import_submenuitem) {
01261         eb_debug(DBG_CORE, "Not rebuilding import menu, it's never been built.\n");
01262         return;
01263     }
01264     gtk_menu_item_remove_submenu(GTK_MENU_ITEM(import_submenuitem));
01265     eb_import_window(import_submenuitem);
01266     gtk_widget_draw(GTK_WIDGET(import_submenuitem), NULL);
01267 }
01268 void rebuild_profile_menu()
01269 {
01270     GtkWidget *profile_submenuitem;
01271 
01272     profile_submenuitem = GetPref("widget::profile_submenuitem");
01273     if(!profile_submenuitem) {
01274         eb_debug(DBG_CORE, "Not rebuilding profile menu, it's never been built.\n");
01275         return;
01276     }
01277     gtk_menu_item_remove_submenu(GTK_MENU_ITEM(profile_submenuitem));
01278     eb_profile_window(profile_submenuitem);
01279     gtk_widget_draw(GTK_WIDGET(profile_submenuitem), NULL);
01280 }
01281 
01282 /*
01283 void rebuild_connections_prefs()
01284 {
01285     GtkWidget *prefs_note, *connections_tab;
01286     static int connections_page=0;
01287 
01288     connections_tab = GetPref("widget::connections_tab");
01289     prefs_note = GetPref("widget::prefs_note");
01290     connections_page = gtk_notebook_page_num(GTK_NOTEBOOK(prefs_note), connections_tab);
01291     gtk_notebook_remove_page(GTK_NOTEBOOK(prefs_note), connections_page);
01292     SetPref("connections_page_num", &connections_page);
01293     build_connections_prefs(prefs_note);
01294     // Remove the page number for future builds of the prefs screen that are not from a reload
01295     SetPref("connections_page_num", NULL);
01296     // Need to refresh the widget -- 
01297     //      This forces the widget to redraw itself. 
01298     gtk_widget_draw(GTK_WIDGET(prefs_note), NULL);
01299 }
01300 */
01301 
01302 void reload_modules(GtkWidget * w, int * data)
01303 {
01304      GtkWidget *module_list;
01305      char *ptr=NULL;
01306      char *modules_path=NULL;
01307 
01308      module_list = GetPref("widget::module_list");
01309      gtk_clist_clear(GTK_CLIST(module_list));
01310 
01311      eb_debug(DBG_CORE, "Reloading modules\n");
01312      modules_path = gtk_editable_get_chars(GTK_EDITABLE(modules_path_text), 0, -1);
01313      ptr=modules_path;
01314      while( (ptr=strchr(ptr, '\n')) )
01315         ptr[0]=':';
01316      cSetLocalPref("modules_path", modules_path);
01317      load_modules();
01318      build_modules_list(module_list);
01319 //   rebuild_connections_prefs();
01320      rebuild_set_status_menu();
01321      rebuild_import_menu();
01322      rebuild_profile_menu();
01323      g_free(modules_path);
01324 }
01325 
01326 typedef struct {
01327     GtkCList *clist;
01328     eb_PLUGIN_INFO *epi;
01329     gint row;
01330 }Plugin_Callback_Data;
01331 
01332 static void reload_plugin_callback(GtkWidget * reload_button, gpointer userdata)
01333 {
01334     Plugin_Callback_Data *PCD=(Plugin_Callback_Data *)userdata;
01335     char *name=NULL, *path=NULL, buffer[1024];
01336     char *module_info[7];
01337 
01338     strncpy(buffer, PCD->epi->name, 1023);
01339     name=rindex(buffer, '/');
01340     if(name) {
01341         name[0]='\0';
01342         name++;
01343         path=buffer;
01344     }
01345     else {
01346             name=buffer;
01347             path=NULL;
01348     }
01349     if(PCD->epi->status==PLUGIN_LOADED)
01350     {
01351         eb_debug(DBG_CORE, "Unloading plugin %s\n", PCD->epi->name);
01352         if(unload_module(PCD->epi)!=0) {
01353             eb_debug(DBG_CORE, "Could not unload plugin %s\n", PCD->epi->name);
01354             return;
01355         }
01356         load_module(path, name);
01357     }
01358     else {
01359             load_module(path, name);
01360     }
01361     module_info[0]=PLUGIN_TYPE_TXT[PCD->epi->pi.type-1];
01362     module_info[1]=PCD->epi->pi.brief_desc;
01363     module_info[2]=PLUGIN_STATUS_TXT[PCD->epi->status];
01364     module_info[3]=PCD->epi->pi.version;
01365     module_info[4]=PCD->epi->pi.date;
01366     module_info[5]=PCD->epi->name;
01367     if(PCD->epi->status_desc)
01368         module_info[6]=(char *)PCD->epi->status_desc;
01369     else
01370         module_info[6]="";
01371     gtk_clist_remove(PCD->clist, PCD->row);
01372     gtk_clist_insert(PCD->clist, PCD->row, module_info);
01373     if(PCD->epi->pi.type==PLUGIN_SERVICE)
01374     {
01375 //      rebuild_connections_prefs();
01376         rebuild_set_status_menu();
01377     }
01378 }
01379 
01380 #define PLUGIN_TYPE_COL 0
01381 #define PLUGIN_BRIEF_COL 1
01382 #define PLUGIN_STATUS_COL 2
01383 #define PLUGIN_VERSION_COL 3
01384 #define PLUGIN_DATE_COL 4
01385 #define PLUGIN_PATH_COL 5
01386 #define PLUGIN_ERROR_COL 6
01387 
01388 static void unload_plugin_callback(GtkWidget * reload_button, gpointer userdata)
01389 {
01390     Plugin_Callback_Data *PCD=(Plugin_Callback_Data *)userdata;
01391 
01392     /*FIXME: Should set a pref so this module is not automatically loaded next time */
01393     eb_debug(DBG_CORE, "Unloading plugin %s\n", PCD->epi->name);
01394     if(unload_module(PCD->epi)==0) {
01395         gtk_clist_set_text(PCD->clist, PCD->row, PLUGIN_STATUS_COL, PLUGIN_STATUS_TXT[PLUGIN_NOT_LOADED]);
01396         eb_debug(DBG_CORE, "Unloaded plugin %s\n", PCD->epi->name);
01397         if(PCD->epi->pi.type==PLUGIN_SERVICE)
01398         {
01399 //          rebuild_connections_prefs();
01400             rebuild_set_status_menu();
01401         }
01402     }
01403     else
01404         eb_debug(DBG_CORE, "Could not unload plugin %s\n", PCD->epi->name);
01405 }
01406 
01407 void update_plugin_prefs(GtkWidget * w, input_list *prefs)
01408 {
01409     eb_debug(DBG_MOD, "updating prefs\n");
01410     eb_input_accept(prefs);
01411     gtk_widget_hide(plugin_prefs_win);
01412 }
01413 
01414 /* Sort the clist based upon the column passed */
01415 void plugin_column_sort(GtkCList *clist, gint column, gpointer userdata)
01416 {
01417     eb_debug(DBG_CORE, "Sorting on column: %i\n", column);
01418     gtk_clist_set_sort_column(GTK_CLIST(clist), column);
01419     gtk_clist_sort(GTK_CLIST(clist));
01420 }
01421 
01422 void plugin_selected(GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer userdata)
01423 {
01424     char *plugin_path=NULL;
01425     eb_PLUGIN_INFO *epi=NULL;
01426 
01427     if(!event)
01428         return;
01429     eb_debug(DBG_CORE, "row: %i column: %i button: %i\n", row, column, event->button);
01430 
01431     gtk_clist_get_text(GTK_CLIST(clist), row, PLUGIN_PATH_COL, &plugin_path);
01432     eb_debug(DBG_CORE, "plugin: %s\n", plugin_path);
01433     epi=FindPluginByName(plugin_path);
01434 
01435     if(!epi) {
01436             fprintf(stderr, "Unable to find plugin %s in plugin list!\n", plugin_path);
01437             return;
01438     }
01439     if (event->button == 3)
01440     {
01441         GtkWidget *menu;
01442         Plugin_Callback_Data *PCD=g_new0(Plugin_Callback_Data, 1);
01443         GtkWidget *button;
01444 
01445         menu = gtk_menu_new();
01446 
01447         PCD->clist=clist;
01448         PCD->epi=epi;
01449         PCD->row=row;
01450         if(epi->status==PLUGIN_LOADED) { // Is this an already loaded plugin? 
01451             eb_debug(DBG_CORE, "Adding Reload button\n");
01452             button = gtk_menu_item_new_with_label(_("Reload"));
01453             gtk_signal_connect(GTK_OBJECT(button), "activate",
01454                 GTK_SIGNAL_FUNC(reload_plugin_callback), PCD);
01455             gtk_menu_append(GTK_MENU(menu), button);
01456             gtk_widget_show(button);
01457             eb_debug(DBG_CORE, "Adding Unload button\n");
01458             button = gtk_menu_item_new_with_label(_("Unload"));
01459             gtk_signal_connect(GTK_OBJECT(button), "activate",
01460                 GTK_SIGNAL_FUNC(unload_plugin_callback), PCD);
01461             gtk_menu_append(GTK_MENU(menu), button);
01462             gtk_widget_show(button);
01463         }
01464         else
01465         {
01466             eb_debug(DBG_CORE, "Adding Reload button\n");
01467             button = gtk_menu_item_new_with_label(_("Load"));
01468             gtk_signal_connect(GTK_OBJECT(button), "activate",
01469                 GTK_SIGNAL_FUNC(reload_plugin_callback), PCD);
01470             gtk_menu_append(GTK_MENU(menu), button);
01471             gtk_widget_show(button);
01472         }
01473         gtk_widget_show(menu);
01474         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
01475             event->button, event->time );
01476     }
01477     else if(event->button == 1)
01478     {
01479         GtkWidget *plugin_prefs_w=GetPref("widget::plugin_prefs_w");
01480         eb_debug(DBG_MOD, "Setting prefs for %s\n", plugin_path);
01481         if(!plugin_prefs_w)
01482         {
01483             g_warning("plugin_prefs_w not defined, not building plugin prefs window!");
01484             return;
01485         }
01486         /* If the window already has a child, destroy it. */
01487         if(GTK_BIN(plugin_prefs_w)->child!=NULL)
01488         {
01489             gtk_widget_hide(plugin_prefs_win);
01490             gtk_widget_destroy(GTK_BIN(plugin_prefs_w)->child);
01491         }
01492 
01493         if(epi->pi.prefs)
01494         {
01495             GtkWidget *button;
01496             GtkWidget *hbox;
01497             GtkWidget *vbox;
01498             vbox = gtk_vbox_new(FALSE, 5);
01499             eb_input_render(epi->pi.prefs, vbox);
01500 
01501             hbox = gtk_hbox_new(TRUE, 50);
01502             button = eb_push_button(_("Update"), hbox);
01503             gtk_widget_show(hbox);
01504 
01505             gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
01506             gtk_signal_connect(GTK_OBJECT(button), "clicked",
01507                     GTK_SIGNAL_FUNC(update_plugin_prefs), (gpointer)epi->pi.prefs);
01508             gtk_scrolled_window_add_with_viewport
01509                 (GTK_SCROLLED_WINDOW(plugin_prefs_w),
01510                 vbox);
01511             gtk_widget_show(vbox);
01512             gtk_widget_show(plugin_prefs_w);
01513             gtk_widget_show(plugin_prefs_win);
01514         }
01515         else
01516             eb_debug(DBG_MOD, "No prefs defined for %s\n", plugin_path);
01517     }
01518 }
01519 
01520 void build_modules_prefs(GtkWidget * prefs_note)
01521 {
01522     GtkWidget * hbox;
01523     GtkWidget * label;
01524     GtkWidget * button;
01525     GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
01526     GtkWidget *vbox2 = NULL;
01527     GtkWidget * module_list=NULL;
01528     GtkWidget *w;
01529     int Columns=7, col=0;
01530     char *titles[7] = {_("Type"), 
01531                _("Brief Description"), 
01532                _("Status"), 
01533                _("Version"), 
01534                _("Date Last Modified") ,
01535                _("Path to module"), 
01536                _("Error Text")};
01537     char *modules_path, *ptr=NULL;
01538     int mod_path_pos=0;
01539 
01540     modules_path_text = gtk_text_new(NULL, NULL);
01541     gtk_editable_set_editable(GTK_EDITABLE(modules_path_text), TRUE);
01542 
01543     vbox2 = gtk_vbox_new(TRUE, 5);
01544     hbox = gtk_hbox_new(FALSE, 0);
01545 
01546     label = gtk_label_new(_("Module Paths"));
01547     gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0);
01548     gtk_widget_show(label);
01549     
01550     button = eb_push_button(_("Rescan"), vbox2);
01551     gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0);
01552     gtk_widget_show(vbox2);
01553 
01554     gtk_signal_connect(GTK_OBJECT(button), "clicked",
01555             GTK_SIGNAL_FUNC(reload_modules), (gpointer)button);
01556 
01557 
01558     modules_path = cGetLocalPref("modules_path");
01559     ptr=modules_path;
01560     while( (ptr=strchr(ptr, ':')) )
01561         ptr[0]='\n';
01562     gtk_widget_set_usize(modules_path_text, 200, 75);
01563     gtk_editable_insert_text(GTK_EDITABLE(modules_path_text), modules_path, strlen(modules_path), &mod_path_pos);
01564     gtk_box_pack_start(GTK_BOX(hbox), modules_path_text, TRUE, TRUE, 10);
01565     gtk_widget_show(modules_path_text);
01566     gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 10);
01567     gtk_widget_show(hbox);
01568 
01569     w=gtk_scrolled_window_new(NULL, NULL);
01570     gtk_widget_set_usize(w, 400, 200);
01571     /* Need to create a new one each time window is created as the old one was destroyed */
01572     module_list=gtk_clist_new_with_titles(Columns, titles);
01573     gtk_container_add(GTK_CONTAINER(w), module_list);
01574     gtk_widget_show(w);
01575     gtk_box_pack_start(GTK_BOX(vbox), w, TRUE, TRUE, 10);
01576     SetPref("widget::module_list", module_list);
01577     build_modules_list(module_list);
01578     gtk_clist_set_reorderable(GTK_CLIST(module_list), TRUE);
01579     gtk_clist_set_auto_sort(GTK_CLIST(module_list), TRUE);
01580     gtk_clist_column_titles_active(GTK_CLIST(module_list));
01581     gtk_signal_connect(GTK_OBJECT(module_list), "click-column",
01582             GTK_SIGNAL_FUNC(plugin_column_sort), NULL);
01583     gtk_clist_set_selection_mode(GTK_CLIST(module_list), GTK_SELECTION_SINGLE);
01584     for(col=0;col<Columns;col++)
01585         gtk_clist_set_column_auto_resize(GTK_CLIST(module_list), col, TRUE);
01586     /* Make sure right mouse button works */
01587     gtk_clist_set_button_actions(GTK_CLIST(module_list), 1, GTK_BUTTON_SELECTS);
01588     gtk_clist_set_button_actions(GTK_CLIST(module_list), 2, GTK_BUTTON_SELECTS);
01589     gtk_clist_set_button_actions(GTK_CLIST(module_list), 3, GTK_BUTTON_SELECTS);
01590     gtk_signal_connect(GTK_OBJECT(module_list), "select-row",
01591             GTK_SIGNAL_FUNC(plugin_selected), NULL);
01592 
01593     gtk_widget_show(label);
01594     w=gtk_scrolled_window_new(NULL,NULL);
01595     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w),
01596         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
01597     gtk_widget_set_usize(w, 300, 300);
01598     gtk_widget_show(w);
01599     SetPref("widget::plugin_prefs_w", w);
01600     /*gtk_box_pack_start(GTK_BOX(vbox), w, TRUE, TRUE, 10);*/
01601     plugin_prefs_win = gtk_window_new(GTK_WINDOW_DIALOG);
01602     gtk_window_set_position(GTK_WINDOW(plugin_prefs_win), GTK_WIN_POS_MOUSE);
01603     gtk_window_set_title(GTK_WINDOW(plugin_prefs_win), _("Plugin preferences"));
01604     gtk_container_add(GTK_CONTAINER(plugin_prefs_win), w);
01605     gtk_widget_hide(plugin_prefs_win);
01606     
01607     gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Modules")));
01608     gtk_widget_show(vbox);
01609     gtk_widget_show(GTK_WIDGET(module_list));
01610 }
01611 
01612 void destroy_modules() 
01613 {
01614     char *modules_path=NULL;
01615     char *ptr=NULL;
01616     if(modules_path_text==NULL) return;
01617     modules_path=gtk_editable_get_chars(GTK_EDITABLE(modules_path_text), 0, -1);
01618     ptr=modules_path;
01619     while( (ptr=strchr(ptr, '\n')) )
01620         ptr[0]=':';
01621     cSetLocalPref("modules_path", modules_path);
01622     g_free(modules_path);
01623      gtk_widget_destroy(modules_path_text);
01624      modules_path_text=NULL;
01625 }
01626 
01627 void write_module_prefs(FILE *fp)
01628 {
01629     GList *plugins=NULL;
01630     GList *master_prefs=NULL;
01631     GList *current_prefs=NULL;
01632     eb_PLUGIN_INFO *epi=NULL;
01633 
01634     fprintf(fp,"modules_path=%s\n", cGetLocalPref("modules_path"));
01635 
01636     fprintf(fp,"plugins\n");
01637     for(plugins=GetPref(EB_PLUGIN_LIST); plugins; plugins=plugins->next) {
01638         epi=plugins->data;
01639         fprintf(fp, "\t%s\n", epi->name);
01640         master_prefs=GetPref(epi->name);
01641         master_prefs=value_pair_remove(master_prefs, "load");
01642         current_prefs=eb_input_to_value_pair(epi->pi.prefs);
01643         if(epi->status==PLUGIN_LOADED)
01644             value_pair_add(current_prefs, "load", "1");
01645         else
01646             value_pair_add(current_prefs, "load", "0");
01647         master_prefs=value_pair_update(master_prefs, current_prefs);
01648         SetPref(epi->name, master_prefs);
01649         value_pair_print_values(master_prefs, fp, 2);
01650         fprintf(fp, "\tend\n");
01651         value_pair_free(current_prefs);
01652     }
01653     fprintf(fp,"end\n");
01654 }
01655 
01656 gint compare_ptr_key(gconstpointer a, gconstpointer b) {
01657         if(!strcmp( ((ptr_list *)a)->key, (char *)b))
01658             return(0);
01659         return(1);
01660 }
01661 
01662 void AddPref(char *key, void *data) {
01663     ptr_list *PrefData;
01664 
01665     PrefData = g_new0(ptr_list, 1);
01666     strcpy(PrefData->key, key);
01667     PrefData->value=(void *)data;
01668     GLOBAL_PREFS = g_list_append(GLOBAL_PREFS, PrefData);
01669     return;
01670 }
01671 
01672 /* Find old pref data, and replace with new, returning old data */
01673 void *SetPref(char *key, void *data) {
01674     ptr_list *PrefData=NULL;
01675     void *old_data=NULL;
01676     GList *ListData = g_list_find_custom(GLOBAL_PREFS, key, compare_ptr_key);
01677 
01678     if(!ListData) {
01679         AddPref(key, data);
01680         return(NULL);
01681     }
01682     PrefData=(ptr_list *)ListData->data;
01683     old_data=PrefData->value;
01684     PrefData->value=data;
01685     return(old_data);
01686 }
01687 
01688 void *GetPref(char *key) {
01689     ptr_list *PrefData=NULL;
01690     GList *ListData = g_list_find_custom(GLOBAL_PREFS, key, compare_ptr_key);
01691 
01692     if(!ListData)
01693         return(NULL);
01694     PrefData = ListData->data;
01695     if(!PrefData)
01696         return(NULL);
01697     return(PrefData->value);
01698 }
01699 
01700 void cSetLocalPref(char *key, char *data) {
01701     char newkey[MAX_PREF_NAME_LEN];
01702     char *oldvalue=NULL;
01703 
01704     sprintf(newkey, "Local::%s", key);
01705     oldvalue = SetPref(newkey, strdup(data));
01706     if(oldvalue)
01707         g_free(oldvalue);
01708     return;
01709 }
01710 
01711 void iSetLocalPref(char *key, int data) {
01712 #ifdef __MINGW32__
01713     char value[MAX_PREF_LEN];
01714 #else
01715     char value[MAX_PREF_NAME_LEN];
01716 #endif
01717 
01718     g_snprintf(value, MAX_PREF_LEN, "%i", data);
01719     cSetLocalPref(key, value);
01720     return;
01721 }
01722 
01723 void fSetLocalPref(char *key, float data) {
01724     char value[MAX_PREF_LEN];
01725 
01726     g_snprintf(value, MAX_PREF_LEN, "%f", data);
01727     cSetLocalPref(key, value);
01728     return;
01729 }
01730 
01731 char *cGetLocalPref(char *key) {
01732     char newkey[MAX_PREF_NAME_LEN];
01733     char *value=NULL;
01734 
01735     sprintf(newkey, "Local::%s", key);
01736     value = (char *)GetPref(newkey);
01737     if(!value)
01738         value="";
01739     return(value);
01740 }
01741 
01742 float fGetLocalPref(char *key) {
01743     float value=0;
01744 
01745     value=atof(cGetLocalPref(key));
01746     return(value);
01747 }
01748 
01749 int iGetLocalPref(char *key) {
01750     int value=0;
01751 
01752     value=atoi(cGetLocalPref(key));
01753     return(value);
01754 }
01755 
01756 /*
01757  * Sound Preferences Dialog
01758  */
01759 
01760 //gchar *sounddevice_old = "/dev/audio"; //defaults at "/dev/audio"
01761 //gint use_sounddevice_old = 0;
01762 //gint use_typical_sound_method_old = 0;
01763 gint do_away_sound = 1;
01764 gint do_away_sound_old = 1;
01765 gint do_no_sound_when_away = 0;
01766 gint do_no_sound_when_away_old = 0;
01767 gint do_no_sound_for_ignore = 1;
01768 gint do_no_sound_for_ignore_old = 1;
01769 gint do_online_sound = 1;
01770 gint do_online_sound_old = 1;
01771 gint do_play_send = 1;
01772 gint do_play_send_old = 1;
01773 gint do_play_first = 1;
01774 gint do_play_first_old = 1;
01775 gint do_play_receive = 1;
01776 gint do_play_receive_old = 1;
01777 
01778 // todo: allocate these 14KB of buffers dynamically
01779 //gchar *sounddevice = "/dev/audio"; //defaults at "/dev/audio"
01780 //gint use_sounddevice = 0;
01781 //gint use_typical_sound_method = 0;
01782 
01783 gchar BuddyArriveFilename_old[1024] = BuddyArriveDefault;
01784 gchar BuddyAwayFilename_old[1024] = BuddyLeaveDefault;
01785 gchar BuddyLeaveFilename_old[1024] = BuddyLeaveDefault;
01786 gchar FirstMsgFilename_old[1024] = ReceiveDefault;
01787 gchar ReceiveFilename_old[1024] = ReceiveDefault;
01788 gchar SendFilename_old[1024] = SendDefault;
01789 
01790 gfloat volume_sound_old = 0;
01791 
01792 static GtkWidget *arrivesoundentry=NULL;
01793 static GtkWidget *awaysoundentry=NULL;
01794 static GtkWidget *leavesoundentry=NULL;
01795 static GtkWidget *sendsoundentry=NULL;
01796 static GtkWidget *receivesoundentry=NULL;
01797 static GtkWidget *firstmsgsoundentry=NULL;
01798 static GtkWidget *volumesoundentry=NULL;
01799 
01800 GtkWidget *add_sound_file_selection_box(gchar *, GtkWidget *, gchar *, int);
01801 GtkWidget *add_sound_volume_selection_box(gchar *, GtkWidget *, GtkAdjustment *);
01802 /* Main Sound Preferences Funtion, hooks in the rest */
01803 
01804 void build_sound_prefs(GtkWidget *prefs_note) 
01805 {
01806      GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
01807      build_sound_tab(vbox);
01808      gtk_widget_show (vbox);
01809      gtk_notebook_append_page(GTK_NOTEBOOK(prefs_note), vbox, gtk_label_new(_("Sound")));
01810 
01811      gtk_widget_show(prefs_note);
01812 
01813 }
01814 
01815      /* This is the sound sub-tabs code */
01816 
01817 void build_sound_tab(GtkWidget * parent_window)
01818 {
01819 
01820      GtkWidget * sound_vbox;
01821      GtkWidget * sound_note;
01822 
01823      sound_note = gtk_notebook_new();
01824 
01825      /* Values */
01826      do_no_sound_when_away_old = do_no_sound_when_away;
01827      do_no_sound_for_ignore_old = do_no_sound_for_ignore;
01828      do_online_sound_old = do_online_sound;
01829      do_play_send_old = do_play_send;
01830      do_play_first_old = do_play_first;
01831      do_play_receive_old = do_play_receive;
01832 //  use_typical_sound_method_old = use_typical_sound_method;
01833 //  use_sounddevice_old = use_sounddevice;
01834 //  sounddevice_old = sounddevice;
01835      strcpy(BuddyArriveFilename_old, cGetLocalPref("BuddyArriveFilename"));
01836      strcpy(BuddyAwayFilename_old, cGetLocalPref("BuddyAwayFilename"));
01837      strcpy(BuddyLeaveFilename_old, cGetLocalPref("BuddyLeaveFilename"));
01838      strcpy(SendFilename_old, cGetLocalPref("SendFilename"));
01839      strcpy(ReceiveFilename_old, cGetLocalPref("ReceiveFilename"));
01840      strcpy(FirstMsgFilename_old, cGetLocalPref("FirstMsgFilename"));
01841      volume_sound_old = iGetLocalPref("SoundVolume");
01842 
01843      /* General Tab */
01844  
01845     sound_vbox = gtk_vbox_new(FALSE, 5);
01846      gtk_widget_show(sound_vbox);
01847 
01848      eb_button(_("Disable sounds when away"), &do_no_sound_when_away, sound_vbox);
01849      eb_button(_("Disable sounds for Ignored people"), &do_no_sound_for_ignore, sound_vbox);
01850      eb_button(_("Enable sounds when sending to a person that is away"),&do_away_sound, sound_vbox);
01851      eb_button(_("Play sounds when signing on or off"), &do_online_sound, sound_vbox);
01852      eb_button(_("Play a sound when sending a message"), &do_play_send, sound_vbox);
01853      eb_button(_("Play a sound when receiving a message"), &do_play_receive, sound_vbox);
01854      eb_button(_("Play a sound when receiving first message"), &do_play_first, sound_vbox);
01855 
01856     gtk_notebook_append_page(GTK_NOTEBOOK(sound_note), sound_vbox, gtk_label_new(_("General")));
01857 
01858      /* Files Tab */
01859 
01860      sound_vbox = gtk_vbox_new(FALSE, 5);
01861      gtk_widget_show(sound_vbox);
01862 
01863      //FIXME: These widgets are never properly freed, why not?
01864      arrivesoundentry = 
01865       add_sound_file_selection_box(_("Buddy Arrive Sound: "),
01866                        sound_vbox,
01867                        cGetLocalPref("BuddyArriveFilename"),
01868                        BUDDY_ARRIVE);
01869      awaysoundentry = 
01870       add_sound_file_selection_box(_("Buddy Away Sound: "),
01871                        sound_vbox,
01872                        cGetLocalPref("BuddyAwayFilename"),
01873                        BUDDY_AWAY);
01874      leavesoundentry = 
01875       add_sound_file_selection_box(_("Buddy Leave Sound: "),
01876                        sound_vbox,
01877                        cGetLocalPref("BuddyLeaveFilename"),
01878                        BUDDY_LEAVE);
01879 
01880      sendsoundentry = 
01881       add_sound_file_selection_box(_("Send Sound: "),
01882                        sound_vbox,
01883                        cGetLocalPref("SendFilename"),
01884                        SEND);
01885 
01886      firstmsgsoundentry = 
01887       add_sound_file_selection_box(_("1st Message Receive: "),
01888                        sound_vbox,
01889                        cGetLocalPref("FirstMsgFilename"),
01890                        FIRSTMSG);
01891 
01892      receivesoundentry = 
01893       add_sound_file_selection_box(_("Receive Sound: "),
01894                        sound_vbox,
01895                        cGetLocalPref("ReceiveFilename"),
01896                        RECEIVE);
01897      volumesoundentry =
01898        add_sound_volume_selection_box(_("Relative Volume (dB)"),
01899                       sound_vbox,
01900                       GTK_ADJUSTMENT(gtk_adjustment_new(iGetLocalPref("SoundVolume"),
01901                              -40,0,1,5,0)));
01902 
01903      gtk_widget_show(sound_vbox);
01904      gtk_notebook_append_page(GTK_NOTEBOOK(sound_note), sound_vbox, 
01905                   gtk_label_new(_("Files")));
01906 
01907      gtk_widget_show(sound_note);
01908      gtk_container_add(GTK_CONTAINER(parent_window), sound_note);
01909 
01910 }
01911 
01912 void cancel_sound_prefs()
01913 {
01914      /* Values */
01915 //  use_typical_sound_method = use_typical_sound_method_old;
01916 //  use_sounddevice = use_sounddevice_old;
01917 //  sounddevice = sounddevice_old;
01918      do_play_send = do_play_send_old;
01919      do_play_first = do_play_first_old;
01920      do_play_receive = do_play_receive_old;
01921      do_online_sound = do_online_sound_old;
01922      do_no_sound_when_away = do_no_sound_when_away_old;
01923      do_no_sound_for_ignore = do_no_sound_for_ignore_old;
01924      do_away_sound = do_away_sound_old;
01925      cSetLocalPref("BuddyArriveFilename", BuddyArriveFilename_old);
01926      cSetLocalPref("BuddyAwayFilename", BuddyAwayFilename_old);
01927      cSetLocalPref("BuddyLeaveFilename", BuddyLeaveFilename_old);
01928      cSetLocalPref("SendFilename", SendFilename_old);
01929      cSetLocalPref("ReceiveFilename", ReceiveFilename_old);
01930      cSetLocalPref("FirstMsgFilename", FirstMsgFilename_old);
01931      fSetLocalPref("SoundVolume", volume_sound_old);
01932 
01933      /* Widgets */
01934      gtk_entry_set_text (GTK_ENTRY (arrivesoundentry), cGetLocalPref("BuddyArriveFilename"));
01935      gtk_entry_set_text (GTK_ENTRY (awaysoundentry), cGetLocalPref("BuddyAwayFilename"));
01936      gtk_entry_set_text (GTK_ENTRY (leavesoundentry), cGetLocalPref("BuddyLeaveFilename"));
01937      gtk_entry_set_text (GTK_ENTRY (sendsoundentry), cGetLocalPref("SendFilename"));
01938      gtk_entry_set_text (GTK_ENTRY (receivesoundentry), cGetLocalPref("ReceiveFilename"));
01939      gtk_entry_set_text (GTK_ENTRY (firstmsgsoundentry), cGetLocalPref("FirstMsgFilename"));
01940 }
01941 
01942 static void setsoundfilename(char * filename, gpointer data);
01943 //static void setsoundfilename(GtkWidget * fileselector, int userdata);
01944 static void getsoundfile (GtkWidget * sendf_button, gpointer userdata);
01945 /*static void soundfile_entry_changed(GtkEntry * entry, int userdata);*/
01946 static void testsoundfile (GtkWidget * sendf_button, int userdata);
01947 static void soundvolume_changed(GtkAdjustment * adjust, int userdata);
01948 
01949 GtkWidget *add_sound_file_selection_box(gchar *labelString,
01950                     GtkWidget *vbox,
01951                     gchar *initialFilename,
01952                     int userdata) 
01953 {
01954      GtkWidget *hbox;
01955      GtkWidget *widget;
01956      GtkWidget *label;
01957      GtkWidget *button;
01958      hbox = gtk_hbox_new(FALSE, 3);
01959      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
01960 
01961      label = gtk_label_new (labelString);
01962      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 3);
01963      gtk_widget_set_usize(label, 125, 10);
01964      gtk_widget_show (label);
01965 
01966      widget = gtk_entry_new ();
01967      gtk_entry_set_text (GTK_ENTRY (widget), initialFilename);
01968      gtk_widget_ref (widget);
01969 /*     gtk_signal_connect(GTK_OBJECT(widget), "changed", 
01970             GTK_SIGNAL_FUNC(soundfile_entry_changed), 
01971             (gpointer) userdata);*/
01972      gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
01973      gtk_widget_show (widget);
01974 
01975      button = gtk_button_new_with_label (_("Browse"));
01976      gtk_signal_connect(GTK_OBJECT(button), "clicked", 
01977             GTK_SIGNAL_FUNC(getsoundfile), 
01978             (gpointer)userdata);
01979      gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
01980      gtk_widget_show (button);
01981 
01982      button = gtk_button_new_with_label (_("Preview"));
01983      gtk_signal_connect(GTK_OBJECT(button), "clicked", 
01984             GTK_SIGNAL_FUNC(testsoundfile), 
01985             (gpointer)userdata);
01986      gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
01987      gtk_widget_show (button);
01988      gtk_widget_show(hbox);
01989      return widget;
01990 }
01991 
01992 GtkWidget *add_sound_volume_selection_box(gchar *labelString,
01993                       GtkWidget *vbox,
01994                       GtkAdjustment *adjust)
01995 {
01996      GtkWidget *hbox;
01997      GtkWidget *widget;
01998      GtkWidget *label;
01999      int dummy=0;
02000      hbox = gtk_hbox_new(FALSE, 3);
02001      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
02002 
02003      label = gtk_label_new (labelString);
02004      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 3);
02005      gtk_widget_set_usize(label, 125, 10);
02006      gtk_widget_show (label);
02007 
02008      widget=gtk_hscale_new(adjust);
02009      /*     widget = gtk_entry_new ();
02010         gtk_entry_set_text (GTK_ENTRY (widget), initialFilename); */
02011      gtk_widget_ref (widget);
02012      gtk_signal_connect(GTK_OBJECT(adjust), "value_changed", 
02013             GTK_SIGNAL_FUNC(soundvolume_changed), 
02014             (gpointer) dummy);
02015      gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
02016      gtk_widget_show (widget);
02017 
02018      gtk_widget_show(hbox);
02019      return widget;
02020 }
02021 
02022 GtkWidget *soundfileselector;
02023 
02024 static void getsoundfile (GtkWidget * sendf_button, gpointer userdata)
02025 {
02026 //  GtkWidget *file_selector;
02027      eb_debug(DBG_CORE, "Just entered getsoundfile\n");
02028      eb_do_file_selector(NULL, _("Select a file to use"), setsoundfilename, 
02029              userdata);
02030 }
02031 
02032 /*static void soundfile_entry_changed(GtkEntry * entry, int userdata)
02033 {
02034     char *ptr=NULL;
02035      switch(userdata) 
02036      {
02037      case BUDDY_ARRIVE:
02038       ptr=gtk_entry_get_text(GTK_ENTRY (arrivesoundentry));
02039       cSetLocalPref("BuddyArriveFilename", ptr);
02040       break;
02041      case BUDDY_LEAVE:  
02042       ptr=gtk_entry_get_text(GTK_ENTRY (leavesoundentry));
02043       cSetLocalPref("BuddyLeaveFilename", ptr);
02044       break;
02045      case SEND:
02046       ptr=gtk_entry_get_text(GTK_ENTRY (sendsoundentry));
02047       cSetLocalPref("SendFilename", ptr);
02048       break;
02049      case RECEIVE:
02050       ptr=gtk_entry_get_text(GTK_ENTRY (receivesoundentry));
02051       cSetLocalPref("ReceiveFilename", ptr);
02052       break;
02053      case BUDDY_AWAY:
02054       ptr=gtk_entry_get_text(GTK_ENTRY (awaysoundentry));
02055       cSetLocalPref("BuddyAwayFilename", ptr);
02056       break;
02057      case FIRSTMSG:
02058       ptr=gtk_entry_get_text(GTK_ENTRY (firstmsgsoundentry));
02059       cSetLocalPref("FirstMsgFilename", ptr);
02060       break;
02061      }
02062      if(ptr)
02063     free(ptr);
02064 }*/
02065 
02066 static void update_soundfile_entries()
02067 {
02068     if(arrivesoundentry == NULL) return;
02069     cSetLocalPref("BuddyArriveFilename", 
02070             gtk_entry_get_text(GTK_ENTRY (arrivesoundentry)));
02071     cSetLocalPref("BuddyLeaveFilename", 
02072             gtk_entry_get_text(GTK_ENTRY (leavesoundentry)));
02073     cSetLocalPref("SendFilename", 
02074             gtk_entry_get_text(GTK_ENTRY (sendsoundentry)));
02075     cSetLocalPref("ReceiveFilename", 
02076             gtk_entry_get_text(GTK_ENTRY (receivesoundentry)));
02077     cSetLocalPref("BuddyAwayFilename", 
02078             gtk_entry_get_text(GTK_ENTRY (awaysoundentry)));
02079     cSetLocalPref("FirstMsgFilename", 
02080             gtk_entry_get_text(GTK_ENTRY (firstmsgsoundentry)));
02081 }
02082 
02083 
02084 static void setsoundfilename(char * selected_filename, gpointer data)
02085 //static void setsoundfilename(GtkWidget * fileselector, int userdata)
02086 {
02087 //     gchar *selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(soundfileselector));
02088 
02089     int userdata = (int)data;
02090 
02091     if(!selected_filename)
02092         return;
02093 
02094      eb_debug(DBG_CORE, "Just entered setsoundfilename and the selected file is %s\n", selected_filename);
02095      switch(userdata) 
02096      {
02097      case BUDDY_ARRIVE:     
02098       cSetLocalPref("BuddyArriveFilename", selected_filename);
02099       gtk_entry_set_text (GTK_ENTRY (arrivesoundentry), 
02100                   selected_filename);
02101       break;
02102      case BUDDY_LEAVE:  
02103       cSetLocalPref("BuddyLeaveFilename", selected_filename);
02104       gtk_entry_set_text (GTK_ENTRY (leavesoundentry), 
02105                   selected_filename);
02106       break;
02107      case SEND:     
02108       cSetLocalPref("SendFilename", selected_filename);
02109       gtk_entry_set_text (GTK_ENTRY (sendsoundentry), selected_filename);
02110       break;
02111      case RECEIVE:      
02112       cSetLocalPref("ReceiveFilename", selected_filename);
02113       gtk_entry_set_text (GTK_ENTRY (receivesoundentry), 
02114                   selected_filename);
02115       break;
02116      case BUDDY_AWAY:   
02117       cSetLocalPref("BuddyAwayFilename", selected_filename);
02118       gtk_entry_set_text (GTK_ENTRY (awaysoundentry), selected_filename);
02119       break;
02120      case FIRSTMSG:     
02121       cSetLocalPref("FirstMsgFilename", selected_filename);
02122       gtk_entry_set_text (GTK_ENTRY (firstmsgsoundentry), 
02123                   selected_filename);
02124       break;
02125 
02126      }
02127 }
02128 
02129 static void testsoundfile (GtkWidget * sendf_button, int userdata)
02130 {
02131      switch(userdata) 
02132      {
02133      case BUDDY_ARRIVE:
02134       playsoundfile(cGetLocalPref("BuddyArriveFilename"));
02135       break;
02136         
02137      case BUDDY_LEAVE:
02138       playsoundfile(cGetLocalPref("BuddyLeaveFilename"));
02139       break;
02140     
02141      case SEND:
02142       playsoundfile(cGetLocalPref("SendFilename"));
02143       break;
02144     
02145      case RECEIVE:
02146       playsoundfile(cGetLocalPref("ReceiveFilename"));
02147       break;
02148     
02149      case BUDDY_AWAY:
02150       playsoundfile(cGetLocalPref("BuddyAwayFilename"));
02151       break;
02152     
02153      case FIRSTMSG:
02154       playsoundfile(cGetLocalPref("FirstMsgFilename"));
02155       break;
02156 
02157      }
02158 }
02159 
02160 static void soundvolume_changed(GtkAdjustment * adjust, int userdata)
02161 {
02162   fSetLocalPref("SoundVolume", adjust->value);
02163 }
02164 
02165 void write_sound_prefs(FILE *fp)
02166 {
02167     update_soundfile_entries();
02168 
02169      fprintf(fp,"do_play_send=%d\n", do_play_send);
02170      fprintf(fp,"do_play_first=%d\n", do_play_first);
02171      fprintf(fp,"do_play_receive=%d\n", do_play_receive);
02172      fprintf(fp,"do_online_sound=%d\n", do_online_sound);
02173 //  fprintf(fp,"use_typical_sound_method=%d\n", use_typical_sound_method);
02174 //  fprintf(fp,"use_sounddevice=%d\n", use_sounddevice);
02175      fprintf(fp,"do_away_sound=%d\n", do_away_sound);
02176      fprintf(fp,"do_no_sound_when_away=%d\n", do_no_sound_when_away);
02177      fprintf(fp,"BuddyArriveFilename=%s\n", cGetLocalPref("BuddyArriveFilename"));
02178      fprintf(fp,"BuddyAwayFilename=%s\n", cGetLocalPref("BuddyAwayFilename"));
02179      fprintf(fp,"BuddyLeaveFilename=%s\n", cGetLocalPref("BuddyLeaveFilename"));
02180      fprintf(fp,"SendFilename=%s\n", cGetLocalPref("SendFilename"));
02181      fprintf(fp,"ReceiveFilename=%s\n", cGetLocalPref("ReceiveFilename"));
02182      fprintf(fp,"FirstMsgFilename=%s\n", cGetLocalPref("FirstMsgFilename"));
02183      fprintf(fp,"SoundVolume=%f\n", fGetLocalPref("SoundVolume"));
02184 }
02185 
02186 void destroy_sound_prefs(void) {
02187     gtk_widget_destroy(arrivesoundentry);
02188     gtk_widget_destroy(awaysoundentry);
02189     gtk_widget_destroy(leavesoundentry);
02190     gtk_widget_destroy(sendsoundentry);
02191     gtk_widget_destroy(receivesoundentry);
02192     gtk_widget_destroy(firstmsgsoundentry);
02193     gtk_widget_destroy(volumesoundentry);
02194     arrivesoundentry=NULL;
02195     awaysoundentry=NULL;
02196     leavesoundentry=NULL;
02197     sendsoundentry=NULL;
02198     receivesoundentry=NULL;
02199     firstmsgsoundentry=NULL;
02200     volumesoundentry=NULL;
02201 }
02202 /*
02203  * Reading/Writing Prefs
02204  */
02205 void write_prefs()
02206 {
02207      gchar buff[1024], file[1024];
02208      FILE * fp;
02209      // todo: write to temp file and rename at end to prevent damaged files
02210      g_snprintf(buff, 1024, "%sprefs.tmp",config_dir);
02211      g_snprintf(file, 1024, "%sprefs",config_dir);
02212      fp = fopen(buff, "w");
02213      write_general_prefs(fp);
02214      write_logs_prefs(fp);
02215      write_sound_prefs(fp);
02216      write_chat_prefs(fp);
02217      write_layout_prefs(fp);
02218 #ifdef HAVE_ICONV_H
02219      write_encoding_prefs(fp);
02220 #endif
02221      write_proxy_prefs(fp);
02222      write_module_prefs(fp);
02223 //     write_connections_prefs(fp);
02224      fprintf(fp, "end\n");
02225      fclose(fp);
02226      rename(buff,file);
02227 }
02228 
02229 #define PLUGIN_PREF 1
02230 #define SERVICE_PREF 2
02231 
02232 // todo: re-organize to separate pref reading into modules
02233 void eb_read_prefs()
02234 {
02235     gchar buff[1024];
02236     int pref_type=0;
02237     FILE * fp;
02238     gchar *param=buff;
02239     gchar *val=buff;
02240 
02241     /* Set some default values */
02242     iSetLocalPref("length_contact_window", length_contact_window_def);
02243     iSetLocalPref("width_contact_window", width_contact_window_def);
02244     cSetLocalPref("modules_path", MODULE_DIR);
02245     cSetLocalPref("BuddyArriveFilename", BuddyArriveDefault);
02246     cSetLocalPref("BuddyAwayFilename", BuddyLeaveDefault);
02247     cSetLocalPref("BuddyLeaveFilename", BuddyLeaveDefault);
02248     cSetLocalPref("FirstMsgFilename", ReceiveDefault);
02249     cSetLocalPref("ReceiveFilename", ReceiveDefault);
02250     cSetLocalPref("SendFilename", SendDefault);
02251     iSetLocalPref("FontSize", font_size_def);
02252     
02253     g_snprintf(buff, 1024, "%sprefs",config_dir);
02254     fp = fopen(buff, "r");
02255     if(!fp)
02256     {
02257         /* This would cause things to crash if there is no file, as services
02258         * are not loaded yet.  It will be called when actual changes are made
02259         * to preferences, until then, it doesn't need to be written.
02260         */
02261         printf("can't open %s\n",buff);
02262 //      write_prefs();
02263         return;
02264     }
02265     while(!feof(fp))
02266     {
02267         fgets(buff, 1024, fp);
02268         param=buff;
02269         if(feof(fp))
02270             break;
02271         g_strstrip(param);
02272         pref_type=0;
02273         if(!strcasecmp(buff, "plugins"))
02274             pref_type=PLUGIN_PREF;
02275         else if(!strcasecmp(buff, "connections"))
02276             pref_type=SERVICE_PREF;
02277         if(pref_type!=0)
02278         {
02279             for(;;)
02280             {
02281                 int id=-1;
02282                 char *plugin_name=NULL;
02283                 GList * session_prefs = NULL;
02284                 GList *osession_prefs = NULL;
02285                 fgets(buff, 1024, fp);
02286                 param=buff;
02287                 g_strstrip(param);
02288                 if(!strcasecmp(param, "end"))
02289                 {
02290                     break;
02291                 }
02292                 switch(pref_type) {
02293                 case PLUGIN_PREF:
02294                     plugin_name=strdup(param);
02295                     break;
02296                 case SERVICE_PREF:
02297                     id = get_service_id(param);
02298                     break;
02299                 default:
02300                     break;
02301                 }
02302 
02303                 for(;;)
02304                 {
02305                     fgets(buff, 1024, fp);
02306                     param=buff;
02307                     g_strstrip(param);
02308                     if(!strcasecmp(param, "end"))
02309                     {
02310                         switch(pref_type) {
02311                         case PLUGIN_PREF:
02312                             osession_prefs = SetPref(plugin_name, session_prefs);
02313                             if(osession_prefs)
02314                             {
02315                                 eb_debug(DBG_CORE, "Freeing osession_prefs\n");
02316                                 value_pair_free(osession_prefs);
02317                             }
02318                             free(plugin_name);
02319                             break;
02320                         case SERVICE_PREF:
02321                             osession_prefs = SetPref(get_service_name(id), session_prefs);
02322                             if(osession_prefs)
02323                             {
02324                                 eb_debug(DBG_CORE, "Freeing osession_prefs\n");
02325                                 value_pair_free(osession_prefs);
02326                             }
02327                             break;
02328                         default:
02329                             eb_debug(DBG_CORE, "Error!  We're not supposed to ever get here!\n");
02330                             break;
02331                         }
02332                         break;
02333                     }
02334                     else
02335                     {
02336                         val=param;
02337 
02338                         while(*val != 0 && *val !='=')
02339                             val++;
02340                         if(*val=='=')
02341                         {
02342                             *val='\0';
02343                             val++;
02344                         }
02345 
02346                         /*
02347                         * if quoted strip off the quotes
02348                         */
02349 
02350                         if(*val == '"')
02351                         {
02352                             val++;
02353                             val[strlen(val)-1] = '\0';
02354                         }
02355                         eb_debug(DBG_CORE,"Adding %s:%s to session_prefs\n", param, val);
02356                         session_prefs = value_pair_add(session_prefs,
02357                             param, val);
02358                     }
02359                 }
02360             }
02361             continue;
02362         } /* if(pref_type !=0) */
02363         val=param;
02364 
02365         while(*val != 0 && *val !='=')
02366             val++;
02367         if(*val=='=')
02368         {
02369             *val='\0';
02370             val++;
02371         }
02372         cSetLocalPref(param, val);
02373     }
02374     do_logging            =iGetLocalPref("do_logging");
02375     do_strip_html         =iGetLocalPref("do_strip_html");
02376     do_play_send          =iGetLocalPref("do_play_send");
02377     do_play_first         =iGetLocalPref("do_play_first");
02378     do_play_receive       =iGetLocalPref("do_play_receive");
02379     do_ignore_unknown     =iGetLocalPref("do_ignore_unknown");
02380     do_send_idle_time     =iGetLocalPref("do_send_idle_time");
02381     do_raise_window       =iGetLocalPref("do_raise_window");
02382     do_timestamp          =iGetLocalPref("do_timestamp");
02383     do_online_sound       =iGetLocalPref("do_online_sound");
02384     do_multi_line         =iGetLocalPref("do_multi_line");
02385     do_ignore_fore        =iGetLocalPref("do_ignore_fore");
02386     do_ignore_back        =iGetLocalPref("do_ignore_back");
02387     do_ignore_font        =iGetLocalPref("do_ignore_font");
02388     do_convo_timestamp    =iGetLocalPref("do_convo_timestamp");
02389     do_typing_notify      =iGetLocalPref("do_typing_notify");
02390     do_send_typing_notify =iGetLocalPref("do_send_typing_notify");
02391     do_smiley             =iGetLocalPref("do_smiley");
02392     do_escape_close       =iGetLocalPref("do_escape_close");
02393     do_enter_send         =iGetLocalPref("do_enter_send");
02394 #ifdef HAVE_ICONV_H
02395     use_recoding          =iGetLocalPref("use_recoding");
02396 #endif
02397     do_restore_last_conv  =iGetLocalPref("do_restore_last_conv");
02398     /*
02399     use_typical_sound_method=iGetLocalPref("use_typical_sound_method");
02400     use_sounddevice=cGetLocalPref("use_sounddevice");
02401     */
02402     do_away_sound         =iGetLocalPref("do_away_sound");
02403     do_no_sound_when_away =iGetLocalPref("do_no_sound_when_away");
02404     do_no_sound_for_ignore=iGetLocalPref("do_no_sound_for_ignore");
02405     do_tabbed_chat        =iGetLocalPref("do_tabbed_chat");
02406     do_tabbed_chat_orient =iGetLocalPref("do_tabbed_chat_orient");
02407 #ifdef HAVE_ISPELL
02408     do_spell_checking     =iGetLocalPref("do_spell_checking");
02409 #endif
02410         do_noautoresize       =iGetLocalPref("do_noautoresize");
02411     use_alternate_browser =iGetLocalPref("use_alternate_browser");
02412     do_applet_show_on_startup=iGetLocalPref("do_applet_show_on_startup");
02413     do_login_on_startup   =iGetLocalPref("do_login_on_startup");
02414     do_yattm_debug   =iGetLocalPref("do_yattm_debug");
02415     do_yattm_debug_html=iGetLocalPref("do_yattm_debug_html");
02416     do_plugin_debug       =iGetLocalPref("do_plugin_debug");
02417     font_size         =iGetLocalPref("FontSize");
02418      gtk_accelerator_parse(cGetLocalPref("accel_next_tab"), &(accel_next_tab.keyval), &(accel_next_tab.modifiers));
02419      gtk_accelerator_parse(cGetLocalPref("accel_prev_tab"), &(accel_prev_tab.keyval), &(accel_prev_tab.modifiers));
02420      proxy_set_proxy(iGetLocalPref("proxy_type"), cGetLocalPref("proxy_host"), iGetLocalPref("proxy_port"));
02421      proxy_set_auth(iGetLocalPref("do_proxy_auth"), cGetLocalPref("proxy_user"), cGetLocalPref("proxy_password"));
02422      fclose(fp);
02423 }
02424 
02425 /*
02426  * Cancel button
02427  */
02428 static void cancel_callback(GtkWidget * widget, gpointer data)
02429 {
02430      cancel_general_prefs();
02431      cancel_logs_prefs();
02432      cancel_layout_prefs();
02433      cancel_chat_prefs();
02434      cancel_sound_prefs();
02435 //     cancel_connections_prefs();
02436      cancel_proxy_prefs();
02437      
02438 }
02439 
02440 static void ok_callback(GtkWidget * widget, gpointer data)
02441 {
02442      write_prefs();
02443 }
02444 
02445 /*
02446  * Destroy prefs window
02447  */
02448 static void destroy(GtkWidget * widget, gpointer data)
02449 {
02450      is_prefs_open = 0;
02451      destroy_proxy();
02452      destroy_general_prefs();
02453      destroy_chat_prefs();
02454      destroy_sound_prefs();
02455      /* reset current parent so error dialogs work correctly */
02456 #ifdef HAVE_ICONV_H
02457      destroy_encodings();
02458 #endif
02459      destroy_modules();
02460      /* it'd be nice to check validity of recoding here 
02461     and cancel change if not supported */
02462 
02463 #ifdef HAVE_ISPELL
02464      if ((!do_spell_checking) && (gtkspell_running()))
02465          gtkspell_stop();
02466 #endif
02467      gtk_widget_destroy(current_parent_widget);
02468      current_parent_widget = NULL;
02469 
02470 }

Contact: Andy Maloney     [Documentation generated by doxygen]