summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h61
-rw-r--r--libopie2/opiepim/core/opimglobal.h2
2 files changed, 46 insertions, 17 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index d101373..d8caa80 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -1,171 +1,198 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: Use plugins 31 * ToDo: Use plugins
32 * ===================================================================== 32 * =====================================================================
33 */ 33 */
34#ifndef OPIE_BACKENDFACTORY_H_ 34#ifndef OPIE_BACKENDFACTORY_H_
35#define OPIE_BACKENDFACTORY_H_ 35#define OPIE_BACKENDFACTORY_H_
36 36
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/opimglobal.h> 41#include <opie2/opimglobal.h>
42#include <opie2/otodoaccessxml.h> 42#include <opie2/otodoaccessxml.h>
43#include <opie2/ocontactaccessbackend_xml.h> 43#include <opie2/ocontactaccessbackend_xml.h>
44#include <opie2/odatebookaccessbackend_xml.h> 44#include <opie2/odatebookaccessbackend_xml.h>
45 45
46#ifdef __USE_SQL 46#ifdef __USE_SQL
47#include <opie2/otodoaccesssql.h> 47#include <opie2/otodoaccesssql.h>
48#include <opie2/ocontactaccessbackend_sql.h> 48#include <opie2/ocontactaccessbackend_sql.h>
49#include <opie2/odatebookaccessbackend_sql.h> 49#include <opie2/odatebookaccessbackend_sql.h>
50#endif 50#endif
51 51
52using namespace Opie; 52using namespace Opie;
53using namespace Opie::Pim; 53using namespace Opie::Pim;
54 54
55namespace Opie { 55namespace Opie {
56 56
57class OBackendPrivate; 57class OBackendPrivate;
58 58
59/** 59/**
60 * This class is our factory. It will give us the default implementations 60 * This class is our factory. It will give us the default implementations
61 * of at least Todolist, Contacts and Datebook. In the future this class will 61 * of at least Todolist, Contacts and Datebook. In the future this class will
62 * allow users to switch the backend with ( XML->SQLite ) without the need 62 * allow users to switch the backend with ( XML->SQLite ) without the need
63 * to recompile.# 63 * to recompile.#
64 * This class - as the whole PIM Api - is making use of templates 64 * This class - as the whole PIM Api - is making use of templates
65 * 65 *
66 * <pre> 66 * <pre>
67 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); 67 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null );
68 * backend->load(); 68 * backend->load();
69 * </pre> 69 * </pre>
70 * 70 *
71 * @author Stefan Eilers 71 * @author Stefan Eilers
72 * @version 0.1 72 * @version 0.1
73 */ 73 */
74template<class T> 74template<class T>
75class OBackendFactory 75class OBackendFactory
76{ 76{
77 public: 77 public:
78 OBackendFactory() {}; 78 OBackendFactory() {};
79 79
80 /** 80 /**
81 * Returns a backend implementation 81 * Returns a selected backend implementation
82 * @param type the type of the backend 82 * @param type the type of the backend
83 * @param database the type of the used database 83 * @param database the type of the used database
84 * @param appName The name of your application. It will be passed on to the backend. 84 * @param appName The name of your application. It will be passed on to the backend.
85 */ 85 */
86 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, 86 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
87 const QString& appName ){ 87 const QString& appName ){
88 qWarning("Selected backend for %d is: %d", type, database ); 88 qWarning("Selected backend for %d is: %d", type, database );
89 89
90 switch ( type ){ 90 switch ( type ){
91 case OPimGlobal::TODOLIST: 91 case OPimGlobal::TODOLIST:
92#ifdef __USE_SQL 92#ifdef __USE_SQL
93 if ( database == OPimGlobal::SQL ) 93 if ( database == OPimGlobal::SQL )
94 return (T*) new OPimTodoAccessBackendSQL(""); 94 return (T*) new OPimTodoAccessBackendSQL("");
95#else 95#else
96 if ( database == OPimGlobal::SQL ) 96 if ( database == OPimGlobal::SQL )
97 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); 97 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
98#endif 98#endif
99 99
100 return (T*) new OPimTodoAccessXML( appName ); 100 return (T*) new OPimTodoAccessXML( appName );
101 case OPimGlobal::CONTACTLIST: 101 case OPimGlobal::CONTACTLIST:
102#ifdef __USE_SQL 102#ifdef __USE_SQL
103 if ( database == OPimGlobal::SQL ) 103 if ( database == OPimGlobal::SQL )
104 return (T*) new OPimContactAccessBackend_SQL(""); 104 return (T*) new OPimContactAccessBackend_SQL("");
105#else 105#else
106 if ( database == OPimGlobal::SQL ) 106 if ( database == OPimGlobal::SQL )
107 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); 107 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
108#endif 108#endif
109 109
110 return (T*) new OPimContactAccessBackend_XML( appName ); 110 return (T*) new OPimContactAccessBackend_XML( appName );
111 case OPimGlobal::DATEBOOK: 111 case OPimGlobal::DATEBOOK:
112#ifdef __USE_SQL 112#ifdef __USE_SQL
113 if ( database == OPimGlobal::SQL ) 113 if ( database == OPimGlobal::SQL )
114 return (T*) new ODateBookAccessBackend_SQL(""); 114 return (T*) new ODateBookAccessBackend_SQL("");
115#else 115#else
116 if ( database == OPimGlobal::SQL ) 116 if ( database == OPimGlobal::SQL )
117 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); 117 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!");
118#endif 118#endif
119 119
120 return (T*) new ODateBookAccessBackend_XML( appName ); 120 return (T*) new ODateBookAccessBackend_XML( appName );
121 default: 121 default:
122 return (T*) NULL; 122 return (T*) NULL;
123 } 123 }
124 124
125 125
126 } 126 }
127 127
128
129 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType backend ){
130 QString group_name;
131 switch ( backend ){
132 case OPimGlobal::TODOLIST:
133 group_name = "todo";
134 break;
135 case OPimGlobal::CONTACTLIST:
136 group_name = "contact";
137 break;
138 case OPimGlobal::DATEBOOK:
139 group_name = "datebook";
140 break;
141 default:
142 group_name = "unknown";
143 }
144
145 Config config( "pimaccess" );
146 config.setGroup ( group_name );
147 QString db_String = config.readEntry( "usebackend" );
148
149 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
150 dictDbTypes.setAutoDelete( TRUE );
151
152 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
153 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
154 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
155
156 int* db_find = dictDbTypes[ db_String ];
157
158 if ( !db_find )
159 return OPimGlobal::UNKNOWN;
160
161 return (OPimGlobal::DatabaseStyle) *db_find;
162 }
163
164
128 /** 165 /**
129 * Returns the default backend implementation for backendName. Which one is used, is defined 166 * Returns the default backend implementation for backendName. Which one is used, is defined
130 * by the configfile "pimaccess.conf". 167 * by the configfile "pimaccess.conf".
131 * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) 168 * @param backendName the type of the backend (use "todo", "contact" or "datebook" )
132 * @param appName The name of your application. It will be passed on to the backend 169 * @param appName The name of your application. It will be passed on to the backend
133 */ 170 */
134 static T* Default( const QString backendName, const QString& appName ){ 171 static T* Default( const QString backendName, const QString& appName ){
135 172
136 QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType ); 173 QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType );
137 dictBackends.setAutoDelete ( TRUE ); 174 dictBackends.setAutoDelete ( TRUE );
138 175
139 dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); 176 dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) );
140 dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); 177 dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) );
141 dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); 178 dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) );
142 179
143 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
144 dictDbTypes.setAutoDelete( TRUE );
145
146 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
147 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
148 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
149
150 Config config( "pimaccess" );
151 config.setGroup ( backendName );
152 QString db_String = config.readEntry( "usebackend" );
153
154 int* db_find = dictDbTypes[ db_String ];
155 int* backend_find = dictBackends[ backendName ]; 180 int* backend_find = dictBackends[ backendName ];
156 if ( !backend_find || !db_find ) return NULL; 181 if ( !backend_find ) return NULL;
182
183 OPimGlobal::DatabaseStyle style = defaultDB( static_cast<OPimGlobal::PimType>( *backend_find ) );
157 184
158 qDebug( "OBackendFactory::Default -> Backend is %s, Database is %s", backendName.latin1(), 185 qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(),
159 db_String.latin1() ); 186 style );
160 187
161 return create( (OPimGlobal::PimType) *backend_find, (OPimGlobal::DatabaseStyle) *db_find, appName ); 188 return create( (OPimGlobal::PimType) *backend_find, style, appName );
162 189
163 } 190 }
164 private: 191 private:
165 OBackendPrivate* d; 192 OBackendPrivate* d;
166 193
167}; 194};
168 195
169} 196}
170 197
171#endif 198#endif
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h
index 2d336b4..d56c9be 100644
--- a/libopie2/opiepim/core/opimglobal.h
+++ b/libopie2/opiepim/core/opimglobal.h
@@ -1,62 +1,64 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef __OPIMGLOBAL_H_ 29#ifndef __OPIMGLOBAL_H_
30#define __OPIMGLOBAL_H_ 30#define __OPIMGLOBAL_H_
31 31
32namespace Opie{ 32namespace Opie{
33namespace Pim{ 33namespace Pim{
34 34
35 35
36 /** 36 /**
37 * Contains global types and enums for the PIM-API 37 * Contains global types and enums for the PIM-API
38 */ 38 */
39class OPimGlobal{ 39class OPimGlobal{
40 public: 40 public:
41 enum PimType { 41 enum PimType {
42 TODOLIST, 42 TODOLIST,
43 CONTACTLIST, 43 CONTACTLIST,
44 DATEBOOK, 44 DATEBOOK,
45 _END_PimType 45 _END_PimType
46 }; 46 };
47 47
48 enum DatabaseStyle { 48 enum DatabaseStyle {
49 DEFAULT, // Use default Database
50 UNKNOWN, // Unknown database style
49 XML, 51 XML,
50 SQL, 52 SQL,
51 VCARD, 53 VCARD,
52 _END_DatabaseStyle 54 _END_DatabaseStyle
53 }; 55 };
54 56
55 57
56}; 58};
57 59
58} 60}
59} 61}
60 62
61 63
62#endif 64#endif