summaryrefslogtreecommitdiff
path: root/libopie2/opiedb/osqlmanager.cpp
blob: f09376628af034e4d8e7bde402dc6c4d193a133d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

#include <stdlib.h>

#include "osqlmanager.h"
#include "osqlbackendmanager.h"
#include "osqlitedriver.h"

namespace Opie {
namespace DB {

OSQLManager::OSQLManager() {
}
OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
    m_list.clear();
    QString opie = QString::fromLatin1( getenv("OPIEDIR") );
    QString qpe = QString::fromLatin1( getenv("QPEDIR") );

    if ( !m_path.contains(opie) && !opie.isEmpty() )
        m_path << opie;
    if ( !m_path.contains(qpe) && !qpe.isEmpty() )
        m_path << qpe;

    OSQLBackEndManager mng( m_path );
    m_list = mng.scan();
    m_list += builtIn();

    return m_list;
}
/*
 * loading dso's is currently not enabled due problems with QLibrary
 * beeing in libqpe and not libqte
 */
OSQLDriver* OSQLManager::load( const QString& name ) {
    OSQLDriver* driver = 0l;

    if ( name == "SQLite" ) {
        driver = new Opie::DB::Internal::OSQLiteDriver;
    }
    return driver;
}
/*
 * same as above
 */
OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) {
    OSQLDriver *driver = 0l;
    if ( end.library() == "builtin" &&
         end.name() == "SQLite" )
        driver = new Opie::DB::Internal::OSQLiteDriver;

    return driver;
}
/*
 * let's find the a default with the highes preference
 */
OSQLDriver* OSQLManager::standard() {
    OSQLDriver* driver =0l;
    if ( m_list.isEmpty() ) queryBackEnd();
    OSQLBackEnd::ValueList::Iterator it;
    OSQLBackEnd back;
    for ( it = m_list.begin(); it != m_list.end(); ++it ) {
        if ( (*it).isDefault() &&
             back.preference() < (*it).preference() ) {
            back = (*it);
        }
    }
    driver = load( back );
    return driver;
}
void OSQLManager::registerPath( const QString& path ) {
    m_path << path;
}
bool OSQLManager::unregisterPath( const QString& path ) {
    m_path.remove( path );
    return true;
}
OSQLBackEnd::ValueList OSQLManager::builtIn()const {
    OSQLBackEnd::ValueList list;
    // create the OSQLiteBackend
    OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" );
    back.setDefault( true );
    back.setPreference( 50 );
    list.append( back );
    return list;
}


}
}