summaryrefslogtreecommitdiff
path: root/libopie/pim/obackendfactory.h
Unidiff
Diffstat (limited to 'libopie/pim/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/obackendfactory.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h
index f3c339d..3567687 100644
--- a/libopie/pim/obackendfactory.h
+++ b/libopie/pim/obackendfactory.h
@@ -1,42 +1,47 @@
1/* 1/*
2 * Class to manage Backends. 2 * Class to manage Backends.
3 * 3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 5 *
6 * ===================================================================== 6 * =====================================================================
7 *This program is free software; you can redistribute it and/or 7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; 9 * License as published by the Free Software Foundation;
10 * either version 2 of the License, or (at your option) any later 10 * either version 2 of the License, or (at your option) any later
11 * version. 11 * version.
12 * ===================================================================== 12 * =====================================================================
13 * ToDo: Use plugins 13 * ToDo: Use plugins
14 * ===================================================================== 14 * =====================================================================
15 * Version: $Id$ 15 * Version: $Id$
16 * ===================================================================== 16 * =====================================================================
17 * History: 17 * History:
18 * $Log$ 18 * $Log$
19 * Revision 1.8 2003/09/22 14:31:16 eilers
20 * Added first experimental incarnation of sql-backend for addressbook.
21 * Some modifications to be able to compile the todo sql-backend.
22 * A lot of changes fill follow...
23 *
19 * Revision 1.7 2003/08/01 12:30:16 eilers 24 * Revision 1.7 2003/08/01 12:30:16 eilers
20 * Merging changes from BRANCH_1_0 to HEAD 25 * Merging changes from BRANCH_1_0 to HEAD
21 * 26 *
22 * Revision 1.6.4.1 2003/06/30 14:34:19 eilers 27 * Revision 1.6.4.1 2003/06/30 14:34:19 eilers
23 * Patches from Zecke: 28 * Patches from Zecke:
24 * Fixing and cleaning up extraMap handling 29 * Fixing and cleaning up extraMap handling
25 * Adding d_ptr for binary compatibility in the future 30 * Adding d_ptr for binary compatibility in the future
26 * 31 *
27 * Revision 1.6 2003/04/13 18:07:10 zecke 32 * Revision 1.6 2003/04/13 18:07:10 zecke
28 * More API doc 33 * More API doc
29 * QString -> const QString& 34 * QString -> const QString&
30 * QString = 0l -> QString::null 35 * QString = 0l -> QString::null
31 * 36 *
32 * Revision 1.5 2003/02/21 23:31:52 zecke 37 * Revision 1.5 2003/02/21 23:31:52 zecke
33 * Add XML datebookresource 38 * Add XML datebookresource
34 * -clean up todoaccessxml header 39 * -clean up todoaccessxml header
35 * -implement some more stuff in the oeven tester 40 * -implement some more stuff in the oeven tester
36 * -extend DefaultFactory to not crash and to use datebook 41 * -extend DefaultFactory to not crash and to use datebook
37 * 42 *
38 * -reading of OEvents is working nicely.. saving will be added 43 * -reading of OEvents is working nicely.. saving will be added
39 * tomorrow 44 * tomorrow
40 * -fix spelling in ODateBookAcces 45 * -fix spelling in ODateBookAcces
41 * 46 *
42 * Revision 1.4 2002/10/14 15:55:18 eilers 47 * Revision 1.4 2002/10/14 15:55:18 eilers
@@ -53,114 +58,119 @@
53 * Fixed libopie.pro to include the new pim-API. 58 * Fixed libopie.pro to include the new pim-API.
54 * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to 59 * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to
55 * compile itself would need to install libsqlite, libopiesql... 60 * compile itself would need to install libsqlite, libopiesql...
56 * Therefore, the backend currently uses XML only.. 61 * Therefore, the backend currently uses XML only..
57 * 62 *
58 * Revision 1.1 2002/10/07 17:35:01 eilers 63 * Revision 1.1 2002/10/07 17:35:01 eilers
59 * added OBackendFactory for advanced backend access 64 * added OBackendFactory for advanced backend access
60 * 65 *
61 * 66 *
62 * ===================================================================== 67 * =====================================================================
63 */ 68 */
64#ifndef OPIE_BACKENDFACTORY_H_ 69#ifndef OPIE_BACKENDFACTORY_H_
65#define OPIE_BACKENDFACTORY_H_ 70#define OPIE_BACKENDFACTORY_H_
66 71
67#include <qstring.h> 72#include <qstring.h>
68#include <qasciidict.h> 73#include <qasciidict.h>
69#include <qpe/config.h> 74#include <qpe/config.h>
70 75
71#include "otodoaccessxml.h" 76#include "otodoaccessxml.h"
72#include "ocontactaccessbackend_xml.h" 77#include "ocontactaccessbackend_xml.h"
73#include "odatebookaccessbackend_xml.h" 78#include "odatebookaccessbackend_xml.h"
74 79
75#ifdef __USE_SQL 80#ifdef __USE_SQL
76#include "otodoaccesssql.h" 81#include "otodoaccesssql.h"
82#include "ocontactaccessbackend_sql.h"
77#endif 83#endif
78 84
79class OBackendPrivate; 85class OBackendPrivate;
80 86
81/** 87/**
82 * This class is our factory. It will give us the default implementations 88 * This class is our factory. It will give us the default implementations
83 * of at least Todolist, Contacts and Datebook. In the future this class will 89 * of at least Todolist, Contacts and Datebook. In the future this class will
84 * allow users to switch the backend with ( XML->SQLite ) without the need 90 * allow users to switch the backend with ( XML->SQLite ) without the need
85 * to recompile.# 91 * to recompile.#
86 * This class as the whole PIM Api is making use of templates 92 * This class as the whole PIM Api is making use of templates
87 * 93 *
88 * <pre> 94 * <pre>
89 * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); 95 * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null );
90 * backend->load(); 96 * backend->load();
91 * </pre> 97 * </pre>
92 * 98 *
93 * @author Stefan Eilers 99 * @author Stefan Eilers
94 * @version 0.1 100 * @version 0.1
95 */ 101 */
96template<class T> 102template<class T>
97class OBackendFactory 103class OBackendFactory
98{ 104{
99 public: 105 public:
100 OBackendFactory() {}; 106 OBackendFactory() {};
101 107
102 enum BACKENDS { 108 enum BACKENDS {
103 TODO, 109 TODO,
104 CONTACT, 110 CONTACT,
105 DATE 111 DATE
106 }; 112 };
107 113
108 /** 114 /**
109 * Returns a backend implementation for backendName 115 * Returns a backend implementation for backendName
110 * @param backendName the type of the backend 116 * @param backendName the type of the backend
111 * @param appName will be passed on to the backend 117 * @param appName will be passed on to the backend
112 */ 118 */
113 static T* Default( const QString backendName, const QString& appName ){ 119 static T* Default( const QString backendName, const QString& appName ){
114 120
115 // __asm__("int3"); 121 // __asm__("int3");
116 122
117 Config config( "pimaccess" ); 123 Config config( "pimaccess" );
118 config.setGroup ( backendName ); 124 config.setGroup ( backendName );
119 QString backend = config.readEntry( "usebackend" ); 125 QString backend = config.readEntry( "usebackend" );
120 126
127 qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() );
128
121 QAsciiDict<int> dict ( 3 ); 129 QAsciiDict<int> dict ( 3 );
122 dict.setAutoDelete ( TRUE ); 130 dict.setAutoDelete ( TRUE );
123 131
124 dict.insert( "todo", new int (TODO) ); 132 dict.insert( "todo", new int (TODO) );
125 dict.insert( "contact", new int (CONTACT) ); 133 dict.insert( "contact", new int (CONTACT) );
126 dict.insert( "datebook", new int(DATE) ); 134 dict.insert( "datebook", new int(DATE) );
127 135
128 qWarning ("TODO is: %d", TODO);
129 qWarning ("CONTACT is: %d", CONTACT);
130
131 int *find = dict[ backendName ]; 136 int *find = dict[ backendName ];
132 if (!find ) return 0; 137 if (!find ) return 0;
133 138
134 switch ( *find ){ 139 switch ( *find ){
135 case TODO: 140 case TODO:
136#ifdef __USE_SQL 141#ifdef __USE_SQL
137 if ( backend == "sql" ) 142 if ( backend == "sql" )
138 return (T*) new OTodoAccessBackendSQL(""); 143 return (T*) new OTodoAccessBackendSQL("");
139#else 144#else
140 if ( backend == "sql" ) 145 if ( backend == "sql" )
141 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 146 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
142#endif 147#endif
143 148
144 return (T*) new OTodoAccessXML( appName ); 149 return (T*) new OTodoAccessXML( appName );
145 case CONTACT: 150 case CONTACT:
151#ifdef __USE_SQL
152 if ( backend == "sql" )
153 return (T*) new OContactAccessBackend_SQL("");
154#else
146 if ( backend == "sql" ) 155 if ( backend == "sql" )
147 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 156 qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!");
157#endif
148 158
149 return (T*) new OContactAccessBackend_XML( appName ); 159 return (T*) new OContactAccessBackend_XML( appName );
150 case DATE: 160 case DATE:
151 if ( backend == "sql" ) 161 if ( backend == "sql" )
152 qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); 162 qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!");
153 163
154 return (T*) new ODateBookAccessBackend_XML( appName ); 164 return (T*) new ODateBookAccessBackend_XML( appName );
155 default: 165 default:
156 return NULL; 166 return NULL;
157 } 167 }
158 168
159 169
160 } 170 }
161 private: 171 private:
162 OBackendPrivate* d; 172 OBackendPrivate* d;
163}; 173};
164 174
165 175
166#endif 176#endif