00001 #ifndef _OPTION_FILE_H_
00002 #define _OPTION_FILE_H_
00003
00004 #include "GVariant.h"
00005 #include "GXmlTree.h"
00006 #include "GSemaphore.h"
00007
00008 class LgiClass GOptionsFile : public GXmlTag, public GSemaphore
00009 {
00010 public:
00011 enum PortableType
00012 {
00013 UnknownMode,
00014 PortableMode,
00015 DesktopMode,
00016 };
00017
00018 private:
00019 GAutoString File;
00020 GAutoString Error;
00021 bool Dirty;
00022
00023 char *LockFile;
00024 int LockLine;
00025
00026 void _Init();
00027 bool _OnAccess(bool Start);
00028
00029
00030 char *GetAttr(const char *Name) { return GXmlTag::GetAttr(Name); }
00031 int GetAsInt(const char *Name) { return GXmlTag::GetAsInt(Name); }
00032 bool SetAttr(const char *Name, char *Value) { return GXmlTag::SetAttr(Name, Value); }
00033 bool SetAttr(const char *Name, int Value) { return GXmlTag::SetAttr(Name, Value); }
00034 bool DelAttr(const char *Name) { return GXmlTag::DelAttr(Name); }
00035 void InsertTag(GXmlTag *t) { GXmlTag::InsertTag(t); }
00036 void RemoveTag() { GXmlTag::RemoveTag(); }
00037 GXmlTag *GetTag(const char *Name, bool Create = false) { return GXmlTag::GetTag(Name, Create); }
00038
00039 protected:
00040 virtual void _Defaults() {}
00041
00042 public:
00043 GOptionsFile(const char *FileName = 0);
00044 GOptionsFile(PortableType Mode, const char *BaseName = 0);
00045 ~GOptionsFile();
00046
00047 void SetFile(const char *f);
00048 bool SetMode(PortableType Mode, const char *BaseName = 0);
00049
00050 bool IsValid();
00051 char *GetFile() { return File; }
00052 char *GetError() { return Error; }
00053 bool Serialize(bool Write);
00054 bool DeleteValue(const char *Name);
00055
00056 bool CreateTag(const char *Name);
00057 bool DeleteTag(const char *Name);
00058 GXmlTag *LockTag(const char *Name, const char *File, int Line);
00059 };
00060
00061 #endif