author | eilers <eilers> | 2004-05-23 17:11:01 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-05-23 17:11:01 (UTC) |
commit | 3025eab185d9e4237c37b4a193fbb20a4dbe504e (patch) (side-by-side diff) | |
tree | a6d4ee84122cdcd207d77c16b7449b432df6096a /libopie2/opiepim | |
parent | 29c68e4c0b10bf31cab3520737d042978d3eb4c0 (diff) | |
download | opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.zip opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.tar.gz opie-3025eab185d9e4237c37b4a193fbb20a4dbe504e.tar.bz2 |
Changes in Backendfactory: Now providing VCARD/VCAL backends if available
Changing API: Default now gets a OPimGlobal::PimType as first param instead of QString.
-rw-r--r-- | libopie2/opiepim/backend/obackendfactory.h | 98 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimglobal.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 3 |
5 files changed, 63 insertions, 46 deletions
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 @@ -29,27 +29,30 @@ /* * ===================================================================== * ToDo: Use plugins * ===================================================================== */ #ifndef OPIE_BACKENDFACTORY_H_ #define OPIE_BACKENDFACTORY_H_ #include <qstring.h> #include <qasciidict.h> #include <qpe/config.h> +#include <opie2/opimaccessbackend.h> #include <opie2/opimglobal.h> #include <opie2/otodoaccessxml.h> +#include <opie2/otodoaccessvcal.h> #include <opie2/ocontactaccessbackend_xml.h> +#include <opie2/ocontactaccessbackend_vcard.h> #include <opie2/odatebookaccessbackend_xml.h> #ifdef __USE_SQL #include <opie2/otodoaccesssql.h> #include <opie2/ocontactaccessbackend_sql.h> #include <opie2/odatebookaccessbackend_sql.h> #endif using namespace Opie; using namespace Opie::Pim; namespace Opie { @@ -73,71 +76,99 @@ class OBackendPrivate; */ template<class T> class OBackendFactory { public: OBackendFactory() {}; /** * Returns a selected backend implementation * @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; } - } /** * Returns the style of the default database which is used to contact PIM data. * @param type the type of the backend * @see OPimGlobal */ static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ QString group_name; switch ( type ){ case OPimGlobal::TODOLIST: group_name = "todo"; @@ -166,43 +197,26 @@ class OBackendFactory int* db_find = dictDbTypes[ db_String ]; if ( !db_find ) return OPimGlobal::UNKNOWN; return (OPimGlobal::DatabaseStyle) *db_find; } /** * 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<int> 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<OPimGlobal::PimType>( *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; }; } #endif 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 @@ -44,37 +44,38 @@ #include <qcopchannel_qws.h> //#include <qpe/qcopenvelope_qws.h> #include <qpe/global.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <opie2/ocontactaccessbackend_xml.h> #include <opie2/opimresolver.h> +#include <opie2/opimglobal.h> namespace Opie { OPimContactAccess::OPimContactAccess ( const QString appname, const QString , OPimContactAccessBackend* end, bool autosync ): OPimAccessTemplate<OPimContact>( end ) { /* take care of the backend. If there is no one defined, we * will use the XML-Backend as default (until we have a cute SQL-Backend..). */ if( end == 0 ) { qWarning ("Using BackendFactory !"); - end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( "contact", appname ); + end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); } // Set backend locally and in template m_backEnd = end; OPimAccessTemplate<OPimContact>::setBackEnd (end); /* Connect signal of external db change to function */ QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(copMessage(const QCString&,const QByteArray&)) ); if ( autosync ){ QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 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 @@ -20,38 +20,39 @@ ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <opie2/obackendfactory.h> #include <opie2/odatebookaccess.h> #include <opie2/opimresolver.h> +#include <opie2/opimglobal.h> namespace Opie { /** * Simple constructor * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation * will be used! * @param back The backend to be used or 0 for the default backend * @param ac What kind of access is intended */ ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) : OPimAccessTemplate<OPimEvent>( back ) { if (!back ) - back = OBackendFactory<ODateBookAccessBackend>::defaultBackend("datebook", QString::null ); + back = OBackendFactory<ODateBookAccessBackend>::defaultBackend( OPimGlobal::DATEBOOK, QString::null ); m_backEnd = back; setBackEnd( m_backEnd ); } ODateBookAccess::~ODateBookAccess() { } /** * @return all events available */ ODateBookAccess::List ODateBookAccess::rawEvents()const { QArray<int> ints = m_backEnd->rawEvents(); 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 @@ -41,24 +41,24 @@ class OPimGlobal{ enum PimType { TODOLIST, CONTACTLIST, DATEBOOK, _END_PimType }; enum DatabaseStyle { DEFAULT, // Use default Database UNKNOWN, // Unknown database style XML, SQL, - VCARD, + VCARD, // Also used for VCARD ! _END_DatabaseStyle }; }; } } #endif 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 @@ -25,35 +25,36 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qdatetime.h> #include <qpe/alarmserver.h> // #include "otodoaccesssql.h" #include <opie2/otodoaccess.h> #include <opie2/obackendfactory.h> #include <opie2/opimresolver.h> +#include <opie2/opimglobal.h> namespace Opie { OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) { // if (end == 0l ) // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! if (end == 0l ) - m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend ("todo", QString::null); + m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null); setBackEnd( m_todoBackEnd ); } OPimTodoAccess::~OPimTodoAccess() { // qWarning("~OPimTodoAccess"); } void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { QValueList<OPimTodo>::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { replace( (*it) ); } } |