-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 | |||
@@ -23,2 +23,5 @@ | |||
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 |
@@ -36,2 +39,3 @@ | |||
36 | #include "ocontactaccess.h" | 39 | #include "ocontactaccess.h" |
40 | #include "obackendfactory.h" | ||
37 | 41 | ||
@@ -55,3 +59,3 @@ | |||
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 ): |
@@ -64,3 +68,5 @@ OContactAccess::OContactAccess ( const QString appname, const QString filename, | |||
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 | } |
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 | |||
@@ -21,2 +21,5 @@ | |||
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 |
@@ -34,2 +37,3 @@ | |||
34 | 37 | ||
38 | #include "ocontact.h" | ||
35 | #include "opimaccessbackend.h" | 39 | #include "opimaccessbackend.h" |
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 | |||
@@ -19,2 +19,5 @@ | |||
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 |
@@ -34,2 +37,3 @@ | |||
34 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qfileinfo.h> | ||
35 | #include <qregexp.h> | 39 | #include <qregexp.h> |
@@ -37,4 +41,10 @@ | |||
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 | ||