summaryrefslogtreecommitdiff
path: root/libopie/pim
Side-by-side diff
Diffstat (limited to 'libopie/pim') (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/opimrecord.cpp3
-rw-r--r--libopie/pim/orecordlist.h2
-rw-r--r--libopie/pim/otodo.cpp4
-rw-r--r--libopie/pim/otodoaccess.cpp4
-rw-r--r--libopie/pim/otodoaccessxml.cpp20
5 files changed, 20 insertions, 13 deletions
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index 60cdbf3..62dc353 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -77,57 +77,58 @@ void OPimRecord::addRelation( const QString& app, int id ) {
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 ) {
-
+// qWarning("setting uid" );
if ( uid == 1)
uid = uidGen().generate();
+// qWarning(" uid %d", uid);
Qtopia::Record::setUid( uid );
};
Qtopia::UidGen &OPimRecord::uidGen() {
return m_uidGen;
}
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index 36728b8..1795938 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -26,96 +26,98 @@ public:
* ORecordList
*/
ORecordListIterator( const QArray<int>, const Base* );
/**
* The standard c'tor
*/
ORecordListIterator();
~ORecordListIterator();
ORecordListIterator( const ORecordListIterator& );
ORecordListIterator &operator=(const ORecordListIterator& );
/**
* a * operator ;)
* use it like this T = (*it);
*/
T operator*();
ORecordListIterator &operator++();
ORecordListIterator &operator--();
bool operator==( const ORecordListIterator& it );
bool operator!=( const ORecordListIterator& it );
private:
QArray<int> m_uids;
int m_current;
const Base* m_temp;
bool m_end : 1;
T m_record;
/* d pointer for future versions */
class IteratorPrivate;
IteratorPrivate *d;
};
/**
* The recordlist used as a return type
* from OPimAccessTemplate
*/
template <class T = OPimRecord >
class ORecordList {
public:
typedef OTemplateBase<T> Base;
typedef ORecordListIterator<T> Iterator;
/**
* c'tor
*/
+ ORecordList () {
+ }
ORecordList( const QArray<int>& ids,
const Base* );
~ORecordList();
/**
* the first iterator
*/
Iterator begin();
/**
* the end
*/
Iterator end();
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
private:
QArray<int> m_ids;
const Base* m_acc;
};
/* ok now implement it */
template <class T>
ORecordListIterator<T>::ORecordListIterator() {
m_current = 0;
m_temp = 0l;
m_end = true;
m_record = T();
}
template <class T>
ORecordListIterator<T>::~ORecordListIterator() {
/* nothing to delete */
}
template <class T>
ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
// qWarning("ORecordListIterator copy c'tor");
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>
ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
m_uids = it.m_uids;
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index cc46b21..6dd4c0e 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -116,97 +116,97 @@ bool OTodo::hasDueDate() const
}
bool OTodo::hasAlarmDateTime() const
{
return data->hasAlarmDateTime;
}
int OTodo::priority()const
{
return data->priority;
}
QString OTodo::summary() const
{
return data->sum;
}
ushort OTodo::progress() const
{
return data->prog;
}
QDate OTodo::dueDate()const
{
return data->date;
}
QDateTime OTodo::alarmDateTime() const
{
return data->alarmDateTime;
}
QString OTodo::description()const
{
return data->desc;
}
void OTodo::setCompleted( bool completed )
{
changeOrModify();
data->isCompleted = completed;
}
void OTodo::setHasDueDate( bool hasDate )
{
changeOrModify();
data->hasDate = hasDate;
}
void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime )
{
changeOrModify();
data->hasAlarmDateTime = hasAlarmDateTime;
}
void OTodo::setDescription(const QString &desc )
{
- qWarning( "desc " + desc );
+// qWarning( "desc " + desc );
changeOrModify();
data->desc = Qtopia::simplifyMultiLineSpace(desc );
}
void OTodo::setSummary( const QString& sum )
{
changeOrModify();
data->sum = sum;
}
void OTodo::setPriority(int prio )
{
changeOrModify();
data->priority = prio;
}
void OTodo::setDueDate( QDate date )
{
changeOrModify();
data->date = date;
}
void OTodo::setAlarmDateTime( const QDateTime& alarm )
{
changeOrModify();
data->alarmDateTime = alarm;
}
bool OTodo::isOverdue( )
{
if( data->hasDate )
return QDate::currentDate() > data->date;
return false;
}
void OTodo::setProgress(ushort progress )
{
changeOrModify();
data->prog = progress;
}
QString OTodo::toShortText() const {
return summary();
}
/*!
Returns a richt text string
*/
QString OTodo::toRichText() const
{
QString text;
QStringList catlist;
// Description of the todo
if ( !summary().isEmpty() ) {
text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
@@ -273,97 +273,97 @@ bool OTodo::operator>(const OTodo &toDoEvent )const
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 ) 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 OPimRecord::operator==( toDoEvent );
}
void OTodo::deref() {
// qWarning("deref in ToDoEvent");
if ( data->deref() ) {
// qWarning("deleting");
delete data;
data= 0;
}
}
OTodo &OTodo::operator=(const OTodo &item )
{
-// OPimRecord::operator=( item );
+ OPimRecord::operator=( item );
//qWarning("operator= ref ");
item.data->ref();
deref();
data = item.data;
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;
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp
index a65cf5c..8ec09bc 100644
--- a/libopie/pim/otodoaccess.cpp
+++ b/libopie/pim/otodoaccess.cpp
@@ -1,71 +1,71 @@
#include <qdatetime.h>
#include <qpe/alarmserver.h>
#include "otodoaccessxml.h"
#include "otodoaccess.h"
OTodoAccess::OTodoAccess( OTodoAccessBackend* end )
: QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
{
if (end == 0l )
m_todoBackEnd = new OTodoAccessXML( "Todolist" );
setBackEnd( m_todoBackEnd );
}
OTodoAccess::~OTodoAccess() {
- qWarning("~OTodoAccess");
+// qWarning("~OTodoAccess");
}
void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
QValueList<OTodo>::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
replace( (*it) );
}
}
OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates ) {
QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
List lis( ints, this );
return lis;
}
OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
bool includeNoDates ) {
return effectiveToDos( start, QDate::currentDate(),
includeNoDates );
}
OTodoAccess::List OTodoAccess::overDue() {
List lis( m_todoBackEnd->overDue(), this );
return lis;
}
void OTodoAccess::addAlarm( const OTodo& event) {
if (!event.hasAlarmDateTime() )
return;
QDateTime now = QDateTime::currentDateTime();
QDateTime schedule = event.alarmDateTime();
if ( schedule > now ){
AlarmServer::addAlarm( schedule,
"QPE/Application/todolist",
"alarm(QDateTime,int)", event.uid() );
}
}
void OTodoAccess::delAlarm( int uid) {
QDateTime schedule; // Create null DateTime
// I hope this will remove all scheduled alarms
// with the given uid !?
// If not: I have to rethink how to remove already
// scheduled events... (se)
// it should be fine -zecke
- qWarning("Removing alarm for event with uid %d", uid );
+// qWarning("Removing alarm for event with uid %d", uid );
AlarmServer::deleteAlarm( schedule ,
"QPE/Application/todolist",
"alarm(QDateTime,int)", uid );
}
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index 3a72881..5fe733c 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,362 +1,366 @@
#include <qfile.h>
#include <qpe/global.h>
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
#include <opie/xmltree.h>
#include "otodoaccessxml.h"
OTodoAccessXML::OTodoAccessXML( const QString& appName,
const QString& fileName )
: OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
{
if (!fileName.isEmpty() )
m_file = fileName;
else
m_file = Global::applicationFileName( "todolist", "todolist.xml" );
}
OTodoAccessXML::~OTodoAccessXML() {
}
bool OTodoAccessXML::load() {
- m_opened = false;
+ m_opened = true;
m_changed = false;
/* initialize dict */
/*
* UPDATE dict if you change anything!!!
*/
QAsciiDict<int> dict(15);
dict.setAutoDelete( TRUE );
dict.insert("Categories" , new int(OTodo::Category) );
dict.insert("Uid" , new int(OTodo::Uid) );
dict.insert("HasDate" , new int(OTodo::HasDate) );
dict.insert("Completed" , new int(OTodo::Completed) );
dict.insert("Description" , new int(OTodo::Description) );
dict.insert("Summary" , new int(OTodo::Summary) );
dict.insert("Priority" , new int(OTodo::Priority) );
dict.insert("DateDay" , new int(OTodo::DateDay) );
dict.insert("DateMonth" , new int(OTodo::DateMonth) );
dict.insert("DateYear" , new int(OTodo::DateYear) );
dict.insert("Progress" , new int(OTodo::Progress) );
dict.insert("Completed", new int(OTodo::Completed) );
dict.insert("CrossReference", new int(OTodo::CrossReference) );
dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
Opie::XMLElement *root = Opie::XMLElement::load( m_file );
int day, year, month;
day = year = month = -1;
/* if opened */
if ( root != 0l ) {
Opie::XMLElement *element = root->firstChild();
if ( element == 0l )
return false;
element = element->firstChild();
while ( element ) {
if ( element->tagName() != QString::fromLatin1("Task") ) {
element = element->nextChild();
continue;
}
/* here is the right element for a task */
OTodo ev = todo( &dict, element );
m_events.insert( ev.uid(), ev );
element = element->nextChild();
}
}else {
- qWarning("could not parse");
+// qWarning("could not parse");
return false;;
}
delete root;
- m_opened = true;
- qWarning("Access %d" + m_events.count() );
+// qWarning("Access %d" + m_events.count() );
return true;
}
bool OTodoAccessXML::reload() {
return load();
}
bool OTodoAccessXML::save() {
- if (!m_opened || !m_changed )
+// qWarning("saving");
+ if (!m_opened || !m_changed ) {
+// qWarning("not saving");
return true;
+ }
QString strNewFile = m_file + ".new";
QFile f( strNewFile );
if (!f.open( IO_WriteOnly|IO_Raw ) )
return false;
int written;
QString out;
out = "<!DOCTYPE Tasks>\n<Tasks>\n";
// for all todos
QMap<int, OTodo>::Iterator it;
for (it = m_events.begin(); it != m_events.end(); ++it ) {
out+= "<Task " + toString( (*it) ) + " />\n";
QCString cstr = out.utf8();
written = f.writeBlock( cstr.data(), cstr.length() );
/* less written then we wanted */
if ( written != (int)cstr.length() ) {
f.close();
QFile::remove( strNewFile );
return false;
}
out = QString::null;
}
out += "</Tasks>";
QCString cstr = out.utf8();
written = f.writeBlock( cstr.data(), cstr.length() );
if ( written != (int)cstr.length() ) {
f.close();
QFile::remove( strNewFile );
return false;
}
/* flush before renaming */
f.close();
if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
- qWarning("error renaming");
+// qWarning("error renaming");
QFile::remove( strNewFile );
}
m_changed = false;
return true;
}
QArray<int> OTodoAccessXML::allRecords()const {
QArray<int> ids( m_events.count() );
QMap<int, OTodo>::ConstIterator it;
int i = 0;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
ids[i] = it.key();
i++;
}
return ids;
}
QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) {
QArray<int> ids(0);
return ids;
}
OTodo OTodoAccessXML::find( int uid )const {
OTodo todo;
todo.setUid( 0 ); // isEmpty()
QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
if ( it != m_events.end() )
todo = it.data();
return todo;
}
void OTodoAccessXML::clear() {
if (m_opened )
m_changed = true;
m_events.clear();
}
bool OTodoAccessXML::add( const OTodo& todo ) {
+// qWarning("add");
m_changed = true;
m_events.insert( todo.uid(), todo );
return true;
}
bool OTodoAccessXML::remove( int uid ) {
m_changed = true;
m_events.remove( uid );
return true;
}
bool OTodoAccessXML::replace( const OTodo& todo) {
m_changed = true;
m_events.replace( todo.uid(), todo );
return true;
}
QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
const QDate& end,
bool includeNoDates ) {
QArray<int> ids( m_events.count() );
QMap<int, OTodo>::Iterator it;
int i = 0;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
if ( !it.data().hasDueDate() ) {
if ( includeNoDates ) {
ids[i] = it.key();
i++;
}
}else if ( it.data().dueDate() >= start &&
it.data().dueDate() <= end ) {
ids[i] = it.key();
i++;
}
}
ids.resize( i );
return ids;
}
QArray<int> OTodoAccessXML::overDue() {
QArray<int> ids( m_events.count() );
int i = 0;
QMap<int, OTodo>::Iterator it;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
if ( it.data().isOverdue() ) {
ids[i] = it.key();
i++;
}
}
ids.resize( i );
return ids;
}
/* private */
OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const {
- qWarning("parse to do from XMLElement" );
+// qWarning("parse to do from XMLElement" );
OTodo ev;
QMap<QString, QString> attributes = element->attributes();
QMap<QString, QString>::Iterator it;
int *find=0;
int day, month, year;
day = month = year = -1;
for ( it = attributes.begin(); it != attributes.end(); ++it ) {
find = (*dict)[ it.key() ];
if (!find ) {
- qWarning("Unknown option" + it.key() );
+// qWarning("Unknown option" + it.key() );
ev.setCustomField( it.key(), it.data() );
continue;
}
switch( *find ) {
case OTodo::Uid:
ev.setUid( it.data().toInt() );
break;
case OTodo::Category:
ev.setCategories( ev.idsFromString( it.data() ) );
break;
case OTodo::HasDate:
ev.setHasDueDate( it.data().toInt() );
break;
case OTodo::Completed:
ev.setCompleted( it.data().toInt() );
break;
case OTodo::Description:
ev.setDescription( it.data() );
break;
case OTodo::Summary:
ev.setSummary( it.data() );
break;
case OTodo::Priority:
ev.setPriority( it.data().toInt() );
break;
case OTodo::DateDay:
day = it.data().toInt();
break;
case OTodo::DateMonth:
month = it.data().toInt();
break;
case OTodo::DateYear:
year = it.data().toInt();
break;
case OTodo::Progress:
ev.setProgress( it.data().toInt() );
break;
case OTodo::CrossReference:
{
/*
* A cross refernce looks like
* appname,id;appname,id
* we need to split it up
*/
QStringList refs = QStringList::split(';', it.data() );
QStringList::Iterator strIt;
for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
int pos = (*strIt).find(',');
if ( pos > -1 )
ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
}
break;
}
case OTodo::HasAlarmDateTime:
ev.setHasAlarmDateTime( it.data().toInt() );
break;
case OTodo::AlarmDateTime: {
/* this sounds better ;) zecke */
ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) );
break;
}
default:
break;
}
}
if ( ev.hasDueDate() ) {
QDate date( year, month, day );
ev.setDueDate( date );
}
return ev;
}
QString OTodoAccessXML::toString( const OTodo& ev )const {
QString str;
str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
str += "Categories=\"" + toString( ev.categories() ) + "\" ";
str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
if ( ev.hasDueDate() ) {
str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
}
+// qWarning( "Uid %d", ev.uid() );
str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
// append the extra options
/* FIXME Qtopia::Record this is currently not
* possible you can set custom fields
* but don' iterate over the list
* I may do #define private protected
* for this case - cough --zecke
*/
/*
QMap<QString, QString> extras = ev.extras();
QMap<QString, QString>::Iterator extIt;
for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
str += extIt.key() + "=\"" + extIt.data() + "\" ";
*/
// cross refernce
QStringList list = ev.relatedApps();
QStringList::Iterator listIt;
QString refs;
str += "CrossReference=\"";
bool added = false;
for ( listIt = list.begin(); listIt != list.end(); ++listIt ) {
added = true;
QArray<int> ints = ev.relations( (*listIt) );
for ( uint i = 0; i< ints.count(); i++ ) {
str += (*listIt) + "," + QString::number( i ) + ";";
}
}
if ( added )
str = str.remove( str.length()-1, 1 );
str += "\" ";
str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" ";
return str;
}
QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
return Qtopia::Record::idsToString( ints );
}