summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-13 19:05:24 (UTC)
committer zecke <zecke>2002-10-13 19:05:24 (UTC)
commit34c1199becdb2f9b0447553e66c85d8f6770558f (patch) (side-by-side diff)
tree36c3bf20b6f07e643f4caef793356261f9982bd6
parenta469689def798954c0f571a00cc52e87d6b008ce (diff)
downloadopie-34c1199becdb2f9b0447553e66c85d8f6770558f.zip
opie-34c1199becdb2f9b0447553e66c85d8f6770558f.tar.gz
opie-34c1199becdb2f9b0447553e66c85d8f6770558f.tar.bz2
Add a vCal Resource
Play a bit with cahce sizes The idea is to have the current page and the prior page cached... still looking how to do that
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/otodoaccesssql.cpp9
-rw-r--r--libopie/pim/otodoaccessvcal.cpp192
-rw-r--r--libopie/pim/otodoaccessvcal.h35
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp9
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp192
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h35
6 files changed, 464 insertions, 8 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index ea8b3c9..9ef6b7c 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -283,32 +283,33 @@ QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
}
OTodo OTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return todo( m_driver->query(&query) );
}
+#define CACHE 32
OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
uint cur, Frontend::CacheDirection dir ) const{
qWarning("searching for %d", uid );
- QArray<int> search( 8 );
+ QArray<int> search( CACHE );
uint size =0;
OTodo to;
- // we try to cache 8 items
+ // we try to cache CACHE items
switch( dir ) {
/* forward */
case 0:
- for (uint i = cur; i < ints.count() && size < 8; i++ ) {
+ for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
qWarning("size %d %d", size, ints[i] );
search[size] = ints[i];
size++;
}
break;
/* reverse */
case 1:
- for (uint i = cur; i != 0 && size < 8; i-- ) {
+ for (uint i = cur; i != 0 && size < CACHE; i-- ) {
search[size] = ints[i];
size++;
}
break;
}
search.resize( size );
diff --git a/libopie/pim/otodoaccessvcal.cpp b/libopie/pim/otodoaccessvcal.cpp
new file mode 100644
index 0000000..ac70ea0
--- a/dev/null
+++ b/libopie/pim/otodoaccessvcal.cpp
@@ -0,0 +1,192 @@
+#include <qfile.h>
+
+#include <qtopia/private/vobject_p.h>
+#include <qtopia/timeconversion.h>
+#include <qtopia/private/qfiledirect_p.h>
+
+#include "otodoaccessvcal.h"
+
+namespace {
+ static OTodo eventByVObj( VObject *obj ){
+ OTodo event;
+ VObject *ob;
+ QCString name;
+ // no uid, attendees, ... and no fun
+ // description
+ if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ event.setDescription( name );
+ }
+ // summary
+ if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
+ name = vObjectStringZValue( ob );
+ event.setSummary( name );
+ }
+ // completed
+ if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ if( name == "COMPLETED" ){
+ event.setCompleted( true );
+ }else{
+ event.setCompleted( false );
+ }
+ }else
+ event.setCompleted( false );
+ // priority
+ if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
+ name = vObjectStringZValue( ob );
+ bool ok;
+ event.setPriority(name.toInt(&ok) );
+ }
+ //due date
+ if((ob = isAPropertyOf(obj, VCDueProp)) ){
+ event.setHasDueDate( true );
+ name = vObjectStringZValue( ob );
+ event.setDueDate( TimeConversion::fromISO8601( name).date() );
+ }
+ // categories
+ if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ qWarning("Categories:%s", name.data() );
+ }
+
+ event.setUid( 1 );
+ return event;
+ };
+ static VObject *vobjByEvent( const OTodo &event ) {
+ VObject *task = newVObject( VCTodoProp );
+ if( task == 0 )
+ return 0l;
+
+ if( event.hasDueDate() )
+ addPropValue( task, VCDueProp,
+ TimeConversion::toISO8601( event.dueDate() ) );
+
+ if( event.isCompleted() )
+ addPropValue( task, VCStatusProp, "COMPLETED");
+
+ QString string = QString::number(event.priority() );
+ addPropValue( task, VCPriorityProp, string.local8Bit() );
+
+ addPropValue( task, VCCategoriesProp,
+ event.idsToString( event.categories() ).local8Bit() );
+
+ addPropValue( task, VCDescriptionProp,
+ event.description().local8Bit() );
+
+ addPropValue( task, VCSummaryProp,
+ event.summary().local8Bit() );
+ return task;
+};
+}
+
+OTodoAccessVCal::OTodoAccessVCal( const QString& path )
+ : m_dirty(false), m_file( path )
+{
+}
+OTodoAccessVCal::~OTodoAccessVCal() {
+}
+bool OTodoAccessVCal::load() {
+ m_map.clear();
+ m_dirty = false;
+
+ VObject* vcal = 0l;
+ vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
+ if (!vcal )
+ return false;
+
+ // Iterate over the list
+ VObjectIterator it;
+ VObject* vobj;
+
+ initPropIterator(&it, vcal);
+
+ while( moreIteration( &it ) ) {
+ vobj = ::nextVObject( &it );
+ QCString name = ::vObjectName( vobj );
+ if( name == VCTodoProp ){
+ OTodo to = eventByVObj( vobj );
+ m_map.insert( to.uid(), to );
+ }
+ }
+
+ // Should I do a delete vcal?
+
+ return true;
+}
+bool OTodoAccessVCal::reload() {
+ return load();
+}
+bool OTodoAccessVCal::save() {
+ if (!m_dirty )
+ return true;
+
+ QFileDirect file( m_file );
+ if (!file.open(IO_WriteOnly ) )
+ return false;
+
+ VObject *obj;
+ obj = newVObject( VCCalProp );
+ addPropValue( obj, VCVersionProp, "1.0" );
+ VObject *vo;
+ for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
+ vo = vobjByEvent( it.data() );
+ addVObjectProp(obj, vo );
+ }
+ writeVObject( file.directHandle(), obj );
+ cleanVObject( obj );
+ cleanStrTbl();
+
+ m_dirty = false;
+ return true;
+}
+void OTodoAccessVCal::clear() {
+ m_map.clear();
+ m_dirty = true;
+}
+bool OTodoAccessVCal::add( const OTodo& to ) {
+ m_map.insert( to.uid(), to );
+ m_dirty = true;
+ return true;
+}
+bool OTodoAccessVCal::remove( int uid ) {
+ m_map.remove( uid );
+ m_dirty = true;
+ return true;
+}
+bool OTodoAccessVCal::replace( const OTodo& to ) {
+ m_map.replace( to.uid(), to );
+ m_dirty = true;
+ return true;
+}
+OTodo OTodoAccessVCal::find(int uid )const {
+ return m_map[uid];
+}
+QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::allRecords()const {
+ QArray<int> ar( m_map.count() );
+ QMap<int, OTodo>::ConstIterator it;
+ int i = 0;
+ for ( it = m_map.begin(); it != m_map.end(); ++it ) {
+ ar[i] = it.key();
+ i++;
+ }
+ return ar;
+}
+QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& ,
+ const QDate& ,
+ bool ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::overDue() {
+ QArray<int> ar(0);
+ return ar;
+}
diff --git a/libopie/pim/otodoaccessvcal.h b/libopie/pim/otodoaccessvcal.h
new file mode 100644
index 0000000..4499a7e
--- a/dev/null
+++ b/libopie/pim/otodoaccessvcal.h
@@ -0,0 +1,35 @@
+#ifndef OPIE_OTODO_ACCESS_VCAL_H
+#define OPIE_OTODO_ACCESS_VCAL_H
+
+#include "otodoaccessbackend.h"
+
+class OTodoAccessVCal : public OTodoAccessBackend {
+public:
+ OTodoAccessVCal(const QString& );
+ ~OTodoAccessVCal();
+
+ bool load();
+ bool reload();
+ bool save();
+
+ QArray<int> allRecords()const;
+ QArray<int> queryByExample( const OTodo& t, int sort );
+ QArray<int> effectiveToDos( const QDate& start,
+ const QDate& end,
+ bool includeNoDates );
+ QArray<int> overDue();
+ QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
+ int cat );
+ OTodo find(int uid)const;
+ void clear();
+ bool add( const OTodo& );
+ bool remove( int uid );
+ bool replace( const OTodo& );
+
+private:
+ bool m_dirty : 1;
+ QString m_file;
+ QMap<int, OTodo> m_map;
+};
+
+#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index ea8b3c9..9ef6b7c 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -283,32 +283,33 @@ QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
}
OTodo OTodoAccessBackendSQL::find(int uid ) const{
FindQuery query( uid );
return todo( m_driver->query(&query) );
}
+#define CACHE 32
OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
uint cur, Frontend::CacheDirection dir ) const{
qWarning("searching for %d", uid );
- QArray<int> search( 8 );
+ QArray<int> search( CACHE );
uint size =0;
OTodo to;
- // we try to cache 8 items
+ // we try to cache CACHE items
switch( dir ) {
/* forward */
case 0:
- for (uint i = cur; i < ints.count() && size < 8; i++ ) {
+ for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
qWarning("size %d %d", size, ints[i] );
search[size] = ints[i];
size++;
}
break;
/* reverse */
case 1:
- for (uint i = cur; i != 0 && size < 8; i-- ) {
+ for (uint i = cur; i != 0 && size < CACHE; i-- ) {
search[size] = ints[i];
size++;
}
break;
}
search.resize( size );
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
new file mode 100644
index 0000000..ac70ea0
--- a/dev/null
+++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp
@@ -0,0 +1,192 @@
+#include <qfile.h>
+
+#include <qtopia/private/vobject_p.h>
+#include <qtopia/timeconversion.h>
+#include <qtopia/private/qfiledirect_p.h>
+
+#include "otodoaccessvcal.h"
+
+namespace {
+ static OTodo eventByVObj( VObject *obj ){
+ OTodo event;
+ VObject *ob;
+ QCString name;
+ // no uid, attendees, ... and no fun
+ // description
+ if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ event.setDescription( name );
+ }
+ // summary
+ if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
+ name = vObjectStringZValue( ob );
+ event.setSummary( name );
+ }
+ // completed
+ if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ if( name == "COMPLETED" ){
+ event.setCompleted( true );
+ }else{
+ event.setCompleted( false );
+ }
+ }else
+ event.setCompleted( false );
+ // priority
+ if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
+ name = vObjectStringZValue( ob );
+ bool ok;
+ event.setPriority(name.toInt(&ok) );
+ }
+ //due date
+ if((ob = isAPropertyOf(obj, VCDueProp)) ){
+ event.setHasDueDate( true );
+ name = vObjectStringZValue( ob );
+ event.setDueDate( TimeConversion::fromISO8601( name).date() );
+ }
+ // categories
+ if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
+ name = vObjectStringZValue( ob );
+ qWarning("Categories:%s", name.data() );
+ }
+
+ event.setUid( 1 );
+ return event;
+ };
+ static VObject *vobjByEvent( const OTodo &event ) {
+ VObject *task = newVObject( VCTodoProp );
+ if( task == 0 )
+ return 0l;
+
+ if( event.hasDueDate() )
+ addPropValue( task, VCDueProp,
+ TimeConversion::toISO8601( event.dueDate() ) );
+
+ if( event.isCompleted() )
+ addPropValue( task, VCStatusProp, "COMPLETED");
+
+ QString string = QString::number(event.priority() );
+ addPropValue( task, VCPriorityProp, string.local8Bit() );
+
+ addPropValue( task, VCCategoriesProp,
+ event.idsToString( event.categories() ).local8Bit() );
+
+ addPropValue( task, VCDescriptionProp,
+ event.description().local8Bit() );
+
+ addPropValue( task, VCSummaryProp,
+ event.summary().local8Bit() );
+ return task;
+};
+}
+
+OTodoAccessVCal::OTodoAccessVCal( const QString& path )
+ : m_dirty(false), m_file( path )
+{
+}
+OTodoAccessVCal::~OTodoAccessVCal() {
+}
+bool OTodoAccessVCal::load() {
+ m_map.clear();
+ m_dirty = false;
+
+ VObject* vcal = 0l;
+ vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
+ if (!vcal )
+ return false;
+
+ // Iterate over the list
+ VObjectIterator it;
+ VObject* vobj;
+
+ initPropIterator(&it, vcal);
+
+ while( moreIteration( &it ) ) {
+ vobj = ::nextVObject( &it );
+ QCString name = ::vObjectName( vobj );
+ if( name == VCTodoProp ){
+ OTodo to = eventByVObj( vobj );
+ m_map.insert( to.uid(), to );
+ }
+ }
+
+ // Should I do a delete vcal?
+
+ return true;
+}
+bool OTodoAccessVCal::reload() {
+ return load();
+}
+bool OTodoAccessVCal::save() {
+ if (!m_dirty )
+ return true;
+
+ QFileDirect file( m_file );
+ if (!file.open(IO_WriteOnly ) )
+ return false;
+
+ VObject *obj;
+ obj = newVObject( VCCalProp );
+ addPropValue( obj, VCVersionProp, "1.0" );
+ VObject *vo;
+ for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
+ vo = vobjByEvent( it.data() );
+ addVObjectProp(obj, vo );
+ }
+ writeVObject( file.directHandle(), obj );
+ cleanVObject( obj );
+ cleanStrTbl();
+
+ m_dirty = false;
+ return true;
+}
+void OTodoAccessVCal::clear() {
+ m_map.clear();
+ m_dirty = true;
+}
+bool OTodoAccessVCal::add( const OTodo& to ) {
+ m_map.insert( to.uid(), to );
+ m_dirty = true;
+ return true;
+}
+bool OTodoAccessVCal::remove( int uid ) {
+ m_map.remove( uid );
+ m_dirty = true;
+ return true;
+}
+bool OTodoAccessVCal::replace( const OTodo& to ) {
+ m_map.replace( to.uid(), to );
+ m_dirty = true;
+ return true;
+}
+OTodo OTodoAccessVCal::find(int uid )const {
+ return m_map[uid];
+}
+QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::allRecords()const {
+ QArray<int> ar( m_map.count() );
+ QMap<int, OTodo>::ConstIterator it;
+ int i = 0;
+ for ( it = m_map.begin(); it != m_map.end(); ++it ) {
+ ar[i] = it.key();
+ i++;
+ }
+ return ar;
+}
+QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& ,
+ const QDate& ,
+ bool ) {
+ QArray<int> ar(0);
+ return ar;
+}
+QArray<int> OTodoAccessVCal::overDue() {
+ QArray<int> ar(0);
+ return ar;
+}
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h
new file mode 100644
index 0000000..4499a7e
--- a/dev/null
+++ b/libopie2/opiepim/backend/otodoaccessvcal.h
@@ -0,0 +1,35 @@
+#ifndef OPIE_OTODO_ACCESS_VCAL_H
+#define OPIE_OTODO_ACCESS_VCAL_H
+
+#include "otodoaccessbackend.h"
+
+class OTodoAccessVCal : public OTodoAccessBackend {
+public:
+ OTodoAccessVCal(const QString& );
+ ~OTodoAccessVCal();
+
+ bool load();
+ bool reload();
+ bool save();
+
+ QArray<int> allRecords()const;
+ QArray<int> queryByExample( const OTodo& t, int sort );
+ QArray<int> effectiveToDos( const QDate& start,
+ const QDate& end,
+ bool includeNoDates );
+ QArray<int> overDue();
+ QArray<int> sorted( bool asc, int sortOrder, int sortFilter,
+ int cat );
+ OTodo find(int uid)const;
+ void clear();
+ bool add( const OTodo& );
+ bool remove( int uid );
+ bool replace( const OTodo& );
+
+private:
+ bool m_dirty : 1;
+ QString m_file;
+ QMap<int, OTodo> m_map;
+};
+
+#endif