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 #ifndef CONFIGHANDLING_H_
20 #define CONFIGHANDLING_H_
21 
22 
23 
24 struct myFiles_struct{
25     FILE *File;
26     //   int iWrite;                 //0=read, 1=write,create, 2=append,create
27     int allreadystarted;
28     GString *gstrFileName;      //including the path
29     GString *gstrIdentifier;
30     GString *gstrValue;
31 };
32 
33 
34 enum{
35     USERCOMMAND_CALLTYPE_ALL=0,
36     USERCOMMAND_CALLTYPE_EACH,
37     USERCOMMAND_CALLTYPE_LIST
38 };
39 
40 enum{
41 	CONFIGFILE_LOAD_NOTHING=0,
42     CONFIGFILE_LOAD_OPTIONS=1,
43     CONFIGFILE_LOAD_USERCOMMANDS=2,
44     CONFIGFILE_LOAD_BOOKMARKS=4
45 };
46 
47 enum{	//-1 = unknown
48 	USERDIALOG_ENTITY_TYPE_QUESTION=0,
49 	USERDIALOG_ENTITY_TYPE_CHECKBOX,
50 	USERDIALOG_ENTITY_TYPE_TEXT,
51 	USERDIALOG_ENTITY_TYPE_FILECHOOSER,
52 	USERDIALOG_ENTITY_TYPE_DIRCHOOSER,
53 	USERDIALOG_ENTITY_TYPE_SEPARATOR
54 };
55 
56 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
57 //!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT!!!!!!!!!!!!!!!!!!
58 //! after the widgets in this struct were used, make the pointers here NULL. Or they will be unrefed when the list gets deleted
59 struct _DialogEntityList {
60 	int iType;				//see enum (e.g. USEDIALOG_ENTITY_TYPE_QUESTION)
61 	int iValid;				//becomes 1 if the information is complete, so we can create this entity
62 
63 	GString 		*gstrVarIdentifier;	//Name of the variable (defined by the user)
64     GString         *gstrVarValue;      //the value assigned with the varIdentifier (we have to leave all the other values untouched)
65                                         //and this is the only value which is written
66 	//label
67 	GString			*gstrLabel;		//the text shown in the label (e.g. the questiontext for qestion entity)
68 	GtkWidget		*wdgtLabel;		//the pointer to the widget which holds the gstrLabel text.
69 
70 	//entrybox
71 	GString 		*gstrPredefine; //question's predefine or true or false for checkboxes, means the checkbox is checked or not
72 	GtkWidget		*wdgtEntryBox;	//text entity has no entrybox.
73 
74 	//other properties
75 	GString			*gstrAdditional1;	//for checkbox: TRUE-Value,   file/dirchooser: Text on the button
76 	GString			*gstrAdditional2;	//for checkbox: FALSE-Value,  file/dirchooser: caption of the chooser dialog
77 	GtkWidget		*wdgtAdditional1;	//for file/dirchooser: the button widget
78 	GtkWidget		*wdgtAdditional2;	//for file/dirchooser: the hbox container
79 
80 	struct _DialogEntityList *nextItem;
81 	struct _DialogEntityList *prevItem;
82 };
83 
84 
85 struct _UserCommandList {
86     int iValid;				//becomes 1 if the information is complete
87     int iIsDefaultCommand; 	//for double click or enter button, 0=nothing special here, 1=its the default command
88     GString *gstrName;      //the name as viewed in contextmenu
89     GList *glistTargets;    //all the Targets (endings), this command belongs to
90     GString *gstrCommand;   //the command as in configfile
91     struct _DialogEntityList *DialogEntityList; //all infos about the entities in the dialog (question, checkbox, ....)
92 	GString *gstrDialogCaption;
93 	GString *gstrDialogLabel;
94 	GString *gstrWorkingDir;    //used for StandardTerminalkey
95 
96     //the options are not stored in a seperate structure as they are not dynamic we can store the information right here
97     int option_iCallType;    //the call type (all/each/list) see enum (USERCOMMAND_CALLTYPE_ALL)
98     GString *option_gstrQuitreply;
99     GString *option_gstrActionnote;
100     GString *option_gstrCaption;    //the caption for the list widget
101     GString *option_gstrLabel;      //the label fot the list widget
102 
103     struct _UserCommandList *nextItem;
104     struct _UserCommandList *prevItem;
105 };
106 
107 
108 struct _OptionsList {   //list for storing options such things like standardTerminal, startpathes, colors and all that
109     GString *gstrID;        //the identifier (for options: e.g. strdld)
110     GString *gstrName;
111     GString *gstrValue;   //the only items which can have more than one value are the standardstartpathesLeft/Right properties.
112                             //but this porperties simply are added more than ones to this list, having the same name but different
113                             //values.
114 
115     struct _OptionsList *nextItem;
116     struct _OptionsList *prevItem;
117 };
118 
119 
120 struct _Items_XML_Relation {  //stores in whitch mode we are when parsing the xml file
121 										//Bit/value		explanation
122 
123 	gboolean bUnKnownBlock;				//0 /1
124 	gboolean bCatsEyEBlock;             //1 /2		we are in <CatsEyE> - Block
125 
126 	gboolean bCatsEyEBookMarksBlock;	//2	/4
127 
128 	gboolean bCatsEyEOptionsBlock;      //3	/8		we are in <CatsEyEOptions> - Block
129 	gboolean bCatsEyEUserCommandsBlock; //4 /16
130     gboolean bUserCommandBlock;			//5	/32		we are in <Usercommand>-Block (within <CatsEyEUsercommands>)
131     gboolean bObjectBlock;				//6 /64
132     gboolean bOptionBlock;				//7	/128		we are in <Option> - Block (within <CatsEyEOptions>-Block)
133 
134 	gboolean bIDBlock;					//8 /256
135     gboolean bNameBlock;				//9 /512
136     gboolean bValueBlock;				//10 /1024
137 
138     int	iRelation;						//all the bools are bitwise accumulated and stored as value here, call accumulateItemXMLRelation
139 };
140 
141 
142 struct _Parser_Mode_Struct {    //to communicate between different xml parser functions.
143     void 		*storageList;      //becomes _OptionsList or _UserCommandList pointer
144     void 		*currentListItem;  //becomes _OptionsList or _UserCommandList pointer, holds the item currently in use which is then stored in the storageList
145     struct _OptionsList *currentOptionBlock; //needed for the usercommand section to cache the <Option> Block, therefor holds a pointer to _OptionsList
146     struct _Items_XML_Relation *relation;
147     int			iCurrentListType;	//stores from wich type the storageList is (see enum, CONFIGFILE_LOAD_OPTIONS, CONFIGFILE_LOAD_USERCOMMANDS, CONFIGFILE_LOAD_BOOKMARKS)
148     gboolean 	bMakeItThreadSave;
149     const char **cppAttributeValues;	//used in UserCommand part, where the <Object> Block has a type attribute to identify the object e.g. as question
150     const char **cppAttributeNames;		//used in UserCommand part, where the <Object> Block has a type attribute to identify the object e.g. as question
151 
152     void (*functionStartNotification)();	//stores a pointer to a function which is called from the XMLParser_foundStart
153     void (*functionStopNotification)();	    //stores a pointer to a function which is called from the XMLParser_foundEnd
154 											//the functions must be declared as follows:
155 											//void *startFunction (struct _Parser_Mode_Struct *info);
156 											//void *endFuntion (struct _Parser_Mode_Struct *info, const char *element_name);
157 	void (*functionTextNotification)();	    //stores a pointer to a function which is called from XMLParser_foundText;
158 											//the functions must be declared as follows:
159 											//void *startFunction (struct _Parser_Mode_Struct *info, const char *text);
160 
161 };
162 
163 
164 
165 /////////////////////////////////
166 ///// declerations /////////////
167 
168 //Main access
169 void                    	configFileHandling_Init();
170 int                     	configFileHandling_loadConfigFile(gboolean bIgnoreTimeStamp, gboolean bMakeItThreadSave);
171 int                         configFileHandling_saveGlobalStructsAsXMLConfigFile (const char *ccpFileName, gboolean bMakeThreadSave);
172 void                    	configFileHandling_clearForShutdown();
173 int 						configFileHandling_defineConfigFileName(const char *ccpFileName);
174 const char              *   configFileHandling_getConfigFileName ();
175 void                        configFileHandling_setPreventReloadFlag (int iValue);
176 void                        configFileHandling_validateUsercommandList(gboolean bMakeItThreadSave);
177 void 					debugOut_PrintLists();
178 
179 
180 // dialog List
181 int 						DialogEntityList_addItem(struct _DialogEntityList **theList, int iType);	//if iType == -1, its unknown
182 int 						DialogEntityList_freeList(struct _DialogEntityList **theList);
183 int 						DialogEntityList_editItem(struct _DialogEntityList *theItem, int iType, char *cpVarID, char *cpLabel, GtkWidget *wdgtLabel, char *cpPredefine, GtkWidget *wdgtEntryBox, char *cpAdd1, char *cpAdd2, GtkWidget *wdgtAdd1 );		//changes the content of the given item
184 int 						DialogEntityList_editLastItem(struct _DialogEntityList *theList, int iType, char *cpVarID, char *cpLabel, GtkWidget *wdgtLabel, char *cpPredefine, GtkWidget *wdgtEntryBox, char *cpAdd1, char *cpAdd2, GtkWidget *wdgtAdd1 );		//changes the content of the given item);	//searches the last item in the list and changes its content
185 struct _DialogEntityList *	DialogEntityList_getLastItem(struct _DialogEntityList *theList);
186 struct _DialogEntityList *	DialogEntityList_getFirstItem(struct _DialogEntityList *theList);
187 void 				DialogEntityList_DebugOut_printList(struct _DialogEntityList *theList);
188 //int 						DialogEntityList_validateList(struct _DialogEntityList *theList);	//checks the content of all items and sets iValid member
189 
190 
191 //UserCommandList
192 int							UserCommandList_addItem(struct _UserCommandList **theList, const char *ccpSource);
193 struct _UserCommandList   *	UserCommandList_deleteItem(struct _UserCommandList *theItem);
194 int 						UserCommandList_clearTargets(struct _UserCommandList *theItem);
195 int 						UserCommandList_freeList(struct _UserCommandList **theList); //has to free _DialogEntityList and glistTargets too.
196 int 						UserCommandList_editItem(struct _UserCommandList *theItem, int iIsDefaultCommand, const char *cpName, const char *cpTarget, const char *cpCommand, int iCallType, const char *cpOptionQuitreply, const char *cpOptionActionnote, const char *cpOptionCaption, const char *cpOptionLabel, const char *cpDialogCaption, const char *cpDialogLabel, const char *cpWorkingDir); //the target amy be added to the GList
197 int 						UserCommandList_deleteItemElement(struct _UserCommandList *theItem, int iName, int iTarget, int iCommand, int iOptionQuitreply, int iOptionActionnote, int iOptionCaption, int iOptionLabel, int iDialogCaption, int iDialogLabel, int iWorkingDir); //0=do nothing, 1=delete this element
198 int 						UserCommandList_addItemAsCopy(struct _UserCommandList **theList, struct _UserCommandList *theNewItem);	//simply adds theNewItem to theList, this will preserve us to copy the whole content of hte list (which holds 2 lists by its own!)
199 struct _UserCommandList *	UserCommandList_getLastItem (struct _UserCommandList *theList);
200 struct _UserCommandList *	UserCommandList_getFirstItem (struct _UserCommandList *theList);
201 GList *						UserCommandList_getCommandsForTarget (struct _UserCommandList *theWholeList, char *cpTarget);
202 gboolean 					UserCommandList_ItemHasTarget (struct _UserCommandList *theItem, char *cpTarget);
203 int 						UserCommandList_copyItemToList (struct _UserCommandList **theList, struct _UserCommandList *NewItem); //really copies!
204 void  				UserCommandList_DebugOut_printList(struct _UserCommandList *theList);
205 
206 
207 //_OptionsList related functions
208 int                     	OptionsList_addItem(struct _OptionsList **OptionsList, const char*cpID, const char *cpName, const char *cpValue);
209 int                     	OptionsList_editItem(struct _OptionsList *OptionsList, const char*cpID, const char *cpName, const char *cpValue);
210 struct _OptionsList     *	OptionsList_getFirstItem(struct _OptionsList *thelist);
211 struct _OptionsList     *	OptionsList_getLastItem(struct _OptionsList *thelist);
212 struct _OptionsList     *	OptionsList_deleteItem(struct _OptionsList *theItem);
213 void                    	OptionsList_freeList(struct _OptionsList **thelist);
214 struct _OptionsList 	*	OptionsList_getItemByName(struct _OptionsList *OptionsList, const char *cpName);
215 struct _OptionsList 	*	OptionsList_getItemByID(struct _OptionsList *OptionsList, const char *cpName);
216 const char              *   OptionsList_getValueByID (struct _OptionsList *OptionsList, const char *cpID);
217 int							OptionsList_GetIntValueByID (struct _OptionsList *OptionsList, const char *cpID, int iDefault);
218 const char              *   OptionsList_getNameByID (struct _OptionsList *OptionsList, const char *cpID);
219 const char              *   OptionsList_getValueAndNextItemByID (struct _OptionsList *StartItem, struct _OptionsList **NextItem, const char *cpID);
220 
221 //gboolean                	OptionsList_checkForID(struct _OptionsList *OptionsList, const char *cpID);
222 void                   OptionsList_DebugOut_printList(struct _OptionsList *theList);
223 
224 
225 //for all
226 void						freeRelicts(struct _Parser_Mode_Struct *info);	//deletes currentItems in this struct if necessary
227 
228 //for Options and Bookmarks
229 int                     	Options_loadOptionsFromFile(struct myFiles_struct *myFilestru, gboolean bMakeItThreadSave);
230 int                     	Options_CreateDefaultList ();
231 void                    	Options_FoundStartCallback(struct _Parser_Mode_Struct *info);
232 void                    	Options_FoundEndCallback(struct _Parser_Mode_Struct *info, const char *element_name);
233 void                    	Options_FoundTextCallback(struct _Parser_Mode_Struct *info, const char *text);
234 
235 
236 
237 //_Itms_XML_Relation functions
238 int 						XMLRelation_updateByNewElement(struct _Items_XML_Relation *relation, const char *cpElement);
239 int 						XMLRelation_accumulateRelations(struct _Items_XML_Relation *relation);
240 int 						XMLRelation_eraseAll(struct _Items_XML_Relation *relation);
241 struct _OptionsList		*	XMLParser_getValidKeyWordsForState(struct _Items_XML_Relation *relation);
242 
243 
244 //XML Parser functions
245 int 						XMLParser_ParseFileFile (struct myFiles_struct *myFilestru, struct _Parser_Mode_Struct *modeStruct, gboolean bMakeItThreadSave);
246 void 						XMLParser_foundStart (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error);
247 void 						XMLParser_foundEnd (GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error);
248 void 						XMLParser_foundText (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error);
249 
250 
251 
252 ////////////////////////////// XML PROCEDURE ENDS HERE ///////////////////////////////////
253 //////////////////////////////////////////////////////////////////////////////////////////
254 //////////////////////////////////////////////////////////////////////////////////////////
255 
256 
257 //file only
258 struct myFiles_struct *myFiles_openFile(char *FileName, char *cpMode);
259 int myFiles_closeFile(struct myFiles_struct *fileInfo);
260 int myFiles_SaveValueToFile(struct myFiles_struct *fileInfo, char *cpLine);
261 int myFiles_findStringInFile(struct myFiles_struct *fileInfo, char *cpString);
262 //common
263 int myFiles_getValueFromIdentifier(struct myFiles_struct *fileInfo, char *cpIdentifier, int again);
264 int myFiles_SeparateMultiValue(struct myFiles_struct *fileInfo, GString *name, GString *command, int ModusSingleOrPair);
265 //configfile
266 //struct myFiles_struct *myFiles_openConfigTypesFile(char *cpMode);
267 //int myFiles_ConfigFileSimpleGetValue(char *Identifier, GString *Value);
268 //savefile
269 struct myFiles_struct *myFiles_openSaveFile( char *cpMode);
270 int myFiles_SaveFileSimpleSave(char *cpLine, char *Mode);
271 int myFiles_SaveFileSimpleGetValue(char *Identifier, GString *Value);
272 
273 
274 #endif //CONFIGHANDLING_H_
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
286 
287 
288