-rw-r--r-- | libopie/pim/obackendfactory.h | 88 |
1 files changed, 88 insertions, 0 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 | ||