tvplanit: Export tasks to ical files (needs more testing).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8404 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-20 21:21:14 +00:00
parent 774c1feda3
commit c4a2f61db6
16 changed files with 290 additions and 127 deletions

View File

@@ -106,6 +106,8 @@ type
private
FSummary: String;
FComment: String;
FCreatedTime: TDateTime;
FCreatedTimeTZ: String;
FStartTime: TDateTime;
FStartTimeTZ: String;
FDueTime: TDateTime;
@@ -120,24 +122,30 @@ type
function GetCategory(AIndex: integer): String;
function GetCategoryCount: Integer;
function GetCompletedTime(UTC: Boolean): TDateTime;
function GetCreatedTime(UTC: Boolean): TDateTime;
function GetDueTime(UTC: Boolean): TDateTime;
function GetStartTime(UTC: Boolean): TDateTime;
procedure SetCompletedTime(UTC: Boolean; const AValue: TDateTime);
procedure SetCreatedTime(UTC: Boolean; const AValue: TDateTime);
procedure SetDueTime(UTC: Boolean; const AValue: TDateTime);
procedure SetStartTime(UTC: Boolean; const AValue: TDateTime);
public
constructor Create(AOwner: TVpICalendar); override;
destructor Destroy; override;
procedure Analyze; override;
function Categories: TStrings;
procedure SaveToStrings(const AList: TStrings); override;
property Summary: String read FSummary;
property Comment: String read FComment;
property StartTime[UTC: Boolean]: TDateTime read GetStartTime;
property DueTime[UTC: Boolean]: TDateTime read GetDueTime;
property CompletedTime[UTC: Boolean]: TDateTime read GetCompletedTime;
property Summary: String read FSummary write FSummary;
property Comment: String read FComment write FComment;
property CreatedTime[UTC: Boolean]: TDateTime read GetCreatedTime write SetCreatedTime;
property StartTime[UTC: Boolean]: TDateTime read GetStartTime write SetStartTime;
property DueTime[UTC: Boolean]: TDateTime read GetDueTime write SetDueTime;
property CompletedTime[UTC: Boolean]: TDateTime read GetCompletedTime write SetCompletedTime;
property Category[AIndex: Integer]: String read GetCategory;
property CategoryCount: Integer read GetCategoryCount;
property PickedCategory: Integer read FPickedCategory write FPickedCategory;
property Priority: Integer read FPriority; // 0=undefined, 1-highest, 9=lowest
property Status: String read FStatus;
property Priority: Integer read FPriority write FPriority; // 0=undefined, 1-highest, 9=lowest
property Status: String read FStatus write FStatus;
end;
TVpICalendar = class
@@ -647,6 +655,13 @@ begin
FSummary := item.Value;
'COMMENT':
FComment := item.Value;
'DTSTAMP':
begin
FCreatedTimeTZ := item.GetAttribute('TZID');
FCreatedTime := iCalDateTime(item.Value, isUTC);
if not isUTC then
FCreatedTime := FCalendar.LocalTimeToUTC(FCreatedTime, FCreatedTimeTZ);
end;
'DTSTART':
begin
FStartTimeTZ := item.GetAttribute('TZID');
@@ -705,6 +720,13 @@ begin
Result := FCalendar.UTCToLocalTime(Result, FCompletedTimeTZ);
end;
function TVpICalToDo.GetCreatedTime(UTC: Boolean): TDateTime;
begin
Result := FCreatedTime;
if (Result > 0) and (not UTC) then
Result := FCalendar.UTCToLocalTime(Result, FCreatedTimeTZ);
end;
function TVpICalToDo.GetDueTime(UTC: Boolean): TDateTime;
begin
if FDueTime <> 0 then
@@ -724,8 +746,102 @@ begin
end;
procedure TVpICalToDo.SaveToStrings(const AList: TStrings);
var
key: String;
dt: TDateTime;
begin
// to do...
AList.Add('BEGIN:TODO');
if FCreatedTimeTZ <> '' then
key := 'DTSTAMP;TZID=' + FCreatedTimeTZ + ':'
else
key := 'DTSTAMP:';
AList.Add(key + FormatDateTime(TIME_FORMAT_UTC, CreatedTime[true]));
if FSummary <> '' then
AList.Add('SUMMARY:' + FSummary);
if FComment <> '' then
AList.Add('COMMENT:' + FComment);
if FCategories.Count > 0 then
AList.Add('CATEGORIES:' + FCategories.DelimitedText);
// todo: check time zones!
if FStartTimeTZ <> '' then
key := 'DTSTART;TZID=' + FStartTimeTZ + ':'
else
key := 'DTSTART:';
AList.Add(key + FormatDateTime(TIME_FORMAT_UTC, StartTime[true]));
if FDueTimeTZ <> '' then
key := 'DUE;TZID=' + FDueTimeTZ + ':'
else
key := 'DUE:';
AList.Add(key + FormatDateTime(TIME_FORMAT_UTC, DueTime[true]));
dt := CompletedTime[true];
if dt > 0 then // 0 means here: "not completed yet"
begin
if FCompletedTimeTZ <> '' then
key := 'COMPLETE;TZID=' + FCompletedTimeTZ + ':'
else
key := 'COMPLETED:';
AList.Add(key + FormatDateTime(TIME_FORMAT_UTC, CompletedTime[true]));
end;
if FDuration <> 0 then
AList.Add('DURATION:' + Duration2iCalStr(FDuration)); // wp: Is this correct?
AList.Add('PRIORITY:' + IntToStr(FPriority));
if FStatus <> '' then
AList.Add('STATUS:' + FStatus);
AList.Add('END:TODO');
end;
procedure TVpICalToDo.SetCompletedTime(UTC: Boolean; const AValue: TDateTime);
begin
if AValue = NO_DATE then
FCompletedTime := NO_DATE
else
if UTC then
FCompletedTime := AValue
else
FCompletedTime := FCalendar.LocalTimeToUTC(AValue, FCompletedTimeTZ);
end;
procedure TVpICalToDo.SetCreatedTime(UTC: Boolean; const AValue: TDateTime);
begin
if AValue = NO_DATE then
FCreatedTime := NO_DATE
else
if UTC then
FCreatedTime := AValue
else
FCreatedTime := FCalendar.LocalTimeToUTC(AValue, FCreatedTimeTZ);
end;
procedure TVpICalToDo.SetDueTime(UTC: Boolean; const AValue: TDateTime);
begin
if AValue = NO_DATE then
FDueTime := NO_DATE
else
if UTC then
FDueTime := AValue
else
FDueTime := FCalendar.LocalTimeToUTC(AValue, FDueTimeTZ);
end;
procedure TVpICalToDo.SetStartTime(UTC: Boolean; const AValue: TDateTime);
begin
if AValue = NO_DATE then
FStartTime := NO_DATE
else
if UTC then
FStartTime := AValue
else
FStartTime := FCalendar.LocalTimeToUTC(AValue, FStartTimeTZ);
end;