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