Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 3567687..761ab9a 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,42 +1,54 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | * Class to manage Backends. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; | 9 | * License as published by the Free Software Foundation; |
10 | * either version 2 of the License, or (at your option) any later | 10 | * either version 2 of the License, or (at your option) any later |
11 | * version. | 11 | * version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: Use plugins | 13 | * ToDo: Use plugins |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * Version: $Id$ | 15 | * Version: $Id$ |
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.9 2003/12/22 10:19:26 eilers | ||
20 | * Finishing implementation of sql-backend for datebook. But I have to | ||
21 | * port the PIM datebook application to use it, before I could debug the | ||
22 | * whole stuff. | ||
23 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
24 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
25 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
26 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
27 | * expression search in the database, which is not supported by sqlite ! | ||
28 | * Therefore we need either an extended sqlite or a workaround which would | ||
29 | * be very slow and memory consuming.. | ||
30 | * | ||
19 | * Revision 1.8 2003/09/22 14:31:16 eilers | 31 | * Revision 1.8 2003/09/22 14:31:16 eilers |
20 | * Added first experimental incarnation of sql-backend for addressbook. | 32 | * Added first experimental incarnation of sql-backend for addressbook. |
21 | * Some modifications to be able to compile the todo sql-backend. | 33 | * Some modifications to be able to compile the todo sql-backend. |
22 | * A lot of changes fill follow... | 34 | * A lot of changes fill follow... |
23 | * | 35 | * |
24 | * Revision 1.7 2003/08/01 12:30:16 eilers | 36 | * Revision 1.7 2003/08/01 12:30:16 eilers |
25 | * Merging changes from BRANCH_1_0 to HEAD | 37 | * Merging changes from BRANCH_1_0 to HEAD |
26 | * | 38 | * |
27 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers | 39 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers |
28 | * Patches from Zecke: | 40 | * Patches from Zecke: |
29 | * Fixing and cleaning up extraMap handling | 41 | * Fixing and cleaning up extraMap handling |
30 | * Adding d_ptr for binary compatibility in the future | 42 | * Adding d_ptr for binary compatibility in the future |
31 | * | 43 | * |
32 | * Revision 1.6 2003/04/13 18:07:10 zecke | 44 | * Revision 1.6 2003/04/13 18:07:10 zecke |
33 | * More API doc | 45 | * More API doc |
34 | * QString -> const QString& | 46 | * QString -> const QString& |
35 | * QString = 0l -> QString::null | 47 | * QString = 0l -> QString::null |
36 | * | 48 | * |
37 | * Revision 1.5 2003/02/21 23:31:52 zecke | 49 | * Revision 1.5 2003/02/21 23:31:52 zecke |
38 | * Add XML datebookresource | 50 | * Add XML datebookresource |
39 | * -clean up todoaccessxml header | 51 | * -clean up todoaccessxml header |
40 | * -implement some more stuff in the oeven tester | 52 | * -implement some more stuff in the oeven tester |
41 | * -extend DefaultFactory to not crash and to use datebook | 53 | * -extend DefaultFactory to not crash and to use datebook |
42 | * | 54 | * |
@@ -59,48 +71,49 @@ | |||
59 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 71 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
60 | * compile itself would need to install libsqlite, libopiesql... | 72 | * compile itself would need to install libsqlite, libopiesql... |
61 | * Therefore, the backend currently uses XML only.. | 73 | * Therefore, the backend currently uses XML only.. |
62 | * | 74 | * |
63 | * Revision 1.1 2002/10/07 17:35:01 eilers | 75 | * Revision 1.1 2002/10/07 17:35:01 eilers |
64 | * added OBackendFactory for advanced backend access | 76 | * added OBackendFactory for advanced backend access |
65 | * | 77 | * |
66 | * | 78 | * |
67 | * ===================================================================== | 79 | * ===================================================================== |
68 | */ | 80 | */ |
69 | #ifndef OPIE_BACKENDFACTORY_H_ | 81 | #ifndef OPIE_BACKENDFACTORY_H_ |
70 | #define OPIE_BACKENDFACTORY_H_ | 82 | #define OPIE_BACKENDFACTORY_H_ |
71 | 83 | ||
72 | #include <qstring.h> | 84 | #include <qstring.h> |
73 | #include <qasciidict.h> | 85 | #include <qasciidict.h> |
74 | #include <qpe/config.h> | 86 | #include <qpe/config.h> |
75 | 87 | ||
76 | #include "otodoaccessxml.h" | 88 | #include "otodoaccessxml.h" |
77 | #include "ocontactaccessbackend_xml.h" | 89 | #include "ocontactaccessbackend_xml.h" |
78 | #include "odatebookaccessbackend_xml.h" | 90 | #include "odatebookaccessbackend_xml.h" |
79 | 91 | ||
80 | #ifdef __USE_SQL | 92 | #ifdef __USE_SQL |
81 | #include "otodoaccesssql.h" | 93 | #include "otodoaccesssql.h" |
82 | #include "ocontactaccessbackend_sql.h" | 94 | #include "ocontactaccessbackend_sql.h" |
95 | #include "odatebookaccessbackend_sql.h" | ||
83 | #endif | 96 | #endif |
84 | 97 | ||
85 | class OBackendPrivate; | 98 | class OBackendPrivate; |
86 | 99 | ||
87 | /** | 100 | /** |
88 | * This class is our factory. It will give us the default implementations | 101 | * This class is our factory. It will give us the default implementations |
89 | * of at least Todolist, Contacts and Datebook. In the future this class will | 102 | * of at least Todolist, Contacts and Datebook. In the future this class will |
90 | * allow users to switch the backend with ( XML->SQLite ) without the need | 103 | * allow users to switch the backend with ( XML->SQLite ) without the need |
91 | * to recompile.# | 104 | * to recompile.# |
92 | * This class as the whole PIM Api is making use of templates | 105 | * This class as the whole PIM Api is making use of templates |
93 | * | 106 | * |
94 | * <pre> | 107 | * <pre> |
95 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | 108 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); |
96 | * backend->load(); | 109 | * backend->load(); |
97 | * </pre> | 110 | * </pre> |
98 | * | 111 | * |
99 | * @author Stefan Eilers | 112 | * @author Stefan Eilers |
100 | * @version 0.1 | 113 | * @version 0.1 |
101 | */ | 114 | */ |
102 | template<class T> | 115 | template<class T> |
103 | class OBackendFactory | 116 | class OBackendFactory |
104 | { | 117 | { |
105 | public: | 118 | public: |
106 | OBackendFactory() {}; | 119 | OBackendFactory() {}; |
@@ -122,55 +135,60 @@ class OBackendFactory | |||
122 | 135 | ||
123 | Config config( "pimaccess" ); | 136 | Config config( "pimaccess" ); |
124 | config.setGroup ( backendName ); | 137 | config.setGroup ( backendName ); |
125 | QString backend = config.readEntry( "usebackend" ); | 138 | QString backend = config.readEntry( "usebackend" ); |
126 | 139 | ||
127 | qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); | 140 | qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); |
128 | 141 | ||
129 | QAsciiDict<int> dict ( 3 ); | 142 | QAsciiDict<int> dict ( 3 ); |
130 | dict.setAutoDelete ( TRUE ); | 143 | dict.setAutoDelete ( TRUE ); |
131 | 144 | ||
132 | dict.insert( "todo", new int (TODO) ); | 145 | dict.insert( "todo", new int (TODO) ); |
133 | dict.insert( "contact", new int (CONTACT) ); | 146 | dict.insert( "contact", new int (CONTACT) ); |
134 | dict.insert( "datebook", new int(DATE) ); | 147 | dict.insert( "datebook", new int(DATE) ); |
135 | 148 | ||
136 | int *find = dict[ backendName ]; | 149 | int *find = dict[ backendName ]; |
137 | if (!find ) return 0; | 150 | if (!find ) return 0; |
138 | 151 | ||
139 | switch ( *find ){ | 152 | switch ( *find ){ |
140 | case TODO: | 153 | case TODO: |
141 | #ifdef __USE_SQL | 154 | #ifdef __USE_SQL |
142 | if ( backend == "sql" ) | 155 | if ( backend == "sql" ) |
143 | return (T*) new OTodoAccessBackendSQL(""); | 156 | return (T*) new OTodoAccessBackendSQL(""); |
144 | #else | 157 | #else |
145 | if ( backend == "sql" ) | 158 | if ( backend == "sql" ) |
146 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 159 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
147 | #endif | 160 | #endif |
148 | 161 | ||
149 | return (T*) new OTodoAccessXML( appName ); | 162 | return (T*) new OTodoAccessXML( appName ); |
150 | case CONTACT: | 163 | case CONTACT: |
151 | #ifdef __USE_SQL | 164 | #ifdef __USE_SQL |
152 | if ( backend == "sql" ) | 165 | if ( backend == "sql" ) |
153 | return (T*) new OContactAccessBackend_SQL(""); | 166 | return (T*) new OContactAccessBackend_SQL(""); |
154 | #else | 167 | #else |
155 | if ( backend == "sql" ) | 168 | if ( backend == "sql" ) |
156 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 169 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
157 | #endif | 170 | #endif |
158 | 171 | ||
159 | return (T*) new OContactAccessBackend_XML( appName ); | 172 | return (T*) new OContactAccessBackend_XML( appName ); |
160 | case DATE: | 173 | case DATE: |
174 | #ifdef __USE_SQL | ||
161 | if ( backend == "sql" ) | 175 | if ( backend == "sql" ) |
162 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 176 | return (T*) new ODateBookAccessBackend_SQL(""); |
177 | #else | ||
178 | if ( backend == "sql" ) | ||
179 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | ||
180 | #endif | ||
163 | 181 | ||
164 | return (T*) new ODateBookAccessBackend_XML( appName ); | 182 | return (T*) new ODateBookAccessBackend_XML( appName ); |
165 | default: | 183 | default: |
166 | return NULL; | 184 | return NULL; |
167 | } | 185 | } |
168 | 186 | ||
169 | 187 | ||
170 | } | 188 | } |
171 | private: | 189 | private: |
172 | OBackendPrivate* d; | 190 | OBackendPrivate* d; |
173 | }; | 191 | }; |
174 | 192 | ||
175 | 193 | ||
176 | #endif | 194 | #endif |