From 3025eab185d9e4237c37b4a193fbb20a4dbe504e Mon Sep 17 00:00:00 2001 From: eilers Date: Sun, 23 May 2004 17:11:01 +0000 Subject: Changes in Backendfactory: Now providing VCARD/VCAL backends if available Changing API: Default now gets a OPimGlobal::PimType as first param instead of QString. --- (limited to 'libopie2/opiepim') diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 4bedbef..c8a4627 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h @@ -38,9 +38,12 @@ #include #include +#include #include #include +#include #include +#include #include #ifdef __USE_SQL @@ -82,53 +85,81 @@ class OBackendFactory * @param type the type of the backend * @param database the type of the used database * @param appName The name of your application. It will be passed on to the backend. + * @param filename Filename of the database file if you don't want to access the default */ static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, - const QString& appName ){ + const QString& appName, const QString& filename = QString::null ){ qWarning("Selected backend for %d is: %d", type, database ); // If we should use the dafult database style, we have to request it - OPimGlobal::DatabaseStyle used_database = database; - if ( database == OPimGlobal::DEFAULT ){ - used_database = defaultDB( type ); + OPimGlobal::DatabaseStyle use_database = database; + if ( use_database == OPimGlobal::DEFAULT ){ + use_database = defaultDB( type ); } - switch ( type ){ case OPimGlobal::TODOLIST: + + switch ( use_database ){ + default: // Use SQL if something weird is given. + // Fall through !! + case OPimGlobal::SQL: #ifdef __USE_SQL - if ( used_database == OPimGlobal::SQL ) - return (T*) new OPimTodoAccessBackendSQL(""); + return (T*) new OPimTodoAccessBackendSQL( filename ); + break; #else - if ( used_database == OPimGlobal::SQL ) qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); + // Fall through !! #endif - - return (T*) new OPimTodoAccessXML( appName ); + case OPimGlobal::XML: + return (T*) new OPimTodoAccessXML( appName, filename ); + break; + case OPimGlobal::VCARD: + return (T*) new OPimTodoAccessVCal( filename ); + break; + } case OPimGlobal::CONTACTLIST: + switch ( use_database ){ + default: // Use SQL if something weird is given. + // Fall through !! + case OPimGlobal::SQL: #ifdef __USE_SQL - if ( used_database == OPimGlobal::SQL ) - return (T*) new OPimContactAccessBackend_SQL(""); + return (T*) new OPimContactAccessBackend_SQL( appName, filename ); + break; #else - if ( used_database == OPimGlobal::SQL ) qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); + // Fall through !! #endif - - return (T*) new OPimContactAccessBackend_XML( appName ); + case OPimGlobal::XML: + return (T*) new OPimContactAccessBackend_XML( appName, filename ); + break; + case OPimGlobal::VCARD: + return (T*) new OPimContactAccessBackend_VCard( appName, filename ); + break; + } case OPimGlobal::DATEBOOK: + switch ( use_database ){ + default: // Use SQL if something weird is given. + // Fall through !! + case OPimGlobal::SQL: #ifdef __USE_SQL - if ( used_database == OPimGlobal::SQL ) - return (T*) new ODateBookAccessBackend_SQL(""); + return (T*) new ODateBookAccessBackend_SQL( appName, filename ); + break; #else - if ( used_database == OPimGlobal::SQL ) - qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); + qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); + // Fall through !! #endif - - return (T*) new ODateBookAccessBackend_XML( appName ); + case OPimGlobal::XML: + return (T*) new ODateBookAccessBackend_XML( appName, filename ); + break; + case OPimGlobal::VCARD: + qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); + return (T*) NULL; + break; + } default: return (T*) NULL; } - } /** @@ -175,28 +206,11 @@ class OBackendFactory /** * Returns the default backend implementation for backendName. Which one is used, is defined * by the configfile "pimaccess.conf". - * @param backendName the type of the backend (use "todo", "contact" or "datebook" ) + * @param type The type of the backend (@see OPimGlobal()) * @param appName The name of your application. It will be passed on to the backend */ - static T* defaultBackend( const QString backendName, const QString& appName ){ - - QAsciiDict dictBackends( OPimGlobal::_END_PimType ); - dictBackends.setAutoDelete ( TRUE ); - - dictBackends.insert( "todo", new int (OPimGlobal::TODOLIST) ); - dictBackends.insert( "contact", new int (OPimGlobal::CONTACTLIST) ); - dictBackends.insert( "datebook", new int(OPimGlobal::DATEBOOK) ); - - int* backend_find = dictBackends[ backendName ]; - if ( !backend_find ) return NULL; - - OPimGlobal::DatabaseStyle style = defaultDB( static_cast( *backend_find ) ); - - qDebug( "OBackendFactory::Default -> Backend is %s, Database is %d", backendName.latin1(), - style ); - - return create( (OPimGlobal::PimType) *backend_find, style, appName ); - + static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ + return create( type, OPimGlobal::DEFAULT, appName ); } private: OBackendPrivate* d; diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 417a954..a372267 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -53,6 +53,7 @@ #include #include +#include namespace Opie { @@ -65,7 +66,7 @@ OPimContactAccess::OPimContactAccess ( const QString appname, const QString , */ if( end == 0 ) { qWarning ("Using BackendFactory !"); - end = OBackendFactory::defaultBackend( "contact", appname ); + end = OBackendFactory::defaultBackend( OPimGlobal::CONTACTLIST, appname ); } // Set backend locally and in template m_backEnd = end; diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index 5f471cf..440ee0a 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace Opie { /** @@ -42,7 +43,7 @@ ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) : OPimAccessTemplate( back ) { if (!back ) - back = OBackendFactory::defaultBackend("datebook", QString::null ); + back = OBackendFactory::defaultBackend( OPimGlobal::DATEBOOK, QString::null ); m_backEnd = back; setBackEnd( m_backEnd ); diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h index d56c9be..efd455c 100644 --- a/libopie2/opiepim/core/opimglobal.h +++ b/libopie2/opiepim/core/opimglobal.h @@ -50,7 +50,7 @@ class OPimGlobal{ UNKNOWN, // Unknown database style XML, SQL, - VCARD, + VCARD, // Also used for VCARD ! _END_DatabaseStyle }; diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 87a211f..c4adbbd 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace Opie { OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) @@ -44,7 +45,7 @@ OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! if (end == 0l ) - m_todoBackEnd = OBackendFactory::defaultBackend ("todo", QString::null); + m_todoBackEnd = OBackendFactory::defaultBackend (OPimGlobal::TODOLIST, QString::null); setBackEnd( m_todoBackEnd ); } -- cgit v0.9.0.2