-rw-r--r-- | libopie2/opiepim/core/opimnotify.cpp | 219 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotify.h | 21 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.cpp | 120 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.h | 18 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 117 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 28 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 235 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.h | 11 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.cpp | 40 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/oevent.cpp | 534 | ||||
-rw-r--r-- | libopie2/opiepim/oevent.h | 33 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 142 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 294 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.h | 27 |
15 files changed, 1349 insertions, 506 deletions
diff --git a/libopie2/opiepim/core/opimnotify.cpp b/libopie2/opiepim/core/opimnotify.cpp index c61f9da..43858f0 100644 --- a/libopie2/opiepim/core/opimnotify.cpp +++ b/libopie2/opiepim/core/opimnotify.cpp @@ -25,91 +25,138 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qshared.h> -#include <opie2/opimnotify.h> +#include "opimnotify.h" -namespace Opie { +/* QT */ +#include <qshared.h> -struct OPimNotify::Data : public QShared { - Data() : QShared(),dur(-1),parent(0) { +namespace Opie +{ +struct OPimNotify::Data : public QShared +{ + Data() : QShared(), dur( -1 ), parent( 0 ) + { } QDateTime start; int dur; QString application; int parent; }; -OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) { +OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) +{ data = new Data; data->start = start; data->dur = duration; data->parent = parent; } + + OPimNotify::OPimNotify( const OPimNotify& noti) : data( noti.data ) { data->ref(); } -OPimNotify::~OPimNotify() { - if ( data->deref() ) { + + +OPimNotify::~OPimNotify() +{ + if ( data->deref() ) + { delete data; data = 0l; } } -OPimNotify &OPimNotify::operator=( const OPimNotify& noti) { + +OPimNotify &OPimNotify::operator=( const OPimNotify& noti ) +{ noti.data->ref(); deref(); data = noti.data; return *this; } -bool OPimNotify::operator==( const OPimNotify& noti ) { + + +bool OPimNotify::operator==( const OPimNotify& noti ) +{ if ( data == noti.data ) return true; if ( data->dur != noti.data->dur ) return false; if ( data->parent != noti.data->parent ) return false; if ( data->application != noti.data->application ) return false; if ( data->start != noti.data->start ) return false; return true; } -QDateTime OPimNotify::dateTime()const { + + +QDateTime OPimNotify::dateTime() const +{ return data->start; } -QString OPimNotify::service()const { + + +QString OPimNotify::service() const +{ return data->application; } -int OPimNotify::parent()const { + + +int OPimNotify::parent() const +{ return data->parent; } -int OPimNotify::duration()const { + + +int OPimNotify::duration() const +{ return data->dur; } -QDateTime OPimNotify::endTime()const { + + +QDateTime OPimNotify::endTime() const +{ return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) ); } -void OPimNotify::setDateTime( const QDateTime& time ) { + + +void OPimNotify::setDateTime( const QDateTime& time ) +{ copyIntern(); data->start = time; } -void OPimNotify::setDuration( int dur ) { + + +void OPimNotify::setDuration( int dur ) +{ copyIntern(); data->dur = dur; } -void OPimNotify::setParent( int uid ) { + + +void OPimNotify::setParent( int uid ) +{ copyIntern(); data->parent = uid; } -void OPimNotify::setService( const QString& str ) { + + +void OPimNotify::setService( const QString& str ) +{ copyIntern(); data->application = str; } -void OPimNotify::copyIntern() { - if ( data->count != 1 ) { + + +void OPimNotify::copyIntern() +{ + if ( data->count != 1 ) + { data->deref(); Data* dat = new Data; dat->start = data->start; dat->dur = data->dur; @@ -117,40 +164,57 @@ void OPimNotify::copyIntern() { dat->parent = data->parent; data = dat; } } -void OPimNotify::deref() { - if ( data->deref() ) { + + +void OPimNotify::deref() +{ + if ( data->deref() ) + { delete data; data = 0; } } + /***********************************************************/ -struct OPimAlarm::Data : public QShared { - Data() : QShared() { +struct OPimAlarm::Data : public QShared +{ + Data() : QShared() + { sound = 1; } int sound; QString file; }; + + OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent ) : OPimNotify( start, duration, parent ) { data = new Data; data->sound = sound; } + + OPimAlarm::OPimAlarm( const OPimAlarm& al) : OPimNotify(al), data( al.data ) { data->ref(); } -OPimAlarm::~OPimAlarm() { - if ( data->deref() ) { + + +OPimAlarm::~OPimAlarm() +{ + if ( data->deref() ) + { delete data; data = 0l; } } + + OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al) { OPimNotify::operator=( al ); deref(); @@ -160,99 +224,156 @@ OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al) return *this; } -bool OPimAlarm::operator==( const OPimAlarm& al) { + + +bool OPimAlarm::operator==( const OPimAlarm& al ) +{ if ( data->sound != al.data->sound ) return false; else if ( data->sound == Custom && data->file != al.data->file ) return false; return OPimNotify::operator==( al ); } -QString OPimAlarm::type()const { + + +QString OPimAlarm::type() const +{ return QString::fromLatin1("OPimAlarm"); } -int OPimAlarm::sound()const { + + +int OPimAlarm::sound() const +{ return data->sound; } -QString OPimAlarm::file()const { + + +QString OPimAlarm::file() const +{ return data->file; } -void OPimAlarm::setSound( int snd) { + + +void OPimAlarm::setSound( int snd ) +{ copyIntern(); data->sound = snd; } -void OPimAlarm::setFile( const QString& sound ) { + + +void OPimAlarm::setFile( const QString& sound ) +{ copyIntern(); data->file = sound; } -void OPimAlarm::deref() { - if ( data->deref() ) { + + +void OPimAlarm::deref() +{ + if ( data->deref() ) + { delete data; data = 0l; } } -void OPimAlarm::copyIntern() { - if ( data->count != 1 ) { + + +void OPimAlarm::copyIntern() +{ + if ( data->count != 1 ) + { data->deref(); Data *newDat = new Data; newDat->sound = data->sound; newDat->file = data->file; data = newDat; } } + + /************************/ -struct OPimReminder::Data : public QShared { - Data() : QShared(), record( 0) { - } +struct OPimReminder::Data : public QShared +{ + Data() : QShared(), record( 0 ) + {} int record; }; + + OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) : OPimNotify( start, dur, parent ) { data = new Data; data->record = uid; } + + OPimReminder::OPimReminder( const OPimReminder& rem ) : OPimNotify( rem ), data( rem.data ) { data->ref(); } -OPimReminder& OPimReminder::operator=( const OPimReminder& rem) { + + +OPimReminder& OPimReminder::operator=( const OPimReminder& rem ) +{ OPimNotify::operator=(rem ); deref(); rem.data->ref(); data = rem.data; return *this; } -bool OPimReminder::operator==( const OPimReminder& rem) { + + +bool OPimReminder::operator==( const OPimReminder& rem ) +{ if ( data->record != rem.data->record ) return false; return OPimNotify::operator==( rem ); } -QString OPimReminder::type()const { + + +QString OPimReminder::type() const +{ return QString::fromLatin1("OPimReminder"); } -int OPimReminder::recordUid()const { + + +int OPimReminder::recordUid() const +{ return data->record; } -void OPimReminder::setRecordUid( int uid ) { + + +void OPimReminder::setRecordUid( int uid ) +{ copyIntern(); data->record = uid; } -void OPimReminder::deref() { - if ( data->deref() ) { + + +void OPimReminder::deref() +{ + if ( data->deref() ) + { delete data; data = 0l; } } -void OPimReminder::copyIntern() { - if ( data->count != 1 ) { + + +void OPimReminder::copyIntern() +{ + if ( data->count != 1 ) + { Data* da = new Data; da->record = data->record; data = da; } } + } diff --git a/libopie2/opiepim/core/opimnotify.h b/libopie2/opiepim/core/opimnotify.h index fed3970..d0e40ca 100644 --- a/libopie2/opiepim/core/opimnotify.h +++ b/libopie2/opiepim/core/opimnotify.h @@ -25,16 +25,18 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_NOTIFY_H -#define OPIE_PIM_NOTIFY_H +#ifndef OPIMNOTIFY_H +#define OPIMNOTIFY_H + +/* QT */ #include <qdatetime.h> #include <qvaluelist.h> - -namespace Opie { +namespace Opie +{ /** * This is the base class of Notifiers. Possible * notifiers would be Alarms, Reminders * What they share is that they have @@ -46,9 +48,11 @@ namespace Opie { * TALK to eilers: have a class OPimDuration which sets the Duration * given on the Due/Start Date? -zecke * discuss: do we need a uid for the notify? -zecke */ -class OPimNotify { +class OPimNotify +{ + public: typedef QValueList<OPimNotify> ValueList; OPimNotify( const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); OPimNotify( const OPimNotify& ); @@ -99,9 +103,10 @@ private: * An alarm is a sound/mail/buzzer played/send * at a given time to inform about * an Event */ -class OPimAlarm : public OPimNotify { +class OPimAlarm : public OPimNotify +{ public: enum Sound{Loud=1, Silent=0, Custom=2 }; OPimAlarm( int sound = Silent, const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); OPimAlarm( const OPimAlarm& ); @@ -134,11 +139,11 @@ private: * datebook * Note that the returned dateTime() may be not valid. * In these cases one must resolve the uid and get the OEvent */ -class OPimReminder : public OPimNotify { +class OPimReminder : public OPimNotify +{ public: - /** * c'tor of a reminder * @param uid The uid of the Record inside the Datebook * @param start the StartDate invalid for all day... diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index 1771fad..a54d597 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp @@ -25,62 +25,96 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/opimnotifymanager.h> +#include "opimnotifymanager.h" + +/* OPIE */ #include <opie2/oconversion.h> +/* QT */ #include <qstringlist.h> -namespace Opie { +namespace Opie +{ OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) : m_rem( rem ), m_al( al ) {} -OPimNotifyManager::~OPimNotifyManager() { -} + + +OPimNotifyManager::~OPimNotifyManager() +{} + + /* use static_cast and type instead of dynamic... */ -void OPimNotifyManager::add( const OPimNotify& noti) { - if ( noti.type() == QString::fromLatin1("OPimReminder") ) { +void OPimNotifyManager::add( const OPimNotify& noti ) +{ + if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) + { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.append( rem ); - }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { + } + else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) + { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.append( al ); } } -void OPimNotifyManager::remove( const OPimNotify& noti) { - if ( noti.type() == QString::fromLatin1("OPimReminder") ) { + + +void OPimNotifyManager::remove( const OPimNotify& noti ) +{ + if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) + { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); - }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { + } + else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) + { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); } } -void OPimNotifyManager::replace( const OPimNotify& noti) { - if ( noti.type() == QString::fromLatin1("OPimReminder") ) { + + +void OPimNotifyManager::replace( const OPimNotify& noti ) +{ + if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) + { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); m_rem.append( rem ); - }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { + } + else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) + { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); m_al.append( al ); } } -OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { + + +OPimNotifyManager::Reminders OPimNotifyManager::reminders() const +{ return m_rem; } -OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { + + +OPimNotifyManager::Alarms OPimNotifyManager::alarms() const +{ return m_al; } -OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { + + +OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const +{ Alarms::ConstIterator it; found = true; - for ( it = m_al.begin(); it != m_al.end(); ++it ){ + for ( it = m_al.begin(); it != m_al.end(); ++it ) + { if ( (*it).dateTime() == when ) return (*it); } @@ -90,53 +124,67 @@ OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found return empty; } -void OPimNotifyManager::setAlarms( const Alarms& al) { +void OPimNotifyManager::setAlarms( const Alarms& al ) +{ m_al = al; } -void OPimNotifyManager::setReminders( const Reminders& rem) { + + +void OPimNotifyManager::setReminders( const Reminders& rem ) +{ m_rem = rem; } + + /* FIXME!!! */ /** * The idea is to check if the provider for our service * is online * if it is we will use QCOP * if not the Factory to get the backend... * Qtopia1.6 services would be kewl to have here.... */ -void OPimNotifyManager::registerNotify( const OPimNotify& ) { - +void OPimNotifyManager::registerNotify( const OPimNotify& ) +{ } + + /* FIXME!!! */ /** * same as above... * Also implement Url model * have a MainWindow.... */ -void OPimNotifyManager::deregister( const OPimNotify& ) { - +void OPimNotifyManager::deregister( const OPimNotify& ) +{ } -bool OPimNotifyManager::isEmpty()const { + +bool OPimNotifyManager::isEmpty() const +{ qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; else return false; } -// Taken from otodoaccessxml.. + +// Taken from otodoaccessxml.. code duplication bad. any alternative? QString OPimNotifyManager::alarmsToString() const { QString str; OPimNotifyManager::Alarms alarms = m_al; - if ( !alarms.isEmpty() ) { + if ( !alarms.isEmpty() ) + { QStringList als; OPimNotifyManager::Alarms::Iterator it = alarms.begin(); - for ( ; it != alarms.end(); ++it ) { + for ( ; it != alarms.end(); ++it ) + { /* only if time is valid */ - if ( (*it).dateTime().isValid() ) { + if ( ( *it ).dateTime().isValid() ) + { als << OConversion::dateTimeToString( (*it).dateTime() ) + ":" + QString::number( (*it).duration() ) + ":" + QString::number( (*it).sound() ) + ":"; @@ -148,29 +196,35 @@ QString OPimNotifyManager::alarmsToString() const } return str; } + + QString OPimNotifyManager::remindersToString() const { QString str; OPimNotifyManager::Reminders reminders = m_rem; - if (!reminders.isEmpty() ) { + if ( !reminders.isEmpty() ) + { OPimNotifyManager::Reminders::Iterator it = reminders.begin(); QStringList records; - for ( ; it != reminders.end(); ++it ) { + for ( ; it != reminders.end(); ++it ) + { records << QString::number( (*it).recordUid() ); } str = records.join(";"); } return str; } + void OPimNotifyManager::alarmsFromString( const QString& str ) { QStringList als = QStringList::split(";", str ); - for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { + for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) + { QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty qWarning("alarm: %s", alarm.join("___").latin1() ); qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); @@ -179,13 +233,15 @@ void OPimNotifyManager::alarmsFromString( const QString& str ) add( al ); } } + void OPimNotifyManager::remindersFromString( const QString& str ) { QStringList rems = QStringList::split(";", str ); - for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { + for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) + { OPimReminder rem( (*it).toInt() ); add( rem ); } diff --git a/libopie2/opiepim/core/opimnotifymanager.h b/libopie2/opiepim/core/opimnotifymanager.h index 0272e5d..9241ea2 100644 --- a/libopie2/opiepim/core/opimnotifymanager.h +++ b/libopie2/opiepim/core/opimnotifymanager.h @@ -25,20 +25,24 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_NOTIFY_MANAGER_H -#define OPIE_PIM_NOTIFY_MANAGER_H - -#include <qvaluelist.h> +#ifndef OPIMNOTIFYMANAGER_H +#define OPIMNOTIFYMANAGER_H +/* OPIE */ #include <opie2/opimnotify.h> -namespace Opie { +/* QT */ +#include <qvaluelist.h> + +namespace Opie +{ /** * The notify manager keeps track of the Notifiers.... */ -class OPimNotifyManager { +class OPimNotifyManager +{ public: typedef QValueList<OPimReminder> Reminders; typedef QValueList<OPimAlarm> Alarms; OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); @@ -105,10 +109,8 @@ public: * @param str String created by remindersToString() */ void remindersFromString( const QString& str ); - - private: Reminders m_rem; Alarms m_al; diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 72bb372..c603f44 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp @@ -25,69 +25,94 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qarray.h> +#include "opimrecord.h" + +/* OPIE */ #include <qpe/categories.h> #include <qpe/categoryselect.h> -#include <opie2/opimrecord.h> +/* QT */ +#include <qarray.h> -namespace Opie { +namespace Opie +{ Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); OPimRecord::OPimRecord( int uid ) - : Qtopia::Record() { + : Qtopia::Record() +{ m_lastHit = -1; setUid( uid ); } -OPimRecord::~OPimRecord() { -} + + +OPimRecord::~OPimRecord() +{} + + OPimRecord::OPimRecord( const OPimRecord& rec ) : Qtopia::Record( rec ) { (*this) = rec; } -OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { + +OPimRecord &OPimRecord::operator=( const OPimRecord& rec ) +{ if ( this == &rec ) return *this; Qtopia::Record::operator=( rec ); m_xrefman = rec.m_xrefman; m_lastHit = rec.m_lastHit; return *this; } + + /* * category names */ -QStringList OPimRecord::categoryNames( const QString& appname ) const { +QStringList OPimRecord::categoryNames( const QString& appname ) const +{ QStringList list; QArray<int> cats = categories(); Categories catDB; catDB.load( categoryFileName() ); - for (uint i = 0; i < cats.count(); i++ ) { + for ( uint i = 0; i < cats.count(); i++ ) + { list << catDB.label( appname, cats[i] ); } return list; } -void OPimRecord::setCategoryNames( const QStringList& ) { + +void OPimRecord::setCategoryNames( const QStringList& ) +{ } -void OPimRecord::addCategoryName( const QString& ) { + + +void OPimRecord::addCategoryName( const QString& ) +{ Categories catDB; catDB.load( categoryFileName() ); } -bool OPimRecord::isEmpty()const { + + +bool OPimRecord::isEmpty() const +{ return ( uid() == 0 ); } + + /*QString OPimRecord::crossToString()const { QString str; QMap<QString, QArray<int> >::ConstIterator it; for (it = m_relations.begin(); it != m_relations.end(); ++it ) { @@ -101,21 +126,31 @@ bool OPimRecord::isEmpty()const { return str; }*/ /* if uid = 1 assign a new one */ -void OPimRecord::setUid( int uid ) { +void OPimRecord::setUid( int uid ) +{ if ( uid == 1) uid = uidGen().generate(); Qtopia::Record::setUid( uid ); }; -Qtopia::UidGen &OPimRecord::uidGen() { + + +Qtopia::UidGen &OPimRecord::uidGen() +{ return m_uidGen; } -OPimXRefManager &OPimRecord::xrefmanager() { + + +OPimXRefManager &OPimRecord::xrefmanager() +{ return m_xrefman; } -int OPimRecord::rtti(){ + + +int OPimRecord::rtti() +{ return 0; } /** @@ -125,18 +160,20 @@ int OPimRecord::rtti(){ * First read UID * Categories * XRef */ -bool OPimRecord::loadFromStream( QDataStream& stream ) { +bool OPimRecord::loadFromStream( QDataStream& stream ) +{ int Int; uint UInt; stream >> Int; setUid(Int); /** Categories */ stream >> UInt; QArray<int> array(UInt); - for (uint i = 0; i < UInt; i++ ) { + for ( uint i = 0; i < UInt; i++ ) + { stream >> array[i]; } setCategories( array ); @@ -144,24 +181,29 @@ bool OPimRecord::loadFromStream( QDataStream& stream ) { * now we do the X-Ref stuff */ OPimXRef xref; stream >> UInt; - for ( uint i = 0; i < UInt; i++ ) { + for ( uint i = 0; i < UInt; i++ ) + { xref.setPartner( OPimXRef::One, partner( stream ) ); xref.setPartner( OPimXRef::Two, partner( stream ) ); m_xrefman.add( xref ); } return true; } -bool OPimRecord::saveToStream( QDataStream& stream )const { + + +bool OPimRecord::saveToStream( QDataStream& stream ) const +{ /** UIDs */ stream << uid(); /** Categories */ stream << categories().count(); - for ( uint i = 0; i < categories().count(); i++ ) { + for ( uint i = 0; i < categories().count(); i++ ) + { stream << categories()[i]; } /* @@ -169,20 +211,27 @@ bool OPimRecord::saveToStream( QDataStream& stream )const { * then the xrefs */ stream << m_xrefman.list().count(); for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); - it != m_xrefman.list().end(); ++it ) { + it != m_xrefman.list().end(); ++it ) + { flush( (*it).partner( OPimXRef::One), stream ); flush( (*it).partner( OPimXRef::Two), stream ); } return true; } -void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ + + +void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const +{ str << par.service(); str << par.uid(); str << par.field(); } -OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { + + +OPimXRefPartner OPimRecord::partner( QDataStream& stream ) +{ OPimXRefPartner par; QString str; int i; @@ -196,18 +245,30 @@ OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { par.setField( i ); return par; } -void OPimRecord::setLastHitField( int lastHit )const { + + +void OPimRecord::setLastHitField( int lastHit ) const +{ m_lastHit = lastHit; } -int OPimRecord::lastHitField()const{ + + +int OPimRecord::lastHitField() const +{ return m_lastHit; } -QMap<QString, QString> OPimRecord::toExtraMap()const { + + +QMap<QString, QString> OPimRecord::toExtraMap() const +{ return customMap; } -void OPimRecord::setExtraMap( const QMap<QString, QString>& map) { + + +void OPimRecord::setExtraMap( const QMap<QString, QString>& map ) +{ customMap = map; } } diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index 63a3a98..4981a41 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h @@ -25,32 +25,36 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_PIM_RECORD_H -#define OPIE_PIM_RECORD_H -#include <qdatastream.h> -#include <qmap.h> -#include <qstring.h> -#include <qstringlist.h> +#ifndef OPIMRECORD_H +#define OPIMRECORD_H +/* OPIE */ +#include <opie2/opimxrefmanager.h> /* * we need to get customMap which is private... */ #define private protected #include <qpe/palmtoprecord.h> #undef private -#include <opie2/opimxrefmanager.h> +/* QT */ +#include <qdatastream.h> +#include <qmap.h> +#include <qstring.h> +#include <qstringlist.h> -namespace Opie { +namespace Opie +{ /** * This is the base class for * all PIM Records * */ -class OPimRecord : public Qtopia::Record { +class OPimRecord : public Qtopia::Record +{ public: /** * c'tor * uid of 0 isEmpty @@ -109,10 +113,12 @@ public: /** * matches the Records the regular expression? */ virtual bool match( const QString ®exp ) const - {setLastHitField( -1 ); - return Qtopia::Record::match(QRegExp(regexp));}; + { + setLastHitField( -1 ); + return Qtopia::Record::match( QRegExp( regexp ) ); + }; /** * if implemented this function returns which item has been * last hit by the match() function. diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index f1a22a7..fa5313f 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp @@ -1,7 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can @@ -26,43 +26,27 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/********************************************************************** -** 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 <opie2/ocontact.h> +#include "ocontact.h" + +/* OPIE */ #include <opie2/opimresolver.h> #include <opie2/oconversion.h> - #include <qpe/stringutil.h> #include <qpe/timestring.h> #include <qpe/config.h> +/* QT */ #include <qobject.h> #include <qregexp.h> #include <qstylesheet.h> #include <qfileinfo.h> #include <qmap.h> +/* STD */ #include <stdio.h> /*! \class Contact contact.h @@ -75,35 +59,35 @@ \ingroup qtopiadesktop */ -namespace Opie { +namespace Opie +{ /*! Creates a new, empty contact. */ -OContact::OContact() - : OPimRecord(), mMap(), d( 0 ) -{ -} +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 ) +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) ){ + if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) + { qWarning( "Invalid UID found. Generate new one.." ); setUid( uidGen().generate() ); - }else + } + else setUid( uidStr.toInt() ); // if ( !uidStr.isEmpty() ) // setUid( uidStr.toInt() ); @@ -112,10 +96,9 @@ OContact::OContact( const QMap<int, QString> &fromMap ) : /*! Destroys a contact. */ OContact::~OContact() -{ -} +{} /*! \fn void OContact::setTitle( const QString &str ) Sets the title of the contact to \a str. */ @@ -480,114 +463,137 @@ QString OContact::toRichText() const if ( !(value = jobTitle()).isEmpty() ) text += Qtopia::escapeString(value) + " "; comp = company(); - if ( !(value = department()).isEmpty() ) { + if ( !( value = department() ).isEmpty() ) + { text += Qtopia::escapeString(value); if ( comp ) text += ", " + Qtopia::escapeString(comp); - }else if ( comp ) + } + else if ( comp ) text += "<br>" + Qtopia::escapeString(comp); text += "<br><hr>"; // defailt email QString defEmail = defaultEmail(); - if ( !defEmail.isEmpty() ){ + if ( !defEmail.isEmpty() ) + { text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>" + Qtopia::escapeString(defEmail); marker = true; } // business address if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || - !businessZip().isEmpty() || !businessCountry().isEmpty() ) { + !businessZip().isEmpty() || !businessCountry().isEmpty() ) + { text += QObject::tr( "<br><b>Work Address:</b>" ); marker = true; } - if ( !(value = businessStreet()).isEmpty() ){ + if ( !( value = businessStreet() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value); marker = true; } - switch( addressformat ){ - case Zip_City_State:{ // Zip_Code City, State + switch ( addressformat ) + { + case Zip_City_State: + { // Zip_Code City, State state = businessState(); - if ( !(value = businessZip()).isEmpty() ){ + if ( !( value = businessZip() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value) + " "; marker = true; } - if ( !(value = businessCity()).isEmpty() ) { + if ( !( value = businessCity() ).isEmpty() ) + { marker = true; if ( businessZip().isEmpty() && !businessStreet().isEmpty() ) text += "<br>"; text += Qtopia::escapeString(value); if ( state ) text += ", " + Qtopia::escapeString(state); - } else if ( !state.isEmpty() ){ + } + else if ( !state.isEmpty() ) + { text += "<br>" + Qtopia::escapeString(state); marker = true; } break; } - case City_State_Zip:{ // City, State Zip_Code + case City_State_Zip: + { // City, State Zip_Code state = businessState(); - if ( !(value = businessCity()).isEmpty() ) { + if ( !( value = businessCity() ).isEmpty() ) + { marker = true; text += "<br>" + Qtopia::escapeString(value); if ( state ) text += ", " + Qtopia::escapeString(state); - } else if ( !state.isEmpty() ){ + } + else if ( !state.isEmpty() ) + { text += "<br>" + Qtopia::escapeString(state); marker = true; } - if ( !(value = businessZip()).isEmpty() ){ + if ( !( value = businessZip() ).isEmpty() ) + { text += " " + Qtopia::escapeString(value); marker = true; } break; } } - if ( !(value = businessCountry()).isEmpty() ){ + if ( !( value = businessCountry() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value); marker = true; } // rest of Business data str = office(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b>" + QObject::tr("Office: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = businessWebpage(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = businessPhone(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = businessFax(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = businessMobile(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = businessPager(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>" + Qtopia::escapeString(str); marker = true; } @@ -595,83 +601,101 @@ QString OContact::toRichText() const // text += "<br>"; // home address if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || - !homeZip().isEmpty() || !homeCountry().isEmpty() ) { + !homeZip().isEmpty() || !homeCountry().isEmpty() ) + { text += QObject::tr( "<br><b>Home Address:</b>" ); marker = true; } - if ( !(value = homeStreet()).isEmpty() ){ + if ( !( value = homeStreet() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value); marker = true; } - switch( addressformat ){ - case Zip_City_State:{ // Zip_Code City, State + switch ( addressformat ) + { + case Zip_City_State: + { // Zip_Code City, State state = homeState(); - if ( !(value = homeZip()).isEmpty() ){ + if ( !( value = homeZip() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value) + " "; marker = true; } - if ( !(value = homeCity()).isEmpty() ) { + if ( !( value = homeCity() ).isEmpty() ) + { marker = true; if ( homeZip().isEmpty() && !homeStreet().isEmpty() ) text += "<br>"; text += Qtopia::escapeString(value); if ( !state.isEmpty() ) text += ", " + Qtopia::escapeString(state); - } else if (!state.isEmpty()) { + } + else if ( !state.isEmpty() ) + { text += "<br>" + Qtopia::escapeString(state); marker = true; } break; } - case City_State_Zip:{ // City, State Zip_Code + case City_State_Zip: + { // City, State Zip_Code state = homeState(); - if ( !(value = homeCity()).isEmpty() ) { + if ( !( value = homeCity() ).isEmpty() ) + { marker = true; text += "<br>" + Qtopia::escapeString(value); if ( state ) text += ", " + Qtopia::escapeString(state); - } else if ( !state.isEmpty() ){ + } + else if ( !state.isEmpty() ) + { text += "<br>" + Qtopia::escapeString(state); marker = true; } - if ( !(value = homeZip()).isEmpty() ){ + if ( !( value = homeZip() ).isEmpty() ) + { text += " " + Qtopia::escapeString(value); marker = true; } break; } } - if ( !(value = homeCountry()).isEmpty() ){ + if ( !( value = homeCountry() ).isEmpty() ) + { text += "<br>" + Qtopia::escapeString(value); marker = true; } // rest of Home data str = homeWebpage(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = homePhone(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = homeFax(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>" + Qtopia::escapeString(str); marker = true; } str = homeMobile(); - if ( !str.isEmpty() ){ + if ( !str.isEmpty() ) + { text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>" + Qtopia::escapeString(str); marker = true; } @@ -696,9 +720,10 @@ QString OContact::toRichText() const if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr("Manager: ") + "</b>" + Qtopia::escapeString(str); str = gender(); - if ( !str.isEmpty() && str.toInt() != 0 ) { + if ( !str.isEmpty() && str.toInt() != 0 ) + { text += "<br>"; if ( str.toInt() == 1 ) str = QObject::tr( "Male" ); else if ( str.toInt() == 2 ) @@ -708,14 +733,16 @@ QString OContact::toRichText() const str = spouse(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr("Spouse: ") + "</b>" + Qtopia::escapeString(str); - if ( birthday().isValid() ){ + if ( birthday().isValid() ) + { str = TimeString::numberDateString( birthday() ); text += "<br><b>" + QObject::tr("Birthday: ") + "</b>" + Qtopia::escapeString(str); } - if ( anniversary().isValid() ){ + if ( anniversary().isValid() ) + { str = TimeString::numberDateString( anniversary() ); text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>" + Qtopia::escapeString(str); } @@ -729,15 +756,17 @@ QString OContact::toRichText() const text += "<br><b>" + QObject::tr("Nickname: ") + "</b>" + Qtopia::escapeString(str); // categories - if ( categoryNames("Contacts").count() ){ + if ( categoryNames( "Contacts" ).count() ) + { text += "<br><b>" + QObject::tr( "Category:") + "</b> "; text += categoryNames("Contacts").join(", "); } // notes last - if ( !(value = notes()).isEmpty() ) { + if ( !( value = notes() ).isEmpty() ) + { text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; QRegExp reg("\n"); //QString tmp = Qtopia::escapeString(value); @@ -836,24 +865,28 @@ QString OContact::fullName() const QString lastName = find( Qtopia::LastName ); QString suffix = find( Qtopia::Suffix ); QString name = title; - if ( !firstName.isEmpty() ) { + if ( !firstName.isEmpty() ) + { if ( !name.isEmpty() ) name += " "; name += firstName; } - if ( !middleName.isEmpty() ) { + if ( !middleName.isEmpty() ) + { if ( !name.isEmpty() ) name += " "; name += middleName; } - if ( !lastName.isEmpty() ) { + if ( !lastName.isEmpty() ) + { if ( !name.isEmpty() ) name += " "; name += lastName; } - if ( !suffix.isEmpty() ) { + if ( !suffix.isEmpty() ) + { if ( !name.isEmpty() ) name += " "; name += suffix; } @@ -899,9 +932,10 @@ QStringList OContact::emailList() const { QString emailStr = emails(); QStringList r; - if ( !emailStr.isEmpty() ) { + if ( !emailStr.isEmpty() ) + { qDebug(" emailstr "); QStringList l = QStringList::split( emailSeparator(), emailStr ); for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) r += (*it).simplifyWhiteSpace(); @@ -945,12 +979,14 @@ 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 ) { + it != mMap.end(); ++it ) + { const QString &value = it.data(); int key = it.key(); - if ( !value.isEmpty() ) { + if ( !value.isEmpty() ) + { if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) continue; key -= Qtopia::AddressCategory+1; @@ -1060,10 +1096,12 @@ bool OContact::match( const QRegExp &r ) const setLastHitField( -1 ); bool match; match = false; QMap<int, QString>::ConstIterator it; - for ( it = mMap.begin(); it != mMap.end(); ++it ) { - if ( (*it).find( r ) > -1 ) { + for ( it = mMap.begin(); it != mMap.end(); ++it ) + { + if ( ( *it ).find( r ) > -1 ) + { setLastHitField( it.key() ); match = true; break; } @@ -1075,15 +1113,16 @@ bool OContact::match( const QRegExp &r ) const QString OContact::toShortText() const { return ( fullName() ); } + + QString OContact::type() const { return QString::fromLatin1( "OContact" ); } - class QString OContact::recordField( int pos ) const { QStringList SLFIELDS = fields(); // ?? why this ? (se) return SLFIELDS[pos]; @@ -1098,9 +1137,10 @@ class QString OContact::recordField( int pos ) const the current stored date will be removed. */ void OContact::setBirthday( const QDate &v ) { - if ( v.isNull() ){ + if ( v.isNull() ) + { qWarning( "Remove Birthday"); replace( Qtopia::Birthday, QString::null ); return; } @@ -1116,9 +1156,10 @@ void OContact::setBirthday( const QDate &v ) null, the current stored date will be removed. */ void OContact::setAnniversary( const QDate &v ) { - if ( v.isNull() ){ + if ( v.isNull() ) + { qWarning( "Remove Anniversary"); replace( Qtopia::Anniversary, QString::null ); return; } @@ -1126,8 +1167,9 @@ void OContact::setAnniversary( const QDate &v ) if ( v.isValid() ) replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); } + /*! \fn QDate OContact::birthday() const Returns the birthday of the contact. */ QDate OContact::birthday() const @@ -1162,9 +1204,10 @@ void OContact::insertEmail( const QString &v ) QString e = v.simplifyWhiteSpace(); QString def = defaultEmail(); // if no default, set it as the default email and don't insert - if ( def.isEmpty() ) { + if ( def.isEmpty() ) + { setDefaultEmail( e ); // will insert into the list for us return; } @@ -1177,8 +1220,9 @@ void OContact::insertEmail( const QString &v ) emailsStr += e; replace( Qtopia::Emails, emailsStr ); } + void OContact::removeEmail( const QString &v ) { QString e = v.simplifyWhiteSpace(); QString def = defaultEmail(); @@ -1196,21 +1240,26 @@ void OContact::removeEmail( const QString &v ) 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 ) { + 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(); @@ -1221,16 +1270,22 @@ void OContact::setDefaultEmail( const QString &v ) insertEmail( e ); } + void OContact::insertEmails( const QStringList &v ) { for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) insertEmail( *it ); } -int OContact::rtti() { + + +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 34888dc..445fd7d 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h @@ -25,14 +25,17 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __OCONTACT_H__ -#define __OCONTACT_H__ +#ifndef OCONTACT_H +#define OCONTACT_H + +/* OPIE */ #include <opie2/opimrecord.h> #include <qpe/recordfields.h> +/* QT */ #include <qdatetime.h> #include <qstringlist.h> #if defined(QPC_TEMPLATEDLL) @@ -40,9 +43,10 @@ QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; // MOC_SKIP_END #endif -namespace Opie { +namespace Opie +{ class OContactPrivate; /** * OContact class represents a specialised PIM Record for contacts. @@ -53,8 +57,9 @@ class OContactPrivate; */ class QPC_EXPORT OContact : public OPimRecord { friend class DataSet; + public: OContact(); OContact( const QMap<int, QString> &fromMap ); virtual ~OContact(); diff --git a/libopie2/opiepim/ocontactfields.cpp b/libopie2/opiepim/ocontactfields.cpp index deaa1e5..bec00f7 100644 --- a/libopie2/opiepim/ocontactfields.cpp +++ b/libopie2/opiepim/ocontactfields.cpp @@ -1,7 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can @@ -26,19 +26,22 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <opie2/ocontactfields.h> +#include "ocontactfields.h" -#include <qstringlist.h> +/* OPIE */ +#include <opie2/ocontact.h> +#include <qpe/recordfields.h> // We should use our own enum in the future .. +#include <qpe/config.h> + +/* QT */ #include <qobject.h> +#include <qstringlist.h> -// We should use our own enum in the future .. -#include <qpe/recordfields.h> -#include <qpe/config.h> -#include <opie2/ocontact.h> -namespace Opie { +namespace Opie +{ /*! \internal Returns a list of personal field names for a contact. */ @@ -422,22 +425,25 @@ OContactFields::OContactFields(): cfg.setGroup( "ContactFieldOrder" ); globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); } -OContactFields::~OContactFields(){ +OContactFields::~OContactFields() +{ // We will store the fieldorder into the config file // to reuse it for the future.. - if ( changedFieldOrder ){ + if ( changedFieldOrder ) + { Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); cfg.writeEntry( "General", globalFieldOrder ); } } -void OContactFields::saveToRecord( OContact &cnt ){ +void OContactFields::saveToRecord( OContact &cnt ) +{ qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); // Store fieldorder into this contact. @@ -447,9 +453,10 @@ void OContactFields::saveToRecord( OContact &cnt ){ changedFieldOrder = true; } -void OContactFields::loadFromRecord( const OContact &cnt ){ +void OContactFields::loadFromRecord( const OContact &cnt ) +{ qDebug("ocontactfields loadFromRecord"); qDebug("loading >%s<",cnt.fullName().latin1()); // Get fieldorder for this contact. If none is defined, @@ -458,17 +465,19 @@ void OContactFields::loadFromRecord( const OContact &cnt ){ fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); - if (fieldOrder.isEmpty()){ + if ( fieldOrder.isEmpty() ) + { fieldOrder = globalFieldOrder; } qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); } -void OContactFields::setFieldOrder( int num, int index ){ +void OContactFields::setFieldOrder( int num, int index ) +{ qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); fieldOrder[num] = QString::number( index, 16 )[0]; @@ -479,9 +488,10 @@ void OContactFields::setFieldOrder( int num, int index ){ qDebug("fieldOrder >%s<",fieldOrder.latin1()); } -int OContactFields::getFieldOrder( int num, int defIndex ){ +int OContactFields::getFieldOrder( int num, int defIndex ) +{ qDebug("ocontactfields getFieldOrder"); qDebug("fieldOrder >%s<",fieldOrder.latin1()); // Get index of combo as char.. diff --git a/libopie2/opiepim/ocontactfields.h b/libopie2/opiepim/ocontactfields.h index 993ce3b..9e89532 100644 --- a/libopie2/opiepim/ocontactfields.h +++ b/libopie2/opiepim/ocontactfields.h @@ -25,22 +25,28 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_CONTACTS_FIELDS -#define OPIE_CONTACTS_FIELDS + +#ifndef OCONTACTFIELDS_H +#define OCONTACTFIELDS_H class QStringList; +/* OPIE */ +#include <opie2/ocontact.h> + +/* QT */ #include <qmap.h> #include <qstring.h> -#include <opie2/ocontact.h> #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" #define DEFAULT_FIELD_ORDER "__________" -namespace Opie { -class OContactFields{ +namespace Opie +{ +class OContactFields +{ public: OContactFields(); ~OContactFields(); diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index de5e30b..d9cee2b 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp @@ -1,7 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) + Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can @@ -25,24 +25,28 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qshared.h> -#include <qarray.h> -#include <qpe/palmtopuidgen.h> -#include <qpe/categories.h> -#include <qpe/stringutil.h> +#include "oevent.h" +/* OPIE */ #include <opie2/orecur.h> #include <opie2/opimresolver.h> #include <opie2/opimnotifymanager.h> +#include <qpe/categories.h> +#include <qpe/palmtopuidgen.h> +#include <qpe/stringutil.h> -#include <opie2/oevent.h> +/* QT */ +#include <qshared.h> +#include <qarray.h> -namespace Opie { +namespace Opie +{ -int OCalendarHelper::week( const QDate& date) { +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 ); @@ -52,36 +56,50 @@ int OCalendarHelper::week( const QDate& date) { week += ( date.day() - 1 ) / 7; return week; } -int OCalendarHelper::ocurrence( const QDate& date) { + + +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 OCalendarHelper::dayOfWeek( char day ) +{ int dayOfWeek = 1; char i = ORecur::MON; - while ( !( i & day ) && i <= ORecur::SUN ) { + while ( !( i & day ) && i <= ORecur::SUN ) + { i <<= 1; ++dayOfWeek; } return dayOfWeek; } -int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { + + +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() { + +struct OEvent::Data : public QShared +{ + Data() : QShared() + { child = 0; recur = 0; manager = 0; isAllDay = false; parent = 0; } - ~Data() { + ~Data() + { delete manager; delete recur; } QString description; @@ -97,33 +115,44 @@ struct OEvent::Data : public QShared { QArray<int>* child; int parent; }; + OEvent::OEvent( int uid ) - : OPimRecord( uid ) { + : OPimRecord( uid ) +{ data = new Data; } + + OEvent::OEvent( const OEvent& ev) : OPimRecord( ev ), data( ev.data ) { data->ref(); } + OEvent::OEvent( const QMap<int, QString> map ) : OPimRecord( 0 ) { data = new Data; fromMap( map ); } -OEvent::~OEvent() { - if ( data->deref() ) { + +OEvent::~OEvent() +{ + if ( data->deref() ) + { delete data; data = 0; } } -OEvent& OEvent::operator=( const OEvent& ev) { + + +OEvent& OEvent::operator=( const OEvent& ev ) +{ if ( this == &ev ) return *this; OPimRecord::operator=( ev ); ev.data->ref(); @@ -132,207 +161,302 @@ OEvent& OEvent::operator=( const OEvent& ev) { return *this; } -QString OEvent::description()const { + + +QString OEvent::description() const +{ return data->description; } -void OEvent::setDescription( const QString& description ) { + + +void OEvent::setDescription( const QString& description ) +{ changeOrModify(); data->description = description; } -void OEvent::setLocation( const QString& loc ) { + + +void OEvent::setLocation( const QString& loc ) +{ changeOrModify(); data->location = loc; } -QString OEvent::location()const { + + +QString OEvent::location() const +{ return data->location; } -OPimNotifyManager &OEvent::notifiers()const { + + +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 { + + +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 { + + +ORecur OEvent::recurrence() const +{ if (!data->recur) data->recur = new ORecur; return *data->recur; } -void OEvent::setRecurrence( const ORecur& rec) { + + +void OEvent::setRecurrence( const ORecur& rec ) +{ changeOrModify(); if (data->recur ) (*data->recur) = rec; else data->recur = new ORecur( rec ); } -bool OEvent::hasRecurrence()const { + + +bool OEvent::hasRecurrence() const +{ if (!data->recur ) return false; return data->recur->doesRecur(); } -QString OEvent::note()const { + + +QString OEvent::note() const +{ return data->note; } -void OEvent::setNote( const QString& note ) { + + +void OEvent::setNote( const QString& note ) +{ changeOrModify(); data->note = note; } -QDateTime OEvent::createdDateTime()const { + + +QDateTime OEvent::createdDateTime() const +{ return data->created; } -void OEvent::setCreatedDateTime( const QDateTime& time ) { + + +void OEvent::setCreatedDateTime( const QDateTime& time ) +{ changeOrModify(); data->created = time; } -QDateTime OEvent::startDateTime()const { + + +QDateTime OEvent::startDateTime() const +{ if ( data->isAllDay ) return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); return data->start; } -QDateTime OEvent::startDateTimeInZone()const { + + +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 ) { + + +void OEvent::setStartDateTime( const QDateTime& dt ) +{ changeOrModify(); data->start = dt; } -QDateTime OEvent::endDateTime()const { + + +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 { + + +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 ) { + + +void OEvent::setEndDateTime( const QDateTime& dt ) +{ changeOrModify(); data->end = dt; } -bool OEvent::isMultipleDay()const { + + +bool OEvent::isMultipleDay() const +{ return data->end.date().day() - data->start.date().day(); } -bool OEvent::isAllDay()const { + + +bool OEvent::isAllDay() const +{ return data->isAllDay; } -void OEvent::setAllDay( bool allDay ) { + + +void OEvent::setAllDay( bool allDay ) +{ changeOrModify(); data->isAllDay = allDay; if (allDay ) data->timezone = "UTC"; } -void OEvent::setTimeZone( const QString& tz ) { + + +void OEvent::setTimeZone( const QString& tz ) +{ changeOrModify(); data->timezone = tz; } -QString OEvent::timeZone()const { + + +QString OEvent::timeZone() const +{ if (data->isAllDay ) return QString::fromLatin1("UTC"); return data->timezone; } -bool OEvent::match( const QRegExp& re )const { - if ( re.match( data->description ) != -1 ){ + + +bool OEvent::match( const QRegExp& re ) const +{ + if ( re.match( data->description ) != -1 ) + { setLastHitField( Qtopia::DatebookDescription ); return true; } - if ( re.match( data->note ) != -1 ){ + if ( re.match( data->note ) != -1 ) + { setLastHitField( Qtopia::Note ); return true; } - if ( re.match( data->location ) != -1 ){ + if ( re.match( data->location ) != -1 ) + { setLastHitField( Qtopia::Location ); return true; } - if ( re.match( data->start.toString() ) != -1 ){ + if ( re.match( data->start.toString() ) != -1 ) + { setLastHitField( Qtopia::StartDateTime ); return true; } - if ( re.match( data->end.toString() ) != -1 ){ + if ( re.match( data->end.toString() ) != -1 ) + { setLastHitField( Qtopia::EndDateTime ); return true; } return false; } -QString OEvent::toRichText()const { + + +QString OEvent::toRichText() const +{ QString text, value; // description text += "<b><h3><img src=\"datebook/DateBook\">"; - if ( !description().isEmpty() ) { + if ( !description().isEmpty() ) + { text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); } text += "</h3></b><br><hr><br>"; // location - if ( !(value = location()).isEmpty() ) { + if ( !( value = location() ).isEmpty() ) + { text += "<b>" + QObject::tr( "Location:" ) + "</b> "; text += Qtopia::escapeString(value) + "<br>"; } // all day event - if ( isAllDay() ) { + if ( isAllDay() ) + { text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; } // multiple day event - else if ( isMultipleDay () ) { + else if ( isMultipleDay () ) + { text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; } // start & end times - else { + else + { // start time - if ( startDateTime().isValid() ) { + if ( startDateTime().isValid() ) + { text += "<b>" + QObject::tr( "Start:") + "</b> "; text += Qtopia::escapeString(startDateTime().toString() ). replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; } // end time - if ( endDateTime().isValid() ) { + if ( endDateTime().isValid() ) + { text += "<b>" + QObject::tr( "End:") + "</b> "; text += Qtopia::escapeString(endDateTime().toString() ). replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; } } // categories - if ( categoryNames("Calendar").count() ){ + if ( categoryNames( "Calendar" ).count() ) + { text += "<b>" + QObject::tr( "Category:") + "</b> "; text += categoryNames("Calendar").join(", "); text += "<br>"; } //notes - if ( !note().isEmpty() ) { + 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 { + + +QString OEvent::toShortText() const +{ QString text; text += QString::number( startDateTime().date().day() ); text += "."; text += QString::number( startDateTime().date().month() ); @@ -345,25 +469,44 @@ QString OEvent::toShortText()const { text += " - "; text += description(); return text; } -QString OEvent::type()const { + + +QString OEvent::type() const +{ return QString::fromLatin1("OEvent"); } -QString OEvent::recordField( int /*id */ )const { + + +QString OEvent::recordField( int /*id */ ) const +{ return QString::null; } -int OEvent::rtti() { + + +int OEvent::rtti() +{ return OPimResolver::DateBook; } -bool OEvent::loadFromStream( QDataStream& ) { + + +bool OEvent::loadFromStream( QDataStream& ) +{ return true; } -bool OEvent::saveToStream( QDataStream& )const { + + +bool OEvent::saveToStream( QDataStream& ) const +{ return true; } -void OEvent::changeOrModify() { - if ( data->count != 1 ) { + + +void OEvent::changeOrModify() +{ + if ( data->count != 1 ) + { data->deref(); Data* d2 = new Data; d2->description = data->description; d2->location = data->location; @@ -381,18 +524,23 @@ void OEvent::changeOrModify() { d2->isAllDay = data->isAllDay; d2->timezone = data->timezone; d2->parent = data->parent; - if ( data->child ) { + if ( data->child ) + { d2->child = new QArray<int>( *data->child ); d2->child->detach(); } data = d2; } } -void OEvent::deref() { - if ( data->deref() ) { + + +void OEvent::deref() +{ + if ( data->deref() ) + { delete data; data = 0; } } @@ -400,9 +548,10 @@ void OEvent::deref() { // encoding as ODateBookAccessBackend_xml does.. // Thus, we could remove the stuff there and use this // for it and for all other places.. // Encoding should happen at one place, only ! (eilers) -QMap<int, QString> OEvent::toMap()const { +QMap<int, QString> OEvent::toMap() const +{ QMap<int, QString> retMap; retMap.insert( OEvent::FUid, QString::number( uid() ) ); retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); @@ -419,20 +568,23 @@ QMap<int, QString> OEvent::toMap()const { retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); if( parent() ) retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); - if( children().count() ){ + if ( children().count() ) + { QArray<int> childr = children(); QString buf; - for ( uint i = 0; i < childr.count(); i++ ) { + for ( uint i = 0; i < childr.count(); i++ ) + { if ( i != 0 ) buf += " "; buf += QString::number( childr[i] ); } retMap.insert( OEvent::FRecChildren, buf ); } // Add recurrence stuff - if( hasRecurrence() ){ + if ( hasRecurrence() ) + { ORecur recur = recurrence(); QMap<int, QString> recFields = recur.toMap(); retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); @@ -441,17 +593,20 @@ QMap<int, QString> OEvent::toMap()const { retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); - } else { + } + else + { ORecur recur = recurrence(); QMap<int, QString> recFields = recur.toMap(); retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); } return retMap; } + void OEvent::fromMap( const QMap<int, QString>& map ) { // We just want to set the UID if it is really stored. @@ -471,27 +626,32 @@ void OEvent::fromMap( const QMap<int, QString>& map ) if( !map[OEvent::FAlarm].isEmpty() ) alarmTime = map[OEvent::FAlarm].toInt(); int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); - if ( ( alarmTime != -1 ) ){ + if ( ( alarmTime != -1 ) ) + { QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); OPimAlarm al( sound , dt ); notifiers().add( al ); } - if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ + if ( !map[ OEvent::FTimeZone ].isEmpty() && ( map[ OEvent::FTimeZone ] != "None" ) ) + { setTimeZone( map[OEvent::FTimeZone] ); } time_t start = (time_t) map[OEvent::FStart].toLong(); time_t end = (time_t) map[OEvent::FEnd].toLong(); /* AllDay is always in UTC */ - if ( isAllDay() ) { + if ( isAllDay() ) + { OTimeZone utc = OTimeZone::utc(); setStartDateTime( utc.fromUTCDateTime( start ) ); setEndDateTime ( utc.fromUTCDateTime( end ) ); setTimeZone( "UTC"); // make sure it is really utc - }else { + } + else + { /* to current date time */ // qWarning(" Start is %d", start ); OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); QDateTime date = zone.toDateTime( start ); @@ -504,17 +664,20 @@ void OEvent::fromMap( const QMap<int, QString>& map ) if ( !map[OEvent::FRecParent].isEmpty() ) setParent( map[OEvent::FRecParent].toInt() ); - if ( !map[OEvent::FRecChildren].isEmpty() ){ + if ( !map[ OEvent::FRecChildren ].isEmpty() ) + { QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); - for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { addChild( (*it).toInt() ); } } // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. - if( !map[OEvent::FRType].isEmpty() ){ + if ( !map[ OEvent::FRType ].isEmpty() ) + { QMap<int, QString> recFields; recFields.insert( ORecur::RType, map[OEvent::FRType] ); recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); @@ -529,70 +692,99 @@ void OEvent::fromMap( const QMap<int, QString>& map ) } -int OEvent::parent()const { +int OEvent::parent() const +{ return data->parent; } -void OEvent::setParent( int uid ) { + + +void OEvent::setParent( int uid ) +{ changeOrModify(); data->parent = uid; } -QArray<int> OEvent::children() const{ + + +QArray<int> OEvent::children() const +{ if (!data->child) return QArray<int>(); else return data->child->copy(); } -void OEvent::setChildren( const QArray<int>& arr ) { + + +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 ) { + + +void OEvent::addChild( int uid ) +{ changeOrModify(); - if (!data->child ) { + if ( !data->child ) + { data->child = new QArray<int>(1); (*data->child)[0] = uid; - }else{ + } + else + { int count = data->child->count(); data->child->resize( count + 1 ); (*data->child)[count] = uid; } } -void OEvent::removeChild( int 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 ) { + 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() { - } + + +struct OEffectiveEvent::Data : public QShared +{ + Data() : QShared() + {} OEvent event; QDate date; QTime start, end; QDate startDate, endDate; bool dates : 1; }; -OEffectiveEvent::OEffectiveEvent() { + +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 ) { + Position pos ) +{ data = new Data; data->event = ev; data->date = startDate; if ( pos & Start ) @@ -606,19 +798,29 @@ OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, data->end = QTime( 23, 59, 59 ); data->dates = false; } -OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { + + +OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) +{ data = ev.data; data->ref(); } -OEffectiveEvent::~OEffectiveEvent() { - if ( data->deref() ) { + + +OEffectiveEvent::~OEffectiveEvent() +{ + if ( data->deref() ) + { delete data; data = 0; } } -OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { + + +OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) +{ if ( *this == ev ) return *this; ev.data->ref(); deref(); @@ -626,88 +828,144 @@ OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { return *this; } -void OEffectiveEvent::setStartTime( const QTime& ti) { + +void OEffectiveEvent::setStartTime( const QTime& ti ) +{ changeOrModify(); data->start = ti; } -void OEffectiveEvent::setEndTime( const QTime& en) { + + +void OEffectiveEvent::setEndTime( const QTime& en ) +{ changeOrModify(); data->end = en; } -void OEffectiveEvent::setEvent( const OEvent& ev) { + + +void OEffectiveEvent::setEvent( const OEvent& ev ) +{ changeOrModify(); data->event = ev; } -void OEffectiveEvent::setDate( const QDate& da) { + + +void OEffectiveEvent::setDate( const QDate& da ) +{ changeOrModify(); data->date = da; } + + void OEffectiveEvent::setEffectiveDates( const QDate& from, - const QDate& to ) { - if (!from.isValid() ) { + const QDate& to ) +{ + if ( !from.isValid() ) + { data->dates = false; return; } data->startDate = from; data->endDate = to; } -QString OEffectiveEvent::description()const { + + +QString OEffectiveEvent::description() const +{ return data->event.description(); } -QString OEffectiveEvent::location()const { + + +QString OEffectiveEvent::location() const +{ return data->event.location(); } -QString OEffectiveEvent::note()const { + + +QString OEffectiveEvent::note() const +{ return data->event.note(); } -OEvent OEffectiveEvent::event()const { + + +OEvent OEffectiveEvent::event() const +{ return data->event; } -QTime OEffectiveEvent::startTime()const { + + +QTime OEffectiveEvent::startTime() const +{ return data->start; } -QTime OEffectiveEvent::endTime()const { + + +QTime OEffectiveEvent::endTime() const +{ return data->end; } -QDate OEffectiveEvent::date()const { + + +QDate OEffectiveEvent::date() const +{ return data->date; } -int OEffectiveEvent::length()const { + + +int OEffectiveEvent::length() const +{ return (data->end.hour() * 60 - data->start.hour() * 60) + QABS(data->start.minute() - data->end.minute() ); } -int OEffectiveEvent::size()const { + + +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 { + + +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 { + + +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() ) { + + +void OEffectiveEvent::deref() +{ + if ( data->deref() ) + { delete data; data = 0; } } -void OEffectiveEvent::changeOrModify() { - if ( data->count != 1 ) { + + +void OEffectiveEvent::changeOrModify() +{ + if ( data->count != 1 ) + { data->deref(); Data* d2 = new Data; d2->event = data->event; d2->date = data->date; @@ -718,32 +976,50 @@ void OEffectiveEvent::changeOrModify() { d2->dates = data->dates; data = d2; } } -bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ + + +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{ + + +bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const +{ return (data->date <= e.date() ); } -bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { + + +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 { + + +bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const +{ return !(*this == e ); } -bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { + + +bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const +{ return !(*this <= e ); } -bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { + + +bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const +{ return !(*this < e); } } diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h index 9502efa..dc5e4d6 100644 --- a/libopie2/opiepim/oevent.h +++ b/libopie2/opiepim/oevent.h @@ -1,7 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) + Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can @@ -27,23 +27,26 @@ Boston, MA 02111-1307, USA. */ // CONTAINS GPLed code of TT -#ifndef OPIE_PIM_EVENT_H -#define OPIE_PIM_EVENT_H - -#include <qstring.h> -#include <qdatetime.h> -#include <qvaluelist.h> +#ifndef OEVENT_H +#define OEVENT_H +/* OPIE */ +#include <opie2/otimezone.h> +#include <opie2/opimrecord.h> #include <qpe/recordfields.h> #include <qpe/palmtopuidgen.h> -#include <opie2/otimezone.h> -#include <opie2/opimrecord.h> +/* QT */ +#include <qstring.h> +#include <qdatetime.h> +#include <qvaluelist.h> -namespace Opie { -struct OCalendarHelper { +namespace Opie +{ +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& ); @@ -64,9 +67,10 @@ 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 { +class OEvent : public OPimRecord +{ public: typedef QValueList<OEvent> ValueList; /** * RecordFields contain possible attributes @@ -190,8 +194,9 @@ public: bool operator<=( const OEvent& ); bool operator>( const OEvent& ); bool operator>=(const OEvent& ); */ + private: inline void changeOrModify(); void deref(); struct Data; @@ -203,9 +208,11 @@ private: /** * AN Event can span through multiple days. We split up a multiday eve */ -class OEffectiveEvent { +class OEffectiveEvent +{ + public: typedef QValueList<OEffectiveEvent> ValueList; enum Position { MidWay, Start, End, StartEnd }; // If we calculate the effective event of a multi-day event diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 8f0011b..1742dcc 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h @@ -26,17 +26,20 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_RECORD_LIST_H -#define OPIE_RECORD_LIST_H - -#include <qarray.h> +#ifndef ORECORDLIST_H +#define ORECORDLIST_H +/* OPIE */ #include <opie2/otemplatebase.h> #include <opie2/opimrecord.h> -namespace Opie { +/* QT */ +#include <qarray.h> + +namespace Opie +{ class ORecordListIteratorPrivate; /** * Our List Iterator @@ -46,10 +49,12 @@ class ORecordListIteratorPrivate; * doSomeCoolStuff( (*it) ); */ template <class T> class ORecordList; template <class T = OPimRecord> -class ORecordListIterator { +class ORecordListIterator +{ friend class ORecordList<T>; + public: typedef OTemplateBase<T> Base; /** @@ -104,24 +109,26 @@ private: /* d pointer for future versions */ ORecordListIteratorPrivate *d; }; + class ORecordListPrivate; /** * The recordlist used as a return type * from OPimAccessTemplate */ template <class T = OPimRecord > -class ORecordList { +class ORecordList +{ public: typedef OTemplateBase<T> Base; typedef ORecordListIterator<T> Iterator; /** * c'tor */ - ORecordList () { - } + ORecordList () + {} ORecordList( const QArray<int>& ids, const Base* ); ~ORecordList(); @@ -157,25 +164,32 @@ private: const Base* m_acc; ORecordListPrivate *d; }; + /* ok now implement it */ template <class T> -ORecordListIterator<T>::ORecordListIterator() { +ORecordListIterator<T>::ORecordListIterator() +{ m_current = 0; m_temp = 0l; m_end = true; m_record = T(); /* forward */ m_direction = TRUE; } + + template <class T> -ORecordListIterator<T>::~ORecordListIterator() { +ORecordListIterator<T>::~ORecordListIterator() +{ /* nothing to delete */ } + template <class T> -ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { +ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it ) +{ // qWarning("ORecordListIterator copy c'tor"); m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; @@ -183,10 +197,12 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { m_record = it.m_record; m_direction = it.m_direction; } + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { +ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it ) +{ m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; m_end = it.m_end; @@ -194,10 +210,12 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIter return *this; } + template <class T> -T ORecordListIterator<T>::operator*() { +T ORecordListIterator<T>::operator*() +{ //qWarning("operator* %d %d", m_current, m_uids[m_current] ); if (!m_end ) m_record = m_temp->find( m_uids[m_current], m_uids, m_current, m_direction ? Base::Forward : @@ -207,33 +225,44 @@ T ORecordListIterator<T>::operator*() { return m_record; } + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator++() { +ORecordListIterator<T> &ORecordListIterator<T>::operator++() +{ m_direction = true; - if (m_current < m_uids.count() ) { + if ( m_current < m_uids.count() ) + { m_end = false; ++m_current; - }else + } + else m_end = true; return *this; } + + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator--() { +ORecordListIterator<T> &ORecordListIterator<T>::operator--() +{ m_direction = false; - if ( m_current > 0 ) { + if ( m_current > 0 ) + { --m_current; m_end = false; - } else + } + else m_end = true; return *this; } + template <class T> -bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { +bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) +{ /* if both are at we're the same.... */ if ( m_end == it.m_end ) return true; @@ -242,12 +271,17 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { if ( m_temp != it.m_temp ) return false; return true; } + + template <class T> -bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { +bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) +{ return !(*this == it ); } + + template <class T> ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, const Base* t ) : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), @@ -256,73 +290,105 @@ ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, /* if the list is empty we're already at the end of the list */ if (uids.count() == 0 ) m_end = true; } + + template <class T> -uint ORecordListIterator<T>::current()const { +uint ORecordListIterator<T>::current() const +{ return m_current; } + + template <class T> -void ORecordListIterator<T>::setCurrent( uint cur ) { - if( cur < m_uids.count() ) { +void ORecordListIterator<T>::setCurrent( uint cur ) +{ + if ( cur < m_uids.count() ) + { m_end = false; m_current= cur; } } template <class T> -uint ORecordListIterator<T>::count()const { +uint ORecordListIterator<T>::count() const +{ return m_uids.count(); } + + template <class T> ORecordList<T>::ORecordList( const QArray<int>& ids, const Base* acc ) : m_ids( ids ), m_acc( acc ) -{ -} +{} + + template <class T> -ORecordList<T>::~ORecordList() { +ORecordList<T>::~ORecordList() +{ /* nothing to do here */ } + + template <class T> -typename ORecordList<T>::Iterator ORecordList<T>::begin() { +typename ORecordList<T>::Iterator ORecordList<T>::begin() +{ Iterator it( m_ids, m_acc ); return it; } + + template <class T> -typename ORecordList<T>::Iterator ORecordList<T>::end() { +typename ORecordList<T>::Iterator ORecordList<T>::end() +{ Iterator it( m_ids, m_acc ); it.m_end = true; it.m_current = m_ids.count(); return it; } + + template <class T> -uint ORecordList<T>::count()const { +uint ORecordList<T>::count() const +{ return m_ids.count(); } + + template <class T> -T ORecordList<T>::operator[]( uint i ) { +T ORecordList<T>::operator[] ( uint i ) +{ if ( i >= m_ids.count() ) return T(); /* forward */ return m_acc->find( m_ids[i], m_ids, i ); } + + template <class T> -int ORecordList<T>::uidAt( uint i ) { +int ORecordList<T>::uidAt( uint i ) +{ return m_ids[i]; } + template <class T> -bool ORecordList<T>::remove( int uid ) { +bool ORecordList<T>::remove( int uid ) +{ QArray<int> copy( m_ids.count() ); int counter = 0; bool ret_val = false; - for (uint i = 0; i < m_ids.count(); i++){ - if ( m_ids[i] != uid ){ + for ( uint i = 0; i < m_ids.count(); i++ ) + { + if ( m_ids[ i ] != uid ) + { copy[counter++] = m_ids[i]; - }else + } + else ret_val = true; } copy.resize( counter ); diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index 3eb0026..f534067 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp @@ -25,39 +25,42 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <qobject.h> -#include <qshared.h> - +#include "otodo.h" +/* OPIE */ +#include <opie2/opimstate.h> +#include <opie2/orecur.h> +#include <opie2/opimmaintainer.h> +#include <opie2/opimnotifymanager.h> +#include <opie2/opimresolver.h> #include <qpe/palmtopuidgen.h> #include <qpe/stringutil.h> #include <qpe/palmtoprecord.h> #include <qpe/stringutil.h> #include <qpe/categories.h> #include <qpe/categoryselect.h> +/* QT */ +#include <qobject.h> +#include <qshared.h> -#include <opie2/opimstate.h> -#include <opie2/orecur.h> -#include <opie2/opimmaintainer.h> -#include <opie2/opimnotifymanager.h> -#include <opie2/opimresolver.h> - -#include <opie2/otodo.h> - -namespace Opie { +namespace Opie +{ -struct OTodo::OTodoData : public QShared { - OTodoData() : QShared() { +struct OTodo::OTodoData : public QShared +{ + OTodoData() : QShared() + { recur = 0; state = 0; maintainer = 0; notifiers = 0; }; - ~OTodoData() { + ~OTodoData() + { delete recur; delete maintainer; delete notifiers; } @@ -77,23 +80,30 @@ struct OTodo::OTodoData : public QShared { QDate completed; OPimNotifyManager *notifiers; }; + OTodo::OTodo(const OTodo &event ) : OPimRecord( event ), data( event.data ) { data->ref(); // qWarning("ref up"); } -OTodo::~OTodo() { + + +OTodo::~OTodo() +{ // qWarning("~OTodo " ); - if ( data->deref() ) { + if ( data->deref() ) + { // qWarning("OTodo::dereffing"); delete data; data = 0l; } } + + OTodo::OTodo(bool completed, int priority, const QArray<int> &category, const QString& summary, const QString &description, @@ -113,8 +123,10 @@ OTodo::OTodo(bool completed, int priority, data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); } + + OTodo::OTodo(bool completed, int priority, const QStringList &category, const QString& summary, const QString &description, @@ -134,171 +146,261 @@ OTodo::OTodo(bool completed, int priority, data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); } + + bool OTodo::match( const QRegExp ®Exp )const { - if( QString::number( data->priority ).find( regExp ) != -1 ){ + if ( QString::number( data->priority ).find( regExp ) != -1 ) + { setLastHitField( Priority ); return true; - }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ + } + else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) + { setLastHitField( HasDate ); return true; - }else if(data->desc.find( regExp ) != -1 ){ + } + else if ( data->desc.find( regExp ) != -1 ) + { setLastHitField( Description ); return true; - }else if(data->sum.find( regExp ) != -1 ) { + } + else if ( data->sum.find( regExp ) != -1 ) + { setLastHitField( Summary ); return true; } return false; } + + bool OTodo::isCompleted() const { return data->isCompleted; } + + bool OTodo::hasDueDate() const { return data->hasDate; } -bool OTodo::hasStartDate()const { + + +bool OTodo::hasStartDate() const +{ return data->start.isValid(); } -bool OTodo::hasCompletedDate()const { + + +bool OTodo::hasCompletedDate() const +{ return data->completed.isValid(); } + + int OTodo::priority()const { return data->priority; } + + QString OTodo::summary() const { return data->sum; } + + ushort OTodo::progress() const { return data->prog; } + + QDate OTodo::dueDate()const { return data->date; } -QDate OTodo::startDate()const { + + +QDate OTodo::startDate() const +{ return data->start; } -QDate OTodo::completedDate()const { + + +QDate OTodo::completedDate() const +{ return data->completed; } + + QString OTodo::description()const { return data->desc; } -bool OTodo::hasState() const{ + + +bool OTodo::hasState() const +{ if (!data->state ) return false; return ( data->state->state() != OPimState::Undefined ); } -OPimState OTodo::state()const { - if (!data->state ) { + + +OPimState OTodo::state() const +{ + if ( !data->state ) + { OPimState state; return state; } return (*data->state); } -bool OTodo::hasRecurrence()const { + + +bool OTodo::hasRecurrence() const +{ if (!data->recur) return false; return data->recur->doesRecur(); } -ORecur OTodo::recurrence()const { + + +ORecur OTodo::recurrence() const +{ if (!data->recur) return ORecur(); return (*data->recur); } -bool OTodo::hasMaintainer()const { + + +bool OTodo::hasMaintainer() const +{ if (!data->maintainer) return false; return (data->maintainer->mode() != OPimMaintainer::Undefined ); } -OPimMaintainer OTodo::maintainer()const { + + +OPimMaintainer OTodo::maintainer() const +{ if (!data->maintainer) return OPimMaintainer(); return (*data->maintainer); } + + void OTodo::setCompleted( bool completed ) { changeOrModify(); data->isCompleted = completed; } + + void OTodo::setHasDueDate( bool hasDate ) { changeOrModify(); data->hasDate = hasDate; } + + void OTodo::setDescription(const QString &desc ) { // qWarning( "desc " + desc ); changeOrModify(); data->desc = Qtopia::simplifyMultiLineSpace(desc ); } + + void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } + + void OTodo::setPriority(int prio ) { changeOrModify(); data->priority = prio; } + + void OTodo::setDueDate( const QDate& date ) { changeOrModify(); data->date = date; } -void OTodo::setStartDate( const QDate& date ) { + + +void OTodo::setStartDate( const QDate& date ) +{ changeOrModify(); data->start = date; } -void OTodo::setCompletedDate( const QDate& date ) { + + +void OTodo::setCompletedDate( const QDate& date ) +{ changeOrModify(); data->completed = date; } -void OTodo::setState( const OPimState& state ) { + + +void OTodo::setState( const OPimState& state ) +{ changeOrModify(); if (data->state ) (*data->state) = state; else data->state = new OPimState( state ); } -void OTodo::setRecurrence( const ORecur& rec) { + + +void OTodo::setRecurrence( const ORecur& rec ) +{ changeOrModify(); if (data->recur ) (*data->recur) = rec; else data->recur = new ORecur( rec ); } -void OTodo::setMaintainer( const OPimMaintainer& pim ) { + + +void OTodo::setMaintainer( const OPimMaintainer& pim ) +{ changeOrModify(); if (data->maintainer ) (*data->maintainer) = pim; else data->maintainer = new OPimMaintainer( pim ); } + + bool OTodo::isOverdue( ) { if( data->hasDate && !data->isCompleted) return QDate::currentDate() > data->date; return false; } + + void OTodo::setProgress(ushort progress ) { changeOrModify(); data->prog = progress; } -QString OTodo::toShortText() const { + + +QString OTodo::toShortText() const +{ return summary(); } + + /*! Returns a richt text string */ QString OTodo::toRichText() const @@ -307,15 +409,17 @@ QString OTodo::toRichText() const QStringList catlist; // summary text += "<b><h3><img src=\"todo/TodoList\"> "; - if ( !summary().isEmpty() ) { + if ( !summary().isEmpty() ) + { text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); } text += "</h3></b><br><hr><br>"; // description - if( !description().isEmpty() ){ + if ( !description().isEmpty() ) + { text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; } @@ -343,9 +447,10 @@ QString OTodo::toRichText() const text += "<b>" + QObject::tr( "Progress:") + " </b>" + QString::number( progress() ) + " %<br>"; // due date - if (hasDueDate() ){ + if ( hasDueDate() ) + { QDate dd = dueDate(); int off = QDate::currentDate().daysTo( dd ); text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; @@ -365,75 +470,110 @@ QString OTodo::toRichText() const text += "<br>"; return text; } -bool OTodo::hasNotifiers()const { + + +bool OTodo::hasNotifiers() const +{ if (!data->notifiers) return false; return !data->notifiers->isEmpty(); } -OPimNotifyManager& OTodo::notifiers() { + + +OPimNotifyManager& OTodo::notifiers() +{ if (!data->notifiers ) data->notifiers = new OPimNotifyManager; return (*data->notifiers); } -const OPimNotifyManager& OTodo::notifiers()const{ + + +const OPimNotifyManager& OTodo::notifiers() const +{ if (!data->notifiers ) data->notifiers = new OPimNotifyManager; return (*data->notifiers); } -bool OTodo::operator<( const OTodo &toDoEvent )const{ + +bool OTodo::operator<( const OTodo &toDoEvent ) const +{ if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; - if( hasDueDate() && toDoEvent.hasDueDate() ){ - if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide return priority() < toDoEvent.priority(); - }else{ + } + else + { return dueDate() < toDoEvent.dueDate(); } } return false; } + + bool OTodo::operator<=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; - if( hasDueDate() && toDoEvent.hasDueDate() ){ - if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide return priority() <= toDoEvent.priority(); - }else{ + } + else + { return dueDate() <= toDoEvent.dueDate(); } } return true; } + + bool OTodo::operator>(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; - if( hasDueDate() && toDoEvent.hasDueDate() ){ - if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide return priority() > toDoEvent.priority(); - }else{ + } + else + { return dueDate() > toDoEvent.dueDate(); } } return false; } + + bool OTodo::operator>=(const OTodo &toDoEvent )const { if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; - if( hasDueDate() && toDoEvent.hasDueDate() ){ - if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide return priority() > toDoEvent.priority(); - }else{ + } + else + { return dueDate() > toDoEvent.dueDate(); } } return true; } + + bool OTodo::operator==(const OTodo &toDoEvent )const { if ( data->priority != toDoEvent.data->priority ) return false; if ( data->priority != toDoEvent.data->prog ) return false; @@ -446,17 +586,23 @@ bool OTodo::operator==(const OTodo &toDoEvent )const return false; return OPimRecord::operator==( toDoEvent ); } -void OTodo::deref() { + + +void OTodo::deref() +{ // qWarning("deref in ToDoEvent"); - if ( data->deref() ) { + if ( data->deref() ) + { // qWarning("deleting"); delete data; data= 0; } } + + OTodo &OTodo::operator=(const OTodo &item ) { if ( this == &item ) return *this; @@ -468,9 +614,11 @@ OTodo &OTodo::operator=(const OTodo &item ) return *this; } -QMap<int, QString> OTodo::toMap() const { + +QMap<int, QString> OTodo::toMap() const +{ QMap<int, QString> map; map.insert( Uid, QString::number( uid() ) ); map.insert( Category, idsToString( categories() ) ); @@ -491,28 +639,34 @@ QMap<int, QString> OTodo::toMap() const { */ return map; } + /** * change or modify looks at the ref count and either * creates a new QShared Object or it can modify it * right in place */ -void OTodo::changeOrModify() { - if ( data->count != 1 ) { +void OTodo::changeOrModify() +{ + if ( data->count != 1 ) + { qWarning("changeOrModify"); data->deref(); OTodoData* d2 = new OTodoData(); copy(data, d2 ); data = d2; } } + + // WATCHOUT /* * if you add something to the Data struct * be sure to copy it here */ -void OTodo::copy( OTodoData* src, OTodoData* dest ) { +void OTodo::copy( OTodoData* src, OTodoData* dest ) +{ dest->date = src->date; dest->isCompleted = src->isCompleted; dest->hasDate = src->hasDate; dest->priority = src->priority; @@ -535,16 +689,24 @@ void OTodo::copy( OTodoData* src, OTodoData* dest ) { if (src->notifiers ) dest->notifiers = new OPimNotifyManager( *src->notifiers ); } -QString OTodo::type() const { + + +QString OTodo::type() const +{ return QString::fromLatin1("OTodo"); } -QString OTodo::recordField(int /*id*/ )const { + + +QString OTodo::recordField( int /*id*/ ) const +{ return QString::null; } -int OTodo::rtti(){ + +int OTodo::rtti() +{ return OPimResolver::TodoList; } } diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h index 61add04..04dd269 100644 --- a/libopie2/opiepim/otodo.h +++ b/libopie2/opiepim/otodo.h @@ -25,32 +25,34 @@ If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef OPIE_TODO_EVENT_H -#define OPIE_TODO_EVENT_H +#ifndef OTODOEVENT_H +#define OTODOEVENT_H +/* OPIE */ +#include <opie2/opimrecord.h> +#include <qpe/recordfields.h> +#include <qpe/palmtopuidgen.h> + +/* QT */ #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 <opie2/opimrecord.h> - - -namespace Opie { +namespace Opie +{ class OPimState; class ORecur; class OPimMaintainer; class OPimNotifyManager; -class OTodo : public OPimRecord { +class OTodo : public OPimRecord +{ public: typedef QValueList<OTodo> ValueList; enum RecordFields { Uid = Qtopia::UID_ID, @@ -305,9 +307,12 @@ public: OTodoPrivate *d; OTodoData *data; }; -inline bool OTodo::operator!=(const OTodo &toDoEvent )const { + + +inline bool OTodo::operator!=( const OTodo &toDoEvent ) const +{ return !(*this == toDoEvent); } } |