summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp18
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.h1
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h6
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp4
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h1
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp16
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h1
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp13
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h6
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h12
-rw-r--r--libopie2/opiepim/core/opimrecord.h6
-rw-r--r--libopie2/opiepim/ocontact.cpp9
-rw-r--r--libopie2/opiepim/ocontact.h3
-rw-r--r--libopie2/opiepim/oevent.cpp41
-rw-r--r--libopie2/opiepim/oevent.h2
-rw-r--r--libopie2/opiepim/otodo.h2
16 files changed, 114 insertions, 27 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index a0ae7b7..ab2eea4 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -1,588 +1,606 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <qasciidict.h>
#include <qfile.h>
#include <qtopia/global.h>
#include <qtopia/stringutil.h>
#include <qtopia/timeconversion.h>
#include "opimnotifymanager.h"
#include "orecur.h"
#include "otimezone.h"
#include "odatebookaccessbackend_xml.h"
namespace {
// FROM TT again
char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
{
char needleChar;
char haystackChar;
if (!needle || !haystack || !hLen || !nLen)
return 0;
const char* hsearch = haystack;
if ((needleChar = *needle++) != 0) {
nLen--; //(to make up for needle++)
do {
do {
if ((haystackChar = *hsearch++) == 0)
return (0);
if (hsearch >= haystack + hLen)
return (0);
} while (haystackChar != needleChar);
} while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
hsearch--;
}
return ((char *)hsearch);
}
}
namespace {
time_t start, end, created, rp_end;
ORecur* rec;
ORecur* recur() {
if (!rec)
rec = new ORecur;
return rec;
}
int alarmTime;
int snd;
enum Attribute{
FDescription = 0,
FLocation,
FCategories,
FUid,
FType,
FAlarm,
FSound,
FRType,
FRWeekdays,
FRPosition,
FRFreq,
FRHasEndDate,
FREndDate,
FRStart,
FREnd,
FNote,
FCreated,
FTimeZone,
FRecParent,
FRecChildren,
FExceptions
};
inline void save( const OEvent& ev, QString& buf ) {
qWarning("Saving %d %s", ev.uid(), ev.description().latin1() );
buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
if (!ev.location().isEmpty() )
buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\"";
buf += " uid=\"" + QString::number( ev.uid() ) + "\"";
if (ev.isAllDay() )
buf += " type=\"AllDay\"";
if (ev.hasNotifiers() ) {
OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
if ( alarm.sound() == OPimAlarm::Loud )
buf += "loud";
else
buf += "silent";
buf += "\"";
}
if ( ev.hasRecurrence() ) {
buf += ev.recurrence().toString();
}
/*
* fscking timezones :) well, we'll first convert
* the QDateTime to a QDateTime in UTC time
* and then we'll create a nice time_t
*/
OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\"";
buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\"";
if (!ev.note().isEmpty() ) {
buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
}
buf += " timezone=\"";
if ( ev.timeZone().isEmpty() )
buf += "None";
else
buf += ev.timeZone();
buf += "\"";
if (ev.parent() != 0 ) {
buf += " recparent=\""+QString::number(ev.parent() )+"\"";
}
if (ev.children().count() != 0 ) {
QArray<int> children = ev.children();
buf += " recchildren=\"";
for ( uint i = 0; i < children.count(); i++ ) {
if ( i != 0 ) buf += " ";
buf += QString::number( children[i] );
}
buf+= "\"";
}
// skip custom writing
}
inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) {
QMap<int, OEvent>::ConstIterator it;
QString buf;
QCString str;
int total_written;
for ( it = list.begin(); it != list.end(); ++it ) {
buf = "<event";
save( it.data(), buf );
buf += " />\n";
str = buf.utf8();
total_written = file.writeBlock(str.data(), str.length() );
if ( total_written != int(str.length() ) )
return false;
}
return true;
}
}
ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
const QString& fileName )
: ODateBookAccessBackend() {
m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
m_changed = false;
}
ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
}
bool ODateBookAccessBackend_XML::load() {
return loadFile();
}
bool ODateBookAccessBackend_XML::reload() {
clear();
return load();
}
bool ODateBookAccessBackend_XML::save() {
if (!m_changed) return true;
int total_written;
QString strFileNew = m_name + ".new";
QFile f( strFileNew );
if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
buf += "<events>\n";
QCString str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length() ) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
if (!forAll( m_raw, f ) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
if (!forAll( m_rep, f ) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
buf = "</events>\n</DATEBOOK>\n";
str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length() ) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
f.close();
if ( ::rename( strFileNew, m_name ) < 0 ) {
QFile::remove( strFileNew );
return false;
}
m_changed = false;
return true;
}
QArray<int> ODateBookAccessBackend_XML::allRecords()const {
QArray<int> ints( m_raw.count()+ m_rep.count() );
uint i = 0;
QMap<int, OEvent>::ConstIterator it;
for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
ints[i] = it.key();
i++;
}
for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
ints[i] = it.key();
i++;
}
return ints;
}
QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) {
return QArray<int>();
}
void ODateBookAccessBackend_XML::clear() {
m_changed = true;
m_raw.clear();
m_rep.clear();
}
OEvent ODateBookAccessBackend_XML::find( int uid ) const{
if ( m_raw.contains( uid ) )
return m_raw[uid];
else
return m_rep[uid];
}
bool ODateBookAccessBackend_XML::add( const OEvent& ev ) {
m_changed = true;
if (ev.hasRecurrence() )
m_rep.insert( ev.uid(), ev );
else
m_raw.insert( ev.uid(), ev );
return true;
}
bool ODateBookAccessBackend_XML::remove( int uid ) {
m_changed = true;
m_rep.remove( uid );
m_rep.remove( uid );
return true;
}
bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) {
replace( ev.uid() );
return add( ev );
}
QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
return allRecords();
}
QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
QArray<int> ints( m_rep.count() );
uint i = 0;
QMap<int, OEvent>::ConstIterator it;
for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
ints[i] = it.key();
i++;
}
return ints;
}
QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
QArray<int> ints( m_raw.count() );
uint i = 0;
QMap<int, OEvent>::ConstIterator it;
for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
ints[i] = it.key();
i++;
}
return ints;
}
OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
OEvent::ValueList list;
QMap<int, OEvent>::ConstIterator it;
for (it = m_raw.begin(); it != m_raw.end(); ++it )
list.append( it.data() );
return list;
}
OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
OEvent::ValueList list;
QMap<int, OEvent>::ConstIterator it;
for (it = m_rep.begin(); it != m_rep.end(); ++it )
list.append( it.data() );
return list;
}
bool ODateBookAccessBackend_XML::loadFile() {
m_changed = false;
int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY );
if ( fd < 0 ) return false;
struct stat attribute;
if ( ::fstat(fd, &attribute ) == -1 ) {
::close( fd );
return false;
}
void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 );
if ( map_addr == ( (caddr_t)-1) ) {
::close( fd );
return false;
}
::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
::close( fd );
QAsciiDict<int> dict(FExceptions+1);
dict.setAutoDelete( true );
dict.insert( "description", new int(FDescription) );
dict.insert( "location", new int(FLocation) );
dict.insert( "categories", new int(FCategories) );
dict.insert( "uid", new int(FUid) );
dict.insert( "type", new int(FType) );
dict.insert( "alarm", new int(FAlarm) );
dict.insert( "sound", new int(FSound) );
dict.insert( "rtype", new int(FRType) );
dict.insert( "rweekdays", new int(FRWeekdays) );
dict.insert( "rposition", new int(FRPosition) );
dict.insert( "rfreq", new int(FRFreq) );
dict.insert( "rhasenddate", new int(FRHasEndDate) );
dict.insert( "enddt", new int(FREndDate) );
dict.insert( "start", new int(FRStart) );
dict.insert( "end", new int(FREnd) );
dict.insert( "note", new int(FNote) );
dict.insert( "created", new int(FCreated) );
dict.insert( "recparent", new int(FRecParent) );
dict.insert( "recchildren", new int(FRecChildren) );
dict.insert( "exceptions", new int(FExceptions) );
dict.insert( "timezone", new int(FTimeZone) );
char* dt = (char*)map_addr;
int len = attribute.st_size;
int i = 0;
char* point;
const char* collectionString = "<event ";
int strLen = ::strlen(collectionString);
int *find;
while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
i = point -dt;
i+= strLen;
alarmTime = -1;
snd = 0; // silent
OEvent ev;
rec = 0;
while ( TRUE ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
break;
// we have another attribute, read it.
int j = i;
while ( j < len && dt[j] != '=' )
++j;
QCString attr( dt+i, j-i+1);
i = ++j; // skip =
// find the start of quotes
while ( i < len && dt[i] != '"' )
++i;
j = ++i;
bool haveUtf = FALSE;
bool haveEnt = FALSE;
while ( j < len && dt[j] != '"' ) {
if ( ((unsigned char)dt[j]) > 0x7f )
haveUtf = TRUE;
if ( dt[j] == '&' )
haveEnt = TRUE;
++j;
}
if ( i == j ) {
// empty value
i = j + 1;
continue;
}
QCString value( dt+i, j-i+1 );
i = j + 1;
QString str = (haveUtf ? QString::fromUtf8( value )
: QString::fromLatin1( value ) );
if ( haveEnt )
str = Qtopia::plainString( str );
/*
* add key + value
*/
find = dict[attr.data()];
if (!find)
ev.setCustomField( attr, value );
else {
setField( ev, *find, value );
}
}
/* time to finalize */
finalizeRecord( ev );
delete rec;
}
::munmap(map_addr, attribute.st_size );
m_changed = false; // changed during add
return true;
}
void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) {
/* AllDay is alway in UTC */
if ( ev.isAllDay() ) {
OTimeZone utc = OTimeZone::utc();
ev.setStartDateTime( utc.fromUTCDateTime( start ) );
ev.setEndDateTime ( utc.fromUTCDateTime( end ) );
ev.setTimeZone( "UTC"); // make sure it is really utc
}else {
/* to current date time */
qWarning(" Start is %d", start );
OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() );
QDateTime date = zone.toDateTime( start );
qWarning(" Start is %s", date.toString().latin1() );
ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );
date = zone.toDateTime( end );
ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) );
}
if ( rec && rec->doesRecur() ) {
OTimeZone utc = OTimeZone::utc();
ORecur recu( *rec ); // call copy c'tor;
recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() );
recu.setCreatedDateTime( utc.fromUTCDateTime( created ) );
recu.setStart( ev.startDateTime().date() );
ev.setRecurrence( recu );
}
if (alarmTime != -1 ) {
QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 );
OPimAlarm al( snd , dt );
ev.notifiers().add( al );
}
if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
qWarning("already contains assign uid");
ev.setUid( 1 );
}
qWarning("addind %d %s", ev.uid(), ev.description().latin1() );
if ( ev.hasRecurrence() )
m_rep.insert( ev.uid(), ev );
else
m_raw.insert( ev.uid(), ev );
}
void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) {
// qWarning(" setting %s", value.latin1() );
switch( id ) {
case FDescription:
e.setDescription( value );
break;
case FLocation:
e.setLocation( value );
break;
case FCategories:
e.setCategories( e.idsFromString( value ) );
break;
case FUid:
e.setUid( value.toInt() );
break;
case FType:
if ( value == "AllDay" ) {
e.setAllDay( true );
e.setTimeZone( "UTC" );
}
break;
case FAlarm:
alarmTime = value.toInt();
break;
case FSound:
snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
break;
// recurrence stuff
case FRType:
if ( value == "Daily" )
recur()->setType( ORecur::Daily );
else if ( value == "Weekly" )
recur()->setType( ORecur::Weekly);
else if ( value == "MonthlyDay" )
recur()->setType( ORecur::MonthlyDay );
else if ( value == "MonthlyDate" )
recur()->setType( ORecur::MonthlyDate );
else if ( value == "Yearly" )
recur()->setType( ORecur::Yearly );
else
recur()->setType( ORecur::NoRepeat );
break;
case FRWeekdays:
recur()->setDays( value.toInt() );
break;
case FRPosition:
recur()->setPosition( value.toInt() );
break;
case FRFreq:
recur()->setFrequency( value.toInt() );
break;
case FRHasEndDate:
recur()->setHasEndDate( value.toInt() );
break;
case FREndDate: {
rp_end = (time_t) value.toLong();
break;
}
case FRStart: {
start = (time_t) value.toLong();
break;
}
case FREnd: {
end = ( (time_t) value.toLong() );
break;
}
case FNote:
e.setNote( value );
break;
case FCreated:
created = value.toInt();
break;
case FRecParent:
e.setParent( value.toInt() );
break;
case FRecChildren:{
QStringList list = QStringList::split(' ', value );
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
e.addChild( (*it).toInt() );
}
}
break;
case FExceptions:{
QStringList list = QStringList::split(' ', value );
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
qWarning("adding exception %s", date.toString().latin1() );
recur()->exceptions().append( date );
}
}
break;
case FTimeZone:
if ( value != "None" )
e.setTimeZone( value );
break;
default:
break;
}
}
+QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const
+{
+ QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() );
+ uint arraycounter = 0;
+ QMap<int, OEvent>::ConstIterator it;
+
+ for ( it = m_raw.begin(); it != m_raw.end(); ++it )
+ if ( it.data().match( r ) )
+ m_currentQuery[arraycounter++] = it.data().uid();
+ for ( it = m_rep.begin(); it != m_rep.end(); ++it )
+ if ( it.data().match( r ) )
+ m_currentQuery[arraycounter++] = it.data().uid();
+
+ // Shrink to fit..
+ m_currentQuery.resize(arraycounter);
+
+ return m_currentQuery;
+}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
index 7848f7c..a5cc0fc 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h
@@ -1,54 +1,55 @@
#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H
#include <qmap.h>
#include "odatebookaccessbackend.h"
/**
* This is the default XML implementation for DateBoook XML storage
* It fully implements the interface
* @see ODateBookAccessBackend
* @see OPimAccessBackend
*/
class ODateBookAccessBackend_XML : public ODateBookAccessBackend {
public:
ODateBookAccessBackend_XML( const QString& appName,
const QString& fileName = QString::null);
~ODateBookAccessBackend_XML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
+ QArray<int> matchRegexp(const QRegExp &r) const;
QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() );
OEvent find( int uid )const;
void clear();
bool add( const OEvent& ev );
bool remove( int uid );
bool replace( const OEvent& ev );
QArray<UID> rawEvents()const;
QArray<UID> rawRepeats()const;
QArray<UID> nonRepeats()const;
OEvent::ValueList directNonRepeats();
OEvent::ValueList directRawRepeats();
private:
bool m_changed :1 ;
bool loadFile();
inline void finalizeRecord( OEvent& ev );
inline void setField( OEvent&, int field, const QString& val );
QString m_name;
QMap<int, OEvent> m_raw;
QMap<int, OEvent> m_rep;
struct Data;
Data* data;
class Private;
Private *d;
};
#endif
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 01a0c86..f4bbe35 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -1,153 +1,159 @@
#ifndef OPIE_PIM_ACCESS_BACKEND
#define OPIE_PIM_ACCESS_BACKEND
#include <qarray.h>
#include <opie/otemplatebase.h>
#include <opie/opimrecord.h>
/**
* OPimAccessBackend is the base class
* for all private backends
* it operates on OPimRecord as the base class
* and it's responsible for fast manipulating
* the resource the implementation takes care
* of
*/
template <class T = OPimRecord>
class OPimAccessBackend {
public:
typedef OTemplateBase<T> Frontend;
/** The access hint from the frontend */
OPimAccessBackend(int access = 0);
virtual ~OPimAccessBackend();
/**
* load the resource
*/
virtual bool load() = 0;
/**
* reload the resource
*/
virtual bool reload() = 0;
/**
* save the resource and
* all it's changes
*/
virtual bool save() = 0;
/**
* return an array of
* all available uids
*/
virtual QArray<int> allRecords()const = 0;
+ /**
+ * return a List of records
+ * that match the regex
+ */
+ virtual QArray<int> matchRegexp(const QRegExp &r) const = 0;
+
/**
* queryByExample for T with the given Settings
*
*/
virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
/**
* find the OPimRecord with uid @param uid
* returns T and T.isEmpty() if nothing was found
*/
virtual T find(int uid )const = 0;
virtual T find(int uid, const QArray<int>& items,
uint current, typename Frontend::CacheDirection )const ;
/**
* clear the back end
*/
virtual void clear() = 0;
/**
* add T
*/
virtual bool add( const T& t ) = 0;
/**
* remove
*/
virtual bool remove( int uid ) = 0;
/**
* replace a record with T.uid()
*/
virtual bool replace( const T& t ) = 0;
/*
* setTheFrontEnd!!!
*/
void setFrontend( Frontend* front );
/**
* set the read ahead count
*/
void setReadAhead( uint count );
protected:
int access()const;
void cache( const T& t )const;
/**
* use a prime number here!
*/
void setSaneCacheSize( int );
uint readAhead()const;
private:
class Private;
Private* d;
Frontend* m_front;
uint m_read;
int m_acc;
};
template <class T>
OPimAccessBackend<T>::OPimAccessBackend(int acc)
: m_acc( acc )
{
m_front = 0l;
}
template <class T>
OPimAccessBackend<T>::~OPimAccessBackend() {
}
template <class T>
void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
m_front = fr;
}
template <class T>
void OPimAccessBackend<T>::cache( const T& t )const {
if (m_front )
m_front->cache( t );
}
template <class T>
void OPimAccessBackend<T>::setSaneCacheSize( int size) {
if (m_front )
m_front->setSaneCacheSize( size );
}
template <class T>
T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
uint, typename Frontend::CacheDirection )const {
return find( uid );
}
template <class T>
void OPimAccessBackend<T>::setReadAhead( uint count ) {
m_read = count;
}
template <class T>
uint OPimAccessBackend<T>::readAhead()const {
return m_read;
}
template <class T>
int OPimAccessBackend<T>::access()const {
return m_acc;
}
#endif
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
index 9bc16c6..3577e14 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.cpp
+++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp
@@ -1,221 +1,225 @@
#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() ) {
QTime time(0, 0, 0);
QDateTime date(event.dueDate(), time );
addPropValue( task, VCDueProp,
TimeConversion::toISO8601( date ) );
}
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;
}
void OTodoAccessVCal::removeAllCompleted() {
for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
if ( (*it).isCompleted() )
m_map.remove( it );
}
}
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::matchRegexp(const QRegExp &r)const {
+ QArray<int> ar(0);
+ return ar;
+}
QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) {
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;
}
QBitArray OTodoAccessVCal::supports()const {
static QBitArray ar = sup();
return ar;
}
QBitArray OTodoAccessVCal::sup() {
QBitArray ar ( OTodo::CompletedDate +1 );
ar.fill( true );
ar[OTodo::CrossReference] = false;
ar[OTodo::State ] = false;
ar[OTodo::Reminders] = false;
ar[OTodo::Notifiers] = false;
ar[OTodo::Maintainer] = false;
ar[OTodo::Progress] = false;
ar[OTodo::Alarms ] = false;
ar[OTodo::Recurrence] = false;
return ar;
}
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h
index 489416b..2b17147 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.h
+++ b/libopie2/opiepim/backend/otodoaccessvcal.h
@@ -1,39 +1,40 @@
#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> matchRegexp(const QRegExp &r) const;
QArray<int> queryByExample( const OTodo& t, int sort, const QDateTime& d = QDateTime() );
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& );
void removeAllCompleted();
virtual QBitArray supports()const;
private:
static QBitArray sup();
bool m_dirty : 1;
QString m_file;
QMap<int, OTodo> m_map;
};
#endif
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 285d2b8..69b7ab4 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -1,776 +1,792 @@
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <qfile.h>
#include <qvector.h>
#include <qpe/global.h>
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
#include "oconversion.h"
#include "opimstate.h"
#include "otimezone.h"
#include "orecur.h"
#include "otodoaccessxml.h"
namespace {
time_t rp_end;
ORecur* rec;
ORecur *recur() {
if (!rec ) rec = new ORecur;
return rec;
}
int snd;
enum MoreAttributes {
FRType = OTodo::CompletedDate + 2,
FRWeekdays,
FRPosition,
FRFreq,
FRHasEndDate,
FREndDate,
FRStart,
FREnd
};
// FROM TT again
char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
{
char needleChar;
char haystackChar;
if (!needle || !haystack || !hLen || !nLen)
return 0;
const char* hsearch = haystack;
if ((needleChar = *needle++) != 0) {
nLen--; //(to make up for needle++)
do {
do {
if ((haystackChar = *hsearch++) == 0)
return (0);
if (hsearch >= haystack + hLen)
return (0);
} while (haystackChar != needleChar);
} while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
hsearch--;
}
return ((char *)hsearch);
}
}
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() {
rec = 0;
m_opened = true;
m_changed = false;
/* initialize dict */
/*
* UPDATE dict if you change anything!!!
*/
QAsciiDict<int> dict(21);
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("CompletedDate", new int(OTodo::CompletedDate) );
dict.insert("StartDate", new int(OTodo::StartDate) );
dict.insert("CrossReference", new int(OTodo::CrossReference) );
dict.insert("State", new int(OTodo::State) );
dict.insert("Alarms", new int(OTodo::Alarms) );
dict.insert("Reminders", new int(OTodo::Reminders) );
dict.insert("Notifiers", new int(OTodo::Notifiers) );
dict.insert("Maintainer", new int(OTodo::Maintainer) );
dict.insert("rtype", new int(FRType) );
dict.insert("rweekdays", new int(FRWeekdays) );
dict.insert("rposition", new int(FRPosition) );
dict.insert("rfreq", new int(FRFreq) );
dict.insert("start", new int(FRStart) );
dict.insert("rhasenddate", new int(FRHasEndDate) );
dict.insert("enddt", new int(FREndDate) );
// here the custom XML parser from TT it's GPL
// but we want to push OpiePIM... to TT.....
// mmap part from zecke :)
int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
struct stat attribut;
if ( fd < 0 ) return false;
if ( fstat(fd, &attribut ) == -1 ) {
::close( fd );
return false;
}
void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
if ( map_addr == ( (caddr_t)-1) ) {
::close(fd );
return false;
}
/* advise the kernel who we want to read it */
::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
/* we do not the file any more */
::close( fd );
char* dt = (char*)map_addr;
int len = attribut.st_size;
int i = 0;
char *point;
const char* collectionString = "<Task ";
int strLen = strlen(collectionString);
while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
i = point -dt;
i+= strLen;
qWarning("Found a start at %d %d", i, (point-dt) );
OTodo ev;
m_year = m_month = m_day = 0;
while ( TRUE ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
break;
// we have another attribute, read it.
int j = i;
while ( j < len && dt[j] != '=' )
++j;
QCString attr( dt+i, j-i+1);
i = ++j; // skip =
// find the start of quotes
while ( i < len && dt[i] != '"' )
++i;
j = ++i;
bool haveUtf = FALSE;
bool haveEnt = FALSE;
while ( j < len && dt[j] != '"' ) {
if ( ((unsigned char)dt[j]) > 0x7f )
haveUtf = TRUE;
if ( dt[j] == '&' )
haveEnt = TRUE;
++j;
}
if ( i == j ) {
// empty value
i = j + 1;
continue;
}
QCString value( dt+i, j-i+1 );
i = j + 1;
QString str = (haveUtf ? QString::fromUtf8( value )
: QString::fromLatin1( value ) );
if ( haveEnt )
str = Qtopia::plainString( str );
/*
* add key + value
*/
todo( &dict, ev, attr, str );
}
/*
* now add it
*/
qWarning("End at %d", i );
if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
ev.setUid( 1 );
m_changed = true;
}
if ( ev.hasDueDate() ) {
ev.setDueDate( QDate(m_year, m_month, m_day) );
}
if ( rec && rec->doesRecur() ) {
OTimeZone utc = OTimeZone::utc();
ORecur recu( *rec ); // call copy c'tor
recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() );
recu.setStart( ev.dueDate() );
ev.setRecurrence( recu );
}
m_events.insert(ev.uid(), ev );
m_year = m_month = m_day = -1;
delete rec;
rec = 0;
}
munmap(map_addr, attribut.st_size );
qWarning("counts %d records loaded!", m_events.count() );
return true;
}
bool OTodoAccessXML::reload() {
m_events.clear();
return load();
}
bool OTodoAccessXML::save() {
// 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");
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, const QDateTime& ) {
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 */
void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
const QCString& attr, const QString& val) {
// qWarning("parse to do from XMLElement" );
int *find=0;
find = (*dict)[ attr.data() ];
if (!find ) {
// qWarning("Unknown option" + it.key() );
ev.setCustomField( attr, val );
return;
}
switch( *find ) {
case OTodo::Uid:
ev.setUid( val.toInt() );
break;
case OTodo::Category:
ev.setCategories( ev.idsFromString( val ) );
break;
case OTodo::HasDate:
ev.setHasDueDate( val.toInt() );
break;
case OTodo::Completed:
ev.setCompleted( val.toInt() );
break;
case OTodo::Description:
ev.setDescription( val );
break;
case OTodo::Summary:
ev.setSummary( val );
break;
case OTodo::Priority:
ev.setPriority( val.toInt() );
break;
case OTodo::DateDay:
m_day = val.toInt();
break;
case OTodo::DateMonth:
m_month = val.toInt();
break;
case OTodo::DateYear:
m_year = val.toInt();
break;
case OTodo::Progress:
ev.setProgress( val.toInt() );
break;
case OTodo::CompletedDate:
ev.setCompletedDate( OConversion::dateFromString( val ) );
break;
case OTodo::StartDate:
ev.setStartDate( OConversion::dateFromString( val ) );
break;
case OTodo::State:
ev.setState( val.toInt() );
break;
case OTodo::CrossReference:
{
/*
* A cross refernce looks like
* appname,id;appname,id
* we need to split it up
*/
QStringList refs = QStringList::split(';', val );
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;
}
/* Recurrence stuff below + post processing later */
case FRType:
if ( val == "Daily" )
recur()->setType( ORecur::Daily );
else if ( val == "Weekly" )
recur()->setType( ORecur::Weekly);
else if ( val == "MonthlyDay" )
recur()->setType( ORecur::MonthlyDay );
else if ( val == "MonthlyDate" )
recur()->setType( ORecur::MonthlyDate );
else if ( val == "Yearly" )
recur()->setType( ORecur::Yearly );
else
recur()->setType( ORecur::NoRepeat );
break;
case FRWeekdays:
recur()->setDays( val.toInt() );
break;
case FRPosition:
recur()->setPosition( val.toInt() );
break;
case FRFreq:
recur()->setFrequency( val.toInt() );
break;
case FRHasEndDate:
recur()->setHasEndDate( val.toInt() );
break;
case FREndDate: {
rp_end = (time_t) val.toLong();
break;
}
default:
break;
}
}
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
if ( ev.hasRecurrence() ) {
str += ev.recurrence().toString();
}
if ( ev.hasStartDate() )
str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" ";
if ( ev.hasCompletedDate() )
str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" ";
if ( ev.hasState() )
str += "State=\""+QString::number( ev.state().state() )+"\" ";
return str;
}
QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
return Qtopia::Record::idsToString( ints );
}
/* internal class for sorting
*
* Inspired by todoxmlio.cpp from TT
*/
struct OTodoXMLContainer {
OTodo todo;
};
namespace {
inline QString string( const OTodo& todo) {
return todo.summary().isEmpty() ?
todo.description().left(20 ) :
todo.summary();
}
inline int completed( const OTodo& todo1, const OTodo& todo2) {
int ret = 0;
if ( todo1.isCompleted() ) ret++;
if ( todo2.isCompleted() ) ret--;
return ret;
}
inline int priority( const OTodo& t1, const OTodo& t2) {
return ( t1.priority() - t2.priority() );
}
inline int description( const OTodo& t1, const OTodo& t2) {
return QString::compare( string(t1), string(t2) );
}
inline int deadline( const OTodo& t1, const OTodo& t2) {
int ret = 0;
if ( t1.hasDueDate() &&
t2.hasDueDate() )
ret = t2.dueDate().daysTo( t1.dueDate() );
else if ( t1.hasDueDate() )
ret = -1;
else if ( t2.hasDueDate() )
ret = 1;
else
ret = 0;
return ret;
}
};
/*
* Returns:
* 0 if item1 == item2
*
* non-zero if item1 != item2
*
* This function returns int rather than bool so that reimplementations
* can return one of three values and use it to sort by:
*
* 0 if item1 == item2
*
* > 0 (positive integer) if item1 > item2
*
* < 0 (negative integer) if item1 < item2
*
*/
class OTodoXMLVector : public QVector<OTodoXMLContainer> {
public:
OTodoXMLVector(int size, bool asc, int sort)
: QVector<OTodoXMLContainer>( size )
{
setAutoDelete( true );
m_asc = asc;
m_sort = sort;
}
/* return the summary/description */
QString string( const OTodo& todo) {
return todo.summary().isEmpty() ?
todo.description().left(20 ) :
todo.summary();
}
/**
* we take the sortorder( switch on it )
*
*/
int compareItems( Item d1, Item d2 ) {
bool seComp, sePrio, seDesc, seDeadline;
seComp = sePrio = seDeadline = seDesc = false;
int ret =0;
OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
/* same item */
if ( con1->todo.uid() == con2->todo.uid() )
return 0;
switch ( m_sort ) {
/* completed */
case 0: {
ret = completed( con1->todo, con2->todo );
seComp = TRUE;
break;
}
/* priority */
case 1: {
ret = priority( con1->todo, con2->todo );
sePrio = TRUE;
break;
}
/* description */
case 2: {
ret = description( con1->todo, con2->todo );
seDesc = TRUE;
break;
}
/* deadline */
case 3: {
ret = deadline( con1->todo, con2->todo );
seDeadline = TRUE;
break;
}
default:
ret = 0;
break;
};
/*
* FIXME do better sorting if the first sort criteria
* ret equals 0 start with complete and so on...
*/
/* twist it we're not ascending*/
if (!m_asc)
ret = ret * -1;
if ( ret )
return ret;
// default did not gave difference let's try it other way around
/*
* General try if already checked if not test
* and return
* 1.Completed
* 2.Priority
* 3.Description
* 4.DueDate
*/
if (!seComp ) {
if ( (ret = completed( con1->todo, con2->todo ) ) ) {
if (!m_asc ) ret *= -1;
return ret;
}
}
if (!sePrio ) {
if ( (ret = priority( con1->todo, con2->todo ) ) ) {
if (!m_asc ) ret *= -1;
return ret;
}
}
if (!seDesc ) {
if ( (ret = description(con1->todo, con2->todo ) ) ) {
if (!m_asc) ret *= -1;
return ret;
}
}
if (!seDeadline) {
if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
if (!m_asc) ret *= -1;
return ret;
}
}
return 0;
}
private:
bool m_asc;
int m_sort;
};
QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
int sortFilter, int cat ) {
qWarning("sorted! %d cat", cat);
OTodoXMLVector vector(m_events.count(), asc,sortOrder );
QMap<int, OTodo>::Iterator it;
int item = 0;
bool bCat = sortFilter & 1 ? true : false;
bool bOnly = sortFilter & 2 ? true : false;
bool comp = sortFilter & 4 ? true : false;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
/* show category */
if ( bCat && cat != 0)
if (!(*it).categories().contains( cat ) ) {
qWarning("category mis match");
continue;
}
/* isOverdue but we should not show overdue - why?*/
/* if ( (*it).isOverdue() && !bOnly ) {
qWarning("item is overdue but !bOnly");
continue;
}
*/
if ( !(*it).isOverdue() && bOnly ) {
qWarning("item is not overdue but bOnly checked");
continue;
}
if ((*it).isCompleted() && comp ) {
qWarning("completed continue!");
continue;
}
OTodoXMLContainer* con = new OTodoXMLContainer();
con->todo = (*it);
vector.insert(item, con );
item++;
}
qWarning("XXX %d Items added", item);
vector.resize( item );
/* sort it now */
vector.sort();
/* now get the uids */
QArray<int> array( vector.count() );
for (uint i= 0; i < vector.count(); i++ ) {
array[i] = ( vector.at(i) )->todo.uid();
}
return array;
};
void OTodoAccessXML::removeAllCompleted() {
for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
if ( (*it).isCompleted() )
m_events.remove( it );
}
}
QBitArray OTodoAccessXML::supports()const {
static QBitArray ar = sup();
return ar;
}
QBitArray OTodoAccessXML::sup() {
QBitArray ar( OTodo::CompletedDate +1 );
ar.fill( true );
ar[OTodo::CrossReference] = false;
ar[OTodo::State ] = false;
ar[OTodo::Reminders] = false;
ar[OTodo::Notifiers] = false;
ar[OTodo::Maintainer] = false;
return ar;
}
+QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const
+{
+ QArray<int> m_currentQuery( m_events.count() );
+ uint arraycounter = 0;
+
+ QMap<int, OTodo>::ConstIterator it;
+ for (it = m_events.begin(); it != m_events.end(); ++it ) {
+ if ( it.data().match( r ) )
+ m_currentQuery[arraycounter++] = it.data().uid();
+
+ }
+ // Shrink to fit..
+ m_currentQuery.resize(arraycounter);
+
+ return m_currentQuery;
+}
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index cc4a16f..e4850a1 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -1,59 +1,60 @@
#ifndef OPIE_TODO_ACCESS_XML_H
#define OPIE_TODO_ACCESS_XML_H
#include <qasciidict.h>
#include <qmap.h>
#include "otodoaccessbackend.h"
namespace Opie {
class XMLElement;
};
class OTodoAccessXML : public OTodoAccessBackend {
public:
/**
* fileName if Empty we will use the default path
*/
OTodoAccessXML( const QString& appName,
const QString& fileName = QString::null );
~OTodoAccessXML();
bool load();
bool reload();
bool save();
QArray<int> allRecords()const;
+ QArray<int> matchRegexp(const QRegExp &r) const;
QArray<int> queryByExample( const OTodo&, int querysettings, const QDateTime& d = QDateTime() );
OTodo find( int uid )const;
void clear();
bool add( const OTodo& );
bool remove( int uid );
void removeAllCompleted();
bool replace( const OTodo& );
/* our functions */
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 );
QBitArray supports()const;
private:
static QBitArray sup();
void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& );
QString toString( const OTodo& )const;
QString toString( const QArray<int>& ints ) const;
QMap<int, OTodo> m_events;
QString m_file;
QString m_app;
bool m_opened : 1;
bool m_changed : 1;
class OTodoAccessXMLPrivate;
OTodoAccessXMLPrivate* d;
int m_year, m_month, m_day;
};
#endif
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 9c9338e..2e3ec1f 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,169 +1,168 @@
/*
* Class to manage the Contacts.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* Info: This class could just work with a change in the header-file
* of the Contact class ! Therefore our libopie only compiles
* with our version of libqpe
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.8 2003/05/08 13:55:09 tille
+ * search stuff
+ * and match, toRichText & toShortText in oevent
+ *
* Revision 1.7 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.6 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* Revision 1.5 2002/10/16 10:52:40 eilers
* Added some docu to the interface and now using the cache infrastucture by zecke.. :)
*
* Revision 1.4 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.3 2002/10/07 17:34:24 eilers
* added OBackendFactory for advanced backend access
*
* Revision 1.2 2002/10/02 16:18:11 eilers
* debugged and seems to work almost perfectly ..
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
*
*/
#include "ocontactaccess.h"
#include "obackendfactory.h"
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qregexp.h>
#include <qlist.h>
#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 "ocontactaccessbackend_xml.h"
OContactAccess::OContactAccess ( const QString appname, const QString ,
OContactAccessBackend* end, bool autosync ):
OPimAccessTemplate<OContact>( end )
{
- /* take care of the backend. If there is no one defined, we
+ /* 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<OContactAccessBackend>::Default( "contact", appname );
}
// Set backend locally and in template
m_backEnd = end;
OPimAccessTemplate<OContact>::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 );
connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(copMessage( const QCString &, const QByteArray &)) );
}
}
OContactAccess::~OContactAccess ()
{
/* The user may forget to save the changed database, therefore try to
* do it for him..
*/
save();
// delete m_backEnd; is done by template..
}
bool OContactAccess::save ()
{
/* If the database was changed externally, we could not save the
* Data. This will remove added items which is unacceptable !
* Therefore: Reload database and merge the data...
*/
if ( OPimAccessTemplate<OContact>::wasChangedExternally() )
reload();
bool status = OPimAccessTemplate<OContact>::save();
if ( !status ) return false;
/* Now tell everyone that new data is available.
*/
QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
return true;
}
-ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{
- QArray<int> matchingContacts = m_backEnd -> matchRegexp( r );
- return ( ORecordList<OContact>(matchingContacts, this) );
-}
-
const uint OContactAccess::querySettings()
{
return ( m_backEnd->querySettings() );
}
bool OContactAccess::hasQuerySettings ( int querySettings ) const
{
return ( m_backEnd->hasQuerySettings ( querySettings ) );
}
ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
{
QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
return ( ORecordList<OContact>(matchingContacts, this) );
}
bool OContactAccess::wasChangedExternally()const
{
return ( m_backEnd->wasChangedExternally() );
}
void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "addressbookUpdated()" ){
qWarning ("OContactAccess: Received addressbokUpdated()");
emit signalChanged ( this );
} else if ( msg == "flush()" ) {
qWarning ("OContactAccess: Received flush()");
save ();
} else if ( msg == "reload()" ) {
qWarning ("OContactAccess: Received reload()");
reload ();
emit signalChanged ( this );
}
}
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index d7ceaf2..e90db32 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,168 +1,170 @@
/*
* Class to manage the Contacts.
*
* Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
* Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later
* version.
* =====================================================================
* ToDo: Define enum for query settings
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.8 2003/05/08 13:55:09 tille
+ * search stuff
+ * and match, toRichText & toShortText in oevent
+ *
* Revision 1.7 2003/04/13 18:07:10 zecke
* More API doc
* QString -> const QString&
* QString = 0l -> QString::null
*
* Revision 1.6 2003/01/02 14:27:12 eilers
* Improved query by example: Search by date is possible.. First step
* for a today plugin for birthdays..
*
* Revision 1.5 2002/11/13 14:14:51 eilers
* Added sorted for Contacts..
*
* Revision 1.4 2002/11/01 15:10:42 eilers
* Added regExp-search in database for all fields in a contact.
*
* Revision 1.3 2002/10/16 10:52:40 eilers
* Added some docu to the interface and now using the cache infrastucture by zecke.. :)
*
* Revision 1.2 2002/10/14 16:21:54 eilers
* Some minor interface updates
*
* Revision 1.1 2002/09/27 17:11:44 eilers
* Added API for accessing the Contact-Database ! It is compiling, but
* please do not expect that anything is working !
* I will debug that stuff in the next time ..
* Please read README_COMPILE for compiling !
*
* =====================================================================
*/
#ifndef _OCONTACTACCESS_H
#define _OCONTACTACCESS_H
#include <qobject.h>
#include <qpe/qcopenvelope_qws.h>
#include <qvaluelist.h>
#include <qfileinfo.h>
#include "ocontact.h"
#include "ocontactaccessbackend.h"
#include "opimaccesstemplate.h"
/**
* Class to access the contacts database.
* This is just a frontend for the real database handling which is
* done by the backend.
* This class is used to access the Contacts on a system. This class as any OPIE PIM
* class is backend independent.
* @see OPimAccessTemplate
*/
class OContactAccess: public QObject, public OPimAccessTemplate<OContact>
{
Q_OBJECT
public:
/**
* Create Database with contacts (addressbook).
* @param appname Name of application which wants access to the database
* (i.e. "todolist")
* @param filename The name of the database file. If not set, the default one
* is used.
* @param backend Pointer to an alternative Backend. If not set, we will use
* the default backend.
* @param handlesync If <b>true</b> the database stores the current state
* automatically if it receives the signals <i>flush()</i> and <i>reload()</i>
* which are used before and after synchronisation. If the application wants
* to react itself, it should be disabled by setting it to <b>false</b>
* @see OContactAccessBackend
*/
OContactAccess (const QString appname, const QString filename = 0l,
OContactAccessBackend* backend = 0l, bool handlesync = true);
~OContactAccess ();
/** Constants for query.
* Use this constants to set the query parameters.
* Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
* @see queryByExample()
*/
enum QuerySettings {
WildCards = 0x0001,
IgnoreCase = 0x0002,
RegExp = 0x0004,
ExactMatch = 0x0008,
MatchOne = 0x0010, // Only one Entry must match
DateDiff = 0x0020, // Find all entries from today until given date
DateYear = 0x0040, // The year matches
DateMonth = 0x0080, // The month matches
DateDay = 0x0100, // The day matches
};
- ORecordList<OContact> matchRegexp( const QRegExp &r )const;
-
/** Return all Contacts in a sorted manner.
* @param ascending true: Sorted in acending order.
* @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
* @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
* @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
*/
List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const;
/** Return all possible settings.
* @return All settings provided by the current backend
* (i.e.: query_WildCards & query_IgnoreCase)
*/
const uint querySettings();
/** Check whether settings are correct.
* @return <i>true</i> if the given settings are correct and possible.
*/
bool hasQuerySettings ( int querySettings ) const;
/**
* if the resource was changed externally.
* You should use the signal instead of polling possible changes !
*/
bool wasChangedExternally()const;
/** Save contacts database.
* Save is more a "commit". After calling this function, all changes are public available.
* @return true if successful
*/
bool save();
signals:
/* Signal is emitted if the database was changed. Therefore
* we may need to reload to stay consistent.
* @param which Pointer to the database who created this event. This pointer
* is useful if an application has to handle multiple databases at the same time.
* @see reload()
*/
void signalChanged ( const OContactAccess *which );
private:
// class OContactAccessPrivate;
// OContactAccessPrivate* d;
OContactAccessBackend *m_backEnd;
bool m_loading:1;
private slots:
void copMessage( const QCString &msg, const QByteArray &data );
};
#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 6a3a0db..8ff205c 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,286 +1,298 @@
#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
#define OPIE_PIM_ACCESS_TEMPLATE_H
#include <qarray.h>
#include <opie/opimrecord.h>
#include <opie/opimaccessbackend.h>
#include <opie/orecordlist.h>
#include "opimcache.h"
#include "otemplatebase.h"
/**
* Thats the frontend to our OPIE PIM
* Library. Either you want to use it's
* interface or you want to implement
* your own Access lib
* Just create a OPimRecord and inherit from
* the plugins
*/
template <class T = OPimRecord >
class OPimAccessTemplate : public OTemplateBase<T> {
public:
enum Access {
Random = 0,
SortedAccess
};
typedef ORecordList<T> List;
typedef OPimAccessBackend<T> BackEnd;
typedef OPimCache<T> Cache;
/**
* c'tor BackEnd
* enum Access a small hint on how to handle the backend
*/
OPimAccessTemplate( BackEnd* end);
virtual ~OPimAccessTemplate();
/**
* load from the backend
*/
bool load();
/** Reload database.
* You should execute this function if the external database
* was changed.
* This function will load the external database and afterwards
* rejoin the local changes. Therefore the local database will be set consistent.
*/
virtual bool reload();
/** Save contacts database.
* Save is more a "commit". After calling this function, all changes are public available.
* @return true if successful
*/
bool save();
/**
* if the resource was changed externally
* You should use the signal handling instead of polling possible changes !
* zecke: Do you implement a signal for otodoaccess ?
*/
bool wasChangedExternally()const;
/**
* return a List of records
* you can iterate over them
*/
virtual List allRecords()const;
+
+ /**
+ * return a List of records
+ * that match the regex
+ */
+ virtual List matchRegexp( const QRegExp &r ) const;
/**
* queryByExample.
* @see otodoaccess, ocontactaccess
*/
virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
/**
* find the OPimRecord uid
*/
virtual T find( int uid )const;
/**
* read ahead cache find method ;)
*/
virtual T find( int uid, const QArray<int>&,
uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
/* invalidate cache here */
/**
* clears the backend and invalidates the backend
*/
void clear() ;
/**
* add T to the backend
* @param t The item to add.
* @return <i>true</i> if added successfully.
*/
virtual bool add( const T& t ) ;
bool add( const OPimRecord& );
/* only the uid matters */
/**
* remove T from the backend
* @param t The item to remove
* @return <i>true</i> if successful.
*/
virtual bool remove( const T& t );
/**
* remove the OPimRecord with uid
* @param uid The ID of the item to remove
* @return <i>true</i> if successful.
*/
bool remove( int uid );
bool remove( const OPimRecord& );
/**
* replace T from backend
* @param t The item to replace
* @return <i>true</i> if successful.
*/
virtual bool replace( const T& t) ;
void setReadAhead( uint count );
/**
* @internal
*/
void cache( const T& )const;
void setSaneCacheSize( int );
QArray<int> records()const;
protected:
/**
* invalidate the cache
*/
void invalidateCache();
void setBackEnd( BackEnd* end );
/**
* returns the backend
*/
BackEnd* backEnd();
BackEnd* m_backEnd;
Cache m_cache;
};
template <class T>
OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
: OTemplateBase<T>(), m_backEnd( end )
{
if (end )
end->setFrontend( this );
}
template <class T>
OPimAccessTemplate<T>::~OPimAccessTemplate() {
qWarning("~OPimAccessTemplate<T>");
delete m_backEnd;
}
template <class T>
bool OPimAccessTemplate<T>::load() {
invalidateCache();
return m_backEnd->load();
}
template <class T>
bool OPimAccessTemplate<T>::reload() {
invalidateCache(); // zecke: I think this should be added (se)
return m_backEnd->reload();
}
template <class T>
bool OPimAccessTemplate<T>::save() {
return m_backEnd->save();
}
template <class T>
typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
QArray<int> ints = m_backEnd->allRecords();
List lis(ints, this );
return lis;
}
template <class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
+ QArray<int> ints = m_backEnd->matchRegexp( r );
+ List lis(ints, this );
+ return lis;
+}
+template <class T>
QArray<int> OPimAccessTemplate<T>::records()const {
return m_backEnd->allRecords();
}
template <class T>
typename OPimAccessTemplate<T>::List
OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
List lis(ints, this );
return lis;
}
template <class T>
T OPimAccessTemplate<T>::find( int uid ) const{
T t = m_backEnd->find( uid );
cache( t );
return t;
}
template <class T>
T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
uint current, typename OTemplateBase<T>::CacheDirection dir )const {
/*
* better do T.isEmpty()
* after a find this way we would
* avoid two finds in QCache...
*/
// qWarning("find it now %d", uid );
if (m_cache.contains( uid ) ) {
return m_cache.find( uid );
}
T t = m_backEnd->find( uid, ar, current, dir );
cache( t );
return t;
}
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
m_backEnd->clear();
}
template <class T>
bool OPimAccessTemplate<T>::add( const T& t ) {
cache( t );
return m_backEnd->add( t );
}
template <class T>
bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
/* same type */
if ( rec.rtti() == T::rtti() ) {
const T &t = static_cast<const T&>(rec);
return add(t);
}
return false;
}
template <class T>
bool OPimAccessTemplate<T>::remove( const T& t ) {
return remove( t.uid() );
}
template <class T>
bool OPimAccessTemplate<T>::remove( int uid ) {
m_cache.remove( uid );
return m_backEnd->remove( uid );
}
template <class T>
bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
return remove( rec.uid() );
}
template <class T>
bool OPimAccessTemplate<T>::replace( const T& t ) {
m_cache.replace( t );
return m_backEnd->replace( t );
}
template <class T>
void OPimAccessTemplate<T>::invalidateCache() {
m_cache.invalidate();
}
template <class T>
typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
return m_backEnd;
}
template <class T>
bool OPimAccessTemplate<T>::wasChangedExternally()const {
return false;
}
template <class T>
void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
m_backEnd = end;
if (m_backEnd )
m_backEnd->setFrontend( this );
}
template <class T>
void OPimAccessTemplate<T>::cache( const T& t ) const{
/* hacky we need to work around the const*/
((OPimAccessTemplate<T>*)this)->m_cache.add( t );
}
template <class T>
void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
m_cache.setSize( size );
}
template <class T>
void OPimAccessTemplate<T>::setReadAhead( uint count ) {
m_backEnd->setReadAhead( count );
}
#endif
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index c7f9460..de2d9f4 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,134 +1,140 @@
#ifndef OPIE_PIM_RECORD_H
#define OPIE_PIM_RECORD_H
#include <qdatastream.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qpe/palmtoprecord.h>
#include <opie/opimxrefmanager.h>
/**
* This is the base class for
* all PIM Records
*
*/
class OPimRecord : public Qtopia::Record {
public:
/**
* c'tor
* uid of 0 isEmpty
* uid of 1 will be assigned a new one
*/
OPimRecord(int uid = 0);
~OPimRecord();
/**
* copy c'tor
*/
OPimRecord( const OPimRecord& rec );
/**
* copy operator
*/
OPimRecord &operator=( const OPimRecord& );
/**
* category names resolved
*/
QStringList categoryNames( const QString& appname )const;
/**
* set category names they will be resolved
*/
void setCategoryNames( const QStringList& );
/**
* addCategoryName adds a name
* to the internal category list
*/
void addCategoryName( const QString& );
/**
* if a Record isEmpty
* it's empty if it's 0
*/
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;
/**
+ * matches the Records the regular expression?
+ */
+ virtual bool match( const QString &regexp ) const {return match(QRegExp(regexp));};
+ virtual bool match( const QRegExp &regexp ) 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;
/**
* returns a reference of the
* Cross Reference Manager
* Partner 'One' is THIS PIM RECORD!
* 'Two' is the Partner where we link to
*/
OPimXRefManager& xrefmanager();
/**
* set the uid
*/
virtual void setUid( int uid );
/*
* used inside the Templates for casting
* REIMPLEMENT in your ....
*/
static int rtti();
/**
* some marshalling and de marshalling code
* saves the OPimRecord
* to and from a DataStream
*/
virtual bool loadFromStream(QDataStream& );
virtual bool saveToStream( QDataStream& stream )const;
protected:
Qtopia::UidGen &uidGen();
// QString crossToString()const;
private:
class OPimRecordPrivate;
OPimRecordPrivate *d;
OPimXRefManager m_xrefman;
static Qtopia::UidGen m_uidGen;
private:
void flush( const OPimXRefPartner&, QDataStream& stream )const;
OPimXRefPartner partner( QDataStream& );
};
#endif
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index 96a5f65..a38b62b 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,1146 +1,1137 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de)
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#define QTOPIA_INTERNAL_CONTACT_MRE
#include "ocontact.h"
#include "opimresolver.h"
#include <qpe/stringutil.h>
#include "oconversion.h"
#include <qpe/timestring.h>
#include <qobject.h>
#include <qregexp.h>
#include <qstylesheet.h>
#include <qfileinfo.h>
#include <qmap.h>
#include <stdio.h>
/*!
\class Contact contact.h
\brief The Contact class holds the data of an address book entry.
This data includes information the name of the person, contact
information, and business information such as deparment and job title.
\ingroup qtopiaemb
\ingroup qtopiadesktop
*/
/*!
Creates a new, empty contact.
*/
OContact::OContact()
: OPimRecord(), mMap(), d( 0 )
{
}
/*!
\internal
Creates a new contact. The properties of the contact are
set from \a fromMap.
*/
OContact::OContact( const QMap<int, QString> &fromMap ) :
OPimRecord(), mMap( fromMap ), d( 0 )
{
QString cats = mMap[ Qtopia::AddressCategory ];
if ( !cats.isEmpty() )
setCategories( idsFromString( cats ) );
QString uidStr = find( Qtopia::AddressUid );
if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
qWarning( "Invalid UID found. Generate new one.." );
setUid( uidGen().generate() );
}else
setUid( uidStr.toInt() );
// if ( !uidStr.isEmpty() )
// setUid( uidStr.toInt() );
}
/*!
Destroys a contact.
*/
OContact::~OContact()
{
}
/*! \fn void OContact::setTitle( const QString &str )
Sets the title of the contact to \a str.
*/
/*! \fn void OContact::setFirstName( const QString &str )
Sets the first name of the contact to \a str.
*/
/*! \fn void OContact::setMiddleName( const QString &str )
Sets the middle name of the contact to \a str.
*/
/*! \fn void OContact::setLastName( const QString &str )
Sets the last name of the contact to \a str.
*/
/*! \fn void OContact::setSuffix( const QString &str )
Sets the suffix of the contact to \a str.
*/
/*! \fn void OContact::setFileAs( const QString &str )
Sets the contact to filed as \a str.
*/
/*! \fn void OContact::setDefaultEmail( const QString &str )
Sets the default email of the contact to \a str.
*/
/*! \fn void OContact::setHomeStreet( const QString &str )
Sets the home street address of the contact to \a str.
*/
/*! \fn void OContact::setHomeCity( const QString &str )
Sets the home city of the contact to \a str.
*/
/*! \fn void OContact::setHomeState( const QString &str )
Sets the home state of the contact to \a str.
*/
/*! \fn void OContact::setHomeZip( const QString &str )
Sets the home zip code of the contact to \a str.
*/
/*! \fn void OContact::setHomeCountry( const QString &str )
Sets the home country of the contact to \a str.
*/
/*! \fn void OContact::setHomePhone( const QString &str )
Sets the home phone number of the contact to \a str.
*/
/*! \fn void OContact::setHomeFax( const QString &str )
Sets the home fax number of the contact to \a str.
*/
/*! \fn void OContact::setHomeMobile( const QString &str )
Sets the home mobile phone number of the contact to \a str.
*/
/*! \fn void OContact::setHomeWebpage( const QString &str )
Sets the home webpage of the contact to \a str.
*/
/*! \fn void OContact::setCompany( const QString &str )
Sets the company for contact to \a str.
*/
/*! \fn void OContact::setJobTitle( const QString &str )
Sets the job title of the contact to \a str.
*/
/*! \fn void OContact::setDepartment( const QString &str )
Sets the department for contact to \a str.
*/
/*! \fn void OContact::setOffice( const QString &str )
Sets the office for contact to \a str.
*/
/*! \fn void OContact::setBusinessStreet( const QString &str )
Sets the business street address of the contact to \a str.
*/
/*! \fn void OContact::setBusinessCity( const QString &str )
Sets the business city of the contact to \a str.
*/
/*! \fn void OContact::setBusinessState( const QString &str )
Sets the business state of the contact to \a str.
*/
/*! \fn void OContact::setBusinessZip( const QString &str )
Sets the business zip code of the contact to \a str.
*/
/*! \fn void OContact::setBusinessCountry( const QString &str )
Sets the business country of the contact to \a str.
*/
/*! \fn void OContact::setBusinessPhone( const QString &str )
Sets the business phone number of the contact to \a str.
*/
/*! \fn void OContact::setBusinessFax( const QString &str )
Sets the business fax number of the contact to \a str.
*/
/*! \fn void OContact::setBusinessMobile( const QString &str )
Sets the business mobile phone number of the contact to \a str.
*/
/*! \fn void OContact::setBusinessPager( const QString &str )
Sets the business pager number of the contact to \a str.
*/
/*! \fn void OContact::setBusinessWebpage( const QString &str )
Sets the business webpage of the contact to \a str.
*/
/*! \fn void OContact::setProfession( const QString &str )
Sets the profession of the contact to \a str.
*/
/*! \fn void OContact::setAssistant( const QString &str )
Sets the assistant of the contact to \a str.
*/
/*! \fn void OContact::setManager( const QString &str )
Sets the manager of the contact to \a str.
*/
/*! \fn void OContact::setSpouse( const QString &str )
Sets the spouse of the contact to \a str.
*/
/*! \fn void OContact::setGender( const QString &str )
Sets the gender of the contact to \a str.
*/
/*! \fn void OContact::setNickname( const QString &str )
Sets the nickname of the contact to \a str.
*/
/*! \fn void OContact::setNotes( const QString &str )
Sets the notes about the contact to \a str.
*/
/*! \fn QString OContact::title() const
Returns the title of the contact.
*/
/*! \fn QString OContact::firstName() const
Returns the first name of the contact.
*/
/*! \fn QString OContact::middleName() const
Returns the middle name of the contact.
*/
/*! \fn QString OContact::lastName() const
Returns the last name of the contact.
*/
/*! \fn QString OContact::suffix() const
Returns the suffix of the contact.
*/
/*! \fn QString OContact::fileAs() const
Returns the string the contact is filed as.
*/
/*! \fn QString OContact::defaultEmail() const
Returns the default email address of the contact.
*/
/*! \fn QString OContact::emails() const
Returns the list of email address for a contact separated by ';'s in a single
string.
*/
/*! \fn QString OContact::homeStreet() const
Returns the home street address of the contact.
*/
/*! \fn QString OContact::homeCity() const
Returns the home city of the contact.
*/
/*! \fn QString OContact::homeState() const
Returns the home state of the contact.
*/
/*! \fn QString OContact::homeZip() const
Returns the home zip of the contact.
*/
/*! \fn QString OContact::homeCountry() const
Returns the home country of the contact.
*/
/*! \fn QString OContact::homePhone() const
Returns the home phone number of the contact.
*/
/*! \fn QString OContact::homeFax() const
Returns the home fax number of the contact.
*/
/*! \fn QString OContact::homeMobile() const
Returns the home mobile number of the contact.
*/
/*! \fn QString OContact::homeWebpage() const
Returns the home webpage of the contact.
*/
/*! \fn QString OContact::company() const
Returns the company for the contact.
*/
/*! \fn QString OContact::department() const
Returns the department for the contact.
*/
/*! \fn QString OContact::office() const
Returns the office for the contact.
*/
/*! \fn QString OContact::jobTitle() const
Returns the job title of the contact.
*/
/*! \fn QString OContact::profession() const
Returns the profession of the contact.
*/
/*! \fn QString OContact::assistant() const
Returns the assistant of the contact.
*/
/*! \fn QString OContact::manager() const
Returns the manager of the contact.
*/
/*! \fn QString OContact::businessStreet() const
Returns the business street address of the contact.
*/
/*! \fn QString OContact::businessCity() const
Returns the business city of the contact.
*/
/*! \fn QString OContact::businessState() const
Returns the business state of the contact.
*/
/*! \fn QString OContact::businessZip() const
Returns the business zip of the contact.
*/
/*! \fn QString OContact::businessCountry() const
Returns the business country of the contact.
*/
/*! \fn QString OContact::businessPhone() const
Returns the business phone number of the contact.
*/
/*! \fn QString OContact::businessFax() const
Returns the business fax number of the contact.
*/
/*! \fn QString OContact::businessMobile() const
Returns the business mobile number of the contact.
*/
/*! \fn QString OContact::businessPager() const
Returns the business pager number of the contact.
*/
/*! \fn QString OContact::businessWebpage() const
Returns the business webpage of the contact.
*/
/*! \fn QString OContact::spouse() const
Returns the spouse of the contact.
*/
/*! \fn QString OContact::gender() const
Returns the gender of the contact.
*/
/*! \fn QString OContact::nickname() const
Returns the nickname of the contact.
*/
/*! \fn QString OContact::children() const
Returns the children of the contact.
*/
/*! \fn QString OContact::notes() const
Returns the notes relating to the the contact.
*/
/*! \fn QString OContact::groups() const
\internal
Returns the groups for the contact.
*/
/*! \fn QStringList OContact::groupList() const
\internal
*/
/*! \fn QString OContact::field(int) const
\internal
*/
/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null )
\internal
*/
/*! \fn void OContact::setUid( int id )
\internal
Sets the uid for this record to \a id.
*/
/*! \enum OContact::journal_action
\internal
*/
/*!
\internal
*/
QMap<int, QString> OContact::toMap() const
{
QMap<int, QString> map = mMap;
QString cats = idsToString( categories() );
if ( !cats.isEmpty() )
map.insert( Qtopia::AddressCategory, cats );
return map;
}
/*!
Returns a rich text formatted QString representing the contents the contact.
*/
QString OContact::toRichText() const
{
QString text;
QString value, comp, state;
QString str;
bool marker = false;
// name, jobtitle and company
if ( !(value = fullName()).isEmpty() )
text += "<b><h3>" + Qtopia::escapeString(value) + "</h3></b><br>";
if ( !(value = jobTitle()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
comp = company();
if ( !(value = department()).isEmpty() ) {
text += Qtopia::escapeString(value);
if ( comp )
text += ", ";
else
text += "<br>";
}
if ( !comp.isEmpty() )
text += Qtopia::escapeString(comp) + "<br>";
QString defEmail = defaultEmail();
if ( !defEmail.isEmpty() )
text += "<b>" + QObject::tr("Default Email: ") + "</b>"
+ Qtopia::escapeString(defEmail) + "<br>";
text += "<hr>";
// business address
if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
!businessZip().isEmpty() || !businessCountry().isEmpty() ) {
text += "<br>";
text += QObject::tr( "<b>Work Address:</b>" );
text += "<br>";
marker = true;
}
if ( !(value = businessStreet()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
state = businessState();
if ( !(value = businessZip()).isEmpty() )
text += Qtopia::escapeString(value) + " ";
if ( !(value = businessCity()).isEmpty() ) {
text += Qtopia::escapeString(value);
if ( state )
text += ", " + Qtopia::escapeString(state);
text += "<br>";
} else if ( !state.isEmpty() )
text += Qtopia::escapeString(state) + "<br>";
if ( !(value = businessCountry()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
// rest of Business data
str = office();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Office: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = businessWebpage();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Business Web Page: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = businessPhone();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Business Phone: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = businessFax();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Business Fax: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = businessMobile();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Business Mobile: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = businessPager();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
// home address
if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
!homeZip().isEmpty() || !homeCountry().isEmpty() ) {
text += "<br>";
text += QObject::tr( "<b>Home Address:</b>" );
text += "<br>";
}
if ( !(value = homeStreet()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
state = homeState();
if ( !(value = homeZip()).isEmpty() )
text += Qtopia::escapeString(value) + " ";
if ( !(value = homeCity()).isEmpty() ) {
text += Qtopia::escapeString(value);
if ( !state.isEmpty() )
text += ", " + Qtopia::escapeString(state);
text += "<br>";
} else if (!state.isEmpty())
text += Qtopia::escapeString(state) + "<br>";
if ( !(value = homeCountry()).isEmpty() )
text += Qtopia::escapeString(value) + "<br>";
// rest of Home data
str = homeWebpage();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Home Web Page: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = homePhone();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Home Phone: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = homeFax();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Home Fax: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
str = homeMobile();
if ( !str.isEmpty() ){
text += "<b>" + QObject::tr("Home Mobile: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
marker = true;
}
if ( marker )
text += "<br><hr><br>";
// the others...
str = emails();
if ( !str.isEmpty() && ( str != defEmail ) )
text += "<b>" + QObject::tr("All Emails: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = profession();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Profession: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = assistant();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Assistant: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = manager();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Manager: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = gender();
if ( !str.isEmpty() && str.toInt() != 0 ) {
if ( str.toInt() == 1 )
str = QObject::tr( "Male" );
else if ( str.toInt() == 2 )
str = QObject::tr( "Female" );
text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
}
str = spouse();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Spouse: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
if ( birthday().isValid() ){
str = TimeString::numberDateString( birthday() );
text += "<b>" + QObject::tr("Birthday: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
}
if ( anniversary().isValid() ){
str = TimeString::numberDateString( anniversary() );
text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
}
str = children();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Children: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
str = nickname();
if ( !str.isEmpty() )
text += "<b>" + QObject::tr("Nickname: ") + "</b>"
+ Qtopia::escapeString(str) + "<br>";
if ( categoryNames("Contacts").count() ){
text += "<b>" + QObject::tr( "Category:") + "</b> ";
text += categoryNames("Contacts").join(", ");
text += "<br>";
}
// notes last
if ( !(value = notes()).isEmpty() ) {
text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> ";
QRegExp reg("\n");
//QString tmp = Qtopia::escapeString(value);
QString tmp = QStyleSheet::convertFromPlainText(value);
//tmp.replace( reg, "<br>" );
text += "<br>" + tmp + "<br>";
}
return text;
}
/*!
\internal
*/
void OContact::insert( int key, const QString &v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.insert( key, value );
}
/*!
\internal
*/
void OContact::replace( int key, const QString & v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.replace( key, value );
}
/*!
\internal
*/
QString OContact::find( int key ) const
{
return mMap[key];
}
/*!
\internal
*/
QString OContact::displayAddress( const QString &street,
const QString &city,
const QString &state,
const QString &zip,
const QString &country ) const
{
QString s = street;
if ( !street.isEmpty() )
s+= "\n";
s += city;
if ( !city.isEmpty() && !state.isEmpty() )
s += ", ";
s += state;
if ( !state.isEmpty() && !zip.isEmpty() )
s += " ";
s += zip;
if ( !country.isEmpty() && !s.isEmpty() )
s += "\n";
s += country;
return s;
}
/*!
\internal
*/
QString OContact::displayBusinessAddress() const
{
return displayAddress( businessStreet(), businessCity(),
businessState(), businessZip(),
businessCountry() );
}
/*!
\internal
*/
QString OContact::displayHomeAddress() const
{
return displayAddress( homeStreet(), homeCity(),
homeState(), homeZip(),
homeCountry() );
}
/*!
Returns the full name of the contact
*/
QString OContact::fullName() const
{
QString title = find( Qtopia::Title );
QString firstName = find( Qtopia::FirstName );
QString middleName = find( Qtopia::MiddleName );
QString lastName = find( Qtopia::LastName );
QString suffix = find( Qtopia::Suffix );
QString name = title;
if ( !firstName.isEmpty() ) {
if ( !name.isEmpty() )
name += " ";
name += firstName;
}
if ( !middleName.isEmpty() ) {
if ( !name.isEmpty() )
name += " ";
name += middleName;
}
if ( !lastName.isEmpty() ) {
if ( !name.isEmpty() )
name += " ";
name += lastName;
}
if ( !suffix.isEmpty() ) {
if ( !name.isEmpty() )
name += " ";
name += suffix;
}
return name.simplifyWhiteSpace();
}
/*!
Returns a list of the names of the children of the contact.
*/
QStringList OContact::childrenList() const
{
return QStringList::split( " ", find( Qtopia::Children ) );
}
/*! \fn void OContact::insertEmail( const QString &email )
Insert \a email into the email list. Ensures \a email can only be added
once. If there is no default email address set, it sets it to the \a email.
*/
/*! \fn void OContact::removeEmail( const QString &email )
Removes the \a email from the email list. If the default email was \a email,
then the default email address is assigned to the first email in the
email list
*/
/*! \fn void OContact::clearEmails()
Clears the email list.
*/
/*! \fn void OContact::insertEmails( const QStringList &emailList )
Appends the \a emailList to the exiting email list
*/
/*!
Returns a list of email addresses belonging to the contact, including
the default email address.
*/
QStringList OContact::emailList() const
{
QString emailStr = emails();
QStringList r;
if ( !emailStr.isEmpty() ) {
qDebug(" emailstr ");
QStringList l = QStringList::split( emailSeparator(), emailStr );
for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
r += (*it).simplifyWhiteSpace();
}
return r;
}
/*!
\overload
Generates the string for the contact to be filed as from the first,
middle and last name of the contact.
*/
void OContact::setFileAs()
{
QString lastName, firstName, middleName, fileas;
lastName = find( Qtopia::LastName );
firstName = find( Qtopia::FirstName );
middleName = find( Qtopia::MiddleName );
if ( !lastName.isEmpty() && !firstName.isEmpty()
&& !middleName.isEmpty() )
fileas = lastName + ", " + firstName + " " + middleName;
else if ( !lastName.isEmpty() && !firstName.isEmpty() )
fileas = lastName + ", " + firstName;
else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
!middleName.isEmpty() )
fileas = firstName + ( firstName.isEmpty() ? "" : " " )
+ middleName + ( middleName.isEmpty() ? "" : " " )
+ lastName;
replace( Qtopia::FileAs, fileas );
}
/*!
\internal
Appends the contact information to \a buf.
*/
void OContact::save( QString &buf ) const
{
static const QStringList SLFIELDS = fields();
// I'm expecting "<Contact " in front of this...
for ( QMap<int, QString>::ConstIterator it = mMap.begin();
it != mMap.end(); ++it ) {
const QString &value = it.data();
int key = it.key();
if ( !value.isEmpty() ) {
if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
continue;
key -= Qtopia::AddressCategory+1;
buf += SLFIELDS[key];
buf += "=\"" + Qtopia::escapeString(value) + "\" ";
}
}
buf += customToXml();
if ( categories().count() > 0 )
buf += "Categories=\"" + idsToString( categories() ) + "\" ";
buf += "Uid=\"" + QString::number( uid() ) + "\" ";
// You need to close this yourself
}
/*!
\internal
Returns the list of fields belonging to a contact
Never change order of this list ! It has to be regarding
enum AddressBookFields !!
*/
QStringList OContact::fields()
{
QStringList list;
list.append( "Title" ); // Not Used!
list.append( "FirstName" );
list.append( "MiddleName" );
list.append( "LastName" );
list.append( "Suffix" );
list.append( "FileAs" );
list.append( "JobTitle" );
list.append( "Department" );
list.append( "Company" );
list.append( "BusinessPhone" );
list.append( "BusinessFax" );
list.append( "BusinessMobile" );
list.append( "DefaultEmail" );
list.append( "Emails" );
list.append( "HomePhone" );
list.append( "HomeFax" );
list.append( "HomeMobile" );
list.append( "BusinessStreet" );
list.append( "BusinessCity" );
list.append( "BusinessState" );
list.append( "BusinessZip" );
list.append( "BusinessCountry" );
list.append( "BusinessPager" );
list.append( "BusinessWebPage" );
list.append( "Office" );
list.append( "Profession" );
list.append( "Assistant" );
list.append( "Manager" );
list.append( "HomeStreet" );
list.append( "HomeCity" );
list.append( "HomeState" );
list.append( "HomeZip" );
list.append( "HomeCountry" );
list.append( "HomeWebPage" );
list.append( "Spouse" );
list.append( "Gender" );
list.append( "Birthday" );
list.append( "Anniversary" );
list.append( "Nickname" );
list.append( "Children" );
list.append( "Notes" );
list.append( "Groups" );
return list;
}
/*!
Sets the list of email address for contact to those contained in \a str.
Email address should be separated by ';'s.
*/
void OContact::setEmails( const QString &str )
{
replace( Qtopia::Emails, str );
if ( str.isEmpty() )
setDefaultEmail( QString::null );
}
/*!
Sets the list of children for the contact to those contained in \a str.
*/
void OContact::setChildren( const QString &str )
{
replace( Qtopia::Children, str );
}
/*!
- Returns TRUE if the contact matches the regular expression \a regexp.
- Otherwise returns FALSE.
-*/
-bool OContact::match( const QString &regexp ) const
-{
- return match(QRegExp(regexp));
-}
-
-/*!
\overload
Returns TRUE if the contact matches the regular expression \a regexp.
Otherwise returns FALSE.
*/
bool OContact::match( const QRegExp &r ) const
{
bool match;
match = false;
QMap<int, QString>::ConstIterator it;
for ( it = mMap.begin(); it != mMap.end(); ++it ) {
if ( (*it).find( r ) > -1 ) {
match = true;
break;
}
}
return match;
}
QString OContact::toShortText() const
{
return ( fullName() );
}
QString OContact::type() const
{
return QString::fromLatin1( "OContact" );
}
// Definition is missing ! (se)
QMap<QString,QString> OContact::toExtraMap() const
{
qWarning ("Function not implemented: OContact::toExtraMap()");
QMap <QString,QString> useless;
return useless;
}
class QString OContact::recordField( int pos ) const
{
QStringList SLFIELDS = fields(); // ?? why this ? (se)
return SLFIELDS[pos];
}
// In future releases, we should store birthday and anniversary
// internally as QDate instead of QString !
// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
/*! \fn void OContact::setBirthday( const QDate& date )
Sets the birthday for the contact to \a date. If date is null
the current stored date will be removed.
*/
void OContact::setBirthday( const QDate &v )
{
if ( v.isNull() ){
qWarning( "Remove Birthday");
replace( Qtopia::Birthday, QString::null );
return;
}
if ( v.isValid() )
replace( Qtopia::Birthday, OConversion::dateToString( v ) );
}
/*! \fn void OContact::setAnniversary( const QDate &date )
Sets the anniversary of the contact to \a date. If date is
null, the current stored date will be removed.
*/
void OContact::setAnniversary( const QDate &v )
{
if ( v.isNull() ){
qWarning( "Remove Anniversary");
replace( Qtopia::Anniversary, QString::null );
return;
}
if ( v.isValid() )
replace( Qtopia::Anniversary, OConversion::dateToString( v ) );
}
/*! \fn QDate OContact::birthday() const
Returns the birthday of the contact.
*/
QDate OContact::birthday() const
{
QString str = find( Qtopia::Birthday );
qWarning ("Birthday %s", str.latin1() );
if ( !str.isEmpty() )
return OConversion::dateFromString ( str );
else
return QDate();
}
/*! \fn QDate OContact::anniversary() const
Returns the anniversary of the contact.
*/
QDate OContact::anniversary() const
{
QDate empty;
QString str = find( Qtopia::Anniversary );
qWarning ("Anniversary %s", str.latin1() );
if ( !str.isEmpty() )
return OConversion::dateFromString ( str );
else
return empty;
}
void OContact::insertEmail( const QString &v )
{
//qDebug("insertEmail %s", v.latin1());
QString e = v.simplifyWhiteSpace();
QString def = defaultEmail();
// if no default, set it as the default email and don't insert
if ( def.isEmpty() ) {
setDefaultEmail( e ); // will insert into the list for us
return;
}
// otherwise, insert assuming doesn't already exist
QString emailsStr = find( Qtopia::Emails );
if ( emailsStr.contains( e ))
return;
if ( !emailsStr.isEmpty() )
emailsStr += emailSeparator();
emailsStr += e;
replace( Qtopia::Emails, emailsStr );
}
void OContact::removeEmail( const QString &v )
{
QString e = v.simplifyWhiteSpace();
QString def = defaultEmail();
QString emailsStr = find( Qtopia::Emails );
QStringList emails = emailList();
// otherwise, must first contain it
if ( !emailsStr.contains( e ) )
return;
// remove it
//qDebug(" removing email from list %s", e.latin1());
emails.remove( e );
// reset the string
emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
replace( Qtopia::Emails, emailsStr );
// if default, then replace the default email with the first one
if ( def == e ) {
//qDebug("removeEmail is default; setting new default");
if ( !emails.count() )
clearEmails();
else // setDefaultEmail will remove e from the list
setDefaultEmail( emails.first() );
}
}
void OContact::clearEmails()
{
mMap.remove( Qtopia::DefaultEmail );
mMap.remove( Qtopia::Emails );
}
void OContact::setDefaultEmail( const QString &v )
{
QString e = v.simplifyWhiteSpace();
//qDebug("OContact::setDefaultEmail %s", e.latin1());
replace( Qtopia::DefaultEmail, e );
if ( !e.isEmpty() )
insertEmail( e );
}
void OContact::insertEmails( const QStringList &v )
{
for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
insertEmail( *it );
}
int OContact::rtti() {
return OPimResolver::AddressBook;
}
void OContact::setUid( int i )
{
OPimRecord::setUid(i);
replace( Qtopia::AddressUid , QString::number(i));
}
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index 50f6176..0e6cbd2 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -1,242 +1,241 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de)
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __OCONTACT_H__
#define __OCONTACT_H__
#include <opie/opimrecord.h>
#include <qpe/recordfields.h>
#include <qdatetime.h>
#include <qstringlist.h>
#if defined(QPC_TEMPLATEDLL)
// MOC_SKIP_BEGIN
QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
// MOC_SKIP_END
#endif
class ContactPrivate;
/**
* OContact class represents a specialised PIM Record for contacts.
* It does store all kind of persopn related information.
*
* @short Contact Container
* @author TT, Stefan Eiler, Holger Freyther
*/
class QPC_EXPORT OContact : public OPimRecord
{
friend class DataSet;
public:
OContact();
OContact( const QMap<int, QString> &fromMap );
virtual ~OContact();
/*
* do we need to inline them
* if yes do we need to inline them this way?
* -zecke
*/
void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
void setFileAs();
// default email address
void setDefaultEmail( const QString &v );
// inserts email to list and ensure's doesn't already exist
void insertEmail( const QString &v );
void removeEmail( const QString &v );
void clearEmails();
void insertEmails( const QStringList &v );
// home
void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
// business
void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
// personal
void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
void setBirthday( const QDate &v );
void setAnniversary( const QDate &v );
void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
void setChildren( const QString &v );
// other
void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
- bool match( const QString &regexp ) const;
- bool match( const QRegExp &regexp ) const;
+ virtual bool match( const QRegExp &regexp ) const;
// // custom
// void setCustomField( const QString &key, const QString &v )
// { replace(Custom- + key, v ); }
// name
QString fullName() const;
QString title() const { return find( Qtopia::Title ); }
QString firstName() const { return find( Qtopia::FirstName ); }
QString middleName() const { return find( Qtopia::MiddleName ); }
QString lastName() const { return find( Qtopia::LastName ); }
QString suffix() const { return find( Qtopia::Suffix ); }
QString fileAs() const { return find( Qtopia::FileAs ); }
// email
QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
QStringList emailList() const;
// home
/*
* OPimAddress address(enum Location)const;
* would be some how nicer...
* -zecke
*/
QString homeStreet() const { return find( Qtopia::HomeStreet ); }
QString homeCity() const { return find( Qtopia::HomeCity ); }
QString homeState() const { return find( Qtopia::HomeState ); }
QString homeZip() const { return find( Qtopia::HomeZip ); }
QString homeCountry() const { return find( Qtopia::HomeCountry ); }
QString homePhone() const { return find( Qtopia::HomePhone ); }
QString homeFax() const { return find( Qtopia::HomeFax ); }
QString homeMobile() const { return find( Qtopia::HomeMobile ); }
QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
/** Multi line string containing all non-empty address info in the form
* Street
* City, State Zip
* Country
*/
QString displayHomeAddress() const;
// business
QString company() const { return find( Qtopia::Company ); }
QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
QString businessCity() const { return find( Qtopia::BusinessCity ); }
QString businessState() const { return find( Qtopia::BusinessState ); }
QString businessZip() const { return find( Qtopia::BusinessZip ); }
QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
QString jobTitle() const { return find( Qtopia::JobTitle ); }
QString department() const { return find( Qtopia::Department ); }
QString office() const { return find( Qtopia::Office ); }
QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
QString businessFax() const { return find( Qtopia::BusinessFax ); }
QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
QString businessPager() const { return find( Qtopia::BusinessPager ); }
QString profession() const { return find( Qtopia::Profession ); }
QString assistant() const { return find( Qtopia::Assistant ); }
QString manager() const { return find( Qtopia::Manager ); }
/** Multi line string containing all non-empty address info in the form
* Street
* City, State Zip
* Country
*/
QString displayBusinessAddress() const;
//personal
QString spouse() const { return find( Qtopia::Spouse ); }
QString gender() const { return find( Qtopia::Gender ); }
QDate birthday() const;
QDate anniversary() const;
QString nickname() const { return find( Qtopia::Nickname ); }
QString children() const { return find( Qtopia::Children ); }
QStringList childrenList() const;
// other
QString notes() const { return find( Qtopia::Notes ); }
QString groups() const { return find( Qtopia::Groups ); }
QStringList groupList() const;
// // custom
// const QString &customField( const QString &key )
// { return find( Custom- + key ); }
QString toRichText() const;
QMap<int, QString> toMap() const;
QString field( int key ) const { return find( key ); }
void setUid( int i );
QString toShortText()const;
QString OContact::type()const;
QMap<QString,QString> OContact::toExtraMap() const;
class QString OContact::recordField(int) const;
// Why private ? (eilers,se)
QString emailSeparator() const { return " "; }
// the emails should be seperated by a comma
void setEmails( const QString &v );
QString emails() const { return find( Qtopia::Emails ); }
static int rtti();
private:
// The XML-Backend needs some access to the private functions
friend class OContactAccessBackend_XML;
void insert( int key, const QString &value );
void replace( int key, const QString &value );
QString find( int key ) const;
static QStringList fields();
void save( QString &buf ) const;
QString displayAddress( const QString &street,
const QString &city,
const QString &state,
const QString &zip,
const QString &country ) const;
QMap<int, QString> mMap;
ContactPrivate *d;
};
#endif
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index 3ba8a52..28cf873 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,495 +1,526 @@
#include <qshared.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/categories.h>
+#include <qpe/stringutil.h>
#include "orecur.h"
#include "opimresolver.h"
#include "opimnotifymanager.h"
#include "oevent.h"
int OCalendarHelper::week( const QDate& date) {
// Calculates the week this date is in within that
// month. Equals the "row" is is in in the month view
int week = 1;
QDate tmp( date.year(), date.month(), 1 );
if ( date.dayOfWeek() < tmp.dayOfWeek() )
++week;
week += ( date.day() - 1 ) / 7;
return week;
}
int OCalendarHelper::ocurrence( const QDate& date) {
// calculates the number of occurrances of this day of the
// week till the given date (e.g 3rd Wednesday of the month)
return ( date.day() - 1 ) / 7 + 1;
}
int OCalendarHelper::dayOfWeek( char day ) {
int dayOfWeek = 1;
char i = ORecur::MON;
while ( !( i & day ) && i <= ORecur::SUN ) {
i <<= 1;
++dayOfWeek;
}
return dayOfWeek;
}
int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
return ( second.year() - first.year() ) * 12 +
second.month() - first.month();
}
struct OEvent::Data : public QShared {
Data() : QShared() {
child = 0;
recur = 0;
manager = 0;
isAllDay = false;
parent = 0;
}
~Data() {
delete manager;
delete recur;
}
QString description;
QString location;
OPimNotifyManager* manager;
ORecur* recur;
QString note;
QDateTime created;
QDateTime start;
QDateTime end;
bool isAllDay : 1;
QString timezone;
QArray<int>* child;
int parent;
};
OEvent::OEvent( int uid )
: OPimRecord( uid ) {
data = new Data;
}
OEvent::OEvent( const OEvent& ev)
: OPimRecord( ev ), data( ev.data )
{
data->ref();
}
OEvent::~OEvent() {
if ( data->deref() ) {
delete data;
data = 0;
}
}
OEvent& OEvent::operator=( const OEvent& ev) {
if ( this == &ev ) return *this;
OPimRecord::operator=( ev );
ev.data->ref();
deref();
data = ev.data;
return *this;
}
QString OEvent::description()const {
return data->description;
}
void OEvent::setDescription( const QString& description ) {
changeOrModify();
data->description = description;
}
void OEvent::setLocation( const QString& loc ) {
changeOrModify();
data->location = loc;
}
QString OEvent::location()const {
return data->location;
}
OPimNotifyManager &OEvent::notifiers()const {
// I hope we can skip the changeOrModify here
// the notifier should take care of it
// and OPimNotify is shared too
if (!data->manager )
data->manager = new OPimNotifyManager;
return *data->manager;
}
bool OEvent::hasNotifiers()const {
if (!data->manager )
return false;
if (data->manager->reminders().isEmpty() &&
data->manager->alarms().isEmpty() )
return false;
return true;
}
ORecur OEvent::recurrence()const {
if (!data->recur)
data->recur = new ORecur;
return *data->recur;
}
void OEvent::setRecurrence( const ORecur& rec) {
changeOrModify();
if (data->recur )
(*data->recur) = rec;
else
data->recur = new ORecur( rec );
}
bool OEvent::hasRecurrence()const {
if (!data->recur ) return false;
return data->recur->doesRecur();
}
QString OEvent::note()const {
return data->note;
}
void OEvent::setNote( const QString& note ) {
changeOrModify();
data->note = note;
}
QDateTime OEvent::createdDateTime()const {
return data->created;
}
void OEvent::setCreatedDateTime( const QDateTime& time ) {
changeOrModify();
data->created = time;
}
QDateTime OEvent::startDateTime()const {
if ( data->isAllDay )
return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
return data->start;
}
QDateTime OEvent::startDateTimeInZone()const {
/* if no timezone, or all day event or if the current and this timeZone match... */
if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
OTimeZone zone(data->timezone );
return zone.toDateTime( data->start, OTimeZone::current() );
}
void OEvent::setStartDateTime( const QDateTime& dt ) {
changeOrModify();
data->start = dt;
}
QDateTime OEvent::endDateTime()const {
/*
* if all Day event the end time needs
* to be on the same day as the start
*/
if ( data->isAllDay )
return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
return data->end;
}
QDateTime OEvent::endDateTimeInZone()const {
/* if no timezone, or all day event or if the current and this timeZone match... */
if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
OTimeZone zone(data->timezone );
return zone.toDateTime( data->end, OTimeZone::current() );
}
void OEvent::setEndDateTime( const QDateTime& dt ) {
changeOrModify();
data->end = dt;
}
bool OEvent::isMultipleDay()const {
return data->end.date().day() - data->start.date().day();
}
bool OEvent::isAllDay()const {
return data->isAllDay;
}
void OEvent::setAllDay( bool allDay ) {
changeOrModify();
data->isAllDay = allDay;
if (allDay ) data->timezone = "UTC";
}
void OEvent::setTimeZone( const QString& tz ) {
changeOrModify();
data->timezone = tz;
}
QString OEvent::timeZone()const {
if (data->isAllDay ) return QString::fromLatin1("UTC");
return data->timezone;
}
-bool OEvent::match( const QRegExp& )const {
- // FIXME
+bool OEvent::match( const QRegExp& re )const {
+ if (data->description.contains( re ) )
+ return true;
+ if ( data->note.contains( re ) )
+ return true;
+ if ( data->location.contains( re ) )
+ return true;
+ if ( data->start.toString().contains( re ) )
+ return true;
+ if ( data->end.toString().contains( re ) )
+ return true;
return false;
}
QString OEvent::toRichText()const {
- // FIXME
- return "OEvent test";
+ QString text;
+ if ( !description().isEmpty() ) {
+ text += "<b>" + QObject::tr( "Description:") + "</b><br>";
+ text += Qtopia::escapeString(description() ).
+ replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
+ }
+ if ( startDateTime().isValid() ) {
+ text += "<b>" + QObject::tr( "Start:") + "</b> ";
+ text += Qtopia::escapeString(startDateTime().toString() ).
+ replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
+ }
+ if ( endDateTime().isValid() ) {
+ text += "<b>" + QObject::tr( "End:") + "</b> ";
+ text += Qtopia::escapeString(endDateTime().toString() ).
+ replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
+ }
+ if ( !note().isEmpty() ) {
+ text += "<b>" + QObject::tr( "Note:") + "</b><br>";
+ text += note();
+// text += Qtopia::escapeString(note() ).
+// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
+ }
+ return text;
}
QString OEvent::toShortText()const {
- return "OEvent shotText";
+ return description();
}
QString OEvent::type()const {
return QString::fromLatin1("OEvent");
}
QString OEvent::recordField( int /*id */ )const {
return QString::null;
}
int OEvent::rtti() {
return OPimResolver::DateBook;
}
bool OEvent::loadFromStream( QDataStream& ) {
return true;
}
bool OEvent::saveToStream( QDataStream& )const {
return true;
}
void OEvent::changeOrModify() {
if ( data->count != 1 ) {
data->deref();
Data* d2 = new Data;
d2->description = data->description;
d2->location = data->location;
if (data->manager )
d2->manager = new OPimNotifyManager( *data->manager );
if ( data->recur )
d2->recur = new ORecur( *data->recur );
d2->note = data->note;
d2->created = data->created;
d2->start = data->start;
d2->end = data->end;
d2->isAllDay = data->isAllDay;
d2->timezone = data->timezone;
d2->parent = data->parent;
if ( data->child ) {
d2->child = new QArray<int>( *data->child );
d2->child->detach();
}
data = d2;
}
}
void OEvent::deref() {
if ( data->deref() ) {
delete data;
data = 0;
}
}
// FIXME
QMap<int, QString> OEvent::toMap()const {
return QMap<int, QString>();
}
QMap<QString, QString> OEvent::toExtraMap()const {
return QMap<QString, QString>();
}
int OEvent::parent()const {
return data->parent;
}
void OEvent::setParent( int uid ) {
changeOrModify();
data->parent = uid;
}
QArray<int> OEvent::children() const{
if (!data->child) return QArray<int>();
else
return data->child->copy();
}
void OEvent::setChildren( const QArray<int>& arr ) {
changeOrModify();
if (data->child) delete data->child;
data->child = new QArray<int>( arr );
data->child->detach();
}
void OEvent::addChild( int uid ) {
changeOrModify();
if (!data->child ) {
data->child = new QArray<int>(1);
(*data->child)[0] = uid;
}else{
int count = data->child->count();
data->child->resize( count + 1 );
(*data->child)[count] = uid;
}
}
void OEvent::removeChild( int uid ) {
if (!data->child || !data->child->contains( uid ) ) return;
changeOrModify();
QArray<int> newAr( data->child->count() - 1 );
int j = 0;
uint count = data->child->count();
for ( uint i = 0; i < count; i++ ) {
if ( (*data->child)[i] != uid ) {
newAr[j] = (*data->child)[i];
j++;
}
}
(*data->child) = newAr;
}
struct OEffectiveEvent::Data : public QShared {
Data() : QShared() {
}
OEvent event;
QDate date;
QTime start, end;
QDate startDate, endDate;
bool dates : 1;
};
OEffectiveEvent::OEffectiveEvent() {
data = new Data;
data->date = QDate::currentDate();
data->start = data->end = QTime::currentTime();
data->dates = false;
}
OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
Position pos ) {
data = new Data;
data->event = ev;
data->date = startDate;
if ( pos & Start )
data->start = ev.startDateTime().time();
else
data->start = QTime( 0, 0, 0 );
if ( pos & End )
data->end = ev.endDateTime().time();
else
data->end = QTime( 23, 59, 59 );
data->dates = false;
}
OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
data = ev.data;
data->ref();
}
OEffectiveEvent::~OEffectiveEvent() {
if ( data->deref() ) {
delete data;
data = 0;
}
}
OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
if ( *this == ev ) return *this;
ev.data->ref();
deref();
data = ev.data;
return *this;
}
void OEffectiveEvent::setStartTime( const QTime& ti) {
changeOrModify();
data->start = ti;
}
void OEffectiveEvent::setEndTime( const QTime& en) {
changeOrModify();
data->end = en;
}
void OEffectiveEvent::setEvent( const OEvent& ev) {
changeOrModify();
data->event = ev;
}
void OEffectiveEvent::setDate( const QDate& da) {
changeOrModify();
data->date = da;
}
void OEffectiveEvent::setEffectiveDates( const QDate& from,
const QDate& to ) {
if (!from.isValid() ) {
data->dates = false;
return;
}
data->startDate = from;
data->endDate = to;
}
QString OEffectiveEvent::description()const {
return data->event.description();
}
QString OEffectiveEvent::location()const {
return data->event.location();
}
QString OEffectiveEvent::note()const {
return data->event.note();
}
OEvent OEffectiveEvent::event()const {
return data->event;
}
QTime OEffectiveEvent::startTime()const {
return data->start;
}
QTime OEffectiveEvent::endTime()const {
return data->end;
}
QDate OEffectiveEvent::date()const {
return data->date;
}
int OEffectiveEvent::length()const {
return (data->end.hour() * 60 - data->start.hour() * 60)
+ QABS(data->start.minute() - data->end.minute() );
}
int OEffectiveEvent::size()const {
return ( data->end.hour() - data->start.hour() ) * 3600
+ (data->end.minute() - data->start.minute() * 60
+ data->end.second() - data->start.second() );
}
QDate OEffectiveEvent::startDate()const {
if ( data->dates )
return data->startDate;
else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
return data->date;
else
return data->event.startDateTime().date();
}
QDate OEffectiveEvent::endDate()const {
if ( data->dates )
return data->endDate;
else if ( data->event.hasRecurrence() )
return data->date;
else
return data->event.endDateTime().date();
}
void OEffectiveEvent::deref() {
if ( data->deref() ) {
delete data;
data = 0;
}
}
void OEffectiveEvent::changeOrModify() {
if ( data->count != 1 ) {
data->deref();
Data* d2 = new Data;
d2->event = data->event;
d2->date = data->date;
d2->start = data->start;
d2->end = data->end;
d2->startDate = data->startDate;
d2->endDate = data->endDate;
d2->dates = data->dates;
data = d2;
}
}
bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
if ( data->date < e.date() )
return TRUE;
if ( data->date == e.date() )
return ( startTime() < e.startTime() );
else
return FALSE;
}
bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
return (data->date <= e.date() );
}
bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
return ( date() == e.date()
&& startTime() == e.startTime()
&& endTime()== e.endTime()
&& event() == e.event() );
}
bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
return !(*this == e );
}
bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
return !(*this <= e );
}
bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
return !(*this < e);
}
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h
index 57d32d0..b696d81 100644
--- a/libopie2/opiepim/oevent.h
+++ b/libopie2/opiepim/oevent.h
@@ -1,221 +1,221 @@
// CONTAINS GPLed code of TT
#ifndef OPIE_PIM_EVENT_H
#define OPIE_PIM_EVENT_H
#include <qstring.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include "otimezone.h"
#include "opimrecord.h"
struct OCalendarHelper {
/** calculate the week number of the date */
static int week( const QDate& );
/** calculate the occurence of week days since the start of the month */
static int ocurrence( const QDate& );
// returns the dayOfWeek for the *first* day it finds (ignores
// any further days!). Returns 1 (Monday) if there isn't any day found
static int dayOfWeek( char day );
/** returns the diff of month */
static int monthDiff( const QDate& first, const QDate& second );
};
class OPimNotifyManager;
class ORecur;
/**
* This is the container for all Events. It encapsules all
* available information for a single Event
* @short container for events.
*/
class OEvent : public OPimRecord {
public:
typedef QValueList<OEvent> ValueList;
/**
* RecordFields contain possible attributes
*/
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
Description,
Location,
Alarm,
Reminder,
Recurrence,
Note,
Created,
StartDate,
EndDate,
AllDay,
TimeZone
};
/**
* Start with an Empty OEvent. UID == 0 means that it is empty
*/
OEvent(int uid = 0);
/**
* copy c'tor
*/
OEvent( const OEvent& );
~OEvent();
OEvent &operator=( const OEvent& );
QString description()const;
void setDescription( const QString& description );
QString location()const;
void setLocation( const QString& loc );
bool hasNotifiers()const;
OPimNotifyManager &notifiers()const;
ORecur recurrence()const;
void setRecurrence( const ORecur& );
bool hasRecurrence()const;
QString note()const;
void setNote( const QString& note );
QDateTime createdDateTime()const;
void setCreatedDateTime( const QDateTime& dt);
/** set the date to dt. dt is the QDateTime in localtime */
void setStartDateTime( const QDateTime& );
/** returns the datetime in the local timeZone */
QDateTime startDateTime()const;
/** returns the start datetime in the current zone */
QDateTime startDateTimeInZone()const;
/** in current timezone */
void setEndDateTime( const QDateTime& );
/** in current timezone */
QDateTime endDateTime()const;
QDateTime endDateTimeInZone()const;
bool isMultipleDay()const;
bool isAllDay()const;
void setAllDay( bool isAllDay );
/* pin this event to a timezone! FIXME */
void setTimeZone( const QString& timeZone );
QString timeZone()const;
- bool match( const QRegExp& )const;
+ virtual bool match( const QRegExp& )const;
/** For exception to recurrence here is a list of children... */
QArray<int> children()const;
void setChildren( const QArray<int>& );
void addChild( int uid );
void removeChild( int uid );
/** return the parent OEvent */
int parent()const;
void setParent( int uid );
/* needed reimp */
QString toRichText()const;
QString toShortText()const;
QString type()const;
QMap<int, QString> toMap()const;
QMap<QString, QString> toExtraMap()const;
QString recordField(int )const;
static int rtti();
bool loadFromStream( QDataStream& );
bool saveToStream( QDataStream& )const;
/* bool operator==( const OEvent& );
bool operator!=( const OEvent& );
bool operator<( const OEvent& );
bool operator<=( const OEvent& );
bool operator>( const OEvent& );
bool operator>=(const OEvent& );
*/
private:
inline void changeOrModify();
void deref();
struct Data;
Data* data;
class Private;
Private* priv;
};
/**
* AN Event can span through multiple days. We split up a multiday eve
*/
class OEffectiveEvent {
public:
typedef QValueList<OEffectiveEvent> ValueList;
enum Position { MidWay, Start, End, StartEnd };
// If we calculate the effective event of a multi-day event
// we have to figure out whether we are at the first day,
// at the end, or anywhere else ("middle"). This is important
// for the start/end times (00:00/23:59)
// MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
// day event
// Start: start time -> 23:59
// End: 00:00 -> end time
// Start | End == StartEnd: for single-day events (default)
// here we draw start time -> end time
OEffectiveEvent();
OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd );
OEffectiveEvent( const OEffectiveEvent& );
OEffectiveEvent &operator=(const OEffectiveEvent& );
~OEffectiveEvent();
void setStartTime( const QTime& );
void setEndTime( const QTime& );
void setEvent( const OEvent& );
void setDate( const QDate& );
void setEffectiveDates( const QDate& from, const QDate& to );
QString description()const;
QString location()const;
QString note()const;
OEvent event()const;
QTime startTime()const;
QTime endTime()const;
QDate date()const;
/* return the length in hours */
int length()const;
int size()const;
QDate startDate()const;
QDate endDate()const;
bool operator<( const OEffectiveEvent &e ) const;
bool operator<=( const OEffectiveEvent &e ) const;
bool operator==( const OEffectiveEvent &e ) const;
bool operator!=( const OEffectiveEvent &e ) const;
bool operator>( const OEffectiveEvent &e ) const;
bool operator>= ( const OEffectiveEvent &e ) const;
private:
void deref();
inline void changeOrModify();
class Private;
Private* priv;
struct Data;
Data* data;
};
#endif
diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h
index a58d9aa..0e7c73f 100644
--- a/libopie2/opiepim/otodo.h
+++ b/libopie2/opiepim/otodo.h
@@ -1,289 +1,289 @@
#ifndef OPIE_TODO_EVENT_H
#define OPIE_TODO_EVENT_H
#include <qarray.h>
#include <qmap.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include <opie/opimrecord.h>
class OPimState;
class ORecur;
class OPimMaintainer;
class OPimNotifyManager;
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,
State,
Recurrence,
Alarms,
Reminders,
Notifiers,
Maintainer,
StartDate,
CompletedDate
};
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 = 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;
bool hasStartDate()const;
bool hasCompletedDate()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;
/**
* When did it start?
*/
QDate startDate()const;
/**
* When was it completed?
*/
QDate completedDate()const;
/**
* does it have a state?
*/
bool hasState()const;
/**
* What is the state of this OTodo?
*/
OPimState state()const;
/**
* has recurrence?
*/
bool hasRecurrence()const;
/**
* the recurrance of this
*/
ORecur recurrence()const;
/**
* does this OTodo have a maintainer?
*/
bool hasMaintainer()const;
/**
* the Maintainer of this OTodo
*/
OPimMaintainer maintainer()const;
/**
* The description of the todo
*/
QString description()const;
/**
* A small summary of the todo
*/
QString summary() const;
/**
* @reimplemented
* Return this todoevent in a RichText formatted QString
*/
QString toRichText() const;
bool hasNotifiers()const;
/*
* check if the sharing is still fine!! -zecke
*/
/**
* return a reference to our notifiers...
*/
OPimNotifyManager &notifiers();
/**
* reimplementations
*/
QString type()const;
QString toShortText()const;
QMap<QString, QString> toExtraMap()const;
QString recordField(int id )const;
/**
* toMap puts all data into the map. int relates
* to ToDoEvent RecordFields enum
*/
QMap<int, QString> toMap()const;
/**
* Set if this Todo is completed
*/
void setCompleted(bool completed );
/**
* set if this todo got an end data
*/
void setHasDueDate( bool hasDate );
// FIXME we do not have these for start, completed
// cause we'll use the isNull() of QDate for figuring
// out if it's has a date...
// decide what to do here? -zecke
/**
* Set the priority of the Todo
*/
void setPriority(int priority );
/**
* Set the progress.
*/
void setProgress( ushort progress );
/**
* set the end date
*/
void setDueDate( const QDate& date );
/**
* set the start date
*/
void setStartDate( const QDate& date );
/**
* set the completed date
*/
void setCompletedDate( const QDate& date );
void setRecurrence( const ORecur& );
/**
* set the alarm time
*/
void setAlarmDateTime ( const QDateTime& alarm );
void setDescription(const QString& );
void setSummary(const QString& );
/**
* set the state of a Todo
* @param state State what the todo should take
*/
void setState( const OPimState& state);
/**
* set the Maintainer Mode
*/
void setMaintainer( const OPimMaintainer& );
bool isOverdue();
- bool match( const QRegExp &r )const;
+ virtual bool match( const QRegExp &r )const;
bool operator<(const OTodo &toDoEvent )const;
bool operator<=(const OTodo &toDoEvent )const;
bool operator!=(const OTodo &toDoEvent )const;
bool operator>(const OTodo &toDoEvent )const;
bool operator>=(const OTodo &toDoEvent)const;
bool operator==(const OTodo &toDoEvent )const;
OTodo &operator=(const OTodo &toDoEvent );
static int rtti();
private:
class OTodoPrivate;
struct OTodoData;
void deref();
inline void changeOrModify();
void copy( OTodoData* src, OTodoData* dest );
OTodoPrivate *d;
OTodoData *data;
};
inline bool OTodo::operator!=(const OTodo &toDoEvent )const {
return !(*this == toDoEvent);
}
#endif