author | eilers <eilers> | 2002-10-07 17:34:24 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-10-07 17:34:24 (UTC) |
commit | 0981af024243b314b45ddaf3ebee08bc184f06e2 (patch) (unidiff) | |
tree | 578c3057b922911010bfbddc373476e3ae3b32f6 /libopie | |
parent | ab5b7ba61580bfd3aa20297e67bd9fa6b6c90d41 (diff) | |
download | opie-0981af024243b314b45ddaf3ebee08bc184f06e2.zip opie-0981af024243b314b45ddaf3ebee08bc184f06e2.tar.gz opie-0981af024243b314b45ddaf3ebee08bc184f06e2.tar.bz2 |
added OBackendFactory for advanced backend access
-rw-r--r-- | libopie/pim/obackendfactory.h | 88 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.cpp | 10 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend.h | 4 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 10 |
4 files changed, 110 insertions, 2 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h new file mode 100644 index 0000000..599fbf2 --- a/dev/null +++ b/libopie/pim/obackendfactory.h | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * Class to manage Backends. | ||
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; | ||
10 | * either version 2 of the License, or (at your option) any later | ||
11 | * version. | ||
12 | * ===================================================================== | ||
13 | * ToDo: Use plugins | ||
14 | * ===================================================================== | ||
15 | * Version: $Id$ | ||
16 | * ===================================================================== | ||
17 | * History: | ||
18 | * $Log$ | ||
19 | * Revision 1.1 2002/10/07 17:35:01 eilers | ||
20 | * added OBackendFactory for advanced backend access | ||
21 | * | ||
22 | * | ||
23 | * ===================================================================== | ||
24 | */ | ||
25 | #ifndef __OPIE_BACKENDFACTORY_H_ | ||
26 | #define __OPIE_BACKENDFACTORY_H_ | ||
27 | |||
28 | #include <qstring.h> | ||
29 | #include <qasciidict.h> | ||
30 | #include <qpe/config.h> | ||
31 | |||
32 | #include "otodoaccessxml.h" | ||
33 | #include "ocontactaccessbackend_xml.h" | ||
34 | #include "otodoaccesssql.h" | ||
35 | |||
36 | |||
37 | template<class T> | ||
38 | class OBackendFactory | ||
39 | { | ||
40 | public: | ||
41 | OBackendFactory() {}; | ||
42 | |||
43 | enum BACKENDS { | ||
44 | TODO, | ||
45 | CONTACT, | ||
46 | DATE | ||
47 | }; | ||
48 | |||
49 | static T* Default( const QString backendName, const QString& appName ){ | ||
50 | |||
51 | |||
52 | Config config( "pimaccess" ); | ||
53 | config.setGroup ( backendName ); | ||
54 | QString backend = config.readEntry( "usebackend" ); | ||
55 | |||
56 | QAsciiDict<int> dict ( 3 ); | ||
57 | dict.setAutoDelete ( TRUE ); | ||
58 | |||
59 | dict.insert( "todo", new int (TODO) ); | ||
60 | dict.insert( "contact", new int (CONTACT) ); | ||
61 | |||
62 | qWarning ("TODO is: %d", TODO); | ||
63 | qWarning ("CONTACT is: %d", CONTACT); | ||
64 | |||
65 | switch ( *dict.take( backendName ) ){ | ||
66 | case TODO: | ||
67 | if ( backend == "sql" ) | ||
68 | return (T*) new OTodoAccessBackendSQL(""); | ||
69 | |||
70 | return (T*) new OTodoAccessXML( appName ); | ||
71 | case CONTACT: | ||
72 | if ( backend == "sql" ) | ||
73 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | ||
74 | |||
75 | return (T*) new OContactAccessBackend_XML( appName ); | ||
76 | case DATE: | ||
77 | qWarning ("OBackendFactory:: DATE-Backend not implemented!"); | ||
78 | return NULL; | ||
79 | default: | ||
80 | return NULL; | ||
81 | } | ||
82 | |||
83 | |||
84 | } | ||
85 | }; | ||
86 | |||
87 | |||
88 | #endif | ||
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp index 8a8ff08..b5f358b 100644 --- a/libopie/pim/ocontactaccess.cpp +++ b/libopie/pim/ocontactaccess.cpp | |||
@@ -21,6 +21,9 @@ | |||
21 | * ===================================================================== | 21 | * ===================================================================== |
22 | * History: | 22 | * History: |
23 | * $Log$ | 23 | * $Log$ |
24 | * Revision 1.3 2002/10/07 17:34:24 eilers | ||
25 | * added OBackendFactory for advanced backend access | ||
26 | * | ||
24 | * Revision 1.2 2002/10/02 16:18:11 eilers | 27 | * Revision 1.2 2002/10/02 16:18:11 eilers |
25 | * debugged and seems to work almost perfectly .. | 28 | * debugged and seems to work almost perfectly .. |
26 | * | 29 | * |
@@ -34,6 +37,7 @@ | |||
34 | */ | 37 | */ |
35 | 38 | ||
36 | #include "ocontactaccess.h" | 39 | #include "ocontactaccess.h" |
40 | #include "obackendfactory.h" | ||
37 | 41 | ||
38 | #include <qasciidict.h> | 42 | #include <qasciidict.h> |
39 | #include <qdatetime.h> | 43 | #include <qdatetime.h> |
@@ -53,7 +57,7 @@ | |||
53 | #include "ocontactaccessbackend_xml.h" | 57 | #include "ocontactaccessbackend_xml.h" |
54 | 58 | ||
55 | 59 | ||
56 | OContactAccess::OContactAccess ( const QString appname, const QString filename, | 60 | OContactAccess::OContactAccess ( const QString appname, const QString , |
57 | OContactAccessBackend* end, bool autosync ): | 61 | OContactAccessBackend* end, bool autosync ): |
58 | OPimAccessTemplate<OContact>( end ), | 62 | OPimAccessTemplate<OContact>( end ), |
59 | m_changed ( false ) | 63 | m_changed ( false ) |
@@ -62,7 +66,9 @@ OContactAccess::OContactAccess ( const QString appname, const QString filename, | |||
62 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 66 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
63 | */ | 67 | */ |
64 | if( end == 0 ) { | 68 | if( end == 0 ) { |
65 | end = new OContactAccessBackend_XML( appname, filename ); | 69 | // __asm__("int3"); |
70 | qWarning ("Using BackendFactory !"); | ||
71 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | ||
66 | } | 72 | } |
67 | // Set backend locally and in template | 73 | // Set backend locally and in template |
68 | m_backEnd = end; | 74 | m_backEnd = end; |
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h index 9469bbc..a651477 100644 --- a/libopie/pim/ocontactaccessbackend.h +++ b/libopie/pim/ocontactaccessbackend.h | |||
@@ -19,6 +19,9 @@ | |||
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.2 2002/10/07 17:34:24 eilers | ||
23 | * added OBackendFactory for advanced backend access | ||
24 | * | ||
22 | * Revision 1.1 2002/09/27 17:11:44 eilers | 25 | * Revision 1.1 2002/09/27 17:11:44 eilers |
23 | * Added API for accessing the Contact-Database ! It is compiling, but | 26 | * Added API for accessing the Contact-Database ! It is compiling, but |
24 | * please do not expect that anything is working ! | 27 | * please do not expect that anything is working ! |
@@ -32,6 +35,7 @@ | |||
32 | #ifndef _OCONTACTACCESSBACKEND_H_ | 35 | #ifndef _OCONTACTACCESSBACKEND_H_ |
33 | #define _OCONTACTACCESSBACKEND_H_ | 36 | #define _OCONTACTACCESSBACKEND_H_ |
34 | 37 | ||
38 | #include "ocontact.h" | ||
35 | #include "opimaccessbackend.h" | 39 | #include "opimaccessbackend.h" |
36 | 40 | ||
37 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 41 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index 2cdb45b..97ef40f 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -17,6 +17,9 @@ | |||
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.2 2002/10/07 17:34:24 eilers | ||
21 | * added OBackendFactory for advanced backend access | ||
22 | * | ||
20 | * Revision 1.1 2002/09/27 17:11:44 eilers | 23 | * Revision 1.1 2002/09/27 17:11:44 eilers |
21 | * Added API for accessing the Contact-Database ! It is compiling, but | 24 | * Added API for accessing the Contact-Database ! It is compiling, but |
22 | * please do not expect that anything is working ! | 25 | * please do not expect that anything is working ! |
@@ -32,11 +35,18 @@ | |||
32 | #include <qasciidict.h> | 35 | #include <qasciidict.h> |
33 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
34 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qfileinfo.h> | ||
35 | #include <qregexp.h> | 39 | #include <qregexp.h> |
36 | #include <qarray.h> | 40 | #include <qarray.h> |
37 | 41 | ||
42 | #include <qpe/global.h> | ||
43 | |||
38 | #include <opie/xmltree.h> | 44 | #include <opie/xmltree.h> |
39 | #include "ocontactaccessbackend.h" | 45 | #include "ocontactaccessbackend.h" |
46 | #include "ocontactaccess.h" | ||
47 | |||
48 | #include <stdlib.h> | ||
49 | #include <errno.h> | ||
40 | 50 | ||
41 | using namespace Opie; | 51 | using namespace Opie; |
42 | 52 | ||