author | eilers <eilers> | 2004-05-23 17:11:01 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-05-23 17:11:01 (UTC) |
commit | 3025eab185d9e4237c37b4a193fbb20a4dbe504e (patch) (unidiff) | |
tree | a6d4ee84122cdcd207d77c16b7449b432df6096a /libopie2/opiepim/backend/obackendfactory.h | |
parent | 29c68e4c0b10bf31cab3520737d042978d3eb4c0 (diff) | |
download | opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.zip opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.tar.gz opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.tar.bz2 |
Changes in Backendfactory: Now providing VCARD/VCAL backends if available
Changing API: Default now gets a OPimGlobal::PimType as first param instead of QString.
Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 98 |
1 files changed, 56 insertions, 42 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 4bedbef..c8a4627 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -40,5 +40,8 @@ | |||
40 | 40 | ||
41 | #include <opie2/opimaccessbackend.h> | ||
41 | #include <opie2/opimglobal.h> | 42 | #include <opie2/opimglobal.h> |
42 | #include <opie2/otodoaccessxml.h> | 43 | #include <opie2/otodoaccessxml.h> |
44 | #include <opie2/otodoaccessvcal.h> | ||
43 | #include <opie2/ocontactaccessbackend_xml.h> | 45 | #include <opie2/ocontactaccessbackend_xml.h> |
46 | #include <opie2/ocontactaccessbackend_vcard.h> | ||
44 | #include <opie2/odatebookaccessbackend_xml.h> | 47 | #include <opie2/odatebookaccessbackend_xml.h> |
@@ -84,44 +87,73 @@ class OBackendFactory | |||
84 | * @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 | ||
85 | */ | 89 | */ |
86 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, | 90 | static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, |
87 | const QString& appName ){ | 91 | const QString& appName, const QString& filename = QString::null ){ |
88 | qWarning("Selected backend for %d is: %d", type, database ); | 92 | qWarning("Selected backend for %d is: %d", type, database ); |
89 | // If we should use the dafult database style, we have to request it | 93 | // If we should use the dafult database style, we have to request it |
90 | OPimGlobal::DatabaseStyle used_database = database; | 94 | OPimGlobal::DatabaseStyle use_database = database; |
91 | if ( database == OPimGlobal::DEFAULT ){ | 95 | if ( use_database == OPimGlobal::DEFAULT ){ |
92 | used_database = defaultDB( type ); | 96 | use_database = defaultDB( type ); |
93 | } | 97 | } |
94 | 98 | ||
95 | |||
96 | switch ( type ){ | 99 | switch ( type ){ |
97 | case OPimGlobal::TODOLIST: | 100 | case OPimGlobal::TODOLIST: |
101 | |||
102 | switch ( use_database ){ | ||
103 | default: // Use SQL if something weird is given. | ||
104 | // Fall through !! | ||
105 | case OPimGlobal::SQL: | ||
98 | #ifdef __USE_SQL | 106 | #ifdef __USE_SQL |
99 | if ( used_database == OPimGlobal::SQL ) | 107 | return (T*) new OPimTodoAccessBackendSQL( filename ); |
100 | return (T*) new OPimTodoAccessBackendSQL(""); | 108 | break; |
101 | #else | 109 | #else |
102 | if ( used_database == OPimGlobal::SQL ) | ||
103 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 110 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
111 | // Fall through !! | ||
104 | #endif | 112 | #endif |
105 | 113 | case OPimGlobal::XML: | |
106 | return (T*) new OPimTodoAccessXML( appName ); | 114 | return (T*) new OPimTodoAccessXML( appName, filename ); |
115 | break; | ||
116 | case OPimGlobal::VCARD: | ||
117 | return (T*) new OPimTodoAccessVCal( filename ); | ||
118 | break; | ||
119 | } | ||
107 | case OPimGlobal::CONTACTLIST: | 120 | case OPimGlobal::CONTACTLIST: |
121 | switch ( use_database ){ | ||
122 | default: // Use SQL if something weird is given. | ||
123 | // Fall through !! | ||
124 | case OPimGlobal::SQL: | ||
108 | #ifdef __USE_SQL | 125 | #ifdef __USE_SQL |
109 | if ( used_database == OPimGlobal::SQL ) | 126 | return (T*) new OPimContactAccessBackend_SQL( appName, filename ); |
110 | return (T*) new OPimContactAccessBackend_SQL(""); | 127 | break; |
111 | #else | 128 | #else |
112 | if ( used_database == OPimGlobal::SQL ) | ||
113 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 129 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
130 | // Fall through !! | ||
114 | #endif | 131 | #endif |
115 | 132 | case OPimGlobal::XML: | |
116 | return (T*) new OPimContactAccessBackend_XML( appName ); | 133 | return (T*) new OPimContactAccessBackend_XML( appName, filename ); |
134 | break; | ||
135 | case OPimGlobal::VCARD: | ||
136 | return (T*) new OPimContactAccessBackend_VCard( appName, filename ); | ||
137 | break; | ||
138 | } | ||
117 | case OPimGlobal::DATEBOOK: | 139 | case OPimGlobal::DATEBOOK: |
140 | switch ( use_database ){ | ||
141 | default: // Use SQL if something weird is given. | ||
142 | // Fall through !! | ||
143 | case OPimGlobal::SQL: | ||
118 | #ifdef __USE_SQL | 144 | #ifdef __USE_SQL |
119 | if ( used_database == OPimGlobal::SQL ) | 145 | return (T*) new ODateBookAccessBackend_SQL( appName, filename ); |
120 | return (T*) new ODateBookAccessBackend_SQL(""); | 146 | break; |
121 | #else | 147 | #else |
122 | if ( used_database == OPimGlobal::SQL ) | 148 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); |
123 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 149 | // Fall through !! |
124 | #endif | 150 | #endif |
125 | 151 | case OPimGlobal::XML: | |
126 | return (T*) new ODateBookAccessBackend_XML( appName ); | 152 | return (T*) new ODateBookAccessBackend_XML( appName, filename ); |
153 | break; | ||
154 | case OPimGlobal::VCARD: | ||
155 | qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); | ||
156 | return (T*) NULL; | ||
157 | break; | ||
158 | } | ||
127 | default: | 159 | default: |
@@ -130,3 +162,2 @@ class OBackendFactory | |||
130 | 162 | ||
131 | |||
132 | } | 163 | } |
@@ -177,24 +208,7 @@ class OBackendFactory | |||
177 | * by the configfile "pimaccess.conf". | 208 | * by the configfile "pimaccess.conf". |
178 | * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) | 209 | * @param type The type of the backend (@see OPimGlobal()) |
179 | * @param appName The name of your application. It will be passed on to the backend | 210 | * @param appName The name of your application. It will be passed on to the backend |
180 | */ | 211 | */ |
181 | static T* defaultBackend( const QString backendName, const QString& appName ){ | 212 | static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ |
182 | 213 | return create( type, OPimGlobal::DEFAULT, appName ); | |
183 | QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); | ||
184 | dictBackends.setAutoDelete ( TRUE ); | ||
185 | |||
186 | dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); | ||
187 | dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); | ||
188 | dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); | ||
189 | |||
190 | int* backend_find = dictBackends[ backendName ]; | ||
191 | if ( !backend_find ) return NULL; | ||
192 | |||
193 | OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) ); | ||
194 | |||
195 | qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), | ||
196 | style ); | ||
197 | |||
198 | return create( (OPimGlobal::PimType) *backend_find, style, appName ); | ||
199 | |||
200 | } | 214 | } |