1 /*
2     Copyright 2007, 2008, 2009, 2010 Geyer Klaus
3 
4     This file is part of Cat'sEyE.
5 
6     Cat'sEyE is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     Cat'sEyE is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Cat'sEyE.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 
22 #include <gtk/gtk.h>
23 #ifndef NO_GIO
24 #include <gio/gio.h>
25 #endif
26 #include <string.h>
27 #include <stdlib.h>
28 #include <gdk/gdkkeysyms.h>
29 
30 
31 #include "helpers.h"
32 #include "Lists.h"
33 #include "mytrace.h"
34 #include "userdata.h"
35 #include "confighandling.h"
36 #include "CommandParser.h"
37 #include "globalDefinitions.h"
38 
39 #include "allInclude.h"
40 
41 extern GtkWindow 	*win;
42 
43 int decryptPredefine(GString *Predefine, struct _predefineStruct *predefStruct);
44 int exchangePredefine(GString *gstrText, struct _predefineStruct *predefStruct);
45 int processBackSpaces(GString *gstrStartText, gboolean bMakeThreadSave);
46 int processMyStandardEscapeSequences(GString *gstrToChange);
47 int exchangeUserVarsInText(GString *gstrText, struct _DialogEntityList *DialogEntityList);
48 void UserDialog_FileDirChooserButton(GtkEntry *entry, gpointer data);
49 int processAsTextWithoutUserVars (GString *gstrDestination, GString *gstrSource, struct _predefineStruct *predefStruct, gboolean bMakeThreadSave);
50 
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////
52 ////////////////////////////////////////////////////////////////////////////////////////////////////////
53 ////////////////////////////////////////////////////////////////////////////////////////////////////////
54 //below are the new prototypes
55 int ParseXMLUserCommand_ParseDialog(struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, struct _predefineStruct *predefineStruct, gboolean *bShowCommand);
56 int ParseXMLUserCommand_FillPredefineStruct (struct _predefineStruct *predefineStruct, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, GString *gstrWorkingPath );
57 int ParseXMLUserCommand_ReplaceVarsInString (GString **gstrpDestination, GString *gstrSource, struct _predefineStruct *predefineStruct, struct _DialogEntityList *DialogEntityList);
58 gboolean ParseXMLUserComman_ESCButtonHandlerForUserDialog(GtkWidget *widget, GdkEventKey *event, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct);
59 int ParseXMLUserCommand_FreePredefineStruct (struct _predefineStruct *predefineStruct);
60 ////////////////////////////////////////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////////////////////////////////////
63 //starting with the new functions
64 
65 
ParseXMLUserCommand(struct _CallUserCommand_StartThreadStructure * ThreadStartStruct,GString ** gstrpParsedCommand,GString ** gstrpQuitReplyText,GString ** gstrpActionNoteText,GString * gstrWorkingPath)66 int ParseXMLUserCommand (struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, GString **gstrpParsedCommand, GString **gstrpQuitReplyText, GString **gstrpActionNoteText, GString *gstrWorkingPath){
67     TRACEIT (10, "ParseXMLUserCommand       start");
68     //in here we build the usercommand ready to be sent to the shell
69     //we will create the dialog if necessary
70     //and fill the Quitreply and actionNote strings
71     //return: error = -1, 0=ok
72     //1=user canceled one item
73     //2=user canceled all items
74     int iRet = 0;
75     int iDRet = 0;
76     gboolean bShowCommand=FALSE;
77     GtkWidget *dialog, *entrybox;
78 
79     if (ThreadStartStruct==NULL || gstrpParsedCommand==NULL || gstrpQuitReplyText==NULL || gstrpActionNoteText==NULL || gstrWorkingPath==NULL){
80         TRACEIT (2, "ParseXMLUserCommand        parameter NULL");
81         return -1;
82     }
83     struct _predefineStruct predefineStruct;
84     struct _UserCommandList *UserCommandList = (struct _UserCommandList*)(ThreadStartStruct->OurUserDataListItem->ListElement);
85 
86     iRet = ParseXMLUserCommand_FillPredefineStruct (&predefineStruct, ThreadStartStruct, gstrWorkingPath);
87 
88     if ( iRet == 0 && (UserCommandList->gstrDialogLabel!=NULL ||  UserCommandList->gstrDialogCaption!=NULL || UserCommandList->DialogEntityList != NULL)){
89         iRet = ParseXMLUserCommand_ParseDialog(ThreadStartStruct, &predefineStruct, &bShowCommand);
90     }
91 
92     if (iRet == 0 ) {
93         //let us build the command
94         iRet = ParseXMLUserCommand_ReplaceVarsInString (gstrpParsedCommand, UserCommandList->gstrCommand, &predefineStruct, UserCommandList->DialogEntityList);
95     }
96 
97     if (iRet == 0 && bShowCommand==TRUE && *gstrpParsedCommand != NULL){
98         myWrap_gdk_threads_enter("ParseXMLUserCommand");
99 
100         dialog = CreateMyDialog("Usercommand ready for take off",win,2,"Go",GTK_RESPONSE_ACCEPT,"Stop execution",GTK_RESPONSE_REJECT, NULL, 0,  TRUE);
101         entrybox = gtk_entry_new();
102         gtk_entry_set_text((GtkEntry *)entrybox,(*gstrpParsedCommand)->str);
103         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),entrybox);
104         gtk_widget_show_all(dialog);
105         iDRet = gtk_dialog_run(GTK_DIALOG(dialog));
106         if (iDRet == GTK_RESPONSE_ACCEPT){
107             g_string_assign(*gstrpParsedCommand, gtk_entry_get_text ((GtkEntry *)entrybox));
108             iRet = 0;
109         }
110         else{
111             iRet = 1;
112             //ThreadStartStruct->iCancelAll = 1;
113         }
114 
115         gtk_widget_destroy(dialog);
116         myWrap_gdk_threads_leave("ParseXMLUserCommand");
117     }
118 
119     if (ThreadStartStruct->iCancelAll == 0 && iRet == 0){
120         if (UserCommandList->option_gstrActionnote != NULL){
121             ParseXMLUserCommand_ReplaceVarsInString (gstrpActionNoteText, UserCommandList->option_gstrActionnote, &predefineStruct, UserCommandList->DialogEntityList);
122         }
123 
124         if (UserCommandList->option_gstrQuitreply != NULL){
125             ParseXMLUserCommand_ReplaceVarsInString (gstrpQuitReplyText, UserCommandList->option_gstrQuitreply, &predefineStruct, UserCommandList->DialogEntityList);
126         }
127     }
128 
129     ParseXMLUserCommand_FreePredefineStruct (&predefineStruct);
130 
131     TRACEIT (10, "ParseXMLUserCommand       end");
132     return iRet;
133 }
134 
135 
ParseXMLUserCommand_ReplaceVarsInString(GString ** gstrpDestination,GString * gstrSource,struct _predefineStruct * predefineStruct,struct _DialogEntityList * DialogEntityList)136 int ParseXMLUserCommand_ReplaceVarsInString (GString **gstrpDestination, GString *gstrSource, struct _predefineStruct *predefineStruct, struct _DialogEntityList *DialogEntityList){
137     TRACEIT (10, "ParseXMLUserCommand_ReplaceVarsInString       start");
138     //used e.g. to create the usercommand
139     if (gstrpDestination == NULL || gstrSource==NULL || predefineStruct==NULL ){
140         TRACEIT (2, "ParseXMLUserCommand_ReplaceVarsInString        parameter NULL");
141         return -1;
142     }
143     int iRet=0;
144     int i;
145 
146     if (*gstrpDestination == NULL){
147         *gstrpDestination = g_string_new(gstrSource->str);
148     }
149     else{
150         g_string_assign (*gstrpDestination, gstrSource->str);
151     }
152 
153     processMyStandardEscapeSequences (*gstrpDestination);
154 
155     i=0;
156     if (DialogEntityList != NULL){
157         do{
158             iRet = exchangeUserVarsInText(*gstrpDestination, DialogEntityList);
159             i++;
160         }while (iRet > 0 && i < 5);
161     }
162     if (iRet == 0){
163         exchangePredefine(*gstrpDestination, predefineStruct);
164     }
165     if (iRet == 0){
166         processBackSpaces(*gstrpDestination, TRUE);
167     }
168     TRACEIT (10, "ParseXMLUserCommand_ReplaceVarsInString       end");
169     return 0;
170 }
171 
172 
ParseXMLUserCommand_ButtonOk(GtkButton * button,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)173 void ParseXMLUserCommand_ButtonOk (GtkButton *button, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
174     TRACEIT (10, "ParseXMLUserCommand_ButtonOk       start");
175 
176     if ( ThreadStartStruct == NULL){
177         TRACEIT (2, "ParseXMLUserCommand_ButtonOk       parameter NULL");
178         return;
179     }
180     //GTK_RESPONSE_ACCEPT,"Cancel",GTK_RESPONSE_REJECT, "Cancel all", GTK_RESPONSE_CANCEL
181     ThreadStartStruct->iUserDialogReturnValue = GTK_RESPONSE_ACCEPT;
182 
183     //do not destroy the dialog in here! as we do need the objects for reading their values, but
184     //didnt increase the refernece pointer!
185     //gtk_widget_destroy (ThreadStartStruct->wdgtUserDialog);
186     g_cond_signal (ThreadStartStruct->gcontDialogCondition);
187 
188     TRACEIT (10, "ParseXMLUserCommand_ButtonOk       end");
189 }
190 
191 
ParseXMLUserCommand_ButtonCancel(GtkButton * button,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)192 void ParseXMLUserCommand_ButtonCancel (GtkButton *button, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
193     TRACEIT (10, "ParseXMLUserCommand_ButtonCancel       start");
194 
195     if (ThreadStartStruct == NULL){
196         TRACEIT (2, "ParseXMLUserCommand_ButtonCancel       parameter NULL");
197         return;
198     }
199     //GTK_RESPONSE_ACCEPT,"Cancel",GTK_RESPONSE_REJECT, "Cancel all", GTK_RESPONSE_CANCEL
200     ThreadStartStruct->iUserDialogReturnValue = GTK_RESPONSE_REJECT;
201 
202     //do not destroy the dialog in here! as we do need the objects for reading their values, but
203     //didnt increase the refernece pointer!
204     //gtk_widget_destroy (ThreadStartStruct->wdgtUserDialog);
205     g_cond_signal (ThreadStartStruct->gcontDialogCondition);
206 
207     TRACEIT (10, "ParseXMLUserCommand_ButtonCancel       end");
208 }
209 
210 
ParseXMLUserCommand_ButtonCancelAll(GtkButton * button,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)211 void ParseXMLUserCommand_ButtonCancelAll (GtkButton *button, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
212     TRACEIT (10, "ParseXMLUserCommand_ButtonCancel       start");
213 
214     if (ThreadStartStruct == NULL){
215         TRACEIT (2, "ParseXMLUserCommand_ButtonCancelAll       parameter NULL");
216         return;
217     }
218     //GTK_RESPONSE_ACCEPT,"Cancel",GTK_RESPONSE_REJECT, "Cancel all", GTK_RESPONSE_CANCEL
219     ThreadStartStruct->iUserDialogReturnValue = GTK_RESPONSE_CANCEL;
220 
221     //do not destroy the dialog in here! as we do need the objects for reading their values, but
222     //didnt increase the refernece pointer!
223     //gtk_widget_destroy (ThreadStartStruct->wdgtUserDialog);
224     g_cond_signal (ThreadStartStruct->gcontDialogCondition);
225 
226 
227     TRACEIT (10, "ParseXMLUserCommand_ButtonCancelAll       end");
228     return;
229 }
230 
231 
ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification(GtkWidget * widget,GdkEvent * event,void * data)232 gboolean ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification (GtkWidget *widget, GdkEvent  *event, void *data){
233     //this is the handler for delete-event, which is called only if the user!! requests the widget to be closed.
234     //but we want the user to be able to close only with our buttons
235     //but if gtk isnt able to avoid the visibility of the close button (mainly placed in the upper right corner of each window)
236     //we will end up here and then we call the cancel button.
237     TRACEIT (10, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification       start");
238     struct _CallUserCommand_StartThreadStructure *ThreadStartStruct = (struct _CallUserCommand_StartThreadStructure *)data;
239     if (ThreadStartStruct == NULL){
240         TRACEIT (2, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification       parameter NULL");
241         return TRUE;
242     }
243 
244     ParseXMLUserCommand_ButtonCancelAll (NULL, ThreadStartStruct);
245 
246 
247     TRACEIT (10, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification       end");
248     return TRUE;    //True: widget will stay
249 }
250 
251 
ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog(char * ccpCaption,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct,int iNumOfButtons)252 GtkWidget * ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog(char *ccpCaption, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, int iNumOfButtons){
253     //iNumOfButtons can be 2 or 3
254     TRACEIT (10, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog       start");
255 
256     if (ccpCaption == NULL || ThreadStartStruct == NULL){
257         TRACEIT (2, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog       parameter NULL");
258         return NULL;
259     }
260     myWrap_gdk_threads_enter("ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog 1");
261     GtkWidget 	*dialog = CreateMyWindow(ccpCaption, win, -1, -1, TRUE, TRUE, TRUE, NULL, FALSE, FALSE);
262     myWrap_gdk_threads_leave("ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog 1");
263     if (dialog == NULL){
264         return NULL;
265     }
266     GtkWidget *btnCancelAll=NULL;
267     GtkWidget *btnCancel=NULL;
268     GtkWidget *hboxButtons=NULL;
269     GtkWidget *btnOk=NULL;
270     GtkWidget *vbox=NULL;
271     GtkWidget *hbox=NULL;
272 
273     myWrap_gdk_threads_enter("ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog 2");
274 
275     hboxButtons         = gtk_hbox_new(TRUE, 0);
276     hbox                = gtk_hbox_new(TRUE, 0);
277     vbox                = gtk_vbox_new(FALSE, 3);
278     btnOk               = gtk_button_new_with_label("Ok");
279     btnCancel           = gtk_button_new_with_label("Cancel");
280     if (iNumOfButtons == 3){
281         btnCancelAll = gtk_button_new_with_label("Cancel all");
282     }
283     GtkWidget *separator    = gtk_hseparator_new();
284 
285     ThreadStartStruct->wdgtUserDialog = dialog;
286     ThreadStartStruct->wdgtUSerDialogMainVBox = vbox;
287     ThreadStartStruct->iUserDialogReturnValue = GTK_RESPONSE_NONE;
288 
289     gtk_box_pack_start ((GtkBox *)hboxButtons, btnOk, TRUE, TRUE, 3);
290     if (iNumOfButtons == 3){
291         gtk_box_pack_start ((GtkBox *)hboxButtons, btnCancelAll, TRUE, TRUE, 3);
292         //gtk_container_add ((GtkContainer *)hbox, btnCancelAll);
293     }
294     gtk_box_pack_start ((GtkBox *)hboxButtons, btnCancel, TRUE, TRUE, 3);
295 
296     gtk_box_pack_end ((GtkBox *)vbox, hboxButtons, FALSE, FALSE, 5);
297     gtk_box_pack_end ((GtkBox *)vbox, separator, FALSE, FALSE, 0);
298 
299     gtk_box_pack_start((GtkBox *)hbox, vbox, TRUE, TRUE, 6);
300 
301     gtk_container_add ((GtkContainer *)dialog, hbox);
302 
303     g_signal_connect (dialog,"key-press-event",G_CALLBACK(ParseXMLUserComman_ESCButtonHandlerForUserDialog),ThreadStartStruct);
304     //g_signal_connect (dialog,"destroy",G_CALLBACK(ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DestroyNotification),(void *)ThreadStartStruct);
305     g_signal_connect (dialog,"delete-event",G_CALLBACK(ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog_DeleteNotification), (void *)ThreadStartStruct);
306 
307     g_signal_connect (btnOk,"clicked",G_CALLBACK(ParseXMLUserCommand_ButtonOk), (void *)ThreadStartStruct);
308     g_signal_connect (btnCancel,"clicked",G_CALLBACK(ParseXMLUserCommand_ButtonCancel), (void *)ThreadStartStruct);
309     if (iNumOfButtons == 3){
310         g_signal_connect (btnCancelAll,"clicked",G_CALLBACK(ParseXMLUserCommand_ButtonCancelAll), (void *)ThreadStartStruct);
311     }
312 
313     myWrap_gdk_threads_leave("ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog 2");
314 
315     TRACEIT (10, "ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog       end");
316     return dialog;
317 }
318 
319 
ParseXMLUserComman_ESCButtonHandlerForUserDialog(GtkWidget * widget,GdkEventKey * event,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)320 gboolean ParseXMLUserComman_ESCButtonHandlerForUserDialog(GtkWidget *widget, GdkEventKey *event, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
321 	TRACEIT(10,"ParseXMLUserComman_ESCButtonHandlerForUserDialog		start");
322 	if (ThreadStartStruct == NULL){
323         TRACEIT (2, "ParseXMLUserComman_ESCButtonHandlerForUserDialog       Parameter NULL");
324         return FALSE;
325     }
326 	guint modifiers;
327 
328 	modifiers = gtk_accelerator_get_default_mod_mask ();
329 
330     if ( (event->keyval == GDK_Escape)){
331         ParseXMLUserCommand_ButtonCancel (NULL, ThreadStartStruct);
332 
333 		TRACEIT(10,"ParseXMLUserComman_ESCButtonHandlerForUserDialog		ends");
334 		return TRUE;
335 	}
336 
337 	TRACEIT(10,"ParseXMLUserComman_ESCButtonHandlerForUserDialog		end");
338 	return FALSE;
339 }
340 
341 
ParseXMLUserCommand_ShowDialogThread(struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)342 void ParseXMLUserCommand_ShowDialogThread(struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
343     //simply will show the dialog given as parameter and locks the mutes also given as parameter
344     //this thread will exit after the widged was created and thats it.
345     TRACEIT (10, "ParseXMLUserCommand_ShowDialogThread       start");
346     if (ThreadStartStruct == NULL){
347         TRACEIT (2, "ParseXMLUserCommand_ShowDialogThread       Parameter NULL");
348         return;
349     }
350     if (ThreadStartStruct->wdgtUserDialog == NULL || ThreadStartStruct->gcontDialogCondition == NULL){
351         TRACEIT (2, "ParseXMLUserCommand_ShowDialogThread       Parameter  2 NULL");
352         return;
353     }
354 
355     myWrap_gdk_threads_enter("ParseXMLUserCommand_ShowDialogThread 1");
356     gtk_widget_show_all (ThreadStartStruct->wdgtUserDialog);
357     myWrap_gdk_threads_leave("ParseXMLUserCommand_ShowDialogThread 1");
358 
359     TRACEIT (10, "ParseXMLUserCommand_ShowDialogThread       end");
360     //g_thread_exit (0); //this is no thread
361     return;
362 }
363 
364 
ParseXMLUserCommand_EntryBoxActivate(GtkEntry * entry,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct)365 void ParseXMLUserCommand_EntryBoxActivate(GtkEntry *entry, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct){
366     TRACEIT (10, "ParseXMLUserCommand_EntryBoxActivate       start");
367     if (ThreadStartStruct == NULL){
368         TRACEIT (2, "ParseXMLUserCommand_EntryBoxActivate      parameter NULL");
369         return;
370     }
371 
372     ParseXMLUserCommand_ButtonOk (NULL, ThreadStartStruct);
373     TRACEIT (10, "ParseXMLUserCommand_EntryBoxActivate       end");
374 }
375 
376 
ParseXMLUserCommand_ParseDialog(struct _CallUserCommand_StartThreadStructure * ThreadStartStruct,struct _predefineStruct * predefineStruct,gboolean * bShowCommand)377 int ParseXMLUserCommand_ParseDialog(struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, struct _predefineStruct *predefineStruct, gboolean *bShowCommand){
378     TRACEIT (10, "ParseXMLUserCommand_ParseDialog       start");
379     //function which creates the dailog and saves the users answers
380     //return: -1=error, 0=ok, 1=cancel this command, 2=cancel all commands (TODO)
381     if (ThreadStartStruct == NULL || predefineStruct == NULL){
382         TRACEIT (2, "ParseXMLUserCommand_ParseDialog            parameter NULL");
383         return -1;
384     }
385     struct _UserCommandList *UserCommandList = (struct _UserCommandList*)(ThreadStartStruct->OurUserDataListItem->ListElement);
386     if (UserCommandList == NULL){
387         TRACEIT (2, "ParseXMLUserCommand_ParseDialog            parameter 2 NULL");
388         return -1;
389     }
390 
391     struct _DialogEntityList *DailogEntityList_BufList = NULL;
392     struct _DialogEntityList *DailogEntityList = UserCommandList->DialogEntityList;
393     //if (DailogEntityList == NULL){
394     //    TRACEIT (2, "ParseXMLUserCommand_ParseDialog            parameter 3 NULL");
395     //    return -1;
396     //}
397 
398     int iRet = 0;
399     int iNumOfButtons = 3;
400 
401     GString *gstrBuf = g_string_sized_new(10);
402 	GtkWidget *label;
403 	GtkWidget* CheckButton;
404 	GtkWidget *sep1;
405 	GString *gstrVarIdentifier = g_string_sized_new(10);
406 	GString *gstrVarValue = g_string_sized_new(10);
407 	GString *gstrLabel = g_string_sized_new(10);
408 	GString *gstrPredefine = g_string_sized_new(10);
409 	GString *gstrAdditional1 = g_string_sized_new(10);
410 	GString *gstrAdditional2 = g_string_sized_new(10);
411 	GtkWidget *MainVBox = NULL;
412 	GtkWidget *VBoxBuf = NULL;
413 
414     if (UserCommandList->gstrDialogCaption == NULL){
415         UserCommandList->gstrDialogCaption = g_string_new("CEE");
416     }
417 
418     if (UserCommandList->option_iCallType == USERCOMMAND_CALLTYPE_ALL){
419         iNumOfButtons = 2;
420     }
421     ParseXMLUserCommand_CreateWidgetPrototypeForUserDialog(UserCommandList->gstrDialogCaption->str, ThreadStartStruct, iNumOfButtons);
422 
423     myWrap_gdk_threads_enter("ParseXMLUserCommand_ParseDialog 1");
424 
425     MainVBox = ThreadStartStruct->wdgtUSerDialogMainVBox;
426 
427 	if (UserCommandList->gstrDialogLabel){
428         processAsTextWithoutUserVars (gstrBuf, UserCommandList->gstrDialogLabel, predefineStruct, FALSE);
429 		label = gtk_label_new(gstrBuf->str);
430 		VBoxBuf = gtk_vbox_new (FALSE, 1);
431 		gtk_box_pack_start ((GtkBox *)VBoxBuf, label, FALSE, FALSE, 0);
432 		gtk_box_pack_start ((GtkBox *)MainVBox, VBoxBuf, FALSE, FALSE, 5);
433 	}
434 
435 	DailogEntityList_BufList = DailogEntityList;
436 	while (DailogEntityList_BufList){
437 	    if (DailogEntityList_BufList->iValid != 1){
438             DailogEntityList_BufList = DailogEntityList_BufList->nextItem;
439             continue;
440 	    }
441 	    g_string_erase (gstrVarIdentifier, 0, -1);
442 	    g_string_erase (gstrVarValue, 0, -1);
443 	    g_string_erase (gstrLabel, 0, -1);
444 	    g_string_erase (gstrPredefine, 0, -1);
445 	    g_string_erase (gstrAdditional1, 0, -1);
446 	    g_string_erase (gstrAdditional2, 0, -1);
447 
448 	    if (DailogEntityList_BufList->gstrVarIdentifier){
449             processAsTextWithoutUserVars (gstrVarIdentifier, DailogEntityList_BufList->gstrVarIdentifier, predefineStruct, FALSE);
450 	    }
451 	    if (DailogEntityList_BufList->gstrVarValue){
452             processAsTextWithoutUserVars (gstrVarValue, DailogEntityList_BufList->gstrVarValue, predefineStruct, FALSE);
453 	    }
454 	    if (DailogEntityList_BufList->gstrLabel){
455             processAsTextWithoutUserVars (gstrLabel, DailogEntityList_BufList->gstrLabel, predefineStruct, FALSE);
456 	    }
457 	    if (DailogEntityList_BufList->gstrPredefine){
458             processAsTextWithoutUserVars (gstrPredefine, DailogEntityList_BufList->gstrPredefine, predefineStruct, FALSE);
459 	    }
460 	    if (DailogEntityList_BufList->gstrAdditional1){
461             processAsTextWithoutUserVars (gstrAdditional1, DailogEntityList_BufList->gstrAdditional1, predefineStruct, FALSE);
462 	    }
463 	    if (DailogEntityList_BufList->gstrAdditional2){
464             processAsTextWithoutUserVars (gstrAdditional2, DailogEntityList_BufList->gstrAdditional2, predefineStruct, FALSE);
465 	    }
466 
467 		if (DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_QUESTION){
468             DailogEntityList_BufList->wdgtLabel =  gtk_label_new(gstrLabel->str);
469             gtk_misc_set_alignment ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 0.0f, 0.0f);
470             //gtk_misc_set_padding ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 4, 0);
471             DailogEntityList_BufList->wdgtEntryBox = gtk_entry_new();
472             if (DailogEntityList_BufList->gstrPredefine){
473                 gtk_entry_set_text(	(GtkEntry *)DailogEntityList_BufList->wdgtEntryBox, gstrPredefine->str);
474             }
475             g_signal_connect ((GtkEntry *)DailogEntityList_BufList->wdgtEntryBox, "activate",G_CALLBACK(ParseXMLUserCommand_EntryBoxActivate),ThreadStartStruct);
476 
477             VBoxBuf = gtk_vbox_new (FALSE, 1);
478             gtk_box_pack_start ((GtkBox *)VBoxBuf, DailogEntityList_BufList->wdgtLabel, FALSE, FALSE, 0);
479             gtk_box_pack_start ((GtkBox *)VBoxBuf, DailogEntityList_BufList->wdgtEntryBox, FALSE, FALSE, 0);
480             gtk_box_pack_start ((GtkBox *)MainVBox, VBoxBuf, FALSE, FALSE, 2);
481 		}
482 		else if (DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
483             DailogEntityList_BufList->wdgtLabel = gtk_check_button_new_with_mnemonic(gstrLabel->str);
484             //VBoxBuf = gtk_vbox_new (FALSE, 1);
485             gtk_box_pack_start ((GtkBox *)MainVBox, DailogEntityList_BufList->wdgtLabel, FALSE, FALSE, 0);
486             if (DailogEntityList_BufList->gstrPredefine){
487                 if (strcmp(DailogEntityList_BufList->gstrPredefine->str, "true")==0 || strcmp(gstrPredefine->str, "TRUE")==0 || strcmp(DailogEntityList_BufList->gstrPredefine->str, "True")==0 ){
488                     gtk_toggle_button_set_active ( (GtkToggleButton *)DailogEntityList_BufList->wdgtLabel, TRUE);
489                 }
490             }
491 		}
492 		else if (DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_TEXT){	//0=question, 1=checkbox, 2=text
493 		    //g_string_assign (gstrBuf, DailogEntityList_BufList->gstrLabel->str);
494 	        DailogEntityList_BufList->wdgtLabel = gtk_label_new (gstrLabel->str);
495             //DailogEntityList_BufList->wdgtLabel = gtk_label_new ("testttt");
496             gtk_misc_set_alignment ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 0.0f, 0.0f);
497             //gtk_misc_set_padding ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 4, 0);
498             gtk_box_pack_start ((GtkBox *)MainVBox, DailogEntityList_BufList->wdgtLabel, FALSE, FALSE, 2);
499 		}
500 		else if (DailogEntityList_BufList->iType==USERDIALOG_ENTITY_TYPE_FILECHOOSER || DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER){ //0=question, 1=checkbox, 2=text, 3=filechooser, 4=dirchooser
501             DailogEntityList_BufList->wdgtLabel =  gtk_label_new(gstrLabel->str);
502             gtk_misc_set_alignment ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 0.0f, 0.0f);
503             //gtk_misc_set_padding ( (GtkMisc *)DailogEntityList_BufList->wdgtLabel, 4, 0);
504             DailogEntityList_BufList->wdgtEntryBox = gtk_entry_new();
505             if (DailogEntityList_BufList->gstrPredefine){
506                 gtk_entry_set_text(	(GtkEntry *)DailogEntityList_BufList->wdgtEntryBox, gstrPredefine->str);
507             }
508             g_signal_connect ((GtkEntry *)DailogEntityList_BufList->wdgtEntryBox, "activate",G_CALLBACK(ParseXMLUserCommand_EntryBoxActivate),ThreadStartStruct);
509 
510             DailogEntityList_BufList->wdgtAdditional2 = gtk_hbox_new (FALSE, 0);
511             DailogEntityList_BufList->wdgtAdditional1 = gtk_button_new_with_label (gstrAdditional1->str);
512 
513             g_signal_connect ((GtkButton *)DailogEntityList_BufList->wdgtAdditional1, "clicked",G_CALLBACK(UserDialog_FileDirChooserButton),DailogEntityList_BufList);
514 
515             VBoxBuf = gtk_vbox_new (FALSE, 1);
516             gtk_box_pack_start ((GtkBox *)DailogEntityList_BufList->wdgtAdditional2, DailogEntityList_BufList->wdgtEntryBox, TRUE, TRUE, 0);
517             gtk_box_pack_start ((GtkBox *)DailogEntityList_BufList->wdgtAdditional2, DailogEntityList_BufList->wdgtAdditional1, FALSE, FALSE, 3);
518             gtk_box_pack_start ((GtkBox *)VBoxBuf, DailogEntityList_BufList->wdgtLabel, FALSE, FALSE, 0);
519             gtk_box_pack_start ((GtkBox *)VBoxBuf, DailogEntityList_BufList->wdgtAdditional2, FALSE, FALSE, 0);
520             gtk_box_pack_start ((GtkBox *)MainVBox, VBoxBuf, FALSE, FALSE, 2);
521   		}
522   		else if (DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_SEPARATOR){	//0=question, 1=checkbox, 2=text
523 	        DailogEntityList_BufList->wdgtLabel = gtk_separator_menu_item_new ();
524             gtk_box_pack_start ((GtkBox *)MainVBox, DailogEntityList_BufList->wdgtLabel, FALSE, FALSE, 0);
525 		}
526 		DailogEntityList_BufList = DailogEntityList_BufList->nextItem;
527 	}
528 
529     sep1 = gtk_separator_menu_item_new ();
530     gtk_box_pack_start ((GtkBox *)MainVBox, sep1, FALSE, FALSE, 0);
531 
532 	CheckButton = gtk_check_button_new_with_label("Show me the complete command");
533 	gtk_box_pack_start ((GtkBox *)MainVBox, CheckButton, FALSE, FALSE, 0);
534 
535     myWrap_gdk_threads_leave("ParseXMLUserCommand_ParseDialog 1");
536 
537     int iDRet = 0;
538     GMutex *mutex = g_mutex_new ();
539     ThreadStartStruct->gcontDialogCondition = g_cond_new ();
540     g_mutex_lock (mutex);
541 
542     ParseXMLUserCommand_ShowDialogThread ((void *)ThreadStartStruct);
543 
544     g_cond_wait (ThreadStartStruct->gcontDialogCondition, mutex);
545     g_mutex_unlock (mutex);
546 
547     g_mutex_free (mutex);
548     mutex = NULL;
549     g_cond_free (ThreadStartStruct->gcontDialogCondition);
550     ThreadStartStruct->gcontDialogCondition = NULL;
551     ThreadStartStruct->gcontEachCondition = NULL;
552 
553     iDRet = ThreadStartStruct->iUserDialogReturnValue;
554 
555     myWrap_gdk_threads_enter("ParseXMLUserCommand_ParseDialog 2");
556 
557 	if (iDRet== GTK_RESPONSE_ACCEPT){
558 		DailogEntityList_BufList = DailogEntityList;
559 		while (DailogEntityList_BufList){
560 		   	if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_QUESTION){
561 				DailogEntityList_BufList->gstrVarValue = g_string_new( gtk_entry_get_text((GtkEntry *)DailogEntityList_BufList->wdgtEntryBox ) );
562 			}
563 			else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
564 				if (gtk_toggle_button_get_active ( (GtkToggleButton *)DailogEntityList_BufList->wdgtLabel)){	//checkbox checked
565 					DailogEntityList_BufList->gstrVarValue = g_string_new((DailogEntityList_BufList->gstrAdditional1!=NULL)?DailogEntityList_BufList->gstrAdditional1->str:"");
566 				}
567 				else if (DailogEntityList_BufList->gstrAdditional2){
568 					DailogEntityList_BufList->gstrVarValue = g_string_new((DailogEntityList_BufList->gstrAdditional2!=NULL)?DailogEntityList_BufList->gstrAdditional2->str:"");
569 				}
570 			}
571 			else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER){
572 				DailogEntityList_BufList->gstrVarValue = g_string_new( gtk_entry_get_text((GtkEntry *)DailogEntityList_BufList->wdgtEntryBox ) );
573 			}
574 			else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER){
575 				DailogEntityList_BufList->gstrVarValue = g_string_new( gtk_entry_get_text((GtkEntry *)DailogEntityList_BufList->wdgtEntryBox ) );
576 			}
577 			DailogEntityList_BufList = DailogEntityList_BufList->nextItem;
578 		}
579 		if (gtk_toggle_button_get_active ( (GtkToggleButton *)CheckButton)){
580 			*bShowCommand = TRUE;
581 		}
582 		else{
583 			*bShowCommand = FALSE;
584 		}
585 
586 		iRet = 0;
587 	}
588 	else if (iDRet == GTK_RESPONSE_CANCEL){
589         iRet = 2;
590         ThreadStartStruct->iCancelAll = 2;
591     }
592     else{ //if (iDRet == GTK_RESPONSE_REJECT){  //fallback
593 		iRet = 1; //cancel this command
594 	}
595 
596     //we have to forget this things, because the list-free fnction would try to unref them
597 	DailogEntityList_BufList = DailogEntityList;
598     while (DailogEntityList_BufList){
599         if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_QUESTION){
600             DailogEntityList_BufList->wdgtLabel = NULL;
601             DailogEntityList_BufList->wdgtEntryBox = NULL;
602         }
603         else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_CHECKBOX){
604             DailogEntityList_BufList->wdgtLabel = NULL;
605         }
606         else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_TEXT){
607             DailogEntityList_BufList->wdgtLabel = NULL;
608         }
609         else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_FILECHOOSER){
610             DailogEntityList_BufList->wdgtLabel = NULL;
611             DailogEntityList_BufList->wdgtEntryBox = NULL;
612             DailogEntityList_BufList->wdgtAdditional1 = NULL;
613             DailogEntityList_BufList->wdgtAdditional2 = NULL;
614         }
615         else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_DIRCHOOSER){
616             DailogEntityList_BufList->wdgtLabel = NULL;
617             DailogEntityList_BufList->wdgtEntryBox = NULL;
618             DailogEntityList_BufList->wdgtAdditional1 = NULL;
619             DailogEntityList_BufList->wdgtAdditional2 = NULL;
620         }
621         else if (DailogEntityList_BufList->iValid == 1 && DailogEntityList_BufList->iType == USERDIALOG_ENTITY_TYPE_SEPARATOR){
622             DailogEntityList_BufList->wdgtLabel = NULL;
623         }
624         DailogEntityList_BufList = DailogEntityList_BufList->nextItem;
625     }
626 
627     gtk_widget_destroy (ThreadStartStruct->wdgtUserDialog);
628 	myWrap_gdk_threads_leave("ParseXMLUserCommand_ParseDialog 2");
629 
630 	g_string_free(gstrBuf, TRUE);
631 	g_string_free(gstrVarIdentifier, TRUE);
632 	g_string_free(gstrVarValue, TRUE);
633 	g_string_free(gstrLabel, TRUE);
634 	g_string_free(gstrPredefine, TRUE);
635 	g_string_free(gstrAdditional1, TRUE);
636 	g_string_free(gstrAdditional2, TRUE);
637 
638     TRACEIT (10, "ParseXMLUserCommand_ParseDialog       end");
639     return iRet;
640 }
641 
642 
ParseXMLUserCommand_FreePredefineStruct(struct _predefineStruct * predefineStruct)643 int ParseXMLUserCommand_FreePredefineStruct (struct _predefineStruct *predefineStruct){
644     TRACEIT (10, "ParseXMLUserCommand_FreePredefineStruct       start");
645     if (predefineStruct == NULL){
646         TRACEIT (2, "ParseXMLUserCommand_FreePredefineStruct        parameter NULL");
647         return -1;
648     }
649 
650     if (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted){
651         g_string_free (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted, TRUE);
652         predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted = NULL;
653     }
654     if (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted){
655         g_string_free (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted, TRUE);
656         predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted = NULL;
657     }
658     if (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted){
659         g_string_free (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted, TRUE);
660         predefineStruct->gstrAllMarkedItems_WithPath_Unquoted = NULL;
661     }
662     if (predefineStruct->gstrAllMarkedItems_WithPath_Quoted){
663         g_string_free (predefineStruct->gstrAllMarkedItems_WithPath_Quoted, TRUE);
664         predefineStruct->gstrAllMarkedItems_WithPath_Quoted = NULL;
665     }
666     if (predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted){
667         g_string_free (predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted, TRUE);
668         predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted = NULL;
669     }
670     if (predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted){
671         g_string_free (predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted, TRUE);
672         predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted = NULL;
673     }
674     if (predefineStruct->gstrOneMarkedItem_WithPath_Unquoted){
675         g_string_free (predefineStruct->gstrOneMarkedItem_WithPath_Unquoted, TRUE);
676         predefineStruct->gstrOneMarkedItem_WithPath_Unquoted = NULL;
677     }
678     if (predefineStruct->gstrOneMarkedItem_WithPath_Quoted){
679         g_string_free (predefineStruct->gstrOneMarkedItem_WithPath_Quoted, TRUE);
680         predefineStruct->gstrOneMarkedItem_WithPath_Quoted = NULL;
681     }
682 
683     TRACEIT (10, "ParseXMLUserCommand_FreePredefineStruct       end");
684     return 0;
685 }
686 
687 
ParseXMLUserCommand_FillPredefineStruct(struct _predefineStruct * predefineStruct,struct _CallUserCommand_StartThreadStructure * ThreadStartStruct,GString * gstrWorkingPath)688 int ParseXMLUserCommand_FillPredefineStruct (struct _predefineStruct *predefineStruct, struct _CallUserCommand_StartThreadStructure *ThreadStartStruct, GString *gstrWorkingPath ){
689     TRACEIT (10, "ParseXMLUserCommand_FillPredefineStruct       start");
690     //fills the struct _predefineStruct with the values from ThreadStartStruct
691     //keep in mind that some GStrings will not be copied but only their pointer!
692     //so, we dont need to free them in here
693     //return: 0=ok, -1=error
694 
695     if (predefineStruct==NULL || ThreadStartStruct==NULL || gstrWorkingPath==NULL){
696         TRACEIT (2, "ParseXMLUserCommand_FillPredefineStruct        parameter NULL");
697         return -1;
698     }
699 
700     GList *glistBuf =  NULL;
701     int iBuf;
702 
703     predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted    = NULL;
704     predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted      = NULL;
705     predefineStruct->gstrAllMarkedItems_WithPath_Unquoted       = NULL;
706     predefineStruct->gstrAllMarkedItems_WithPath_Quoted         = NULL;
707     predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted     = NULL;
708     predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted       = NULL;
709     predefineStruct->gstrOneMarkedItem_WithPath_Unquoted        = NULL;
710     predefineStruct->gstrOneMarkedItem_WithPath_Quoted          = NULL;
711 
712 
713     predefineStruct->gstrThisSidePath   = ThreadStartStruct->gstrThisSidePath;
714     predefineStruct->gstrOtherSidePath  = ThreadStartStruct->gstrOtherSidePath;
715     predefineStruct->gstrLeftSidePath   = ThreadStartStruct->gstrLeftSidePath;
716     predefineStruct->gstrRightSidePath  = ThreadStartStruct->gstrRightSidePath;
717     predefineStruct->gstrHomeDir        = ThreadStartStruct->gstrHomeDir;
718     //predefineStruct->gstrWorkingPath    = gstrWorkingPath;
719 
720     //if we come from FileShelf gstrThisSidePath and gstrOtherSidePath are NULL
721     if (ThreadStartStruct->OurUserDataListItem->iSourceType == SOURCE_FILESHELF){
722         if (predefineStruct->gstrThisSidePath == NULL){
723             predefineStruct->gstrThisSidePath = g_string_new(gstrWorkingPath->str);
724             ThreadStartStruct->gstrThisSidePath = predefineStruct->gstrThisSidePath; //write this back to let others free �t
725         }
726         if (predefineStruct->gstrOtherSidePath == NULL){
727             predefineStruct->gstrOtherSidePath = g_string_new(ThreadStartStruct->gstrLeftSidePath->str);
728             ThreadStartStruct->gstrOtherSidePath = predefineStruct->gstrOtherSidePath; //write this back to let others free �t
729         }
730     }
731 
732     if (ThreadStartStruct->glistItemsWithPath != NULL)
733         glistBuf = g_list_first (ThreadStartStruct->glistItemsWithPath);
734     else
735         glistBuf = NULL;
736     predefineStruct->gstrAllMarkedItems_WithPath_Unquoted   = g_string_new("");
737     predefineStruct->gstrAllMarkedItems_WithPath_Quoted     = g_string_new("");
738     iBuf = 0;
739     while (glistBuf){
740         g_string_append_c (predefineStruct->gstrAllMarkedItems_WithPath_Quoted, '\"');
741         g_string_append   (predefineStruct->gstrAllMarkedItems_WithPath_Quoted, ((GString *)(glistBuf->data))->str);
742         g_string_append   (predefineStruct->gstrAllMarkedItems_WithPath_Quoted, "\" ");
743 
744         g_string_append   (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted, ((GString *)(glistBuf->data))->str);
745         g_string_append_c (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted, ' ');
746 
747         iBuf = 1;
748 
749         glistBuf = glistBuf->next;
750     }
751     if (iBuf == 1){
752         g_string_erase (predefineStruct->gstrAllMarkedItems_WithPath_Quoted, strlen (predefineStruct->gstrAllMarkedItems_WithPath_Quoted->str)-1, -1);
753         g_string_erase (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted, strlen (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted->str)-1, -1);
754     }
755     if (ThreadStartStruct->glistItemsWithPath != NULL)
756         glistBuf = g_list_first (ThreadStartStruct->glistItemsWithoutPath);
757     else
758         glistBuf = NULL;
759     predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted   = g_string_new("");
760     predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted     = g_string_new("");
761     iBuf = 0;
762     while (glistBuf){
763         g_string_append_c (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted, '\"');
764         g_string_append   (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted, ((GString *)(glistBuf->data))->str);
765         g_string_append   (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted, "\" ");
766 
767         g_string_append   (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted, ((GString *)(glistBuf->data))->str);
768         g_string_append_c (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted, ' ');
769 
770         iBuf = 1;
771 
772         glistBuf = glistBuf->next;
773     }
774     if (iBuf == 1){
775         g_string_erase (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted, strlen (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted->str)-1, -1);
776         g_string_erase (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted, strlen (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted->str)-1, -1);
777     }
778     //if the calltype is "all", the predefine variables for MarkedItem (not MarkedItems) have to the same as for MarkedItems
779     if (((struct _UserCommandList  *)(ThreadStartStruct->OurUserDataListItem->ListElement))->option_iCallType == USERCOMMAND_CALLTYPE_ALL && ThreadStartStruct->glistItemsWithoutPath!=NULL && ThreadStartStruct->glistItemsWithPath!=NULL){
780         predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted = g_string_new (predefineStruct->gstrAllMarkedItems_WithoutPath_Unquoted->str);
781         predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted = g_string_new (predefineStruct->gstrAllMarkedItems_WithoutPath_Quoted->str);
782         predefineStruct->gstrOneMarkedItem_WithPath_Unquoted = g_string_new (predefineStruct->gstrAllMarkedItems_WithPath_Unquoted->str);
783         predefineStruct->gstrOneMarkedItem_WithPath_Quoted = g_string_new (predefineStruct->gstrAllMarkedItems_WithPath_Quoted->str);
784     }
785     else{
786         if (ThreadStartStruct->glistItemsWithoutPath)
787             glistBuf = g_list_nth(ThreadStartStruct->glistItemsWithoutPath, ThreadStartStruct->uiCurrentPositionInList);
788         else
789             glistBuf = NULL;
790         if (glistBuf){
791             predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted = g_string_new (((GString *)(glistBuf->data))->str);
792             predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted = g_string_new (((GString *)(glistBuf->data))->str);
793             g_string_prepend (predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted, "\"");
794             g_string_append (predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted, "\"");
795         }
796         else{
797             predefineStruct->gstrOneMarkedItem_WithoutPath_Unquoted = g_string_new("");
798             predefineStruct->gstrOneMarkedItem_WithoutPath_Quoted = g_string_new("");
799         }
800 
801         if (ThreadStartStruct->glistItemsWithPath)
802             glistBuf = g_list_nth(ThreadStartStruct->glistItemsWithPath, ThreadStartStruct->uiCurrentPositionInList);
803         else
804             glistBuf = NULL;
805         if (glistBuf){
806             predefineStruct->gstrOneMarkedItem_WithPath_Unquoted = g_string_new (((GString *)(glistBuf->data))->str);
807             predefineStruct->gstrOneMarkedItem_WithPath_Quoted = g_string_new (((GString *)(glistBuf->data))->str);
808             g_string_prepend (predefineStruct->gstrOneMarkedItem_WithPath_Quoted, "\"");
809             g_string_append (predefineStruct->gstrOneMarkedItem_WithPath_Quoted, "\"");
810         }
811         else{
812             predefineStruct->gstrOneMarkedItem_WithPath_Unquoted = g_string_new ("");
813             predefineStruct->gstrOneMarkedItem_WithPath_Quoted = g_string_new("");
814         }
815     }
816 
817     TRACEIT (10, "ParseXMLUserCommand_FillPredefineStruct       end");
818     return 0;
819 }
820 
821 
processMyStandardEscapeSequences(GString * gstrToChange)822 int processMyStandardEscapeSequences(GString *gstrToChange){
823     TRACEIT (10, "processMyStandardEscapeSequences       start");
824 
825     if (gstrToChange == NULL){
826         TRACEIT (2, "processMyStandardEscapeSequences       parameter NULL");
827         return -1;
828     }
829     GString *gg = g_string_new("\\n");
830     GString *tt = g_string_new("\n");
831     exchangeNameWithValue(gstrToChange,gg,tt);
832 
833     g_string_assign(gg,"\\t");
834     g_string_assign(tt,"\t");
835     exchangeNameWithValue(gstrToChange,gg,tt);
836 
837     g_string_assign(gg,"\\\"");
838     g_string_assign(tt,"\"");
839     exchangeNameWithValue(gstrToChange,gg,tt);
840 
841     g_string_free(gg,TRUE);
842     g_string_free(tt,TRUE);
843 
844     TRACEIT (10, "processMyStandardEscapeSequences       end");
845     return 0;
846 }
847 
848 
processAsTextWithoutUserVars(GString * gstrDestination,GString * gstrSource,struct _predefineStruct * predefStruct,gboolean bMakeThreadSave)849 int processAsTextWithoutUserVars (GString *gstrDestination, GString *gstrSource, struct _predefineStruct *predefStruct, gboolean bMakeThreadSave){
850     TRACEIT (10, "processAsTextWithoutUserVars       start");
851     //gstrSource is copied to gstrDestination
852     //after that, the string in gstrDestination is checked for predefines, Backspaces and esacapeSequences
853     //NO USERVARS
854 
855     if (gstrDestination == NULL || gstrSource == NULL){
856         TRACEIT (2, "processAsTextWithoutUserVars       parameter NULL");
857         return -1;
858     }
859 
860     g_string_assign (gstrDestination, gstrSource->str);
861     processMyStandardEscapeSequences (gstrDestination);
862     exchangePredefine(gstrDestination, predefStruct);
863     processBackSpaces (gstrDestination, bMakeThreadSave);
864 
865     TRACEIT (10, "processAsTextWithoutUserVars       end");
866     return 0;
867 }
868 
869 
exchangePredefine(GString * gstrText,struct _predefineStruct * predefStruct)870 int exchangePredefine(GString *gstrText, struct _predefineStruct *predefStruct){
871 	TRACEIT(10,"exchangePredefine		start");
872 	if (gstrText == NULL || predefStruct == NULL){
873         TRACEIT (2, "exchangePredefine      parameter NULL");
874         return -1;
875 	}
876 
877 	char *KnownPredefines[] = KNOWNPREDEFINES;
878 	int Count = NUMBEROFPREDEFINES;
879 	int i;
880 
881 	GString *gstrBuf = g_string_sized_new(20);
882 	GString *gstrBuf2 = g_string_sized_new(20);
883 
884 	for (i=0;i<Count;i++){
885 		g_string_assign(gstrBuf,KnownPredefines[i]);
886 		g_string_assign(gstrBuf2,KnownPredefines[i]);
887 		g_string_append_c(gstrBuf2,')');
888 		g_string_prepend (gstrBuf2, "$(");
889 		decryptPredefine(gstrBuf, predefStruct);
890 		exchangeNameWithValue(gstrText, gstrBuf2, gstrBuf);
891 	}
892 	g_string_free(gstrBuf2,TRUE);
893 	g_string_free(gstrBuf,TRUE);
894 
895 	//if (ret == -Count){	//not one Predefine was found
896 	//	TRACEIT(10,"exchangePredefine		end");
897 	//	return -1;
898 	//}
899 	TRACEIT(10,"exchangePredefine		end");
900 	return 0;
901 }
902 
903 
exchangeUserVarsInText(GString * gstrText,struct _DialogEntityList * DialogEntityList)904 int exchangeUserVarsInText(GString *gstrText, struct _DialogEntityList *DialogEntityList){
905     TRACEIT(10,"exchangeUserVarsInText		start");
906     if (gstrText == NULL ){
907         TRACEIT(2,"exchangeUserVarsInText		end, text = NULL");
908         return -1;
909     }
910     if (DialogEntityList == NULL){
911         TRACEIT(10,"exchangeUserVarsInText		end");
912         return -1;
913     }
914     int ret=0;
915     //struct userDialogEntitiesList *bufList = inputList;
916     struct _DialogEntityList *bufList =  DialogEntityList;
917     GString *gstrBuf = g_string_sized_new(10);
918     GString *gstrEmpty = g_string_new("");
919     while (bufList){
920         if (bufList->iValid == 1 &&
921                 (   bufList->iType==USERDIALOG_ENTITY_TYPE_QUESTION ||
922                     bufList->iType==USERDIALOG_ENTITY_TYPE_CHECKBOX ||
923                     bufList->iType==USERDIALOG_ENTITY_TYPE_FILECHOOSER ||
924                     bufList->iType==USERDIALOG_ENTITY_TYPE_DIRCHOOSER )){
925             g_string_assign(gstrBuf, bufList->gstrVarIdentifier->str);
926             g_string_append_c(gstrBuf,')');
927             //g_string_prepend_c(gstrBuf,'<');
928             g_string_prepend(gstrBuf,"$(");
929             if (bufList->gstrVarValue == NULL){    //we exchange the varlabel with an empty string (means we just delete the varlable in the command string)
930                 ret += exchangeNameWithValue(gstrText, gstrBuf, gstrEmpty);
931             }
932             else{
933                 ret += exchangeNameWithValue(gstrText, gstrBuf, bufList->gstrVarValue);
934             }
935         }
936         //else if (bufList->iValid == 0){
937         //    ret = -1;    //some error
938         //}
939 
940         bufList=bufList->nextItem;
941     }
942     g_string_free(gstrBuf, TRUE);
943     g_string_free(gstrEmpty, TRUE);
944     TRACEIT(10,"exchangeUserVarsInText		end");
945     return ret;
946 }
947 
948 
processBackSpaces(GString * gstrStartText,gboolean bMakeThreadSave)949 int processBackSpaces(GString *gstrStartText, gboolean bMakeThreadSave){
950     // Replaces all \\b and delets the leading character
951     // returns -1 when the text ends up in an empty string and leave the gstrText untouched
952     // returns 0 if nothing was done
953     // returns 1 when the string was processed
954     TRACEIT(10,"processBackSpaces		start");
955     if (gstrStartText==NULL){
956         TRACEIT(2,"processBackSpaces		end gstrText=NULL, SHOULD NOT HAPPEN");
957         return -2;
958     }
959     GString *gstrTextBuf = g_string_new(gstrStartText->str);
960     GString *gstrbuf = g_string_sized_new(10);
961 
962     char Enemy[]="\\b";
963     char *cStart;
964 	int iPosition=0;
965 	int iSize;
966 	int firstTime = 1;
967 	int diff=0;
968 	cStart = gstrTextBuf->str;
969 	do {
970 	    //printf( "gstrTextBuf: %s\n",gstrTextBuf->str);
971 		cStart = strstr(gstrTextBuf->str,Enemy);
972 		if (cStart == gstrTextBuf->str){
973             //we will not try to delete something if there is nothing in front of it
974             //cStart+=1; //+1 is possible because of our enemy
975             break;;
976 		}
977 		if (cStart == NULL && firstTime==0){
978 			break;
979 		}
980 		else if(firstTime == 1 && cStart==NULL){
981 		    TRACEIT(10,"processBackSpaces		end, no backspace");
982 		    g_string_free(gstrTextBuf, TRUE);
983             g_string_free(gstrbuf, TRUE);
984 			return 0;	//No backspace found !!!
985 		}
986 		firstTime = 0;
987 		iSize = strlen(Enemy);
988 		iPosition = 0;
989 		while( (gstrTextBuf->str)+iPosition != cStart){
990 			iPosition++;
991 		}
992 		diff=(iPosition==0)?0:1;
993 		iPosition-=diff;
994 		iSize+=diff;
995 		g_string_erase(gstrTextBuf,iPosition,iSize);
996 		//printf( "gstrTextBuf: %s\n",gstrTextBuf->str);
997 	}while (cStart != NULL);
998 
999     g_string_assign(gstrbuf, gstrTextBuf->str);
1000 	cutSpacesFromGString(gstrbuf);
1001 	if (strlen(gstrbuf->str) == 0){
1002         TRACEIT(5,"processBackSpaces		end, strlen ends up in 0");
1003         if (bMakeThreadSave)
1004             myWrap_gdk_threads_enter ("exchangeNameWithValue");
1005         MyMessageWidget (win,"UserCommandParser","Backspace error\nThe Backspaces lead to an empty string.\nCheck config file.");
1006         if (bMakeThreadSave)
1007             myWrap_gdk_threads_leave ("exchangeNameWithValue");
1008         //g_string_free(gstrTextBuf, TRUE);
1009         //g_string_free(gstrbuf, TRUE);
1010         //return -1;
1011 	}
1012     g_string_assign(gstrStartText, gstrTextBuf->str);
1013 
1014     g_string_free(gstrTextBuf, TRUE);
1015     g_string_free(gstrbuf, TRUE);
1016 	TRACEIT(10,"processBackSpaces		end");
1017 	return 0;
1018 }
1019 
1020 
UserDialog_FileDirChooserButton(GtkEntry * entry,gpointer data)1021 void UserDialog_FileDirChooserButton(GtkEntry *entry, gpointer data){
1022     //used in getUserInput, connected to the file/dirchooser button
1023     TRACEIT(10,"UserDialog_FileDirChooserButton		start");
1024     //struct userDialogEntitiesList *ListItem = (struct userDialogEntitiesList *)data;
1025     struct _DialogEntityList *listItem = (struct _DialogEntityList *)data;
1026 
1027     if (listItem == NULL){
1028         TRACEIT(10,"UserDialog_FileDirChooserButton		parameter NULL");
1029         return;
1030     }
1031 
1032     GString *gstrCaption = g_string_new("choose a file");
1033     char *filename=NULL;
1034 
1035     if (listItem->gstrAdditional2){
1036         g_string_assign(gstrCaption, listItem->gstrAdditional2->str);
1037     }
1038 
1039     GtkWidget *dialog = gtk_file_chooser_dialog_new (gstrCaption->str,
1040                                                         win,
1041                                                         listItem->iType==USERDIALOG_ENTITY_TYPE_FILECHOOSER?GTK_FILE_CHOOSER_ACTION_OPEN:GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1042                                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1043                                                         GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1044                                                         NULL);
1045 
1046     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
1047         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1048         gtk_entry_set_text(	(GtkEntry *)listItem->wdgtEntryBox, filename);
1049     }
1050 
1051     gtk_widget_destroy (dialog);
1052     if (filename)
1053         g_free (filename);
1054     g_string_free(gstrCaption, TRUE);
1055 
1056     TRACEIT(10,"UserDialog_FileDirChooserButton		end");
1057 }
1058 
1059 
decryptPredefine(GString * Predefine,struct _predefineStruct * predefStruct)1060 int decryptPredefine(GString *Predefine, struct _predefineStruct *predefStruct){
1061 	TRACEIT(10,"decryptPredefine		start");
1062 	char *KnownPredefines[] = KNOWNPREDEFINES;
1063 	int Count = NUMBEROFPREDEFINES;				//Change this if you add or remove a String to/from KownPredefines
1064 	int i;
1065 
1066 	for (i=0; i<Count; i++){
1067 		if (strcmp(KnownPredefines[i], Predefine->str) == 0){
1068 			break;
1069 		}
1070 	}
1071 
1072 	switch(i){
1073 		case 0:	//ThisDirectory
1074 		case 1:
1075 				g_string_assign(Predefine,predefStruct->gstrThisSidePath->str);
1076 				break;
1077 		case 2:	//OtherDirectory
1078 		case 3:
1079 				g_string_assign(Predefine,predefStruct->gstrOtherSidePath->str);
1080 				break;
1081 		case 4:	//LeftSideDirectory
1082 		case 5:
1083 				g_string_assign(Predefine,predefStruct->gstrLeftSidePath->str);
1084 				break;
1085 		case 6:	//gstrRightSidePath
1086 		case 7:
1087 				g_string_assign(Predefine,predefStruct->gstrRightSidePath->str);
1088 				break;
1089 		case 8:	//Home
1090 		case 9:
1091 		case 26:
1092                 //getHomeDirectory(&Predefine);
1093                 g_string_assign(Predefine,predefStruct->gstrHomeDir->str);
1094 				break;
1095         case 10: //gstrAllMarkedItems_WithoutPath_Unquoted
1096         case 11:
1097                 g_string_assign(Predefine,predefStruct->gstrAllMarkedItems_WithoutPath_Unquoted->str);
1098                 break;
1099         case 12: //gstrAllMarkedItems_WithoutPath_Quoted
1100         case 13:
1101                 g_string_assign(Predefine,predefStruct->gstrAllMarkedItems_WithoutPath_Quoted->str);
1102                 break;
1103         case 14: //gstrAllMarkedItems_WithPath_Unquoted
1104         case 15:
1105                 g_string_assign(Predefine,predefStruct->gstrAllMarkedItems_WithPath_Unquoted->str);
1106                 break;
1107         case 16: //gstrAllMarkedItems_WithPath_Quoted
1108         case 17:
1109                 g_string_assign(Predefine,predefStruct->gstrAllMarkedItems_WithPath_Quoted->str);
1110                 break;
1111         case 18: //gstrOneMarkedItem_WithoutPath_Unquoted
1112         case 19:
1113                 g_string_assign(Predefine,predefStruct->gstrOneMarkedItem_WithoutPath_Unquoted->str);
1114                 break;
1115         case 20: //gstrOneMarkedItem_WithoutPath_Quoted
1116         case 21:
1117                 g_string_assign(Predefine,predefStruct->gstrOneMarkedItem_WithoutPath_Quoted->str);
1118                 break;
1119         case 22: //gstrOneMarkedItem_WithPath_Unquoted
1120         case 23:
1121                 g_string_assign(Predefine,predefStruct->gstrOneMarkedItem_WithPath_Unquoted->str);
1122                 break;
1123         case 24: //gstrOneMarkedItem_WithPath_Unquoted
1124         case 25:
1125                 g_string_assign(Predefine,predefStruct->gstrOneMarkedItem_WithPath_Quoted->str);
1126                 break;
1127 		default:
1128 				Predefine->str[0] = '\0';
1129 	};
1130 	TRACEIT(10,"decryptPredefine		end");
1131 	return 0;
1132 }
1133