summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h276
1 files changed, 138 insertions, 138 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 3680ded..9f3a823 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -62,9 +62,9 @@ using namespace Opie;
62using namespace Opie::Pim; 62using namespace Opie::Pim;
63 63
64namespace Opie { 64namespace Opie {
65 65
66class OBackendPrivate; 66class 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
@@ -80,151 +80,151 @@ class OBackendPrivate;
80 * @author Stefan Eilers 80 * @author Stefan Eilers
81 * @version 0.1 81 * @version 0.1
82 */ 82 */
83template<class T> 83 template<class T>
84class 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: " << database << oendl;
100 // 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
101 OPimGlobal::DatabaseStyle use_database = database; 101 OPimGlobal::DatabaseStyle use_database = database;
102 if ( use_database == OPimGlobal::DEFAULT ){ 102 if ( use_database == OPimGlobal::DEFAULT ){
103 use_database = defaultDB( type ); 103 use_database = defaultDB( type );
104 } 104 }
105 105
106 switch ( type ){ 106 switch ( type ){
107 case OPimGlobal::TODOLIST: 107 case OPimGlobal::TODOLIST:
108 108
109 switch ( use_database ){ 109 switch ( use_database ){
110 default: // Use SQL if something weird is given. 110 default: // Use SQL if something weird is given.
111 // Fall through !! 111 // Fall through !!
112 case OPimGlobal::SQL: 112 case OPimGlobal::SQL:
113#ifdef __USE_SQL 113#ifdef __USE_SQL
114 return (T*) new OPimTodoAccessBackendSQL( filename ); 114 return (T*) new OPimTodoAccessBackendSQL( filename );
115 break; 115 break;
116#else 116#else
117 owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl; 117 owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl;
118 // Fall through !! 118 // Fall through !!
119#endif 119#endif
120 case OPimGlobal::XML: 120 case OPimGlobal::XML:
121 return (T*) new OPimTodoAccessXML( appName, filename ); 121 return (T*) new OPimTodoAccessXML( appName, filename );
122 break; 122 break;
123 case OPimGlobal::VCARD: 123 case OPimGlobal::VCARD:
124 return (T*) new OPimTodoAccessVCal( filename ); 124 return (T*) new OPimTodoAccessVCal( filename );
125 break; 125 break;
126 } 126 }
127 case OPimGlobal::CONTACTLIST: 127 case OPimGlobal::CONTACTLIST:
128 switch ( use_database ){ 128 switch ( use_database ){
129 default: // Use SQL if something weird is given. 129 default: // Use SQL if something weird is given.
130 // Fall through !! 130 // Fall through !!
131 case OPimGlobal::SQL: 131 case OPimGlobal::SQL:
132#ifdef __USE_SQL 132#ifdef __USE_SQL
133 return (T*) new OPimContactAccessBackend_SQL( appName, filename ); 133 return (T*) new OPimContactAccessBackend_SQL( appName, filename );
134 break; 134 break;
135#else 135#else
136 owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl; 136 owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl;
137 // Fall through !! 137 // Fall through !!
138#endif 138#endif
139 case OPimGlobal::XML: 139 case OPimGlobal::XML:
140 return (T*) new OPimContactAccessBackend_XML( appName, filename ); 140 return (T*) new OPimContactAccessBackend_XML( appName, filename );
141 break; 141 break;
142 case OPimGlobal::VCARD: 142 case OPimGlobal::VCARD:
143 return (T*) new OPimContactAccessBackend_VCard( appName, filename ); 143 return (T*) new OPimContactAccessBackend_VCard( appName, filename );
144 break; 144 break;
145 } 145 }
146 case OPimGlobal::DATEBOOK: 146 case OPimGlobal::DATEBOOK:
147 switch ( use_database ){ 147 switch ( use_database ){
148 default: // Use SQL if something weird is given. 148 default: // Use SQL if something weird is given.
149 // Fall through !! 149 // Fall through !!
150 case OPimGlobal::SQL: 150 case OPimGlobal::SQL:
151#ifdef __USE_SQL 151#ifdef __USE_SQL
152 return (T*) new ODateBookAccessBackend_SQL( appName, filename ); 152 return (T*) new ODateBookAccessBackend_SQL( appName, filename );
153 break; 153 break;
154#else 154#else
155 owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl; 155 owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl;
156 // Fall through !! 156 // Fall through !!
157#endif 157#endif
158 case OPimGlobal::XML: 158 case OPimGlobal::XML:
159 return (T*) new ODateBookAccessBackend_XML( appName, filename ); 159 return (T*) new ODateBookAccessBackend_XML( appName, filename );
160 break; 160 break;
161 case OPimGlobal::VCARD: 161 case OPimGlobal::VCARD:
162 owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl; 162 owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl;
163 return (T*) NULL; 163 return (T*) NULL;
164 break; 164 break;
165 } 165 }
166 default: 166 default:
167 return (T*) NULL; 167 return (T*) NULL;
168 } 168 }
169 169
170 } 170 }
171 171
172 /** 172 /**
173 * 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.
174 * @param type the type of the backend 174 * @param type the type of the backend
175 * @see OPimGlobal() 175 * @see OPimGlobal()
176 */ 176 */
177 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ 177 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
178 QString group_name; 178 QString group_name;
179 switch ( type ){ 179 switch ( type ){
180 case OPimGlobal::TODOLIST: 180 case OPimGlobal::TODOLIST:
181 group_name = "todo"; 181 group_name = "todo";
182 break; 182 break;
183 case OPimGlobal::CONTACTLIST: 183 case OPimGlobal::CONTACTLIST:
184 group_name = "contact"; 184 group_name = "contact";
185 break; 185 break;
186 case OPimGlobal::DATEBOOK: 186 case OPimGlobal::DATEBOOK:
187 group_name = "datebook"; 187 group_name = "datebook";
188 break; 188 break;
189 default: 189 default:
190 group_name = "unknown"; 190 group_name = "unknown";
191 } 191 }
192 192
193 Config config( "pimaccess" ); 193 Config config( "pimaccess" );
194 config.setGroup ( group_name ); 194 config.setGroup ( group_name );
195 QString db_String = config.readEntry( "usebackend", "xml" ); 195 QString db_String = config.readEntry( "usebackend", "xml" );
196 196
197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); 197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
198 dictDbTypes.setAutoDelete( TRUE ); 198 dictDbTypes.setAutoDelete( TRUE );
199 199
200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); 200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
201 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); 201 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); 202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
203 203
204 int* db_find = dictDbTypes[ db_String ]; 204 int* db_find = dictDbTypes[ db_String ];
205 205
206 if ( !db_find ) 206 if ( !db_find )
207 return OPimGlobal::UNKNOWN; 207 return OPimGlobal::UNKNOWN;
208 208
209 return (OPimGlobal::DatabaseStyle) *db_find; 209 return (OPimGlobal::DatabaseStyle) *db_find;
210 } 210 }
211 211
212 212
213 /** 213 /**
214 * 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
215 * by the configfile "pimaccess.conf". 215 * by the configfile "pimaccess.conf".
216 * @param type The type of the backend (@see OPimGlobal()) 216 * @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 217 * @param appName The name of your application. It will be passed on to the backend
218 * @see OPimGlobal() 218 * @see OPimGlobal()
219 */ 219 */
220 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ 220 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
221 return create( type, OPimGlobal::DEFAULT, appName ); 221 return create( type, OPimGlobal::DEFAULT, appName );
222 } 222 }
223 private: 223 private:
224 OBackendPrivate* d; 224 OBackendPrivate* d;
225 225
226}; 226 };
227 227
228} 228}
229 229
230#endif 230#endif