summaryrefslogtreecommitdiff
path: root/src/unstable/settingsdriverini.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/settingsdriverini.cpp')
-rw-r--r--src/unstable/settingsdriverini.cpp258
1 files changed, 129 insertions, 129 deletions
diff --git a/src/unstable/settingsdriverini.cpp b/src/unstable/settingsdriverini.cpp
index 90debcb..31bc146 100644
--- a/src/unstable/settingsdriverini.cpp
+++ b/src/unstable/settingsdriverini.cpp
@@ -15,146 +15,146 @@ Bu::SettingsDriverIni::SettingsDriverIni()
15 15
16Bu::SettingsDriverIni::~SettingsDriverIni() 16Bu::SettingsDriverIni::~SettingsDriverIni()
17{ 17{
18 Bu::File fOut( sPath, Bu::File::WriteNew ); 18 Bu::File fOut( sPath, Bu::File::WriteNew );
19 Bu::Buffer bOut( fOut ); 19 Bu::Buffer bOut( fOut );
20 Bu::Formatter f( bOut ); 20 Bu::Formatter f( bOut );
21 21
22 for( GroupHash::iterator i = hGroup.begin(); i; i++ ) 22 for( GroupHash::iterator i = hGroup.begin(); i; i++ )
23 { 23 {
24 f << "[" << i.getKey().get() << "]" << f.nl; 24 f << "[" << i.getKey().get() << "]" << f.nl;
25 for( StrHash::iterator k = (*i).begin(); k; k++ ) 25 for( StrHash::iterator k = (*i).begin(); k; k++ )
26 { 26 {
27 f << k.getKey().get() << " = " << k.getValue().get() << f.nl; 27 f << k.getKey().get() << " = " << k.getValue().get() << f.nl;
28 } 28 }
29 f << f.nl; 29 f << f.nl;
30 } 30 }
31} 31}
32 32
33void Bu::SettingsDriverIni::init( const Bu::UtfString &sCompany, 33void Bu::SettingsDriverIni::init( const Bu::UtfString &sCompany,
34 const Bu::UtfString &sProduct ) 34 const Bu::UtfString &sProduct )
35{ 35{
36 Bu::UtfString us( getenv("HOME") ); 36 Bu::UtfString us( getenv("HOME") );
37 us += "/.config/"; 37 us += "/.config/";
38 us += sCompany; 38 us += sCompany;
39 us += "/"; 39 us += "/";
40 us += sProduct; 40 us += sProduct;
41 sPath = us.get(); 41 sPath = us.get();
42 try 42 try
43 { 43 {
44 Bu::File fIn( sPath, Bu::File::Read|Bu::File::Create ); 44 Bu::File fIn( sPath, Bu::File::Read|Bu::File::Create );
45 Bu::Buffer bIn( fIn ); 45 Bu::Buffer bIn( fIn );
46 StrHash hKeys; 46 StrHash hKeys;
47 Bu::String sGroup; 47 Bu::String sGroup;
48 bool bStart = true; 48 bool bStart = true;
49 while( !bIn.isEos() ) 49 while( !bIn.isEos() )
50 { 50 {
51 Bu::String sIn = bIn.readLine(); 51 Bu::String sIn = bIn.readLine();
52 if( sIn.isEmpty() ) 52 if( sIn.isEmpty() )
53 continue; 53 continue;
54 if( sIn[0] == '[' ) 54 if( sIn[0] == '[' )
55 { 55 {
56 if( bStart != true ) 56 if( bStart != true )
57 { 57 {
58 hGroup.insert( sGroup, hKeys ); 58 hGroup.insert( sGroup, hKeys );
59 hKeys.clear(); 59 hKeys.clear();
60 } 60 }
61 sGroup = Bu::String( sIn.begin()+1, sIn.find(']') ); 61 sGroup = Bu::String( sIn.begin()+1, sIn.find(']') );
62 bStart = false; 62 bStart = false;
63 } 63 }
64 else 64 else
65 { 65 {
66 Bu::String::iterator i = sIn.find('='); 66 Bu::String::iterator i = sIn.find('=');
67 if( !i ) 67 if( !i )
68 continue; 68 continue;
69 69
70 hKeys.insert( Bu::String( sIn.begin(), i ).trimWhitespace(), 70 hKeys.insert( Bu::String( sIn.begin(), i ).trimWhitespace(),
71 Bu::String( i+1, sIn.end() ).trimWhitespace() ); 71 Bu::String( i+1, sIn.end() ).trimWhitespace() );
72 } 72 }
73 } 73 }
74 hGroup.insert( sGroup, hKeys ); 74 hGroup.insert( sGroup, hKeys );
75 } 75 }
76 catch(...) 76 catch(...)
77 { 77 {
78 } 78 }
79} 79}
80 80
81void Bu::SettingsDriverIni::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) 81void Bu::SettingsDriverIni::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue )
82{ 82{
83 Bu::String suKey = sKey.get(); 83 Bu::String suKey = sKey.get();
84 Bu::String::iterator i = suKey.find('/'); 84 Bu::String::iterator i = suKey.find('/');
85 Bu::UtfString sGrp; 85 Bu::UtfString sGrp;
86 Bu::UtfString sId; 86 Bu::UtfString sId;
87 if( !i ) 87 if( !i )
88 { 88 {
89 sGrp = ""; 89 sGrp = "";
90 sId = sKey; 90 sId = sKey;
91 } 91 }
92 else 92 else
93 { 93 {
94 Bu::String::iterator in; 94 Bu::String::iterator in;
95 for(;;) 95 for(;;)
96 { 96 {
97 in = i; 97 in = i;
98 i = (in + 1).find('/'); 98 i = (in + 1).find('/');
99 if( !i ) 99 if( !i )
100 break; 100 break;
101 } 101 }
102 102
103 sGrp.set( Bu::String( suKey.begin(), in ) ); 103 sGrp.set( Bu::String( suKey.begin(), in ) );
104 sId.set( Bu::String( in+1, suKey.end() ) ); 104 sId.set( Bu::String( in+1, suKey.end() ) );
105 } 105 }
106 106
107// sio << "Group: " << sGrp.get() << sio.nl 107// sio << "Group: " << sGrp.get() << sio.nl
108// << "Key: " << sId.get() << sio.nl; 108// << "Key: " << sId.get() << sio.nl;
109 109
110 if( !hGroup.has( sGrp ) ) 110 if( !hGroup.has( sGrp ) )
111 { 111 {
112 StrHash hVal; 112 StrHash hVal;
113 hVal.insert( sId, sValue ); 113 hVal.insert( sId, sValue );
114 hGroup.insert( sGrp, hVal ); 114 hGroup.insert( sGrp, hVal );
115 } 115 }
116 else 116 else
117 { 117 {
118 hGroup.get( sGrp ).insert( sId, sValue ); 118 hGroup.get( sGrp ).insert( sId, sValue );
119 } 119 }
120} 120}
121 121
122Bu::UtfString Bu::SettingsDriverIni::get( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) 122Bu::UtfString Bu::SettingsDriverIni::get( const Bu::UtfString &sKey, const Bu::UtfString &sValue )
123{ 123{
124 Bu::String suKey = sKey.get(); 124 Bu::String suKey = sKey.get();
125 Bu::String::iterator i = suKey.find('/'); 125 Bu::String::iterator i = suKey.find('/');
126 Bu::UtfString sGrp; 126 Bu::UtfString sGrp;
127 Bu::UtfString sId; 127 Bu::UtfString sId;
128 if( !i ) 128 if( !i )
129 { 129 {
130 sGrp = ""; 130 sGrp = "";
131 sId = sKey; 131 sId = sKey;
132 } 132 }
133 else 133 else
134 { 134 {
135 Bu::String::iterator in; 135 Bu::String::iterator in;
136 for(;;) 136 for(;;)
137 { 137 {
138 in = i; 138 in = i;
139 i = (in + 1).find('/'); 139 i = (in + 1).find('/');
140 if( !i ) 140 if( !i )
141 break; 141 break;
142 } 142 }
143 143
144 sGrp.set( Bu::String( suKey.begin(), in ) ); 144 sGrp.set( Bu::String( suKey.begin(), in ) );
145 sId.set( Bu::String( in+1, suKey.end() ) ); 145 sId.set( Bu::String( in+1, suKey.end() ) );
146 } 146 }
147 147
148// sio << "Group: " << sGrp.get() << sio.nl 148// sio << "Group: " << sGrp.get() << sio.nl
149// << "Key: " << sId.get() << sio.nl; 149// << "Key: " << sId.get() << sio.nl;
150 150
151 try 151 try
152 { 152 {
153 return hGroup.get( sGrp ).get( sId ); 153 return hGroup.get( sGrp ).get( sId );
154 } 154 }
155 catch(...) 155 catch(...)
156 { 156 {
157 return sValue; 157 return sValue;
158 } 158 }
159} 159}
160 160