summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h98
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp3
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp3
-rw-r--r--libopie2/opiepim/core/opimglobal.h2
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp3
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
@@ -37,11 +37,14 @@
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/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>
45 48
46#ifdef __USE_SQL 49#ifdef __USE_SQL
47#include <opie2/otodoaccesssql.h> 50#include <opie2/otodoaccesssql.h>
@@ -81,55 +84,83 @@ class OBackendFactory
81 * Returns a selected backend implementation 84 * Returns a selected backend implementation
82 * @param type the type of the backend 85 * @param type the type of the backend
83 * @param database the type of the used database 86 * @param database the type of the used database
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:
128 return (T*) NULL; 160 return (T*) NULL;
129 } 161 }
130 162
131
132 } 163 }
133 164
134 /** 165 /**
135 * Returns the style of the default database which is used to contact PIM data. 166 * Returns the style of the default database which is used to contact PIM data.
@@ -174,30 +205,13 @@ class OBackendFactory
174 205
175 /** 206 /**
176 * Returns the default backend implementation for backendName. Which one is used, is defined 207 * Returns the default backend implementation for backendName. Which one is used, is defined
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 }
201 private: 215 private:
202 OBackendPrivate* d; 216 OBackendPrivate* d;
203 217
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
@@ -52,8 +52,9 @@
52#include <stdlib.h> 52#include <stdlib.h>
53 53
54#include <opie2/ocontactaccessbackend_xml.h> 54#include <opie2/ocontactaccessbackend_xml.h>
55#include <opie2/opimresolver.h> 55#include <opie2/opimresolver.h>
56#include <opie2/opimglobal.h>
56 57
57namespace Opie { 58namespace Opie {
58 59
59OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 60OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
@@ -64,9 +65,9 @@ OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
64 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 65 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
65 */ 66 */
66 if( end == 0 ) { 67 if( end == 0 ) {
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 }
70 // Set backend locally and in template 71 // Set backend locally and in template
71 m_backEnd = end; 72 m_backEnd = end;
72 OPimAccessTemplate<OPimContact>::setBackEnd (end); 73 OPimAccessTemplate<OPimContact>::setBackEnd (end);
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
@@ -28,8 +28,9 @@
28*/ 28*/
29#include <opie2/obackendfactory.h> 29#include <opie2/obackendfactory.h>
30#include <opie2/odatebookaccess.h> 30#include <opie2/odatebookaccess.h>
31#include <opie2/opimresolver.h> 31#include <opie2/opimresolver.h>
32#include <opie2/opimglobal.h>
32 33
33namespace Opie { 34namespace Opie {
34/** 35/**
35 * Simple constructor 36 * Simple constructor
@@ -41,9 +42,9 @@ namespace Opie {
41ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 42ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
42 : OPimAccessTemplate<OPimEvent>( back ) 43 : OPimAccessTemplate<OPimEvent>( back )
43{ 44{
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
47 m_backEnd = back; 48 m_backEnd = back;
48 setBackEnd( m_backEnd ); 49 setBackEnd( m_backEnd );
49} 50}
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
@@ -49,9 +49,9 @@ class OPimGlobal{
49 DEFAULT, // Use default Database 49 DEFAULT, // Use default Database
50 UNKNOWN, // Unknown database style 50 UNKNOWN, // Unknown database style
51 XML, 51 XML,
52 SQL, 52 SQL,
53 VCARD, 53 VCARD, // Also used for VCARD !
54 _END_DatabaseStyle 54 _END_DatabaseStyle
55 }; 55 };
56 56
57 57
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
@@ -33,8 +33,9 @@
33// #include "otodoaccesssql.h" 33// #include "otodoaccesssql.h"
34#include <opie2/otodoaccess.h> 34#include <opie2/otodoaccess.h>
35#include <opie2/obackendfactory.h> 35#include <opie2/obackendfactory.h>
36#include <opie2/opimresolver.h> 36#include <opie2/opimresolver.h>
37#include <opie2/opimglobal.h>
37 38
38namespace Opie { 39namespace Opie {
39OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) 40OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
40 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) 41 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
@@ -43,9 +44,9 @@ OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
43// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); 44// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null);
44 45
45 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! 46 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben !
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
49 setBackEnd( m_todoBackEnd ); 50 setBackEnd( m_todoBackEnd );
50} 51}
51OPimTodoAccess::~OPimTodoAccess() { 52OPimTodoAccess::~OPimTodoAccess() {