00001 #include <gtk/gtk.h>
00002 #include "vapi.h"
00003 #include "vapiAux.h"
00004 #include "vapiTypes.h"
00005 #include "vapiString.h"
00006 #include "vapiGtkInterface.h"
00007 #include "vapiGtkAux.h"
00008 #include "vapiGtkAuxWindow.h"
00009 #include "vapiGtkOptions.h"
00010 #include "vapiGtkOptionsOperations.h"
00011 #include "vapiOperationOptions.h"
00012 #include "vapiGtkEventsOperations.h"
00013 #include "vapiGtkEventsMacros.h"
00014 #include "vapiMacroXML.h"
00015 #include "vapiGtkMacro.h"
00016 #include "vapiGtkMacrosTables.h"
00017 #include "vapiGtkTable.h"
00018 #include "vapiOperationsDefault.h"
00019 #include "vapiImagesAux.h"
00020 #include "vapiGtkImages.h"
00021 #include "vapiMacroBypass.h"
00022
00023 static vBoolean AppendOperation;
00024
00025 static struct
00026 {
00027 GtkWidget *dialogMacroDelete;
00028 GtkWidget *lblMacroDelete;
00029 GtkWidget *cbMacro;
00030 GtkTextView *txtMacroComent;
00031 GtkWidget *txtMacroName;
00032 vMacroList *MacroList;
00033 vOperationList *OperationList;
00034 GtkTextView *txtMacroChangeComment;
00035 GtkWidget *txtMacroChangeName;
00036 GList **OptionsData;
00037 } GtkMacroEvents;
00038 static GtkWidget *winCreateMacro;
00039 static GtkWidget *txtOperation;
00040 static vBoolean MacroRunning;
00045 void
00046 vapiGtkEventsMacrosInit (GladeXML * xml, vMacroList * MacroList,
00047 vOperationList * OperationList, vImages * Images,
00048 GList ** OptionsData)
00049 {
00050 GtkWidget *btMacroDeleteOk;
00051 GtkWidget *btMacroOpen;
00052 GtkWidget *btMacroSave;
00053 GtkWidget *btMacroNew;
00054 GtkWidget *winMacroChange;
00055 GtkWidget *btMacroChange;
00056 GtkWidget *btMacroNext;
00057 GtkWidget *btMacroStop;
00058
00059 GtkMacroEvents.txtMacroName =
00060 glade_xml_get_widget (xml, "txtMacroName");
00061 btMacroNew = glade_xml_get_widget (xml, "btMacroNew");
00062 GtkMacroEvents.dialogMacroDelete =
00063 glade_xml_get_widget (xml, "dialogMacroDelete");
00064 GtkMacroEvents.lblMacroDelete =
00065 glade_xml_get_widget (xml, "lblMacroDelete");
00066 GtkMacroEvents.cbMacro = glade_xml_get_widget (xml, "cbMacro");
00067 btMacroDeleteOk = glade_xml_get_widget (xml, "btMacroDeleteOk");
00068 btMacroOpen = glade_xml_get_widget (xml, "btMacroFromFile");
00069 btMacroSave = glade_xml_get_widget (xml, "btMacroSave");
00070 btMacroChange = glade_xml_get_widget (xml, "btMacroChange");
00071 winMacroChange = glade_xml_get_widget (xml, "winMacroChange");
00072 winCreateMacro = glade_xml_get_widget (xml, "winCreateMacro");
00073 GtkMacroEvents.txtMacroComent =
00074 (GtkTextView *) glade_xml_get_widget (xml, "txtMacroComment");
00075 GtkMacroEvents.txtMacroChangeComment =
00076 (GtkTextView *) glade_xml_get_widget (xml,
00077 "txtMacroChangeComment");
00078 GtkMacroEvents.txtMacroChangeName =
00079 glade_xml_get_widget (xml, "txtMacroChangeName");
00080 btMacroNext = glade_xml_get_widget (xml, "btMacroNext");
00081 btMacroStop = glade_xml_get_widget (xml, "btMacroStop");
00082 txtOperation = glade_xml_get_widget (xml, "txtOperation");
00083 AppendOperation = vFALSE;
00084 GtkMacroEvents.MacroList = MacroList;
00085 GtkMacroEvents.OptionsData = OptionsData;
00086 GtkMacroEvents.OperationList = OperationList;
00087 MacroRunning = vFALSE;
00088
00089 g_signal_connect (G_OBJECT (btMacroDeleteOk), "clicked",
00090 G_CALLBACK (vapiGtkMacroDeleteMacro), NULL);
00091 g_signal_connect (G_OBJECT (btMacroSave), "clicked",
00092 G_CALLBACK (vapiGtkMacroLaunchMacroSave), NULL);
00093 g_signal_connect (G_OBJECT (btMacroOpen), "clicked",
00094 G_CALLBACK (vapiGtkMacroLaunchMacroOpen),
00095 OperationList);
00096 g_signal_connect (G_OBJECT (btMacroChange), "clicked",
00097 G_CALLBACK (vapiGtkMacroLaunchChangeWindow),
00098 winMacroChange);
00099 g_signal_connect (G_OBJECT (winMacroChange), "response",
00100 G_CALLBACK (vapiGtkMacroChange), NULL);
00101 g_signal_connect (G_OBJECT (btMacroNew), "clicked",
00102 G_CALLBACK (vapiGtkMacroCreate), NULL);
00103 g_signal_connect (G_OBJECT (winCreateMacro), "response",
00104 G_CALLBACK (vapiGtkMacroCreate), NULL);
00105 g_signal_connect (G_OBJECT (btMacroNext), "clicked",
00106 G_CALLBACK (vapiGtkMacroSelectNext), Images);
00107 g_signal_connect (G_OBJECT (btMacroStop), "clicked",
00108 G_CALLBACK (vapiGtkMacroStop), NULL);
00109 }
00110
00111 void
00112 vapiGtkMacroCreate (GtkWidget * widget, int response, vapiTemp1Struct * temp)
00113 {
00114 char *string;
00115 char *MacroComment;
00116 GtkTextBuffer *textBuffer;
00117 GtkTextIter iterStart, iterEnd;
00118 int MacroNumber;
00119 vMacroHeader *MacroHeader;
00120 if (response != GTK_RESPONSE_OK)
00121 {
00122 return;
00123 }
00124 if (vapiGtkMacroIsItRunning ())
00125 {
00126 return;
00127 }
00128 string = (char *) gtk_entry_get_text ((GtkEntry *) GtkMacroEvents.
00129 txtMacroName);
00130 if (!strcmp (string, ""))
00131 {
00132 return;
00133 }
00134 if ((MacroNumber =
00135 vapiMacroListMacroExist (GtkMacroEvents.MacroList, string,
00136 1)) != -1)
00137 {
00138 MacroHeader = vapiMacroNew (string);
00139 textBuffer =
00140 gtk_text_view_get_buffer (GtkMacroEvents.
00141 txtMacroComent);
00142 gtk_text_buffer_get_start_iter (textBuffer, &iterStart);
00143
00144 gtk_text_buffer_get_end_iter (textBuffer, &iterEnd);
00145
00146 MacroComment =
00147 gtk_text_buffer_get_text (textBuffer, &iterStart,
00148 &iterEnd, TRUE);
00149 gtk_text_buffer_set_text (textBuffer, "", -1);
00150 v_debug ("comentário à macro .%s.", MacroComment);
00151 vapiMacroUpdateComment (MacroHeader, MacroComment);
00152 vapiMacroListAddItem (GtkMacroEvents.MacroList, MacroHeader);
00153 MacroNumber =
00154 vapiMacroListMacroExist (GtkMacroEvents.MacroList,
00155 string, 0);
00156 vapiGtkCbMacroStart ();
00157
00158 if (SelectedMacro == -1 && AppendOperation)
00159 {
00160 SelectedMacro = MacroNumber;
00161 vapiGtkMacroAppendItem (widget, NULL);
00162
00163 AppendOperation = vFALSE;
00164 }
00165 gtk_widget_hide (widget);
00166
00167 vapiGtkComboBoxSetActive (GtkMacroEvents.cbMacro,
00168 MacroNumber);
00169 }
00170 gtk_entry_set_text ((GtkEntry *) GtkMacroEvents.txtMacroName, "");
00171 }
00172
00173 void
00174 vapiGtkMacroLaunchChangeWindow (GtkWidget * widget,
00175 GtkWidget * winMacroChange)
00176 {
00177 GtkTextBuffer *textBuffer;
00178 vMacroHeader *MacroHeader;
00179 if (vapiGtkMacroCheckSelected ())
00180 {
00181 return;
00182 }
00183 MacroHeader =
00184 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00185 SelectedMacro);
00186 gtk_entry_set_text ((GtkEntry *) GtkMacroEvents.txtMacroChangeName,
00187 MacroHeader->MacroName);
00188 textBuffer =
00189 gtk_text_view_get_buffer (GtkMacroEvents.
00190 txtMacroChangeComment);
00191 gtk_text_buffer_set_text (textBuffer, MacroHeader->MacroComment, -1);
00192 gtk_widget_show (winMacroChange);
00193 }
00194
00195 void
00196 vapiGtkMacroChange (GtkWidget * widget, int response, vapiTemp1Struct * temp)
00197 {
00198 char *MacroName, *MacroComment;
00199 GtkTextBuffer *textBuffer;
00200 GtkTextIter iterEnd, iterStart;
00201 vMacroHeader *MacroHeader;
00202 if (response != GTK_RESPONSE_OK)
00203 {
00204 return;
00205 }
00206 if (SelectedMacro == -1)
00207 {
00208 return;
00209 }
00210 MacroHeader =
00211 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00212 SelectedMacro);
00213
00214 MacroName = (char *) gtk_entry_get_text ((GtkEntry *)
00215 GtkMacroEvents.
00216 txtMacroChangeName);
00217 textBuffer =
00218 gtk_text_view_get_buffer (GtkMacroEvents.
00219 txtMacroChangeComment);
00220 gtk_text_buffer_get_start_iter (textBuffer, &iterStart);
00221
00222 gtk_text_buffer_get_end_iter (textBuffer, &iterEnd);
00223
00224 MacroComment =
00225 gtk_text_buffer_get_text (textBuffer, &iterStart,
00226 &iterEnd, TRUE);
00227 gtk_text_buffer_set_text (textBuffer, "", -1);
00228
00229 vapiMacroUpdateName (MacroHeader, MacroName);
00230
00231 vapiMacroUpdateComment (MacroHeader, MacroComment);
00232
00233 vapiGtkCbMacroStart ();
00234
00235 gtk_widget_hide (widget);
00236 }
00237
00238 void
00239 vapiGtkMacroUpdateItemOptions (GtkWidget * widget, vapiTemp1Struct * temp)
00240 {
00241
00242 vMacroItem *item;
00243 vMacroHeader *MacroHeader;
00244 int selected;
00245 if (vapiGtkMacroCheckSelected ())
00246 {
00247 return;
00248 }
00249 MacroHeader =
00250 vapiMacroListSelectItem (temp->MacroList, SelectedMacro);
00251 selected = vapiGtkMacroTableGetSelected ();
00252 if (selected >= 0)
00253 {
00254 item = vapiMacroSelectItem (MacroHeader->Macro, selected);
00255 vOperationOptionsFree (item->Options, item->Operation);
00256 item->Options = vapiOperationOptionsInit (item->Operation);
00257 vapiGtkOptionsGetOptions (item->Options,
00258 item->Operation->
00259 OptionsSettings,
00260 &vapiGtkOptionsGetOptionsCustomOperations,
00261 &temp->Widgets->OptionsData);
00262 vapiGtkMacroTable ();
00263 }
00264 else
00265 {
00266 v_error ("Nenhuma Operação seleccionada para actualização.");
00267 }
00268 }
00269
00270 void
00271 vapiGtkMacroAppendItem (GtkWidget * widget, vapiTemp1Struct * temp1)
00272 {
00273 vOptions *options;
00274 vMacroHeader *MacroHeader;
00275 vEffect *Operation;
00276 if (vapiGtkMacroIsItRunning ())
00277 {
00278 return;
00279 }
00280 Operation =
00281 vapiGetOperationFromTxtOperation (txtOperation,
00282 GtkMacroEvents.
00283 OperationList);
00284 if (vapiGtkAuxCheckOperation (Operation))
00285 {
00286 return;
00287 }
00288 if (SelectedMacro == -1)
00289 {
00290 AppendOperation = vTRUE;
00291 gtk_widget_show (winCreateMacro);
00292 return;
00293 }
00294 AppendOperation = vFALSE;
00295 if (Operation == NULL)
00296 {
00297 return;
00298 }
00299
00300
00301
00302 options = vapiOperationOptionsInit (Operation);
00303 vapiGtkOptionsGetOptions (options,
00304 Operation->OptionsSettings,
00305 &vapiGtkOptionsGetOptionsCustomOperations,
00306 GtkMacroEvents.OptionsData);
00307 if (vapiCheckOperations
00308 (Operation, options, GtkMacroEvents.MacroList))
00309 {
00310 return;
00311 }
00312 MacroHeader =
00313 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00314 SelectedMacro);
00315 vapiMacroAddItem (MacroHeader->Macro, Operation, options);
00316 v_bypass_set_updatable (vTRUE);
00317 vapiGtkMacroTable ();
00318 }
00319
00320
00321 void
00322 vapiGtkMacroInsertItem (GtkWidget * widget, vapiTemp1Struct * temp1)
00323 {
00324 vMacroHeader *MacroHeader;
00325 vOptions *options;
00326 vEffect *Operation;
00327 int total, selectedRow;
00328 if (vapiGtkMacroCheckSelected ())
00329 {
00330 return;
00331 }
00332 if (vapiGtkMacroIsItRunning ())
00333 {
00334 return;
00335 }
00336 MacroHeader =
00337 vapiMacroListSelectItem (temp1->MacroList, SelectedMacro);
00338 Operation =
00339 vapiGetOperationFromTxtOperation (txtOperation,
00340 GtkMacroEvents.
00341 OperationList);
00342 if (vapiGtkAuxCheckOperation (Operation))
00343 {
00344 return;
00345 }
00346 options = vapiOperationOptionsInit (Operation);
00347 vapiGtkOptionsGetOptions (options,
00348 Operation->OptionsSettings,
00349 &vapiGtkOptionsGetOptionsCustomOperations,
00350 &temp1->Widgets->OptionsData);
00351 if (vapiCheckOperations (Operation, options, temp1->MacroList))
00352 {
00353 return;
00354 }
00355
00356
00357
00358
00359
00360 selectedRow = vapiGtkMacroTableGetSelected ();
00361
00362
00363
00364 total = vapiMacroCountElements (MacroHeader->Macro);
00365
00366
00367
00368 vapiMacroAddItemPositioned (MacroHeader->Macro,
00369 Operation, options, selectedRow);
00370 v_bypass_set_updatable (vTRUE);
00371 vapiGtkMacroTable ();
00372 }
00373
00374
00375 void
00376 vapiGtkMacroDeleteItem (GtkWidget * widget, vapiTemp1Struct * temp1)
00377 {
00378 vMacroHeader *MacroHeader;
00379 int selectedRow;
00380 if (vapiGtkMacroCheckSelected ())
00381 {
00382 return;
00383 }
00384 if (vapiGtkMacroIsItRunning ())
00385 {
00386 return;
00387 }
00388 MacroHeader =
00389 vapiMacroListSelectItem (temp1->MacroList, SelectedMacro);
00390 selectedRow = vapiGtkMacroTableGetSelected ();
00391 if (selectedRow >= 0)
00392 {
00393 vapiMacroDeleteItem (MacroHeader->Macro, selectedRow);
00394 v_bypass_set_updatable (vTRUE);
00395 vapiGtkMacroTable (MacroHeader);
00396 }
00397 else
00398 {
00399 v_info ("Macro Delete Item: no row selected.\n");
00400 }
00401 }
00402
00403 void
00404 vapiGtkMacroApply (GtkWidget * widget, vapiTemp1Struct * temp)
00405 {
00406 vMacroHeader *MacroHeader;
00407 vMacroThread *MacroThread;
00408 GError *error;
00409 if (vapiGtkMacroCheckSelected ())
00410 {
00411 return;
00412 }
00413 if (vapiGtkMacroIsItRunning ())
00414 {
00415 return;
00416 }
00417 vapiGtkMacroRunningStart ();
00418 MacroHeader =
00419 vapiMacroListSelectItem (temp->MacroList, SelectedMacro);
00420 MacroThread = vapiGtkMacroThreadNew (MacroHeader, temp->Images);
00421 g_thread_create ((vpointer) & vapiGtkApplyMacroThread, MacroThread,
00422 FALSE, &error);
00423 }
00424
00425 void
00426 vapiGtkMacroSelectItem (GtkWidget * widget,
00427 GtkTreePath * path,
00428 GtkTreeIter * iter,
00429 vMacroTablesSelect * MacroTablesSelect)
00430 {
00431 vMacroItem *item;
00432 gint *itemNum;
00433 GError *error;
00434 vMacroThread *MacroThread;
00435 vMacroHeader *MacroHeader;
00436 itemNum = gtk_tree_path_get_indices (path);
00437 v_debug ("antes do if");
00438 MacroHeader =
00439 vapiMacroListSelectItem (MacroTablesSelect->MacroList,
00440 SelectedMacro);
00441 if (!vapiGtkMacroRunningTest ())
00442 {
00443 vResultReset (MacroHeader->PreviousResult);
00444 MacroHeader->PreviousResult->macroTag =
00445 vapiGtkMacroGetMacroTag ();
00446 vapiGtkMacroApplyAllMacros ();
00447
00448 MacroThread =
00449 vapiGtkMacroThreadNew (MacroHeader,
00450 MacroTablesSelect->Images);
00451 MacroThread->Until = itemNum[0];
00452 g_thread_create ((vpointer) & vapiGtkApplyMacroUntilThread,
00453 MacroThread, FALSE, &error);
00454 }
00455 item = vapiMacroSelectItem (MacroHeader->Macro, itemNum[0]);
00456 v_debug ("depois do select");
00457 gtk_entry_set_text ((GtkEntry *) MacroTablesSelect->
00458 txtOperation, item->Operation->name);
00459 v_debug ("set text");
00460 vapiGtkOptionsPopulate (item->Options,
00461 item->Operation->
00462 OptionsSettings,
00463 MacroTablesSelect->Lists,
00464 &vapiGtkOptionsPopulateCustomOperations);
00465 v_debug ("populate");
00466 }
00467
00468 void
00469 vapiGtkMacroSaveToXML (GtkFileChooser * chooser,
00470 gint response, vapiTemp1Struct * temp)
00471 {
00472 vMacroHeader *MacroHeader;
00473 char *filename;
00474 v_debug ("entrou no grvar xml");
00475 if (response == GTK_RESPONSE_CANCEL)
00476 {
00477 gtk_widget_destroy ((GtkWidget *) chooser);
00478 return;
00479 }
00480
00481 if (vapiGtkMacroCheckSelected () || response != GTK_RESPONSE_OK)
00482 {
00483 v_error_ui ("Nenhua Macro Seleccionada");
00484 return;
00485 }
00486
00487 MacroHeader =
00488 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00489 SelectedMacro);
00490 filename = gtk_file_chooser_get_filename (chooser);
00491 vapiMacroToXML (MacroHeader, filename);
00492 gtk_widget_destroy ((GtkWidget *) chooser);
00493 }
00494
00495 void
00496 vapiGtkMacroOpenFromXML (GtkFileChooser * chooser,
00497 gint response, vOperationList * OperationList)
00498 {
00499 const char *filename;
00500 vMacroHeader *MacroHeader;
00501 if (response == GTK_RESPONSE_CANCEL)
00502 {
00503 gtk_widget_destroy ((GtkWidget *) chooser);
00504 return;
00505 }
00506 if (response != GTK_RESPONSE_OK)
00507 {
00508 return;
00509 }
00510 filename = gtk_file_chooser_get_filename ((GtkFileChooser *) chooser);
00511 v_debug ("aqui %s", filename);
00512 if (vapiMacroXMLLoadToList
00513 (GtkMacroEvents.MacroList, OperationList, filename))
00514 {
00515 if (!vapiGtkMacroIsItRunning ())
00516 {
00517 SelectedMacro =
00518 (vapiMacroListCountElements
00519 (GtkMacroEvents.MacroList) - 1);
00520 }
00521 vapiGtkCbMacroStart ();
00522 MacroHeader =
00523 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00524 SelectedMacro);
00525 gtk_widget_destroy ((GtkWidget *) chooser);
00526 }
00527 else
00528 {
00529 v_error_ui ("A Macro \"%s\" jé existe",
00530 vapiMacroFromXMLSetName (filename));
00531 }
00532 }
00533
00534 void
00535 vapiGtkMacroDeleteMacro (GtkWidget * widget, gpointer user_data)
00536 {
00537 if (vapiGtkMacroCheckSelected ())
00538 {
00539 return;
00540 }
00541 if (vapiGtkMacroIsItRunning ())
00542 {
00543 return;
00544 }
00545 vapiMacroListDeleteItem (GtkMacroEvents.MacroList, SelectedMacro);
00546 SelectedMacro = -1;
00547 SelectedMacroGlobal = -1;
00548 vapiGtkCbMacroStart ();
00549 vapiGtkMacrosTablesCleanToDefault ();
00550 gtk_widget_hide (GtkMacroEvents.dialogMacroDelete);
00551 }
00552
00553 void
00554 vapiGtkMacroSelect (GtkWidget * widget, gpointer user_data)
00555 {
00556 int Exist;
00557 char *string;
00558 vMacroHeader *MacroHeader;
00559 string = gtk_combo_box_get_active_text ((GtkComboBox *) widget);
00560
00561 Exist = vapiGtkComboBoxGetActiveRow (widget);
00562 if (Exist >= 0)
00563 {
00564 if (SelectedMacroGlobal == -1)
00565 {
00566 v_bypass_init ();
00567 }
00568 SelectedMacro = Exist;
00569 SelectedMacroGlobal = Exist;
00570 MacroHeader =
00571 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00572 Exist);
00573 v_bypass_set_updatable (vTRUE);
00574 vapiGtkMacroTable ();
00575 }
00576 else
00577 {
00578 vapiGtkMacrosTablesCleanToDefault ();
00579 SelectedMacroGlobal = -1;
00580 SelectedMacro = -1;
00581 }
00582 }
00583
00584 void
00585 vapiGtkMacroLauchDeleteDialog (GtkWidget * widget, gpointer user_data)
00586 {
00587 vMacroHeader *MacroHeader;
00588 if (vapiGtkMacroCheckSelected ())
00589 {
00590 return;
00591 }
00592 if (vapiGtkMacroIsItRunning ())
00593 {
00594 return;
00595 }
00596 MacroHeader =
00597 vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00598 SelectedMacro);
00599 gtk_label_set_text ((GtkLabel *) GtkMacroEvents.
00600 lblMacroDelete,
00601 g_strdup_printf
00602 ("Tem a certeza que deseja eliminar a Tarefa com o nome: \n %s",
00603 MacroHeader->MacroName));
00604 gtk_widget_show (GtkMacroEvents.dialogMacroDelete);
00605 }
00606
00607 void
00608 vapiGtkMacroLaunchMacroOpen (GtkWidget * widget,
00609 vOperationList * OperationList)
00610 {
00611 GtkWidget *chooser;
00612 GtkWidget *preview_macro_label;
00613 GtkWidget *preview_macro_name;
00614 GtkWidget *preview_pack;
00615 GtkWidget *preview_separator;
00616 preview_pack = gtk_vbox_new (FALSE, 0);
00617 gtk_widget_set_size_request (preview_pack, 260, -1);
00618 preview_macro_label = gtk_label_new ("");
00619 gtk_label_set_markup ((GtkLabel *)
00620 preview_macro_label,
00621 "<b><span size=\"large\"> Nome da Macro</span></b>");
00622 gtk_box_pack_start ((GtkBox *) preview_pack,
00623 preview_macro_label, FALSE, FALSE, 6);
00624 preview_separator = gtk_hseparator_new ();
00625 gtk_box_pack_start ((GtkBox *) preview_pack,
00626 preview_separator, FALSE, FALSE, 0);
00627 preview_macro_name = gtk_label_new ("");
00628 gtk_box_pack_start ((GtkBox *) preview_pack,
00629 preview_macro_name, FALSE, FALSE, 4);
00630 chooser =
00631 gtk_file_chooser_dialog_new
00632 ("Carregar Macro de ficheiro", NULL,
00633 GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
00634
00635
00636
00637 gtk_dialog_add_buttons ((GtkDialog *) chooser,
00638 "gtk-cancel",
00639 GTK_RESPONSE_CANCEL,
00640 "gtk-open", GTK_RESPONSE_OK, NULL);
00641 gtk_file_chooser_set_preview_widget_active ((GtkFileChooser *)
00642 chooser, TRUE);
00643 gtk_file_chooser_set_preview_widget ((GtkFileChooser *) chooser,
00644 preview_pack);
00645 gtk_file_chooser_add_filter ((GtkFileChooser *) chooser,
00646 vapiGtkMacroFileFilterOpen ());
00647 g_signal_connect (G_OBJECT (chooser), "response",
00648 G_CALLBACK (vapiGtkMacroOpenFromXML),
00649 OperationList);
00650 g_signal_connect_after (G_OBJECT (chooser), "update-preview",
00651 G_CALLBACK (vapiGtkMacroUpdateMacroName),
00652 preview_macro_name);
00653 gtk_widget_show_all (chooser);
00654 gtk_widget_show_all (preview_pack);
00655 }
00656
00657 void
00658 vapiGtkMacroLaunchMacroSave (GtkWidget * widget,
00659 vOperationList * OperationList)
00660 {
00661 GtkWidget *chooser;
00662 if (vapiGtkMacroCheckSelected ())
00663 {
00664 return;
00665 }
00666
00667 chooser =
00668 gtk_file_chooser_dialog_new
00669 ("Guardar Macro Para Ficheiro", NULL,
00670 GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
00671
00672
00673
00674 gtk_dialog_add_buttons ((GtkDialog *) chooser,
00675 "gtk-cancel",
00676 GTK_RESPONSE_CANCEL,
00677 "gtk-save", GTK_RESPONSE_OK, NULL);
00678 gtk_file_chooser_set_preview_widget_active ((GtkFileChooser *)
00679 chooser, FALSE);
00680 gtk_file_chooser_add_filter ((GtkFileChooser *) chooser,
00681 vapiGtkMacroFileFilterSave ());
00682 g_signal_connect (G_OBJECT (chooser), "response",
00683 G_CALLBACK (vapiGtkMacroSaveToXML), NULL);
00684 gtk_widget_show_all (chooser);
00685 }
00686
00687 void
00688 vapiGtkMacroUpdateMacroName (GtkWidget * widget,
00689 GtkLabel * preview_macro_name)
00690 {
00691 char *filename, *macro_name;
00692 filename = gtk_file_chooser_get_filename ((GtkFileChooser *) widget);
00693 if (filename == NULL)
00694 {
00695 return;
00696 }
00697
00698
00699
00700
00701
00702
00703
00704 #ifdef VAPI_OS_LINUX
00705 if (vapiIsDirectory (filename))
00706 {
00707 return;
00708 }
00709 #else
00710 if (strstr (filename, ".xml") == NULL)
00711 {
00712 return;
00713 }
00714 #endif
00715 macro_name = vapiMacroFromXMLSetName (filename);
00716 if (macro_name == NULL)
00717 {
00718 g_free (filename);
00719 gtk_label_set_text ((GtkLabel *) preview_macro_name, "");
00720 return;
00721 }
00722
00723 gtk_label_set_text ((GtkLabel *) preview_macro_name, macro_name);
00724 g_free (filename);
00725 v_debug ("macro preview");
00726 }
00727
00728 void
00729 vapiGtkMacroSelectNext (GtkWidget * widget, vImages * Images)
00730 {
00731 int SelectedOperation;
00732 vMacroHeader *MacroHeader;
00733 vMacroItem *Item;
00734 if (vapiGtkMacroCheckSelected ())
00735 {
00736 return;
00737 }
00738 if (vapiGtkMacroIsItRunning ())
00739 {
00740 return;
00741 }
00742 vapiGtkMacroRunningStart ();
00743 SelectedOperation = vapiGtkMacroTableGetSelected ();
00744 if (SelectedOperation < 0)
00745 {
00746 SelectedOperation = 0;
00747 }
00748 else
00749 {
00750 SelectedOperation++;
00751 }
00752 if (vapiGtkMacroTableSelectRow (SelectedOperation))
00753 {
00754 vapiGtkMacroRunningStop ();
00755 return;
00756 }
00757 MacroHeader = vapiMacroListSelectItem (GtkMacroEvents.MacroList,
00758 SelectedMacro);
00759 Item = vapiMacroSelectItem (MacroHeader->Macro, SelectedOperation);
00760
00761 vapiApplyOperation (Images, Item->Operation, Item->Options,
00762 MacroHeader->PreviousResult);
00763 vapiGtkMacroRunningStop ();
00764 vapiGtkImagesUpdateInterface (Images, gtkImActual);
00765
00766 }
00767
00768 void
00769 vapiGtkMacroStop (GtkWidget * widget, GMutex * mutex)
00770 {
00771 vapiGtkMacroRunningStop ();
00772 v_debug ("parar a macro");
00773 }
00774
00775 void
00776 vapiGtkMacroSetBypass (GtkCellRendererToggle * cell_renderer,
00777 gchar * path, gpointer user_data)
00778 {
00779 char *macroTag;
00780 GtkTreePath *TreePath;
00781 gint *itemNum;
00782 TreePath = gtk_tree_path_new_from_string (path);
00783 itemNum = gtk_tree_path_get_indices (TreePath);
00784 macroTag = vapiGtkMacroGetMacroTag ();
00785 v_debug ("macro tag no bypass: %s", macroTag);
00786 v_bypass_set (macroTag, itemNum[0]);
00787 vapiGtkMacroTable ();
00788 free (macroTag);
00789 }
00790
00791 vBoolean
00792 vapiGtkMacroIsItRunning ()
00793 {
00794 if (MacroRunning)
00795 {
00796 v_error_ui ("Existe uma tarefa em execução.");
00797 return vTRUE;
00798 }
00799 return vFALSE;
00800 }
00801
00802 void
00803 vapiGtkMacroSetStopby (GtkCellRendererToggle * cell_renderer,
00804 gchar * path, gpointer user_data)
00805 {
00806 char *macroTag;
00807 GtkTreePath *TreePath;
00808 gint *itemNum;
00809 TreePath = gtk_tree_path_new_from_string (path);
00810 itemNum = gtk_tree_path_get_indices (TreePath);
00811 macroTag = vapiGtkMacroGetMacroTag ();
00812 v_stopby_set (macroTag, itemNum[0]);
00813 vapiGtkMacroTable ();
00814 free (macroTag);
00815 }
00816
00817 void
00818 vapiGtkMacroRunningStart ()
00819 {
00820 v_debug ("vapiGtkMacroRunningStart");
00821 MacroRunning = vTRUE;
00822 }
00823
00824 void
00825 vapiGtkMacroRunningStop ()
00826 {
00827 v_debug ("vapiGtkMacroRunningStop");
00828 MacroRunning = vFALSE;
00829 }
00830
00831 vBoolean
00832 vapiGtkMacroRunningTest ()
00833 {
00834 if (MacroRunning)
00835 {
00836 return vTRUE;
00837 }
00838 return vFALSE;
00839 }