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