Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Prefs.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 // Prefs.c
00025 
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <xmlparse.h>
00029 
00030 #include "debug.h"
00031 #include "Prefs.h"
00032 #include "Common.h"
00033 #include "Gui.h"
00034 #include "Memory.h"
00035 
00036 
00037 struct Prefs_s
00038 {
00039   char *appname;
00040   int parse_status;
00041 };
00042 
00043 
00044 struct PrefsFile_s
00045 {
00046   char *filename;
00047 
00048 };
00049 
00050 struct PrefsItem_s
00051 {
00052   int type;
00053   union
00054   {
00055     u32 number;
00056     char *string;
00057   } value;
00058 };
00059 
00060 
00061 /*EZ JO, CSAK MEG NEM KELL!
00062 static void prefs_StartElement(void *userData, const char *name, const char **atts)
00063 {
00064   Prefs_t *prefs=(Prefs_t *)userData;
00065   int i;
00066   char *att;
00067 
00068   printf("prefs START> %s\n",name);
00069   if(prefs->parse_status==0)
00070   {
00071     if(strcmp(name,"Prefs")==0)
00072     {
00073       if(NULL!=(att=common_GetAttr(atts,"App"))&&strcmp(att,prefs->appname)==0)
00074       {
00075         prefs->parse_status=1;
00076       }
00077     }
00078   }
00079   else if(prefs->parse_status>0)
00080   {
00081     for(i=0;atts[i]!=NULL;i+=2) printf("  %s=%s\n",atts[i],atts[i+1]);
00082   }
00083 }
00084 static void prefs_EndElement(void *userData, const char *name)
00085 {
00086   Prefs_t *prefs=(Prefs_t *)userData;
00087 
00088   if(prefs->parse_status>0&&strcmp(name,"Prefs")==0) prefs->parse_status=-1;
00089   printf("prefs END< %s\n",name);
00090 }
00091 */
00092 
00093 static void prefs_LoadPrefs(Prefs_t *prefs, char *filename)
00094 {
00095 /*
00096   XML_Parser ctxt;
00097   int xmlret;
00098   char *file;
00099 
00100   if(NULL!=(file=gui_LoadFile(filename,NULL)))
00101   {
00102     if((ctxt=XML_ParserCreate(NULL)))
00103     {
00104       prefs->parse_status=0;
00105       XML_SetUserData(ctxt,prefs);
00106       XML_SetElementHandler(ctxt,prefs_StartElement,prefs_EndElement);
00107       xmlret=XML_Parse(ctxt,file,strlen(file),TRUE);
00108       if(!xmlret) printf("%s at line %d\n",XML_ErrorString(XML_GetErrorCode(ctxt)),XML_GetCurrentLineNumber(ctxt));
00109       XML_ParserFree(ctxt);
00110     }
00111     mem_free(file);
00112   }
00113 */
00114 }
00115 
00116 
00117 void prefs_Init(void)
00118 {
00119   // load global/global and local/global prefs
00120 }
00121 
00122 Prefs_t *prefs_InitApp(char *app)
00123 {
00124   Prefs_t *prefs=NULL;
00125 
00126   // load global/app and local/app prefs
00127   if(NULL!=(prefs=mem_malloc(sizeof(Prefs_t))))
00128   {
00129     if(NULL!=(prefs->appname=mem_malloc(strlen(app)+1)))
00130     {
00131       strcpy(prefs->appname,app);
00132       prefs->parse_status=0;
00133     }
00134     else
00135     {
00136       prefs_CleanUpApp(prefs);
00137       prefs=NULL;
00138     }
00139   }
00140 
00141   return(prefs);
00142 }
00143 
00144 void prefs_CleanUpApp(Prefs_t *prefs)
00145 {
00146   if(prefs!=NULL)
00147   {
00148     if(prefs->appname!=NULL) mem_free(prefs->appname);
00149     mem_free(prefs);
00150   }
00151 }
00152 
00153 void prefs_CleanUp(void)
00154 {
00155   debug_Begin();
00156   debug_End();
00157 }
00158 
00159 int prefs_Save(Prefs_t *prefs)
00160 {
00161   if(prefs!=NULL)
00162   {
00163     prefs_LoadPrefs(prefs,"TestApp_prefs.xml");
00164   }
00165   return(0);
00166 }
00167 
00168 char *prefs_GetString(Prefs_t *prefs, char *name, char *def)
00169 {
00170   return(def);
00171 }
00172 
00173 u32 prefs_GetNumber(Prefs_t *prefs, char *name, u32 def)
00174 {
00175   return(def);
00176 }
00177 
00178 char *prefs_SetString(Prefs_t *prefs, char *name, char *value, int flags)
00179 {
00180   return(NULL);
00181 }
00182 
00183 u32 prefs_SetNumber(Prefs_t *prefs, char *name, u32 value, int flags)
00184 {
00185   return(0L);
00186 }
00187 
00188 void prefs_Delete(Prefs_t *prefs, char *name, int flags)
00189 {
00190 }
00191 

Generated on Tue Jan 7 12:11:23 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002