-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 98 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimglobal.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 3 |
5 files changed, 63 insertions, 46 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 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 417a954..a372267 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -55,2 +55,3 @@ | |||
55 | #include <opie2/opimresolver.h> | 55 | #include <opie2/opimresolver.h> |
56 | #include <opie2/opimglobal.h> | ||
56 | 57 | ||
@@ -67,3 +68,3 @@ OPimContactAccess::OPimContactAccess ( const QString appname, const QString , | |||
67 | qWarning ("Using BackendFactory !"); | 68 | qWarning ("Using BackendFactory !"); |
68 | end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( "contact", appname ); | 69 | end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); |
69 | } | 70 | } |
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index 5f471cf..440ee0a 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp | |||
@@ -31,2 +31,3 @@ | |||
31 | #include <opie2/opimresolver.h> | 31 | #include <opie2/opimresolver.h> |
32 | #include <opie2/opimglobal.h> | ||
32 | 33 | ||
@@ -44,3 +45,3 @@ ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | |||
44 | if (!back ) | 45 | if (!back ) |
45 | back = OBackendFactory<ODateBookAccessBackend>::defaultBackend("datebook", QString::null ); | 46 | back = OBackendFactory<ODateBookAccessBackend>::defaultBackend( OPimGlobal::DATEBOOK, QString::null ); |
46 | 47 | ||
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h index d56c9be..efd455c 100644 --- a/libopie2/opiepim/core/opimglobal.h +++ b/libopie2/opiepim/core/opimglobal.h | |||
@@ -52,3 +52,3 @@ class OPimGlobal{ | |||
52 | SQL, | 52 | SQL, |
53 | VCARD, | 53 | VCARD, // Also used for VCARD ! |
54 | _END_DatabaseStyle | 54 | _END_DatabaseStyle |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 87a211f..c4adbbd 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -36,2 +36,3 @@ | |||
36 | #include <opie2/opimresolver.h> | 36 | #include <opie2/opimresolver.h> |
37 | #include <opie2/opimglobal.h> | ||
37 | 38 | ||
@@ -46,3 +47,3 @@ OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) | |||
46 | if (end == 0l ) | 47 | if (end == 0l ) |
47 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend ("todo", QString::null); | 48 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null); |
48 | 49 | ||