📄 datetransfer.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
*
* File: DateTransfer.c
*
* Release: Palm OS 5 SDK (68K) R3.
*
* Description:
* DateBook routines to transfer records.
*
*****************************************************************************/
#include <PalmOS.h>
#include <TraceMgr.h>
#include <PdiLib.h>
#include <UDAMgr.h>
#include <PalmUtils.h>
#include "Datebook.h"
#include "ToDo.h"
//#include "DateTime.h"
//#include "DateTransfer.h"
// Use this to determine whether the vCalendar 1.0 format used for beaming events uses
// universal time (GMT) instead of local time. Both formats are supported by the standard,
// but Palm OS 3.5 and older devices have always used local time. Using universal time
// causes problems when beaming to these older Palm devices, since they don't know how to
// convert from GMT to local time. Turn this on for testing the ability of this version
// of Datebook to handle incoming beams from devices which use universal time, such as a
// Windows laptop beaming a vCalendar exported from Outlook (or from Palm desktop).
#define GENERATE_UNIVERSAL_TIME_VCALENDARS 0
#define identifierLengthMax 40
#define tempStringLengthMax 24 // AALARM is longest
#define RRULEStringLengthMax 48 // ABa: Now used to construct the whole RRULE value
#define dateDBType 'DATA'
#define dateSuffix ("." dateExtension)
// Aba: internal version of vCalendar. Must be updated
// the export side of the vCalendar code evoluate
#define kVObjectVersion "5.3"
/////////////////////////////////////
// Macros
#define BitAtPosition(pos) ((UInt32)1 << (pos))
#define GetBitMacro(bitfield, index) ((bitfield) & BitAtPosition(index))
#define SetBitMacro(bitfield, index) ((bitfield) |= BitAtPosition(index))
#define RemoveBitMacro(bitfield, index) ((bitfield) &= ~BitAtPosition(index))
static UInt16 GetChar(const void * exgSocketP);
static void PutString(void * exgSocketP, const Char * const stringP);
/***********************************************************************
*
* Global variables from MainApp can NOT be referenced in our PlugIn!
*
***********************************************************************/
/***********************************************************************
*
* FUNCTION: PrvPdiLibLoad
*
* DESCRIPTION: Load Pdi library
* PARAMETERS: a pointer to an integer: the refNum of the libary
* return whether the library had to be loaded (and therefore
* needs to be unloaded)
*
* RETURNED: An error if library is not found
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* ABa 4/10/00 Created
*
***********************************************************************/
static Err PrvPdiLibLoad(UInt16* refNum, Boolean *loadedP)
{
Err error;
// Load the Pdi library
// Check if the library was pre-loaded (this is useful if we can
// be called from another app via an action code and want to use an existing
// instance of the library in case our caller has already loaded it)
*loadedP = false;
error = SysLibFind(kPdiLibName, refNum);
if (error != 0)
{
error = SysLibLoad(sysResTLibrary, sysFileCPdiLib, refNum);
TraceOutput(TL(appErrorClass, "Loading Pdi library."));
if (! error)
*loadedP = true;
}
if (error)
{
// We're here because the Pdi library failed to load.
// Inform the user or do something else defensive here.
ErrNonFatalDisplay(kPdiLibName " not found");
return error;
}
error = PdiLibOpen(*refNum);
return error;
}
/***********************************************************************
*
* FUNCTION: PrvPdiLibUnload
*
* DESCRIPTION: Unload Pdi library
* PARAMETERS: The refnum of the pdi library
* Whether the library was loaded (and therefore needs to be unloaded)
*
* RETURNED: NONE
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* ABa 4/10/00 Created
*
***********************************************************************/
static void PrvPdiLibUnload(UInt16 refNum, Boolean loaded)
{
if (PdiLibClose(refNum) == 0)
{
TraceOutput(TL(appErrorClass, "Unloading Pdi library."));
if (loaded)
SysLibRemove(refNum);
}
}
/***********************************************************************
*
* FUNCTION: PrvTransferCleanFileName
*
* DESCRIPTION: Remove dot characters in file name but not the least
* PARAMETERS: a pointer to a string
*
* RETURNED: String parameter doesn't contains superfluous dot characters
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* ABa 7/28/00 Created
*
***********************************************************************/
static void PrvTransferCleanFileName(Char* ioFileName)
{
Char* mayBeLastDotP;
Char* lastDotP;
UInt32 chrFullStopSize = TxtCharSize(chrFullStop);
// prevent NULL & empty string
if (ioFileName == NULL || *ioFileName == 0)
return;
// remove dot but not the last one
mayBeLastDotP = StrChr(ioFileName, chrFullStop);
while ((lastDotP = StrChr(mayBeLastDotP + chrFullStopSize, chrFullStop)))
{
// remove the dot
StrCopy(mayBeLastDotP, mayBeLastDotP + chrFullStopSize);
mayBeLastDotP = lastDotP - chrFullStopSize;
}
}
/***********************************************************************
*
* FUNCTION: ApptGetAlarmTimeVCalForm
*
* DESCRIPTION: This routine determines the date and time of the next alarm
* for the appointment passed.
*
* PARAMETERS: apptRec - pointer to an appointment record
*
* RETURNED: date and time of the alarm, in seconds, or zero if there
* is no alarm
*
* NOTE: the only differences between this function and the
* function ApptGetAlarmTime in the App is that
* this function does not return 0 if the alarm time has passed
* and it returns the first event Date as the alarm date
* for reapeating events
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/20/95 Initial Revision
* djk 7/28/97 modified for vCal
*
***********************************************************************/
static UInt32 ApptGetAlarmTimeVCalForm (ApptDBRecordPtr apptRec)
{
UInt32 advance;
UInt32 alarmTime;
DateTimeType apptDateTime;
// An alarm on an untimed event triggers at midnight.
if (TimeToInt (apptRec->when->startTime) == apptNoTime)
{
apptDateTime.minute = 0;
apptDateTime.hour = 0;
}
else
{
apptDateTime.minute = apptRec->when->startTime.minutes;
apptDateTime.hour = apptRec->when->startTime.hours;
}
apptDateTime.second = 0;
apptDateTime.day = apptRec->when->date.day;
apptDateTime.month = apptRec->when->date.month;
apptDateTime.year = apptRec->when->date.year + firstYear;
// Compute the time of the alarm by adjusting the date and time
// of the appointment by the length of the advance notice.
advance = apptRec->alarm->advance;
switch (apptRec->alarm->advanceUnit)
{
case aauMinutes:
advance *= minutesInSeconds;
break;
case aauHours:
advance *= hoursInSeconds;
break;
case aauDays:
advance *= daysInSeconds;
break;
}
alarmTime = TimDateTimeToSeconds (&apptDateTime) - advance;
return alarmTime;
}
/************************************************************
*
* FUNCTION: TranslateAlarm
*
* DESCRIPTION: Translate an alarm in seconds to a DateTimeType.
* Broken out of DateImportVEvent for linking on the device purposes.
*
* PARAMETERS:
* newDateRecordP - the new record
* alarmDTinSec - date and time of the alarm in seconds
*
* RETURNS: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 9/19/97 Created
*
*************************************************************/
static void TranslateAlarm(ApptDBRecordType *newDateRecordP, UInt32 alarmDTinSec)
{
DateTimeType eventDT;
UInt32 alarmAdvanceSeconds;
UInt32 alarmAdvance;
// allocate a new AlarmInfoType
newDateRecordP->alarm = (AlarmInfoType *) MemPtrNew (sizeof(AlarmInfoType));
eventDT.year = newDateRecordP->when->date.year + firstYear;
eventDT.month = newDateRecordP->when->date.month;
eventDT.day = newDateRecordP->when->date.day;
if (TimeToInt (newDateRecordP->when->startTime) == noTime)
{
// The time for alarms is midnight.
eventDT.hour = 0;
eventDT.minute = 0;
}
else
{
eventDT.hour = newDateRecordP->when->startTime.hours;
eventDT.minute = newDateRecordP->when->startTime.minutes;
}
eventDT.second = 0;
alarmAdvanceSeconds = TimDateTimeToSeconds(&eventDT) - alarmDTinSec;
// aro - Fix Bug #51570
// Check if the alarm is after the event.
// In this case set it to the same time since we don't handle post event alarm
if ((Int32)alarmAdvanceSeconds < 0)
{
TraceOutput(TL(appErrorClass, "*** Alarm is after the starting time. Set it to the same time"));
alarmAdvanceSeconds = 0;
}
// convert to minutes
alarmAdvance = alarmAdvanceSeconds / minutesInSeconds;
if (alarmAdvance < 100 && alarmAdvance != hoursInMinutes)
{
newDateRecordP->alarm->advanceUnit = aauMinutes;
newDateRecordP->alarm->advance = (Int8) alarmAdvance;
}
else
{
// convert to hours
alarmAdvance = alarmAdvance / hoursInMinutes;
if (alarmAdvance < 100 && (alarmAdvance % hoursPerDay))
{
newDateRecordP->alarm->advanceUnit = aauHours;
newDateRecordP->alarm->advance = (Int8) alarmAdvance;
}
else
{
// convert to days
alarmAdvance = alarmAdvance / hoursPerDay;
// set to the lesser of 99 and alarmAdvance
newDateRecordP->alarm->advanceUnit = aauDays;
if (alarmAdvance < 99)
newDateRecordP->alarm->advance = (Int8) alarmAdvance;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -