Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

mlview-attributes-list.c

Go to the documentation of this file.
00001 /*
00002  *This file is part of GNU MlView
00003  *
00004  *GNU MlView is free software; you can redistribute it and/or modify it under the terms of 
00005  *the GNU General Public License as published by the Free Software Foundation; either version 2, 
00006  *or (at your option) any later version.
00007  *
00008  *GNU MlView is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
00009  *without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010  *See the GNU General Public License for more details.
00011  *
00012  *You should have received a copy of the GNU General Public License along with MlView; 
00013  *see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00014  *
00015  *
00016  *Copyright 2001-2002 Dodji Seketeli.
00017  */
00018 
00019 #include <libxml/hash.h>
00020 
00021 #include "mlview-attributes-list.h"
00022 #include "mlview-name-value-pair.h"
00023 #include "mlview-attribute-picker.h"
00024 #include "utils.h"
00025 
00026 
00031 enum
00032 {
00033         EDIT_STATE_CHANGED,
00034         ATTRIBUTE_CHANGED,
00035         NUMBER_OF_SIGNALS
00036 };
00037 
00038 struct _MlViewAttributesListPrivate {
00040         GtkCList *attributes_view;
00041 
00043         GtkEntry *name_edit_entry ;
00044 
00046         GtkEntry *value_edit_entry ;
00047         
00049         GtkButton *add_attribute_button ;
00050 
00052         GtkButton *remove_attribute_button ;
00053 
00055         gchar *names_title ;
00056 
00058         gchar *values_title ;
00059 
00061         gint current_selected_row ; 
00062 
00064         gboolean editable ; 
00065 
00071         guint name_edit_entry_changed_handler_id ;
00072 
00078         guint value_edit_entry_changed_handler_id ;
00079 
00084         xmlNodePtr current_xml_node ;
00085 
00089         MlViewAppContext * app_context ;
00090 
00095         MlViewAttributePicker * attribute_picker ;
00096 };
00097 
00098 
00099 #define PRIVATE(list) ((list)->private)
00100 
00101 /*compulsory functions to comply with the Gtk type system framework*/
00102 static void mlview_attributes_list_class_init() ;
00103 static void mlview_attributes_list_init(MlViewAttributesList *a_attributes) ;
00104 static void mlview_attributes_list_destroy(GtkObject * a_object) ;
00105 static GtkVBoxClass *parent_class=NULL ;
00106 
00107 /*signals array*/
00108 static guint mlview_attributes_list_signals[NUMBER_OF_SIGNALS]={0} ;
00109 
00110 /*private helper functions*/
00111 static xmlAttr *  mlview_attributes_list_add_attribute_to_node_interactive(MlViewAttributesList * a_list,
00112                                                                            xmlNode * a_node) ;
00113 /*signal callbacks*/
00114 
00115 static void row_selected_cb(GtkCList *a_clist, gint a_row, gint a_column,
00116                             GdkEventButton *a_event, MlViewAttributesList *a_attributes) ;
00117 static void name_edit_entry_changed_cb(GtkEntry *a_entry, gpointer *a_attributes) ; /*called when a name edit entry changed*/
00118 static void value_edit_entry_changed_cb(GtkEntry *a_entry, MlViewAttributesList *a_attributes) ;/*called when a value edit entry changed*/
00119 static void add_attribute_button_clicked_cb(GtkButton *a_add_attribute_button, MlViewAttributesList *a_attributes_list) ;
00120 static void remove_attribute_button_clicked_cb(GtkButton *a_remove_attribute_button, MlViewAttributesList *a_attributes_list) ;
00121 
00122 /*default signal handlers*/
00123 static void mlview_attributes_list_edit_state_changed_default_handler(MlViewAttributesList *a_attributes,
00124                                                                       gpointer data) ;
00125 static void mlview_attributes_list_attribute_changed_default_handler(MlViewAttributesList *a_attributes,
00126                                                                     gpointer data) ;
00127 
00128 
00129 /*
00130  *Mandatory private functions to comply with the gtk object
00131  *framework. go to http://www.gtk.org/tutorial/sec-theanatomyofawidget.html
00132  *to learn about what the object oriented widget framework looks like.
00133  */
00134 
00135 
00140 static void
00141 mlview_attributes_list_class_init (MlViewAttributesListClass *a_klass)
00142 {
00143         GtkObjectClass *object_class ;
00144         g_return_if_fail (a_klass!=NULL) ;
00145         
00146         parent_class = gtk_type_class(GTK_TYPE_VBOX) ;
00147         
00148         object_class = GTK_OBJECT_CLASS(a_klass) ;
00149         object_class->destroy=mlview_attributes_list_destroy ; /*overload the destroy method of GtkObjectClass*/
00150   
00151         /*signal definitions*/
00152         mlview_attributes_list_signals[EDIT_STATE_CHANGED]=gtk_signal_new("edit-state-changed",
00153                                                                           GTK_RUN_FIRST,
00154                                                                           object_class->type,
00155                                                                           GTK_SIGNAL_OFFSET(MlViewAttributesListClass,edit_state_changed),
00156                                                                           gtk_marshal_NONE__NONE,
00157                                                                           GTK_TYPE_NONE,
00158                                                                           0);
00159         mlview_attributes_list_signals[ATTRIBUTE_CHANGED]=gtk_signal_new("attribute-changed",
00160                                                                         GTK_RUN_FIRST,
00161                                                                         object_class->type,
00162                                                                         GTK_SIGNAL_OFFSET(MlViewAttributesListClass,attribute_changed),
00163                                                                         gtk_marshal_NONE__NONE,
00164                                                                         GTK_TYPE_NONE,0);
00165         gtk_object_class_add_signals(object_class,mlview_attributes_list_signals,NUMBER_OF_SIGNALS) ;
00166         a_klass->edit_state_changed=mlview_attributes_list_edit_state_changed_default_handler;
00167         a_klass->attribute_changed=mlview_attributes_list_attribute_changed_default_handler;
00168 }
00169 
00175 static void
00176 mlview_attributes_list_init (MlViewAttributesList *a_attributes)
00177 {
00178         gchar * titles[2]={"names","values"} ;
00179         GtkWidget * nv_edition_table, *scrolled_window ;
00180   
00181         g_return_if_fail(a_attributes!=NULL);
00182 
00183         a_attributes->private = g_malloc0 (sizeof (MlViewAttributesListPrivate)) ;
00184 
00185         PRIVATE (a_attributes)->current_selected_row=-1 ;
00186         gtk_box_set_spacing (GTK_BOX (a_attributes),0) ;
00187         
00188         /*initialyze the attributes viewer*/
00189         PRIVATE (a_attributes)->attributes_view = 
00190                 GTK_CLIST (gtk_clist_new_with_titles (2,titles));
00191 
00192         gtk_signal_connect (GTK_OBJECT(PRIVATE (a_attributes)->attributes_view),
00193                             "select_row",
00194                             GTK_SIGNAL_FUNC (row_selected_cb),
00195                             a_attributes) ;
00196         scrolled_window = gtk_scrolled_window_new (NULL, NULL) ;
00197 
00198         gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(PRIVATE (a_attributes)->attributes_view)) ;
00199         gtk_box_pack_start(GTK_BOX(a_attributes),
00200                            scrolled_window,
00201                            TRUE,TRUE,0);
00202         gtk_widget_show (GTK_WIDGET(PRIVATE (a_attributes)->attributes_view)) ;
00203   
00204         /*init the value/name edition entries*/
00205         PRIVATE (a_attributes)->name_edit_entry  = GTK_ENTRY (gtk_entry_new ());
00206         gtk_entry_set_editable (PRIVATE (a_attributes)->name_edit_entry,
00207                                PRIVATE (a_attributes)->editable) ;
00208 
00209         PRIVATE (a_attributes)->name_edit_entry_changed_handler_id = 
00210                 gtk_signal_connect(GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry),
00211                                    "changed",
00212                                    GTK_SIGNAL_FUNC(name_edit_entry_changed_cb),
00213                                    a_attributes) ;      
00214   
00215         PRIVATE (a_attributes)->value_edit_entry = GTK_ENTRY (gtk_entry_new ());
00216         gtk_entry_set_editable (PRIVATE (a_attributes)->value_edit_entry,
00217                                 PRIVATE (a_attributes)->editable) ;
00218         PRIVATE (a_attributes)->value_edit_entry_changed_handler_id =
00219                 gtk_signal_connect(GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry),
00220                                    "changed",
00221                                    GTK_SIGNAL_FUNC(value_edit_entry_changed_cb),
00222                                    a_attributes) ;
00223         /*add/remove attribute buttons*/
00224         PRIVATE (a_attributes)->add_attribute_button = 
00225                 GTK_BUTTON (gtk_button_new_with_label (_("Add an attribute"))) ;
00226         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_attributes)->add_attribute_button),
00227                             "clicked",
00228                             GTK_SIGNAL_FUNC (add_attribute_button_clicked_cb),
00229                             a_attributes) ;
00230         PRIVATE (a_attributes)->remove_attribute_button = GTK_BUTTON( gtk_button_new_with_label (_("Remove attributes"))) ;
00231         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_attributes)->remove_attribute_button),
00232                             "clicked",
00233                             GTK_SIGNAL_FUNC (remove_attribute_button_clicked_cb),
00234                             a_attributes) ;
00235         nv_edition_table = gtk_table_new (2,2,TRUE) ;
00236         gtk_table_attach_defaults (GTK_TABLE (nv_edition_table),
00237                                    GTK_WIDGET (PRIVATE (a_attributes)->name_edit_entry),
00238                                    0,1,0,1) ;
00239         gtk_widget_show (GTK_WIDGET (PRIVATE (a_attributes)->name_edit_entry));
00240 
00241         gtk_table_attach_defaults (GTK_TABLE (nv_edition_table),
00242                                    GTK_WIDGET(PRIVATE (a_attributes)->value_edit_entry),
00243                                    1,2,0,1) ;
00244         gtk_widget_show (GTK_WIDGET (PRIVATE (a_attributes)->value_edit_entry));
00245         
00246         gtk_table_attach_defaults (GTK_TABLE(nv_edition_table),
00247                                    GTK_WIDGET(PRIVATE (a_attributes)->add_attribute_button),
00248                                    0,1,1,2) ;
00249         gtk_widget_show (GTK_WIDGET (PRIVATE (a_attributes)->add_attribute_button));
00250 
00251         gtk_table_attach_defaults (GTK_TABLE (nv_edition_table),
00252                                    GTK_WIDGET (PRIVATE (a_attributes)->remove_attribute_button),
00253                                    1,2,1,2) ;
00254         gtk_widget_show (GTK_WIDGET (PRIVATE (a_attributes)->remove_attribute_button));
00255         
00256         gtk_box_pack_start (GTK_BOX (a_attributes),
00257                             GTK_WIDGET (nv_edition_table),
00258                             FALSE,TRUE,0);
00259         gtk_widget_show (GTK_WIDGET (nv_edition_table)) ;
00260 
00261         mlview_attributes_list_set_editable (a_attributes,TRUE) ;
00262         PRIVATE (a_attributes)->names_title = NULL ;
00263         PRIVATE (a_attributes)->values_title = NULL ;
00264 }
00265 
00273 static void
00274 mlview_attributes_list_destroy (GtkObject *a_object)
00275 {
00276         MlViewAttributesList *attributes ;
00277 
00278         g_return_if_fail(a_object !=NULL) ;
00279         g_return_if_fail(MLVIEW_IS_ATTRIBUTES_LIST(a_object));
00280         
00281   
00282         attributes = MLVIEW_ATTRIBUTES_LIST(a_object) ;
00283         
00284         if (PRIVATE (attributes) == NULL)
00285                 return ;
00286   
00287         /*destroy allocated widgets and other objects*/
00288         if (PRIVATE (attributes)->names_title) {
00289                 g_free (PRIVATE (attributes)->names_title) ;
00290                 PRIVATE (attributes)->names_title = NULL;
00291         }
00292         if (PRIVATE (attributes)->values_title) {
00293                 g_free (PRIVATE (attributes)->values_title) ;
00294                 PRIVATE (attributes)->values_title=NULL;
00295         }
00296         
00297         if (PRIVATE (attributes)->attribute_picker) {
00298                 gtk_widget_destroy (GTK_WIDGET (PRIVATE (attributes)->attribute_picker)) ;
00299                 PRIVATE (attributes)->attribute_picker = NULL ;
00300         }
00301 
00302         if (PRIVATE (attributes)) {
00303                 g_free (PRIVATE (attributes)) ;
00304                 attributes->private = NULL ;
00305         }
00306 
00307         /*call the destroy method of the object class*/
00308         if(GTK_OBJECT_CLASS(parent_class)->destroy)
00309                 (*GTK_OBJECT_CLASS(parent_class)->destroy)(a_object) ;
00310 
00311 }
00312 
00313 /*===================================
00314  *private helper functions
00315  *==================================*/
00316 
00322 static xmlAttr* 
00323 mlview_attributes_list_add_attribute_to_node_interactive (MlViewAttributesList * a_list,
00324                                                           xmlNode * a_node)
00325 {
00326         gint button ;
00327         gchar * name_str, *value_str ;
00328         gboolean loop=TRUE ;
00329         xmlAttr * result=NULL ;
00330 
00331         g_return_val_if_fail (a_list != NULL, NULL) ;
00332         g_return_val_if_fail (MLVIEW_IS_ATTRIBUTES_LIST (a_list), NULL) ;
00333 
00334         if (PRIVATE (a_list)->attribute_picker == NULL) {
00335                 PRIVATE (a_list)->attribute_picker = 
00336                         MLVIEW_ATTRIBUTE_PICKER (mlview_attribute_picker_new (_("Enter attribute name and value"), 
00337                                                      PRIVATE (a_list)->app_context)) ;
00338         }
00339 
00340         mlview_attribute_picker_grab_focus_to_name_entry (PRIVATE (a_list)->attribute_picker) ;
00341         
00342         gtk_window_set_modal (GTK_WINDOW (PRIVATE (a_list)->attribute_picker), TRUE) ;
00343         name_str = mlview_attribute_picker_get_attribute_name (PRIVATE (a_list)->attribute_picker) ;
00344 
00345         if ( !utils_is_white_string(name_str) )
00346                 mlview_attribute_picker_select_attribute_name (PRIVATE (a_list)->attribute_picker) ;
00347 
00348         mlview_attribute_picker_set_current_xml_node (PRIVATE (a_list)->attribute_picker, a_node) ;
00349         mlview_attribute_picker_build_attribute_name_choice_list (PRIVATE (a_list)->attribute_picker,
00350                                                                   a_node) ;
00351 
00352         while (loop) {
00353                 xmlAttributeType attr_type ;
00354 
00355                 gtk_widget_realize (GTK_WIDGET (PRIVATE (a_list)->attribute_picker)) ;
00356                 mlview_app_context_set_window_icon (PRIVATE (a_list)->app_context, GTK_WIDGET (PRIVATE (a_list)->attribute_picker)) ;
00357                 button = gnome_dialog_run (GNOME_DIALOG (PRIVATE (a_list)->attribute_picker)) ;
00358 
00359                 switch (button) {
00360                 case 0:
00361                         name_str = mlview_attribute_picker_get_attribute_name (PRIVATE (a_list)->attribute_picker) ;
00362                         value_str = mlview_attribute_picker_get_attribute_value (PRIVATE (a_list)->attribute_picker) ;
00363                         attr_type = mlview_attribute_picker_get_attribute_type (PRIVATE (a_list)->attribute_picker) ;
00364 
00365                         if ( !utils_is_white_string (value_str) && !utils_is_white_string (name_str) ) {
00366                                 gchar * local_name ;
00367                                 xmlNs * ns ;
00368                                 utils_parse_full_name (a_node, name_str, &ns, &local_name) ;
00369                                 result = xmlNewNsProp (a_node, ns, local_name, value_str) ;
00370 
00371                                 /*FIXME: do this only when validation is on*/
00372                                 if (attr_type == XML_ATTRIBUTE_ID
00373                                     && a_node->doc 
00374                                     && a_node->doc->ids) {
00375                                         xmlID *id ;
00376 
00377                                         result->atype = XML_ATTRIBUTE_ID ;
00378                                         id = xmlMalloc (sizeof (xmlID)) ;
00379                                         g_assert (id != NULL) ;
00380                                         id->value = g_strdup (value_str) ;
00381                                         id->attr = result ;
00382                                         xmlHashAddEntry (result->doc->ids, (const xmlChar*)value_str, id) ;
00383                                 }
00384 
00385                                 if (local_name) {
00386                                         g_free (local_name) ;
00387                                         local_name = NULL ;
00388                                 }
00389                                 loop = FALSE ;
00390                         }                       
00391                         break ;
00392                 case 1:
00393                         loop = FALSE ;
00394                         break ;
00395                 case -1:
00396                         loop = FALSE ;
00397                         break ;
00398                 default :
00399                         break ;
00400                 }
00401         }
00402         gnome_dialog_close(GNOME_DIALOG (PRIVATE (a_list)->attribute_picker)) ;
00403         return result ;
00404 }
00405 
00406 /*signal handlers and callbacks*/
00407 
00408 
00415 static void
00416 mlview_attributes_list_edit_state_changed_default_handler(MlViewAttributesList *a_attributes,
00417                                                           gpointer a_data)
00418 {
00419         g_return_if_fail(a_attributes != NULL);
00420         gtk_entry_set_editable(PRIVATE (a_attributes)->name_edit_entry,
00421                                PRIVATE (a_attributes)->editable) ;
00422         gtk_entry_set_editable(PRIVATE (a_attributes)->value_edit_entry,
00423                                PRIVATE (a_attributes)->editable) ;
00424 }
00425 
00426 
00427 static void
00428 mlview_attributes_list_attribute_changed_default_handler(MlViewAttributesList *a_attributes,
00429                                                         gpointer data){
00430 
00431 }
00432 
00433 
00446 static void
00447 row_selected_cb (GtkCList *a_clist, gint a_row, gint a_column,
00448                  GdkEventButton *a_event, MlViewAttributesList *a_attributes)
00449 {
00450         gchar *prop_name=NULL,*prop_value=NULL;
00451         xmlAttr * xml_attr ;
00452         
00453         g_return_if_fail(a_attributes!=NULL);
00454         g_return_if_fail(PRIVATE (a_attributes)->current_xml_node != NULL) ;
00455         g_return_if_fail(PRIVATE (a_attributes)->name_edit_entry != NULL) ;
00456         g_return_if_fail(PRIVATE (a_attributes)->value_edit_entry != NULL) ;
00457         
00458         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry),PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00459         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry),PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00460 
00461         gtk_entry_set_text(PRIVATE (a_attributes)->name_edit_entry,"") ;
00462         gtk_entry_set_text(PRIVATE (a_attributes)->value_edit_entry,"") ;
00463 
00464         gtk_clist_get_text(a_clist,a_row,ATTRIBUTE_NAME_OFFSET,&prop_name) ;
00465         gtk_clist_get_text(a_clist,a_row,ATTRIBUTE_VALUE_OFFSET,&prop_value) ;
00466 
00467         mlview_attributes_list_get_attribute(a_attributes,a_row,&xml_attr) ;
00468         
00469         gtk_entry_set_text(PRIVATE (a_attributes)->name_edit_entry,prop_name) ;
00470 
00471         gtk_entry_set_text(PRIVATE (a_attributes)->value_edit_entry,prop_value) ;
00472 
00473         gtk_signal_handler_unblock(GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry),PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00474         gtk_signal_handler_unblock(GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry),PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00475         PRIVATE (a_attributes)->current_selected_row = a_row ;  
00476 }
00477 
00489 static void
00490 name_edit_entry_changed_cb(GtkEntry *a_entry, gpointer *a_attributes)
00491 {
00492         MlViewAttributesList *attributes;
00493         xmlAttrPtr xml_attr ;
00494         gchar *name=NULL ;
00495 
00496         g_return_if_fail(a_attributes!=NULL);
00497         attributes=MLVIEW_ATTRIBUTES_LIST(a_attributes) ;
00498 
00499         g_return_if_fail(PRIVATE (attributes)->current_selected_row >= 0) ;
00500         g_return_if_fail(PRIVATE (attributes)->current_xml_node != NULL) ;
00501 
00502         mlview_attributes_list_get_attribute(attributes,PRIVATE (attributes)->current_selected_row,&xml_attr) ;
00503         if(xml_attr != NULL){
00504                 gchar *local_name ;
00505                 xmlNs * ns ;
00506                 name = gtk_entry_get_text(GTK_ENTRY(a_entry)) ;
00507                 utils_parse_full_name(PRIVATE (attributes)->current_xml_node, name, &ns, &local_name) ;
00508                 xmlSetNs((xmlNodePtr)xml_attr, ns) ;
00509                 xmlNodeSetName((xmlNodePtr)xml_attr,local_name);
00510                 if(ns && ns->prefix)
00511                         name = g_strconcat(ns->prefix, ":", local_name, NULL) ;
00512                 else
00513                         name = g_strdup(local_name) ;
00514                 gtk_clist_set_text(GTK_CLIST(PRIVATE (attributes)->attributes_view),
00515                                    PRIVATE (attributes)->current_selected_row,ATTRIBUTE_NAME_OFFSET,
00516                                    name) ;
00517                 if(local_name){
00518                         g_free(local_name) ;
00519                 }
00520                 if(name){
00521                         g_free(name) ;
00522                 }
00523         }
00524         gtk_signal_emit(GTK_OBJECT(attributes), mlview_attributes_list_signals[ATTRIBUTE_CHANGED]);
00525 }
00526 
00536 static void
00537 value_edit_entry_changed_cb(GtkEntry *a_entry, MlViewAttributesList *a_attributes)
00538 {
00539         gchar *value;
00540         xmlAttrPtr xml_attr ;
00541         g_return_if_fail(a_attributes!=NULL);
00542         g_return_if_fail(PRIVATE (a_attributes)->current_selected_row >= 0) ;
00543         
00544         value = gtk_entry_get_text(GTK_ENTRY(a_entry)) ;
00545         mlview_attributes_list_get_attribute(a_attributes, PRIVATE (a_attributes)->current_selected_row, &xml_attr) ;
00546         if(xml_attr != NULL ){
00547                 xmlSetProp(xml_attr->parent, xml_attr->name, g_strdup(value)) ;
00548                 gtk_clist_set_text(GTK_CLIST(PRIVATE (a_attributes)->attributes_view),
00549                                    PRIVATE (a_attributes)->current_selected_row,ATTRIBUTE_VALUE_OFFSET,
00550                                    value) ;
00551         }
00552         gtk_signal_emit(GTK_OBJECT(a_attributes), mlview_attributes_list_signals[ATTRIBUTE_CHANGED]);
00553 }
00554 
00560 static void 
00561 add_attribute_button_clicked_cb (GtkButton *a_add_attribute_button, 
00562                                  MlViewAttributesList *a_attributes_list)
00563 {
00564         g_return_if_fail (a_add_attribute_button != NULL) ;
00565         g_return_if_fail (a_attributes_list != NULL) ;
00566 
00567         mlview_attributes_list_create_attribute (a_attributes_list) ;
00568 }
00569 
00575 static void
00576 remove_attribute_button_clicked_cb(GtkButton *a_remove_attribute_button, 
00577                                    MlViewAttributesList *a_attributes_list)
00578 {
00579         g_return_if_fail(a_remove_attribute_button != NULL) ;   
00580         g_return_if_fail(a_attributes_list != NULL) ;
00581         g_return_if_fail(PRIVATE (a_attributes_list)->current_selected_row > -1) ;
00582         mlview_attributes_list_remove_attribute(a_attributes_list, PRIVATE (a_attributes_list)->current_selected_row) ;
00583 }
00584 
00585 /*===================================================================
00586  *public methods
00587  *==================================================================
00588  */
00589 
00594 guint
00595 mlview_attributes_list_get_type (void)
00596 {
00597         static guint mlview_attributes_list_type = 0 ;
00598         if (!mlview_attributes_list_type) {
00599                 static const GtkTypeInfo t_info = {
00600                         "MlViewAttributesList",
00601                         sizeof (MlViewAttributesList),
00602                         sizeof (MlViewAttributesListClass),
00603                         (GtkClassInitFunc) mlview_attributes_list_class_init,
00604                         (GtkObjectInitFunc) mlview_attributes_list_init,
00605                         NULL, NULL, NULL
00606                 };
00607                 mlview_attributes_list_type = gtk_type_unique (GTK_TYPE_VBOX, &t_info) ;
00608         }
00609         return mlview_attributes_list_type ;
00610 }
00611 
00612 
00620 GtkWidget*
00621 mlview_attributes_list_new (gchar *a_names_title,
00622                             gchar *a_values_title,
00623                             MlViewAppContext *a_app_context)
00624 {
00625         MlViewAttributesList *attributes ;
00626         attributes = gtk_type_new (MLVIEW_TYPE_ATTRIBUTES_LIST) ;
00627 
00628         mlview_attributes_list_set_app_context (attributes, a_app_context) ;
00629 
00630         if ( a_names_title )
00631                 gtk_clist_set_column_title (GTK_CLIST(PRIVATE (attributes)->attributes_view),
00632                                             ATTRIBUTE_NAME_OFFSET,
00633                                             a_names_title) ;
00634         if ( a_values_title )
00635                 gtk_clist_set_column_title (GTK_CLIST(PRIVATE (attributes)->attributes_view),
00636                                             ATTRIBUTE_VALUE_OFFSET,
00637                                             a_values_title) ;
00638         return GTK_WIDGET (attributes) ;
00639 }
00640 
00641 
00648 void
00649 mlview_attributes_list_set_app_context (MlViewAttributesList * a_attributes,
00650                                         MlViewAppContext *a_app_context)
00651 {
00652         g_return_if_fail (a_attributes) ;
00653         g_return_if_fail (MLVIEW_IS_ATTRIBUTES_LIST (a_attributes)) ;
00654         g_return_if_fail (PRIVATE (a_attributes) != NULL) ;
00655 
00656         PRIVATE (a_attributes)->app_context = a_app_context ;
00657 }
00658 
00659 
00667 void
00668 mlview_attributes_list_set_editable (MlViewAttributesList *a_attributes,
00669                                      gboolean a_editable)
00670 {
00671         g_return_if_fail (a_attributes != NULL) ;
00672         g_return_if_fail (MLVIEW_IS_ATTRIBUTES_LIST (a_attributes)) ;
00673         g_return_if_fail (PRIVATE (a_attributes) != NULL) ;
00674 
00675         PRIVATE (a_attributes)->editable = a_editable ;
00676         gtk_signal_emit (GTK_OBJECT (a_attributes),
00677                          mlview_attributes_list_signals[EDIT_STATE_CHANGED]);
00678 }
00679 
00688 void
00689 mlview_attributes_list_set_titles (MlViewAttributesList *a_attributes,
00690                                    gchar *a_names_title,
00691                                    gchar *a_values_title)
00692 {
00693   
00694         g_return_if_fail (a_attributes != NULL);
00695         g_return_if_fail (a_names_title!=NULL) ;
00696         g_return_if_fail (a_values_title!=NULL);
00697 
00698         if ( strcmp(a_names_title, "") ) {
00699                 if ( PRIVATE (a_attributes)->names_title )
00700                         g_free (PRIVATE (a_attributes)->names_title) ;
00701                 PRIVATE (a_attributes)->names_title = 
00702                         g_strdup(a_names_title) ;
00703         }
00704         if ( strcmp(a_values_title, "") ) {
00705                 if ( PRIVATE (a_attributes)->values_title )
00706                         g_free (PRIVATE (a_attributes)->values_title);
00707                 PRIVATE (a_attributes)->values_title = 
00708                         g_strdup(a_values_title);
00709         }  
00710 }
00711 
00720 void
00721 mlview_attributes_list_set_attribute(MlViewAttributesList *a_attributes, guint a_offset,
00722                                      const xmlAttrPtr a_xml_attr)
00723 {
00724         g_return_if_fail(a_attributes != NULL) ;
00725         g_return_if_fail(PRIVATE (a_attributes)->attributes_view != NULL) ;
00726         g_return_if_fail(a_xml_attr != NULL) ;
00727         g_return_if_fail(PRIVATE (a_attributes)->name_edit_entry != NULL ) ;
00728         g_return_if_fail(PRIVATE (a_attributes)->value_edit_entry !=NULL ) ;
00729         
00730         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry), PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00731         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry), PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00732 
00733         gtk_clist_set_text(PRIVATE (a_attributes)->attributes_view,
00734                            a_offset,ATTRIBUTE_NAME_OFFSET,
00735                            a_xml_attr->name) ;
00736         gtk_clist_set_text(PRIVATE (a_attributes)->attributes_view,
00737                            a_offset,ATTRIBUTE_VALUE_OFFSET,
00738                            xmlNodeListGetString(a_xml_attr->doc,a_xml_attr->children,1)) ;
00739         gtk_clist_set_row_data(PRIVATE (a_attributes)->attributes_view,
00740                                a_offset,
00741                                a_xml_attr) ;
00742         gtk_entry_set_text(PRIVATE (a_attributes)->name_edit_entry,"") ;
00743         gtk_entry_set_text(PRIVATE (a_attributes)->value_edit_entry,"") ;
00744 
00745         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry), PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00746         gtk_signal_handler_block(GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry), PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00747 }
00748 
00755 void
00756 mlview_attributes_list_edit_xml_attributes(MlViewAttributesList *a_attributes_list,
00757                                            const xmlNodePtr a_xml_node)
00758 {
00759         xmlAttrPtr xml_attr ;
00760 
00761         g_return_if_fail(a_attributes_list != NULL) ;
00762         g_return_if_fail (MLVIEW_IS_ATTRIBUTES_LIST (a_attributes_list)) ;
00763         g_return_if_fail (PRIVATE (a_attributes_list) != NULL) ;
00764         g_return_if_fail(a_xml_node) ;
00765         
00766         /*
00767          *even if there are no attributes, do not forget to store the pointer to the xml_node so that
00768          *it will be possible to add new attributes to that xml_node.
00769          */
00770         PRIVATE (a_attributes_list)->current_xml_node = a_xml_node;
00771         if( a_xml_node->properties == NULL)
00772                 return ;
00773         for(xml_attr=a_xml_node->properties; xml_attr != NULL ;xml_attr=xml_attr->next){
00774                 if(xml_attr->name){
00775                         mlview_attributes_list_add_attribute_to_view(a_attributes_list,xml_attr) ;
00776                 }
00777         }
00778         gtk_widget_show_all(GTK_WIDGET(a_attributes_list)) ;
00779 }
00780 
00788 gint
00789 mlview_attributes_list_add_attribute_to_view(MlViewAttributesList *a_attributes,
00790                                              const xmlAttrPtr a_xml_attr)
00791 {
00792         gchar *attributes[2], *name, *value ;
00793         gint row_offset ;
00794 
00795         g_return_val_if_fail(a_attributes!=NULL, -1) ;
00796         g_return_val_if_fail(PRIVATE (a_attributes)->attributes_view!=NULL, -1);
00797         g_return_val_if_fail(a_xml_attr != NULL, -1) ;
00798   
00799         if(a_xml_attr->ns != NULL  &&  a_xml_attr->ns->prefix)
00800                 name = g_strconcat(a_xml_attr->ns->prefix, ":", a_xml_attr->name, NULL) ;
00801         else
00802                 name = g_strdup(a_xml_attr->name); 
00803         
00804         value = g_strdup(xmlNodeListGetString(a_xml_attr->doc, a_xml_attr->children,1));
00805 
00806         attributes[ATTRIBUTE_NAME_OFFSET]= name ;
00807         attributes[ATTRIBUTE_VALUE_OFFSET]= value ;
00808 
00809         row_offset = gtk_clist_append(PRIVATE (a_attributes)->attributes_view,
00810                                       attributes) ;
00811         gtk_clist_set_row_data(PRIVATE (a_attributes)->attributes_view,
00812                                row_offset,
00813                                a_xml_attr) ;
00814         if(name)
00815                 g_free(name) ;
00816         if(value)
00817                 g_free(value) ;
00818         return row_offset ;
00819 }
00820 
00821 
00829 void
00830 mlview_attributes_list_get_attribute(MlViewAttributesList *a_attributes,
00831                                      const guint a_offset,
00832                                      xmlAttrPtr *a_xml_attr_ptr)
00833 {
00834         g_return_if_fail(a_attributes!=NULL) ;
00835         *a_xml_attr_ptr = gtk_clist_get_row_data(PRIVATE (a_attributes)->attributes_view,a_offset) ;
00836 }
00837 
00838 
00844 void
00845 mlview_attributes_list_clear (MlViewAttributesList *a_attributes)
00846 {
00847         g_return_if_fail (a_attributes!=NULL) ;
00848         g_return_if_fail (PRIVATE (a_attributes)->attributes_view) ;
00849         g_return_if_fail (PRIVATE (a_attributes)->name_edit_entry) ;
00850         g_return_if_fail (PRIVATE (a_attributes)->value_edit_entry) ;
00851         
00852         gtk_signal_handler_block (GTK_OBJECT (PRIVATE (a_attributes)->name_edit_entry), 
00853                                   PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00854         gtk_signal_handler_block (GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry), 
00855                                   PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00856         
00857         gtk_clist_clear (PRIVATE (a_attributes)->attributes_view) ;
00858         gtk_entry_set_text (PRIVATE (a_attributes)->name_edit_entry,"") ;
00859         gtk_entry_set_text (PRIVATE (a_attributes)->value_edit_entry,"") ;
00860 
00861         PRIVATE (a_attributes)->current_xml_node = NULL ;
00862         PRIVATE (a_attributes)->current_selected_row = -1 ;
00863 
00864         gtk_signal_handler_unblock (GTK_OBJECT (PRIVATE (a_attributes)->name_edit_entry), 
00865                                     PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00866         gtk_signal_handler_unblock (GTK_OBJECT (PRIVATE (a_attributes)->value_edit_entry), 
00867                                     PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00868 }
00869 
00878 gint
00879 mlview_attributes_list_create_attribute (MlViewAttributesList *a_attributes)
00880 {
00881         xmlAttrPtr xml_attr ;
00882         gint result ;
00883         g_return_val_if_fail (a_attributes != NULL, MLVIEW_ATTRIBUTES_LIST_NULL_PARAMETER);
00884         g_return_val_if_fail (PRIVATE (a_attributes)->current_xml_node != NULL, MLVIEW_ATTRIBUTES_LIST_NULL_XML_NODE) ;
00885         
00886         if (PRIVATE (a_attributes)->editable == FALSE)
00887                 return MLVIEW_ATTRIBUTES_LIST_READ_ONLY ;
00888         
00889         xml_attr = 
00890                 mlview_attributes_list_add_attribute_to_node_interactive (a_attributes,
00891                                                                           PRIVATE (a_attributes)->current_xml_node) ;
00892         if (xml_attr == NULL)
00893                 return -1 ;
00894 
00895         result = 
00896                 mlview_attributes_list_add_attribute_to_view (a_attributes,
00897                                                               xml_attr) ;
00898         gtk_signal_emit (GTK_OBJECT (a_attributes),
00899                          mlview_attributes_list_signals[ATTRIBUTE_CHANGED]) ;
00900         return result ;
00901 }
00902 
00903 
00913 void
00914 mlview_attributes_list_remove_attribute (MlViewAttributesList *a_attributes,
00915                                          const guint a_attr_offset)
00916 {
00917         xmlAttrPtr xml_attr ;
00918         gint result ;
00919         g_return_if_fail (a_attributes != NULL) ;
00920         g_return_if_fail (PRIVATE (a_attributes)->current_xml_node != NULL) ;
00921         g_return_if_fail (PRIVATE (a_attributes)->attributes_view) ;
00922         
00923         xml_attr = (xmlAttrPtr) gtk_clist_get_row_data (PRIVATE (a_attributes)->attributes_view, 
00924                                                         a_attr_offset) ;
00925         g_return_if_fail (xml_attr != NULL) ;
00926         result = xmlRemoveProp (xml_attr) ;
00927         g_return_if_fail (result == 0) ;
00928         gtk_clist_remove (PRIVATE (a_attributes)->attributes_view,
00929                           PRIVATE (a_attributes)->current_selected_row) ;
00930 
00931         gtk_signal_handler_block (GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry), 
00932                                   PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00933         gtk_signal_handler_block (GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry), 
00934                                   PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00935 
00936         gtk_entry_set_text (PRIVATE (a_attributes)->name_edit_entry, "") ;
00937         gtk_entry_set_text (PRIVATE (a_attributes)->value_edit_entry, "") ;
00938 
00939         gtk_signal_handler_unblock (GTK_OBJECT(PRIVATE (a_attributes)->name_edit_entry), 
00940                                     PRIVATE (a_attributes)->name_edit_entry_changed_handler_id) ;
00941         gtk_signal_handler_unblock (GTK_OBJECT(PRIVATE (a_attributes)->value_edit_entry), 
00942                                     PRIVATE (a_attributes)->value_edit_entry_changed_handler_id) ;
00943 
00944         gtk_signal_emit (GTK_OBJECT (a_attributes),
00945                          mlview_attributes_list_signals[ATTRIBUTE_CHANGED]) ;   
00946 }
00947 
00948 
00954 GtkCList *
00955 mlview_attributes_list_get_internal_clist (MlViewAttributesList *a_attributes)
00956 {
00957         g_return_val_if_fail(a_attributes != NULL, NULL) ;
00958         g_return_val_if_fail(MLVIEW_IS_ATTRIBUTES_LIST(a_attributes), NULL) ;
00959         
00960         return PRIVATE (a_attributes)->attributes_view ;
00961 }

Generated on Sat Jul 6 09:57:32 2002 for Gnome-MlView by doxygen1.2.16