tvplanit: Refactor ical and vcard import forms to reduce duplicate code.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8397 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-19 13:57:51 +00:00
parent 33b73bbc8b
commit 259d689c42
12 changed files with 120 additions and 202 deletions

View File

@ -19,7 +19,6 @@ type
const Value: string);
private
FCalendar: TVpICalendar;
FDatastore: TVpCustomDatastore;
FDefaultCategory: String;
FTimeFormat: String;
function GetEventText(AEvent: TVpICalEvent): String;
@ -35,7 +34,6 @@ type
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
function IsChecked(ARow: Integer): Boolean; override;
property Calendar: TVpICalendar read FCalendar write SetCalendar;
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
end;
@ -52,6 +50,10 @@ uses
constructor TVPImportPreviewICalEventForm.Create(AOwner: TComponent);
begin
inherited;
Grid.OnGetEditText := @GridGetEditText;
Grid.OnSetEditText := @GridSetEditText;
Caption := RSImportICalEvent;
FTimeFormat := 'c'; // short date + long time format
end;
@ -114,7 +116,7 @@ begin
RSDescriptionLbl + ' ' + AEvent.Summary;
// Categories
if Assigned(FDatastore) then
if Assigned(Datastore) then
begin
cat := AEvent.Categories.CommaText;
if cat = '' then cat := RSNoneStr;
@ -216,45 +218,37 @@ var
event: TVpICalEvent;
cat: String;
begin
Grid.Columns[1].Title.Caption := RSEventItems;
Grid.Columns[2].Title.Caption := RSAssignedCategory;
// Populate picklist in column 2
L := TStringList.Create;
try
for i := 0 to 9 do
L.Add(Datastore.CategoryColorMap.GetName(i));
Grid.Columns[2].PickList.Assign(L);
finally
L.Free;
end;
FItems.Clear;
if FCalendar <> nil then
if (FCalendar <> nil) and (Datastore <> nil) then
for i := 0 to FCalendar.Count-1 do
if (FCalendar.Entry[i] is TVpICalEvent) then
FItems.Add(FCalendar.Entry[i]);
if (FCalendar.Entry[i] is TVpICalEvent) then
begin
// Add ical event
event := TVpIcalEvent(FCalendar.Entry[i]);
FItems.Add(event);
// Select best category in picklist column
cat := Datastore.FindBestEventCategory(event.Categories);
if cat = '' then cat := FDefaultCategory;
if cat <> '' then
event.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
else
event.PickedCategory := 0;
end;
inherited;
if (FCalendar <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
begin
Grid.Columns[1].Title.Caption := RSEventItems;
with Grid.Columns.Add do
begin
SizePriority := 0;
Width := 160;
Title.Caption := RSAssignedCategory;
ButtonStyle := cbsPickList;
L := TStringList.Create;
try
for i := 0 to 9 do
L.Add(FDatastore.CategoryColorMap.GetName(i));
PickList.Assign(L);
finally
L.Free;
end;
end;
for i := 0 to FItems.Count-1 do
begin
event := TVpICalEvent(FItems[i]);
cat := FDatastore.FindBestEventCategory(event.Categories);
if cat = '' then cat := FDefaultCategory;
if cat <> '' then
event.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
else
event.PickedCategory := 0;
end;
end;
end;
procedure TVpImportPreviewICalEventForm.SetCalendar(const AValue: TVpICalendar);