diff options
Diffstat (limited to '')
-rw-r--r-- | src/unstable/settingsdrivertaf.cpp | 81 |
1 files changed, 77 insertions, 4 deletions
diff --git a/src/unstable/settingsdrivertaf.cpp b/src/unstable/settingsdrivertaf.cpp index 164bf0b..8cbcbc5 100644 --- a/src/unstable/settingsdrivertaf.cpp +++ b/src/unstable/settingsdrivertaf.cpp | |||
@@ -12,18 +12,91 @@ Bu::SettingsDriverTaf::SettingsDriverTaf() : | |||
12 | 12 | ||
13 | Bu::SettingsDriverTaf::~SettingsDriverTaf() | 13 | Bu::SettingsDriverTaf::~SettingsDriverTaf() |
14 | { | 14 | { |
15 | if( !pRoot ) | ||
16 | return; | ||
17 | |||
18 | Bu::File fOut( sPath, Bu::File::WriteNew ); | ||
19 | Bu::TafWriter tw( fOut ); | ||
20 | tw.writeGroup( pRoot ); | ||
21 | delete pRoot; | ||
15 | } | 22 | } |
16 | 23 | ||
17 | void Bu::SettingsDriverTaf::init( const Bu::UtfString &sCompany, | 24 | void Bu::SettingsDriverTaf::init( const Bu::UtfString &sCompany, |
18 | const Bu::UtfString &sProduct ) | 25 | const Bu::UtfString &sProduct ) |
19 | { | 26 | { |
20 | Bu::UtfString us( getenv("HOME") ); | 27 | Bu::UtfString us( getenv("HOME") ); |
21 | us += "/"; | 28 | us += "/.config/"; |
22 | us += sCompany; | 29 | us += sCompany; |
23 | us += "/"; | 30 | us += "/"; |
24 | us += sProduct; | 31 | us += sProduct; |
25 | Bu::File fIn( us.get(), Bu::File::Read|Bu::File::Create ); | 32 | sPath = us.get(); |
26 | Bu::TafReader tr( fIn ); | 33 | try |
27 | pRoot = tr.readGroup(); | 34 | { |
35 | Bu::File fIn( sPath, Bu::File::Read|Bu::File::Create ); | ||
36 | Bu::TafReader tr( fIn ); | ||
37 | pRoot = tr.readGroup(); | ||
38 | } | ||
39 | catch(...) | ||
40 | { | ||
41 | } | ||
42 | if( !pRoot ) | ||
43 | { | ||
44 | pRoot = new Bu::TafGroup( sProduct.get() ); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void Bu::SettingsDriverTaf::set( const Bu::UtfString &sKey, | ||
49 | const Bu::UtfString &sValue ) | ||
50 | { | ||
51 | Bu::StringList lPath = sKey.get().split('/'); | ||
52 | Bu::StringList::iterator i = lPath.begin(); | ||
53 | Bu::StringList::iterator in; | ||
54 | Bu::TafGroup *pGrp = pRoot; | ||
55 | for(; i;) | ||
56 | { | ||
57 | in = i; | ||
58 | in++; | ||
59 | if( in ) | ||
60 | { | ||
61 | if( pGrp->hasChild( *i ) ) | ||
62 | pGrp = (Bu::TafGroup *)pGrp->getChild( *i ); | ||
63 | else | ||
64 | pGrp = pGrp->addGroup( *i ); | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | pGrp->addProperty( *i, sValue.get() ); | ||
69 | } | ||
70 | i = in; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | Bu::UtfString Bu::SettingsDriverTaf::get( const Bu::UtfString &sKey, | ||
75 | const Bu::UtfString &sValue ) | ||
76 | { | ||
77 | Bu::StringList lPath = sKey.get().split('/'); | ||
78 | Bu::StringList::iterator i = lPath.begin(); | ||
79 | Bu::StringList::iterator in; | ||
80 | Bu::TafGroup *pGrp = pRoot; | ||
81 | for(; i;) | ||
82 | { | ||
83 | in = i; | ||
84 | in++; | ||
85 | if( in ) | ||
86 | { | ||
87 | if( pGrp->hasChild( *i ) ) | ||
88 | pGrp = (Bu::TafGroup *)pGrp->getChild( *i ); | ||
89 | else | ||
90 | return sValue; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | if( pGrp->hasProperty( *i ) ) | ||
95 | return pGrp->getProperty( *i ); | ||
96 | else | ||
97 | return sValue; | ||
98 | } | ||
99 | i = in; | ||
100 | } | ||
28 | } | 101 | } |
29 | 102 | ||