зеркало из https://github.com/mozilla/pjs.git
Added ability to Snooze Alarms. Removed asserts to prevent crash on an erroneous calendar file
This commit is contained in:
Родитель
5c50a97069
Коммит
9d6193a87b
|
@ -40,7 +40,6 @@
|
|||
|
||||
#include "oeICalEventImpl.h"
|
||||
#include "nsMemory.h"
|
||||
//#include "stdlib.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define strcasecmp strcmp
|
||||
|
@ -141,7 +140,7 @@ oeICalEventImpl::oeICalEventImpl()
|
|||
m_location = nsnull;
|
||||
m_category = nsnull;
|
||||
m_isprivate = true;
|
||||
m_syncid = 0;
|
||||
m_syncid = nsnull;
|
||||
m_allday = false;
|
||||
m_hasalarm = false;
|
||||
m_alarmlength = 0;
|
||||
|
@ -157,6 +156,7 @@ oeICalEventImpl::oeICalEventImpl()
|
|||
m_lastalarmack = icaltime_null_time();
|
||||
SetAlarmUnits( "minutes" );
|
||||
SetRecurUnits( "weeks" );
|
||||
SetSyncId( "" );
|
||||
}
|
||||
|
||||
oeICalEventImpl::~oeICalEventImpl()
|
||||
|
@ -181,6 +181,8 @@ oeICalEventImpl::~oeICalEventImpl()
|
|||
nsMemory::Free( m_inviteemail );
|
||||
if( m_recurunits )
|
||||
nsMemory::Free( m_recurunits );
|
||||
if( m_syncid )
|
||||
nsMemory::Free( m_syncid );
|
||||
|
||||
if( m_start )
|
||||
m_start->Release();
|
||||
|
@ -380,22 +382,34 @@ NS_IMETHODIMP oeICalEventImpl::SetPrivateEvent(PRBool aNewVal)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute long SyncId; */
|
||||
NS_IMETHODIMP oeICalEventImpl::GetSyncId(PRUint32 *aRetVal)
|
||||
|
||||
/* attribute string SyncId; */
|
||||
NS_IMETHODIMP oeICalEventImpl::GetSyncId(char * *aRetVal)
|
||||
{
|
||||
#ifdef ICAL_DEBUG_ALL
|
||||
printf( "GetSyncId()\n" );
|
||||
#endif
|
||||
*aRetVal = m_syncid;
|
||||
return NS_OK;
|
||||
if( m_alarmunits ) {
|
||||
*aRetVal= (char*) nsMemory::Clone( m_syncid, strlen(m_syncid)+1);
|
||||
if( *aRetVal == nsnull )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
} else
|
||||
*aRetVal= EmptyReturn();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::SetSyncId(PRUint32 aNewVal)
|
||||
NS_IMETHODIMP oeICalEventImpl::SetSyncId(const char * aNewVal)
|
||||
{
|
||||
#ifdef ICAL_DEBUG_ALL
|
||||
printf( "SetSyncId(%lu)\n", aNewVal );
|
||||
printf( "SetSyncId( %s )\n", aNewVal );
|
||||
#endif
|
||||
m_syncid = aNewVal;
|
||||
if( m_syncid )
|
||||
nsMemory::Free( m_syncid );
|
||||
|
||||
if( aNewVal )
|
||||
m_syncid= (char*) nsMemory::Clone( aNewVal, strlen(aNewVal)+1);
|
||||
else
|
||||
m_syncid = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -675,9 +689,14 @@ NS_IMETHODIMP oeICalEventImpl::GetNextRecurrence( PRTime begin, PRTime *retval,
|
|||
|
||||
//for recurring events
|
||||
icalcomponent *vcalendar = AsIcalComponent();
|
||||
if ( !vcalendar ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::GetNextRecurrence() failed!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalcomponent *vevent = icalcomponent_get_first_component( vcalendar, ICAL_VEVENT_COMPONENT );
|
||||
assert( vevent != 0);
|
||||
|
||||
icalproperty *prop = icalcomponent_get_first_property( vevent, ICAL_RRULE_PROPERTY );
|
||||
if ( prop != 0) {
|
||||
|
@ -747,11 +766,21 @@ icaltimetype oeICalEventImpl::GetNextAlarmTime( icaltimetype begin ) {
|
|||
icaltimetype checkloop = starting;
|
||||
do {
|
||||
checkloop = GetNextRecurrence( checkloop );
|
||||
if( icaltime_is_null_time( checkloop ) )
|
||||
return checkloop;
|
||||
result = checkloop;
|
||||
if( icaltime_is_null_time( checkloop ) ) {
|
||||
break;
|
||||
}
|
||||
result = CalculateAlarmTime( result );
|
||||
} while ( icaltime_compare( starting, result ) >= 0 );
|
||||
|
||||
for( int i=0; i<m_snoozetimes.size(); i++ ) {
|
||||
icaltimetype snoozetime = ConvertFromPrtime( m_snoozetimes[i] );
|
||||
if( icaltime_is_null_time( result ) || icaltime_compare( snoozetime, result ) < 0 ) {
|
||||
if ( icaltime_compare( snoozetime, starting ) > 0 ) {
|
||||
result = snoozetime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -828,7 +857,15 @@ NS_IMETHODIMP oeICalEventImpl::GetIcalString(char **aRetVal)
|
|||
printf( "GetIcalString() = " );
|
||||
#endif
|
||||
|
||||
*aRetVal = nsnull;
|
||||
icalcomponent *vcalendar = AsIcalComponent();
|
||||
if ( !vcalendar ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::GetIcalString() failed!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char *str = icalcomponent_as_ical_string( vcalendar );
|
||||
if( str ) {
|
||||
*aRetVal= (char*) nsMemory::Clone( str, strlen(str)+1);
|
||||
|
@ -912,6 +949,21 @@ bool oeICalEventImpl::IsExcepted( PRTime date ) {
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::SetSnoozeTime( PRTime snoozetime )
|
||||
{
|
||||
#ifdef ICAL_DEBUG_ALL
|
||||
printf( "oeICalEventImpl::SetSnoozeTime()\n" );
|
||||
#endif
|
||||
icaltimetype tmpdate = ConvertFromPrtime( snoozetime );
|
||||
snoozetime = icaltime_as_timet( tmpdate );
|
||||
snoozetime *= 1000;
|
||||
m_snoozetimes.push_back( snoozetime );
|
||||
PRTime nowinms = time( nsnull );
|
||||
nowinms *= 1000;
|
||||
m_lastalarmack = ConvertFromPrtime( nowinms );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void oeICalEventImpl::ParseIcalComponent( icalcomponent *vcalendar )
|
||||
{
|
||||
#ifdef ICAL_DEBUG_ALL
|
||||
|
@ -919,11 +971,22 @@ void oeICalEventImpl::ParseIcalComponent( icalcomponent *vcalendar )
|
|||
#endif
|
||||
|
||||
icalcomponent *vevent = icalcomponent_get_first_component( vcalendar, ICAL_VEVENT_COMPONENT );
|
||||
assert( vevent != 0);
|
||||
if ( !vevent ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::ParseIcalComponent() failed: VEVENT not found!\n" );
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
//id
|
||||
icalproperty *prop = icalcomponent_get_first_property( vevent, ICAL_UID_PROPERTY );
|
||||
assert( prop != 0);
|
||||
if ( !prop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::ParseIcalComponent() failed: UID not found!\n" );
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
const char *tmpstr = icalproperty_get_uid( prop );
|
||||
m_id = atol( tmpstr );
|
||||
|
||||
|
@ -984,17 +1047,17 @@ void oeICalEventImpl::ParseIcalComponent( icalcomponent *vcalendar )
|
|||
prop = icalcomponent_get_next_property( vevent, ICAL_X_PROPERTY ) ) {
|
||||
icalparameter *tmppar = icalproperty_get_first_parameter( prop, ICAL_MEMBER_PARAMETER );
|
||||
if ( tmppar != 0 ) {
|
||||
tmpstr = (char *)icalparameter_get_member( tmppar );
|
||||
tmpstr = icalparameter_get_member( tmppar );
|
||||
if( strcmp( tmpstr, "SyncId" ) == 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( prop != 0) {
|
||||
tmpstr = (char *)icalproperty_get_value_as_string( prop );
|
||||
m_syncid= atol( tmpstr );
|
||||
tmpstr = icalproperty_get_value_as_string( prop );
|
||||
SetSyncId( tmpstr );
|
||||
} else
|
||||
m_syncid = 0;
|
||||
SetSyncId( "" );
|
||||
|
||||
//allday
|
||||
for( prop = icalcomponent_get_first_property( vevent, ICAL_X_PROPERTY );
|
||||
|
@ -1186,6 +1249,21 @@ void oeICalEventImpl::ParseIcalComponent( icalcomponent *vcalendar )
|
|||
PRTime exdateinms = ConvertToPrtime( exdate );
|
||||
m_exceptiondates.push_back( exdateinms );
|
||||
}
|
||||
|
||||
//snoozetimes
|
||||
icalcomponent *tmpcomp = icalcomponent_get_first_component( vevent, ICAL_X_COMPONENT );
|
||||
if ( tmpcomp != 0) {
|
||||
for( prop = icalcomponent_get_first_property( tmpcomp, ICAL_DTSTAMP_PROPERTY );
|
||||
prop != 0 ;
|
||||
prop = icalcomponent_get_next_property( tmpcomp, ICAL_DTSTAMP_PROPERTY ) ) {
|
||||
icaltimetype snoozetime = icalproperty_get_dtstamp( prop );
|
||||
if( !icaltime_is_null_time( m_lastalarmack ) && icaltime_compare( m_lastalarmack, snoozetime ) >= 0 )
|
||||
continue;
|
||||
PRTime snoozetimeinms = icaltime_as_timet( snoozetime );
|
||||
snoozetimeinms *= 1000;
|
||||
m_snoozetimes.push_back( snoozetimeinms );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define ICALEVENT_VERSION "1.1"
|
||||
|
@ -1198,7 +1276,12 @@ icalcomponent* oeICalEventImpl::AsIcalComponent()
|
|||
icalcomponent *newcalendar;
|
||||
|
||||
newcalendar = icalcomponent_new_vcalendar();
|
||||
assert(newcalendar != 0);
|
||||
if ( !newcalendar ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::AsIcalComponent() failed: Cannot create VCALENDAR!\n" );
|
||||
#endif
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
//version
|
||||
icalproperty *prop = icalproperty_new_version( ICALEVENT_VERSION );
|
||||
|
@ -1243,11 +1326,11 @@ icalcomponent* oeICalEventImpl::AsIcalComponent()
|
|||
icalcomponent_add_property( vevent, prop );
|
||||
|
||||
icalparameter *tmppar;
|
||||
|
||||
//syncId
|
||||
if( m_syncid ) {
|
||||
sprintf( tmpstr, "%lu", m_syncid );
|
||||
tmppar = icalparameter_new_member( "SyncId" );
|
||||
prop = icalproperty_new_x( tmpstr );
|
||||
if( m_syncid && strlen( m_syncid ) != 0 ){
|
||||
icalparameter *tmppar = icalparameter_new_member( "SyncId" );
|
||||
prop = icalproperty_new_x( m_syncid );
|
||||
icalproperty_add_parameter( prop, tmppar );
|
||||
icalcomponent_add_property( vevent, prop );
|
||||
}
|
||||
|
@ -1475,6 +1558,18 @@ icalcomponent* oeICalEventImpl::AsIcalComponent()
|
|||
prop = icalproperty_new_dtend( m_end->m_datetime );
|
||||
icalcomponent_add_property( vevent, prop );
|
||||
|
||||
//snoozetimes
|
||||
icalcomponent *tmpcomp=NULL;
|
||||
for( int i=0; i<m_snoozetimes.size(); i++ ) {
|
||||
if( tmpcomp == NULL )
|
||||
tmpcomp = icalcomponent_new( ICAL_X_COMPONENT );
|
||||
icaltimetype snoozetime = ConvertFromPrtime( m_snoozetimes[i] );
|
||||
prop = icalproperty_new_dtstamp( snoozetime );
|
||||
icalcomponent_add_property( tmpcomp, prop );
|
||||
}
|
||||
if( tmpcomp )
|
||||
icalcomponent_add_component( vevent, tmpcomp );
|
||||
|
||||
//add event to newcalendar
|
||||
icalcomponent_add_component( newcalendar, vevent );
|
||||
return newcalendar;
|
||||
|
|
|
@ -81,11 +81,10 @@ public:
|
|||
/* additional members */
|
||||
void ParseIcalComponent( icalcomponent *vcalendar );
|
||||
icalcomponent *AsIcalComponent();
|
||||
NS_IMETHODIMP SetId( PRUint32 newid );
|
||||
icaltimetype GetNextAlarmTime( icaltimetype begin );
|
||||
private:
|
||||
unsigned long m_id;
|
||||
unsigned long m_syncid;
|
||||
char *m_syncid;
|
||||
char *m_title;
|
||||
char *m_description;
|
||||
char *m_location;
|
||||
|
@ -109,6 +108,7 @@ private:
|
|||
oeDateTimeImpl *m_recurend;
|
||||
icaltimetype m_lastalarmack;
|
||||
std::vector<PRTime> m_exceptiondates;
|
||||
std::vector<PRTime> m_snoozetimes;
|
||||
icaltimetype GetNextRecurrence( icaltimetype begin );
|
||||
icaltimetype CalculateAlarmTime( icaltimetype date );
|
||||
bool IsExcepted( PRTime date );
|
||||
|
|
|
@ -309,13 +309,28 @@ END:VCALENDAR\n\
|
|||
";
|
||||
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalcalendar = icalparser_parse_string(icalrawcalendarstr);
|
||||
assert(icalcalendar != 0);
|
||||
if ( !icalcalendar ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: Cannot create VCALENDAR!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalevent = icalcomponent_get_first_component(icalcalendar,ICAL_VEVENT_COMPONENT);
|
||||
assert(icalevent != 0);
|
||||
if ( !icalevent ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: VEVENT not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalproperty *uid = icalproperty_new_uid( uidstr );
|
||||
icalcomponent_add_property( icalevent, uid );
|
||||
|
@ -445,10 +460,20 @@ END:VCALENDAR\n\
|
|||
#endif
|
||||
|
||||
icalcomponent *fetchedcal = icalfileset_fetch( stream, uidstr );
|
||||
assert( fetchedcal != 0 );
|
||||
if ( !fetchedcal ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: Cannot fetch event!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalcomponent *fetchedevent = icalcomponent_get_first_component( fetchedcal,ICAL_VEVENT_COMPONENT);
|
||||
assert( fetchedevent != 0 );
|
||||
if ( !fetchedevent ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: VEVENT not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Fetched Event\n");
|
||||
|
@ -457,50 +482,90 @@ END:VCALENDAR\n\
|
|||
icalproperty *tmpprop;
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_UID_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: UID not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("id: %s\n", icalproperty_get_uid( tmpprop ) );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_SUMMARY_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: SUMMARY not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Title: %s\n", icalproperty_get_summary( tmpprop ) );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_CATEGORIES_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: CATEGORIES not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Category: %s\n", icalproperty_get_categories( tmpprop ) );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_DESCRIPTION_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: DESCRIPTION not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Description: %s\n", icalproperty_get_description( tmpprop ) );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_LOCATION_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: LOCATION not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Location: %s\n", icalproperty_get_location( tmpprop ) );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_CLASS_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: CLASS not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Class: %s\n", (icalproperty_get_class( tmpprop ) == ICAL_CLASS_PUBLIC) ? "PUBLIC" : "PRIVATE" );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_DTSTART_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: DTSTART not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
start = icalproperty_get_dtstart( tmpprop );
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Start: %d-%d-%d %d:%d\n", start.year, start.month, start.day, start.hour, start.minute );
|
||||
#endif
|
||||
//
|
||||
tmpprop = icalcomponent_get_first_property( fetchedevent, ICAL_DTEND_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: DTEND not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
end = icalproperty_get_dtstart( tmpprop );
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("End: %d-%d-%d %d:%d\n", end.year, end.month, end.day, end.hour, end.minute );
|
||||
|
@ -516,11 +581,26 @@ END:VCALENDAR\n\
|
|||
}
|
||||
|
||||
icalcomponent *newcomp = icalcomponent_new_clone( fetchedcal );
|
||||
assert( newcomp != 0 );
|
||||
if ( !newcomp ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: Cannot clone event!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
icalcomponent *newevent = icalcomponent_get_first_component( newcomp, ICAL_VEVENT_COMPONENT );
|
||||
assert( newevent != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: VEVENT not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
tmpprop = icalcomponent_get_first_property( newevent, ICAL_SUMMARY_PROPERTY );
|
||||
assert( tmpprop != 0 );
|
||||
if ( !tmpprop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: SUMMARY not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
icalproperty_set_summary( tmpprop, "LUNCH AND LEARN TIME" );
|
||||
// icalfileset_modify( stream, fetchedcal, newcomp );
|
||||
icalfileset_remove_component( stream, fetchedcal );
|
||||
|
@ -528,20 +608,25 @@ END:VCALENDAR\n\
|
|||
icalcomponent_free( fetchedcal );
|
||||
//
|
||||
|
||||
icalfileset_commit(stream);
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Event updated\n");
|
||||
printf( "New Title: %s\n", icalproperty_get_summary( tmpprop ) );
|
||||
#endif
|
||||
|
||||
fetchedcal = icalfileset_fetch( stream, uidstr );
|
||||
assert( fetchedcal != 0 );
|
||||
if ( !fetchedcal ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::Test() failed: Cannot fetch event!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
icalfileset_remove_component( stream, fetchedcal );
|
||||
|
||||
#ifdef ICAL_DEBUG
|
||||
printf("Removed Event\n");
|
||||
#endif
|
||||
|
||||
icalfileset_commit(stream);
|
||||
icalfileset_free(stream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -567,7 +652,12 @@ oeICalImpl::SetServer( const char *str ) {
|
|||
icalfileset *stream;
|
||||
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SetServer() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalcomponent *comp;
|
||||
for( comp = icalfileset_get_first_component( stream );
|
||||
|
@ -613,7 +703,16 @@ NS_IMETHODIMP oeICalImpl::SetBatchMode(PRBool aBatchMode)
|
|||
if( m_batchMode != newBatchMode )
|
||||
{
|
||||
m_batchMode = aBatchMode;
|
||||
|
||||
// if batch mode changed to off, call set up alarm mamnager
|
||||
|
||||
if( !m_batchMode )
|
||||
{
|
||||
SetupAlarmManager();
|
||||
}
|
||||
|
||||
// tell observers about the change
|
||||
|
||||
for( int i=0; i<m_observerlist.size(); i++ )
|
||||
{
|
||||
if( m_batchMode )
|
||||
|
@ -653,14 +752,24 @@ NS_IMETHODIMP oeICalImpl::AddEvent(oeIICalEvent *icalevent, PRInt32 *retid)
|
|||
|
||||
*retid = 0;
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::AddEvent() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
do {
|
||||
newid = 900000000 + ((rand()%0x4ff) << 16) + rand()%0xFFFF;
|
||||
sprintf( uidstr, "%lu", newid );
|
||||
} while ( (fetchedcal = icalfileset_fetch( stream, uidstr )) != 0 );
|
||||
((oeICalEventImpl *)icalevent)->GetId( (PRUint32 *)&newid );
|
||||
|
||||
if( newid == 0 ) {
|
||||
do {
|
||||
newid = 900000000 + ((rand()%0x4ff) << 16) + rand()%0xFFFF;
|
||||
sprintf( uidstr, "%lu", newid );
|
||||
} while ( (fetchedcal = icalfileset_fetch( stream, uidstr )) != 0 );
|
||||
|
||||
((oeICalEventImpl *)icalevent)->SetId( newid );
|
||||
}
|
||||
|
||||
((oeICalEventImpl *)icalevent)->SetId( newid );
|
||||
vcalendar = ((oeICalEventImpl *)icalevent)->AsIcalComponent();
|
||||
|
||||
icalfileset_add_component( stream, vcalendar );
|
||||
|
@ -703,27 +812,40 @@ NS_IMETHODIMP oeICalImpl::ModifyEvent(oeIICalEvent *icalevent, PRInt32 *retid)
|
|||
icalcomponent *vcalendar;
|
||||
char uidstr[10];
|
||||
|
||||
*retid = 0;
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::ModifyEvent() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
((oeICalEventImpl *)icalevent)->GetId( (PRUint32 *)&id );
|
||||
vcalendar = ((oeICalEventImpl *)icalevent)->AsIcalComponent();
|
||||
|
||||
sprintf( uidstr, "%lu", id );
|
||||
|
||||
icalcomponent *fetchedcal = icalfileset_fetch( stream, uidstr );
|
||||
|
||||
oeICalEventImpl *oldevent;
|
||||
oeICalEventImpl *oldevent=nsnull;
|
||||
if( fetchedcal ) {
|
||||
icalfileset_remove_component( stream, fetchedcal );
|
||||
nsresult rv;
|
||||
if( NS_FAILED( rv = NS_NewICalEvent((oeIICalEvent**) &oldevent ))) {
|
||||
icalfileset_free(stream);
|
||||
return rv;
|
||||
}
|
||||
oldevent->ParseIcalComponent( fetchedcal );
|
||||
icalcomponent_free( fetchedcal );
|
||||
} else {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "WARNING Event not found.\n" );
|
||||
#endif
|
||||
icalfileset_free(stream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
vcalendar = ((oeICalEventImpl *)icalevent)->AsIcalComponent();
|
||||
icalfileset_add_component( stream, vcalendar );
|
||||
|
||||
*retid = id;
|
||||
|
@ -790,7 +912,12 @@ oeICalImpl::DeleteEvent( PRInt32 id )
|
|||
char uidstr[10];
|
||||
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::DeleteEvent() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sprintf( uidstr, "%lu", id );
|
||||
|
||||
|
@ -869,10 +996,20 @@ oeICalImpl::SearchBySQL( const char *sqlstr, nsISimpleEnumerator **resultList )
|
|||
eventEnum->Init( this );
|
||||
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
if ( !stream ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SearchBySQL() failed: Cannot open stream: %s!\n", serveraddr );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
gauge = icalgauge_new_from_sql( (char *)sqlstr );
|
||||
assert( gauge != 0 );
|
||||
if ( !gauge ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SearchBySQL() failed: Cannot create gauge\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalfileset_select( stream, gauge );
|
||||
|
||||
|
@ -881,10 +1018,20 @@ oeICalImpl::SearchBySQL( const char *sqlstr, nsISimpleEnumerator **resultList )
|
|||
comp != 0;
|
||||
comp = icalfileset_get_next_component( stream ) ) {
|
||||
icalcomponent *vevent = icalcomponent_get_first_component( comp, ICAL_VEVENT_COMPONENT );
|
||||
assert( vevent != 0);
|
||||
if ( !vevent ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SearchBySQL() failed: VEVENT not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
icalproperty *prop = icalcomponent_get_first_property( vevent, ICAL_UID_PROPERTY );
|
||||
assert( prop != 0);
|
||||
if ( !prop ) {
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SearchBySQL() failed: UID not found!\n" );
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
eventEnum->AddEventId( atol( icalproperty_get_uid( prop ) ) );
|
||||
}
|
||||
|
@ -1096,6 +1243,15 @@ void oeICalImpl::SetupAlarmManager() {
|
|||
printf( "oeICalImpl::SetupAlarmManager()\n" );
|
||||
#endif
|
||||
|
||||
if( m_batchMode )
|
||||
{
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SetupAlarmManager() - defering alarms while in batch mode\n" );
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRTime todayinms = PR_Now();
|
||||
PRInt64 usecpermsec;
|
||||
LL_I2L( usecpermsec, PR_USEC_PER_MSEC );
|
||||
|
@ -1145,167 +1301,3 @@ void oeICalImpl::SetupAlarmManager() {
|
|||
m_alarmtimer->Init( AlarmTimerCallback, this, timediff*1000, NS_PRIORITY_NORMAL, NS_TYPE_ONE_SHOT );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* SnoozeEvent
|
||||
*
|
||||
* DESCRIPTION: Deactivates an alarm of an event
|
||||
*
|
||||
* PARAMETERS:
|
||||
* id - Id of the event to deactivet its alarm
|
||||
*
|
||||
* RETURN
|
||||
* None
|
||||
*/
|
||||
/*
|
||||
NS_IMETHODIMP
|
||||
oeICalImpl::SnoozeEvent( PRInt32 id )
|
||||
{
|
||||
cal_open(serveraddr, 0);
|
||||
if( 0 ) {
|
||||
printf("cal_open() failed - SnoozeEvent\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!cal_snooze(id)) {
|
||||
printf("cal_snooze() failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cal_close(0);
|
||||
if ( 0 ) {
|
||||
printf("cal_close() failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void GetNextRecurrence( icalcomponent *vevent, PRInt16 year, PRInt16 month, PRInt16 day, struct icaldurationtype before, char *aRetVal ) {
|
||||
|
||||
struct icaltimetype start, estart, next;
|
||||
struct icalrecurrencetype recur;
|
||||
icalrecur_iterator* ritr;
|
||||
|
||||
start.year = year; start.month = month; start.day = day;
|
||||
start.hour = 0; start.minute = 0; start.second = 0;
|
||||
|
||||
icalproperty *dtstart = icalcomponent_get_first_property( vevent, ICAL_DTSTART_PROPERTY );
|
||||
if( dtstart != 0 ) {
|
||||
estart = icalproperty_get_dtstart( dtstart );
|
||||
start.hour = estart.hour; start.minute = estart.minute; start.second = estart.second;
|
||||
}
|
||||
|
||||
aRetVal[0]= 0;
|
||||
icalproperty *prop = icalcomponent_get_first_property( vevent, ICAL_RRULE_PROPERTY );
|
||||
if ( prop != 0) {
|
||||
recur = icalproperty_get_rrule(prop);
|
||||
ritr = icalrecur_iterator_new(recur,estart);
|
||||
for(next = icalrecur_iterator_next(ritr);
|
||||
!icaltime_is_null_time(next);
|
||||
next = icalrecur_iterator_next(ritr)){
|
||||
struct icaltimetype tmpnext = icaltime_add( next, before );
|
||||
if( icaltime_compare( tmpnext , start ) >= 0 ) {
|
||||
sprintf( aRetVal, "%04d%02d%02dT%02d%02d%02d" , next.year, next.month, next.day, next.hour, next.minute, next.second );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
*
|
||||
* SearchAlarm
|
||||
*
|
||||
* DESCRIPTION: Searches for events having active alarms
|
||||
*
|
||||
* PARAMETERS:
|
||||
* whenstr - String representation of the date-time reference of the alarm
|
||||
* resultstr - Place to store the string representation of the id list
|
||||
*
|
||||
* RETURN
|
||||
* None
|
||||
*/
|
||||
/*
|
||||
NS_IMETHODIMP
|
||||
oeICalImpl::SearchAlarm( PRInt16 startyear, PRInt16 startmonth, PRInt16 startday,
|
||||
PRInt16 starthour, PRInt16 startmin,
|
||||
nsISimpleEnumerator **resultList )
|
||||
{
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::SearchAlarm()\n" );
|
||||
#endif
|
||||
icalfileset *stream;
|
||||
icaltimetype check,checkend;
|
||||
icaldurationtype checkduration;
|
||||
icalproperty *prop;
|
||||
|
||||
nsCOMPtr<oeEventEnumerator> eventEnum = new oeEventEnumerator( );
|
||||
|
||||
if (!eventEnum)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
eventEnum->Init( this );
|
||||
|
||||
check.year = startyear; check.month = startmonth; check.day = startday;
|
||||
check.hour = starthour; check.minute = startmin; check.second = 0;
|
||||
printf( "CHECK: %d-%d-%d %d:%d:%d\n", check.year, check.month, check.day, check.hour, check.minute, check.second );
|
||||
checkduration.is_neg = false;
|
||||
checkduration.weeks = checkduration.days = checkduration.minutes = checkduration.seconds = 0;
|
||||
checkduration.hours = 24;
|
||||
checkend = icaltime_add( check, checkduration );
|
||||
printf( "CHECKEND: %d-%d-%d %d:%d:%d\n", checkend.year, checkend.month, checkend.day, checkend.hour, checkend.minute, checkend.second );
|
||||
|
||||
stream = icalfileset_new(serveraddr);
|
||||
assert(stream != 0);
|
||||
|
||||
icalcomponent *comp;
|
||||
for( comp = icalfileset_get_first_component( stream );
|
||||
comp != 0;
|
||||
comp = icalfileset_get_next_component( stream ) ) {
|
||||
icalcomponent *vevent = icalcomponent_get_first_component( comp, ICAL_VEVENT_COMPONENT );
|
||||
assert( vevent != 0);
|
||||
|
||||
icalcomponent *valarm = icalcomponent_get_first_component( vevent, ICAL_VALARM_COMPONENT );
|
||||
if( valarm ){
|
||||
struct icaltimetype start;
|
||||
|
||||
//get duration
|
||||
prop = icalcomponent_get_first_property( valarm, ICAL_TRIGGER_PROPERTY );
|
||||
assert( prop != 0);
|
||||
struct icaltriggertype trig;
|
||||
trig = icalproperty_get_trigger( prop );
|
||||
|
||||
prop = icalcomponent_get_first_property( vevent, ICAL_RRULE_PROPERTY );
|
||||
if ( prop != 0) {
|
||||
char result[80];
|
||||
GetNextRecurrence( vevent, check.year, check.month, check.day , trig.duration, result );
|
||||
start = icaltime_from_string( result );
|
||||
printf( "RECUR START: %d-%d-%d %d:%d:%d\n", start.year, start.month, start.day, start.hour, start.minute, start.second );
|
||||
} else {
|
||||
//get dtstart
|
||||
prop = icalcomponent_get_first_property( vevent, ICAL_DTSTART_PROPERTY );
|
||||
assert( prop != 0);
|
||||
start = icalproperty_get_dtstart( prop );
|
||||
printf( "START: %d-%d-%d %d:%d:%d\n", start.year, start.month, start.day, start.hour, start.minute, start.second );
|
||||
}
|
||||
start = icaltime_add( start, trig.duration );
|
||||
printf( "TRIGGER: %d-%d-%d %d:%d:%d\n", start.year, start.month, start.day, start.hour, start.minute, start.second );
|
||||
if( icaltime_compare( start, check ) >= 0 && icaltime_compare( start, checkend ) < 0 ) {
|
||||
prop = icalcomponent_get_first_property( vevent, ICAL_UID_PROPERTY );
|
||||
assert( prop != 0);
|
||||
|
||||
eventEnum->AddEventId( atol( icalproperty_get_value_as_string( prop ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
icalfileset_free(stream);
|
||||
|
||||
// bump ref count
|
||||
return eventEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void **)resultList);
|
||||
}*/
|
||||
|
|
|
@ -68,13 +68,13 @@ interface oeIICalEvent : nsISupports
|
|||
{
|
||||
readonly attribute oeIDateTime start;
|
||||
readonly attribute oeIDateTime end;
|
||||
readonly attribute unsigned long id;
|
||||
attribute unsigned long id;
|
||||
attribute string title;
|
||||
attribute string description;
|
||||
attribute string location;
|
||||
attribute string category;
|
||||
attribute boolean privateEvent;
|
||||
attribute unsigned long syncId;
|
||||
attribute string syncId;
|
||||
attribute boolean allDay;
|
||||
attribute boolean alarm;
|
||||
attribute string alarmUnits;
|
||||
|
@ -94,6 +94,7 @@ interface oeIICalEvent : nsISupports
|
|||
void parseIcalString(in string icalstr);
|
||||
void addException( in PRTime exdate );
|
||||
nsISimpleEnumerator getExceptions();
|
||||
void setSnoozeTime( in PRTime exdate );
|
||||
// PRTime calculateAlarmTime();
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче