Diffstat (limited to 'libopie2/opiedb/osqlbackendmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiedb/osqlbackendmanager.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp index 95ed77b..fc18e07 100644 --- a/libopie2/opiedb/osqlbackendmanager.cpp +++ b/libopie2/opiedb/osqlbackendmanager.cpp | |||
@@ -1,98 +1,106 @@ | |||
1 | #include <qdir.h> | 1 | #include <qdir.h> |
2 | #include <qmap.h> | 2 | #include <qmap.h> |
3 | 3 | ||
4 | #include "osqlbackendmanager.h" | 4 | #include "osqlbackendmanager.h" |
5 | 5 | ||
6 | /** | ||
7 | * \todo FIXME CONFIG!!! | ||
8 | */ | ||
9 | |||
6 | namespace { | 10 | namespace { |
7 | class Config { | 11 | class Config { |
8 | typedef QMap<QString, QString> List; | 12 | typedef QMap<QString, QString> List; |
9 | public: | 13 | public: |
10 | Config( const QString& fileName ); | 14 | Config( const QString& fileName ); |
11 | /** | 15 | /** |
12 | * Quite simple layout in nature | 16 | * Quite simple layout in nature |
13 | * BeginFile | 17 | * BeginFile |
14 | * Key = Value | 18 | * Key = Value |
15 | */ | 19 | */ |
16 | bool load(); | 20 | bool load(); |
17 | QString value( const QString& key ); | 21 | QString value( const QString& key ); |
18 | private: | 22 | private: |
19 | List m_list; | 23 | List m_list; |
20 | QString m_fileName; | 24 | QString m_fileName; |
21 | }; | 25 | }; |
22 | Config::Config( const QString& fileName ) | 26 | Config::Config( const QString& fileName ) |
23 | : m_fileName( fileName ) { | 27 | : m_fileName( fileName ) { |
24 | } | 28 | } |
25 | 29 | ||
26 | bool Config::load() { | 30 | bool Config::load() { |
27 | if (!QFile::exists( m_fileName ) ) | 31 | if (!QFile::exists( m_fileName ) ) |
28 | return false; | 32 | return false; |
29 | QFile file( m_fileName ); | 33 | QFile file( m_fileName ); |
30 | if (!file.open(IO_ReadOnly ) ) | 34 | if (!file.open(IO_ReadOnly ) ) |
31 | return false; | 35 | return false; |
32 | QStringList list = QStringList::split( '\n', file.readAll() ); | 36 | QStringList list = QStringList::split( '\n', file.readAll() ); |
33 | QStringList::Iterator it; | 37 | QStringList::Iterator it; |
34 | QString line; | 38 | QString line; |
35 | for (it = list.begin(); it != list.end(); ++it ) { | 39 | for (it = list.begin(); it != list.end(); ++it ) { |
36 | line = (*it).stripWhiteSpace(); | 40 | line = (*it).stripWhiteSpace(); |
37 | qWarning("Anonymous::Config:" + line ); | 41 | qWarning("Anonymous::Config:" + line ); |
38 | QStringList test = QStringList::split(' ', line ); | 42 | QStringList test = QStringList::split(' ', line ); |
39 | m_list.insert( test[0], test[2] ); | 43 | m_list.insert( test[0], test[2] ); |
40 | } | 44 | } |
41 | return true; | 45 | return true; |
42 | } | 46 | } |
43 | QString Config::value( const QString& key ) { | 47 | QString Config::value( const QString& key ) { |
44 | return m_list[key]; | 48 | return m_list[key]; |
45 | } | 49 | } |
46 | }; | 50 | }; |
51 | |||
52 | |||
53 | using namespace Opie::DB; | ||
54 | |||
47 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) | 55 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) |
48 | :m_path( path ) | 56 | :m_path( path ) |
49 | { | 57 | { |
50 | } | 58 | } |
51 | OSQLBackEndManager::~OSQLBackEndManager() { | 59 | OSQLBackEndManager::~OSQLBackEndManager() { |
52 | } | 60 | } |
53 | /** | 61 | /** |
54 | * scan dirs | 62 | * scan dirs |
55 | */ | 63 | */ |
56 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { | 64 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { |
57 | OSQLBackEnd::ValueList list; | 65 | OSQLBackEnd::ValueList list; |
58 | if (!m_path.isEmpty() ) { | 66 | if (!m_path.isEmpty() ) { |
59 | QStringList::Iterator it; | 67 | QStringList::Iterator it; |
60 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { | 68 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { |
61 | list += scanDir( (*it) ); | 69 | list += scanDir( (*it) ); |
62 | } | 70 | } |
63 | } | 71 | } |
64 | return list; | 72 | return list; |
65 | } | 73 | } |
66 | /** | 74 | /** |
67 | * scan a specified dir for *.osql | 75 | * scan a specified dir for *.osql |
68 | */ | 76 | */ |
69 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { | 77 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { |
70 | OSQLBackEnd::ValueList list; | 78 | OSQLBackEnd::ValueList list; |
71 | QDir dir( dirName ); | 79 | QDir dir( dirName ); |
72 | if (dir.exists() ) { | 80 | if (dir.exists() ) { |
73 | QStringList files = dir.entryList( "*.osql" ); | 81 | QStringList files = dir.entryList( "*.osql" ); |
74 | QStringList::Iterator it; | 82 | QStringList::Iterator it; |
75 | for ( it = files.begin(); it != files.end(); ++it ) { | 83 | for ( it = files.begin(); it != files.end(); ++it ) { |
76 | list.append( file2backend( (*it) ) ); | 84 | list.append( file2backend( (*it) ) ); |
77 | } | 85 | } |
78 | } | 86 | } |
79 | return list; | 87 | return list; |
80 | } | 88 | } |
81 | 89 | ||
82 | /** | 90 | /** |
83 | * read a config file and convert it to a OSQLBackEnd | 91 | * read a config file and convert it to a OSQLBackEnd |
84 | */ | 92 | */ |
85 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { | 93 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { |
86 | OSQLBackEnd end; | 94 | OSQLBackEnd end; |
87 | qWarning("fileName: " + file ); | 95 | qWarning("fileName: " + file ); |
88 | Config cfg( file ); | 96 | Config cfg( file ); |
89 | if (cfg.load() ) { | 97 | if (cfg.load() ) { |
90 | end.setName( cfg.value( "Name") ); | 98 | end.setName( cfg.value( "Name") ); |
91 | end.setVendor( cfg.value("Vendor") ); | 99 | end.setVendor( cfg.value("Vendor") ); |
92 | end.setLicense( cfg.value("License") ); | 100 | end.setLicense( cfg.value("License") ); |
93 | end.setLibrary( cfg.value("Library").local8Bit() ); | 101 | end.setLibrary( cfg.value("Library").local8Bit() ); |
94 | end.setDefault( cfg.value("Default").toInt() ); | 102 | end.setDefault( cfg.value("Default").toInt() ); |
95 | end.setPreference( cfg.value("Preference").toInt() ); | 103 | end.setPreference( cfg.value("Preference").toInt() ); |
96 | } | 104 | } |
97 | return end; | 105 | return end; |
98 | } | 106 | } |