00001 #include "vapiGtkInterface.h"
00002 #include "vapiAux.h"
00003 #include "vapiString.h"
00004 #include "vapiImagesAux.h"
00005 #include "vapiGtkImages.h"
00006 #include "vapiGtkSetOriginWindow.h"
00007 #include "vapiCameraSettings.h"
00008 #include "vapiCameraAcquisition.h"
00009
00010 GtkWidget *btTestOrigin;
00011
00012 void
00013 vapiGtkSetOriginWindowInit (GladeXML * xml, vCameraSettings * CameraSettings,
00014 vImages * Images)
00015 {
00016 vapiGtkSetOriginWindow *SetOrigin =
00017 malloc (sizeof (vapiGtkSetOriginWindow));
00018 GtkWidget *btSaveOrigin;
00019 GtkWidget *btNewVapi;
00020 GtkWidget *winSetImageOrigin;
00021 GtkWidget *btSelectImage;
00022
00023 SetOrigin->Images = Images;
00024 SetOrigin->CameraSettings = CameraSettings;
00025 SetOrigin->nbCameraType = glade_xml_get_widget (xml, "nbCamType");
00026 SetOrigin->CamLocalFilePATH =
00027 glade_xml_get_widget (xml, "CamLocalFilePATH");
00028 btTestOrigin = glade_xml_get_widget (xml, "btTestOrigin");
00029 btSaveOrigin = glade_xml_get_widget (xml, "btSaveOrigin");
00030 SetOrigin->imOriginTest = glade_xml_get_widget (xml, "imOriginTest");
00031 SetOrigin->CamIndex = glade_xml_get_widget (xml, "CamIndex");
00032 SetOrigin->CamIP = glade_xml_get_widget (xml, "CamIP");
00033 SetOrigin->CamURL = glade_xml_get_widget (xml, "CamURL");
00034 btNewVapi = glade_xml_get_widget (xml, "btNewVapi");
00035 winSetImageOrigin = glade_xml_get_widget (xml, "winSetImageOrigin");
00036 SetOrigin->RefreshButton = glade_xml_get_widget (xml, "btRefresh");
00037 btSelectImage = glade_xml_get_widget (xml, "btSelectImage");
00038
00039
00040
00041 g_signal_connect_after (G_OBJECT (btTestOrigin), "clicked",
00042 G_CALLBACK (vapiGtkSetOriginWindowTestOrigin),
00043 SetOrigin);
00044
00045 g_signal_connect_after (G_OBJECT (btSaveOrigin), "clicked",
00046 G_CALLBACK (vapiGtkSetOriginWindowSaveOrigin),
00047 SetOrigin);
00048 g_signal_connect_after (G_OBJECT (btNewVapi), "clicked",
00049 G_CALLBACK (vapiGtkSetOriginWindowNewVapi),
00050 SetOrigin);
00051 g_signal_connect_after (G_OBJECT (btSelectImage), "clicked",
00052 G_CALLBACK
00053 (vapiGtkSetOriginWindowLaunchImageLoad),
00054 SetOrigin);
00055
00056 if (vapiCameraSettingsGetType (SetOrigin->CameraSettings) ==
00057 vCameraNONE)
00058 {
00059 gtk_widget_show_all (winSetImageOrigin);
00060 gtk_widget_grab_focus (LoadScreen);
00061 }
00062 }
00063
00064 void
00065 vapiGtkSetOriginWindowTestOrigin (GtkWidget * widget,
00066 vapiGtkSetOriginWindow * SetOrigin)
00067 {
00068 vapiGtkSetOriginWindowTestSaveOrigin (SetOrigin, vFALSE);
00069
00070 }
00071
00072 void
00073 vapiGtkSetOriginWindowSaveOrigin (GtkWidget * widget,
00074 vapiGtkSetOriginWindow * SetOrigin)
00075 {
00076 vImagesFreeImages (SetOrigin->Images);
00077 vapiGtkSetOriginWindowTestSaveOrigin (SetOrigin, vTRUE);
00078
00079
00080
00081 g_signal_emit_by_name (SetOrigin->RefreshButton, "clicked", NULL);
00082 }
00083
00084 void
00085 vapiGtkSetOriginWindowTestSaveOrigin (vapiGtkSetOriginWindow * SetOrigin,
00086 vBoolean SaveSettings)
00087 {
00088 int NoteBookPage, CamIndex;
00089 vCameraSettings *CameraSettings;
00090 vImages *tempImages;
00091 const char *Filename, *IP, *URL;
00092
00093 HaveAcquisitionLoadingProgress = vFALSE;
00094
00095 if (SaveSettings)
00096 {
00097 tempImages = SetOrigin->Images;
00098 CameraSettings = SetOrigin->CameraSettings;
00099 }
00100 else
00101 {
00102 tempImages = vImagesInit ();
00103 CameraSettings = vapiCameraSettingsInit ();
00104
00105 }
00106
00107 NoteBookPage =
00108 gtk_notebook_get_current_page ((GtkNotebook *) SetOrigin->
00109 nbCameraType);
00110
00111 switch (NoteBookPage)
00112 {
00113 case 0:
00114 {
00115 Filename =
00116 gtk_entry_get_text ((GtkEntry *)
00117 SetOrigin->CamLocalFilePATH);
00118 if (strlen (Filename) < 4)
00119 {
00120 return;
00121 }
00122 vapiCameraSettingsSetTypeLocalFile (CameraSettings, Filename);
00123 break;
00124 }
00125 #ifndef VAPI_DEMO
00126 case 1:
00127 {
00128
00129 CamIndex =
00130 gtk_spin_button_get_value_as_int ((GtkSpinButton *)
00131 SetOrigin->
00132 CamIndex);
00133 vapiCameraSettingsSetTypeLocal (CameraSettings, CamIndex);
00134 break;
00135 }
00136 case 2:
00137 {
00138 IP = gtk_entry_get_text ((GtkEntry *) SetOrigin->CamIP);
00139 URL = gtk_entry_get_text ((GtkEntry *) SetOrigin->CamURL);
00140 vapiCameraSettingsSetTypeRemoteIP (CameraSettings, IP, URL);
00141 break;
00142 }
00143 #endif
00144
00145 }
00146
00147 vapiGetSnapshot (tempImages, CameraSettings);
00148
00149 vapiOriginal2Actual (tempImages);
00150
00151
00152 if (!SaveSettings)
00153 {
00154 vapiGtkPutImage (SetOrigin->imOriginTest,
00155 tempImages->Original);
00156 vImagesFree (tempImages);
00157 vCameraSettingsFree (CameraSettings);
00158 }
00159
00160 }
00161
00162 void
00163 vapiGtkSetOriginWindowNewVapi (GtkWidget * widget,
00164 vapiGtkSetOriginWindow * SetOrigin)
00165 {
00166
00167 vapiGtkSetOriginWindow *SetOrigin2;
00168 vImages *tempImages = vImagesInit ();
00169 vCameraSettings *tempCameraSettings;
00170 tempCameraSettings = vapiCameraSettingsInit ();
00171
00172 SetOrigin2 = malloc (sizeof (vapiGtkSetOriginWindow));
00173
00174 SetOrigin2->Images = tempImages;
00175 SetOrigin2->nbCameraType = SetOrigin->nbCameraType;
00176 SetOrigin2->CameraSettings = tempCameraSettings;
00177 SetOrigin2->CamLocalFilePATH = SetOrigin->CamLocalFilePATH;
00178 SetOrigin2->CamIP = SetOrigin->CamIP;
00179 SetOrigin2->CamIndex = SetOrigin->CamIndex;
00180 SetOrigin2->CamURL = SetOrigin->CamURL;
00181 v_info ("a iniciar um vapi novo");
00182 vapiGtkSetOriginWindowTestSaveOrigin (SetOrigin2, vTRUE);
00183 if (vapiCameraSettingsStartNewVapi (SetOrigin2->CameraSettings))
00184 {
00185 v_error ("erro ao iniciar um novo vapi");
00186 }
00187 vImagesFree (tempImages);
00188 vCameraSettingsFree (tempCameraSettings);
00189 free (SetOrigin2);
00190 }
00191
00192 void
00193 vapiGtkSetOriginWindowDefineSource (GtkFileChooser * chooser, gint response,
00194 vapiGtkSetOriginWindow * SetOrigin)
00195 {
00196 char *filename;
00197 if (response == GTK_RESPONSE_CANCEL)
00198 {
00199 gtk_widget_destroy ((GtkWidget *) chooser);
00200 return;
00201 }
00202 if (response != GTK_RESPONSE_OK)
00203 {
00204 return;
00205 }
00206 filename = gtk_file_chooser_get_filename (chooser);
00207 v_debug ("here");
00208 gtk_entry_set_text ((GtkEntry *) SetOrigin->CamLocalFilePATH,
00209 filename);
00210 v_debug ("here2");
00211 gtk_widget_destroy ((GtkWidget *) chooser);
00212 g_free (filename);
00213 g_signal_emit_by_name (btTestOrigin, "clicked");
00214 }
00215
00216 void
00217 vapiGtkSetOriginWindowUpdatePreview (GtkFileChooser * chooser,
00218 GtkWidget * ImPreview)
00219 {
00220 char *filename;
00221 GError *error = NULL;
00222 GdkPixbuf *image;
00223
00224 filename = gtk_file_chooser_get_preview_filename (chooser);
00225 if (filename == NULL)
00226 {
00227 return;
00228 }
00229 image = gdk_pixbuf_new_from_file_at_scale (filename, 260, -1, TRUE,
00230 &error);
00231 if (image == NULL)
00232 {
00233 return;
00234 }
00235 gtk_image_set_from_pixbuf ((GtkImage *) ImPreview, image);
00236 g_object_unref (image);
00237 g_free (filename);
00238 }
00239
00240 void
00241 vapiGtkSetOriginWindowLaunchImageLoad (GtkWidget * widget,
00242 vapiGtkSetOriginWindow * SetOrigin)
00243 {
00244 GtkWidget *chooser;
00245 GtkWidget *ImPreview;
00246
00247 ImPreview = gtk_image_new ();
00248 gtk_widget_set_size_request (ImPreview, 260, 200);
00249
00250 chooser =
00251 gtk_file_chooser_dialog_new ("Carregar Macro de ficheiro",
00252 NULL,
00253 GTK_FILE_CHOOSER_ACTION_OPEN,
00254 NULL, NULL);
00255
00256
00257
00258 gtk_dialog_add_buttons ((GtkDialog *) chooser,
00259 "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-open",
00260 GTK_RESPONSE_OK, NULL);
00261 gtk_file_chooser_set_preview_widget_active ((GtkFileChooser *)
00262 chooser, TRUE);
00263 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser),
00264 vapiGtkImagesFilter ());
00265 gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser),
00266 ImPreview);
00267
00268 g_signal_connect (G_OBJECT (chooser), "update-preview",
00269 G_CALLBACK (vapiGtkSetOriginWindowUpdatePreview),
00270 ImPreview);
00271
00272 g_signal_connect (G_OBJECT (chooser), "response",
00273 G_CALLBACK (vapiGtkSetOriginWindowDefineSource),
00274 SetOrigin);
00275
00276 gtk_widget_show_all (chooser);
00277 }