-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccessfactory.h | 22 |
2 files changed, 16 insertions, 12 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index c8a4627..6f46652 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,222 +1,224 @@ | |||
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/opimaccessbackend.h> | 41 | #include <opie2/opimaccessbackend.h> |
42 | #include <opie2/opimglobal.h> | 42 | #include <opie2/opimglobal.h> |
43 | #include <opie2/otodoaccessxml.h> | 43 | #include <opie2/otodoaccessxml.h> |
44 | #include <opie2/otodoaccessvcal.h> | 44 | #include <opie2/otodoaccessvcal.h> |
45 | #include <opie2/ocontactaccessbackend_xml.h> | 45 | #include <opie2/ocontactaccessbackend_xml.h> |
46 | #include <opie2/ocontactaccessbackend_vcard.h> | 46 | #include <opie2/ocontactaccessbackend_vcard.h> |
47 | #include <opie2/odatebookaccessbackend_xml.h> | 47 | #include <opie2/odatebookaccessbackend_xml.h> |
48 | 48 | ||
49 | #ifdef __USE_SQL | 49 | #ifdef __USE_SQL |
50 | #include <opie2/otodoaccesssql.h> | 50 | #include <opie2/otodoaccesssql.h> |
51 | #include <opie2/ocontactaccessbackend_sql.h> | 51 | #include <opie2/ocontactaccessbackend_sql.h> |
52 | #include <opie2/odatebookaccessbackend_sql.h> | 52 | #include <opie2/odatebookaccessbackend_sql.h> |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | using namespace Opie; | 55 | using namespace Opie; |
56 | using namespace Opie::Pim; | 56 | using namespace Opie::Pim; |
57 | 57 | ||
58 | namespace Opie { | 58 | namespace Opie { |
59 | 59 | ||
60 | class OBackendPrivate; | 60 | class OBackendPrivate; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * This class is our factory. It will give us the default implementations | 63 | * This class is our factory. It will give us the default implementations |
64 | * of at least Todolist, Contacts and Datebook. In the future this class will | 64 | * of at least Todolist, Contacts and Datebook. In the future this class will |
65 | * allow users to switch the backend with ( XML->SQLite ) without the need | 65 | * allow users to switch the backend with ( XML->SQLite ) without the need |
66 | * to recompile.# | 66 | * to recompile.# |
67 | * This class - as the whole PIM Api - is making use of templates | 67 | * This class - as the whole PIM Api - is making use of templates |
68 | * | 68 | * |
69 | * <pre> | 69 | * <pre> |
70 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); | 70 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null ); |
71 | * backend->load(); | 71 | * backend->load(); |
72 | * </pre> | 72 | * </pre> |
73 | * | 73 | * |
74 | * @author Stefan Eilers | 74 | * @author Stefan Eilers |
75 | * @version 0.1 | 75 | * @version 0.1 |
76 | */ | 76 | */ |
77 | template<class T> | 77 | template<class T> |
78 | class OBackendFactory | 78 | class OBackendFactory |
79 | { | 79 | { |
80 | public: | 80 | public: |
81 | OBackendFactory() {}; | 81 | OBackendFactory() {}; |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Returns a selected backend implementation | 84 | * Returns a selected backend implementation |
85 | * @param type the type of the backend | 85 | * @param type the type of the backend |
86 | * @param database the type of the used database | 86 | * @param database the type of the used database |
87 | * @param appName The name of your application. It will be passed on to the backend. | 87 | * @param appName The name of your application. It will be passed on to the backend. |
88 | * @param filename Filename of the database file if you don't want to access the default | 88 | * @param filename Filename of the database file if you don't want to access the default |
89 | * @see OPimGlobal() | ||
89 | */ | 90 | */ |
90 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, | 91 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
91 | const QString& appName, const QString& filename = QString::null ){ | 92 | const QString& appName, const QString& filename = QString::null ){ |
92 | qWarning("Selected backend for %d is: %d", type, database ); | 93 | qWarning("Selected backend for %d is: %d", type, database ); |
93 | // If we should use the dafult database style, we have to request it | 94 | // If we should use the dafult database style, we have to request it |
94 | OPimGlobal::DatabaseStyle use_database = database; | 95 | OPimGlobal::DatabaseStyle use_database = database; |
95 | if ( use_database == OPimGlobal::DEFAULT ){ | 96 | if ( use_database == OPimGlobal::DEFAULT ){ |
96 | use_database = defaultDB( type ); | 97 | use_database = defaultDB( type ); |
97 | } | 98 | } |
98 | 99 | ||
99 | switch ( type ){ | 100 | switch ( type ){ |
100 | case OPimGlobal::TODOLIST: | 101 | case OPimGlobal::TODOLIST: |
101 | 102 | ||
102 | switch ( use_database ){ | 103 | switch ( use_database ){ |
103 | default: // Use SQL if something weird is given. | 104 | default: // Use SQL if something weird is given. |
104 | // Fall through !! | 105 | // Fall through !! |
105 | case OPimGlobal::SQL: | 106 | case OPimGlobal::SQL: |
106 | #ifdef __USE_SQL | 107 | #ifdef __USE_SQL |
107 | return (T*) new OPimTodoAccessBackendSQL( filename ); | 108 | return (T*) new OPimTodoAccessBackendSQL( filename ); |
108 | break; | 109 | break; |
109 | #else | 110 | #else |
110 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 111 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
111 | // Fall through !! | 112 | // Fall through !! |
112 | #endif | 113 | #endif |
113 | case OPimGlobal::XML: | 114 | case OPimGlobal::XML: |
114 | return (T*) new OPimTodoAccessXML( appName, filename ); | 115 | return (T*) new OPimTodoAccessXML( appName, filename ); |
115 | break; | 116 | break; |
116 | case OPimGlobal::VCARD: | 117 | case OPimGlobal::VCARD: |
117 | return (T*) new OPimTodoAccessVCal( filename ); | 118 | return (T*) new OPimTodoAccessVCal( filename ); |
118 | break; | 119 | break; |
119 | } | 120 | } |
120 | case OPimGlobal::CONTACTLIST: | 121 | case OPimGlobal::CONTACTLIST: |
121 | switch ( use_database ){ | 122 | switch ( use_database ){ |
122 | default: // Use SQL if something weird is given. | 123 | default: // Use SQL if something weird is given. |
123 | // Fall through !! | 124 | // Fall through !! |
124 | case OPimGlobal::SQL: | 125 | case OPimGlobal::SQL: |
125 | #ifdef __USE_SQL | 126 | #ifdef __USE_SQL |
126 | return (T*) new OPimContactAccessBackend_SQL( appName, filename ); | 127 | return (T*) new OPimContactAccessBackend_SQL( appName, filename ); |
127 | break; | 128 | break; |
128 | #else | 129 | #else |
129 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 130 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
130 | // Fall through !! | 131 | // Fall through !! |
131 | #endif | 132 | #endif |
132 | case OPimGlobal::XML: | 133 | case OPimGlobal::XML: |
133 | return (T*) new OPimContactAccessBackend_XML( appName, filename ); | 134 | return (T*) new OPimContactAccessBackend_XML( appName, filename ); |
134 | break; | 135 | break; |
135 | case OPimGlobal::VCARD: | 136 | case OPimGlobal::VCARD: |
136 | return (T*) new OPimContactAccessBackend_VCard( appName, filename ); | 137 | return (T*) new OPimContactAccessBackend_VCard( appName, filename ); |
137 | break; | 138 | break; |
138 | } | 139 | } |
139 | case OPimGlobal::DATEBOOK: | 140 | case OPimGlobal::DATEBOOK: |
140 | switch ( use_database ){ | 141 | switch ( use_database ){ |
141 | default: // Use SQL if something weird is given. | 142 | default: // Use SQL if something weird is given. |
142 | // Fall through !! | 143 | // Fall through !! |
143 | case OPimGlobal::SQL: | 144 | case OPimGlobal::SQL: |
144 | #ifdef __USE_SQL | 145 | #ifdef __USE_SQL |
145 | return (T*) new ODateBookAccessBackend_SQL( appName, filename ); | 146 | return (T*) new ODateBookAccessBackend_SQL( appName, filename ); |
146 | break; | 147 | break; |
147 | #else | 148 | #else |
148 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 149 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); |
149 | // Fall through !! | 150 | // Fall through !! |
150 | #endif | 151 | #endif |
151 | case OPimGlobal::XML: | 152 | case OPimGlobal::XML: |
152 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); | 153 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); |
153 | break; | 154 | break; |
154 | case OPimGlobal::VCARD: | 155 | case OPimGlobal::VCARD: |
155 | qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); | 156 | qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); |
156 | return (T*) NULL; | 157 | return (T*) NULL; |
157 | break; | 158 | break; |
158 | } | 159 | } |
159 | default: | 160 | default: |
160 | return (T*) NULL; | 161 | return (T*) NULL; |
161 | } | 162 | } |
162 | 163 | ||
163 | } | 164 | } |
164 | 165 | ||
165 | /** | 166 | /** |
166 | * Returns the style of the default database which is used to contact PIM data. | 167 | * Returns the style of the default database which is used to contact PIM data. |
167 | * @param type the type of the backend | 168 | * @param type the type of the backend |
168 | * @see OPimGlobal | 169 | * @see OPimGlobal() |
169 | */ | 170 | */ |
170 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ | 171 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ |
171 | QString group_name; | 172 | QString group_name; |
172 | switch ( type ){ | 173 | switch ( type ){ |
173 | case OPimGlobal::TODOLIST: | 174 | case OPimGlobal::TODOLIST: |
174 | group_name = "todo"; | 175 | group_name = "todo"; |
175 | break; | 176 | break; |
176 | case OPimGlobal::CONTACTLIST: | 177 | case OPimGlobal::CONTACTLIST: |
177 | group_name = "contact"; | 178 | group_name = "contact"; |
178 | break; | 179 | break; |
179 | case OPimGlobal::DATEBOOK: | 180 | case OPimGlobal::DATEBOOK: |
180 | group_name = "datebook"; | 181 | group_name = "datebook"; |
181 | break; | 182 | break; |
182 | default: | 183 | default: |
183 | group_name = "unknown"; | 184 | group_name = "unknown"; |
184 | } | 185 | } |
185 | 186 | ||
186 | Config config( "pimaccess" ); | 187 | Config config( "pimaccess" ); |
187 | config.setGroup ( group_name ); | 188 | config.setGroup ( group_name ); |
188 | QString db_String = config.readEntry( "usebackend", "xml" ); | 189 | QString db_String = config.readEntry( "usebackend", "xml" ); |
189 | 190 | ||
190 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | 191 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); |
191 | dictDbTypes.setAutoDelete( TRUE ); | 192 | dictDbTypes.setAutoDelete( TRUE ); |
192 | 193 | ||
193 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | 194 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); |
194 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | 195 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); |
195 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | 196 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); |
196 | 197 | ||
197 | int* db_find = dictDbTypes[ db_String ]; | 198 | int* db_find = dictDbTypes[ db_String ]; |
198 | 199 | ||
199 | if ( !db_find ) | 200 | if ( !db_find ) |
200 | return OPimGlobal::UNKNOWN; | 201 | return OPimGlobal::UNKNOWN; |
201 | 202 | ||
202 | return (OPimGlobal::DatabaseStyle) *db_find; | 203 | return (OPimGlobal::DatabaseStyle) *db_find; |
203 | } | 204 | } |
204 | 205 | ||
205 | 206 | ||
206 | /** | 207 | /** |
207 | * Returns the default backend implementation for backendName. Which one is used, is defined | 208 | * Returns the default backend implementation for backendName. Which one is used, is defined |
208 | * by the configfile "pimaccess.conf". | 209 | * by the configfile "pimaccess.conf". |
209 | * @param type The type of the backend (@see OPimGlobal()) | 210 | * @param type The type of the backend (@see OPimGlobal()) |
210 | * @param appName The name of your application. It will be passed on to the backend | 211 | * @param appName The name of your application. It will be passed on to the backend |
212 | * @see OPimGlobal() | ||
211 | */ | 213 | */ |
212 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ | 214 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ |
213 | return create( type, OPimGlobal::DEFAULT, appName ); | 215 | return create( type, OPimGlobal::DEFAULT, appName ); |
214 | } | 216 | } |
215 | private: | 217 | private: |
216 | OBackendPrivate* d; | 218 | OBackendPrivate* d; |
217 | 219 | ||
218 | }; | 220 | }; |
219 | 221 | ||
220 | } | 222 | } |
221 | 223 | ||
222 | #endif | 224 | #endif |
diff --git a/libopie2/opiepim/core/opimaccessfactory.h b/libopie2/opiepim/core/opimaccessfactory.h index ee55ba5..3cd448e 100644 --- a/libopie2/opiepim/core/opimaccessfactory.h +++ b/libopie2/opiepim/core/opimaccessfactory.h | |||
@@ -1,120 +1,122 @@ | |||
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 | #ifndef __OPIE_OPIMACCESSFACTORY_H_ | 30 | #ifndef __OPIE_OPIMACCESSFACTORY_H_ |
31 | #define __OPIE_OPIMACCESSFACTORY_H_ | 31 | #define __OPIE_OPIMACCESSFACTORY_H_ |
32 | 32 | ||
33 | #include <opie2/opimglobal.h> | 33 | #include <opie2/opimglobal.h> |
34 | #include <opie2/obackendfactory.h> | 34 | #include <opie2/obackendfactory.h> |
35 | #include <opie2/ocontactaccess.h> | 35 | #include <opie2/ocontactaccess.h> |
36 | #include <opie2/otodoaccess.h> | 36 | #include <opie2/otodoaccess.h> |
37 | #include <opie2/odatebookaccess.h> | 37 | #include <opie2/odatebookaccess.h> |
38 | 38 | ||
39 | using namespace Opie::Pim; | 39 | using namespace Opie::Pim; |
40 | 40 | ||
41 | namespace Opie { | 41 | namespace Opie { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * This class is our factory for creating PIM access objects. You should use these objects to load, store and search | 45 | * This class is our factory for creating PIM access objects. You should use these objects to load, store and search |
46 | * information in our PIM databases. Currently we support objects for accessing the datebook, the contact- and the | 46 | * information in our PIM databases. Currently we support objects for accessing the datebook, the contact- and the |
47 | * todolist. | 47 | * todolist. |
48 | * @see OPimGlobal for more information of used values. | 48 | * @see OPimGlobal for more information of used values. |
49 | * | 49 | * |
50 | * This class - as the whole PIM Api - is making use of templates | 50 | * This class - as the whole PIM Api - is making use of templates |
51 | * | 51 | * |
52 | * Example for getting an access object for the XML database of todolist: | 52 | * Example for getting an access object for the XML database of todolist: |
53 | * <pre> | 53 | * <pre> |
54 | * OPimTodoAccess* access = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "example" ); | 54 | * OPimTodoAccess* access = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "example" ); |
55 | * </pre> | 55 | * </pre> |
56 | * | 56 | * |
57 | * @author Stefan Eilers | 57 | * @author Stefan Eilers |
58 | * @version 0.1 | 58 | * @version 0.1 |
59 | */ | 59 | */ |
60 | 60 | ||
61 | template<class T> | 61 | template<class T> |
62 | class OPimAccessFactory | 62 | class OPimAccessFactory |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | |||
66 | // Maybe we should introduce a global class for storing such global enums | ||
67 | // (something like opimglobal.h) ? (eilers) | ||
68 | |||
69 | OPimAccessFactory() {}; | 65 | OPimAccessFactory() {}; |
70 | 66 | ||
71 | /** | 67 | /** |
72 | * Returns the selected PIM access-object. | 68 | * Returns the selected PIM access-object. |
73 | * @param type Type of the selected database (addressbook, todolist or datebook) | 69 | * @param type Type of the selected database (addressbook, todolist or datebook) |
74 | * @param dbStyle Which database style should be used (xml, sql, vcard) | 70 | * @param dbStyle Which database style should be used (xml, sql, vcard) |
75 | * @param appName "Name" of your application. This should be any constant string which is used | 71 | * @param appName "Name" of your application. This should be any constant string which is used |
76 | * by some backends for creating special files (i.e.journal files). Please keep the | 72 | * by some backends for creating special files (i.e.journal files). Please keep the |
77 | * string unique for your application ! | 73 | * string unique for your application ! |
78 | * @see OPimGlobal | 74 | * @param fileName Filename of database if something different as the default should be used. |
75 | * @see OPimGlobal() | ||
79 | */ | 76 | */ |
80 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle dbStyle, const QString& appName ){ | 77 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle dbStyle, const QString& appName, |
78 | const QString& fileName = QString::null ){ | ||
81 | OPimBase *base; | 79 | OPimBase *base; |
82 | switch ( type ){ | 80 | switch ( type ){ |
83 | case OPimGlobal::TODOLIST: | 81 | case OPimGlobal::TODOLIST: |
84 | base = new OPimTodoAccess( OBackendFactory<OPimTodoAccessBackend>::create( type, dbStyle, appName ) ); | 82 | base = new OPimTodoAccess( OBackendFactory<OPimTodoAccessBackend>::create( type, dbStyle, |
83 | appName, fileName ) ); | ||
85 | break; | 84 | break; |
86 | case OPimGlobal::CONTACTLIST: | 85 | case OPimGlobal::CONTACTLIST: |
87 | base = new OPimContactAccess( QString::null, QString::null, OBackendFactory<OPimContactAccessBackend>::create( type, dbStyle, appName ) ); | 86 | base = new OPimContactAccess( QString::null, QString::null, |
87 | OBackendFactory<OPimContactAccessBackend>::create( type, dbStyle, | ||
88 | appName, fileName ) ); | ||
88 | break; | 89 | break; |
89 | case OPimGlobal::DATEBOOK: | 90 | case OPimGlobal::DATEBOOK: |
90 | base = new ODateBookAccess( OBackendFactory<ODateBookAccessBackend>::create( type, dbStyle, appName ) ); | 91 | base = new ODateBookAccess( OBackendFactory<ODateBookAccessBackend>::create( type, dbStyle, |
92 | appName, fileName ) ); | ||
91 | break; | 93 | break; |
92 | default: | 94 | default: |
93 | return 0l; | 95 | return 0l; |
94 | } | 96 | } |
95 | return static_cast<T*>( base ); | 97 | return static_cast<T*>( base ); |
96 | } | 98 | } |
97 | 99 | ||
98 | 100 | ||
99 | /** | 101 | /** |
100 | * Returns the selected PIM access-object, using the default database style | 102 | * Returns the selected PIM access-object, using the default database style |
101 | * Which style is selected is defined in the configfile "pimaccess.conf" in | 103 | * Which style is selected is defined in the configfile "pimaccess.conf" in |
102 | * the directory "Settings" | 104 | * the directory "Settings" |
103 | * @param type Type of the selected database (addressbook, todolist or datebook) | 105 | * @param type Type of the selected database (addressbook, todolist or datebook) |
104 | * @param appName "Name" of your application. This should be any constant string which is used | 106 | * @param appName "Name" of your application. This should be any constant string which is used |
105 | * by some backends for creating special files (i.e.journal files). Please keep the | 107 | * by some backends for creating special files (i.e.journal files). Please keep the |
106 | * string unique for your application ! | 108 | * string unique for your application ! |
107 | * @see OPimGlobal | 109 | * @see OPimGlobal() |
108 | * | 110 | * |
109 | */ | 111 | */ |
110 | static T* defaultAccess( typename OPimGlobal::PimType type, const QString& appName ){ | 112 | static T* defaultAccess( typename OPimGlobal::PimType type, const QString& appName ){ |
111 | 113 | ||
112 | return create( type, OPimGlobal::DEFAULT, appName ); | 114 | return create( type, OPimGlobal::DEFAULT, appName ); |
113 | 115 | ||
114 | } | 116 | } |
115 | }; | 117 | }; |
116 | 118 | ||
117 | } | 119 | } |
118 | 120 | ||
119 | 121 | ||
120 | #endif | 122 | #endif |