Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 242 |
1 files changed, 124 insertions, 118 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 6f46652..3680ded 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -33,26 +33,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 | /* OPIE */ |
38 | #include <qasciidict.h> | ||
39 | #include <qpe/config.h> | ||
40 | |||
41 | #include <opie2/opimaccessbackend.h> | 38 | #include <opie2/opimaccessbackend.h> |
42 | #include <opie2/opimglobal.h> | 39 | #include <opie2/opimglobal.h> |
43 | #include <opie2/otodoaccessxml.h> | 40 | #include <opie2/otodoaccessxml.h> |
44 | #include <opie2/otodoaccessvcal.h> | 41 | #include <opie2/otodoaccessvcal.h> |
45 | #include <opie2/ocontactaccessbackend_xml.h> | 42 | #include <opie2/ocontactaccessbackend_xml.h> |
46 | #include <opie2/ocontactaccessbackend_vcard.h> | 43 | #include <opie2/ocontactaccessbackend_vcard.h> |
47 | #include <opie2/odatebookaccessbackend_xml.h> | 44 | #include <opie2/odatebookaccessbackend_xml.h> |
45 | #include <opie2/odebug.h> | ||
48 | 46 | ||
49 | #ifdef __USE_SQL | 47 | #ifdef __USE_SQL |
50 | #include <opie2/otodoaccesssql.h> | 48 | #include <opie2/otodoaccesssql.h> |
51 | #include <opie2/ocontactaccessbackend_sql.h> | 49 | #include <opie2/ocontactaccessbackend_sql.h> |
52 | #include <opie2/odatebookaccessbackend_sql.h> | 50 | #include <opie2/odatebookaccessbackend_sql.h> |
53 | #endif | 51 | #endif |
54 | 52 | ||
53 | #include <qpe/config.h> | ||
54 | |||
55 | /* QT */ | ||
56 | #include <qstring.h> | ||
57 | #include <qasciidict.h> | ||
58 | |||
59 | |||
60 | |||
55 | using namespace Opie; | 61 | using namespace Opie; |
56 | using namespace Opie::Pim; | 62 | using namespace Opie::Pim; |
57 | 63 | ||
58 | namespace Opie { | 64 | namespace Opie { |
@@ -77,146 +83,146 @@ class OBackendPrivate; | |||
77 | template<class T> | 83 | template<class T> |
78 | class OBackendFactory | 84 | class OBackendFactory |
79 | { | 85 | { |
80 | public: | 86 | public: |
81 | OBackendFactory() {}; | 87 | OBackendFactory() {}; |
82 | 88 | ||
83 | /** | 89 | /** |
84 | * Returns a selected backend implementation | 90 | * Returns a selected backend implementation |
85 | * @param type the type of the backend | 91 | * @param type the type of the backend |
86 | * @param database the type of the used database | 92 | * @param database the type of the used database |
87 | * @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. |
88 | * @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 |
89 | * @see OPimGlobal() | 95 | * @see OPimGlobal() |
90 | */ | 96 | */ |
91 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, | 97 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
92 | const QString& appName, const QString& filename = QString::null ){ | 98 | const QString& appName, const QString& filename = QString::null ){ |
93 | qWarning("Selected backend for %d is: %d", type, database ); | 99 | owarn << "Selected backend for " << type << " is: " << database << oendl; |
94 | // If we should use the dafult database style, we have to request it | 100 | // If we should use the dafult database style, we have to request it |
95 | OPimGlobal::DatabaseStyle use_database = database; | 101 | OPimGlobal::DatabaseStyle use_database = database; |
96 | if ( use_database == OPimGlobal::DEFAULT ){ | 102 | if ( use_database == OPimGlobal::DEFAULT ){ |
97 | use_database = defaultDB( type ); | 103 | use_database = defaultDB( type ); |
98 | } | 104 | } |
99 | 105 | ||
100 | switch ( type ){ | 106 | switch ( type ){ |
101 | case OPimGlobal::TODOLIST: | 107 | case OPimGlobal::TODOLIST: |
102 | 108 | ||
103 | switch ( use_database ){ | 109 | switch ( use_database ){ |
104 | default: // Use SQL if something weird is given. | 110 | default: // Use SQL if something weird is given. |
105 | // Fall through !! | 111 | // Fall through !! |
106 | case OPimGlobal::SQL: | 112 | case OPimGlobal::SQL: |
107 | #ifdef __USE_SQL | 113 | #ifdef __USE_SQL |
108 | return (T*) new OPimTodoAccessBackendSQL( filename ); | 114 | return (T*) new OPimTodoAccessBackendSQL( filename ); |
109 | break; | 115 | break; |
110 | #else | 116 | #else |
111 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 117 | owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl; |
112 | // Fall through !! | 118 | // Fall through !! |
113 | #endif | 119 | #endif |
114 | case OPimGlobal::XML: | 120 | case OPimGlobal::XML: |
115 | return (T*) new OPimTodoAccessXML( appName, filename ); | 121 | return (T*) new OPimTodoAccessXML( appName, filename ); |
116 | break; | 122 | break; |
117 | case OPimGlobal::VCARD: | 123 | case OPimGlobal::VCARD: |
118 | return (T*) new OPimTodoAccessVCal( filename ); | 124 | return (T*) new OPimTodoAccessVCal( filename ); |
119 | break; | 125 | break; |
120 | } | 126 | } |
121 | case OPimGlobal::CONTACTLIST: | 127 | case OPimGlobal::CONTACTLIST: |
122 | switch ( use_database ){ | 128 | switch ( use_database ){ |
123 | default: // Use SQL if something weird is given. | 129 | default: // Use SQL if something weird is given. |
124 | // Fall through !! | 130 | // Fall through !! |
125 | case OPimGlobal::SQL: | 131 | case OPimGlobal::SQL: |
126 | #ifdef __USE_SQL | 132 | #ifdef __USE_SQL |
127 | return (T*) new OPimContactAccessBackend_SQL( appName, filename ); | 133 | return (T*) new OPimContactAccessBackend_SQL( appName, filename ); |
128 | break; | 134 | break; |
129 | #else | 135 | #else |
130 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 136 | owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl; |
131 | // Fall through !! | 137 | // Fall through !! |
132 | #endif | 138 | #endif |
133 | case OPimGlobal::XML: | 139 | case OPimGlobal::XML: |
134 | return (T*) new OPimContactAccessBackend_XML( appName, filename ); | 140 | return (T*) new OPimContactAccessBackend_XML( appName, filename ); |
135 | break; | 141 | break; |
136 | case OPimGlobal::VCARD: | 142 | case OPimGlobal::VCARD: |
137 | return (T*) new OPimContactAccessBackend_VCard( appName, filename ); | 143 | return (T*) new OPimContactAccessBackend_VCard( appName, filename ); |
138 | break; | 144 | break; |
139 | } | 145 | } |
140 | case OPimGlobal::DATEBOOK: | 146 | case OPimGlobal::DATEBOOK: |
141 | switch ( use_database ){ | 147 | switch ( use_database ){ |
142 | default: // Use SQL if something weird is given. | 148 | default: // Use SQL if something weird is given. |
143 | // Fall through !! | 149 | // Fall through !! |
144 | case OPimGlobal::SQL: | 150 | case OPimGlobal::SQL: |
145 | #ifdef __USE_SQL | 151 | #ifdef __USE_SQL |
146 | return (T*) new ODateBookAccessBackend_SQL( appName, filename ); | 152 | return (T*) new ODateBookAccessBackend_SQL( appName, filename ); |
147 | break; | 153 | break; |
148 | #else | 154 | #else |
149 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 155 | owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl; |
150 | // Fall through !! | 156 | // Fall through !! |
151 | #endif | 157 | #endif |
152 | case OPimGlobal::XML: | 158 | case OPimGlobal::XML: |
153 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); | 159 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); |
154 | break; | 160 | break; |
155 | case OPimGlobal::VCARD: | 161 | case OPimGlobal::VCARD: |
156 | qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); | 162 | owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl; |
157 | return (T*) NULL; | 163 | return (T*) NULL; |
158 | break; | 164 | break; |
159 | } | 165 | } |
160 | default: | 166 | default: |
161 | return (T*) NULL; | 167 | return (T*) NULL; |
162 | } | 168 | } |
163 | 169 | ||
164 | } | 170 | } |
165 | 171 | ||
166 | /** | 172 | /** |
167 | * Returns the style of the default database which is used to contact PIM data. | 173 | * Returns the style of the default database which is used to contact PIM data. |
168 | * @param type the type of the backend | 174 | * @param type the type of the backend |
169 | * @see OPimGlobal() | 175 | * @see OPimGlobal() |
170 | */ | 176 | */ |
171 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ | 177 | static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ |
172 | QString group_name; | 178 | QString group_name; |
173 | switch ( type ){ | 179 | switch ( type ){ |
174 | case OPimGlobal::TODOLIST: | 180 | case OPimGlobal::TODOLIST: |
175 | group_name = "todo"; | 181 | group_name = "todo"; |
176 | break; | 182 | break; |
177 | case OPimGlobal::CONTACTLIST: | 183 | case OPimGlobal::CONTACTLIST: |
178 | group_name = "contact"; | 184 | group_name = "contact"; |
179 | break; | 185 | break; |
180 | case OPimGlobal::DATEBOOK: | 186 | case OPimGlobal::DATEBOOK: |
181 | group_name = "datebook"; | 187 | group_name = "datebook"; |
182 | break; | 188 | break; |
183 | default: | 189 | default: |
184 | group_name = "unknown"; | 190 | group_name = "unknown"; |
185 | } | 191 | } |
186 | 192 | ||
187 | Config config( "pimaccess" ); | 193 | Config config( "pimaccess" ); |
188 | config.setGroup ( group_name ); | 194 | config.setGroup ( group_name ); |
189 | QString db_String = config.readEntry( "usebackend", "xml" ); | 195 | QString db_String = config.readEntry( "usebackend", "xml" ); |
190 | 196 | ||
191 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); | 197 | QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); |
192 | dictDbTypes.setAutoDelete( TRUE ); | 198 | dictDbTypes.setAutoDelete( TRUE ); |
193 | 199 | ||
194 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); | 200 | dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); |
195 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); | 201 | dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); |
196 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); | 202 | dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); |
197 | 203 | ||
198 | int* db_find = dictDbTypes[ db_String ]; | 204 | int* db_find = dictDbTypes[ db_String ]; |
199 | 205 | ||
200 | if ( !db_find ) | 206 | if ( !db_find ) |
201 | return OPimGlobal::UNKNOWN; | 207 | return OPimGlobal::UNKNOWN; |
202 | 208 | ||
203 | return (OPimGlobal::DatabaseStyle) *db_find; | 209 | return (OPimGlobal::DatabaseStyle) *db_find; |
204 | } | 210 | } |
205 | 211 | ||
206 | 212 | ||
207 | /** | 213 | /** |
208 | * Returns the default backend implementation for backendName. Which one is used, is defined | 214 | * Returns the default backend implementation for backendName. Which one is used, is defined |
209 | * by the configfile "pimaccess.conf". | 215 | * by the configfile "pimaccess.conf". |
210 | * @param type The type of the backend (@see OPimGlobal()) | 216 | * @param type The type of the backend (@see OPimGlobal()) |
211 | * @param appName The name of your application. It will be passed on to the backend | 217 | * @param appName The name of your application. It will be passed on to the backend |
212 | * @see OPimGlobal() | 218 | * @see OPimGlobal() |
213 | */ | 219 | */ |
214 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ | 220 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ |
215 | return create( type, OPimGlobal::DEFAULT, appName ); | 221 | return create( type, OPimGlobal::DEFAULT, appName ); |
216 | } | 222 | } |
217 | private: | 223 | private: |
218 | OBackendPrivate* d; | 224 | OBackendPrivate* d; |
219 | 225 | ||
220 | }; | 226 | }; |
221 | 227 | ||
222 | } | 228 | } |