author | eilers <eilers> | 2002-10-07 17:34:24 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-10-07 17:34:24 (UTC) |
commit | 0981af024243b314b45ddaf3ebee08bc184f06e2 (patch) (side-by-side diff) | |
tree | 578c3057b922911010bfbddc373476e3ae3b32f6 /libopie2/opiepim | |
parent | ab5b7ba61580bfd3aa20297e67bd9fa6b6c90d41 (diff) | |
download | opie-0981af024243b314b45ddaf3ebee08bc184f06e2.zip opie-0981af024243b314b45ddaf3ebee08bc184f06e2.tar.gz opie-0981af024243b314b45ddaf3ebee08bc184f06e2.tar.bz2 |
added OBackendFactory for advanced backend access
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 88 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 10 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 10 |
4 files changed, 110 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h new file mode 100644 index 0000000..599fbf2 --- a/dev/null +++ b/libopie2/opiepim/backend/obackendfactory.h @@ -0,0 +1,88 @@ +/* + * Class to manage Backends. + * + * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) + * + * ===================================================================== + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later + * version. + * ===================================================================== + * ToDo: Use plugins + * ===================================================================== + * Version: $Id$ + * ===================================================================== + * History: + * $Log$ + * Revision 1.1 2002/10/07 17:35:01 eilers + * added OBackendFactory for advanced backend access + * + * + * ===================================================================== + */ +#ifndef __OPIE_BACKENDFACTORY_H_ +#define __OPIE_BACKENDFACTORY_H_ + +#include <qstring.h> +#include <qasciidict.h> +#include <qpe/config.h> + +#include "otodoaccessxml.h" +#include "ocontactaccessbackend_xml.h" +#include "otodoaccesssql.h" + + +template<class T> +class OBackendFactory +{ + public: + OBackendFactory() {}; + + enum BACKENDS { + TODO, + CONTACT, + DATE + }; + + static T* Default( const QString backendName, const QString& appName ){ + + + Config config( "pimaccess" ); + config.setGroup ( backendName ); + QString backend = config.readEntry( "usebackend" ); + + QAsciiDict<int> dict ( 3 ); + dict.setAutoDelete ( TRUE ); + + dict.insert( "todo", new int (TODO) ); + dict.insert( "contact", new int (CONTACT) ); + + qWarning ("TODO is: %d", TODO); + qWarning ("CONTACT is: %d", CONTACT); + + switch ( *dict.take( backendName ) ){ + case TODO: + if ( backend == "sql" ) + return (T*) new OTodoAccessBackendSQL(""); + + return (T*) new OTodoAccessXML( appName ); + case CONTACT: + if ( backend == "sql" ) + qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); + + return (T*) new OContactAccessBackend_XML( appName ); + case DATE: + qWarning ("OBackendFactory:: DATE-Backend not implemented!"); + return NULL; + default: + return NULL; + } + + + } +}; + + +#endif diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index 9469bbc..a651477 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h @@ -21,2 +21,5 @@ * $Log$ + * Revision 1.2 2002/10/07 17:34:24 eilers + * added OBackendFactory for advanced backend access + * * Revision 1.1 2002/09/27 17:11:44 eilers @@ -34,2 +37,3 @@ +#include "ocontact.h" #include "opimaccessbackend.h" diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 2cdb45b..97ef40f 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h @@ -19,2 +19,5 @@ * $Log$ + * Revision 1.2 2002/10/07 17:34:24 eilers + * added OBackendFactory for advanced backend access + * * Revision 1.1 2002/09/27 17:11:44 eilers @@ -34,2 +37,3 @@ #include <qfile.h> +#include <qfileinfo.h> #include <qregexp.h> @@ -37,4 +41,10 @@ +#include <qpe/global.h> + #include <opie/xmltree.h> #include "ocontactaccessbackend.h" +#include "ocontactaccess.h" + +#include <stdlib.h> +#include <errno.h> diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 8a8ff08..b5f358b 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -23,2 +23,5 @@ * $Log$ + * Revision 1.3 2002/10/07 17:34:24 eilers + * added OBackendFactory for advanced backend access + * * Revision 1.2 2002/10/02 16:18:11 eilers @@ -36,2 +39,3 @@ #include "ocontactaccess.h" +#include "obackendfactory.h" @@ -55,3 +59,3 @@ -OContactAccess::OContactAccess ( const QString appname, const QString filename, +OContactAccess::OContactAccess ( const QString appname, const QString , OContactAccessBackend* end, bool autosync ): @@ -64,3 +68,5 @@ OContactAccess::OContactAccess ( const QString appname, const QString filename, if( end == 0 ) { - end = new OContactAccessBackend_XML( appname, filename ); + // __asm__("int3"); + qWarning ("Using BackendFactory !"); + end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); } |