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
FVCards: TVpVCards;
FDatastore: TVpCustomDatastore;
FDefaultCategory: String;
function GetCardText(ACard: TVpVCard): String;
procedure SetVCards(const AValue: TVpVCards);
@ -33,7 +32,6 @@ type
procedure CheckItem(ARow: Integer; AChecked: Boolean); override;
function IsChecked(ARow: Integer): Boolean; override;
property VCards: TVpVCards read FVCards write SetVCards;
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
end;
@ -51,6 +49,8 @@ constructor TVPImportPreviewVCardForm.Create(AOwner: TComponent);
begin
inherited;
Caption := RSImportVCard;
Grid.OnGetEditText := @GridGetEditText;
Grid.OnSetEditText := @GridSetEditText;
end;
procedure TVpImportPreviewVCardForm.CheckItem(ARow: Integer; AChecked: Boolean);
@ -146,47 +146,37 @@ var
ct: TVpCategoryType;
L: TStrings;
begin
FItems.Clear;
if FVCards <> nil then
for i := 0 to FVCards.Count-1 do
FItems.Add(FVCards.Card[i]);
inherited;
Grid.Columns[1].Title.Caption := RSContactItems;
Grid.Columns[2].Title.Caption := RSAssignedCategory;
if (FVCards <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
begin
Grid.Columns[1].Title.Caption := RSContactItems;
// 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;
with Grid.Columns.Add do
FItems.Clear;
if (FVCards <> nil) and (Datastore <> nil) then
for i := 0 to FVCards.Count-1 do
begin
SizePriority := 0;
Width := 160;
Title.Caption := RSAssignedCategory;
ButtonStyle := cbsPickList;
L := TStringList.Create;
try
for ct in TVpCategoryType do
L.Add(CategoryLabel(ct));
PickList.Assign(L);
finally
L.Free;
end;
end;
// Add vcard
card := FVCards.Card[i];
FItems.Add(card);
for i := 0 to FItems.Count-1 do
begin
card := TVpVCard(FItems[i]);
cat := FDatastore.FindBestCategory(card.Categories);
// Select best category in picklist columns
cat := Datastore.FindBestCategory(card.Categories);
if cat = '' then cat := FDefaultCategory;
if cat <> '' then
card.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
else
card.PickedCategory := ord(ctOther);
end;
end;
inherited;
end;
procedure TVpImportPreviewVCardForm.SetVCards(const AValue: TVpVCards);