Diffstat (limited to 'libopie2/opiepim/backend/obackendfactory.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 3a73210..ad6cf5a 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,102 +1,126 @@ | |||
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.6 2003/04/13 18:07:10 zecke | ||
20 | * More API doc | ||
21 | * QString -> const QString& | ||
22 | * QString = 0l -> QString::null | ||
23 | * | ||
19 | * Revision 1.5 2003/02/21 23:31:52 zecke | 24 | * Revision 1.5 2003/02/21 23:31:52 zecke |
20 | * Add XML datebookresource | 25 | * Add XML datebookresource |
21 | * -clean up todoaccessxml header | 26 | * -clean up todoaccessxml header |
22 | * -implement some more stuff in the oeven tester | 27 | * -implement some more stuff in the oeven tester |
23 | * -extend DefaultFactory to not crash and to use datebook | 28 | * -extend DefaultFactory to not crash and to use datebook |
24 | * | 29 | * |
25 | * -reading of OEvents is working nicely.. saving will be added | 30 | * -reading of OEvents is working nicely.. saving will be added |
26 | * tomorrow | 31 | * tomorrow |
27 | * -fix spelling in ODateBookAcces | 32 | * -fix spelling in ODateBookAcces |
28 | * | 33 | * |
29 | * Revision 1.4 2002/10/14 15:55:18 eilers | 34 | * Revision 1.4 2002/10/14 15:55:18 eilers |
30 | * Redeactivate SQL.. ;) | 35 | * Redeactivate SQL.. ;) |
31 | * | 36 | * |
32 | * Revision 1.3 2002/10/10 17:08:58 zecke | 37 | * Revision 1.3 2002/10/10 17:08:58 zecke |
33 | * The Cache is finally in place | 38 | * The Cache is finally in place |
34 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
35 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... | 40 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... |
36 | * I still have to fully implement read ahead | 41 | * I still have to fully implement read ahead |
37 | * This change is bic but sc | 42 | * This change is bic but sc |
38 | * | 43 | * |
39 | * Revision 1.2 2002/10/08 09:27:36 eilers | 44 | * Revision 1.2 2002/10/08 09:27:36 eilers |
40 | * Fixed libopie.pro to include the new pim-API. | 45 | * Fixed libopie.pro to include the new pim-API. |
41 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
42 | * compile itself would need to install libsqlite, libopiesql... | 47 | * compile itself would need to install libsqlite, libopiesql... |
43 | * Therefore, the backend currently uses XML only.. | 48 | * Therefore, the backend currently uses XML only.. |
44 | * | 49 | * |
45 | * Revision 1.1 2002/10/07 17:35:01 eilers | 50 | * Revision 1.1 2002/10/07 17:35:01 eilers |
46 | * added OBackendFactory for advanced backend access | 51 | * added OBackendFactory for advanced backend access |
47 | * | 52 | * |
48 | * | 53 | * |
49 | * ===================================================================== | 54 | * ===================================================================== |
50 | */ | 55 | */ |
51 | #ifndef OPIE_BACKENDFACTORY_H_ | 56 | #ifndef OPIE_BACKENDFACTORY_H_ |
52 | #define OPIE_BACKENDFACTORY_H_ | 57 | #define OPIE_BACKENDFACTORY_H_ |
53 | 58 | ||
54 | #include <qstring.h> | 59 | #include <qstring.h> |
55 | #include <qasciidict.h> | 60 | #include <qasciidict.h> |
56 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
57 | 62 | ||
58 | #include "otodoaccessxml.h" | 63 | #include "otodoaccessxml.h" |
59 | #include "ocontactaccessbackend_xml.h" | 64 | #include "ocontactaccessbackend_xml.h" |
60 | #include "odatebookaccessbackend_xml.h" | 65 | #include "odatebookaccessbackend_xml.h" |
61 | 66 | ||
62 | #ifdef __USE_SQL | 67 | #ifdef __USE_SQL |
63 | #include "otodoaccesssql.h" | 68 | #include "otodoaccesssql.h" |
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | 71 | /** | |
72 | * This class is our factory. It will give us the default implementations | ||
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | ||
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | ||
75 | * to recompile.# | ||
76 | * This class as the whole PIM Api is making use of templates | ||
77 | * | ||
78 | * <pre> | ||
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | ||
80 | * backend->load(); | ||
81 | * </pre> | ||
82 | * | ||
83 | * @author Stefan Eilers | ||
84 | * @version 0.1 | ||
85 | */ | ||
67 | template<class T> | 86 | template<class T> |
68 | class OBackendFactory | 87 | class OBackendFactory |
69 | { | 88 | { |
70 | public: | 89 | public: |
71 | OBackendFactory() {}; | 90 | OBackendFactory() {}; |
72 | 91 | ||
73 | enum BACKENDS { | 92 | enum BACKENDS { |
74 | TODO, | 93 | TODO, |
75 | CONTACT, | 94 | CONTACT, |
76 | DATE | 95 | DATE |
77 | }; | 96 | }; |
78 | 97 | ||
98 | /** | ||
99 | * Returns a backend implementation for backendName | ||
100 | * @param backendName the type of the backend | ||
101 | * @param appName will be passed on to the backend | ||
102 | */ | ||
79 | static T* Default( const QString backendName, const QString& appName ){ | 103 | static T* Default( const QString backendName, const QString& appName ){ |
80 | 104 | ||
81 | // __asm__("int3"); | 105 | // __asm__("int3"); |
82 | 106 | ||
83 | Config config( "pimaccess" ); | 107 | Config config( "pimaccess" ); |
84 | config.setGroup ( backendName ); | 108 | config.setGroup ( backendName ); |
85 | QString backend = config.readEntry( "usebackend" ); | 109 | QString backend = config.readEntry( "usebackend" ); |
86 | 110 | ||
87 | QAsciiDict<int> dict ( 3 ); | 111 | QAsciiDict<int> dict ( 3 ); |
88 | dict.setAutoDelete ( TRUE ); | 112 | dict.setAutoDelete ( TRUE ); |
89 | 113 | ||
90 | dict.insert( "todo", new int (TODO) ); | 114 | dict.insert( "todo", new int (TODO) ); |
91 | dict.insert( "contact", new int (CONTACT) ); | 115 | dict.insert( "contact", new int (CONTACT) ); |
92 | dict.insert( "datebook", new int(DATE) ); | 116 | dict.insert( "datebook", new int(DATE) ); |
93 | 117 | ||
94 | qWarning ("TODO is: %d", TODO); | 118 | qWarning ("TODO is: %d", TODO); |
95 | qWarning ("CONTACT is: %d", CONTACT); | 119 | qWarning ("CONTACT is: %d", CONTACT); |
96 | 120 | ||
97 | int *find = dict[ backendName ]; | 121 | int *find = dict[ backendName ]; |
98 | if (!find ) return 0; | 122 | if (!find ) return 0; |
99 | 123 | ||
100 | switch ( *find ){ | 124 | switch ( *find ){ |
101 | case TODO: | 125 | case TODO: |
102 | #ifdef __USE_SQL | 126 | #ifdef __USE_SQL |