00001 #include "vapiGtkInterface.h"
00002 #include "vapiGtkAux.h"
00003 #include "vapiIO.h"
00004 #include "vapiIOXML.h"
00005 #include "vapiIOList.h"
00006 #include "vapiGtkOptions.h"
00007 #include "vapiGtkWindowIOAdd.h"
00008 #include "vapiGtkWindowIOConfigure.h"
00009 #include "vapiGtkTable.h"
00010
00011 static struct _vGtkIOAddWindow
00012 {
00013 GtkWidget *tvIOAddGlobalIOList;
00014 GtkWidget *vboxIOAddPropertiesMainContainer;
00015 GtkWidget *OptionsContainer;
00016 GtkWidget *txtIOAddDescription;
00017 GtkWidget *winIOAdd;
00018 GtkWidget *IOAddGroupButtonBox;
00019 GList *Auxiliar;
00020 GList *OptionsData;
00021 GList *OptionsEvents;
00022 GList *GroupButtonList;
00023 } GtkIOAddWindow;
00024
00025 GList **Lists[3];
00026
00027 int SelectedIO;
00028
00029 void
00030 vapiGtkWindowIOAddInit (GladeXML * xml)
00031 {
00032 GtkWidget *btIOAddWinAdd;
00033 GtkCellRenderer *renderer;
00034 GtkIOAddWindow.GroupButtonList = NULL;
00035 SelectedIO = -1;
00036 GtkIOAddWindow.Auxiliar = NULL;
00037 GtkIOAddWindow.OptionsData = NULL;
00038 GtkIOAddWindow.OptionsEvents = NULL;
00039 GtkIOAddWindow.OptionsContainer = 0;
00040
00041 Lists[0] = &GtkIOAddWindow.Auxiliar;
00042 Lists[1] = &GtkIOAddWindow.OptionsData;
00043 Lists[2] = &GtkIOAddWindow.OptionsEvents;
00044
00045 GtkIOAddWindow.tvIOAddGlobalIOList =
00046 glade_xml_get_widget (xml, "tvIOAddGlobalIOList");
00047 GtkIOAddWindow.vboxIOAddPropertiesMainContainer =
00048 glade_xml_get_widget (xml,
00049 "vboxIOAddPropertiesMainContainer");
00050 GtkIOAddWindow.txtIOAddDescription = glade_xml_get_widget (xml,
00051 "txtIOAddDescription");
00052
00053 GtkIOAddWindow.winIOAdd = glade_xml_get_widget (xml, "winIOAdd");
00054 GtkIOAddWindow.IOAddGroupButtonBox =
00055 glade_xml_get_widget (xml, "IOAddGroupButtonBox");
00056 btIOAddWinAdd = glade_xml_get_widget (xml, "btIOAddWinAdd");
00057
00058
00059
00060
00061 renderer = gtk_cell_renderer_text_new ();
00062 gtk_tree_selection_set_mode (gtk_tree_view_get_selection
00063 (GTK_TREE_VIEW
00064 (GtkIOAddWindow.tvIOAddGlobalIOList)),
00065 GTK_SELECTION_SINGLE);
00066 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
00067 (GtkIOAddWindow.
00068 tvIOAddGlobalIOList),
00069 -1, "Nome", renderer,
00070 "text", 0, NULL);
00071
00072 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
00073 (GtkIOAddWindow.
00074 tvIOAddGlobalIOList),
00075 -1, "Tipo",
00076 renderer, "text", 1,
00077 NULL);
00078
00079
00080
00081
00082 vapiGtkGroupButtons (GlobalIOGroups,
00083 &GtkIOAddWindow.GroupButtonList,
00084 GtkIOAddWindow.IOAddGroupButtonBox,
00085 G_CALLBACK (vapiGtkWindowIOAddSelectGroup),
00086 NULL);
00087 vapiGtkWindowIOAddInitIOList ();
00088
00089
00090
00091
00092
00093
00094 g_signal_connect (G_OBJECT (GtkIOAddWindow.tvIOAddGlobalIOList),
00095 "row_activated",
00096 G_CALLBACK (vapiGtkWindowIOAddSelectIO), NULL);
00097
00098 g_signal_connect (G_OBJECT (btIOAddWinAdd), "clicked",
00099 G_CALLBACK (vapiGtkWindowIOAdd_Add), NULL);
00100 }
00101
00102 void
00103 vapiGtkWindowIOAddInitIOList ()
00104 {
00105 int i, ListSize;
00106 vIO *IO;
00107 GtkTreeStore *treeStore;
00108 GtkTreeIter iter;
00109
00110 treeStore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
00111 ListSize = v_list_count_elements (GlobalIOList);
00112 if (ListSize > 0)
00113 {
00114 for (i = 0; i < ListSize; i++)
00115 {
00116 IO = (vIO *) v_list_get (GlobalIOList, i);
00117 gtk_tree_store_append (treeStore, &iter, NULL);
00118 gtk_tree_store_set (treeStore, &iter, 0,
00119 IO->IOname, 1,
00120 vapiIOTypeToString (IO->IOtype),
00121 -1);
00122 }
00123 }
00124 gtk_tree_view_set_model ((GtkTreeView *) GtkIOAddWindow.
00125 tvIOAddGlobalIOList,
00126 GTK_TREE_MODEL (treeStore));
00127 g_object_unref (treeStore);
00128 }
00129
00130 void
00131 vapiGtkWindowIOAddSelectIO (GtkWidget * widget, GtkTreePath * path,
00132 GtkTreeIter * iter, gpointer Data)
00133 {
00134 vIO *IO;
00135 vOptions *fakeOptions;
00136 GValue value = {
00137 0,
00138 };
00139 char *IOName;
00140
00141 vapiGtkTableGetValueFromSelection (widget, &value, 0);
00142
00143 IOName = (char *) g_value_get_string (&value);
00144 SelectedIO = vapiIOListSelectN (GlobalIOList, IOName);
00145
00146
00147 vapiGtkWindowIOAddShowDescription ();
00148
00149 if (SelectedIO < 0)
00150 {
00151 vapiGtkOptionsFree (&GtkIOAddWindow.OptionsContainer, Lists);
00152 return;
00153 }
00154
00155 IO = v_list_get (GlobalIOList, SelectedIO);
00156
00157 fakeOptions = vapiOptionsInit (IO->OptionsSettings);
00158 vapiGtkOptionsCreate
00159 (GtkIOAddWindow.vboxIOAddPropertiesMainContainer,
00160 &GtkIOAddWindow.OptionsContainer,
00161 Lists, fakeOptions, IO->OptionsSettings, NULL, NULL, NULL);
00162 gtk_box_reorder_child ((GtkBox *) GtkIOAddWindow.
00163 vboxIOAddPropertiesMainContainer,
00164 GtkIOAddWindow.OptionsContainer, 1);
00165 vOptionsFree (fakeOptions, IO->OptionsSettings, NULL);
00166
00167
00168 }
00169
00170 void vapiGtkWindowIOAdd_Add (GtkWidget * widget, gpointer data)
00171 {
00172 vOptions *Options;
00173 vIO *IO;
00174
00175 if (SelectedIO < 0)
00176 {
00177 return;
00178 }
00179 IO = v_list_get (GlobalIOList, SelectedIO);
00180
00181 Options = vapiOptionsInit (IO->OptionsSettings);
00182
00183 vapiGtkOptionsGetOptions (Options, IO->OptionsSettings, NULL,
00184 &GtkIOAddWindow.OptionsData);
00185 if (vapiOptionsCheck (IO->OptionsSettings, Options))
00186 {
00187 vOptionsFree (Options, IO->OptionsSettings, NULL);
00188 v_error ("Opções incorrectas, preencher as caixas de texto");
00189 return;
00190 }
00191
00192 vapiIOListConfiguredAdd (IO, Options);
00193
00194 vapiGtkWindowIOConfiguredList ();
00195
00196 gtk_widget_hide (GtkIOAddWindow.winIOAdd);
00197
00198 vapiIOConfiguredToXML ();
00199
00200 }
00201
00202 void vapiGtkWindowIOAddShowDescription ()
00203 {
00204 GtkTextBuffer *MessagesBuffer;
00205 vIO *IO;
00206
00207 MessagesBuffer =
00208 gtk_text_view_get_buffer ((GtkTextView *) GtkIOAddWindow.
00209 txtIOAddDescription);
00210
00211 if (SelectedIO < 0)
00212 {
00213 gtk_text_buffer_set_text (MessagesBuffer, "", -1);
00214 }
00215 IO = v_list_get (GlobalIOList, SelectedIO);
00216 gtk_text_buffer_set_text (MessagesBuffer, IO->IOdescription, -1);
00217
00218 }
00219
00220 void vapiGtkWindowIOAddSelectGroup (GtkWidget * button, gpointer data)
00221 {
00222
00223
00224 int group;
00225
00226 group = vapiGtkSelectGroupButton (button,
00227 GlobalIOGroups,
00228 &GtkIOAddWindow.GroupButtonList);
00229
00230 vapiGtkWindowIOAddPopulateGroup (group);
00231
00232 }
00233
00234 void vapiGtkWindowIOAddPopulateGroup (int group)
00235 {
00236 int i, NumberOfIO;
00237 GtkTreeStore *treeStore;
00238 GtkTreeIter iter;
00239 GtkTextBuffer *MessagesBuffer;
00240 vIO *IO;
00241 char *GroupName;
00242 if (group == -1)
00243 {
00244 return;
00245 }
00246 GroupName = vapiGroupListSelectItem (GlobalIOGroups, group);
00247
00248 treeStore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
00249 NumberOfIO = v_list_count_elements (GlobalIOList);
00250 if (NumberOfIO == 0)
00251 {
00252 return;
00253 }
00254
00255 for (i = 0; i < NumberOfIO; i++)
00256 {
00257 IO = v_list_get (GlobalIOList, i);
00258
00259 if (!strcmp (IO->Group, GroupName)
00260 || !strcmp ("Todos", GroupName))
00261 {
00262 gtk_tree_store_append (treeStore, &iter, NULL);
00263 gtk_tree_store_set (treeStore, &iter, 0,
00264 IO->IOname, 1,
00265 vapiIOTypeToString (IO->IOtype),
00266 -1);
00267 }
00268 }
00269
00270 gtk_tree_view_set_model ((GtkTreeView *) GtkIOAddWindow.
00271 tvIOAddGlobalIOList,
00272 GTK_TREE_MODEL (treeStore));
00273 gtk_tree_view_columns_autosize ((GtkTreeView *) GtkIOAddWindow.
00274 tvIOAddGlobalIOList);
00275 g_object_unref (treeStore);
00276
00277
00278
00279
00280 MessagesBuffer =
00281 gtk_text_view_get_buffer ((GtkTextView *) GtkIOAddWindow.
00282 txtIOAddDescription);
00283
00284 gtk_text_buffer_set_text (MessagesBuffer, " ", -1);
00285 }