tvplanit: Add preview for importing VCard files.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8381 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-08-11 20:32:13 +00:00
parent 097b466e92
commit d97209a2a3
16 changed files with 478 additions and 6 deletions

View File

@ -0,0 +1,150 @@
unit VpImportPreview_VCard;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
VpData, VpBaseDS, VpImportPreview, VpVCard;
type
{ TVpImportPreviewVCardForm }
TVpImportPreviewVCardForm = class(TVpImportPreviewForm)
private
FVCards: TVpVCards;
FDatastore: TVpCustomDatastore;
function GetCardText(ACard: TVpVCard): String;
procedure SetVCards(const AValue: TVpVCards);
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 VCards: TVpVCards read FVCards write SetVCards;
property Datastore: TVpCustomDatastore read FDatastore write FDatastore;
end;
var
VpImportPreviewVCardForm: TVpImportPreviewVCardForm;
implementation
{$R *.lfm}
uses
VpSR;
constructor TVPImportPreviewVCardForm.Create(AOwner: TComponent);
begin
inherited;
Caption := RSImportVCard;
end;
procedure TVpImportPreviewVCardForm.CheckItem(ARow: Integer; AChecked: Boolean);
var
card: TVpVCard;
begin
if ARow < Grid.FixedRows then
exit;
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
if card <> nil then
card.Skip := not AChecked;
end;
function TVpImportPreviewVCardForm.GetCellText(ACol, ARow: Integer): String;
var
card: TVpVCard;
begin
Result := '';
if (ACol = 1) and (ARow >= Grid.FixedRows) then
begin
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
if card <> nil then
Result := GetCardText(card);
end;
end;
function TVpImportPreviewVCardForm.GetCardText(ACard: TVpVCard): String;
var
s: String;
begin
Result := ACard.GetFullName;
s := ACard.GetWorkAddress;
if s <> '' then
Result := Result + LineEnding + 'Work address: ' + s;
s := ACard.GetHomeAddress;
if s <> '' then
Result := Result + LineEnding + 'Home address: ' + s;
s := ACard.GetPhone;
if s <> '' then
Result := Result + LineEnding + 'Phone: ' + s;
s := ACard.GetEMail;
if s <> '' then
Result := Result + LineEnding + 'E-Mail: ' + s;
(*
Result := RSDescriptionLbl + ' ' + AToDo.Summary + LineEnding +
RSDueDateLabel + ' ' + FormatDateTime(FTimeFormat, AToDo.DueTime[false]) + LineEnding +
RSCreatedOn + ' ' + FormatDateTime(FTimeFormat, AToDo.StartTime[false]);
case TVpTask.GetTaskPriority(AToDo.Priority) of
tpLow: s := RSLow;
tpNormal: s := RSNormal;
tpHigh: s := RSHigh;
end;
Result := Result + LineEnding + RSPriorityLabel + ' ' + s + LineEnding + RSCategoryLabel + ' ';
if Assigned(FDatastore) then
begin
cat := FDatastore.FindBestTaskCategory(AToDo.Categories);
if cat = '' then cat := FDefaultCategory;
Result := Result + cat;
end;
*)
end;
function TVpImportPreviewVCardForm.IsChecked(ARow: Integer): Boolean;
var
card: TVpVCard;
begin
Result := false;
if ARow < Grid.FixedRows then
exit;
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
if (card <> nil) then
Result := not card.Skip;
end;
procedure TVpImportPreviewVCardForm.PrepareItems;
var
i: Integer;
begin
FItems.Clear;
if FVCards <> nil then
for i := 0 to FVCards.Count-1 do
FItems.Add(FVCards.Card[i]);
inherited;
end;
procedure TVpImportPreviewVCardForm.SetVCards(const AValue: TVpVCards);
begin
if AValue <> FVCards then
begin
FVCards := AValue;
PrepareItems;
end;
end;
end.