libopie PIM API Documentation

obackendfactory.h

Go to the documentation of this file.
00001 /*
00002  * Class to manage Backends.
00003  *
00004  * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
00005  *
00006  * =====================================================================
00007  *  This program is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *      License as published by the Free Software Foundation;
00010  *      either version 2 of the License, or (at your option) any later
00011  *      version.
00012  * =====================================================================
00013  * ToDo: Use plugins
00014  * =====================================================================
00015  * Version: $Id: obackendfactory.h,v 1.9 2003/12/22 10:19:26 eilers Exp $
00016  * =====================================================================
00017  * History:
00018  * $Log: obackendfactory.h,v $
00019  * Revision 1.9  2003/12/22 10:19:26  eilers
00020  * Finishing implementation of sql-backend for datebook. But I have to
00021  * port the PIM datebook application to use it, before I could debug the
00022  * whole stuff.
00023  * Thus, PIM-Database backend is finished, but highly experimental. And some
00024  * parts are still generic. For instance, the "queryByExample()" methods are
00025  * not (or not fully) implemented. Todo: custom-entries not stored.
00026  * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
00027  * expression search in the database, which is not supported by sqlite !
00028  * Therefore we need either an extended sqlite or a workaround which would
00029  * be very slow and memory consuming..
00030  *
00031  * Revision 1.8  2003/09/22 14:31:16  eilers
00032  * Added first experimental incarnation of sql-backend for addressbook.
00033  * Some modifications to be able to compile the todo sql-backend.
00034  * A lot of changes fill follow...
00035  *
00036  * Revision 1.7  2003/08/01 12:30:16  eilers
00037  * Merging changes from BRANCH_1_0 to HEAD
00038  *
00039  * Revision 1.6.4.1  2003/06/30 14:34:19  eilers
00040  * Patches from Zecke:
00041  * Fixing and cleaning up extraMap handling
00042  * Adding d_ptr for binary compatibility in the future
00043  *
00044  * Revision 1.6  2003/04/13 18:07:10  zecke
00045  * More API doc
00046  * QString -> const QString&
00047  * QString = 0l -> QString::null
00048  *
00049  * Revision 1.5  2003/02/21 23:31:52  zecke
00050  * Add XML datebookresource
00051  * -clean up todoaccessxml header
00052  * -implement some more stuff in the oeven tester
00053  * -extend DefaultFactory to not crash and to use datebook
00054  *
00055  * -reading of OEvents is working nicely.. saving will be added
00056  *  tomorrow
00057  *  -fix spelling in ODateBookAcces
00058  *
00059  * Revision 1.4  2002/10/14 15:55:18  eilers
00060  * Redeactivate SQL.. ;)
00061  *
00062  * Revision 1.3  2002/10/10 17:08:58  zecke
00063  * The Cache is finally in place
00064  * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;)
00065  * 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....
00066  * I still have to fully implement read ahead
00067  * This change is bic but sc
00068  *
00069  * Revision 1.2  2002/10/08 09:27:36  eilers
00070  * Fixed libopie.pro to include the new pim-API.
00071  * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to
00072  * compile itself would need to install libsqlite, libopiesql...
00073  * Therefore, the backend currently uses XML only..
00074  *
00075  * Revision 1.1  2002/10/07 17:35:01  eilers
00076  * added OBackendFactory for advanced backend access
00077  *
00078  *
00079  * =====================================================================
00080  */
00081 #ifndef OPIE_BACKENDFACTORY_H_
00082 #define OPIE_BACKENDFACTORY_H_
00083 
00084 #include <qstring.h>
00085 #include <qasciidict.h>
00086 #include <qpe/config.h>
00087 
00088 #include "otodoaccessxml.h"
00089 #include "ocontactaccessbackend_xml.h"
00090 #include "odatebookaccessbackend_xml.h"
00091 
00092 #ifdef __USE_SQL
00093 #include "otodoaccesssql.h"
00094 #include "ocontactaccessbackend_sql.h"
00095 #include "odatebookaccessbackend_sql.h"
00096 #endif
00097 
00098 class OBackendPrivate;
00099 
00115 template<class T>
00116 class OBackendFactory
00117 {
00118  public:
00119     OBackendFactory() {};
00120 
00121     enum BACKENDS {
00122         TODO,
00123         CONTACT,
00124         DATE
00125     };
00126 
00132     static T* Default( const QString backendName, const QString& appName ){
00133 
00134         // __asm__("int3");
00135 
00136         Config config( "pimaccess" );
00137         config.setGroup ( backendName );
00138         QString backend = config.readEntry( "usebackend" );
00139 
00140         qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); 
00141 
00142         QAsciiDict<int> dict ( 3 );
00143         dict.setAutoDelete ( TRUE );
00144 
00145         dict.insert( "todo", new int (TODO) );
00146         dict.insert( "contact", new int (CONTACT) );
00147                 dict.insert( "datebook", new int(DATE) );
00148 
00149                 int *find = dict[ backendName ];
00150                 if (!find ) return 0;
00151 
00152         switch ( *find ){
00153         case TODO:
00154 #ifdef __USE_SQL
00155             if ( backend == "sql" )
00156                 return (T*) new OTodoAccessBackendSQL("");
00157 #else
00158             if ( backend == "sql" )
00159                 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!");
00160 #endif
00161 
00162             return (T*) new OTodoAccessXML( appName );
00163         case CONTACT:
00164 #ifdef __USE_SQL
00165             if ( backend == "sql" )
00166                 return (T*) new OContactAccessBackend_SQL("");
00167 #else
00168             if ( backend == "sql" )
00169                 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!");
00170 #endif
00171 
00172             return (T*) new OContactAccessBackend_XML( appName );
00173         case DATE:
00174 #ifdef __USE_SQL
00175             if ( backend == "sql" )
00176                 return (T*) new ODateBookAccessBackend_SQL("");
00177 #else
00178             if ( backend == "sql" )
00179                             qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!");
00180 #endif
00181 
00182             return (T*) new ODateBookAccessBackend_XML( appName );
00183         default:
00184             return NULL;
00185         }
00186 
00187 
00188     }
00189     private:
00190     OBackendPrivate* d;
00191 };
00192 
00193 
00194 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:19 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001