Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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

Generated on Sat Nov 5 16:16:13 2005 for OPIE by  doxygen 1.4.2