summaryrefslogtreecommitdiff
path: root/libsql/osqlmanager.cpp
Unidiff
Diffstat (limited to 'libsql/osqlmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libsql/osqlmanager.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/libsql/osqlmanager.cpp b/libsql/osqlmanager.cpp
new file mode 100644
index 0000000..b0fea04
--- a/dev/null
+++ b/libsql/osqlmanager.cpp
@@ -0,0 +1,83 @@
1
2#include <stdlib.h>
3
4#include "osqlbackend.h"
5#include "osqldriver.h"
6#include "osqlmanager.h"
7#include "osqlbackendmanager.h"
8#include "osqlitedriver.h"
9
10OSQLManager::OSQLManager() {
11}
12OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
13 m_list.clear();
14 QString opie = QString::fromLatin1( getenv("OPIEDIR") );
15 QString qpe = QString::fromLatin1( getenv("QPEDIR") );
16
17 if ( !m_path.contains(opie) && !opie.isEmpty() )
18 m_path << opie;
19 if ( !m_path.contains(qpe) && !qpe.isEmpty() )
20 m_path << qpe;
21
22 OSQLBackEndManager mng( m_path );
23 m_list = mng.scan();
24 m_list += builtIn();
25
26 return m_list;
27}
28/*
29 * loading dso's is currently not enabled due problems with QLibrary
30 * beeing in libqpe and not libqte
31 */
32OSQLDriver* OSQLManager::load( const QString& name ) {
33 OSQLDriver* driver = 0l;
34
35 if ( name == "SQLite" ) {
36 driver = new OSQLiteDriver();
37 }
38 return driver;
39}
40/*
41 * same as above
42 */
43OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) {
44 OSQLDriver *driver = 0l;
45 if ( end.library() == "builtin" &&
46 end.name() == "SQLite" )
47 driver = new OSQLiteDriver();
48
49 return driver;
50}
51/*
52 * let's find the a default with the highes preference
53 */
54OSQLDriver* OSQLManager::standard() {
55 OSQLDriver* driver =0l;
56 if ( m_list.isEmpty() ) queryBackEnd();
57 OSQLBackEnd::ValueList::Iterator it;
58 OSQLBackEnd back;
59 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
60 if ( (*it).isDefault() &&
61 back.preference() < (*it).preference() ) {
62 back = (*it);
63 }
64 }
65 driver = load( back );
66 return driver;
67}
68void OSQLManager::registerPath( const QString& path ) {
69 m_path << path;
70}
71bool OSQLManager::unregisterPath( const QString& path ) {
72 m_path.remove( path );
73 return true;
74}
75OSQLBackEnd::ValueList OSQLManager::builtIn()const {
76 OSQLBackEnd::ValueList list;
77 // create the OSQLiteBackend
78 OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" );
79 back.setDefault( true );
80 back.setPreference( 50 );
81 list.append( back );
82 return list;
83}