Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 103 |
1 files changed, 62 insertions, 41 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 06421d1..d101373 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -2,3 +2,3 @@ | |||
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
@@ -40,2 +40,3 @@ | |||
40 | 40 | ||
41 | #include <opie2/opimglobal.h> | ||
41 | #include <opie2/otodoaccessxml.h> | 42 | #include <opie2/otodoaccessxml.h> |
@@ -50,2 +51,5 @@ | |||
50 | 51 | ||
52 | using namespace Opie; | ||
53 | using namespace Opie::Pim; | ||
54 | |||
51 | namespace Opie { | 55 | namespace Opie { |
@@ -59,3 +63,3 @@ class OBackendPrivate; | |||
59 | * to recompile.# | 63 | * to recompile.# |
60 | * This class as the whole PIM Api is making use of templates | 64 | * This class - as the whole PIM Api - is making use of templates |
61 | * | 65 | * |
@@ -75,40 +79,19 @@ class OBackendFactory | |||
75 | 79 | ||
76 | enum BACKENDS { | ||
77 | TODO, | ||
78 | CONTACT, | ||
79 | DATE | ||
80 | }; | ||
81 | |||
82 | /** | 80 | /** |
83 | * Returns a backend implementation for backendName | 81 | * Returns a backend implementation |
84 | * @param backendName the type of the backend | 82 | * @param type the type of the backend |
85 | * @param appName will be passed on to the backend | 83 | * @param database the type of the used database |
84 | * @param appName The name of your application. It will be passed on to the backend. | ||
86 | */ | 85 | */ |
87 | static T* Default( const QString backendName, const QString& appName ){ | 86 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
88 | 87 | const QString& appName ){ | |
89 | // __asm__("int3"); | 88 | qWarning("Selected backend for %d is: %d", type, database ); |
90 | |||
91 | Config config( "pimaccess" ); | ||
92 | config.setGroup ( backendName ); | ||
93 | QString backend = config.readEntry( "usebackend" ); | ||
94 | 89 | ||
95 | qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); | 90 | switch ( type ){ |
96 | 91 | case OPimGlobal::TODOLIST: | |
97 | QAsciiDict<int> dict ( 3 ); | ||
98 | dict.setAutoDelete ( TRUE ); | ||
99 | |||
100 | dict.insert( "todo", new int (TODO) ); | ||
101 | dict.insert( "contact", new int (CONTACT) ); | ||
102 | dict.insert( "datebook", new int(DATE) ); | ||
103 | |||
104 | int *find = dict[ backendName ]; | ||
105 | if (!find ) return 0; | ||
106 | |||
107 | switch ( *find ){ | ||
108 | case TODO: | ||
109 | #ifdef __USE_SQL | 92 | #ifdef __USE_SQL |
110 | if ( backend == "sql" ) | 93 | if ( database == OPimGlobal::SQL ) |
111 | return (T*) new OPimTodoAccessBackendSQL(""); | 94 | return (T*) new OPimTodoAccessBackendSQL(""); |
112 | #else | 95 | #else |
113 | if ( backend == "sql" ) | 96 | if ( database == OPimGlobal::SQL ) |
114 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 97 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
@@ -117,8 +100,8 @@ class OBackendFactory | |||
117 | return (T*) new OPimTodoAccessXML( appName ); | 100 | return (T*) new OPimTodoAccessXML( appName ); |
118 | case CONTACT: | 101 | case OPimGlobal::CONTACTLIST: |
119 | #ifdef __USE_SQL | 102 | #ifdef __USE_SQL |
120 | if ( backend == "sql" ) | 103 | if ( database == OPimGlobal::SQL ) |
121 | return (T*) new OPimContactAccessBackend_SQL(""); | 104 | return (T*) new OPimContactAccessBackend_SQL(""); |
122 | #else | 105 | #else |
123 | if ( backend == "sql" ) | 106 | if ( database == OPimGlobal::SQL ) |
124 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 107 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
@@ -127,8 +110,8 @@ class OBackendFactory | |||
127 | return (T*) new OPimContactAccessBackend_XML( appName ); | 110 | return (T*) new OPimContactAccessBackend_XML( appName ); |
128 | case DATE: | 111 | case OPimGlobal::DATEBOOK: |
129 | #ifdef __USE_SQL | 112 | #ifdef __USE_SQL |
130 | if ( backend == "sql" ) | 113 | if ( database == OPimGlobal::SQL ) |
131 | return (T*) new ODateBookAccessBackend_SQL(""); | 114 | return (T*) new ODateBookAccessBackend_SQL(""); |
132 | #else | 115 | #else |
133 | if ( backend == "sql" ) | 116 | if ( database == OPimGlobal::SQL ) |
134 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 117 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); |
@@ -138,3 +121,3 @@ class OBackendFactory | |||
138 | default: | 121 | default: |
139 | return NULL; | 122 | return (T*) NULL; |
140 | } | 123 | } |
@@ -143,4 +126,42 @@ class OBackendFactory | |||
143 | } | 126 | } |
127 | |||
128 | /** | ||
129 | * Returns the default backend implementation for backendName. Which one is used, is defined | ||
130 | * by the configfile "pimaccess.conf". | ||
131 | * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) | ||
132 | * @param appName The name of your application. It will be passed on to the backend | ||
133 | */ | ||
134 | static T* Default( const QString backendName, const QString& appName ){ | ||
135 | |||
136 | QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); | ||
137 | dictBackends.setAutoDelete ( TRUE ); | ||
138 | |||
139 | dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); | ||
140 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); | ||
141 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); | ||
142 | |||
143 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | ||
144 | dictDbTypes.setAutoDelete( TRUE ); | ||
145 | |||
146 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | ||
147 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | ||
148 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | ||
149 | |||
150 | Config config( "pimaccess" ); | ||
151 | config.setGroup ( backendName ); | ||
152 | QString db_String = config.readEntry( "usebackend" ); | ||
153 | |||
154 | int* db_find = dictDbTypes[ db_String ]; | ||
155 | int* backend_find = dictBackends[ backendName ]; | ||
156 | if ( !backend_find || !db_find ) return NULL; | ||
157 | |||
158 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %s", backendName.latin1(), | ||
159 | db_String.latin1() ); | ||
160 | |||
161 | return create( (OPimGlobal::PimType) *backend_find, (OPimGlobal::DatabaseStyle) *db_find, appName ); | ||
162 | |||
163 | } | ||
144 | private: | 164 | private: |
145 | OBackendPrivate* d; | 165 | OBackendPrivate* d; |
166 | |||
146 | }; | 167 | }; |