Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 9f3a823..25e247b 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -53,68 +53,70 @@ | |||
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | /* QT */ | 55 | /* QT */ |
56 | #include <qstring.h> | 56 | #include <qstring.h> |
57 | #include <qasciidict.h> | 57 | #include <qasciidict.h> |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | using namespace Opie::Pim; | 62 | using namespace Opie::Pim; |
63 | 63 | ||
64 | namespace Opie { | 64 | namespace Opie { |
65 | 65 | ||
66 | class OBackendPrivate; | 66 | class OBackendPrivate; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * This class is our factory. It will give us the default implementations | 69 | * This class is our factory. It will give us the default implementations |
70 | * of at least Todolist, Contacts and Datebook. In the future this class will | 70 | * of at least Todolist, Contacts and Datebook. In the future this class will |
71 | * allow users to switch the backend with ( XML->SQLite ) without the need | 71 | * allow users to switch the backend with ( XML->SQLite ) without the need |
72 | * to recompile.# | 72 | * to recompile.# |
73 | * This class - as the whole PIM Api - is making use of templates | 73 | * This class - as the whole PIM Api - is making use of templates |
74 | * | 74 | * |
75 | * <pre> | 75 | * <pre> |
76 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null ); | 76 | * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null ); |
77 | * backend->load(); | 77 | * backend->load(); |
78 | * </pre> | 78 | * </pre> |
79 | * | 79 | * |
80 | * @author Stefan Eilers | 80 | * @author Stefan Eilers |
81 | * @version 0.1 | 81 | * @version 0.1 |
82 | */ | 82 | */ |
83 | template<class T> | 83 | template<class T> |
84 | class OBackendFactory | 84 | class OBackendFactory |
85 | { | 85 | { |
86 | public: | 86 | public: |
87 | OBackendFactory() {}; | 87 | OBackendFactory() {}; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Returns a selected backend implementation | 90 | * Returns a selected backend implementation |
91 | * @param type the type of the backend | 91 | * @param type the type of the backend |
92 | * @param database the type of the used database | 92 | * @param database the type of the used database |
93 | * @param appName The name of your application. It will be passed on to the backend. | 93 | * @param appName The name of your application. It will be passed on to the backend. |
94 | * @param filename Filename of the database file if you don't want to access the default | 94 | * @param filename Filename of the database file if you don't want to access the default |
95 | * @see OPimGlobal() | 95 | * @see OPimGlobal() |
96 | */ | 96 | */ |
97 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, | 97 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
98 | const QString& appName, const QString& filename = QString::null ){ | 98 | const QString& appName, const QString& filename = QString::null ){ |
99 | owarn << "Selected backend for " << type << " is: " << database << oendl; | 99 | owarn << "Selected backend for " << type << " is: " << |
100 | // If we should use the dafult database style, we have to request it | 100 | database << oendl; |
101 | |||
102 | // If we should use the dafult database style, we have to request it | ||
101 | OPimGlobal::DatabaseStyle use_database = database; | 103 | OPimGlobal::DatabaseStyle use_database = database; |
102 | if ( use_database == OPimGlobal::DEFAULT ){ | 104 | if ( use_database == OPimGlobal::DEFAULT ){ |
103 | use_database = defaultDB( type ); | 105 | use_database = defaultDB( type ); |
104 | } | 106 | } |
105 | 107 | ||
106 | switch ( type ){ | 108 | switch ( type ){ |
107 | case OPimGlobal::TODOLIST: | 109 | case OPimGlobal::TODOLIST: |
108 | 110 | ||
109 | switch ( use_database ){ | 111 | switch ( use_database ){ |
110 | default: // Use SQL if something weird is given. | 112 | default: // Use SQL if something weird is given. |
111 | // Fall through !! | 113 | // Fall through !! |
112 | case OPimGlobal::SQL: | 114 | case OPimGlobal::SQL: |
113 | #ifdef __USE_SQL | 115 | #ifdef __USE_SQL |
114 | return (T*) new OPimTodoAccessBackendSQL( filename ); | 116 | return (T*) new OPimTodoAccessBackendSQL( filename ); |
115 | break; | 117 | break; |
116 | #else | 118 | #else |
117 | owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl; | 119 | owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl; |
118 | // Fall through !! | 120 | // Fall through !! |
119 | #endif | 121 | #endif |
120 | case OPimGlobal::XML: | 122 | case OPimGlobal::XML: |
@@ -157,74 +159,74 @@ class OBackendPrivate; | |||
157 | #endif | 159 | #endif |
158 | case OPimGlobal::XML: | 160 | case OPimGlobal::XML: |
159 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); | 161 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); |
160 | break; | 162 | break; |
161 | case OPimGlobal::VCARD: | 163 | case OPimGlobal::VCARD: |
162 | owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl; | 164 | owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl; |
163 | return (T*) NULL; | 165 | return (T*) NULL; |
164 | break; | 166 | break; |
165 | } | 167 | } |
166 | default: | 168 | default: |
167 | return (T*) NULL; | 169 | return (T*) NULL; |
168 | } | 170 | } |
169 | 171 | ||
170 | } | 172 | } |
171 | 173 | ||
172 | /** | 174 | /** |
173 | * Returns the style of the default database which is used to contact PIM data. | 175 | * Returns the style of the default database which is used to contact PIM data. |
174 | * @param type the type of the backend | 176 | * @param type the type of the backend |
175 | * @see OPimGlobal() | 177 | * @see OPimGlobal() |
176 | */ | 178 | */ |
177 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ | 179 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ |
178 | QString group_name; | 180 | QString group_name; |
179 | switch ( type ){ | 181 | switch ( type ){ |
180 | case OPimGlobal::TODOLIST: | 182 | case OPimGlobal::TODOLIST: |
181 | group_name = "todo"; | 183 | group_name = "todo"; |
182 | break; | 184 | break; |
183 | case OPimGlobal::CONTACTLIST: | 185 | case OPimGlobal::CONTACTLIST: |
184 | group_name = "contact"; | 186 | group_name = "contact"; |
185 | break; | 187 | break; |
186 | case OPimGlobal::DATEBOOK: | 188 | case OPimGlobal::DATEBOOK: |
187 | group_name = "datebook"; | 189 | group_name = "datebook"; |
188 | break; | 190 | break; |
189 | default: | 191 | default: |
190 | group_name = "unknown"; | 192 | group_name = "unknown"; |
191 | } | 193 | } |
192 | 194 | ||
193 | Config config( "pimaccess" ); | 195 | Config config( "pimaccess" ); |
194 | config.setGroup ( group_name ); | 196 | config.setGroup ( group_name ); |
195 | QString db_String = config.readEntry( "usebackend", "xml" ); | 197 | QString db_String = config.readEntry( "usebackend", "xml" ); |
196 | 198 | ||
197 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | 199 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); |
198 | dictDbTypes.setAutoDelete( TRUE ); | 200 | dictDbTypes.setAutoDelete( TRUE ); |
199 | 201 | ||
200 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | 202 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); |
201 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | 203 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); |
202 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | 204 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); |
203 | 205 | ||
204 | int* db_find = dictDbTypes[ db_String ]; | 206 | int* db_find = dictDbTypes[ db_String ]; |
205 | 207 | ||
206 | if ( !db_find ) | 208 | if ( !db_find ) |
207 | return OPimGlobal::UNKNOWN; | 209 | return OPimGlobal::UNKNOWN; |
208 | 210 | ||
209 | return (OPimGlobal::DatabaseStyle) *db_find; | 211 | return (OPimGlobal::DatabaseStyle) *db_find; |
210 | } | 212 | } |
211 | 213 | ||
212 | 214 | ||
213 | /** | 215 | /** |
214 | * Returns the default backend implementation for backendName. Which one is used, is defined | 216 | * Returns the default backend implementation for backendName. Which one is used, is defined |
215 | * by the configfile "pimaccess.conf". | 217 | * by the configfile "pimaccess.conf". |
216 | * @param type The type of the backend (@see OPimGlobal()) | 218 | * @param type The type of the backend (@see OPimGlobal()) |
217 | * @param appName The name of your application. It will be passed on to the backend | 219 | * @param appName The name of your application. It will be passed on to the backend |
218 | * @see OPimGlobal() | 220 | * @see OPimGlobal() |
219 | */ | 221 | */ |
220 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ | 222 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ |
221 | return create( type, OPimGlobal::DEFAULT, appName ); | 223 | return create( type, OPimGlobal::DEFAULT, appName ); |
222 | } | 224 | } |
223 | private: | 225 | private: |
224 | OBackendPrivate* d; | 226 | OBackendPrivate* d; |
225 | 227 | ||
226 | }; | 228 | }; |
227 | 229 | ||
228 | } | 230 | } |
229 | 231 | ||
230 | #endif | 232 | #endif |