-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 4daf861..4bedbef 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,208 +1,208 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | 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> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: Use plugins | 31 | * ToDo: Use plugins |
32 | * ===================================================================== | 32 | * ===================================================================== |
33 | */ | 33 | */ |
34 | #ifndef OPIE_BACKENDFACTORY_H_ | 34 | #ifndef OPIE_BACKENDFACTORY_H_ |
35 | #define OPIE_BACKENDFACTORY_H_ | 35 | #define OPIE_BACKENDFACTORY_H_ |
36 | 36 | ||
37 | #include <qstring.h> | 37 | #include <qstring.h> |
38 | #include <qasciidict.h> | 38 | #include <qasciidict.h> |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | 40 | ||
41 | #include <opie2/opimglobal.h> | 41 | #include <opie2/opimglobal.h> |
42 | #include <opie2/otodoaccessxml.h> | 42 | #include <opie2/otodoaccessxml.h> |
43 | #include <opie2/ocontactaccessbackend_xml.h> | 43 | #include <opie2/ocontactaccessbackend_xml.h> |
44 | #include <opie2/odatebookaccessbackend_xml.h> | 44 | #include <opie2/odatebookaccessbackend_xml.h> |
45 | 45 | ||
46 | #ifdef __USE_SQL | 46 | #ifdef __USE_SQL |
47 | #include <opie2/otodoaccesssql.h> | 47 | #include <opie2/otodoaccesssql.h> |
48 | #include <opie2/ocontactaccessbackend_sql.h> | 48 | #include <opie2/ocontactaccessbackend_sql.h> |
49 | #include <opie2/odatebookaccessbackend_sql.h> | 49 | #include <opie2/odatebookaccessbackend_sql.h> |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | using namespace Opie; | 52 | using namespace Opie; |
53 | using namespace Opie::Pim; | 53 | using namespace Opie::Pim; |
54 | 54 | ||
55 | namespace Opie { | 55 | namespace Opie { |
56 | 56 | ||
57 | class OBackendPrivate; | 57 | class OBackendPrivate; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * This class is our factory. It will give us the default implementations | 60 | * This class is our factory. It will give us the default implementations |
61 | * of at least Todolist, Contacts and Datebook. In the future this class will | 61 | * of at least Todolist, Contacts and Datebook. In the future this class will |
62 | * allow users to switch the backend with ( XML->SQLite ) without the need | 62 | * allow users to switch the backend with ( XML->SQLite ) without the need |
63 | * to recompile.# | 63 | * to recompile.# |
64 | * 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 |
65 | * | 65 | * |
66 | * <pre> | 66 | * <pre> |
67 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); | 67 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); |
68 | * backend->load(); | 68 | * backend->load(); |
69 | * </pre> | 69 | * </pre> |
70 | * | 70 | * |
71 | * @author Stefan Eilers | 71 | * @author Stefan Eilers |
72 | * @version 0.1 | 72 | * @version 0.1 |
73 | */ | 73 | */ |
74 | template<class T> | 74 | template<class T> |
75 | class OBackendFactory | 75 | class OBackendFactory |
76 | { | 76 | { |
77 | public: | 77 | public: |
78 | OBackendFactory() {}; | 78 | OBackendFactory() {}; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Returns a selected backend implementation | 81 | * Returns a selected backend implementation |
82 | * @param type the type of the backend | 82 | * @param type the type of the backend |
83 | * @param database the type of the used database | 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. | 84 | * @param appName The name of your application. It will be passed on to the backend. |
85 | */ | 85 | */ |
86 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, | 86 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
87 | const QString& appName ){ | 87 | const QString& appName ){ |
88 | qWarning("Selected backend for %d is: %d", type, database ); | 88 | qWarning("Selected backend for %d is: %d", type, database ); |
89 | // If we should use the dafult database style, we have to request it | 89 | // If we should use the dafult database style, we have to request it |
90 | OPimGlobal::DatabaseStyle used_database = database; | 90 | OPimGlobal::DatabaseStyle used_database = database; |
91 | if ( database == OPimGlobal::DEFAULT ){ | 91 | if ( database == OPimGlobal::DEFAULT ){ |
92 | used_database = defaultDB( type ); | 92 | used_database = defaultDB( type ); |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | switch ( type ){ | 96 | switch ( type ){ |
97 | case OPimGlobal::TODOLIST: | 97 | case OPimGlobal::TODOLIST: |
98 | #ifdef __USE_SQL | 98 | #ifdef __USE_SQL |
99 | if ( used_database == OPimGlobal::SQL ) | 99 | if ( used_database == OPimGlobal::SQL ) |
100 | return (T*) new OPimTodoAccessBackendSQL(""); | 100 | return (T*) new OPimTodoAccessBackendSQL(""); |
101 | #else | 101 | #else |
102 | if ( used_database == OPimGlobal::SQL ) | 102 | if ( used_database == OPimGlobal::SQL ) |
103 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 103 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | return (T*) new OPimTodoAccessXML( appName ); | 106 | return (T*) new OPimTodoAccessXML( appName ); |
107 | case OPimGlobal::CONTACTLIST: | 107 | case OPimGlobal::CONTACTLIST: |
108 | #ifdef __USE_SQL | 108 | #ifdef __USE_SQL |
109 | if ( used_database == OPimGlobal::SQL ) | 109 | if ( used_database == OPimGlobal::SQL ) |
110 | return (T*) new OPimContactAccessBackend_SQL(""); | 110 | return (T*) new OPimContactAccessBackend_SQL(""); |
111 | #else | 111 | #else |
112 | if ( used_database == OPimGlobal::SQL ) | 112 | if ( used_database == OPimGlobal::SQL ) |
113 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 113 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | return (T*) new OPimContactAccessBackend_XML( appName ); | 116 | return (T*) new OPimContactAccessBackend_XML( appName ); |
117 | case OPimGlobal::DATEBOOK: | 117 | case OPimGlobal::DATEBOOK: |
118 | #ifdef __USE_SQL | 118 | #ifdef __USE_SQL |
119 | if ( used_database == OPimGlobal::SQL ) | 119 | if ( used_database == OPimGlobal::SQL ) |
120 | return (T*) new ODateBookAccessBackend_SQL(""); | 120 | return (T*) new ODateBookAccessBackend_SQL(""); |
121 | #else | 121 | #else |
122 | if ( used_database == OPimGlobal::SQL ) | 122 | if ( used_database == OPimGlobal::SQL ) |
123 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 123 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); |
124 | #endif | 124 | #endif |
125 | 125 | ||
126 | return (T*) new ODateBookAccessBackend_XML( appName ); | 126 | return (T*) new ODateBookAccessBackend_XML( appName ); |
127 | default: | 127 | default: |
128 | return (T*) NULL; | 128 | return (T*) NULL; |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | } | 132 | } |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Returns the style of the default database which is used to contact PIM data. | 135 | * Returns the style of the default database which is used to contact PIM data. |
136 | * @param type the type of the backend | 136 | * @param type the type of the backend |
137 | * @see OPimGlobal | 137 | * @see OPimGlobal |
138 | */ | 138 | */ |
139 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ | 139 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ |
140 | QString group_name; | 140 | QString group_name; |
141 | switch ( type ){ | 141 | switch ( type ){ |
142 | case OPimGlobal::TODOLIST: | 142 | case OPimGlobal::TODOLIST: |
143 | group_name = "todo"; | 143 | group_name = "todo"; |
144 | break; | 144 | break; |
145 | case OPimGlobal::CONTACTLIST: | 145 | case OPimGlobal::CONTACTLIST: |
146 | group_name = "contact"; | 146 | group_name = "contact"; |
147 | break; | 147 | break; |
148 | case OPimGlobal::DATEBOOK: | 148 | case OPimGlobal::DATEBOOK: |
149 | group_name = "datebook"; | 149 | group_name = "datebook"; |
150 | break; | 150 | break; |
151 | default: | 151 | default: |
152 | group_name = "unknown"; | 152 | group_name = "unknown"; |
153 | } | 153 | } |
154 | 154 | ||
155 | Config config( "pimaccess" ); | 155 | Config config( "pimaccess" ); |
156 | config.setGroup ( group_name ); | 156 | config.setGroup ( group_name ); |
157 | QString db_String = config.readEntry( "usebackend" ); | 157 | QString db_String = config.readEntry( "usebackend", "xml" ); |
158 | 158 | ||
159 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | 159 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); |
160 | dictDbTypes.setAutoDelete( TRUE ); | 160 | dictDbTypes.setAutoDelete( TRUE ); |
161 | 161 | ||
162 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | 162 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); |
163 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | 163 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); |
164 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | 164 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); |
165 | 165 | ||
166 | int* db_find = dictDbTypes[ db_String ]; | 166 | int* db_find = dictDbTypes[ db_String ]; |
167 | 167 | ||
168 | if ( !db_find ) | 168 | if ( !db_find ) |
169 | return OPimGlobal::UNKNOWN; | 169 | return OPimGlobal::UNKNOWN; |
170 | 170 | ||
171 | return (OPimGlobal::DatabaseStyle) *db_find; | 171 | return (OPimGlobal::DatabaseStyle) *db_find; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Returns the default backend implementation for backendName. Which one is used, is defined | 176 | * Returns the default backend implementation for backendName. Which one is used, is defined |
177 | * by the configfile "pimaccess.conf". | 177 | * by the configfile "pimaccess.conf". |
178 | * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) | 178 | * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) |
179 | * @param appName The name of your application. It will be passed on to the backend | 179 | * @param appName The name of your application. It will be passed on to the backend |
180 | */ | 180 | */ |
181 | static T* defaultBackend( const QString backendName, const QString& appName ){ | 181 | static T* defaultBackend( const QString backendName, const QString& appName ){ |
182 | 182 | ||
183 | QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); | 183 | QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); |
184 | dictBackends.setAutoDelete ( TRUE ); | 184 | dictBackends.setAutoDelete ( TRUE ); |
185 | 185 | ||
186 | dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); | 186 | dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); |
187 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); | 187 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); |
188 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); | 188 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); |
189 | 189 | ||
190 | int* backend_find = dictBackends[ backendName ]; | 190 | int* backend_find = dictBackends[ backendName ]; |
191 | if ( !backend_find ) return NULL; | 191 | if ( !backend_find ) return NULL; |
192 | 192 | ||
193 | OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) ); | 193 | OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) ); |
194 | 194 | ||
195 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), | 195 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), |
196 | style ); | 196 | style ); |
197 | 197 | ||
198 | return create( (OPimGlobal::PimType) *backend_find, style, appName ); | 198 | return create( (OPimGlobal::PimType) *backend_find, style, appName ); |
199 | 199 | ||
200 | } | 200 | } |
201 | private: | 201 | private: |
202 | OBackendPrivate* d; | 202 | OBackendPrivate* d; |
203 | 203 | ||
204 | }; | 204 | }; |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | #endif | 208 | #endif |