From 0981af024243b314b45ddaf3ebee08bc184f06e2 Mon Sep 17 00:00:00 2001 From: eilers Date: Mon, 07 Oct 2002 17:34:24 +0000 Subject: added OBackendFactory for advanced backend access --- (limited to 'libopie/pim/obackendfactory.h') 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 @@ +/* + * 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 +#include +#include + +#include "otodoaccessxml.h" +#include "ocontactaccessbackend_xml.h" +#include "otodoaccesssql.h" + + +template +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 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 -- cgit v0.9.0.2