Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index ad6cf5a..f3c339d 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,154 +1,166 @@ | |||
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.7 2003/08/01 12:30:16 eilers | ||
20 | * Merging changes from BRANCH_1_0 to HEAD | ||
21 | * | ||
22 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers | ||
23 | * Patches from Zecke: | ||
24 | * Fixing and cleaning up extraMap handling | ||
25 | * Adding d_ptr for binary compatibility in the future | ||
26 | * | ||
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | 27 | * Revision 1.6 2003/04/13 18:07:10 zecke |
20 | * More API doc | 28 | * More API doc |
21 | * QString -> const QString& | 29 | * QString -> const QString& |
22 | * QString = 0l -> QString::null | 30 | * QString = 0l -> QString::null |
23 | * | 31 | * |
24 | * Revision 1.5 2003/02/21 23:31:52 zecke | 32 | * Revision 1.5 2003/02/21 23:31:52 zecke |
25 | * Add XML datebookresource | 33 | * Add XML datebookresource |
26 | * -clean up todoaccessxml header | 34 | * -clean up todoaccessxml header |
27 | * -implement some more stuff in the oeven tester | 35 | * -implement some more stuff in the oeven tester |
28 | * -extend DefaultFactory to not crash and to use datebook | 36 | * -extend DefaultFactory to not crash and to use datebook |
29 | * | 37 | * |
30 | * -reading of OEvents is working nicely.. saving will be added | 38 | * -reading of OEvents is working nicely.. saving will be added |
31 | * tomorrow | 39 | * tomorrow |
32 | * -fix spelling in ODateBookAcces | 40 | * -fix spelling in ODateBookAcces |
33 | * | 41 | * |
34 | * Revision 1.4 2002/10/14 15:55:18 eilers | 42 | * Revision 1.4 2002/10/14 15:55:18 eilers |
35 | * Redeactivate SQL.. ;) | 43 | * Redeactivate SQL.. ;) |
36 | * | 44 | * |
37 | * Revision 1.3 2002/10/10 17:08:58 zecke | 45 | * Revision 1.3 2002/10/10 17:08:58 zecke |
38 | * The Cache is finally in place | 46 | * The Cache is finally in place |
39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 47 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
40 | * 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.... | 48 | * 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.... |
41 | * I still have to fully implement read ahead | 49 | * I still have to fully implement read ahead |
42 | * This change is bic but sc | 50 | * This change is bic but sc |
43 | * | 51 | * |
44 | * Revision 1.2 2002/10/08 09:27:36 eilers | 52 | * Revision 1.2 2002/10/08 09:27:36 eilers |
45 | * Fixed libopie.pro to include the new pim-API. | 53 | * Fixed libopie.pro to include the new pim-API. |
46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 54 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
47 | * compile itself would need to install libsqlite, libopiesql... | 55 | * compile itself would need to install libsqlite, libopiesql... |
48 | * Therefore, the backend currently uses XML only.. | 56 | * Therefore, the backend currently uses XML only.. |
49 | * | 57 | * |
50 | * Revision 1.1 2002/10/07 17:35:01 eilers | 58 | * Revision 1.1 2002/10/07 17:35:01 eilers |
51 | * added OBackendFactory for advanced backend access | 59 | * added OBackendFactory for advanced backend access |
52 | * | 60 | * |
53 | * | 61 | * |
54 | * ===================================================================== | 62 | * ===================================================================== |
55 | */ | 63 | */ |
56 | #ifndef OPIE_BACKENDFACTORY_H_ | 64 | #ifndef OPIE_BACKENDFACTORY_H_ |
57 | #define OPIE_BACKENDFACTORY_H_ | 65 | #define OPIE_BACKENDFACTORY_H_ |
58 | 66 | ||
59 | #include <qstring.h> | 67 | #include <qstring.h> |
60 | #include <qasciidict.h> | 68 | #include <qasciidict.h> |
61 | #include <qpe/config.h> | 69 | #include <qpe/config.h> |
62 | 70 | ||
63 | #include "otodoaccessxml.h" | 71 | #include "otodoaccessxml.h" |
64 | #include "ocontactaccessbackend_xml.h" | 72 | #include "ocontactaccessbackend_xml.h" |
65 | #include "odatebookaccessbackend_xml.h" | 73 | #include "odatebookaccessbackend_xml.h" |
66 | 74 | ||
67 | #ifdef __USE_SQL | 75 | #ifdef __USE_SQL |
68 | #include "otodoaccesssql.h" | 76 | #include "otodoaccesssql.h" |
69 | #endif | 77 | #endif |
70 | 78 | ||
79 | class OBackendPrivate; | ||
80 | |||
71 | /** | 81 | /** |
72 | * This class is our factory. It will give us the default implementations | 82 | * This class is our factory. It will give us the default implementations |
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | 83 | * of at least Todolist, Contacts and Datebook. In the future this class will |
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | 84 | * allow users to switch the backend with ( XML->SQLite ) without the need |
75 | * to recompile.# | 85 | * to recompile.# |
76 | * This class as the whole PIM Api is making use of templates | 86 | * This class as the whole PIM Api is making use of templates |
77 | * | 87 | * |
78 | * <pre> | 88 | * <pre> |
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | 89 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); |
80 | * backend->load(); | 90 | * backend->load(); |
81 | * </pre> | 91 | * </pre> |
82 | * | 92 | * |
83 | * @author Stefan Eilers | 93 | * @author Stefan Eilers |
84 | * @version 0.1 | 94 | * @version 0.1 |
85 | */ | 95 | */ |
86 | template<class T> | 96 | template<class T> |
87 | class OBackendFactory | 97 | class OBackendFactory |
88 | { | 98 | { |
89 | public: | 99 | public: |
90 | OBackendFactory() {}; | 100 | OBackendFactory() {}; |
91 | 101 | ||
92 | enum BACKENDS { | 102 | enum BACKENDS { |
93 | TODO, | 103 | TODO, |
94 | CONTACT, | 104 | CONTACT, |
95 | DATE | 105 | DATE |
96 | }; | 106 | }; |
97 | 107 | ||
98 | /** | 108 | /** |
99 | * Returns a backend implementation for backendName | 109 | * Returns a backend implementation for backendName |
100 | * @param backendName the type of the backend | 110 | * @param backendName the type of the backend |
101 | * @param appName will be passed on to the backend | 111 | * @param appName will be passed on to the backend |
102 | */ | 112 | */ |
103 | static T* Default( const QString backendName, const QString& appName ){ | 113 | static T* Default( const QString backendName, const QString& appName ){ |
104 | 114 | ||
105 | // __asm__("int3"); | 115 | // __asm__("int3"); |
106 | 116 | ||
107 | Config config( "pimaccess" ); | 117 | Config config( "pimaccess" ); |
108 | config.setGroup ( backendName ); | 118 | config.setGroup ( backendName ); |
109 | QString backend = config.readEntry( "usebackend" ); | 119 | QString backend = config.readEntry( "usebackend" ); |
110 | 120 | ||
111 | QAsciiDict<int> dict ( 3 ); | 121 | QAsciiDict<int> dict ( 3 ); |
112 | dict.setAutoDelete ( TRUE ); | 122 | dict.setAutoDelete ( TRUE ); |
113 | 123 | ||
114 | dict.insert( "todo", new int (TODO) ); | 124 | dict.insert( "todo", new int (TODO) ); |
115 | dict.insert( "contact", new int (CONTACT) ); | 125 | dict.insert( "contact", new int (CONTACT) ); |
116 | dict.insert( "datebook", new int(DATE) ); | 126 | dict.insert( "datebook", new int(DATE) ); |
117 | 127 | ||
118 | qWarning ("TODO is: %d", TODO); | 128 | qWarning ("TODO is: %d", TODO); |
119 | qWarning ("CONTACT is: %d", CONTACT); | 129 | qWarning ("CONTACT is: %d", CONTACT); |
120 | 130 | ||
121 | int *find = dict[ backendName ]; | 131 | int *find = dict[ backendName ]; |
122 | if (!find ) return 0; | 132 | if (!find ) return 0; |
123 | 133 | ||
124 | switch ( *find ){ | 134 | switch ( *find ){ |
125 | case TODO: | 135 | case TODO: |
126 | #ifdef __USE_SQL | 136 | #ifdef __USE_SQL |
127 | if ( backend == "sql" ) | 137 | if ( backend == "sql" ) |
128 | return (T*) new OTodoAccessBackendSQL(""); | 138 | return (T*) new OTodoAccessBackendSQL(""); |
129 | #else | 139 | #else |
130 | if ( backend == "sql" ) | 140 | if ( backend == "sql" ) |
131 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 141 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
132 | #endif | 142 | #endif |
133 | 143 | ||
134 | return (T*) new OTodoAccessXML( appName ); | 144 | return (T*) new OTodoAccessXML( appName ); |
135 | case CONTACT: | 145 | case CONTACT: |
136 | if ( backend == "sql" ) | 146 | if ( backend == "sql" ) |
137 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 147 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
138 | 148 | ||
139 | return (T*) new OContactAccessBackend_XML( appName ); | 149 | return (T*) new OContactAccessBackend_XML( appName ); |
140 | case DATE: | 150 | case DATE: |
141 | if ( backend == "sql" ) | 151 | if ( backend == "sql" ) |
142 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 152 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
143 | 153 | ||
144 | return (T*) new ODateBookAccessBackend_XML( appName ); | 154 | return (T*) new ODateBookAccessBackend_XML( appName ); |
145 | default: | 155 | default: |
146 | return NULL; | 156 | return NULL; |
147 | } | 157 | } |
148 | 158 | ||
149 | 159 | ||
150 | } | 160 | } |
161 | private: | ||
162 | OBackendPrivate* d; | ||
151 | }; | 163 | }; |
152 | 164 | ||
153 | 165 | ||
154 | #endif | 166 | #endif |