summaryrefslogtreecommitdiff
authorzecke <zecke>2002-09-21 15:02:50 (UTC)
committer zecke <zecke>2002-09-21 15:02:50 (UTC)
commite6c53c4d7317e766235449535b22d0d2fe709214 (patch) (side-by-side diff)
treec210c639611acd5aa3c1863451fb4e31ac3af29a
parentfe0806def8ec79815832193fe402c75361108622 (diff)
downloadopie-e6c53c4d7317e766235449535b22d0d2fe709214.zip
opie-e6c53c4d7317e766235449535b22d0d2fe709214.tar.gz
opie-e6c53c4d7317e766235449535b22d0d2fe709214.tar.bz2
Some more implementation
in OPimRecord::setUid ORecordList implemented never compiled it though OTodo a new c'tor and some more changes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimrecord.cpp11
-rw-r--r--libopie/pim/opimrecord.h1
-rw-r--r--libopie/pim/orecordlist.h139
-rw-r--r--libopie/pim/otodo.cpp52
-rw-r--r--libopie/pim/otodo.h10
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp11
-rw-r--r--libopie2/opiepim/core/opimrecord.h1
-rw-r--r--libopie2/opiepim/orecordlist.h139
-rw-r--r--libopie2/opiepim/otodo.cpp52
-rw-r--r--libopie2/opiepim/otodo.h10
10 files changed, 366 insertions, 60 deletions
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index d8f73c7..e510f4e 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -1,57 +1,54 @@
#include "opimrecord.h"
OPimRecord::OPimRecord( int uid )
: Qtopia::Record() {
setUid( uid );
- /* assign a new UID */
- if ( uid == 1 )
- assignUid();
}
OPimRecord::~OPimRecord() {
}
OPimRecord::OPimRecord( const OPimRecord& rec )
: Qtopia::Record( rec )
{
(*this) = rec;
}
OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
Qtopia::Record::operator=( rec );
m_relations = rec.m_relations;
return *this;
}
QStringList OPimRecord::categoryNames()const {
QStringList list;
return list;
}
void OPimRecord::setCategoryNames( const QStringList& ) {
}
void OPimRecord::addCategoryName( const QString& ) {
}
bool OPimRecord::isEmpty()const {
return ( uid() == 0 );
}
QStringList OPimRecord::relatedApps()const{
QStringList list;
QMap<QString, QArray<int> >::ConstIterator it;
for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
list << it.key();
}
return list;
}
QArray<int> OPimRecord::relations(const QString& app )const {
QArray<int> tmp;
QMap<QString, QArray<int> >::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 );
}
@@ -59,48 +56,56 @@ void OPimRecord::addRelation( const QString& app, int id ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> 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<int> ids ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> 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 );
}
QString OPimRecord::crossToString()const {
QString str;
QMap<QString, QArray<int> >::ConstIterator it;
for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
QArray<int> id = it.data();
for ( uint i = 0; i < id.size(); ++i ) {
str += it.key() + "," + QString::number( i ) + ";";
}
}
str = str.remove( str.length()-1, 1); // strip the ;
//qWarning("IDS " + str );
return str;
}
+/* if uid = 1 assign a new one */
+void OPimRecord::setUid( int uid ) {
+
+ if ( uid == 1)
+ uid = uidGen().generate();
+
+ Qtopia::Record::setUid( uid );
+};
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index 18112d4..297ff12 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -56,62 +56,63 @@ public:
* 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<int, QString> toMap()const = 0;
/**
* key value representation of extra items
*/
virtual QMap<QString, QString> 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<int> relations( const QString& app )const;
/**
*
*/
void clearRelation( const QString& app );
/**
*
*/
void addRelation( const QString& app, int id );
/**
*
*/
void setRelations( const QString&, QArray<int> ids );
+ virtual void setUid( int uid );
protected:
QString crossToString()const;
private:
class OPimRecordPrivate;
OPimRecordPrivate *d;
QMap<QString, QArray<int> > m_relations;
};
#endif
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index c17186f..65c2169 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -1,44 +1,159 @@
#ifndef OPIE_RECORD_LIST_H
#define OPIE_RECORD_LIST_H
#include <opie/opimaccesstemplate.h>
#include <opie/opimrecord.h>
template <class T = OPimRecord >
class ORecordList {
public:
class Iterator {
friend class ORecordList;
public:
- Iterator() {}
- ~Iterator() {}
- Iterator(const Iterator& ) {}
+ Iterator();
+ ~Iterator();
+ Iterator(const Iterator& );
Iterator &operator=(const Iterator& );
- T &operator*() {}
+ T &operator*();
Iterator &operator++();
+ Iterator &operator--();
bool operator==( const Iterator& it );
bool operator!=( const Iterator& it );
- }
- ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc )
- : m_ids(ids ), m_acc( acc ) {
+ private:
+ Iterator( const QArray<int>,
+ OPimAccessTemplate<T>* );
- }
- ~ORecordList() {
+ QArray<int> m_uids;
+ int m_current;
+ OPimAccessTemplate* m_temp;
+ bool m_end : 1;
+ T m_record;
- }
+ /* d pointer for future versions */
+ class IteratorPrivate;
+ IteratorPrivate *d;
+ };
+ ORecordList( const QArray<int>& ids,
+ OPimAccessTemplate<T>* acc );
+ ~ORecordList();
Iterator begin();
Iterator end();
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
- QArray<int> ids;
+ QArray<int> m_ids;
OPimAccessTemplate<T>* m_acc;
};
+/* ok now implement it */
+template <class T= OPimRecord>
+ORecordList<T>::Iterator::Iterator() {
+ m_current = 0;
+ m_temp = 0l;
+ m_end = true;
+}
+template <class T= OPimRecord>
+ORecordList<T>::Iterator::~Iterator() {
+/* nothing to delete */
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
+ m_uids = it.m_uids;
+ m_current = it.m_current;
+ m_temp = it.m_temp;
+ m_end = it.m_end;
+ m_record = it.m_record;
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) {
+ m_uids = it.m_uids;
+ m_current = it.m_current;
+ m_temp = it.m_temp;
+ m_end = it.m_end;
+ m_record = it.m_record;
+
+ return *this;
+}
+
+template <class T = OPimRecord>
+T &ORecordList<T>::Iterator::operator*() {
+ if (!m_end )
+ m_record = m_temp->find( m_uids[m_current] );
+ else
+ m_record = T;
+
+ return m_record;
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
+ if (m_current < m_uids.count() ) {
+ m_end = false;
+ ++m_current;
+ }else
+ m_end = true;
+
+ return *this;
+}
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
+ if ( m_current > 0 ) {
+ --m_current;
+ m_end = false;
+ } else
+ m_end = true;
+
+ return *this;
+}
+
+template <class T = OPimRecord>
+bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) {
+
+ /* if both are at we're the same.... */
+ if ( m_end == it.m_end ) return true;
+
+ if ( m_uids != it.m_uids ) return false;
+ if ( m_current != it.m_current ) return false;
+ if ( m_temp != it.m_temp ) return false;
+
+ return true;
+}
+template <class T = ORecordList>
+bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) {
+ return !(*this == it );
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator::Iterator( const QArray<int> uids,
+ OPimAccessTemplate<T>* t )
+ : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
+{
+}
+template <class T = ORecordList>
+ORecordList<T>::ORecordList( const QArray<int>& ids,
+ OPimAccessTemplate<T>* acc )
+ : m_ids( ids ), m_acc( acc )
+{
+}
+template <class T = ORecordList>
+ORecordList<T>::~ORecordList() {
+/* nothing to do here */
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator ORecordList<T>::begin() {
+ Iterator it( m_ids, m_acc );
+ return it;
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator ORecordList<T>::end() {
+ Iterator it( m_ids, m_acc );
+ it.m_end = true;
+ it.m_current = m_ids.count();
+}
#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index 3c93838..8239ba6 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,97 +1,116 @@
#include <qobject.h>
#include <qshared.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/stringutil.h>
#include <qpe/palmtoprecord.h>
#include <qpe/stringutil.h>
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include "otodo.h"
struct OTodo::OTodoData : public QShared {
OTodoData() : QShared() {
};
QDate date;
bool isCompleted:1;
bool hasDate:1;
int priority;
- QStringList category;
QString desc;
QString sum;
QMap<QString, QString> extra;
ushort prog;
bool hasAlarmDateTime :1;
QDateTime alarmDateTime;
};
OTodo::OTodo(const OTodo &event )
: OPimRecord( event ), data( event.data )
{
data->ref();
//qWarning("ref up");
}
OTodo::~OTodo() {
if ( data->deref() ) {
//qWarning("OTodo::dereffing");
delete data;
data = 0l;
}
}
+OTodo::OTodo(bool completed, int priority,
+ const QArray<int> &category,
+ const QString& summary,
+ const QString &description,
+ ushort progress,
+ bool hasDate, QDate date, int uid )
+ : OPimRecord( uid )
+{
+ //qWarning("OTodoData");
+ setCategories( category );
+ data = new OTodoData;
+ data->date = date;
+ data->isCompleted = completed;
+ data->hasDate = hasDate;
+ data->priority = priority;
+ data->sum = summary;
+ data->prog = progress;
+ data->desc = Qtopia::simplifyMultiLineSpace(description );
+ data->hasAlarmDateTime = false;
+}
OTodo::OTodo(bool completed, int priority,
const QStringList &category,
const QString& summary,
const QString &description,
ushort progress,
bool hasDate, QDate date, int uid )
: OPimRecord( uid )
{
//qWarning("OTodoData");
setCategories( idsFromString( category.join(";") ) );
data = new OTodoData;
data->date = date;
data->isCompleted = completed;
data->hasDate = hasDate;
data->priority = priority;
data->sum = summary;
data->prog = progress;
data->desc = Qtopia::simplifyMultiLineSpace(description );
data->hasAlarmDateTime = false;
}
bool OTodo::match( const QRegExp &regExp )const
{
if( QString::number( data->priority ).find( regExp ) != -1 ){
return true;
}else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
return true;
}else if(data->desc.find( regExp ) != -1 ){
return true;
}else if(data->sum.find( regExp ) != -1 ) {
return true;
}
return false;
}
bool OTodo::isCompleted() const
{
return data->isCompleted;
}
bool OTodo::hasDueDate() const
{
return data->hasDate;
}
bool OTodo::hasAlarmDateTime() const
{
return data->hasAlarmDateTime;
}
int OTodo::priority()const
{
@@ -222,133 +241,138 @@ bool OTodo::operator<( const OTodo &toDoEvent )const{
return priority() < toDoEvent.priority();
}else{
return dueDate() < toDoEvent.dueDate();
}
}
return false;
}
bool OTodo::operator<=(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() <= toDoEvent.priority();
}else{
return dueDate() <= toDoEvent.dueDate();
}
}
return true;
}
bool OTodo::operator>(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return dueDate() > toDoEvent.dueDate();
}
}
return false;
}
bool OTodo::operator>=(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return dueDate() > toDoEvent.dueDate();
}
}
return true;
}
bool OTodo::operator==(const OTodo &toDoEvent )const
{
- if( data->priority == toDoEvent.data->priority &&
- data->priority == toDoEvent.data->prog &&
- data->isCompleted == toDoEvent.data->isCompleted &&
- data->hasDate == toDoEvent.data->hasDate &&
- data->date == toDoEvent.data->date &&
- data->category == toDoEvent.data->category &&
- data->sum == toDoEvent.data->sum &&
- data->desc == toDoEvent.data->desc &&
- data->hasAlarmDateTime == toDoEvent.data->hasAlarmDateTime &&
- data->alarmDateTime == toDoEvent.data->alarmDateTime )
- return true;
+ if ( data->priority != toDoEvent.data->priority ) return false;
+ if ( data->priority != toDoEvent.data->prog ) return false;
+ if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
+ if ( data->hasDate != toDoEvent.data->hasDate ) return false;
+ if ( data->date != toDoEvent.data->date ) return false;
+ if ( data->sum != toDoEvent.data->sum ) return false;
+ if ( data->desc != toDoEvent.data->desc ) return false;
+ if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
+ return false;
+ if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
+ return false;
- return false;
+ return OPimRecord::operator==( toDoEvent );
}
void OTodo::deref() {
//qWarning("deref in ToDoEvent");
if ( data->deref() ) {
//qWarning("deleting");
delete data;
d= 0;
}
}
OTodo &OTodo::operator=(const OTodo &item )
{
OPimRecord::operator=( item );
//qWarning("operator= ref ");
item.data->ref();
deref();
return *this;
}
QMap<int, QString> OTodo::toMap() const {
QMap<int, QString> map;
map.insert( Uid, QString::number( uid() ) );
map.insert( Category, idsToString( categories() ) );
map.insert( HasDate, QString::number( data->hasDate ) );
map.insert( Completed, QString::number( data->isCompleted ) );
map.insert( Description, data->desc );
map.insert( Summary, data->sum );
map.insert( Priority, QString::number( data->priority ) );
map.insert( DateDay, QString::number( data->date.day() ) );
map.insert( DateMonth, QString::number( data->date.month() ) );
map.insert( DateYear, QString::number( data->date.year() ) );
map.insert( Progress, QString::number( data->prog ) );
map.insert( CrossReference, crossToString() );
map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) );
map.insert( AlarmDateTime, data->alarmDateTime.toString() );
return map;
}
QMap<QString, QString> OTodo::toExtraMap()const {
return data->extra;
}
/**
* change or modify looks at the ref count and either
* creates a new QShared Object or it can modify it
* right in place
*/
void OTodo::changeOrModify() {
if ( data->count != 1 ) {
//qWarning("changeOrModify");
data->deref();
OTodoData* d2 = new OTodoData();
copy(data, d2 );
data = d2;
}
}
void OTodo::copy( OTodoData* src, OTodoData* dest ) {
dest->date = src->date;
dest->isCompleted = src->isCompleted;
dest->hasDate = src->hasDate;
dest->priority = src->priority;
dest->desc = src->desc;
dest->sum = src->sum;
dest->extra = src->extra;
dest->prog = src->prog;
dest->hasAlarmDateTime = src->hasAlarmDateTime;
dest->alarmDateTime = src->alarmDateTime;
}
-
+QString OTodo::type() const {
+ return QString::fromLatin1("OTodo");
+}
+QString OTodo::recordField(int id )const {
+ return QString::null;
+}
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h
index e1729db..75af44c 100644
--- a/libopie/pim/otodo.h
+++ b/libopie/pim/otodo.h
@@ -10,97 +10,105 @@
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include <opie/opimrecord.h>
class OTodo : public OPimRecord {
public:
typedef QValueList<OTodo> ValueList;
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
HasDate,
Completed,
Description,
Summary,
Priority,
DateDay,
DateMonth,
DateYear,
Progress,
CrossReference,
HasAlarmDateTime,
AlarmDateTime
};
public:
// priorities from Very low to very high
enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
/* Constructs a new ToDoEvent
@param completed Is the TodoEvent completed
@param priority What is the priority of this ToDoEvent
@param category Which category does it belong( uid )
@param summary A small summary of the todo
@param description What is this ToDoEvent about
@param hasDate Does this Event got a deadline
@param date what is the deadline?
@param uid what is the UUID of this Event
**/
OTodo( bool completed = false, int priority = Normal,
const QStringList &category = QStringList(),
const QString &summary = QString::null ,
const QString &description = QString::null,
ushort progress = 0,
bool hasDate = false, QDate date = QDate::currentDate(),
- int uid = -1 );
+ int uid = 0 /*empty*/ );
+
+ OTodo( bool completed, int priority,
+ const QArray<int>& category,
+ const QString& summary = QString::null,
+ const QString& description = QString::null,
+ ushort progress = 0,
+ bool hasDate = false, QDate date = QDate::currentDate(),
+ int uid = 0 /* empty */ );
/* Copy c'tor
**/
OTodo(const OTodo & );
/**
*destructor
*/
~OTodo();
/**
* Is this event completed?
*/
bool isCompleted() const;
/**
* Does this Event have a deadline
*/
bool hasDueDate() const;
/**
* Does this Event has an alarm time ?
*/
bool hasAlarmDateTime() const;
/**
* What is the priority?
*/
int priority()const ;
/**
* progress as ushort 0, 20, 40, 60, 80 or 100%
*/
ushort progress() const;
/**
* The due Date
*/
QDate dueDate()const;
/**
* Alarm Date and Time
*/
QDateTime alarmDateTime()const;
/**
* The description of the todo
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index d8f73c7..e510f4e 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,57 +1,54 @@
#include "opimrecord.h"
OPimRecord::OPimRecord( int uid )
: Qtopia::Record() {
setUid( uid );
- /* assign a new UID */
- if ( uid == 1 )
- assignUid();
}
OPimRecord::~OPimRecord() {
}
OPimRecord::OPimRecord( const OPimRecord& rec )
: Qtopia::Record( rec )
{
(*this) = rec;
}
OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
Qtopia::Record::operator=( rec );
m_relations = rec.m_relations;
return *this;
}
QStringList OPimRecord::categoryNames()const {
QStringList list;
return list;
}
void OPimRecord::setCategoryNames( const QStringList& ) {
}
void OPimRecord::addCategoryName( const QString& ) {
}
bool OPimRecord::isEmpty()const {
return ( uid() == 0 );
}
QStringList OPimRecord::relatedApps()const{
QStringList list;
QMap<QString, QArray<int> >::ConstIterator it;
for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
list << it.key();
}
return list;
}
QArray<int> OPimRecord::relations(const QString& app )const {
QArray<int> tmp;
QMap<QString, QArray<int> >::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 );
}
@@ -59,48 +56,56 @@ void OPimRecord::addRelation( const QString& app, int id ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> 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<int> ids ) {
QMap<QString, QArray<int> >::Iterator it;
QArray<int> 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 );
}
QString OPimRecord::crossToString()const {
QString str;
QMap<QString, QArray<int> >::ConstIterator it;
for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
QArray<int> id = it.data();
for ( uint i = 0; i < id.size(); ++i ) {
str += it.key() + "," + QString::number( i ) + ";";
}
}
str = str.remove( str.length()-1, 1); // strip the ;
//qWarning("IDS " + str );
return str;
}
+/* if uid = 1 assign a new one */
+void OPimRecord::setUid( int uid ) {
+
+ if ( uid == 1)
+ uid = uidGen().generate();
+
+ Qtopia::Record::setUid( uid );
+};
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 18112d4..297ff12 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -56,62 +56,63 @@ public:
* 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<int, QString> toMap()const = 0;
/**
* key value representation of extra items
*/
virtual QMap<QString, QString> 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<int> relations( const QString& app )const;
/**
*
*/
void clearRelation( const QString& app );
/**
*
*/
void addRelation( const QString& app, int id );
/**
*
*/
void setRelations( const QString&, QArray<int> ids );
+ virtual void setUid( int uid );
protected:
QString crossToString()const;
private:
class OPimRecordPrivate;
OPimRecordPrivate *d;
QMap<QString, QArray<int> > m_relations;
};
#endif
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index c17186f..65c2169 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -1,44 +1,159 @@
#ifndef OPIE_RECORD_LIST_H
#define OPIE_RECORD_LIST_H
#include <opie/opimaccesstemplate.h>
#include <opie/opimrecord.h>
template <class T = OPimRecord >
class ORecordList {
public:
class Iterator {
friend class ORecordList;
public:
- Iterator() {}
- ~Iterator() {}
- Iterator(const Iterator& ) {}
+ Iterator();
+ ~Iterator();
+ Iterator(const Iterator& );
Iterator &operator=(const Iterator& );
- T &operator*() {}
+ T &operator*();
Iterator &operator++();
+ Iterator &operator--();
bool operator==( const Iterator& it );
bool operator!=( const Iterator& it );
- }
- ORecordList( const QArray<int>& ids,
- OPimAccessTemplate<T>* acc )
- : m_ids(ids ), m_acc( acc ) {
+ private:
+ Iterator( const QArray<int>,
+ OPimAccessTemplate<T>* );
- }
- ~ORecordList() {
+ QArray<int> m_uids;
+ int m_current;
+ OPimAccessTemplate* m_temp;
+ bool m_end : 1;
+ T m_record;
- }
+ /* d pointer for future versions */
+ class IteratorPrivate;
+ IteratorPrivate *d;
+ };
+ ORecordList( const QArray<int>& ids,
+ OPimAccessTemplate<T>* acc );
+ ~ORecordList();
Iterator begin();
Iterator end();
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
- QArray<int> ids;
+ QArray<int> m_ids;
OPimAccessTemplate<T>* m_acc;
};
+/* ok now implement it */
+template <class T= OPimRecord>
+ORecordList<T>::Iterator::Iterator() {
+ m_current = 0;
+ m_temp = 0l;
+ m_end = true;
+}
+template <class T= OPimRecord>
+ORecordList<T>::Iterator::~Iterator() {
+/* nothing to delete */
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
+ m_uids = it.m_uids;
+ m_current = it.m_current;
+ m_temp = it.m_temp;
+ m_end = it.m_end;
+ m_record = it.m_record;
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) {
+ m_uids = it.m_uids;
+ m_current = it.m_current;
+ m_temp = it.m_temp;
+ m_end = it.m_end;
+ m_record = it.m_record;
+
+ return *this;
+}
+
+template <class T = OPimRecord>
+T &ORecordList<T>::Iterator::operator*() {
+ if (!m_end )
+ m_record = m_temp->find( m_uids[m_current] );
+ else
+ m_record = T;
+
+ return m_record;
+}
+
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
+ if (m_current < m_uids.count() ) {
+ m_end = false;
+ ++m_current;
+ }else
+ m_end = true;
+
+ return *this;
+}
+template <class T = OPimRecord>
+ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
+ if ( m_current > 0 ) {
+ --m_current;
+ m_end = false;
+ } else
+ m_end = true;
+
+ return *this;
+}
+
+template <class T = OPimRecord>
+bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) {
+
+ /* if both are at we're the same.... */
+ if ( m_end == it.m_end ) return true;
+
+ if ( m_uids != it.m_uids ) return false;
+ if ( m_current != it.m_current ) return false;
+ if ( m_temp != it.m_temp ) return false;
+
+ return true;
+}
+template <class T = ORecordList>
+bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) {
+ return !(*this == it );
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator::Iterator( const QArray<int> uids,
+ OPimAccessTemplate<T>* t )
+ : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
+{
+}
+template <class T = ORecordList>
+ORecordList<T>::ORecordList( const QArray<int>& ids,
+ OPimAccessTemplate<T>* acc )
+ : m_ids( ids ), m_acc( acc )
+{
+}
+template <class T = ORecordList>
+ORecordList<T>::~ORecordList() {
+/* nothing to do here */
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator ORecordList<T>::begin() {
+ Iterator it( m_ids, m_acc );
+ return it;
+}
+template <class T = ORecordList>
+ORecordList<T>::Iterator ORecordList<T>::end() {
+ Iterator it( m_ids, m_acc );
+ it.m_end = true;
+ it.m_current = m_ids.count();
+}
#endif
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index 3c93838..8239ba6 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,97 +1,116 @@
#include <qobject.h>
#include <qshared.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/stringutil.h>
#include <qpe/palmtoprecord.h>
#include <qpe/stringutil.h>
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include "otodo.h"
struct OTodo::OTodoData : public QShared {
OTodoData() : QShared() {
};
QDate date;
bool isCompleted:1;
bool hasDate:1;
int priority;
- QStringList category;
QString desc;
QString sum;
QMap<QString, QString> extra;
ushort prog;
bool hasAlarmDateTime :1;
QDateTime alarmDateTime;
};
OTodo::OTodo(const OTodo &event )
: OPimRecord( event ), data( event.data )
{
data->ref();
//qWarning("ref up");
}
OTodo::~OTodo() {
if ( data->deref() ) {
//qWarning("OTodo::dereffing");
delete data;
data = 0l;
}
}
+OTodo::OTodo(bool completed, int priority,
+ const QArray<int> &category,
+ const QString& summary,
+ const QString &description,
+ ushort progress,
+ bool hasDate, QDate date, int uid )
+ : OPimRecord( uid )
+{
+ //qWarning("OTodoData");
+ setCategories( category );
+ data = new OTodoData;
+ data->date = date;
+ data->isCompleted = completed;
+ data->hasDate = hasDate;
+ data->priority = priority;
+ data->sum = summary;
+ data->prog = progress;
+ data->desc = Qtopia::simplifyMultiLineSpace(description );
+ data->hasAlarmDateTime = false;
+}
OTodo::OTodo(bool completed, int priority,
const QStringList &category,
const QString& summary,
const QString &description,
ushort progress,
bool hasDate, QDate date, int uid )
: OPimRecord( uid )
{
//qWarning("OTodoData");
setCategories( idsFromString( category.join(";") ) );
data = new OTodoData;
data->date = date;
data->isCompleted = completed;
data->hasDate = hasDate;
data->priority = priority;
data->sum = summary;
data->prog = progress;
data->desc = Qtopia::simplifyMultiLineSpace(description );
data->hasAlarmDateTime = false;
}
bool OTodo::match( const QRegExp &regExp )const
{
if( QString::number( data->priority ).find( regExp ) != -1 ){
return true;
}else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
return true;
}else if(data->desc.find( regExp ) != -1 ){
return true;
}else if(data->sum.find( regExp ) != -1 ) {
return true;
}
return false;
}
bool OTodo::isCompleted() const
{
return data->isCompleted;
}
bool OTodo::hasDueDate() const
{
return data->hasDate;
}
bool OTodo::hasAlarmDateTime() const
{
return data->hasAlarmDateTime;
}
int OTodo::priority()const
{
@@ -222,133 +241,138 @@ bool OTodo::operator<( const OTodo &toDoEvent )const{
return priority() < toDoEvent.priority();
}else{
return dueDate() < toDoEvent.dueDate();
}
}
return false;
}
bool OTodo::operator<=(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() <= toDoEvent.priority();
}else{
return dueDate() <= toDoEvent.dueDate();
}
}
return true;
}
bool OTodo::operator>(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return dueDate() > toDoEvent.dueDate();
}
}
return false;
}
bool OTodo::operator>=(const OTodo &toDoEvent )const
{
if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if( hasDueDate() && toDoEvent.hasDueDate() ){
if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return dueDate() > toDoEvent.dueDate();
}
}
return true;
}
bool OTodo::operator==(const OTodo &toDoEvent )const
{
- if( data->priority == toDoEvent.data->priority &&
- data->priority == toDoEvent.data->prog &&
- data->isCompleted == toDoEvent.data->isCompleted &&
- data->hasDate == toDoEvent.data->hasDate &&
- data->date == toDoEvent.data->date &&
- data->category == toDoEvent.data->category &&
- data->sum == toDoEvent.data->sum &&
- data->desc == toDoEvent.data->desc &&
- data->hasAlarmDateTime == toDoEvent.data->hasAlarmDateTime &&
- data->alarmDateTime == toDoEvent.data->alarmDateTime )
- return true;
+ if ( data->priority != toDoEvent.data->priority ) return false;
+ if ( data->priority != toDoEvent.data->prog ) return false;
+ if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
+ if ( data->hasDate != toDoEvent.data->hasDate ) return false;
+ if ( data->date != toDoEvent.data->date ) return false;
+ if ( data->sum != toDoEvent.data->sum ) return false;
+ if ( data->desc != toDoEvent.data->desc ) return false;
+ if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
+ return false;
+ if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
+ return false;
- return false;
+ return OPimRecord::operator==( toDoEvent );
}
void OTodo::deref() {
//qWarning("deref in ToDoEvent");
if ( data->deref() ) {
//qWarning("deleting");
delete data;
d= 0;
}
}
OTodo &OTodo::operator=(const OTodo &item )
{
OPimRecord::operator=( item );
//qWarning("operator= ref ");
item.data->ref();
deref();
return *this;
}
QMap<int, QString> OTodo::toMap() const {
QMap<int, QString> map;
map.insert( Uid, QString::number( uid() ) );
map.insert( Category, idsToString( categories() ) );
map.insert( HasDate, QString::number( data->hasDate ) );
map.insert( Completed, QString::number( data->isCompleted ) );
map.insert( Description, data->desc );
map.insert( Summary, data->sum );
map.insert( Priority, QString::number( data->priority ) );
map.insert( DateDay, QString::number( data->date.day() ) );
map.insert( DateMonth, QString::number( data->date.month() ) );
map.insert( DateYear, QString::number( data->date.year() ) );
map.insert( Progress, QString::number( data->prog ) );
map.insert( CrossReference, crossToString() );
map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) );
map.insert( AlarmDateTime, data->alarmDateTime.toString() );
return map;
}
QMap<QString, QString> OTodo::toExtraMap()const {
return data->extra;
}
/**
* change or modify looks at the ref count and either
* creates a new QShared Object or it can modify it
* right in place
*/
void OTodo::changeOrModify() {
if ( data->count != 1 ) {
//qWarning("changeOrModify");
data->deref();
OTodoData* d2 = new OTodoData();
copy(data, d2 );
data = d2;
}
}
void OTodo::copy( OTodoData* src, OTodoData* dest ) {
dest->date = src->date;
dest->isCompleted = src->isCompleted;
dest->hasDate = src->hasDate;
dest->priority = src->priority;
dest->desc = src->desc;
dest->sum = src->sum;
dest->extra = src->extra;
dest->prog = src->prog;
dest->hasAlarmDateTime = src->hasAlarmDateTime;
dest->alarmDateTime = src->alarmDateTime;
}
-
+QString OTodo::type() const {
+ return QString::fromLatin1("OTodo");
+}
+QString OTodo::recordField(int id )const {
+ return QString::null;
+}
diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h
index e1729db..75af44c 100644
--- a/libopie2/opiepim/otodo.h
+++ b/libopie2/opiepim/otodo.h
@@ -10,97 +10,105 @@
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include <opie/opimrecord.h>
class OTodo : public OPimRecord {
public:
typedef QValueList<OTodo> ValueList;
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
HasDate,
Completed,
Description,
Summary,
Priority,
DateDay,
DateMonth,
DateYear,
Progress,
CrossReference,
HasAlarmDateTime,
AlarmDateTime
};
public:
// priorities from Very low to very high
enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
/* Constructs a new ToDoEvent
@param completed Is the TodoEvent completed
@param priority What is the priority of this ToDoEvent
@param category Which category does it belong( uid )
@param summary A small summary of the todo
@param description What is this ToDoEvent about
@param hasDate Does this Event got a deadline
@param date what is the deadline?
@param uid what is the UUID of this Event
**/
OTodo( bool completed = false, int priority = Normal,
const QStringList &category = QStringList(),
const QString &summary = QString::null ,
const QString &description = QString::null,
ushort progress = 0,
bool hasDate = false, QDate date = QDate::currentDate(),
- int uid = -1 );
+ int uid = 0 /*empty*/ );
+
+ OTodo( bool completed, int priority,
+ const QArray<int>& category,
+ const QString& summary = QString::null,
+ const QString& description = QString::null,
+ ushort progress = 0,
+ bool hasDate = false, QDate date = QDate::currentDate(),
+ int uid = 0 /* empty */ );
/* Copy c'tor
**/
OTodo(const OTodo & );
/**
*destructor
*/
~OTodo();
/**
* Is this event completed?
*/
bool isCompleted() const;
/**
* Does this Event have a deadline
*/
bool hasDueDate() const;
/**
* Does this Event has an alarm time ?
*/
bool hasAlarmDateTime() const;
/**
* What is the priority?
*/
int priority()const ;
/**
* progress as ushort 0, 20, 40, 60, 80 or 100%
*/
ushort progress() const;
/**
* The due Date
*/
QDate dueDate()const;
/**
* Alarm Date and Time
*/
QDateTime alarmDateTime()const;
/**
* The description of the todo