summaryrefslogtreecommitdiff
authorzecke <zecke>2004-11-18 21:45:49 (UTC)
committer zecke <zecke>2004-11-18 21:45:49 (UTC)
commit7484344ff5be1f7c54e51715776d0e3cadeb1ed0 (patch) (side-by-side diff)
tree96f427f7a1fb1c8ca0a6efbd72b51e916cb1651d
parent3302eb30390e6053637929316670da3e8fbe279e (diff)
downloadopie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.zip
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.gz
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.bz2
Big PIM API Update Core Part (1/2 of what should be implemented):
OPimRecords: -Add a so called safeCast using the rtti value OPimTodo: -Fix memleak with OPimState OPimOccurrence: -New class. Every 'Access' can give occurrences for a period of time Move Documentation
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/core.pro3
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp7
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h47
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp35
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h9
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h345
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp24
-rw-r--r--libopie2/opiepim/core/opimcontact.h4
-rw-r--r--libopie2/opiepim/core/opimevent.cpp19
-rw-r--r--libopie2/opiepim/core/opimevent.h22
-rw-r--r--libopie2/opiepim/core/opimglobal.h12
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp5
-rw-r--r--libopie2/opiepim/core/opimoccurrence.cpp319
-rw-r--r--libopie2/opiepim/core/opimoccurrence.h142
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp23
-rw-r--r--libopie2/opiepim/core/opimrecord.h9
-rw-r--r--libopie2/opiepim/core/opimrecordlist.h15
-rw-r--r--libopie2/opiepim/core/opimresolver.h2
-rw-r--r--libopie2/opiepim/core/opimstate.h6
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.cpp112
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h135
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp44
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp127
-rw-r--r--libopie2/opiepim/core/opimtodo.h11
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp23
-rw-r--r--libopie2/opiepim/core/otodoaccess.h36
26 files changed, 1226 insertions, 310 deletions
diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro
index b1b5655..f943318 100644
--- a/libopie2/opiepim/core/core.pro
+++ b/libopie2/opiepim/core/core.pro
@@ -1,48 +1,51 @@
HEADERS += \
core/ocontactaccess.h \
core/odatebookaccess.h \
core/opimaccessfactory.h \
core/opimaccesstemplate.h \
core/opimcache.h \
core/opimcontactfields.h \
core/opimcontact.h \
core/opimdateconversion.h \
core/opimevent.h \
core/opimglobal.h \
core/opimmaintainer.h \
core/opimnotify.h \
core/opimnotifymanager.h \
+ core/opimoccurrence.h \
core/opimrecord.h \
core/opimrecordlist.h \
core/opimrecurrence.h \
core/opimresolver.h \
core/opimstate.h \
core/opimtemplatebase.h \
core/opimtimezone.h \
core/opimtodo.h \
core/opimxref.h \
core/opimxrefmanager.h \
core/opimxrefpartner.h \
core/otodoaccess.h
SOURCES += \
core/ocontactaccess.cpp \
core/odatebookaccess.cpp \
core/opimcontactfields.cpp \
core/opimcontact.cpp \
core/opimdateconversion.cpp \
core/opimevent.cpp \
core/opimmaintainer.cpp \
core/opimnotify.cpp \
core/opimnotifymanager.cpp \
+ core/opimoccurrence.cpp \
core/opimrecord.cpp \
core/opimrecurrence.cpp \
core/opimresolver.cpp \
core/opimstate.cpp \
+ core/opimtemplatebase.cpp \
core/opimtimezone.cpp \
core/opimtodo.cpp \
core/opimxref.cpp \
core/opimxrefmanager.cpp \
core/opimxrefpartner.cpp \
core/otodoaccess.cpp
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 771d855..9bbc820 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,164 +1,163 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
* =====================================================================
* ToDo: XML-Backend: Automatic reload if something was changed...
*
*
*/
#include <opie2/ocontactaccess.h>
#include <opie2/obackendfactory.h>
/* OPIE */
#include <opie2/ocontactaccessbackend_xml.h>
#include <opie2/opimresolver.h>
#include <opie2/opimglobal.h>
#include <opie2/odebug.h>
//#include <qpe/qcopenvelope_qws.h>
#include <qpe/global.h>
/* QT */
#include <qasciidict.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qregexp.h>
#include <qlist.h>
#include <qcopchannel_qws.h>
/* STD */
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
namespace Opie {
OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
OPimContactAccessBackend* end, bool autosync ):
OPimAccessTemplate<OPimContact>( end )
{
/* 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 ) {
- owarn << "Using BackendFactory !" << oendl;
end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
}
// Set backend locally and in template
m_backEnd = end;
OPimAccessTemplate<OPimContact>::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&)) );
}
}
OPimContactAccess::~OPimContactAccess ()
{
/* 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 OPimContactAccess::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<OPimContact>::wasChangedExternally() )
reload();
bool status = OPimAccessTemplate<OPimContact>::save();
if ( !status ) return false;
/* Now tell everyone that new data is available.
*/
QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
return true;
}
const uint OPimContactAccess::querySettings()
{
return ( m_backEnd->querySettings() );
}
bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
{
return ( m_backEnd->hasQuerySettings ( querySettings ) );
}
+
+#if 0
OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
{
QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
return ( OPimRecordList<OPimContact>(matchingContacts, this) );
}
+#endif
bool OPimContactAccess::wasChangedExternally()const
{
return ( m_backEnd->wasChangedExternally() );
}
void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
{
if ( msg == "addressbookUpdated()" ){
- owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl;
emit signalChanged ( this );
} else if ( msg == "flush()" ) {
- owarn << "OPimContactAccess: Received flush()" << oendl;
save ();
} else if ( msg == "reload()" ) {
- owarn << "OPimContactAccess: Received reload()" << oendl;
reload ();
emit signalChanged ( this );
}
}
int OPimContactAccess::rtti() const
{
return OPimResolver::AddressBook;
}
}
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 4429b6f..691ece2 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -1,163 +1,156 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
* =====================================================================
* ToDo: Define enum for query settings
* =====================================================================
*/
#ifndef _OCONTACTACCESS_H
#define _OCONTACTACCESS_H
#include <qobject.h>
#include <qpe/qcopenvelope_qws.h>
#include <qvaluelist.h>
#include <qfileinfo.h>
#include <opie2/opimcontact.h>
#include <opie2/ocontactaccessbackend.h>
#include <opie2/opimaccesstemplate.h>
namespace Opie {
/**
* 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.
* @author Stefan Eilers, Holger Freyther
* @see OPimAccessTemplate
*/
class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
{
Q_OBJECT
public:
+ enum SortFilter {
+ DoNotShowNoneChildren = FilterCustom<<1,
+ DoNotShowNoneAnniversary = FilterCustom<<2,
+ DoNotShowNoneBirthday = FilterCustom<<3,
+ DoNotShowNoHomeAddress = FilterCustom<<4,
+ DoNotShowNoBusinessAddress = FilterCustom<<5
+ };
+
+ enum SortOrder {
+ SortTitle = SortCustom,
+ SortFirstName,
+ SortMiddleName,
+ SortSuffix,
+ SortEmail,
+ SortNickname,
+ SortAnniversary,
+ SortBirthday,
+ SortGender
+ };
+
/**
* 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 OPimContactAccessBackend
*/
OPimContactAccess (const QString appname, const QString filename = 0l,
OPimContactAccessBackend* backend = 0l, bool handlesync = true);
~OPimContactAccess ();
- /** 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
- };
-
-
- /** 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();
/**
* Return identification of used records
*/
int rtti() const;
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 OPimContactAccess *which );
private:
- // class OPimContactAccessPrivate;
- // OPimContactAccessPrivate* d;
OPimContactAccessBackend *m_backEnd;
bool m_loading:1;
private slots:
void copMessage( const QCString &msg, const QByteArray &data );
private:
class Private;
Private *d;
};
}
#endif
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index 440ee0a..32fbb7d 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -1,118 +1,95 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/obackendfactory.h>
#include <opie2/odatebookaccess.h>
#include <opie2/opimresolver.h>
#include <opie2/opimglobal.h>
namespace Opie {
/**
* Simple constructor
* It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation
* will be used!
* @param back The backend to be used or 0 for the default backend
* @param ac What kind of access is intended
*/
-ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
+ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access )
: OPimAccessTemplate<OPimEvent>( back )
{
if (!back )
back = OBackendFactory<ODateBookAccessBackend>::defaultBackend( OPimGlobal::DATEBOOK, QString::null );
m_backEnd = back;
setBackEnd( m_backEnd );
}
ODateBookAccess::~ODateBookAccess() {
}
-/**
- * @return all events available
- */
-ODateBookAccess::List ODateBookAccess::rawEvents()const {
- QArray<int> ints = m_backEnd->rawEvents();
-
- List lis( ints, this );
- return lis;
-}
/**
* @return all repeating events
*/
ODateBookAccess::List ODateBookAccess::rawRepeats()const {
QArray<int> ints = m_backEnd->rawRepeats();
List lis( ints, this );
return lis;
}
/**
* @return all non repeating events
*/
ODateBookAccess::List ODateBookAccess::nonRepeats()const {
QArray<int> ints = m_backEnd->nonRepeats();
List lis( ints, this );
return lis;
}
/**
- * @return dates in the time span between from and to
- * @param from Include all events from...
- * @param to Include all events to...
- */
-OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const {
- return m_backEnd->effectiveEvents( from, to );
-}
-/**
- * @return all events at a given datetime
- */
-OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const {
- return m_backEnd->effectiveEvents( start );
-}
-
-/**
* @return non repeating dates in the time span between from and to
* @param from Include all events from...
* @param to Include all events to...
*/
-OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const {
- return m_backEnd->effectiveNonRepeatingEvents( from, to );
+OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const {
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( from, to ) );
}
/**
* @return all non repeating events at a given datetime
*/
-OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
- return m_backEnd->effectiveNonRepeatingEvents( start );
+OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( start ) );
}
+
int ODateBookAccess::rtti() const
{
return OPimResolver::DateBook;
}
}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index c6c3598..0be8606 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -1,81 +1,76 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIE_DATE_BOOK_ACCESS_H
#define OPIE_DATE_BOOK_ACCESS_H
#include "odatebookaccessbackend.h"
#include "opimaccesstemplate.h"
#include <opie2/opimevent.h>
namespace Opie {
/**
* This is the object orientated datebook database. It'll use OBackendFactory
* to query for a backend.
* All access to the datebook should be done via this class.
* Make sure to load and save the datebook this is not part of
* destructing and creating the object
*
* @author Holger Freyther, Stefan Eilers
*/
class ODateBookAccess : public OPimAccessTemplate<OPimEvent> {
public:
ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
~ODateBookAccess();
- /* return all events */
- List rawEvents()const;
-
/* return repeating events */
List rawRepeats()const;
/* return non repeating events */
List nonRepeats()const;
/* return non repeating events (from,to) */
- OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const;
- OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const;
- OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
- OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const;
+ OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
+ OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const;
/**
* Return identification of used records
*/
int rtti() const;
private:
ODateBookAccessBackend* m_backEnd;
class Private;
Private* d;
};
}
#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f936d4e..2deb92a 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,373 +1,522 @@
/*
This file is part of the Opie Project
Copyright (C) Holger Freyther <zecke@handhelds.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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
#define OPIE_PIM_ACCESS_TEMPLATE_H
/* OPIE */
#include <opie2/opimrecord.h>
#include <opie2/opimaccessbackend.h>
#include <opie2/opimrecordlist.h>
#include <opie2/opimtemplatebase.h>
#include <opie2/odebug.h>
/* QT */
#include <qarray.h>
+#include <qdatetime.h>
namespace Opie {
class OPimAccessTemplatePrivate;
/**
* 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 templates
*/
template <class T = OPimRecord >
class OPimAccessTemplate : public OTemplateBase<T> {
public:
+ /**
+ *
+ */
enum Access {
Random = 0,
SortedAccess
};
typedef OPimRecordList<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();
+ void clear() ;
+ //@}
+
- /**
- * 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
- */
- T find( int uid )const;
-
- /**
- * read ahead cache find method ;)
- */
- T find( int uid, const QArray<int>&,
+ virtual T find( UID uid )const;
+ virtual T find( UID uid, const QArray<int>&,
uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
+ virtual List sorted( const List&, bool ascending, int sortOrder,
+ int sortFilter, int cat )const;
+ virtual List sorted( const List&, bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const;
+ virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const;
+ virtual List sorted( bool ascending, int sortOrder, int sortOrder,
+ const QArray<UID>& cats )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.
+ * (Re)Implementation
*/
+ //@{
+ UIDArray matchRegexpSimple( const QRegExp& r )const;
+ UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const;
+ UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
+ int sortFilter, int cat )const;
+ UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
+ int sortFilter, const QArray<int>& )const;
+ UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
+ int cat )const;
+ UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
+ const QArray<int>& )const;
+ OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const;
+ OPimOccurrence::List occurrences( const QDateTime& dt )const;
+ //@}
+
+ //@{
virtual bool add( const T& t ) ;
-
bool add( const OPimRecord& );
- /**
- * Add an Opie PimRecord.
- * Info: Take this if you are working with OPimRecords and you need to add it into any database.
- * But take care that the accessing database is compatible to the real type of OPimRecord !!
- * Otherwise this access will be rejected !
- */
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( UID 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
- */
+ virtual T cacheFind( int uid )const;
void cache( const T& )const;
void setSaneCacheSize( int );
- QArray<int> records()const;
+ QArray<UID> records()const;
protected:
/**
* invalidate the cache
*/
void invalidateCache();
void setBackEnd( BackEnd* end );
/**
* returns the backend
*/
BackEnd* backEnd();
BackEnd* m_backEnd;
Cache m_cache;
private:
OPimAccessTemplatePrivate *d;
};
+/**
+ * c'tor BackEnd
+ * enum Access a small hint on how to handle the backend
+ */
template <class T>
OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
: OTemplateBase<T>(), m_backEnd( end )
{
if (end )
end->setFrontend( this );
}
template <class T>
OPimAccessTemplate<T>::~OPimAccessTemplate() {
- owarn << "~OPimAccessTemplate<T>" << oendl;
delete m_backEnd;
}
+
+/**
+ * load from the backend
+ */
template <class T>
bool OPimAccessTemplate<T>::load() {
invalidateCache();
return m_backEnd->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.
+ */
template <class T>
bool OPimAccessTemplate<T>::reload() {
invalidateCache();
return m_backEnd->reload();
}
+
+/**
+ * Save contacts database.
+ * Save is more a "commit". After calling this function, all changes are public available.
+ * @return true if successful
+ */
template <class T>
bool OPimAccessTemplate<T>::save() {
return m_backEnd->save();
}
+
+
+/**
+ * return a List of records
+ * you can iterate over them
+ */
template <class T>
typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
QArray<int> ints = m_backEnd->allRecords();
List lis(ints, this );
return lis;
}
+
+/**
+ * return a List of records
+ * that match the regex
+ */
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;
}
+
+/**
+ * find the OPimRecord uid
+ */
template <class T>
QArray<int> OPimAccessTemplate<T>::records()const {
return m_backEnd->allRecords();
}
+
+
+/**
+ * queryByExample.
+ * @see otodoaccess, ocontactaccess
+ */
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 OPimAccessTemplate<T>::find( UID uid ) const{
// First search in cache..
if ( m_cache.contains( uid ) )
return m_cache.find( uid );
T t = m_backEnd->find( uid );
cache( t );
return t;
}
template <class T>
-T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
+T OPimAccessTemplate<T>::cacheFind( int uid ) const
+{
+ return m_cache.find( uid );
+}
+
+/**
+ * read ahead cache find method ;)
+ */
+template <class T>
+T OPimAccessTemplate<T>::find( UID 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...
*/
- // owarn << "find it now " << uid << oendl;
- if ( m_cache.contains( uid ) ) {
+ if (m_cache.contains( uid ) )
return m_cache.find( uid );
- }
+
T t = m_backEnd->find( uid, ar, current, dir );
cache( t );
return t;
}
+
+/**
+ * clears the backend and invalidates the backend
+ */
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
m_backEnd->clear();
}
+
+
+/**
+ * add T to the backend
+ * @param t The item to add.
+ * @return <i>true</i> if added successfully.
+ */
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 */
T tempInstance;
if ( rec.rtti() == tempInstance.rtti() ) {
const T& t = static_cast<const T&>(rec);
return add(t);
} else {
owarn << "Adding not possible: Objecttype mismatch" << oendl;
}
return false;
}
+/**
+ * Add an Opie PimRecord.
+ * Info: Take this if you are working with OPimRecords and you need to add it into any database.
+ * But take care that the accessing database is compatible to the real type of OPimRecord !!
+ * Otherwise this access will be rejected !
+ */
template <class T>
bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
/* same type, but pointer */
T tempInstance;
if ( rec -> rtti() == tempInstance.rtti() ) {
const T* t = static_cast<const T*>(rec);
return add( *t );
} else {
owarn << "Adding not possible: Objecttype mismatch" << oendl;
}
return false;
}
+/**
+ * remove T from the backend
+ * @param t The item to remove
+ * @return <i>true</i> if successful.
+ */
template <class T>
bool OPimAccessTemplate<T>::remove( const T& t ) {
return remove( t.uid() );
}
+
+/**
+ * remove the OPimRecord with uid
+ * @param uid The ID of the item to remove
+ * @return <i>true</i> if successful.
+ */
template <class T>
-bool OPimAccessTemplate<T>::remove( int uid ) {
+bool OPimAccessTemplate<T>::remove( UID uid ) {
m_cache.remove( uid );
return m_backEnd->remove( uid );
}
template <class T>
bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
return remove( rec.uid() );
}
+
+/**
+ * replace T from backend
+ * @param t The item to replace
+ * @return <i>true</i> if successful.
+ */
template <class T>
bool OPimAccessTemplate<T>::replace( const T& t ) {
m_cache.replace( t );
return m_backEnd->replace( t );
}
+
+/**
+ * @internal
+ */
template <class T>
void OPimAccessTemplate<T>::invalidateCache() {
m_cache.invalidate();
}
template <class T>
typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
return m_backEnd;
}
+
+/**
+ * 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 ?
+ */
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 );
}
+
+template <class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
+ bool ascending, int sortOrder,
+ int sortFilter, int cat )const {
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
+ bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const {
+ UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
+ int sortFilter, int cat )const {
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template<class T>
+typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
+ int sortFilter, const QArray<UID>& cats )const {
+ UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
+ sortFilter, cats );
+ return List(ints, this);
+}
+
+template <class T>
+OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start,
+ const QDate& end ) const {
+ /*
+ * Some magic involved to go from single OPimBackendOccurrence
+ * to multiple OPimOccurrence's
+ */
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) );
+}
+
+template<class T>
+OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const {
+ return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) );
+}
+
+/*
+ *Implementations!!
+ */
+template <class T>
+UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const {
+ return m_backEnd->matchRegexp( r );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec,
+ int settings,
+ const QDateTime& d )const {
+ return m_backEnd->queryByExample( rec, settings, d );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
+ bool ascending,
+ int sortOrder, int sortFilter,
+ int cat ) const{
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+ return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
+ bool ascending,
+ int sortOrder, int sortFilter,
+ const QArray<int>& cats ) const{
+ return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
+ int sortOrder, int sortFilter,
+ int cat ) const{
+ QArray<int> cats( 1 );
+ cats[0] = cat;
+
+ return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
+}
+
+template <class T>
+UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
+ int sortOrder, int sortFilter,
+ const QArray<int>& cats ) const{
+ return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
+}
}
#endif
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index 36e9a93..64f195b 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -1,596 +1,595 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#define QTOPIA_INTERNAL_CONTACT_MRE
#include "opimcontact.h"
/* OPIE */
#include <opie2/opimresolver.h>
#include <opie2/opimdateconversion.h>
#include <opie2/odebug.h>
#include <qpe/stringutil.h>
#include <qpe/timestring.h>
#include <qpe/config.h>
/* QT */
#include <qstylesheet.h>
/* STD */
#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
*/
namespace Opie
{
/*!
Creates a new, empty contact.
*/
OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
{}
/*!
\internal
Creates a new contact. The properties of the contact are
set from \a fromMap.
*/
OPimContact::OPimContact( 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 ) )
{
- owarn << "Invalid UID found. Generate new one.." << oendl;
setUid( uidGen().generate() );
}
else
setUid( uidStr.toInt() );
// if ( !uidStr.isEmpty() )
// setUid( uidStr.toInt() );
}
/*!
Destroys a contact.
*/
OPimContact::~OPimContact()
{}
/*! \fn void OPimContact::setTitle( const QString &str )
Sets the title of the contact to \a str.
*/
/*! \fn void OPimContact::setFirstName( const QString &str )
Sets the first name of the contact to \a str.
*/
/*! \fn void OPimContact::setMiddleName( const QString &str )
Sets the middle name of the contact to \a str.
*/
/*! \fn void OPimContact::setLastName( const QString &str )
Sets the last name of the contact to \a str.
*/
/*! \fn void OPimContact::setSuffix( const QString &str )
Sets the suffix of the contact to \a str.
*/
/*! \fn void OPimContact::setFileAs( const QString &str )
Sets the contact to filed as \a str.
*/
/*! \fn void OPimContact::setDefaultEmail( const QString &str )
Sets the default email of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeStreet( const QString &str )
Sets the home street address of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeCity( const QString &str )
Sets the home city of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeState( const QString &str )
Sets the home state of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeZip( const QString &str )
Sets the home zip code of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeCountry( const QString &str )
Sets the home country of the contact to \a str.
*/
/*! \fn void OPimContact::setHomePhone( const QString &str )
Sets the home phone number of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeFax( const QString &str )
Sets the home fax number of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeMobile( const QString &str )
Sets the home mobile phone number of the contact to \a str.
*/
/*! \fn void OPimContact::setHomeWebpage( const QString &str )
Sets the home webpage of the contact to \a str.
*/
/*! \fn void OPimContact::setCompany( const QString &str )
Sets the company for contact to \a str.
*/
/*! \fn void OPimContact::setJobTitle( const QString &str )
Sets the job title of the contact to \a str.
*/
/*! \fn void OPimContact::setDepartment( const QString &str )
Sets the department for contact to \a str.
*/
/*! \fn void OPimContact::setOffice( const QString &str )
Sets the office for contact to \a str.
*/
/*! \fn void OPimContact::setBusinessStreet( const QString &str )
Sets the business street address of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessCity( const QString &str )
Sets the business city of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessState( const QString &str )
Sets the business state of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessZip( const QString &str )
Sets the business zip code of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessCountry( const QString &str )
Sets the business country of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessPhone( const QString &str )
Sets the business phone number of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessFax( const QString &str )
Sets the business fax number of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessMobile( const QString &str )
Sets the business mobile phone number of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessPager( const QString &str )
Sets the business pager number of the contact to \a str.
*/
/*! \fn void OPimContact::setBusinessWebpage( const QString &str )
Sets the business webpage of the contact to \a str.
*/
/*! \fn void OPimContact::setProfession( const QString &str )
Sets the profession of the contact to \a str.
*/
/*! \fn void OPimContact::setAssistant( const QString &str )
Sets the assistant of the contact to \a str.
*/
/*! \fn void OPimContact::setManager( const QString &str )
Sets the manager of the contact to \a str.
*/
/*! \fn void OPimContact::setSpouse( const QString &str )
Sets the spouse of the contact to \a str.
*/
/*! \fn void OPimContact::setGender( const QString &str )
Sets the gender of the contact to \a str.
*/
/*! \fn void OPimContact::setNickname( const QString &str )
Sets the nickname of the contact to \a str.
*/
/*! \fn void OPimContact::setNotes( const QString &str )
Sets the notes about the contact to \a str.
*/
/*! \fn QString OPimContact::title() const
Returns the title of the contact.
*/
/*! \fn QString OPimContact::firstName() const
Returns the first name of the contact.
*/
/*! \fn QString OPimContact::middleName() const
Returns the middle name of the contact.
*/
/*! \fn QString OPimContact::lastName() const
Returns the last name of the contact.
*/
/*! \fn QString OPimContact::suffix() const
Returns the suffix of the contact.
*/
/*! \fn QString OPimContact::fileAs() const
Returns the string the contact is filed as.
*/
/*! \fn QString OPimContact::defaultEmail() const
Returns the default email address of the contact.
*/
/*! \fn QString OPimContact::emails() const
Returns the list of email address for a contact separated by ';'s in a single
string.
*/
/*! \fn QString OPimContact::homeStreet() const
Returns the home street address of the contact.
*/
/*! \fn QString OPimContact::homeCity() const
Returns the home city of the contact.
*/
/*! \fn QString OPimContact::homeState() const
Returns the home state of the contact.
*/
/*! \fn QString OPimContact::homeZip() const
Returns the home zip of the contact.
*/
/*! \fn QString OPimContact::homeCountry() const
Returns the home country of the contact.
*/
/*! \fn QString OPimContact::homePhone() const
Returns the home phone number of the contact.
*/
/*! \fn QString OPimContact::homeFax() const
Returns the home fax number of the contact.
*/
/*! \fn QString OPimContact::homeMobile() const
Returns the home mobile number of the contact.
*/
/*! \fn QString OPimContact::homeWebpage() const
Returns the home webpage of the contact.
*/
/*! \fn QString OPimContact::company() const
Returns the company for the contact.
*/
/*! \fn QString OPimContact::department() const
Returns the department for the contact.
*/
/*! \fn QString OPimContact::office() const
Returns the office for the contact.
*/
/*! \fn QString OPimContact::jobTitle() const
Returns the job title of the contact.
*/
/*! \fn QString OPimContact::profession() const
Returns the profession of the contact.
*/
/*! \fn QString OPimContact::assistant() const
Returns the assistant of the contact.
*/
/*! \fn QString OPimContact::manager() const
Returns the manager of the contact.
*/
/*! \fn QString OPimContact::businessStreet() const
Returns the business street address of the contact.
*/
/*! \fn QString OPimContact::businessCity() const
Returns the business city of the contact.
*/
/*! \fn QString OPimContact::businessState() const
Returns the business state of the contact.
*/
/*! \fn QString OPimContact::businessZip() const
Returns the business zip of the contact.
*/
/*! \fn QString OPimContact::businessCountry() const
Returns the business country of the contact.
*/
/*! \fn QString OPimContact::businessPhone() const
Returns the business phone number of the contact.
*/
/*! \fn QString OPimContact::businessFax() const
Returns the business fax number of the contact.
*/
/*! \fn QString OPimContact::businessMobile() const
Returns the business mobile number of the contact.
*/
/*! \fn QString OPimContact::businessPager() const
Returns the business pager number of the contact.
*/
/*! \fn QString OPimContact::businessWebpage() const
Returns the business webpage of the contact.
*/
/*! \fn QString OPimContact::spouse() const
Returns the spouse of the contact.
*/
/*! \fn QString OPimContact::gender() const
Returns the gender of the contact.
*/
/*! \fn QString OPimContact::nickname() const
Returns the nickname of the contact.
*/
/*! \fn QString OPimContact::children() const
Returns the children of the contact.
*/
/*! \fn QString OPimContact::notes() const
Returns the notes relating to the the contact.
*/
/*! \fn QString OPimContact::groups() const
\internal
Returns the groups for the contact.
*/
/*! \fn QStringList OPimContact::groupList() const
\internal
*/
/*! \fn QString OPimContact::field(int) const
\internal
*/
/*! \fn void OPimContact::saveJournal( journal_action, const QString & = QString::null )
\internal
*/
/*! \fn void OPimContact::setUid( int id )
\internal
Sets the uid for this record to \a id.
*/
/*! \enum OPimContact::journal_action
\internal
*/
/*!
\internal
*/
QMap<int, QString> OPimContact::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 OPimContact::toRichText() const
{
QString text;
QString value, comp, state;
QString str;
bool marker = false;
Config cfg( "qpe" );
cfg.setGroup( "Appearance" );
int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
// name, jobtitle and company
if ( !( value = fullName() ).isEmpty() )
text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>";
if ( !( value = jobTitle() ).isEmpty() )
text += Qtopia::escapeString( value ) + " ";
comp = company();
if ( !( value = department() ).isEmpty() )
{
text += Qtopia::escapeString( value );
if ( comp )
text += ", " + Qtopia::escapeString( comp );
}
else if ( comp )
text += "<br>" + Qtopia::escapeString( comp );
text += "<br><hr>";
// defailt email
QString defEmail = defaultEmail();
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() )
{
text += QObject::tr( "<br><b>Work Address:</b>" );
marker = true;
}
if ( !( value = businessStreet() ).isEmpty() )
{
text += "<br>" + Qtopia::escapeString( value );
marker = true;
}
switch ( addressformat )
{
case Zip_City_State:
{ // Zip_Code City, State
state = businessState();
if ( !( value = businessZip() ).isEmpty() )
{
text += "<br>" + Qtopia::escapeString( value ) + " ";
marker = true;
}
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() )
{
text += "<br>" + Qtopia::escapeString( state );
marker = true;
}
break;
}
case City_State_Zip:
{ // City, State Zip_Code
state = businessState();
if ( !( value = businessCity() ).isEmpty() )
{
marker = true;
text += "<br>" + Qtopia::escapeString( value );
if ( state )
text += ", " + Qtopia::escapeString( state );
}
else if ( !state.isEmpty() )
{
text += "<br>" + Qtopia::escapeString( state );
marker = true;
}
if ( !( value = businessZip() ).isEmpty() )
{
text += " " + Qtopia::escapeString( value );
marker = true;
}
break;
}
}
if ( !( value = businessCountry() ).isEmpty() )
{
text += "<br>" + Qtopia::escapeString( value );
marker = true;
}
// rest of Business data
str = office();
if ( !str.isEmpty() )
{
text += "<br><b>" + QObject::tr( "Office: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
}
str = businessWebpage();
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() )
{
text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
}
str = businessFax();
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() )
{
text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
}
str = businessPager();
if ( !str.isEmpty() )
{
text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
@@ -629,663 +628,678 @@ QString OPimContact::toRichText() const
text += "<br>";
text += Qtopia::escapeString( value );
if ( !state.isEmpty() )
text += ", " + Qtopia::escapeString( state );
}
else if ( !state.isEmpty() )
{
text += "<br>" + Qtopia::escapeString( state );
marker = true;
}
break;
}
case City_State_Zip:
{ // City, State Zip_Code
state = homeState();
if ( !( value = homeCity() ).isEmpty() )
{
marker = true;
text += "<br>" + Qtopia::escapeString( value );
if ( state )
text += ", " + Qtopia::escapeString( state );
}
else if ( !state.isEmpty() )
{
text += "<br>" + Qtopia::escapeString( state );
marker = true;
}
if ( !( value = homeZip() ).isEmpty() )
{
text += " " + Qtopia::escapeString( value );
marker = true;
}
break;
}
}
if ( !( value = homeCountry() ).isEmpty() )
{
text += "<br>" + Qtopia::escapeString( value );
marker = true;
}
// rest of Home data
str = homeWebpage();
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() )
{
text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
}
str = homeFax();
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() )
{
text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>"
+ Qtopia::escapeString( str );
marker = true;
}
if ( marker )
text += "<br><hr>";
// the rest...
str = emails();
if ( !str.isEmpty() && ( str != defEmail ) )
text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>"
+ Qtopia::escapeString( str );
str = profession();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>"
+ Qtopia::escapeString( str );
str = assistant();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>"
+ Qtopia::escapeString( str );
str = manager();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>"
+ Qtopia::escapeString( str );
str = gender();
if ( !str.isEmpty() && str.toInt() != 0 )
{
text += "<br>";
if ( str.toInt() == 1 )
str = QObject::tr( "Male" );
else if ( str.toInt() == 2 )
str = QObject::tr( "Female" );
text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str;
}
str = spouse();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>"
+ Qtopia::escapeString( str );
if ( birthday().isValid() )
{
str = TimeString::numberDateString( birthday() );
text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>"
+ Qtopia::escapeString( str );
}
if ( anniversary().isValid() )
{
str = TimeString::numberDateString( anniversary() );
text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>"
+ Qtopia::escapeString( str );
}
str = children();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Children: " ) + "</b>"
+ Qtopia::escapeString( str );
str = nickname();
if ( !str.isEmpty() )
text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>"
+ Qtopia::escapeString( str );
// categories
if ( categoryNames( "Contacts" ).count() )
{
text += "<br><b>" + QObject::tr( "Category:" ) + "</b> ";
text += categoryNames( "Contacts" ).join( ", " );
}
// 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 OPimContact::insert( int key, const QString &v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.insert( key, value );
}
/*!
\internal
*/
void OPimContact::replace( int key, const QString & v )
{
QString value = v.stripWhiteSpace();
if ( value.isEmpty() )
mMap.remove( key );
else
mMap.replace( key, value );
}
/*!
\internal
*/
QString OPimContact::find( int key ) const
{
return mMap[ key ];
}
/*!
\internal
*/
QString OPimContact::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 OPimContact::displayBusinessAddress() const
{
return displayAddress( businessStreet(), businessCity(),
businessState(), businessZip(),
businessCountry() );
}
/*!
\internal
*/
QString OPimContact::displayHomeAddress() const
{
return displayAddress( homeStreet(), homeCity(),
homeState(), homeZip(),
homeCountry() );
}
/*!
Returns the full name of the contact
*/
QString OPimContact::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 OPimContact::childrenList() const
{
return QStringList::split( " ", find( Qtopia::Children ) );
}
/*! \fn void OPimContact::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 OPimContact::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 OPimContact::clearEmails()
Clears the email list.
*/
/*! \fn void OPimContact::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 OPimContact::emailList() const
{
QString emailStr = emails();
QStringList r;
if ( !emailStr.isEmpty() )
{
odebug << " emailstr " << oendl;
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 OPimContact::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 OPimContact::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 OPimContact::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 OPimContact::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 OPimContact::setChildren( const QString &str )
{
replace( Qtopia::Children, str );
}
/*!
\overload
Returns TRUE if the contact matches the regular expression \a regexp.
Otherwise returns FALSE.
*/
bool OPimContact::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 )
{
setLastHitField( it.key() );
match = true;
break;
}
}
return match;
}
QString OPimContact::toShortText() const
{
return ( fullName() );
}
QString OPimContact::type() const
{
return QString::fromLatin1( "OPimContact" );
}
class QString OPimContact::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 OPimContact::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 OPimContact::setBirthday( const QDate &v )
{
if ( v.isNull() )
{
- owarn << "Remove Birthday" << oendl;
replace( Qtopia::Birthday, QString::null );
return ;
}
if ( v.isValid() )
replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
}
/*! \fn void OPimContact::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 OPimContact::setAnniversary( const QDate &v )
{
if ( v.isNull() )
{
- owarn << "Remove Anniversary" << oendl;
replace( Qtopia::Anniversary, QString::null );
return ;
}
if ( v.isValid() )
replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
}
/*! \fn QDate OPimContact::birthday() const
Returns the birthday of the contact.
*/
QDate OPimContact::birthday() const
{
QString str = find( Qtopia::Birthday );
- // owarn << "Birthday " << str << oendl;
if ( !str.isEmpty() )
return OPimDateConversion::dateFromString ( str );
else
return QDate();
}
/*! \fn QDate OPimContact::anniversary() const
Returns the anniversary of the contact.
*/
QDate OPimContact::anniversary() const
{
QDate empty;
QString str = find( Qtopia::Anniversary );
- // owarn << "Anniversary " << str << oendl;
if ( !str.isEmpty() )
return OPimDateConversion::dateFromString ( str );
else
return empty;
}
void OPimContact::insertEmail( const QString &v )
{
//odebug << "insertEmail " << v << "" << oendl;
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 OPimContact::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
//odebug << " removing email from list " << e << "" << oendl;
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 )
{
//odebug << "removeEmail is default; setting new default" << oendl;
if ( !emails.count() )
clearEmails();
else // setDefaultEmail will remove e from the list
setDefaultEmail( emails.first() );
}
}
void OPimContact::clearEmails()
{
mMap.remove( Qtopia::DefaultEmail );
mMap.remove( Qtopia::Emails );
}
void OPimContact::setDefaultEmail( const QString &v )
{
QString e = v.simplifyWhiteSpace();
//odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
replace( Qtopia::DefaultEmail, e );
if ( !e.isEmpty() )
insertEmail( e );
}
void OPimContact::insertEmails( const QStringList &v )
{
for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
insertEmail( *it );
}
int OPimContact::rtti() const
{
return OPimResolver::AddressBook;
}
+/**
+ * \brief Cast to OPimContact or on failure return 0l
+ *
+ * This method tries to cast from a OPimRecord to a
+ * OPimContact it uses. If the OPimRecord is from type
+ * OPimContact the case will suceed and a pointer to
+ * OPimContact is returned otherwise a Null Pointer is returned.
+ *
+ *
+ * @see OPimTodo::safeCast()
+ * @see OPimEvent::safeCast()
+ * @return Return a OPimContact or a Null Pointer
+ */
+OPimContact* OPimContact::safeCast( const OPimRecord* rec ) {
+ return( rec && rec->rtti() == OPimResolver::AddressBook ) ?
+ static_cast<OPimContact*>( const_cast<OPimRecord*>(rec) ) :
+ 0l;
+}
+
void OPimContact::setUid( int i )
{
OPimRecord::setUid( i );
replace( Qtopia::AddressUid , QString::number( i ) );
}
}
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
index 6891dd6..6fa2c4b 100644
--- a/libopie2/opiepim/core/opimcontact.h
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -1,256 +1,260 @@
/*
This file is part of the Opie Project
Copyright (C) Stefan Eilers <eilers.stefan@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
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
/* OPIE */
#include <opie2/opimrecord.h>
#include <qpe/recordfields.h>
/* QT */
#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
namespace Opie
{
class OPimContactPrivate;
/**
* OPimContact 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 OPimContact : public OPimRecord
{
friend class DataSet;
public:
OPimContact();
OPimContact( const QMap<int, QString> &fromMap );
virtual ~OPimContact();
enum DateFormat{
Zip_City_State = 0,
City_State_Zip
};
/*
* 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 ); }
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;
QString toRichText() const;
QMap<int, QString> toMap() const;
QString field( int key ) const { return find( key ); }
void setUid( int i );
QString toShortText() const;
QString type() const;
class QString 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 ); }
+
+ //@{
int rtti() const;
+ static OPimContact* safeCast( const OPimRecord* );
+ //@}
private:
// The XML Backend needs some access to the private functions
friend class OPimContactAccessBackend_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;
OPimContactPrivate *d;
};
}
#endif
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 7bc6c32..1b553d8 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -1,1003 +1,1022 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimevent.h"
/* OPIE */
#include <opie2/opimrecurrence.h>
#include <opie2/opimresolver.h>
#include <opie2/opimnotifymanager.h>
#include <opie2/odebug.h>
#include <qpe/categories.h>
#include <qpe/stringutil.h>
/* QT */
namespace Opie
{
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 = OPimRecurrence::MON;
while ( !( i & day ) && i <= static_cast<char>(OPimRecurrence::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 OPimEvent::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;
OPimRecurrence* recur;
QString note;
QDateTime created;
QDateTime start;
QDateTime end;
bool isAllDay : 1;
QString timezone;
QArray<int>* child;
int parent;
};
OPimEvent::OPimEvent( int uid )
: OPimRecord( uid )
{
data = new Data;
}
OPimEvent::OPimEvent( const OPimEvent& ev )
: OPimRecord( ev ), data( ev.data )
{
data->ref();
}
OPimEvent::OPimEvent( const QMap<int, QString> map )
: OPimRecord( 0 )
{
data = new Data;
fromMap( map );
}
OPimEvent::~OPimEvent()
{
if ( data->deref() )
{
delete data;
data = 0;
}
}
OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
{
if ( this == &ev ) return * this;
OPimRecord::operator=( ev );
ev.data->ref();
deref();
data = ev.data;
return *this;
}
QString OPimEvent::description() const
{
return data->description;
}
void OPimEvent::setDescription( const QString& description )
{
changeOrModify();
data->description = description;
}
void OPimEvent::setLocation( const QString& loc )
{
changeOrModify();
data->location = loc;
}
QString OPimEvent::location() const
{
return data->location;
}
OPimNotifyManager &OPimEvent::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 OPimEvent::hasNotifiers() const
{
if ( !data->manager )
return false;
if ( data->manager->reminders().isEmpty() &&
data->manager->alarms().isEmpty() )
return false;
return true;
}
OPimRecurrence OPimEvent::recurrence() const
{
if ( !data->recur )
data->recur = new OPimRecurrence;
return *data->recur;
}
void OPimEvent::setRecurrence( const OPimRecurrence& rec )
{
changeOrModify();
if ( data->recur )
( *data->recur ) = rec;
else
data->recur = new OPimRecurrence( rec );
}
bool OPimEvent::hasRecurrence() const
{
if ( !data->recur ) return false;
return data->recur->doesRecur();
}
QString OPimEvent::note() const
{
return data->note;
}
void OPimEvent::setNote( const QString& note )
{
changeOrModify();
data->note = note;
}
QDateTime OPimEvent::createdDateTime() const
{
return data->created;
}
void OPimEvent::setCreatedDateTime( const QDateTime& time )
{
changeOrModify();
data->created = time;
}
QDateTime OPimEvent::startDateTime() const
{
if ( data->isAllDay )
return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
return data->start;
}
QDateTime OPimEvent::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 == OPimTimeZone::current().timeZone() ) return startDateTime();
OPimTimeZone zone( data->timezone );
return zone.toDateTime( data->start, OPimTimeZone::current() );
}
void OPimEvent::setStartDateTime( const QDateTime& dt )
{
changeOrModify();
data->start = dt;
}
QDateTime OPimEvent::endDateTime() const
{
/*
* if all Day event the end time needs
* to be on the same day as the start
*/
if ( data->isAllDay ) {
QDate end = data->end.isValid() ? data->end.date() : data->start.date() ;
return QDateTime( end, QTime( 23, 59, 59 ) );
}
return data->end;
}
QDateTime OPimEvent::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 == OPimTimeZone::current().timeZone() ) return endDateTime();
OPimTimeZone zone( data->timezone );
return zone.toDateTime( data->end, OPimTimeZone::current() );
}
void OPimEvent::setEndDateTime( const QDateTime& dt )
{
changeOrModify();
data->end = dt;
}
bool OPimEvent::isMultipleDay() const
{
return data->end.date().day() - data->start.date().day();
}
bool OPimEvent::isAllDay() const
{
return data->isAllDay;
}
void OPimEvent::setAllDay( bool allDay )
{
changeOrModify();
data->isAllDay = allDay;
}
void OPimEvent::setTimeZone( const QString& tz )
{
changeOrModify();
data->timezone = tz;
}
QString OPimEvent::timeZone() const
{
if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" );
return data->timezone;
}
bool OPimEvent::match( const QRegExp& re ) const
{
if ( re.match( data->description ) != -1 )
{
setLastHitField( Qtopia::DatebookDescription );
return true;
}
if ( re.match( data->note ) != -1 )
{
setLastHitField( Qtopia::Note );
return true;
}
if ( re.match( data->location ) != -1 )
{
setLastHitField( Qtopia::Location );
return true;
}
if ( re.match( data->start.toString() ) != -1 )
{
setLastHitField( Qtopia::StartDateTime );
return true;
}
if ( re.match( data->end.toString() ) != -1 )
{
setLastHitField( Qtopia::EndDateTime );
return true;
}
return false;
}
QString OPimEvent::toRichText() const
{
QString text, value;
// description
text += "<b><h3><img src=\"datebook/DateBook\">";
if ( !description().isEmpty() )
{
text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
}
text += "</h3></b><br><hr><br>";
// location
if ( !( value = location() ).isEmpty() )
{
text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
text += Qtopia::escapeString( value ) + "<br>";
}
// all day event
if ( isAllDay() )
{
text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
}
// multiple day event
else if ( isMultipleDay () )
{
text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
}
// start & end times
else
{
// start time
if ( startDateTime().isValid() )
{
text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
text += Qtopia::escapeString( startDateTime().toString() ).
replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
}
// end time
if ( endDateTime().isValid() )
{
text += "<b>" + QObject::tr( "End:" ) + "</b> ";
text += Qtopia::escapeString( endDateTime().toString() ).
replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
}
}
// categories
if ( categoryNames( "Calendar" ).count() )
{
text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
text += categoryNames( "Calendar" ).join( ", " );
text += "<br>";
}
//notes
if ( !note().isEmpty() )
{
text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
text += note();
// text += Qtopia::escapeString(note() ).
// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
}
return text;
}
QString OPimEvent::toShortText() const
{
QString text;
text += QString::number( startDateTime().date().day() );
text += ".";
text += QString::number( startDateTime().date().month() );
text += ".";
text += QString::number( startDateTime().date().year() );
text += " ";
text += QString::number( startDateTime().time().hour() );
text += ":";
text += QString::number( startDateTime().time().minute() );
text += " - ";
text += description();
return text;
}
QString OPimEvent::type() const
{
return QString::fromLatin1( "OPimEvent" );
}
QString OPimEvent::recordField( int /*id */ ) const
{
return QString::null;
}
int OPimEvent::rtti() const
{
return OPimResolver::DateBook;
}
+/**
+ * \brief Cast safely to OPimEvent from OPimRecord
+ *
+ * Safely cast from OPimRecord to OPimEvent. If the
+ * OPimRecord is not of type OPimEvent Null will be
+ * returned.
+ *
+ * @param rec The OPimRecord to be casted to OPimEvent
+ *
+ * @see OPimTodo::safeCast
+ * @return OPimEvent or Null Pointer
+ */
+OPimEvent* OPimEvent::safeCast( const OPimRecord* rec) {
+ return ( rec && rec->rtti() == OPimResolver::DateBook ) ?
+ static_cast<OPimEvent*>( const_cast<OPimRecord*>(rec) ) :
+ 0l;
+}
+
+
bool OPimEvent::loadFromStream( QDataStream& )
{
return true;
}
bool OPimEvent::saveToStream( QDataStream& ) const
{
return true;
}
void OPimEvent::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 OPimRecurrence( *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 OPimEvent::deref()
{
if ( data->deref() )
{
delete data;
data = 0;
}
}
// Exporting Event data to map. Using the same
// 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> OPimEvent::toMap() const
{
QMap<int, QString> retMap;
retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
if ( notifiers().alarms().count() ){
// Currently we just support one alarm.. (eilers)
OPimAlarm alarm = notifiers().alarms() [ 0 ];
retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
}
/* either use UTC timeZone or current() if there is was a timezone set */
OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
if ( parent() )
retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
if ( children().count() )
{
QArray<int> childr = children();
QString buf;
for ( uint i = 0; i < childr.count(); i++ )
{
if ( i != 0 ) buf += " ";
buf += QString::number( childr[ i ] );
}
retMap.insert( OPimEvent::FRecChildren, buf );
}
// Add recurrence stuff
if ( hasRecurrence() )
{
OPimRecurrence recur = recurrence();
QMap<int, QString> recFields = recur.toMap();
retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
}
else
{
OPimRecurrence recur = recurrence();
QMap<int, QString> recFields = recur.toMap();
retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
}
return retMap;
}
void OPimEvent::fromMap( const QMap<int, QString>& map )
{
// We just want to set the UID if it is really stored.
if ( !map[ OPimEvent::FUid ].isEmpty() )
setUid( map[ OPimEvent::FUid ].toInt() );
setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
setDescription( map[ OPimEvent::FDescription ] );
setLocation( map[ OPimEvent::FLocation ] );
if ( map[ OPimEvent::FType ] == "AllDay" )
setAllDay( true );
else
setAllDay( false );
if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
{
setTimeZone( map[ OPimEvent::FTimeZone ] );
}
time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
/* AllDay is always in UTC */
if ( isAllDay() )
{
OPimTimeZone utc = OPimTimeZone::utc();
setStartDateTime(utc.toDateTime( start ) );
setEndDateTime ( utc.toDateTime( end ) );
}
else {
/* to current date time */
OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
setStartDateTime(to_zone.toDateTime( start));
setEndDateTime (to_zone.toDateTime( end));
}
int alarmTime = -1;
if ( !map[ OPimEvent::FAlarm ].isEmpty() )
alarmTime = map[ OPimEvent::FAlarm ].toInt();
int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
if ( ( alarmTime != -1 ) )
{
QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
OPimAlarm al( sound , dt );
notifiers().add( al );
}
if ( !map[ OPimEvent::FNote ].isEmpty() )
setNote( map[ OPimEvent::FNote ] );
if ( !map[ OPimEvent::FRecParent ].isEmpty() )
setParent( map[ OPimEvent::FRecParent ].toInt() );
if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
{
QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
{
addChild( ( *it ).toInt() );
}
}
// Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
if ( !map[ OPimEvent::FRType ].isEmpty() )
{
QMap<int, QString> recFields;
recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
OPimRecurrence recur( recFields );
setRecurrence( recur );
}
}
int OPimEvent::parent() const
{
return data->parent;
}
void OPimEvent::setParent( int uid )
{
changeOrModify();
data->parent = uid;
}
QArray<int> OPimEvent::children() const
{
if ( !data->child ) return QArray<int>();
else
return data->child->copy();
}
void OPimEvent::setChildren( const QArray<int>& arr )
{
changeOrModify();
if ( data->child ) delete data->child;
data->child = new QArray<int>( arr );
data->child->detach();
}
void OPimEvent::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 OPimEvent::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()
{}
OPimEvent 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 OPimEvent& 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 OPimEvent& 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();
}
OPimEvent 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
{
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h
index 5553cac..32f648f 100644
--- a/libopie2/opiepim/core/opimevent.h
+++ b/libopie2/opiepim/core/opimevent.h
@@ -1,275 +1,289 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
// CONTAINS GPLed code of TT
#ifndef OEVENT_H
#define OEVENT_H
/* OPIE */
#include <opie2/opimtimezone.h>
#include <opie2/opimrecord.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
/* QT */
#include <qstring.h>
#include <qdatetime.h>
#include <qvaluelist.h>
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& );
// 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 OPimRecurrence;
/**
* This is the container for all Events. It encapsules all
* available information for a single Event
* @short container for events.
*/
class OPimEvent : public OPimRecord
{
public:
typedef QValueList<OPimEvent> ValueList;
/**
* RecordFields contain possible attributes
* used in the Results of toMap()..
*/
enum RecordFields {
FUid = Qtopia::UID_ID,
FCategories = Qtopia::CATEGORY_ID,
FDescription /* = 0 Why this ? (eilers) */,
FLocation,
FType,
FAlarm,
FSound,
FRType,
FRWeekdays,
FRPosition,
FRFreq,
FRHasEndDate,
FREndDate,
FRCreated,
FRExceptions,
FStart,
FEnd,
FNote,
FTimeZone,
FRecParent,
FRecChildren,
};
/**
* Start with an Empty OPimEvent. UID == 0 means that it is empty
*/
OPimEvent( int uid = 0 );
/**
* copy c'tor
*/
OPimEvent( const OPimEvent& );
/**
* Create OPimEvent, initialized by map
* @see enum RecordFields
*/
OPimEvent( const QMap<int, QString> map );
~OPimEvent();
OPimEvent &operator=( const OPimEvent& );
+ //@{
QString description() const;
void setDescription( const QString& description );
QString location() const;
void setLocation( const QString& loc );
+ //@}
+ //@{
bool hasNotifiers() const;
OPimNotifyManager &notifiers() const;
+ //@}
+ //@{
OPimRecurrence recurrence() const;
void setRecurrence( const OPimRecurrence& );
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;
- 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 OPimEvent */
int parent() const;
void setParent( int uid );
/* needed reimp */
+ //@{ Reimplementations
+ virtual bool match( const QRegExp& ) const;
QString toRichText() const;
QString toShortText() const;
QString type() const;
QMap<int, QString> toMap() const;
void fromMap( const QMap<int, QString>& map );
QString recordField( int ) const;
- int rtti() const;
-
bool loadFromStream( QDataStream& );
bool saveToStream( QDataStream& ) const;
+ //@}
+
+ //@{
+ int rtti() const;
+ static OPimEvent* safeCast( const OPimRecord* );
+ //@}
/* bool operator==( const OPimEvent& );
bool operator!=( const OPimEvent& );
bool operator<( const OPimEvent& );
bool operator<=( const OPimEvent& );
bool operator>( const OPimEvent& );
bool operator>=(const OPimEvent& );
*/
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 OPimEvent& 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 OPimEvent& );
void setDate( const QDate& );
void setEffectiveDates( const QDate& from, const QDate& to );
QString description() const;
QString location() const;
QString note() const;
OPimEvent 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/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h
index 3925c89..9d319a1 100644
--- a/libopie2/opiepim/core/opimglobal.h
+++ b/libopie2/opiepim/core/opimglobal.h
@@ -1,64 +1,76 @@
/*
This file is part of the Opie Project
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
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __OPIMGLOBAL_H_
#define __OPIMGLOBAL_H_
+#include <qarray.h>
+
namespace Opie{
+
+/**
+ * The unique identifier for every
+ * PIM record. For now it is a negative
+ * int but we could change it to long or QUuid
+ * in the future
+ */
+typedef int UID;
+typedef QArray<UID> UIDArray;
+
namespace Pim{
/**
* Contains global types and enums for the PIM-API
*/
class OPimGlobal{
public:
enum PimType {
TODOLIST,
CONTACTLIST,
DATEBOOK,
_END_PimType
};
enum DatabaseStyle {
DEFAULT, // Use default Database
UNKNOWN, // Unknown database style
XML,
SQL,
VCARD, // Also used for VCAL !
_END_DatabaseStyle
};
};
}
}
#endif
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 516dc79..77cd922 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -1,250 +1,245 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimnotifymanager.h"
/* OPIE */
#include <opie2/opimdateconversion.h>
#include <opie2/odebug.h>
/* QT */
#include <qstringlist.h>
namespace Opie
{
OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al )
: m_rem( rem ), m_al( al )
{}
OPimNotifyManager::~OPimNotifyManager()
{}
/* use static_cast and type instead of dynamic... */
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" ) )
{
const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
m_al.append( al );
}
}
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" ) )
{
const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
m_al.remove( al );
}
}
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" ) )
{
const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
m_al.remove( al );
m_al.append( al );
}
}
OPimNotifyManager::Reminders OPimNotifyManager::reminders() const
{
return m_rem;
}
OPimNotifyManager::Alarms OPimNotifyManager::alarms() const
{
return m_al;
}
OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const
{
Alarms::ConstIterator it;
found = true;
for ( it = m_al.begin(); it != m_al.end(); ++it )
{
if ( ( *it ).dateTime() == when )
return ( *it );
}
// Fall through if nothing could be found
found = false;
OPimAlarm empty;
return empty;
}
void OPimNotifyManager::setAlarms( const Alarms& al )
{
m_al = al;
}
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& )
{
}
/* FIXME!!! */
/**
* same as above...
* Also implement Url model
* have a MainWindow....
*/
void OPimNotifyManager::deregister( const OPimNotify& )
{
}
bool OPimNotifyManager::isEmpty() const
{
- owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl;
if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
else return false;
}
// Taken from otodoaccessxml.. code duplication bad. any alternative?
QString OPimNotifyManager::alarmsToString() const
{
QString str;
OPimNotifyManager::Alarms alarms = m_al;
if ( !alarms.isEmpty() )
{
QStringList als;
OPimNotifyManager::Alarms::Iterator it = alarms.begin();
for ( ; it != alarms.end(); ++it )
{
/* only if time is valid */
if ( ( *it ).dateTime().isValid() )
{
als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() )
+ ":" + QString::number( ( *it ).duration() )
+ ":" + QString::number( ( *it ).sound() )
+ ":";
}
}
// now write the list
- owarn << "als: " << als.join( "____________" ) << "" << oendl;
str = als.join( ";" );
}
return str;
}
QString OPimNotifyManager::remindersToString() const
{
QString str;
OPimNotifyManager::Reminders reminders = m_rem;
if ( !reminders.isEmpty() )
{
OPimNotifyManager::Reminders::Iterator it = reminders.begin();
QStringList records;
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 )
{
QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
- owarn << "alarm: " << alarm.join( "___" ) << "" << oendl;
- owarn << "alarm[0]: " << alarm[ 0 ] << " "
- << OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString() << oendl;
OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
alarm[ 1 ].toInt() );
add( al );
}
}
void OPimNotifyManager::remindersFromString( const QString& str )
{
QStringList rems = QStringList::split( ";", str );
for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it )
{
OPimReminder rem( ( *it ).toInt() );
add( rem );
}
}
}
diff --git a/libopie2/opiepim/core/opimoccurrence.cpp b/libopie2/opiepim/core/opimoccurrence.cpp
new file mode 100644
index 0000000..14ab5cf
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.cpp
@@ -0,0 +1,319 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "opimoccurrence.h"
+#include <opie2/opimtemplatebase.h>
+#include <opie2/private/opimoccurrence_p.h>
+
+
+/* QT */
+#include <qshared.h>
+
+
+namespace Opie {
+
+OPimOccurrence::OPimOccurrence( OPimOccurrence::Data* _data,
+ enum OPimOccurrence::Position pos )
+ : m_pos( pos ), data( _data )
+{}
+
+/**
+ * \brief Copy constructor
+ */
+OPimOccurrence::OPimOccurrence( const OPimOccurrence& oc )
+ : data( oc.data )
+{
+ /*
+ * Increment the reference count
+ */
+ data->ref();
+
+ /*
+ * copy the other information
+ */
+ m_start = oc.m_start;
+ m_end = oc.m_end;
+ m_occurrence = oc.m_occurrence;
+ m_isAllDay = oc.m_isAllDay;
+ m_pos = oc.m_pos;
+}
+
+OPimOccurrence::OPimOccurrence()
+ : m_isAllDay( false ), m_pos( StartEnd )
+{
+ /* simple convient c'tor */
+ data = new OPimOccurrence::Data();
+}
+
+OPimOccurrence::~OPimOccurrence() {
+ deref();
+}
+
+/**
+ * \brief Copy Operator
+ */
+OPimOccurrence& OPimOccurrence::operator=( const OPimOccurrence& oc ) {
+ /* guard against self assignment */
+ if ( this == &oc ) return *this;
+
+ oc.data->ref();
+ deref();
+ data = oc.data;
+
+
+ /*
+ * copy the other information
+ */
+ m_start = oc.m_start;
+ m_end = oc.m_end;
+ m_occurrence = oc.m_occurrence;
+ m_isAllDay = oc.m_isAllDay;
+ m_pos = oc.m_pos;
+
+ return *this;
+}
+
+
+/**
+ * @internal
+ */
+void OPimOccurrence::deref() {
+ if ( data->deref() ) {
+ delete data;
+ data = 0;
+ }
+}
+
+/**
+ * \brief Set the Occurrence to be All Day on a specified QDate
+ *
+ * If no QTime is associated to a OPimOccurrence use this Method
+ * to set the Period of this Occurrence. When using this Method
+ * later calls to \sa isAllDay() will return true.
+ * The Occurrence will be set to occurr on \par from.
+ *
+ * @param from The Day this OPimOccurrence occurs
+ *
+ */
+void OPimOccurrence::setPeriod( const QDate& from ) {
+ m_occurrence = from;
+ m_start = m_end = QTime(); // assign invalid value just in case
+ m_isAllDay = true;
+}
+
+/**
+ * \brief Set the period of this Occurrence with a QTime associated (overloaded)
+ *
+ * Set the period of time for this Occurrence. Each Ocurrence is limited
+ * to one day. Using this Method will make \sa isAllDay() return false.
+ * If \par from and \par to are on two different days the QDate of the
+ * \par from QDateTime will be used.
+ *
+ * @param from The Start Date Time of the Occurrence
+ * @param to The End Date Time of the Occurrence
+ */
+void OPimOccurrence::setPeriod( const QDateTime& from, const QDateTime& to ) {
+ m_occurrence = from.date();
+ m_start = from.time();
+ m_end = to.time();
+ m_isAllDay = false;
+}
+
+/**
+ * \brief Set the period of this Occurrence with a QTime associated
+ *
+ * @param from The QDate of the Occurrence
+ * @param start The Start QTime of the Occurrence
+ * @param end The End QTime of the Occurrence
+ */
+void OPimOccurrence::setPeriod( const QDate& from, const QTime& start,
+ const QTime& end ) {
+ m_occurrence = from;
+ m_start = start;
+ m_end = end;
+ m_isAllDay = false;
+}
+
+
+/**
+ * \brief Is a QTime associated to the OPimOccurrence
+ *
+ * @return Return true if no QTime is associated
+ */
+bool OPimOccurrence::isAllDay()const {
+ return m_isAllDay;
+}
+
+
+/**
+ * \brief Return the QDate where this OPimOccurrence takes place
+ * @return the QDate where this OPimOccurrence occurrs.
+ */
+QDate OPimOccurrence::date()const {
+ return m_occurrence;
+}
+
+
+/**
+ * \brief Return the start time of the OPimOccurrence
+ *
+ * @return Return the Start Time of the OPimOccurrence. It is
+ * invalid if \sa isAllDay() returns true.
+ */
+QTime OPimOccurrence::startTime()const {
+ return m_start;
+}
+
+QTime OPimOccurrence::endTime()const {
+ return m_end;
+}
+
+QDateTime OPimOccurrence::startDateTime()const {
+ return QDateTime( m_occurrence, m_start );
+}
+
+QDateTime OPimOccurrence::endDateTime()const {
+ return QDateTime( m_occurrence, m_end );
+}
+
+
+QString OPimOccurrence::summary()const {
+ return data->summary;
+}
+
+QString OPimOccurrence::location()const {
+ return data->location;
+}
+
+QString OPimOccurrence::note()const {
+ return data->note;
+}
+
+
+/**
+ * -1 if no time is associated
+ * otherwise the length of the occurrence in hours
+ */
+int OPimOccurrence::length()const {
+ if ( m_isAllDay )
+ return -1;
+ else
+ return ( m_end.hour() * 60 - m_start.hour() * 60 )
+ + QABS( m_start.minute() - m_end.minute() );
+}
+
+enum OPimOccurrence::Position OPimOccurrence::position()const {
+ return m_pos;
+}
+
+void OPimOccurrence::setPosition( enum OPimOccurrence::Position& pos ) {
+ m_pos = pos;
+}
+
+
+Opie::Core::OSharedPointer<OPimRecord> OPimOccurrence::record()const {
+ if ( !data->record && data->backend )
+ data->record = data->backend->record( data->uid );
+ return data->record;
+}
+
+template<class Record> Record OPimOccurrence::internalToRecord()const {
+ Record target;
+
+ /* If it is not loaded, try to load it using OPimBase */
+ if ( !data->record && data->backend )
+ data->record = data->backend->record( data->uid );
+
+ Record *ta = Record::safeCast( data->record );
+ if ( ta )
+ target = *ta;
+
+
+ return target;
+}
+
+OPimEvent OPimOccurrence::toEvent()const {
+ return internalToRecord<OPimEvent>();
+}
+
+OPimTodo OPimOccurrence::toTodo()const {
+ return internalToRecord<OPimTodo>();
+}
+
+OPimContact OPimOccurrence::toContact()const {
+ return internalToRecord<OPimContact>();
+}
+
+bool OPimOccurrence::operator<( const OPimOccurrence& oc )const {
+ if ( m_occurrence < oc.m_occurrence )
+ return true;
+ if ( m_occurrence == oc.m_occurrence )
+ return m_start < oc.m_start;
+ else
+ return false;
+}
+
+bool OPimOccurrence::operator<=( const OPimOccurrence& oc )const {
+ return ( m_occurrence <= oc.m_occurrence );
+}
+
+bool OPimOccurrence::operator==( const OPimOccurrence& oc )const {
+ if ( data->uid != oc.data->uid )
+ return false;
+ if ( m_occurrence != oc.m_occurrence )
+ return false;
+ if ( m_isAllDay != oc.m_isAllDay )
+ return false;
+ if ( m_isAllDay && oc.m_isAllDay )
+ if ( m_start != oc.m_start ||
+ m_end != oc.m_end )
+ return false;
+ if ( data->summary != oc.data->summary )
+ return false;
+ if ( data->note != oc.data->note )
+ return false;
+ if ( data->location != oc.data->location )
+ return false;
+
+ return true;
+}
+
+bool OPimOccurrence::operator!=( const OPimOccurrence& oc )const {
+ return !( *this == oc );
+}
+
+bool OPimOccurrence::operator>( const OPimOccurrence& oc )const {
+ return !( *this <= oc );
+}
+
+bool OPimOccurrence::operator>=( const OPimOccurrence& oc )const {
+ return !( *this < oc );
+}
+
+}
diff --git a/libopie2/opiepim/core/opimoccurrence.h b/libopie2/opiepim/core/opimoccurrence.h
new file mode 100644
index 0000000..902638b
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.h
@@ -0,0 +1,142 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef OPIE_PIM_OCCURRENCE_H
+#define OPIE_PIM_OCCURRENCE_H
+
+#include <opie2/osharedpointer.h>
+#include <opie2/opimrecord.h>
+#include <opie2/opimevent.h>
+#include <opie2/opimtodo.h>
+#include <opie2/opimcontact.h>
+
+#include <qdatetime.h>
+#include <qstringlist.h>
+
+namespace Opie {
+
+template<class T> class OPimAccessTemplate;
+/**
+ * \brief An OPimOccurrence represents a occurence for one day of a OPimRecord
+ *
+ * An OPimOccurrence represents the occurrence of one OPimRecord
+ * for a period of Time for one day. An occurrence can spawn
+ * more then one day and then is splitted into multiple OPimOccurrence.
+ * By attributes you can find if a OPimOccurrence is the beginning and
+ * end, begin, end or is midway of a multiday occurrence.
+ *
+ */
+class OPimOccurrence {
+ friend class OPimBase;
+public:
+ typedef QValueList<OPimOccurrence> List;
+ /**
+ * The position of the OPimOccurrence in a possible
+ * MultiDay Occurrence.
+ */
+ enum Position {
+ MidWay, /* This OPimOccurrence is somewhere in between Start and End */
+ Start, /* This OPimOccurrence is the Start of a multi day Occurrence */
+ End, /* This OPimOccurrence is the End of a multi day Occurrence */
+ StartEnd /* This OPimOccurrence only spans one day */
+ };
+
+ //@{
+ OPimOccurrence();
+ OPimOccurrence( const OPimOccurrence& );
+ ~OPimOccurrence();
+ //@}
+
+ //@{
+ void setPeriod( const QDate& from );
+ void setPeriod( const QDateTime& from, const QDateTime& to );
+ void setPeriod( const QDate& from, const QTime& start, const QTime& end );
+ //@}
+
+ //@{
+ bool isAllDay()const;
+ QDate date()const;
+ QTime startTime()const;
+ QTime endTime()const;
+ QDateTime startDateTime()const;
+ QDateTime endDateTime()const;
+ //@}
+
+ //@{
+ QString summary()const;
+ QString location()const;
+ QString note()const;
+ //@}
+
+ //@{
+ int length()const;
+ Position position()const;
+ void setPosition( enum Position& );
+ //@}
+
+ //@{
+ Opie::Core::OSharedPointer<OPimRecord> record()const;
+ OPimEvent toEvent()const;
+ OPimTodo toTodo()const;
+ OPimContact toContact()const;
+ //@}
+
+
+ //@{
+ bool operator< ( const OPimOccurrence& )const;
+ bool operator<=( const OPimOccurrence& )const;
+ bool operator==( const OPimOccurrence& )const;
+ bool operator!=( const OPimOccurrence& )const;
+ bool operator> ( const OPimOccurrence& )const;
+ bool operator>=( const OPimOccurrence& )const;
+ OPimOccurrence &operator=( const OPimOccurrence& );
+ //@}
+
+private:
+ QDate m_occurrence;
+ QTime m_start, m_end;
+ bool m_isAllDay : 1;
+ enum Position m_pos;
+
+ void deref();
+ inline void changeOrModify();
+
+ struct Private;
+ struct Data;
+
+ Data *data;
+ Private *d;
+
+private: // ctor
+ OPimOccurrence( OPimOccurrence::Data *, enum Position );
+ template<class T> T internalToRecord()const;
+};
+}
+
+#endif
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 6546d99..60946e0 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,273 +1,264 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimrecord.h"
/* OPIE */
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
/* QT */
namespace Opie
{
Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
OPimRecord::OPimRecord( int uid )
: Qtopia::Record()
{
m_lastHit = -1;
setUid( uid );
}
OPimRecord::~OPimRecord()
{}
OPimRecord::OPimRecord( const OPimRecord& rec )
: Qtopia::Record( rec )
{
( *this ) = 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 list;
QArray<int> cats = categories();
Categories catDB;
catDB.load( categoryFileName() );
for ( uint i = 0; i < cats.count(); i++ )
{
list << catDB.label( appname, cats[ i ] );
}
return list;
}
void OPimRecord::setCategoryNames( const QStringList& )
{
}
void OPimRecord::addCategoryName( const QString& )
{
Categories catDB;
catDB.load( categoryFileName() );
-
-
}
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 ) {
- QArray<int> id = it.data();
- for ( uint i = 0; i < id.size(); ++i ) {
- str += it.key() + "," + QString::number( i ) + ";";
- }
- }
- str = str.remove( str.length()-1, 1); // strip the ;
- //owarn << "IDS " + str << oendl;
-
- return str;
- }*/
/* if uid = 1 assign a new one */
void OPimRecord::setUid( int uid )
{
if ( uid == 1 )
uid = uidGen().generate();
Qtopia::Record::setUid( uid );
};
Qtopia::UidGen &OPimRecord::uidGen()
{
return m_uidGen;
}
OPimXRefManager &OPimRecord::xrefmanager()
{
return m_xrefman;
}
int OPimRecord::rtti() const
{
return 0;
}
/**
* now let's put our data into the stream
*/
/*
* First read UID
* Categories
* XRef
*/
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++ )
{
stream >> array[ i ];
}
setCategories( array );
/*
* now we do the X-Ref stuff
*/
OPimXRef xref;
stream >> UInt;
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
{
/** UIDs */
stream << uid();
/** Categories */
stream << categories().count();
for ( uint i = 0; i < categories().count(); i++ )
{
stream << categories() [ i ];
}
/*
* first the XRef count
* then the xrefs
*/
stream << m_xrefman.list().count();
for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
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
{
str << par.service();
str << par.uid();
str << par.field();
}
OPimXRefPartner OPimRecord::partner( QDataStream& stream )
{
OPimXRefPartner par;
QString str;
int i;
stream >> str;
par.setService( str );
stream >> i;
par.setUid( i );
stream >> i ;
par.setField( i );
return par;
}
void OPimRecord::setLastHitField( int lastHit ) const
{
m_lastHit = lastHit;
}
int OPimRecord::lastHitField() const
{
return m_lastHit;
}
QMap<QString, QString> OPimRecord::toExtraMap() const
{
return customMap;
}
void OPimRecord::setExtraMap( const QMap<QString, QString>& map )
{
customMap = map;
}
+#if 0
+QString OPimRecord::recordAttributeTranslated( int field )const
+{
+ return recordAttributeTranslated()[field];
+}
+#endif
+
}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 127439a..363cc78 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,193 +1,200 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIMRECORD_H
#define OPIMRECORD_H
/* OPIE */
#include <opie2/opimxrefmanager.h>
+#include <opie2/opimglobal.h>
+
/*
* we need to get customMap which is private...
*/
#define private protected
#include <qpe/palmtoprecord.h>
#undef private
/* QT */
#include <qdatastream.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
namespace Opie
{
/**
* 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( UID 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
{
setLastHitField( -1 );
return Qtopia::Record::match( QRegExp( regexp ) );
};
/**
* if implemented this function returns which item has been
* last hit by the match() function.
* or -1 if not implemented or no hit has occured
*/
int lastHitField() const;
/**
* converts the internal structure to a map
*/
virtual QMap<int, QString> toMap() const = 0;
// virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers)
/**
* key value representation of extra items
*/
QMap<QString, QString> toExtraMap() const;
void setExtraMap( const QMap<QString, QString>& );
+//@{
/**
* the name for a recordField
*/
virtual QString recordField( int ) const = 0;
+// virtual QArray<int> recordAttributes()const = 0;
+// virtual QMap<int,QString> recordAttributesTranslated() const = 0;
+// QString recordAttributeTranslated(int field)const;
+//@}
/**
* 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 ....
*/
virtual int rtti() const;
/**
* 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:
// need to be const cause it is called from const methods
mutable int m_lastHit;
void setLastHitField( int lastHit ) const;
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/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h
index 1d5027f..0459f41 100644
--- a/libopie2/opiepim/core/opimrecordlist.h
+++ b/libopie2/opiepim/core/opimrecordlist.h
@@ -1,403 +1,410 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ORECORDLIST_H
#define ORECORDLIST_H
/* OPIE */
#include <opie2/opimtemplatebase.h>
#include <opie2/opimrecord.h>
//#include <opie2/odebug.h>
/* QT */
#include <qarray.h>
namespace Opie
{
+template<class T> class OPimAccessTemplate;
class OPimRecordListIteratorPrivate;
/**
* Our List Iterator
* it behaves like STL or Qt
*
* for(it = list.begin(); it != list.end(); ++it )
* doSomeCoolStuff( (*it) );
*/
template <class T> class OPimRecordList;
template <class T = OPimRecord>
class OPimRecordListIterator
{
friend class OPimRecordList<T>;
public:
typedef OTemplateBase<T> Base;
/**
* The c'tor used internally from
* OPimRecordList
*/
OPimRecordListIterator( const QArray<int>, const Base* );
/**
* The standard c'tor
*/
OPimRecordListIterator();
~OPimRecordListIterator();
OPimRecordListIterator( const OPimRecordListIterator& );
OPimRecordListIterator &operator=( const OPimRecordListIterator& );
/**
* a * operator ;)
* use it like this T = (*it);
*/
T operator*();
OPimRecordListIterator &operator++();
OPimRecordListIterator &operator--();
bool operator==( const OPimRecordListIterator& it );
bool operator!=( const OPimRecordListIterator& it );
/**
* the current item
*/
uint current() const;
/**
* the number of items
*/
uint count() const;
/**
* sets the current item
*/
void setCurrent( uint cur );
private:
QArray<int> m_uids;
uint m_current;
const Base* m_temp;
bool m_end : 1;
T m_record;
bool m_direction : 1;
/* d pointer for future versions */
OPimRecordListIteratorPrivate *d;
};
class OPimRecordListPrivate;
/**
* The recordlist used as a return type
* from OPimAccessTemplate
*/
template <class T = OPimRecord >
class OPimRecordList
{
+ template<class> friend class OPimAccessTemplate;
public:
typedef OTemplateBase<T> Base;
typedef OPimRecordListIterator<T> Iterator;
/**
* c'tor
*/
- OPimRecordList ()
- {}
+ OPimRecordList (){}
OPimRecordList( const QArray<int>& ids,
const Base* );
~OPimRecordList();
/**
* the first iterator
*/
Iterator begin();
/**
* the end
*/
Iterator end();
/**
* the number of items in the list
*/
uint count() const;
T operator[] ( uint i );
int uidAt( uint i );
/**
* Remove the contact with given uid
*/
bool remove( int uid );
/*
ConstIterator begin()const;
ConstIterator end()const;
*/
+ protected:
+ UIDArray uids()const;
+
private:
QArray<int> m_ids;
const Base* m_acc;
OPimRecordListPrivate *d;
};
/* ok now implement it */
template <class T>
OPimRecordListIterator<T>::OPimRecordListIterator()
{
m_current = 0;
m_temp = 0l;
m_end = true;
m_record = T();
/* forward */
m_direction = TRUE;
}
template <class T>
OPimRecordListIterator<T>::~OPimRecordListIterator()
{
/* nothing to delete */
}
template <class T>
OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it )
{
- //owarn << "OPimRecordListIterator copy c'tor" << oendl;
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
m_direction = it.m_direction;
}
template <class T>
OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it )
{
m_uids = it.m_uids;
m_current = it.m_current;
m_temp = it.m_temp;
m_end = it.m_end;
m_record = it.m_record;
return *this;
}
template <class T>
T OPimRecordListIterator<T>::operator*()
{
- //owarn << "operator* " << m_current << " " << m_uids[m_current] << oendl;
if ( !m_end )
m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current,
m_direction ? Base::Forward :
Base::Reverse );
else
m_record = T();
return m_record;
}
template <class T>
OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++()
{
m_direction = true;
if ( m_current < m_uids.count() )
{
m_end = false;
++m_current;
}
else
m_end = true;
return *this;
}
template <class T>
OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--()
{
m_direction = false;
if ( m_current > 0 )
{
--m_current;
m_end = false;
}
else
m_end = true;
return *this;
}
template <class T>
bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it )
{
/* if both are at we're the same.... */
if ( m_end == it.m_end ) return true;
if ( m_uids != it.m_uids ) return false;
if ( m_current != it.m_current ) return false;
if ( m_temp != it.m_temp ) return false;
return true;
}
template <class T>
bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it )
{
return !( *this == it );
}
template <class T>
OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids,
const Base* t )
: m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
m_direction( false )
{
/* 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 OPimRecordListIterator<T>::current() const
{
return m_current;
}
template <class T>
void OPimRecordListIterator<T>::setCurrent( uint cur )
{
if ( cur < m_uids.count() )
{
m_end = false;
m_current = cur;
}
}
template <class T>
uint OPimRecordListIterator<T>::count() const
{
return m_uids.count();
}
template <class T>
OPimRecordList<T>::OPimRecordList( const QArray<int>& ids,
const Base* acc )
: m_ids( ids ), m_acc( acc )
{}
template <class T>
OPimRecordList<T>::~OPimRecordList()
{
/* nothing to do here */
}
template <class T>
typename OPimRecordList<T>::Iterator OPimRecordList<T>::begin()
{
Iterator it( m_ids, m_acc );
return it;
}
template <class T>
typename OPimRecordList<T>::Iterator OPimRecordList<T>::end()
{
Iterator it( m_ids, m_acc );
it.m_end = true;
it.m_current = m_ids.count();
return it;
}
template <class T>
uint OPimRecordList<T>::count() const
{
return m_ids.count();
}
template <class T>
T OPimRecordList<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 OPimRecordList<T>::uidAt( uint i )
{
return m_ids[ i ];
}
template <class T>
bool OPimRecordList<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 )
{
copy[ counter++ ] = m_ids[ i ];
}
else
ret_val = true;
}
copy.resize( counter );
m_ids = copy;
return ret_val;
}
+template<class T>
+UIDArray OPimRecordList<T>::uids()const {
+ return m_ids;
+}
+
}
#endif
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h
index 0a6dddf..088474b 100644
--- a/libopie2/opiepim/core/opimresolver.h
+++ b/libopie2/opiepim/core/opimresolver.h
@@ -1,125 +1,123 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIMRESOLVER_H
#define OPIMRESOLVER_H
/* OPIE */
#include <opie2/opimtemplatebase.h>
/* QT */
#include <qstring.h>
#include <qvaluelist.h>
namespace Opie {
/**
* OPimResolver is a MetaClass to access
* available backends read only.
* It will be used to resolve uids + app names
* to full informations
* to traverse through a list of alarms, reminders
* to get access to built in PIM functionality
* and to more stuff
- * THE PERFORMANCE will depend on THE BACKEND
- * USING XML is a waste of memory!!!!!
*/
class OPimResolver {
public:
enum BuiltIn { TodoList = 0,
DateBook,
AddressBook
};
static OPimResolver* self();
/**
* return a record for a uid
* and an service
* You've THE OWNERSHIP NOW!
*/
OPimRecord *record( const QString& service, int uid );
/**
* return the QCopChannel for service
* When we will use Qtopia Services it will be used here
*/
QCString qcopChannel( enum BuiltIn& )const;
QCString qcopChannel( const QString& service )const;
/**
* The Application channel (QPE/Application/name)
*/
QCString applicationChannel( enum BuiltIn& )const;
QCString applicationChannel( const QString& service )const;
/**
* return a list of available services
*/
QStringList services()const;
inline QString serviceName(int rrti )const;
int serviceId( const QString& Service);
/**
* add a record to a service... ;)
*/
bool add( const QString& service, const OPimRecord& );
/**
* record returns an empty record for a given service.
* Be sure to delete it!!!
*
*/
OPimRecord* record( const QString& service );
OPimRecord* record( int rtti );
/**
* you can cast to your
*/
OPimBase* backend( const QString& service );
OPimBase* backend( int rtti );
private:
OPimResolver();
void loadData();
inline bool isBuiltIn( const QString& )const;
OPimRecord* recordExtern( const QString&, int );
OPimRecord* recordExtern( const QString& );
static OPimResolver* m_self;
struct Data;
class Private;
Data* data;
Private* d;
QStringList m_builtIns;
};
}
#endif
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h
index 8336b3e..ae1e0d2 100644
--- a/libopie2/opiepim/core/opimstate.h
+++ b/libopie2/opiepim/core/opimstate.h
@@ -1,78 +1,72 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIMSTATE_H
#define OPIMSTATE_H
/* QT */
#include <qstring.h>
namespace Opie {
/**
* The State of a Task
* This class encapsules the state of a todo
* and it's shared too
*/
-/*
- * in c a simple struct would be enough ;)
- * g_new_state();
- * g_do_some_thing( state_t* );
- * ;)
- */
class OPimState {
public:
enum State {
Started = 0,
Postponed,
Finished,
NotStarted,
Undefined
};
OPimState( int state = Undefined );
OPimState( const OPimState& );
~OPimState();
bool operator==( const OPimState& );
OPimState &operator=( const OPimState& );
void setState( int state);
int state()const;
private:
void deref();
inline void copyInternally();
struct Data;
Data* data;
class Private;
Private *d;
};
}
#endif
diff --git a/libopie2/opiepim/core/opimtemplatebase.cpp b/libopie2/opiepim/core/opimtemplatebase.cpp
new file mode 100644
index 0000000..0a07320
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtemplatebase.cpp
@@ -0,0 +1,112 @@
+/*
+ This file is part of the Opie Project
+ Copyright (C) 2004 Holger Freyther <zecke@handhelds.org>
+ =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
+ .=l.
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "opimtemplatebase.h"
+
+#include <opie2/opimoccurrence.h>
+#include <opie2/private/opimoccurrence_p.h>
+
+namespace Opie {
+
+static void setPeriod( OPimOccurrence& oc, bool period, const QDate& d,
+ const QTime& s, const QTime& t ) {
+ if ( period )
+ oc.setPeriod( d );
+ else
+ oc.setPeriod( d, s, t );
+}
+
+// namespace Opie {
+OPimBase::OPimBase() {}
+OPimBase::~OPimBase() {}
+
+/**
+ * @internal Convert internal Occurrence representation
+ * to the external
+ */
+OPimOccurrence::List OPimBase::convertOccurrenceFromBackend( const OPimBackendOccurrence::List& lst )const {
+ OPimOccurrence::List oc_lst;
+
+ /*
+ * Split multiday events up. Create the internal data structure
+ * and then iterate over the days and create the OPimOccurrecne.
+ */
+ for ( OPimBackendOccurrence::List::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
+ OPimBackendOccurrence boc = *it;
+
+ /*
+ * Create the Shared Data Structure
+ */
+ OPimOccurrence::Data *data = new OPimOccurrence::Data();
+ data->summary = boc.summary();
+ data->location = boc.location();
+ data->note = boc.note();
+ data->uid = boc.uid();
+ data->backend = const_cast<OPimBase*>(this);
+
+ QDateTime start = boc.startDateTime();
+ QDateTime end = boc.endDateTime();
+
+ /*
+ * Start and End are on the same day
+ * Start and End are on two different ways.
+ * - Add Start and End and the days inbetween
+ */
+ int dto = start.daysTo( end );
+ bool allDay = boc.isAllDay();
+
+ if ( dto == 0 ) {
+ OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::StartEnd );
+ setPeriod( oc, allDay, start.date(), start.time(), end.time() );
+ oc_lst.append( oc );
+ }else {
+
+ OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::Start );
+ setPeriod( oc, allDay, start.date(), start.time(), QTime(23,59,59));
+ oc_lst.append( oc );
+
+ QDate next = start.addDays( 1 ).date();
+ while ( next != end.date() ) {
+ oc = OPimOccurrence( data, OPimOccurrence::MidWay );
+ setPeriod( oc, allDay, next, QTime(0, 0, 0), QTime(23, 59, 59));
+ oc_lst.append( oc );
+ next = next.addDays( 1 );
+ }
+
+ oc = OPimOccurrence( data, OPimOccurrence::End );
+ setPeriod( oc, allDay, end.date(), QTime(0, 0, 0 ), end.time() );
+ oc_lst.append( oc );
+ }
+ }
+
+ return oc_lst;
+}
+// }
+
+}
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index 787486c..b238a68 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -1,130 +1,223 @@
/*
This file is part of the Opie Project
Copyright (C) Holger Freyther <zecke@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTEMPLATEBASE_H
#define OTEMPLATEBASE_H
/* OPIE */
#include <opie2/opimrecord.h>
#include <opie2/opimcache.h>
+#include <opie2/opimoccurrence.h>
+#include <opie2/opimbackendoccurrence.h>
/* QT */
#include <qarray.h>
+#include <qdatetime.h>
namespace Opie {
+
+class OPimBasePrivate;
+
/**
- * Templates do not have a base class, This is why
- * we've this class
- * this is here to give us the possibility
- * to have a common base class
- * You may not want to use that interface internaly
- * POOR mans interface
+ * This is the base class for all our Interfaces to the
+ * PIM Records. It is pointer based and can be used
+ * generically for all types of Records.
+ *
*/
-class OPimBasePrivate;
struct OPimBase {
+ //@{
+ OPimBase();
+ virtual ~OPimBase();
+ //@}
+
+ //@{
/**
* return the rtti
*/
virtual int rtti() const = 0;
virtual OPimRecord* record()const = 0;
virtual OPimRecord* record(int uid)const = 0;
+ //@}
+
+ //@{
virtual bool add( const OPimRecord& ) = 0;
virtual bool add( const OPimRecord* ) = 0;
+
virtual bool remove( int uid ) = 0;
virtual bool remove( const OPimRecord& ) = 0;
+ //@}
+
+ //@{
virtual void clear() = 0;
virtual bool load() = 0;
virtual bool save() = 0;
- virtual QArray<int> records()const = 0;
- /*
- * ADD editing here?
- * -zecke
+ //@}
+
+ //@{
+ virtual QArray<UID> records()const = 0;
+
+ /** 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, /** Use Wildcards */
+ IgnoreCase = 0x0002, /** Ignore the Case */
+ RegExp = 0x0004, /** Do a Regular Expression match */
+ ExactMatch = 0x0008, /** It needs to exactly match */
+ 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 */
+ LastItem = 0xffff /** the last possible name */
+ };
+
+ /**
+ * Common Attributes for the Sort Order
*/
+ enum SortOrderBase {
+ SortSummary = 0, /** Sort by a Summary of the records */
+ SortByCategory = 1, /** Sort by Category */
+ SortByDate = 2, /** Sort by Date */
+ SortCustom = 10, /** The First available sort number for the OPimAccessTemplates */
+ LastSortOrderBase = 0xffff /** make this enum 16bit large */
+ };
+
+ /**
+ * Sort with the help of the \sa sorted function
+ * a list of Items.
+ * The Item you provide in SortOrder will be used
+ * for sorting.
+ *
+ * @see sorted
+ */
+ enum SortFilterBase {
+ FilterCategory = 1,
+ FilterCustom = 1024,
+ LastSortFilterBase = 0xffffffff
+ };
+
+ virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0;
+ virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings,
+ const QDateTime& d = QDateTime() )const = 0;
+ virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
+ int sortOrder, int sortFilter, int cat)const = 0;
+ virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
+ int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
+ virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0;
+ virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
+ virtual OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const = 0;
+ virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0;
+ //@}
+
+
+protected:
+ OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const;
+
private:
OPimBasePrivate* d;
-
};
+
+
/**
* internal template base
* Attention: T needs to implement the copy c'tor!!!
*/
class OTemplateBasePrivate;
template <class T = OPimRecord>
class OTemplateBase : public OPimBase {
public:
- /** Look ahead direction of cache */
- enum CacheDirection { Forward=0, Reverse };
-
- OTemplateBase() {
+ /**
+ * The Direction for ReadAhead/ReadBehind which will
+ * be used by the backends to Cache Items in
+ * advance.
+ * For example if you know that you will access the
+ * next ten items you can give the backend a hint
+ * to read ahead or read before.
+ */
+ enum CacheDirection {
+ Forward=0, /** Go forward when caching (++ to the index) */
+ Reverse /** Go backward when caching (-- to the index) */
};
- virtual ~OTemplateBase() {
- }
+
+
+ //@{
+ OTemplateBase() {};
+ virtual ~OTemplateBase() {}
+ //@}
+
+
+ //@{
virtual T find( int uid )const = 0;
/**
* read ahead find
*/
virtual T find( int uid, const QArray<int>& items,
uint current, CacheDirection dir = Forward )const = 0;
+ //@}
+ //@{
/**
* Put element into Cache
*/
virtual void cache( const T& )const = 0;
virtual void setSaneCacheSize( int ) = 0;
OPimRecord* record()const;
OPimRecord* record(int uid )const;
static T* rec();
-
+ //@}
private:
OTemplateBasePrivate *d;
};
template <class T>
OPimRecord* OTemplateBase<T>::record()const {
T* t = new T;
return t;
}
template <class T>
OPimRecord* OTemplateBase<T>::record(int uid )const {
T t2 = find(uid );
T* t1 = new T(t2);
return t1;
-};
+}
+
template <class T>
T* OTemplateBase<T>::rec() {
return new T;
}
-
}
#endif
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index 5b32b1f..1dc36b4 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -1,193 +1,207 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimtimezone.h"
/* OPIE */
#include <opie2/odebug.h>
/* STD */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
namespace Opie
{
-QDateTime utcTime( time_t t )
+/*
+ * Save the old timeZone in a secure way (NULL Pointer check),
+ * set the new timeZone from the parameter, call tzset
+ * and then return the old timezone
+ */
+static QString setTimeZone( const QString& zone) {
+ QString old;
+ char *org = ::getenv( "TZ" );
+ if( org )
+ old = QString::fromLocal8Bit( org );
+
+ ::setenv( "TZ", zone.local8Bit(), true );
+ ::tzset();
+
+ return old;
+}
+
+static void resetTimeZone( const QString& zone ) {
+ ::setenv( "TZ", zone.local8Bit(), true );
+}
+
+static QDateTime utcTime( time_t t )
{
tm * broken = ::gmtime( &t );
QDateTime ret;
ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
return ret;
}
-QDateTime utcTime( time_t t, const QString& zone )
+static QDateTime utcTime( time_t t, const QString& zone )
{
- QCString org = ::getenv( "TZ" );
-#ifndef Q_OS_MACX // Following line causes bus errors on Mac
-
- ::setenv( "TZ", zone.latin1(), true );
- ::tzset();
+#ifndef Q_OS_MACX // Following line causes bus errors on Mac
+ QString old = setTimeZone( zone );
tm* broken = ::localtime( &t );
- ::setenv( "TZ", org, true );
+ resetTimeZone( old );
#else
#warning "Need a replacement for MacOSX!!"
tm* broken = ::localtime( &t );
#endif
QDateTime ret;
ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
return ret;
}
-time_t to_Time_t( const QDateTime& utc, const QString& str )
+static time_t to_Time_t( const QDateTime& utc, const QString& str )
{
QDate d = utc.date();
QTime t = utc.time();
tm broken;
broken.tm_year = d.year() - 1900;
broken.tm_mon = d.month() - 1;
broken.tm_mday = d.day();
broken.tm_hour = t.hour();
broken.tm_min = t.minute();
broken.tm_sec = t.second();
- QCString org = ::getenv( "TZ" );
#ifndef Q_OS_MACX // Following line causes bus errors on Mac
-
- ::setenv( "TZ", str.latin1(), true );
- ::tzset();
-
+ QString old = setTimeZone( str );
time_t ti = ::mktime( &broken );
- ::setenv( "TZ", org, true );
+ resetTimeZone( old );
#else
#warning "Need a replacement for MacOSX!!"
time_t ti = ::mktime( &broken );
#endif
return ti;
}
}
namespace Opie
{
OPimTimeZone::OPimTimeZone( const ZoneName& zone )
: m_name( zone )
{}
OPimTimeZone::~OPimTimeZone()
{}
bool OPimTimeZone::isValid() const
{
return !m_name.isEmpty();
}
/*
* we will get the current timezone
* and ask it to convert to the timezone date
*/
QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt )
{
return OPimTimeZone::current().toDateTime( dt, *this );
}
QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt )
{
return OPimTimeZone::utc().toDateTime( dt, *this );
}
QDateTime OPimTimeZone::fromUTCDateTime( time_t t )
{
return utcTime( t );
}
QDateTime OPimTimeZone::toDateTime( time_t t )
{
return utcTime( t, m_name );
}
/*
* convert dt to utc using zone.m_name
* convert utc -> timeZoneDT using this->m_name
*/
QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
{
time_t utc = to_Time_t( dt, m_name );
return utcTime( utc, zone.m_name );
}
time_t OPimTimeZone::fromDateTime( const QDateTime& time )
{
return to_Time_t( time, m_name );
}
time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
{
return to_Time_t( time, "Europe/London" );
}
OPimTimeZone OPimTimeZone::current()
{
QCString str = ::getenv( "TZ" );
OPimTimeZone zone( str );
return zone;
}
OPimTimeZone OPimTimeZone::utc()
{
return OPimTimeZone( "Europe/London" );
}
QString OPimTimeZone::timeZone() const
{
return m_name;
}
}
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 27b36a6..16ca987 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -1,713 +1,810 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimtodo.h"
/* OPIE */
#include <opie2/opimstate.h>
#include <opie2/opimrecurrence.h>
#include <opie2/opimmaintainer.h>
#include <opie2/opimnotifymanager.h>
#include <opie2/opimresolver.h>
#include <opie2/odebug.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/palmtoprecord.h>
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include <qpe/stringutil.h>
/* QT */
#include <qobject.h>
#include <qshared.h>
namespace Opie
{
struct OPimTodo::OPimTodoData : public QShared
{
OPimTodoData() : QShared()
{
recur = 0;
state = 0;
maintainer = 0;
notifiers = 0;
};
~OPimTodoData()
{
delete recur;
delete maintainer;
delete notifiers;
+ delete state;
}
QDate date;
bool isCompleted: 1;
bool hasDate: 1;
int priority;
QString desc;
QString sum;
QMap<QString, QString> extra;
ushort prog;
OPimState *state;
OPimRecurrence *recur;
OPimMaintainer *maintainer;
QDate start;
QDate completed;
OPimNotifyManager *notifiers;
};
OPimTodo::OPimTodo( const OPimTodo &event )
: OPimRecord( event ), data( event.data )
{
data->ref();
- // owarn << "ref up" << oendl;
}
OPimTodo::~OPimTodo()
{
- // owarn << "~OPimTodo " << oendl;
if ( data->deref() )
{
- // owarn << "OPimTodo::dereffing" << oendl;
delete data;
data = 0l;
}
}
OPimTodo::OPimTodo( bool completed, int priority,
const QArray<int> &category,
const QString& summary,
const QString &description,
ushort progress,
bool hasDate, QDate date, int uid )
: OPimRecord( uid )
{
- // owarn << "OPimTodoData " + summary << oendl;
setCategories( category );
data = new OPimTodoData;
data->date = date;
data->isCompleted = completed;
data->hasDate = hasDate;
data->priority = priority;
data->sum = summary;
data->prog = progress;
data->desc = Qtopia::simplifyMultiLineSpace( description );
}
OPimTodo::OPimTodo( bool completed, int priority,
const QStringList &category,
const QString& summary,
const QString &description,
ushort progress,
bool hasDate, QDate date, int uid )
: OPimRecord( uid )
{
- // owarn << "OPimTodoData" + summary << oendl;
setCategories( idsFromString( category.join( ";" ) ) );
data = new OPimTodoData;
data->date = date;
data->isCompleted = completed;
data->hasDate = hasDate;
data->priority = priority;
data->sum = summary;
data->prog = progress;
data->desc = Qtopia::simplifyMultiLineSpace( description );
}
bool OPimTodo::match( const QRegExp &regExp ) const
{
if ( QString::number( data->priority ).find( regExp ) != -1 )
{
setLastHitField( Priority );
return true;
}
else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
{
setLastHitField( HasDate );
return true;
}
else if ( data->desc.find( regExp ) != -1 )
{
setLastHitField( Description );
return true;
}
else if ( data->sum.find( regExp ) != -1 )
{
setLastHitField( Summary );
return true;
}
return false;
}
bool OPimTodo::isCompleted() const
{
return data->isCompleted;
}
bool OPimTodo::hasDueDate() const
{
return data->hasDate;
}
-
+/**
+ * \brief Does this Todo have a start date
+ *
+ * Does this Todo have a start date. The decision
+ * is based on if the internal startDate isValid
+ * in the sense of QDate::isValid.
+ *
+ * @return True if the startDate isValid
+ * @see startDate
+ * @see setStartDate
+ * @see QDate::isValid()
+ */
bool OPimTodo::hasStartDate() const
{
return data->start.isValid();
}
-
+/**
+ * \brief Does this Todo have a Date when it was completed
+ *
+ * As in \sa hasStartDate() it is determined if there
+ * is a completed date by looking if the internal date
+ * isValid \sa QDate::isValid.
+ *
+ * @see hasStartDate
+ * @return True if the completedDate is set and valid.
+ */
bool OPimTodo::hasCompletedDate() const
{
return data->completed.isValid();
}
int OPimTodo::priority() const
{
return data->priority;
}
QString OPimTodo::summary() const
{
return data->sum;
}
ushort OPimTodo::progress() const
{
return data->prog;
}
QDate OPimTodo::dueDate() const
{
return data->date;
}
QDate OPimTodo::startDate() const
{
return data->start;
}
QDate OPimTodo::completedDate() const
{
return data->completed;
}
QString OPimTodo::description() const
{
return data->desc;
}
bool OPimTodo::hasState() const
{
if ( !data->state ) return false;
return ( data->state->state() != OPimState::Undefined );
}
OPimState OPimTodo::state() const
{
if ( !data->state )
{
OPimState state;
return state;
}
return ( *data->state );
}
bool OPimTodo::hasRecurrence() const
{
if ( !data->recur ) return false;
return data->recur->doesRecur();
}
OPimRecurrence OPimTodo::recurrence() const
{
if ( !data->recur ) return OPimRecurrence();
return ( *data->recur );
}
bool OPimTodo::hasMaintainer() const
{
if ( !data->maintainer ) return false;
return ( data->maintainer->mode() != OPimMaintainer::Undefined );
}
OPimMaintainer OPimTodo::maintainer() const
{
if ( !data->maintainer ) return OPimMaintainer();
return ( *data->maintainer );
}
void OPimTodo::setCompleted( bool completed )
{
changeOrModify();
data->isCompleted = completed;
}
void OPimTodo::setHasDueDate( bool hasDate )
{
changeOrModify();
data->hasDate = hasDate;
}
void OPimTodo::setDescription( const QString &desc )
{
- // owarn << "desc " + desc << oendl;
changeOrModify();
data->desc = Qtopia::simplifyMultiLineSpace( desc );
}
void OPimTodo::setSummary( const QString& sum )
{
changeOrModify();
data->sum = sum;
}
void OPimTodo::setPriority( int prio )
{
changeOrModify();
data->priority = prio;
}
void OPimTodo::setDueDate( const QDate& date )
{
changeOrModify();
data->date = date;
}
void OPimTodo::setStartDate( const QDate& date )
{
changeOrModify();
data->start = date;
}
void OPimTodo::setCompletedDate( const QDate& date )
{
changeOrModify();
data->completed = date;
}
void OPimTodo::setState( const OPimState& state )
{
changeOrModify();
if ( data->state )
( *data->state ) = state;
else
data->state = new OPimState( state );
}
void OPimTodo::setRecurrence( const OPimRecurrence& rec )
{
changeOrModify();
if ( data->recur )
( *data->recur ) = rec;
else
data->recur = new OPimRecurrence( rec );
}
void OPimTodo::setMaintainer( const OPimMaintainer& pim )
{
changeOrModify();
if ( data->maintainer )
( *data->maintainer ) = pim;
else
data->maintainer = new OPimMaintainer( pim );
}
-bool OPimTodo::isOverdue( )
+bool OPimTodo::isOverdue( )const
{
if ( data->hasDate && !data->isCompleted )
return QDate::currentDate() > data->date;
return false;
}
void OPimTodo::setProgress( ushort progress )
{
changeOrModify();
data->prog = progress;
}
QString OPimTodo::toShortText() const
{
return summary();
}
/*!
Returns a richt text string
*/
QString OPimTodo::toRichText() const
{
QString text;
QStringList catlist;
// summary
text += "<b><h3><img src=\"todo/TodoList\"> ";
if ( !summary().isEmpty() )
{
text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
}
text += "</h3></b><br><hr><br>";
// description
if ( !description().isEmpty() )
{
text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
}
// priority
int priorityval = priority();
text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
QString::number( priorityval ) + "\"> ";
switch ( priorityval )
{
case 1 : text += QObject::tr( "Very high" );
break;
case 2 : text += QObject::tr( "High" );
break;
case 3 : text += QObject::tr( "Normal" );
break;
case 4 : text += QObject::tr( "Low" );
break;
case 5 : text += QObject::tr( "Very low" );
break;
};
text += "<br>";
// progress
text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
+ QString::number( progress() ) + " %<br>";
// due date
if ( hasDueDate() )
{
QDate dd = dueDate();
int off = QDate::currentDate().daysTo( dd );
text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
if ( off < 0 )
text += "#FF0000";
else if ( off == 0 )
text += "#FFFF00";
else if ( off > 0 )
text += "#00FF00";
text += "\">" + dd.toString() + "</font><br>";
}
// categories
text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
text += categoryNames( "Todo List" ).join( ", " );
text += "<br>";
return text;
}
bool OPimTodo::hasNotifiers() const
{
if ( !data->notifiers ) return false;
return !data->notifiers->isEmpty();
}
OPimNotifyManager& OPimTodo::notifiers()
{
if ( !data->notifiers )
data->notifiers = new OPimNotifyManager;
return ( *data->notifiers );
}
const OPimNotifyManager& OPimTodo::notifiers() const
{
if ( !data->notifiers )
data->notifiers = new OPimNotifyManager;
return ( *data->notifiers );
}
bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
{
if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if ( hasDueDate() && toDoEvent.hasDueDate() )
{
if ( dueDate() == toDoEvent.dueDate() )
{ // let's the priority decide
return priority() < toDoEvent.priority();
}
else
{
return dueDate() < toDoEvent.dueDate();
}
}
return false;
}
bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
{
if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
if ( hasDueDate() && toDoEvent.hasDueDate() )
{
if ( dueDate() == toDoEvent.dueDate() )
{ // let's the priority decide
return priority() <= toDoEvent.priority();
}
else
{
return dueDate() <= toDoEvent.dueDate();
}
}
return true;
}
bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
{
if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if ( hasDueDate() && toDoEvent.hasDueDate() )
{
if ( dueDate() == toDoEvent.dueDate() )
{ // let's the priority decide
return priority() > toDoEvent.priority();
}
else
{
return dueDate() > toDoEvent.dueDate();
}
}
return false;
}
bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
{
if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
if ( hasDueDate() && toDoEvent.hasDueDate() )
{
if ( dueDate() == toDoEvent.dueDate() )
{ // let's the priority decide
return priority() > toDoEvent.priority();
}
else
{
return dueDate() > toDoEvent.dueDate();
}
}
return true;
}
bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
{
if ( data->priority != toDoEvent.data->priority ) return false;
if ( data->priority != toDoEvent.data->prog ) return false;
if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
if ( data->hasDate != toDoEvent.data->hasDate ) return false;
if ( data->date != toDoEvent.data->date ) return false;
if ( data->sum != toDoEvent.data->sum ) return false;
if ( data->desc != toDoEvent.data->desc ) return false;
if ( data->maintainer != toDoEvent.data->maintainer )
return false;
return OPimRecord::operator==( toDoEvent );
}
void OPimTodo::deref()
{
- // owarn << "deref in ToDoEvent" << oendl;
if ( data->deref() )
{
- // owarn << "deleting" << oendl;
delete data;
data = 0;
}
}
OPimTodo &OPimTodo::operator=( const OPimTodo &item )
{
if ( this == &item ) return * this;
OPimRecord::operator=( item );
- //owarn << "operator= ref " << oendl;
item.data->ref();
deref();
data = item.data;
return *this;
}
QMap<int, QString> OPimTodo::toMap() const
{
QMap<int, QString> map;
map.insert( Uid, QString::number( uid() ) );
map.insert( Category, idsToString( categories() ) );
map.insert( HasDate, QString::number( data->hasDate ) );
map.insert( Completed, QString::number( data->isCompleted ) );
map.insert( Description, data->desc );
map.insert( Summary, data->sum );
map.insert( Priority, QString::number( data->priority ) );
map.insert( DateDay, QString::number( data->date.day() ) );
map.insert( DateMonth, QString::number( data->date.month() ) );
map.insert( DateYear, QString::number( data->date.year() ) );
map.insert( Progress, QString::number( data->prog ) );
// map.insert( CrossReference, crossToString() );
/* FIXME!!! map.insert( State, );
map.insert( Recurrence, );
map.insert( Reminders, );
map.
*/
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 OPimTodo::changeOrModify()
{
if ( data->count != 1 )
{
- owarn << "changeOrModify" << oendl;
data->deref();
OPimTodoData* d2 = new OPimTodoData();
copy( data, d2 );
data = d2;
}
}
// WATCHOUT
/*
* if you add something to the Data struct
* be sure to copy it here
*/
void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
{
dest->date = src->date;
dest->isCompleted = src->isCompleted;
dest->hasDate = src->hasDate;
dest->priority = src->priority;
dest->desc = src->desc;
dest->sum = src->sum;
dest->extra = src->extra;
dest->prog = src->prog;
if ( src->state )
dest->state = new OPimState( *src->state );
if ( src->recur )
dest->recur = new OPimRecurrence( *src->recur );
if ( src->maintainer )
dest->maintainer = new OPimMaintainer( *src->maintainer )
;
dest->start = src->start;
dest->completed = src->completed;
if ( src->notifiers )
dest->notifiers = new OPimNotifyManager( *src->notifiers );
}
QString OPimTodo::type() const
{
return QString::fromLatin1( "OPimTodo" );
}
-QString OPimTodo::recordField( int /*id*/ ) const
+QString OPimTodo::recordField( int id) const
{
- return QString::null;
+ QString res;
+ Q_UNUSED( id )
+#if 0
+ switch( id ) {
+ case HasDate:
+ res = (hasDueDate() ?
+ QObject::tr( "Has a due-date" )
+ : QObject::tr( "No due-date" ));
+ break;
+ case Completed:
+ res = ( isCompleted() ?
+ QObject::tr( "Completed" ) :
+ QObject::tr( "Not completed" ));
+ break;
+ case Description:
+ res = description();
+ break;
+ case Summary:
+ res = summary();
+ break;
+ case Priority:
+ res = QString::number( priority() );
+ break;
+ case DateDay:
+ res = QString::number( dueDate().day() );
+ break;
+ case DateMonth:
+ res = QString::number( dueDate().month() );
+ break;
+ case DateYear:
+ res = QString::number( dueDate().year() );
+ break;
+ case Progress:
+ res = QString::number( progress() );
+ break;
+ case State:
+ res = QString::number( state().state() );
+ break;
+ case Recurrence:
+ res = ( hasRecurrence() ?
+ QString::null /*recurrence().summary()*/ :
+ QObject::tr("No reccurrence"));
+ break;
+ case Alarms:
+ break;
+ case Reminders:
+ break;
+ case Maintainer:
+ break;
+ case StartDate:
+ res = ( hasStartDate() ?
+ /*TimeString::()*/ QString::null :
+ QObject::tr( "No start-date" ) );
+ break;
+ case CompletedDate:
+ res = ( hasCompletedDate() ?
+ /*TimeString::()*/ QString::null :
+ QObject::tr( "No completed-date" ) );
+ break;
+ case DueDate:
+ res = ( hasDueDate() ?
+ /*TimeString::()*/ QString::null :
+ QObject::tr( "No due-date" );
+ break;
+ default:
+ res = OPimRecord::recordField( id );
+ }
+
+#endif
+ return res;
}
int OPimTodo::rtti() const
{
return OPimResolver::TodoList;
}
+/**
+ * \brief Provide a SafeCast to OPimTodo from a OPimRecord
+ *
+ * Provide a safe cast that will return 0 if the record
+ * type is not OPimTodo. In the other case it will
+ * be casted to OPimTodo and returned
+ *
+ * @param rec The OPimRecord to be casted
+ *
+ * @return a pointer to OPimTodo or 0l
+ */
+OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) {
+ return (rec && rec->rtti() == OPimResolver::TodoList ) ?
+ static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) :
+ 0l;
+}
+
}
diff --git a/libopie2/opiepim/core/opimtodo.h b/libopie2/opiepim/core/opimtodo.h
index e17fe6a..f4f9926 100644
--- a/libopie2/opiepim/core/opimtodo.h
+++ b/libopie2/opiepim/core/opimtodo.h
@@ -1,320 +1,325 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#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>
namespace Opie
{
class OPimState;
class OPimRecurrence;
class OPimMaintainer;
class OPimNotifyManager;
class OPimTodo : public OPimRecord
{
public:
typedef QValueList<OPimTodo> 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
+ CompletedDate,
+//ADDITIONAL FOR RECORDFIELD
+ DueDate,
};
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
**/
OPimTodo( 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*/ );
OPimTodo( 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
*
*/
OPimTodo( const OPimTodo & );
/**
*destructor
*/
~OPimTodo();
/**
* Is this event completed?
*/
bool isCompleted() const;
/**
* Does this Event have a deadline
*/
bool hasDueDate() const;
bool hasStartDate() const;
bool hasCompletedDate() 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 OPimTodo?
*/
OPimState state() const;
/**
* has recurrence?
*/
bool hasRecurrence() const;
/**
* the recurrance of this
*/
OPimRecurrence recurrence() const;
/**
* does this OPimTodo have a maintainer?
*/
bool hasMaintainer() const;
/**
* the Maintainer of this OPimTodo
*/
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;
/*
* FIXME check if the sharing is still fine!! -zecke
* ### CHECK If API is fine
*/
/**
* return a reference to our notifiers...
*/
OPimNotifyManager &notifiers();
/**
*
*/
const OPimNotifyManager &notifiers() const;
/**
* reimplementations
*/
QString type() const;
QString toShortText() 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 OPimRecurrence& );
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 isOverdue()const;
virtual bool match( const QRegExp &r ) const;
bool operator<( const OPimTodo &toDoEvent ) const;
bool operator<=( const OPimTodo &toDoEvent ) const;
bool operator!=( const OPimTodo &toDoEvent ) const;
bool operator>( const OPimTodo &toDoEvent ) const;
bool operator>=( const OPimTodo &toDoEvent ) const;
bool operator==( const OPimTodo &toDoEvent ) const;
OPimTodo &operator=( const OPimTodo &toDoEvent );
+ //@{
int rtti() const;
+ static OPimTodo* safeCast( const OPimRecord* );
+ //@}
+
private:
class OPimTodoPrivate;
struct OPimTodoData;
void deref();
inline void changeOrModify();
void copy( OPimTodoData* src, OPimTodoData* dest );
OPimTodoPrivate *d;
OPimTodoData *data;
};
inline bool OPimTodo::operator!=( const OPimTodo &toDoEvent ) const
{
return !( *this == toDoEvent );
}
}
#endif
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index 26a68a0..4ad5950 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -1,101 +1,88 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qdatetime.h>
#include <qpe/alarmserver.h>
// #include "otodoaccesssql.h"
#include <opie2/otodoaccess.h>
#include <opie2/obackendfactory.h>
#include <opie2/opimresolver.h>
#include <opie2/opimglobal.h>
namespace Opie {
OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
: QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
{
// if (end == 0l )
// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null);
// Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben !
if (end == 0l )
m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null);
setBackEnd( m_todoBackEnd );
}
OPimTodoAccess::~OPimTodoAccess() {
-// owarn << "~OPimTodoAccess" << oendl;
}
+
void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
QValueList<OPimTodo>::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
replace( (*it) );
}
}
OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
const QDate& end,
- bool includeNoDates ) {
+ bool includeNoDates )const {
QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
List lis( ints, this );
return lis;
}
OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
- bool includeNoDates ) {
+ bool includeNoDates )const {
return effectiveToDos( start, QDate::currentDate(),
includeNoDates );
}
-OPimTodoAccess::List OPimTodoAccess::overDue() {
+OPimTodoAccess::List OPimTodoAccess::overDue()const {
List lis( m_todoBackEnd->overDue(), this );
return lis;
}
-/* sort order */
-OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
- QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
- filter, cat );
- OPimTodoAccess::List list( ints, this );
- return list;
-}
+
void OPimTodoAccess::removeAllCompleted() {
m_todoBackEnd->removeAllCompleted();
}
-QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
- return m_todoBackEnd->supports();
-}
-bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
- return backendSupport(ar).testBit( attr );
-}
-
int OPimTodoAccess::rtti() const
{
return OPimResolver::TodoList;
}
}
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index 3f5af30..8338586 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -1,142 +1,118 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIE_TODO_ACCESS_H
#define OPIE_TODO_ACCESS_H
#include <qobject.h>
#include <qvaluelist.h>
#include <opie2/opimtodo.h>
#include <opie2/otodoaccessbackend.h>
#include <opie2/opimaccesstemplate.h>
namespace Opie {
/**
* OPimTodoAccess
* the class to get access to
* the todolist
*/
class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> {
Q_OBJECT
public:
- enum SortOrder { Completed = 0,
+ enum SortOrder { Completed = SortCustom,
Priority,
- Description,
Deadline };
- enum SortFilter{ Category =1,
- OnlyOverDue= 2,
- DoNotShowCompleted =4 };
+ enum SortFilter{ OnlyOverDue= FilterCustom,
+ DoNotShowCompleted = FilterCustom<<1 };
/**
* if you use 0l
* the default resource will be
* picked up
*/
OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random );
~OPimTodoAccess();
/* our functions here */
/**
* include todos from start to end
* includeNoDates whether or not to include
* events with no dates
*/
List effectiveToDos( const QDate& start,
const QDate& end,
- bool includeNoDates = true );
+ bool includeNoDates = true )const;
/**
* start
* end date taken from the currentDate()
*/
List effectiveToDos( const QDate& start,
- bool includeNoDates = true );
+ bool includeNoDates = true )const;
/**
* return overdue OPimTodos
*/
- List overDue();
-
- /**
- *
- */
- List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
+ List overDue()const;
/**
* merge a list of OPimTodos into
* the resource
*/
void mergeWith( const QValueList<OPimTodo>& );
/**
* delete all already completed items
*/
void removeAllCompleted();
/**
- * request information about what a backend supports.
- * Supports in the sense of beeing able to store.
- * This is related to the enum in OPimTodo
- *
- * @param backend Will be used in the future when we support multiple backend
- */
- QBitArray backendSupport( const QString& backend = QString::null )const;
-
- /**
- * see above but for a specefic attribute. This method was added for convience
- * @param attr The attribute to be queried for
- * @param backend Will be used in the future when we support multiple backends
- */
- bool backendSupports( int attr, const QString& backend = QString::null )const;
-
-
- /**
* Return identification of used records
*/
int rtti() const;
signals:
/**
* if the OPimTodoAccess was changed
*/
void changed( const OPimTodoAccess* );
void changed( const OPimTodoAccess*, int uid );
void added( const OPimTodoAccess*, int uid );
void removed( const OPimTodoAccess*, int uid );
private:
int m_cat;
OPimTodoAccessBackend* m_todoBackEnd;
class OPimTodoAccessPrivate;
OPimTodoAccessPrivate* d;
};
}
#endif