src/interface/vapiGtkWindowIOConfigure.c

Ir para a documentação deste ficheiro.
00001 #include "vapiGtkInterface.h"
00002 #include "vapiIO.h"
00003 #include "vapiIOXML.h"
00004 #include "vapiIOList.h"
00005 #include "vapiGtkOptions.h"
00006 #include "vapiGtkWindowIOConfigure.h"
00007 #include "vapiGtkTable.h"
00008 
00009 #define NumberOfIOTypes 3
00010 #define NumberOfIOTypesPlusPlus NumberOfIOTypes + 1
00011 
00012 GtkWidget *tvIOConfiguredList[NumberOfIOTypesPlusPlus];
00013 GtkWidget *vboxIOConfiguredOptionsContainer;
00014 GtkWidget *OptionsIOConfiguredContainer;
00015 GList *IOConfAuxiliar;
00016 GList *IOConfOptionsData;
00017 GList *IOConfOptionsEvents;
00018 
00019 GList **ListsConfigured[3];
00020 
00021 int SelectedIOConfigured;
00022 
00023 void
00024 vapiGtkWindowIOConfigureInit (GladeXML * xml)
00025 {
00026         GtkWidget *btIOConfiguredWinEdit;
00027         GtkWidget *btIOConfiguredRemove;
00028         GtkWidget *btIOConfiguredWinSaveChanges;
00029 
00030         tvIOConfiguredList[0] =
00031                 glade_xml_get_widget (xml, "tvIOConfiguredInput");
00032         tvIOConfiguredList[1] =
00033                 glade_xml_get_widget (xml, "tvIOConfiguredOutput");
00034         tvIOConfiguredList[2] =
00035                 glade_xml_get_widget (xml, "tvIOConfiguredInput_Output");
00036         tvIOConfiguredList[3] =
00037                 glade_xml_get_widget (xml, "tvIOConfiguredALL");
00038 
00039         vboxIOConfiguredOptionsContainer =
00040                 glade_xml_get_widget (xml,
00041                                       "vboxIOConfiguredOptionsContainer");
00042         btIOConfiguredWinEdit = glade_xml_get_widget (xml,
00043                                                       "btIOConfiguredWinEdit");
00044 
00045         btIOConfiguredRemove = glade_xml_get_widget (xml,
00046                                                      "btIOConfiguredRemove");
00047 
00048         btIOConfiguredWinSaveChanges = glade_xml_get_widget (xml,
00049                                                              "btIOConfiguredWinSaveChanges");
00050         OptionsIOConfiguredContainer = 0;
00051         IOConfAuxiliar = NULL;
00052         IOConfOptionsData = NULL;
00053         IOConfOptionsEvents = NULL;
00054         ListsConfigured[0] = &IOConfAuxiliar;
00055         ListsConfigured[1] = &IOConfOptionsData;
00056         ListsConfigured[2] = &IOConfOptionsEvents;
00057 
00058         SelectedIOConfigured = -1;
00059 
00060         /*
00061          * Configurar a Tabela.
00062          */
00063         vapiGtkWindowIOConfiguredTablesInit ();
00064 
00065         vapiGtkWindowIOConfiguredList ();
00066 
00067         /*
00068          * FIXME: Necessita de uma função para detectar o IO seleccionado
00069          
00070          *g_signal_connect (G_OBJECT (btIOConfiguredWinEdit), "clicked",
00071          *                G_CALLBACK (vapiGtkWindowIOConfiguredSelect), NULL);
00072          */
00073         g_signal_connect (G_OBJECT (btIOConfiguredRemove), "clicked",
00074                           G_CALLBACK (vapiGtkWindowIOConfiguredRemove), NULL);
00075 
00076         g_signal_connect (G_OBJECT (btIOConfiguredWinSaveChanges), "clicked",
00077                           G_CALLBACK (vapiGtkWindowIOConfiguredSaveChanges),
00078                           NULL);
00079 }
00080 
00081 void
00082 vapiGtkWindowIOConfiguredList ()
00083 {
00084 
00085         int i, ConfiguredListSize, type;
00086         vIOConfigured *IOConfigured;
00087         GtkTreeIter iter;
00088         GtkTreeStore *treeStore[NumberOfIOTypesPlusPlus];
00089 
00090         /*
00091          * Iniciar variaveis e treeStores.
00092          */
00093         SelectedIOConfigured = -1;
00094 
00095         for (i = 0; i <= NumberOfIOTypes; i++)
00096         {
00097                 treeStore[i] =
00098                         gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,
00099                                             G_TYPE_STRING);
00100         }
00101 
00102         ConfiguredListSize = v_list_count_elements (GlobalIOListConfigured);
00103 
00104         if (ConfiguredListSize > 0)
00105         {
00106 
00107                 for (i = 0; i < ConfiguredListSize; i++)
00108                 {
00109                         IOConfigured =
00110                                 (vIOConfigured *)
00111                                 v_list_get (GlobalIOListConfigured, i);
00112                         /*
00113                          * Adicionar Nova linha na tabela.
00114                          */
00115                         v_debug ("aqui %d", IOConfigured->IO->IOtype);
00116                         switch (IOConfigured->IO->IOtype)
00117                         {
00118                         case vInput:
00119                         case vInputN:
00120                         {
00121                                 type = 0;
00122                                 break;
00123                         }
00124 
00125                         case vOutput:
00126                         case vOutputN:
00127                         {
00128                                 type = 1;
00129                                 break;
00130                         }
00131                         case vIOBoth:
00132                         case vIOBothN:
00133                         {
00134                                 type = 2;
00135                                 break;
00136                         }
00137                         default:
00138                         {
00139                                 type = NumberOfIOTypes;
00140                                 v_error ("Tipo de IO não definido");
00141                                 break;
00142                         }
00143                         }
00144                         v_debug ("ali %d", type);
00145                         if (type >= 0 && type < NumberOfIOTypes)
00146                         {
00147                                 v_debug ("Type of IO %d", type);
00148                                 gtk_tree_store_append (treeStore[type], &iter,
00149                                                        NULL);
00150                                 gtk_tree_store_set (treeStore[type], &iter, 0,
00151                                                     i, 1,
00152                                                     vapiIOTypeToString
00153                                                     (IOConfigured->IO->
00154                                                      IOtype), 2,
00155                                                     IOConfigured->IO->IOname,
00156                                                     -1);
00157 
00158                                 gtk_tree_store_append (treeStore
00159                                                        [NumberOfIOTypes],
00160                                                        &iter, NULL);
00161                                 gtk_tree_store_set (treeStore
00162                                                     [NumberOfIOTypes], &iter,
00163                                                     0, i, 1,
00164                                                     vapiIOTypeToString
00165                                                     (IOConfigured->IO->
00166                                                      IOtype), 2,
00167                                                     IOConfigured->IO->IOname,
00168                                                     -1);
00169                         }
00170                 }
00171         }
00172         for (i = 0; i <= NumberOfIOTypes; i++)
00173         {
00174                 gtk_tree_view_set_model (GTK_TREE_VIEW
00175                                          (tvIOConfiguredList[i]),
00176                                          GTK_TREE_MODEL (treeStore[i]));
00177         }
00178 
00179 }
00180 
00181 void
00182 vapiGtkWindowIOConfiguredSelect (GtkWidget * widget, GtkTreePath * path,
00183                                  GtkTreeIter * iter, gpointer data)
00184 {
00185         vIOConfigured *IOConfigured;
00186         GtkWidget *Table;
00187         GValue gvalue = { 0, };
00188         if (path == NULL)
00189         {
00190                 return;
00191         }
00192         Table = vapiGtkWindowIOConfiguredGetActiveTable ();
00193 
00194         if (Table == NULL)
00195         {
00196                 return;
00197         }
00198 
00199         vapiGtkTableGetValueFromSelection (Table, &gvalue, 0);
00200         SelectedIOConfigured = (int) g_value_get_int (&gvalue);
00201         IOConfigured = v_list_get (GlobalIOListConfigured, SelectedIOConfigured);
00202 
00203         vapiGtkOptionsCreate
00204                 (vboxIOConfiguredOptionsContainer,
00205                  &OptionsIOConfiguredContainer,
00206                  ListsConfigured, IOConfigured->Options,
00207                  IOConfigured->IO->OptionsSettings, NULL, NULL, NULL);
00208 
00209         gtk_box_reorder_child ((GtkBox *) vboxIOConfiguredOptionsContainer,
00210                                OptionsIOConfiguredContainer, 1);
00211 }
00212 
00213 void
00214 vapiGtkWindowIOConfiguredTablesInit ()
00215 {
00216         GtkCellRenderer *renderer;
00217         int i;
00218 
00219         for (i = 0; i <= NumberOfIOTypes; i++)
00220         {
00221 
00222                 renderer = gtk_cell_renderer_text_new ();
00223                 gtk_tree_selection_set_mode (gtk_tree_view_get_selection
00224                                              (GTK_TREE_VIEW
00225                                               (tvIOConfiguredList[i])),
00226                                              GTK_SELECTION_SINGLE);
00227 
00228                 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
00229                                                              (tvIOConfiguredList
00230                                                               [i]), -1, "id",
00231                                                              renderer, "text",
00232                                                              0, NULL);
00233 
00234                 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
00235                                                              (tvIOConfiguredList
00236                                                               [i]), -1,
00237                                                              "Tipo", renderer,
00238                                                              "text", 1, NULL);
00239                 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
00240                                                              (tvIOConfiguredList
00241                                                               [i]), -1,
00242                                                              "Nome", renderer,
00243                                                              "text", 2, NULL);
00244 
00245                 g_signal_connect (G_OBJECT (tvIOConfiguredList[i]),
00246                                   "row_activated",
00247                                   G_CALLBACK
00248                                   (vapiGtkWindowIOConfiguredSelect), NULL);
00249 
00250         }
00251 
00252 
00253         g_signal_connect (G_OBJECT (tvIOConfiguredList[NumberOfIOTypes]),
00254                           "row_activated",
00255                           G_CALLBACK (vapiGtkWindowIOConfiguredSelect), NULL);
00256 }
00257 
00258 GtkWidget *
00259 vapiGtkWindowIOConfiguredGetActiveTable ()
00260 {
00261         int selectedRow, i;
00262         for (i = 0; i <= NumberOfIOTypes; i++)
00263         {
00264                 selectedRow =
00265                         vapiGtkTableGetSelectedRow (tvIOConfiguredList[i]);
00266 
00267                 if (selectedRow >= 0)
00268                 {
00269                         v_debug ("é a tabela numero %d", i);
00270                         return tvIOConfiguredList[i];
00271                 }
00272         }
00273         return NULL;
00274 }
00275 
00276 void
00277 vapiGtkWindowIOConfiguredRemove (GtkWidget * widget, gpointer user_data)
00278 {
00279         GtkWidget *Table;
00280         GValue gvalue = {
00281                 0,
00282         };
00283 
00284         int IOConfiguredIndex;
00285 
00286         Table = vapiGtkWindowIOConfiguredGetActiveTable ();
00287         if (Table == NULL)
00288         {
00289                 return;
00290         }
00291         vapiGtkTableGetValueFromSelection (Table, &gvalue, 0);
00292         IOConfiguredIndex = (int) g_value_get_int (&gvalue);
00293 
00294         vapiIOConfiguredDelete (IOConfiguredIndex);
00295 
00296         vapiGtkWindowIOConfiguredList ();
00297         vapiIOConfiguredToXML ();
00298 }
00299 
00300 void
00301 vapiGtkWindowIOConfiguredSaveChanges (GtkWidget * widget, gpointer user_data)
00302 {
00303         vOptions *Options;
00304         GtkWidget *Table;
00305         GValue gvalue = { 0, };
00306         int IOConfiguredIndex;
00307         vIOConfigured *IOConfigured;
00308         Table = vapiGtkWindowIOConfiguredGetActiveTable ();
00309 
00310         if (Table == NULL)
00311         {
00312                 return;
00313         }
00314         vapiGtkTableGetValueFromSelection (Table, &gvalue, 0);
00315         IOConfiguredIndex = (int) g_value_get_int (&gvalue);
00316         IOConfigured = v_list_get (GlobalIOListConfigured, IOConfiguredIndex);
00317 
00318         Options = vapiOptionsInit (IOConfigured->IO->OptionsSettings);
00319         vapiGtkOptionsGetOptions (Options, IOConfigured->IO->OptionsSettings,
00320                                   NULL, &IOConfOptionsData);
00321         vOptionsFree (IOConfigured->Options,
00322                       IOConfigured->IO->OptionsSettings, NULL);
00323         IOConfigured->Options=Options;
00324         
00325         vapiIOConfiguredToXML ();
00326 }

Gerado em Tue Jul 24 10:34:58 2007 para Vapi por  doxygen 1.5.1