2022-08-11 16:46:32 +00:00
|
|
|
unit VpImportPreview_ICalTask;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
2022-08-22 20:56:10 +00:00
|
|
|
{$WARN 5024 off : Parameter "$1" not used}
|
2022-08-11 16:46:32 +00:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
|
2022-08-12 13:47:03 +00:00
|
|
|
VpData, VpBaseDS, VpImportPreview, VpICal, Grids;
|
2022-08-11 16:46:32 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TVpImportPreviewICalTaskForm }
|
|
|
|
|
|
|
|
TVpImportPreviewICalTaskForm = class(TVpImportPreviewForm)
|
2022-08-22 20:56:10 +00:00
|
|
|
procedure GridGetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
|
2022-08-12 13:47:03 +00:00
|
|
|
var Value: string);
|
2022-08-22 20:56:10 +00:00
|
|
|
procedure GridSetEditText(Sender: TObject; {%H-}ACol, ARow: Integer;
|
2022-08-12 13:47:03 +00:00
|
|
|
const Value: string);
|
2022-08-11 16:46:32 +00:00
|
|
|
private
|
|
|
|
FCalendar: TVpICalendar;
|
|
|
|
FDefaultCategory: String;
|
|
|
|
FTimeFormat: String;
|
|
|
|
function GetTaskText(AToDo: TVpICalToDo): String;
|
|
|
|
procedure SetCalendar(const AValue: TVpICalendar);
|
|
|
|
|
|
|
|
protected
|
|
|
|
function GetCellText(ACol, ARow: Integer): String; override;
|
|
|
|
procedure PrepareItems; override;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
|
|
|
|
function IsChecked(ARow: Integer): Boolean; override;
|
|
|
|
property Calendar: TVpICalendar read FCalendar write SetCalendar;
|
|
|
|
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
VpImportPreviewICalTaskForm: TVpImportPreviewICalTaskForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
uses
|
2022-08-12 13:47:03 +00:00
|
|
|
VpSR, VpConst;
|
2022-08-11 16:46:32 +00:00
|
|
|
|
|
|
|
constructor TVPImportPreviewICalTaskForm.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
2022-08-19 13:57:51 +00:00
|
|
|
|
|
|
|
Grid.OnGetEditText := @GridGetEditText;
|
|
|
|
Grid.OnSetEditText := @GridSetEditText;
|
|
|
|
|
2022-08-11 16:46:32 +00:00
|
|
|
Caption := RSImportICalTask;
|
|
|
|
FTimeFormat := 'c'; // short date + long time format
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewICalTaskForm.CheckItem(ARow: Integer; AChecked: Boolean);
|
|
|
|
var
|
|
|
|
item: TVpICalEntry;
|
|
|
|
begin
|
|
|
|
if ARow < Grid.FixedRows then
|
|
|
|
exit;
|
|
|
|
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
|
|
|
if item <> nil then
|
2022-08-19 21:32:56 +00:00
|
|
|
begin
|
|
|
|
item.Checked := AChecked;
|
|
|
|
inherited;
|
|
|
|
end;
|
2022-08-11 16:46:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpImportPreviewICalTaskForm.GetCellText(ACol, ARow: Integer): String;
|
|
|
|
var
|
2022-08-12 13:47:03 +00:00
|
|
|
task: TVpICalToDo;
|
2022-08-11 16:46:32 +00:00
|
|
|
begin
|
|
|
|
Result := '';
|
2022-08-12 13:47:03 +00:00
|
|
|
if (ARow >= Grid.FixedRows) then
|
2022-08-11 16:46:32 +00:00
|
|
|
begin
|
2022-08-12 13:47:03 +00:00
|
|
|
task := TVpICalToDo(FItems[ARow - Grid.FixedRows]);
|
|
|
|
case ACol of
|
|
|
|
1: Result := GetTaskText(task);
|
|
|
|
2: Result := Grid.Columns[2].PickList[task.PickedCategory]
|
|
|
|
end;
|
2022-08-11 16:46:32 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2022-08-12 13:47:03 +00:00
|
|
|
procedure TVpImportPreviewICalTaskForm.GridGetEditText(Sender: TObject; ACol,
|
|
|
|
ARow: Integer; var Value: string);
|
|
|
|
var
|
|
|
|
task: TVpICalToDo;
|
|
|
|
begin
|
|
|
|
task := TVpICalToDo(FItems[Grid.Row - Grid.FixedRows]);
|
|
|
|
if task <> nil then
|
|
|
|
Value := Grid.Columns[2].PickList[task.PickedCategory];
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewICalTaskForm.GridSetEditText(Sender: TObject; ACol,
|
|
|
|
ARow: Integer; const Value: string);
|
|
|
|
var
|
|
|
|
task: TVpICalToDo;
|
|
|
|
begin
|
|
|
|
task:= TVpICalToDo(FItems[Grid.Row - Grid.FixedRows]);
|
|
|
|
if task <> nil then
|
|
|
|
task.PickedCategory := Grid.Columns[2].PickList.IndexOf(Value);;
|
|
|
|
end;
|
|
|
|
|
2022-08-11 16:46:32 +00:00
|
|
|
function TVpImportPreviewICalTaskForm.GetTaskText(AToDo: TVpICalToDo): String;
|
|
|
|
var
|
|
|
|
s: String;
|
2022-08-12 13:47:03 +00:00
|
|
|
dt: TDateTime;
|
2022-08-11 16:46:32 +00:00
|
|
|
begin
|
2022-08-12 13:47:03 +00:00
|
|
|
Result := RSDescriptionLbl + ' ' + AToDo.Summary;
|
|
|
|
|
|
|
|
dt := AToDo.DueTime[false];
|
|
|
|
if dt <> NO_DATE then
|
|
|
|
s := FormatDateTime(FTimeFormat, dt)
|
|
|
|
else
|
|
|
|
s := RSNoneStr;
|
|
|
|
Result := Result + LineEnding + RSDueDateLabel + ' ' + s;
|
|
|
|
|
|
|
|
dt := AToDo.StartTime[false];
|
|
|
|
if dt <> NO_DATE then
|
|
|
|
s := FormatDateTime(FTimeFormat, dt)
|
|
|
|
else
|
|
|
|
s := RSNoneStr;
|
|
|
|
Result := Result + LineEnding + RSCreatedOn + ' ' + s;
|
2022-08-11 16:46:32 +00:00
|
|
|
|
|
|
|
case TVpTask.GetTaskPriority(AToDo.Priority) of
|
|
|
|
tpLow: s := RSLow;
|
|
|
|
tpNormal: s := RSNormal;
|
|
|
|
tpHigh: s := RSHigh;
|
|
|
|
end;
|
2022-08-12 13:47:03 +00:00
|
|
|
Result := Result + LineEnding + RSPriorityLabel + ' ' + s;
|
2022-08-11 16:46:32 +00:00
|
|
|
|
2022-08-12 13:47:03 +00:00
|
|
|
s := AToDo.Categories.CommaText;
|
|
|
|
if s = '' then s := RSNoneStr;
|
|
|
|
Result := Result + LineEnding + RSCategoryLabel + ' ' + s;
|
2022-08-11 16:46:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpImportPreviewICalTaskForm.IsChecked(ARow: Integer): Boolean;
|
|
|
|
var
|
|
|
|
item: TVpICalEntry;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
if ARow < Grid.FixedRows then
|
|
|
|
exit;
|
|
|
|
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
|
|
|
if (item <> nil) then
|
2022-08-19 14:06:54 +00:00
|
|
|
Result := item.Checked;
|
2022-08-11 16:46:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewICalTaskForm.PrepareItems;
|
|
|
|
var
|
2022-08-22 20:56:10 +00:00
|
|
|
i: Integer;
|
2022-08-12 13:47:03 +00:00
|
|
|
ct: TVpCategoryType;
|
|
|
|
cat: String;
|
|
|
|
L: TStrings;
|
|
|
|
task: TVpICalToDo;
|
2022-08-11 16:46:32 +00:00
|
|
|
begin
|
2022-08-19 13:57:51 +00:00
|
|
|
Grid.Columns[1].Title.Caption := RSTaskItems;
|
|
|
|
Grid.Columns[2].Title.Caption := RSAssignedCategory;
|
|
|
|
// Populate picklist in column 2
|
|
|
|
L := TStringList.Create;
|
|
|
|
try
|
|
|
|
for ct in TVpCategoryType do
|
|
|
|
L.Add(CategoryLabel(ct));
|
|
|
|
Grid.Columns[2].PickList.Assign(L);
|
|
|
|
finally
|
|
|
|
L.Free;
|
|
|
|
end;
|
|
|
|
|
2022-08-11 16:46:32 +00:00
|
|
|
FItems.Clear;
|
2022-08-19 13:57:51 +00:00
|
|
|
if (FCalendar <> nil) and (Datastore <> nil) then
|
2022-08-11 16:46:32 +00:00
|
|
|
for i := 0 to FCalendar.Count-1 do
|
2022-08-19 13:57:51 +00:00
|
|
|
if (FCalendar.Entry[i] is TVpICalToDo) then
|
|
|
|
begin
|
|
|
|
// Add ical todo item
|
|
|
|
task := TVpICalToDo(FCalendar.Entry[i]);
|
|
|
|
FItems.Add(task);
|
|
|
|
|
|
|
|
// Select best category in picklist column
|
|
|
|
cat := Datastore.FindBestCategory(task.Categories);
|
|
|
|
if cat = '' then cat := FDefaultCategory;
|
|
|
|
if cat <> '' then
|
|
|
|
task.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
|
|
|
|
else
|
|
|
|
task.PickedCategory := ord(ctOther);
|
2022-08-12 13:47:03 +00:00
|
|
|
end;
|
2022-08-19 13:57:51 +00:00
|
|
|
|
|
|
|
inherited;
|
2022-08-11 16:46:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewICalTaskForm.SetCalendar(const AValue: TVpICalendar);
|
|
|
|
begin
|
|
|
|
if AValue <> FCalendar then
|
|
|
|
begin
|
|
|
|
FCalendar := AValue;
|
|
|
|
PrepareItems;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|