summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
authorzecke <zecke>2004-07-29 19:42:59 (UTC)
committer zecke <zecke>2004-07-29 19:42:59 (UTC)
commit52b1ae9281920cf5a40fe543112d8b00e7699ef6 (patch) (side-by-side diff)
tree0b0a79ff9a45a66f32fe555ee662b4acc8f6eff9 /libopie2/opiepim/core
parentc170d1f931ae03c2ec917b7abf4bd5d0e94a3760 (diff)
downloadopie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.zip
opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.gz
opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.bz2
-UTC -> Europe/London when referring to no timezone
-special handling for allDay Event in OPImEvent, avoid setting timezone as it is by default UTC -No timezone set by default for an Event -Recurrence is UTC (no timezone) -Provide upgrade path from DateBook as by default events were in the current timezone but didn't have the timezone attribute -unified handling of timezones, compatible with QtopiaDesktop -do less conversions -...
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimevent.cpp38
-rw-r--r--libopie2/opiepim/core/opimrecurrence.cpp22
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp12
3 files changed, 35 insertions, 37 deletions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 8752fce..739cb6f 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -275,101 +275,102 @@ QDateTime OPimEvent::startDateTime() const
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 )
- return QDateTime( data->start.date(), QTime( 23, 59, 59 ) );
+ 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;
- if ( allDay ) data->timezone = "UTC";
}
void OPimEvent::setTimeZone( const QString& tz )
{
changeOrModify();
data->timezone = tz;
}
QString OPimEvent::timeZone() const
{
- if ( data->isAllDay ) return QString::fromLatin1( "UTC" );
+ 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 );
@@ -543,51 +544,52 @@ void OPimEvent::deref()
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" );
}
- OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
- retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
- retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
+ /* 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 ] );
@@ -609,69 +611,63 @@ QMap<int, QString> OPimEvent::toMap() const
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();
+ time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
/* AllDay is always in UTC */
if ( isAllDay() )
{
OPimTimeZone utc = OPimTimeZone::utc();
- setStartDateTime( utc.fromUTCDateTime( start ) );
- setEndDateTime ( utc.fromUTCDateTime( end ) );
- setTimeZone( "UTC" ); // make sure it is really utc
+ setStartDateTime(utc.toDateTime( start ) );
+ setEndDateTime ( utc.toDateTime( end ) );
}
- else
- {
+ else {
/* to current date time */
- // owarn << " Start is " << start << "" << oendl;
- OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
- QDateTime date = zone.toDateTime( start );
- owarn << " Start is " << date.toString() << "" << oendl;
- setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
-
- date = zone.toDateTime( end );
- setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
+ OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
+
+ ev.setStartDateTime(to_zone.toDateTime( start));
+ ev.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 ] );
diff --git a/libopie2/opiepim/core/opimrecurrence.cpp b/libopie2/opiepim/core/opimrecurrence.cpp
index 4b1d886..c3ae350 100644
--- a/libopie2/opiepim/core/opimrecurrence.cpp
+++ b/libopie2/opiepim/core/opimrecurrence.cpp
@@ -611,81 +611,81 @@ QString OPimRecurrence::rTypeString() const
}
return retString;
}
QMap<QString, OPimRecurrence::RepeatType> OPimRecurrence::rTypeValueConvertMap() const
{
QMap<QString, RepeatType> convertMap;
convertMap.insert( QString( "Daily" ), OPimRecurrence::Daily );
convertMap.insert( QString( "Weekly" ), OPimRecurrence::Weekly );
convertMap.insert( QString( "MonthlyDay" ), OPimRecurrence::MonthlyDay );
convertMap.insert( QString( "MonthlyDate" ), OPimRecurrence::MonthlyDate );
convertMap.insert( QString( "Yearly" ), OPimRecurrence::Yearly );
convertMap.insert( QString( "NoRepeat" ), OPimRecurrence::NoRepeat );
return convertMap;
}
QMap<int, QString> OPimRecurrence::toMap() const
{
QMap<int, QString> retMap;
-
+
retMap.insert( OPimRecurrence::RType, rTypeString() );
retMap.insert( OPimRecurrence::RWeekdays, QString::number( static_cast<int>( data->days ) ) );
retMap.insert( OPimRecurrence::RPosition, QString::number(data->pos ) );
retMap.insert( OPimRecurrence::RFreq, QString::number( data->freq ) );
retMap.insert( OPimRecurrence::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) );
if( data -> hasEnd )
- retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) );
- retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::utc().fromUTCDateTime( data->create ) ) );
-
+ retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::current().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) );
+ retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::current().fromUTCDateTime( data->create ) ) );
+
if ( data->list.isEmpty() ) return retMap;
// save exceptions list here!!
ExceptionList::ConstIterator it;
ExceptionList list = data->list;
QString exceptBuf;
QDate date;
for ( it = list.begin(); it != list.end(); ++it ) {
date = (*it);
if ( it != list.begin() ) exceptBuf += " ";
-
+
exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() );
}
retMap.insert( OPimRecurrence::Exceptions, exceptBuf );
return retMap;
}
void OPimRecurrence::fromMap( const QMap<int, QString>& map )
{
- QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap();
+ QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap();
data -> type = repTypeMap[ map [OPimRecurrence::RType] ];
data -> days = (char) map[ OPimRecurrence::RWeekdays ].toInt();
data -> pos = map[ OPimRecurrence::RPosition ].toInt();
data -> freq = map[ OPimRecurrence::RFreq ].toInt();
data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false;
- OPimTimeZone utc = OPimTimeZone::utc();
+ OPimTimeZone cur = OPimTimeZone::current();
if ( data -> hasEnd ){
- data -> end = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date();
+ data -> end = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date();
}
- data -> create = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date();
+ data -> create = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date();
#if 0
// FIXME: Exceptions currently not supported...
// Convert the list of exceptions from QString into ExceptionList
data -> list.clear();
QString exceptStr = map[ OPimRecurrence::Exceptions ];
QStringList exceptList = QStringList::split( " ", exceptStr );
...
#endif
-
-
+
+
}
}
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index fefceb5..5b32b1f 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -27,70 +27,73 @@
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 )
{
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 )
{
QCString org = ::getenv( "TZ" );
#ifndef Q_OS_MACX // Following line causes bus errors on Mac
::setenv( "TZ", zone.latin1(), true );
::tzset();
tm* broken = ::localtime( &t );
::setenv( "TZ", org, true );
#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 )
{
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();
time_t ti = ::mktime( &broken );
::setenv( "TZ", org, true );
#else
#warning "Need a replacement for MacOSX!!"
@@ -130,62 +133,61 @@ QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt )
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, zone.m_name );
- owarn << "" << utc << " " << zone.m_name << "" << oendl;
- return utcTime( utc, m_name );
+ 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, "UTC" );
+ return to_Time_t( time, "Europe/London" );
}
OPimTimeZone OPimTimeZone::current()
{
QCString str = ::getenv( "TZ" );
OPimTimeZone zone( str );
return zone;
}
OPimTimeZone OPimTimeZone::utc()
{
- return OPimTimeZone( "UTC" );
+ return OPimTimeZone( "Europe/London" );
}
QString OPimTimeZone::timeZone() const
{
return m_name;
}
}