summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authoreilers <eilers>2004-05-16 15:22:41 (UTC)
committer eilers <eilers>2004-05-16 15:22:41 (UTC)
commit703b468052367682959f0e1494eec4b3d12754a8 (patch) (unidiff)
treeaf6e153211a148c416a5afb4ee4aa580ebfd6275 /libopie2/opiepim
parent27794ba158d682d115b2feafea023995265991e6 (diff)
downloadopie-703b468052367682959f0e1494eec4b3d12754a8.zip
opie-703b468052367682959f0e1494eec4b3d12754a8.tar.gz
opie-703b468052367682959f0e1494eec4b3d12754a8.tar.bz2
Introducing a new factory for creating access objects for the pim backends.
It is still very basic but simplifies the access of the pim database and covers the creation process itself.. The new class OPimGlobal will contain constants and enums which should be public available for users of the PIM-classes..
Diffstat (limited to 'libopie2/opiepim') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h103
-rw-r--r--libopie2/opiepim/core/opimaccessfactory.h100
-rw-r--r--libopie2/opiepim/core/opimglobal.h62
3 files changed, 224 insertions, 41 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 06421d1..d101373 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 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 .>+-=
@@ -38,6 +38,7 @@
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/otodoaccessxml.h> 42#include <opie2/otodoaccessxml.h>
42#include <opie2/ocontactaccessbackend_xml.h> 43#include <opie2/ocontactaccessbackend_xml.h>
43#include <opie2/odatebookaccessbackend_xml.h> 44#include <opie2/odatebookaccessbackend_xml.h>
@@ -48,6 +49,9 @@
48#include <opie2/odatebookaccessbackend_sql.h> 49#include <opie2/odatebookaccessbackend_sql.h>
49#endif 50#endif
50 51
52using namespace Opie;
53using namespace Opie::Pim;
54
51namespace Opie { 55namespace Opie {
52 56
53class OBackendPrivate; 57class OBackendPrivate;
@@ -57,7 +61,7 @@ class OBackendPrivate;
57 * 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
58 * 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
59 * to recompile.# 63 * to recompile.#
60 * 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
61 * 65 *
62 * <pre> 66 * <pre>
63 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null ); 67 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default("todo", QString::null );
@@ -73,76 +77,93 @@ class OBackendFactory
73 public: 77 public:
74 OBackendFactory() {}; 78 OBackendFactory() {};
75 79
76 enum BACKENDS {
77 TODO,
78 CONTACT,
79 DATE
80 };
81
82 /** 80 /**
83 * Returns a backend implementation for backendName 81 * Returns a backend implementation
84 * @param backendName the type of the backend 82 * @param type the type of the backend
85 * @param appName will be passed on to the backend 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.
86 */ 85 */
87 static T* Default( const QString backendName, const QString& appName ){ 86 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
88 87 const QString& appName ){
89 // __asm__("int3"); 88 qWarning("Selected backend for %d is: %d", type, database );
90
91 Config config( "pimaccess" );
92 config.setGroup ( backendName );
93 QString backend = config.readEntry( "usebackend" );
94 89
95 qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); 90 switch ( type ){
96 91 case OPimGlobal::TODOLIST:
97 QAsciiDict<int> dict ( 3 );
98 dict.setAutoDelete ( TRUE );
99
100 dict.insert( "todo", new int (TODO) );
101 dict.insert( "contact", new int (CONTACT) );
102 dict.insert( "datebook", new int(DATE) );
103
104 int *find = dict[ backendName ];
105 if (!find ) return 0;
106
107 switch ( *find ){
108 case TODO:
109#ifdef __USE_SQL 92#ifdef __USE_SQL
110 if ( backend == "sql" ) 93 if ( database == OPimGlobal::SQL )
111 return (T*) new OPimTodoAccessBackendSQL(""); 94 return (T*) new OPimTodoAccessBackendSQL("");
112#else 95#else
113 if ( backend == "sql" ) 96 if ( database == OPimGlobal::SQL )
114 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); 97 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
115#endif 98#endif
116 99
117 return (T*) new OPimTodoAccessXML( appName ); 100 return (T*) new OPimTodoAccessXML( appName );
118 case CONTACT: 101 case OPimGlobal::CONTACTLIST:
119#ifdef __USE_SQL 102#ifdef __USE_SQL
120 if ( backend == "sql" ) 103 if ( database == OPimGlobal::SQL )
121 return (T*) new OPimContactAccessBackend_SQL(""); 104 return (T*) new OPimContactAccessBackend_SQL("");
122#else 105#else
123 if ( backend == "sql" ) 106 if ( database == OPimGlobal::SQL )
124 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); 107 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
125#endif 108#endif
126 109
127 return (T*) new OPimContactAccessBackend_XML( appName ); 110 return (T*) new OPimContactAccessBackend_XML( appName );
128 case DATE: 111 case OPimGlobal::DATEBOOK:
129#ifdef __USE_SQL 112#ifdef __USE_SQL
130 if ( backend == "sql" ) 113 if ( database == OPimGlobal::SQL )
131 return (T*) new ODateBookAccessBackend_SQL(""); 114 return (T*) new ODateBookAccessBackend_SQL("");
132#else 115#else
133 if ( backend == "sql" ) 116 if ( database == OPimGlobal::SQL )
134 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); 117 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!");
135#endif 118#endif
136 119
137 return (T*) new ODateBookAccessBackend_XML( appName ); 120 return (T*) new ODateBookAccessBackend_XML( appName );
138 default: 121 default:
139 return NULL; 122 return (T*) NULL;
140 } 123 }
141 124
142 125
143 } 126 }
127
128 /**
129 * Returns the default backend implementation for backendName. Which one is used, is defined
130 * by the configfile "pimaccess.conf".
131 * @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
133 */
134 static T* Default( const QString backendName, const QString& appName ){
135
136 QAsciiDict<int> dictBackends( OPimGlobal::_END_PimType );
137 dictBackends.setAutoDelete ( TRUE );
138
139 dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) );
140 dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) );
141 dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) );
142
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 ];
156 if ( !backend_find || !db_find ) return NULL;
157
158 qDebug( "OBackendFactory::Default -> Backend is %s, Database is %s", backendName.latin1(),
159 db_String.latin1() );
160
161 return create( (OPimGlobal::PimType) *backend_find, (OPimGlobal::DatabaseStyle) *db_find, appName );
162
163 }
144 private: 164 private:
145 OBackendPrivate* d; 165 OBackendPrivate* d;
166
146}; 167};
147 168
148} 169}
diff --git a/libopie2/opiepim/core/opimaccessfactory.h b/libopie2/opiepim/core/opimaccessfactory.h
new file mode 100644
index 0000000..ba99a15
--- a/dev/null
+++ b/libopie2/opiepim/core/opimaccessfactory.h
@@ -0,0 +1,100 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef __OPIE_OPIMACCESSFACTORY_H_
31#define __OPIE_OPIMACCESSFACTORY_H_
32
33#include <opie2/opimglobal.h>
34#include <opie2/obackendfactory.h>
35#include <opie2/ocontactaccess.h>
36#include <opie2/otodoaccess.h>
37#include <opie2/odatebookaccess.h>
38
39using namespace Opie::Pim;
40
41namespace Opie {
42
43
44/**
45 * This class is our factory for creating PIM access objects. You should use these objects to load, store and search
46 * information in our PIM databases. Currently we support objects for accessing the datebook, the contact- and the
47 * todolist.
48 * @see OPimGlobal for more information of used values.
49 *
50 * This class - as the whole PIM Api - is making use of templates
51 *
52 * Example for getting an access object for the XML database of todolist:
53 * <pre>
54 * OPimTodoAccess* access = OPimAccessFactory<OPimTodoAccess>::create( OPimGlobal::TODOLIST, OPimGlobal::XML, "example" );
55 * </pre>
56 *
57 * @author Stefan Eilers
58 * @version 0.1
59 */
60 */
61
62template<class T>
63class OPimAccessFactory
64{
65 public:
66
67 // Maybe we should introduce a global class for storing such global enums
68 // (something like opimglobal.h) ? (eilers)
69
70 OPimAccessFactory() {};
71
72 /**
73 * Returns the selected PIM access-object.
74 * @param type Type of the selected database (addressbook, todolist or datebook)
75 * @param dbStyle Which database style should be used (xml, sql, vcard)
76 * @param appName "Name" of your application. This should be any constant string which is used
77 * by some backends for creating special files (i.e.journal files). Please keep the
78 * string unique for your application !
79 * @see OPimGlobal
80 */
81 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle dbStyle, const QString& appName ){
82
83 switch ( type ){
84 case OPimGlobal::TODOLIST:
85 return dynamic_cast<T*>( new OPimTodoAccess( OBackendFactory<OPimTodoAccessBackend>::create( type, dbStyle, appName ) ) );
86 case OPimGlobal::CONTACTLIST:
87 return dynamic_cast<T*>( new OPimContactAccess( QString::null, QString::null, OBackendFactory<OPimContactAccessBackend>::create( type, dbStyle, appName ) ) );
88 case OPimGlobal::DATEBOOK:
89 return dynamic_cast<T*>( new ODateBookAccess( OBackendFactory<ODateBookAccessBackend>::create( type, dbStyle, appName ) ) );
90 default:
91 return 0l;
92
93 }
94 }
95};
96
97}
98
99
100#endif
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h
new file mode 100644
index 0000000..2d336b4
--- a/dev/null
+++ b/libopie2/opiepim/core/opimglobal.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29#ifndef __OPIMGLOBAL_H_
30#define __OPIMGLOBAL_H_
31
32namespace Opie{
33namespace Pim{
34
35
36 /**
37 * Contains global types and enums for the PIM-API
38 */
39class OPimGlobal{
40 public:
41 enum PimType {
42 TODOLIST,
43 CONTACTLIST,
44 DATEBOOK,
45 _END_PimType
46 };
47
48 enum DatabaseStyle {
49 XML,
50 SQL,
51 VCARD,
52 _END_DatabaseStyle
53 };
54
55
56};
57
58}
59}
60
61
62#endif