aboutsummaryrefslogtreecommitdiff
path: root/src/unstable
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-08-24 20:11:04 +0000
committerMike Buland <eichlan@xagasoft.com>2012-08-24 20:11:04 +0000
commitd7d2c0929a5d7871e913451fd542e03ae4561183 (patch)
treea5ca60568edc265e1c4f657706709db7d27f50bc /src/unstable
parentda642482dee91921fc16786208aa497d3ee31d94 (diff)
downloadlibbu++-d7d2c0929a5d7871e913451fd542e03ae4561183.tar.gz
libbu++-d7d2c0929a5d7871e913451fd542e03ae4561183.tar.bz2
libbu++-d7d2c0929a5d7871e913451fd542e03ae4561183.tar.xz
libbu++-d7d2c0929a5d7871e913451fd542e03ae4561183.zip
Taf isn't really...the best backend for this now, I need some more fixes there
first, so next up we need the windows registry backend.
Diffstat (limited to 'src/unstable')
-rw-r--r--src/unstable/settings.cpp7
-rw-r--r--src/unstable/settings.h1
-rw-r--r--src/unstable/settingsdriver.h2
-rw-r--r--src/unstable/settingsdrivertaf.cpp81
-rw-r--r--src/unstable/settingsdrivertaf.h7
5 files changed, 94 insertions, 4 deletions
diff --git a/src/unstable/settings.cpp b/src/unstable/settings.cpp
index e993250..ac3975f 100644
--- a/src/unstable/settings.cpp
+++ b/src/unstable/settings.cpp
@@ -36,5 +36,12 @@ Bu::Settings::~Settings()
36 36
37void Bu::Settings::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ) 37void Bu::Settings::set( const Bu::UtfString &sKey, const Bu::UtfString &sValue )
38{ 38{
39 pDriver->set( sKey, sValue );
40}
41
42Bu::UtfString Bu::Settings::get( const Bu::UtfString &sKey,
43 const Bu::UtfString &sValue )
44{
45 return pDriver->get( sKey, sValue );
39} 46}
40 47
diff --git a/src/unstable/settings.h b/src/unstable/settings.h
index 0736ee5..c1d0e1c 100644
--- a/src/unstable/settings.h
+++ b/src/unstable/settings.h
@@ -23,6 +23,7 @@ namespace Bu
23 virtual ~Settings(); 23 virtual ~Settings();
24 24
25 void set( const Bu::UtfString &sKey, const Bu::UtfString &sValue ); 25 void set( const Bu::UtfString &sKey, const Bu::UtfString &sValue );
26 Bu::UtfString get( const Bu::UtfString &sKey, const Bu::UtfString &sValue=Bu::UtfString() );
26 27
27 private: 28 private:
28 Bu::UtfString sCompany; 29 Bu::UtfString sCompany;
diff --git a/src/unstable/settingsdriver.h b/src/unstable/settingsdriver.h
index 0a63106..47b7d9d 100644
--- a/src/unstable/settingsdriver.h
+++ b/src/unstable/settingsdriver.h
@@ -20,6 +20,8 @@ namespace Bu
20 20
21 protected: 21 protected:
22 virtual void init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct )=0; 22 virtual void init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct )=0;
23 virtual void set( const Bu::UtfString &sKey, const Bu::UtfString &sValue )=0;
24 virtual Bu::UtfString get( const Bu::UtfString &sKey, const Bu::UtfString &sValue )=0;
23 }; 25 };
24}; 26};
25 27
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
13Bu::SettingsDriverTaf::~SettingsDriverTaf() 13Bu::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
17void Bu::SettingsDriverTaf::init( const Bu::UtfString &sCompany, 24void 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
48void 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
74Bu::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
diff --git a/src/unstable/settingsdrivertaf.h b/src/unstable/settingsdrivertaf.h
index d7d751b..b5f8b07 100644
--- a/src/unstable/settingsdrivertaf.h
+++ b/src/unstable/settingsdrivertaf.h
@@ -2,11 +2,15 @@
2#define BU_SETTINGS_DRIVER_TAF_H 2#define BU_SETTINGS_DRIVER_TAF_H
3 3
4#include "bu/settingsdriver.h" 4#include "bu/settingsdriver.h"
5#include "bu/string.h"
5 6
6namespace Bu 7namespace Bu
7{ 8{
8 class TafGroup; 9 class TafGroup;
9 10
11 /**
12 * The taf driver is flawed until I fix taf editing, I've been meaning to...
13 */
10 class SettingsDriverTaf : public SettingsDriver 14 class SettingsDriverTaf : public SettingsDriver
11 { 15 {
12 public: 16 public:
@@ -15,8 +19,11 @@ namespace Bu
15 19
16 protected: 20 protected:
17 virtual void init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct ); 21 virtual void init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct );
22 virtual void set( const Bu::UtfString &sKey, const Bu::UtfString &sValue );
23 virtual Bu::UtfString get( const Bu::UtfString &sKey, const Bu::UtfString &sValue );
18 24
19 private: 25 private:
26 Bu::String sPath;
20 class Bu::TafGroup *pRoot; 27 class Bu::TafGroup *pRoot;
21 }; 28 };
22}; 29};