2022-08-11 20:32:13 +00:00
|
|
|
unit VpImportPreview_VCard;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
|
2022-08-22 20:56:10 +00:00
|
|
|
VpBaseDS, VpImportPreview, VpVCard, Grids;
|
2022-08-11 20:32:13 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TVpImportPreviewVCardForm }
|
|
|
|
|
|
|
|
TVpImportPreviewVCardForm = class(TVpImportPreviewForm)
|
2022-08-22 20:56:10 +00:00
|
|
|
procedure GridGetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
|
2022-08-19 10:53:49 +00:00
|
|
|
var Value: string);
|
2022-08-22 20:56:10 +00:00
|
|
|
procedure GridSetEditText(Sender: TObject; {%H-}ACol, {%H-}ARow: Integer;
|
2022-08-19 10:53:49 +00:00
|
|
|
const Value: string);
|
2022-08-11 20:32:13 +00:00
|
|
|
private
|
|
|
|
FVCards: TVpVCards;
|
2022-08-19 10:53:49 +00:00
|
|
|
FDefaultCategory: String;
|
2022-08-11 20:32:13 +00:00
|
|
|
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;
|
2022-08-19 10:53:49 +00:00
|
|
|
property DefaultCategory: String read FDefaultCategory write FDefaultCategory;
|
2022-08-11 20:32:13 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
VpImportPreviewVCardForm: TVpImportPreviewVCardForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
uses
|
|
|
|
VpSR;
|
|
|
|
|
|
|
|
constructor TVPImportPreviewVCardForm.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
Caption := RSImportVCard;
|
2022-08-19 13:57:51 +00:00
|
|
|
Grid.OnGetEditText := @GridGetEditText;
|
|
|
|
Grid.OnSetEditText := @GridSetEditText;
|
2022-08-11 20:32:13 +00:00
|
|
|
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
|
2022-08-19 21:32:56 +00:00
|
|
|
begin
|
2022-08-19 14:06:54 +00:00
|
|
|
card.Checked := AChecked;
|
2022-08-19 21:32:56 +00:00
|
|
|
inherited;
|
|
|
|
end;
|
2022-08-11 20:32:13 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpImportPreviewVCardForm.GetCellText(ACol, ARow: Integer): String;
|
|
|
|
var
|
|
|
|
card: TVpVCard;
|
|
|
|
begin
|
|
|
|
Result := '';
|
2022-08-19 10:53:49 +00:00
|
|
|
if (ARow >= Grid.FixedRows) then
|
2022-08-11 20:32:13 +00:00
|
|
|
begin
|
|
|
|
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
|
2022-08-19 10:53:49 +00:00
|
|
|
case ACol of
|
|
|
|
1: Result := GetCardText(card);
|
|
|
|
2: Result := Grid.Columns[2].PickList[card.PickedCategory]
|
|
|
|
end;
|
2022-08-11 20:32:13 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVpImportPreviewVCardForm.GetCardText(ACard: TVpVCard): String;
|
|
|
|
var
|
|
|
|
s: String;
|
|
|
|
begin
|
|
|
|
Result := ACard.GetFullName;
|
|
|
|
|
|
|
|
s := ACard.GetWorkAddress;
|
|
|
|
if s <> '' then
|
2022-08-18 17:44:47 +00:00
|
|
|
Result := Result + LineEnding + RSWorkAddress + ': ' + s;
|
2022-08-11 20:32:13 +00:00
|
|
|
|
|
|
|
s := ACard.GetHomeAddress;
|
|
|
|
if s <> '' then
|
2022-08-18 17:44:47 +00:00
|
|
|
Result := Result + LineEnding + RSHomeAddress + ': ' + s;
|
2022-08-11 20:32:13 +00:00
|
|
|
|
|
|
|
s := ACard.GetPhone;
|
|
|
|
if s <> '' then
|
2022-08-18 17:44:47 +00:00
|
|
|
Result := Result + LineEnding + RSPhone + ': ' + s;
|
2022-08-11 20:32:13 +00:00
|
|
|
|
|
|
|
s := ACard.GetEMail;
|
|
|
|
if s <> '' then
|
2022-08-12 13:47:03 +00:00
|
|
|
Result := Result + LineEnding + RSEMail + ': ' + s;
|
2022-08-19 10:53:49 +00:00
|
|
|
|
|
|
|
s := ACard.Categories.CommaText;
|
|
|
|
if s = '' then s := RSNoneStr;
|
|
|
|
Result := Result + LineEnding + RSCategoryLabel + ' ' + s;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewVCardForm.GridGetEditText(Sender: TObject; ACol,
|
|
|
|
ARow: Integer; var Value: string);
|
|
|
|
var
|
|
|
|
card: TVpVCard;
|
|
|
|
begin
|
|
|
|
card := TVpVCard(FItems[Grid.Row - Grid.FixedRows]);
|
|
|
|
if card <> nil then
|
|
|
|
Value := Grid.Columns[2].PickList[card.PickedCategory];
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewVCardForm.GridSetEditText(Sender: TObject; ACol,
|
|
|
|
ARow: Integer; const Value: string);
|
|
|
|
var
|
|
|
|
card: TVpVCard;
|
|
|
|
begin
|
|
|
|
card := TVpVCard(FItems[Grid.Row - Grid.FixedRows]);
|
|
|
|
if card <> nil then
|
|
|
|
card.PickedCategory := Grid.Columns[2].PickList.IndexOf(Value);;
|
2022-08-11 20:32:13 +00:00
|
|
|
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
|
2022-08-19 14:06:54 +00:00
|
|
|
Result := card.Checked;
|
2022-08-11 20:32:13 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewVCardForm.PrepareItems;
|
|
|
|
var
|
|
|
|
i: Integer;
|
2022-08-19 10:53:49 +00:00
|
|
|
card: TVpVCard;
|
|
|
|
cat: string;
|
|
|
|
ct: TVpCategoryType;
|
|
|
|
L: TStrings;
|
2022-08-11 20:32:13 +00:00
|
|
|
begin
|
2022-08-12 13:47:03 +00:00
|
|
|
Grid.Columns[1].Title.Caption := RSContactItems;
|
2022-08-19 13:57:51 +00:00
|
|
|
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-19 10:53:49 +00:00
|
|
|
|
2022-08-19 13:57:51 +00:00
|
|
|
FItems.Clear;
|
|
|
|
if (FVCards <> nil) and (Datastore <> nil) then
|
|
|
|
for i := 0 to FVCards.Count-1 do
|
2022-08-19 10:53:49 +00:00
|
|
|
begin
|
2022-08-19 13:57:51 +00:00
|
|
|
// Add vcard
|
|
|
|
card := FVCards.Card[i];
|
|
|
|
FItems.Add(card);
|
2022-08-19 10:53:49 +00:00
|
|
|
|
2022-08-19 13:57:51 +00:00
|
|
|
// Select best category in picklist columns
|
|
|
|
cat := Datastore.FindBestCategory(card.Categories);
|
2022-08-19 10:53:49 +00:00
|
|
|
if cat = '' then cat := FDefaultCategory;
|
|
|
|
if cat <> '' then
|
|
|
|
card.PickedCategory := Grid.Columns[2].PickList.IndexOf(cat)
|
|
|
|
else
|
|
|
|
card.PickedCategory := ord(ctOther);
|
|
|
|
end;
|
2022-08-19 13:57:51 +00:00
|
|
|
|
|
|
|
inherited;
|
2022-08-11 20:32:13 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TVpImportPreviewVCardForm.SetVCards(const AValue: TVpVCards);
|
|
|
|
begin
|
|
|
|
if AValue <> FVCards then
|
|
|
|
begin
|
|
|
|
FVCards := AValue;
|
|
|
|
PrepareItems;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|