From a05c10c9744020be31c3038b2de3401b5cc673fb Mon Sep 17 00:00:00 2001 From: zecke Date: Fri, 20 Sep 2002 12:59:29 +0000 Subject: Our new common template based start for Accessing and Manipulating the Records The CROSS_REFERENCE branch will get ported to it. We use templates for several reasons They allow us to share code and to be easily extended I've to make them not inline to save memory... I've to port all DBs and Record related classes --- (limited to 'libopie2/opiepim/core') diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h new file mode 100644 index 0000000..f2a241d --- a/dev/null +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -0,0 +1,82 @@ +#ifndef OPIE_PIM_ACCESS_TEMPLATE_H +#define OPIE_PIM_ACCESS_TEMPLATE_H + +#include + +#include +#include +#include + +template +class OPimAccessTemplate { +public: + typedef ORecordList List; + typedef OPimAccessBackend BackEnd; + OPimAccessTemplate( BackEnd* end) + : m_backEnd( end ) { + } + ~OPimAccessTemplate() { + delete m_backEnd; + } + virtual void load() { + m_backEnd->load(); + } + virtual void reload() { + m_backEnd->reload(); + } + virtual void save() { + m_backEnd->save(); + } + + /* + *do array to Records conversion + * QArray ids + */ + virtual List allRecords()const { + QArray ints = m_backEnd->allRecords(); + + List lis( ints, this ); + return lis; + } + virtual List queryByExample( const T& t, int sortOrder ) { + QArray ints = m_backEnd->query( t, sortOrder ); + List lis( ints, this ); + + return lis; + } + /* implement QCache here */ + virtual T find( int uid ) { + T t = m_backEnd->find( uid ); + return t; + } + + /* invalidate cache here */ + virtual void clear() { + invalidateCache(); + m_backEnd->clear(); + } + virtual bool add( const T& t ) { + return m_backEnd->add( t ); + } + + /* only the uid matters */ + virtual bool remove( const T& t ) { + /* remove from cache */ + return m_backEnd->remove( t.uid() ); + } + virtual bool remove( int uid ) { + /* remove from cache */ + return m_backEnd->remove(uid); + } + virtual bool replace( const T& t) { + return m_backEnd->replace( t ); + } +protected: + void invalidateCache() { + + } + BackEnd* m_backEnd; + +}; + +#endif diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp new file mode 100644 index 0000000..95de1df --- a/dev/null +++ b/libopie2/opiepim/core/opimrecord.cpp @@ -0,0 +1,90 @@ +#include "opimrecord.h" + +OPimRecord::OPimRecord( int uid ) + : Qtopia::Record() { + setUid( uid ); + if ( uid == 1 ) + assignUid(); +} +OPimRecord::~OPimRecord() { +} +OPimRecord::OPimRecord( OPimRecord& rec ) + : Qtopia::Record( rec ) +{ + (*this) = rec; +} + +OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { + /* how do I call the parent copy operator ? */ + setUid( rec.uid() ); + setCategories( rec.categories() ); + return *this; +} +QStringList OPimRecord::categoryNames()const { + QStringList list; + + return list; +} +void OPimRecord::setCategoryName( const QStringList& ) { + +} +void OPimRecord::addCategoryName( const QString& ) { + +} +bool OPimRecord::isEmpty()const { + return ( uid() == 0 ); +} +QStringList OPimRecord::relatedApps()const{ + QStringList list; + QMap >::ConstIterator it; + for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { + list << it.key(); + } + return list; +} +QArray OPimRecord::relations(const QString& app )const { + QArray tmp; + QMap >::ConstIterator it; + it = m_relations.find( app); + if ( it != m_relations.end() ) + tmp = it.data(); + return tmp; +} +void OPimRecord::clearRelation( const QString& app ) { + m_relations.remove( app ); +} +void OPimRecord::addRelation( const QString& app, int id ) { + + QMap >::Iterator it; + QArray tmp; + + it = m_relations.find( app ); + if ( it == m_relations.end() ) { + tmp.resize(1 ); + tmp[0] = id; + }else{ + tmp = it.data(); + tmp.resize( tmp.size() + 1 ); + tmp[tmp.size() - 1] = id; + } + m_relations.replace( app, tmp ); +} +void OPimRecord::setRelations( const QString& app, QArray ids ) { + + QMap >::Iterator it; + QArray tmp; + + it = m_relations.find( app); + if ( it == m_relations.end() ) { + tmp = ids; + }else{ + tmp = it.data(); + int offset = tmp.size()-1; + tmp.resize( tmp.size() + ids.size() ); + for (uint i = 0; i < ids.size(); i++ ) { + tmp[offset+i] = ids[i]; + } + + } + m_relations.replace( app, tmp ); +} diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h new file mode 100644 index 0000000..a0e0413 --- a/dev/null +++ b/libopie2/opiepim/core/opimrecord.h @@ -0,0 +1,117 @@ +#ifndef OPIE_PIM_RECORD_H +#define OPIE_PIM_RECORD_H + +#include +#include +#include + +#include + +class OPimRecord : public Qtopia::Record { +public: + /** + * uid of 0 isEmpty + * uid of 1 will be assigned a new one + */ + OPimRecord(int uid = 0); + ~OPimRecord(); + + /** + * copy c'tor + */ + OPimRecord( OPimRecord& rec ); + + /** + * copy operator + */ + OPimRecord &operator=( const OPimRecord& ); + + /** + * category names resolved + */ + QStringList categoryNames()const; + + /** + * set category names they will be resolved + */ + void setCategoryName( const QStringList& ); + + /** + * addCategoryName adds a name + * to the internal category list + */ + void addCategoryName( const QString& ); + + /** + * if a Record isEmpty + */ + virtual bool isEmpty()const; + + /** + * toRichText summary + */ + virtual QString toRichText()const = 0; + + /** + * a small one line summary + */ + virtual QString toShortText()const = 0; + + /** + * the name of the Record + */ + virtual QString type()const = 0; + + /** + * converts the internal structure to a map + */ + virtual QMap toMap()const = 0; + + /** + * key value representation of extra items + */ + virtual QMap toExtraMap()const = 0; + + /** + * the name for a recordField + */ + virtual QString recordField(int)const = 0; + + /** + * the related apps names + */ + QStringList relatedApps()const; + + /** + * the realtions between an app + */ + QArray relations( const QString& app )const; + + /** + * + */ + void clearRelation( const QString& app ); + + /** + * + */ + void addRelation( const QString& app, int id ); + + /** + * + */ + void setRelations( const QString&, QArray ids ); + +protected: + QString crossToString()const; + +private: + class OPimRecordPrivate; + OPimRecordPrivate *d; + QMap > m_relations; + +}; + + + +#endif -- cgit v0.9.0.2