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