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

input_list.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 #include "intl.h"
00023 #include <gtk/gtk.h>
00024 #include <string.h>
00025 #include <stdlib.h>
00026 #include "globals.h"
00027 #include "debug.h"
00028 #include "dialog.h"
00029 #include "input_list.h"
00030 #include "value_pair.h"
00031 
00032 void eb_input_render(input_list * il, GtkWidget * box)
00033 {
00034     /* XXX: for backwards compatibility remove later */
00035     char *item_label=NULL;
00036 
00037     if(!il)
00038     {
00039         return;
00040     }
00041 
00042     /* XXX: for backwards compatibility change later */
00043     switch(il->type)
00044     {
00045         case EB_INPUT_CHECKBOX:
00046             if(il->widget.checkbox.label)
00047                 item_label = il->widget.checkbox.label;
00048             else
00049                 item_label = il->widget.checkbox.name;
00050 
00051             break;
00052         case EB_INPUT_ENTRY:
00053             if(il->widget.entry.label)
00054                 item_label = il->widget.entry.label;
00055             else
00056                 item_label = il->widget.entry.name;
00057 
00058             break;
00059     }
00060     /* End b/w comp code */
00061 
00062     switch(il->type)
00063     {
00064         case EB_INPUT_CHECKBOX:
00065             {
00066                 eb_button(item_label, /* XXX */
00067                         il->widget.checkbox.value,
00068                         box);
00069                 il->widget.checkbox.saved_value =
00070                     *(il->widget.checkbox.value);
00071             }
00072             break;
00073         case EB_INPUT_ENTRY:
00074             {
00075                 GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
00076                 GtkWidget * widget = gtk_label_new(item_label); /* XXX */
00077                 gtk_widget_set_usize(widget, 100, 15);
00078                 gtk_box_pack_start(GTK_BOX(hbox),
00079                         widget, FALSE, FALSE, 0);
00080                 gtk_widget_show(widget);
00081 
00082                 widget = gtk_entry_new();
00083                 il->widget.entry.entry = widget;
00084                 gtk_entry_set_text(GTK_ENTRY(widget),
00085                         il->widget.entry.value);
00086                 gtk_box_pack_start(GTK_BOX(hbox),
00087                         widget, FALSE, FALSE, 0);
00088                 gtk_widget_show(widget);
00089 
00090                 gtk_box_pack_start(GTK_BOX(box), hbox,
00091                         FALSE, FALSE, 0);
00092                 gtk_widget_show(hbox);
00093 
00094 
00095             }
00096             break;
00097     }
00098 
00099     eb_input_render(il->next, box);
00100 }
00101 
00102 void eb_input_cancel(input_list * il)
00103 {
00104     if(!il)
00105     {
00106         return;
00107     }
00108 
00109     switch(il->type)
00110     {
00111         case EB_INPUT_CHECKBOX:
00112             {
00113                 *(il->widget.checkbox.value)
00114                     = il->widget.checkbox.saved_value;
00115             }
00116             break;
00117         case EB_INPUT_ENTRY:
00118             {
00119                 GtkWidget * w = il->widget.entry.entry;
00120                 char * text = il->widget.entry.value;
00121                 gtk_entry_set_text(GTK_ENTRY(w), text);
00122             }
00123             break;
00124     }
00125 
00126     eb_input_cancel(il->next);
00127 }
00128 
00129 void eb_input_accept(input_list * il)
00130 {
00131     if(!il)
00132     {
00133         return;
00134     }
00135 
00136     switch(il->type)
00137     {
00138         case EB_INPUT_CHECKBOX:
00139             {
00140             }
00141             break;
00142         case EB_INPUT_ENTRY:
00143             {
00144                 GtkWidget * w = il->widget.entry.entry;
00145                 char * text = gtk_entry_get_text(GTK_ENTRY(w));
00146                 strncpy(il->widget.entry.value, text, MAX_PREF_LEN);
00147                 gtk_entry_set_text(GTK_ENTRY(w), il->widget.entry.value);
00148 
00149             }
00150             break;
00151     }
00152 
00153     eb_input_accept(il->next);
00154 }
00155 
00156 GList *eb_input_to_value_pair(input_list * il)
00157 {
00158     GList *vp=NULL;
00159     char key[MAX_PREF_NAME_LEN];
00160     char value[MAX_PREF_LEN];
00161     char *ptr=NULL;
00162 
00163     for(; il; il=il->next)
00164     {
00165         switch(il->type)
00166         {
00167             case EB_INPUT_CHECKBOX:
00168                 {
00169                     sprintf(key, "%s", il->widget.checkbox.name);
00170                     for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00171                         *ptr='_';
00172                     sprintf(value, "%i", *il->widget.checkbox.value);
00173                     vp=value_pair_add(vp, key, value);
00174                 }
00175                 break;
00176             case EB_INPUT_ENTRY:
00177                 {
00178                     sprintf(key, "%s", il->widget.entry.name);
00179                     for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00180                         *ptr='_';
00181                     vp=value_pair_add(vp, key, il->widget.entry.value);
00182                 }
00183                 break;
00184         }
00185     }
00186     return(vp);
00187 }
00188 
00189 void eb_update_from_value_pair(input_list *il, GList *vp)
00190 {
00191     char key[MAX_PREF_NAME_LEN];
00192     char *value;
00193     char *ptr=NULL;
00194 
00195     if(!il || ! vp)
00196         return;
00197     for(; il; il=il->next)
00198     {
00199         switch(il->type)
00200         {
00201             case EB_INPUT_CHECKBOX:
00202                 {
00203                     if(!il->widget.checkbox.value) {
00204                         eb_debug(DBG_CORE, "checkbox.value is NULL\n");
00205                         break;
00206                     }
00207                     sprintf(key, "%s", il->widget.checkbox.name);
00208                     for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00209                         *ptr='_';
00210                     value=value_pair_get_value(vp, key);
00211 
00212                     /* XXX
00213                      * this block is to convert old prefs files to new format.
00214                      * this should be removed after about two or three versions
00215                      * have been released.  We're currently in 0.4.2
00216                      */
00217                     if(!value && il->widget.checkbox.label) {
00218                         sprintf(key, "%s", il->widget.checkbox.label);
00219                         for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00220                             *ptr='_';
00221                         value=value_pair_get_value(vp, key);
00222                     }
00223 
00224                     /* Was there a matching entry? */
00225                     if(value) {
00226                         *il->widget.checkbox.value=atoi(value);
00227                         g_free(value);
00228                     }
00229                 }
00230                 break;
00231             case EB_INPUT_ENTRY:
00232                 {
00233                     if(!il->widget.entry.value) {
00234                         eb_debug(DBG_CORE, "entry.value is NULL\n");
00235                         break;
00236                     }
00237                     sprintf(key, "%s", il->widget.entry.name);
00238                     for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00239                         *ptr='_';
00240                     value=value_pair_get_value(vp, key);
00241                     
00242                     /* XXX
00243                      * this block is to convert old prefs files to new format.
00244                      * this should be removed after about two or three versions
00245                      * have been released.  We're currently in 0.4.2
00246                      */
00247                     if(!value && il->widget.entry.label) {
00248                         sprintf(key, "%s", il->widget.entry.label);
00249                         for( ptr=strchr(key, ' '); ptr; ptr=strchr(ptr, ' '))
00250                             *ptr='_';
00251                         value=value_pair_get_value(vp, key);
00252                     }
00253 
00254                     /* Was there a matching entry? */
00255                     if(value) {
00256                         strncpy(il->widget.entry.value, value, MAX_PREF_LEN);
00257                         g_free(value);
00258                     }
00259                 }
00260                 break;
00261         }
00262     }
00263 }

Contact: Andy Maloney     [Documentation generated by doxygen]