You've already forked lazarus-ccr
tvplanit: Support contacts in VCard import/export.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8396 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -6,16 +6,21 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
|
||||
VpData, VpBaseDS, VpImportPreview, VpVCard;
|
||||
VpData, VpBaseDS, VpImportPreview, VpVCard, Grids;
|
||||
|
||||
type
|
||||
|
||||
{ TVpImportPreviewVCardForm }
|
||||
|
||||
TVpImportPreviewVCardForm = class(TVpImportPreviewForm)
|
||||
procedure GridGetEditText(Sender: TObject; ACol, ARow: Integer;
|
||||
var Value: string);
|
||||
procedure GridSetEditText(Sender: TObject; ACol, ARow: Integer;
|
||||
const Value: string);
|
||||
private
|
||||
FVCards: TVpVCards;
|
||||
FDatastore: TVpCustomDatastore;
|
||||
FDefaultCategory: String;
|
||||
function GetCardText(ACard: TVpVCard): String;
|
||||
procedure SetVCards(const AValue: TVpVCards);
|
||||
|
||||
@ -29,6 +34,7 @@ type
|
||||
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;
|
||||
|
||||
var
|
||||
@ -63,11 +69,13 @@ var
|
||||
card: TVpVCard;
|
||||
begin
|
||||
Result := '';
|
||||
if (ACol = 1) and (ARow >= Grid.FixedRows) then
|
||||
if (ARow >= Grid.FixedRows) then
|
||||
begin
|
||||
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
|
||||
if card <> nil then
|
||||
Result := GetCardText(card);
|
||||
case ACol of
|
||||
1: Result := GetCardText(card);
|
||||
2: Result := Grid.Columns[2].PickList[card.PickedCategory]
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -92,6 +100,30 @@ begin
|
||||
s := ACard.GetEMail;
|
||||
if s <> '' then
|
||||
Result := Result + LineEnding + RSEMail + ': ' + s;
|
||||
|
||||
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);;
|
||||
end;
|
||||
|
||||
function TVpImportPreviewVCardForm.IsChecked(ARow: Integer): Boolean;
|
||||
@ -109,6 +141,10 @@ end;
|
||||
procedure TVpImportPreviewVCardForm.PrepareItems;
|
||||
var
|
||||
i: Integer;
|
||||
card: TVpVCard;
|
||||
cat: string;
|
||||
ct: TVpCategoryType;
|
||||
L: TStrings;
|
||||
begin
|
||||
FItems.Clear;
|
||||
if FVCards <> nil then
|
||||
@ -118,6 +154,39 @@ begin
|
||||
inherited;
|
||||
|
||||
Grid.Columns[1].Title.Caption := RSContactItems;
|
||||
|
||||
if (FVCards <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
|
||||
begin
|
||||
Grid.Columns[1].Title.Caption := RSContactItems;
|
||||
|
||||
with Grid.Columns.Add 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;
|
||||
|
||||
for i := 0 to FItems.Count-1 do
|
||||
begin
|
||||
card := TVpVCard(FItems[i]);
|
||||
cat := FDatastore.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;
|
||||
|
||||
end;
|
||||
|
||||
procedure TVpImportPreviewVCardForm.SetVCards(const AValue: TVpVCards);
|
||||
|
Reference in New Issue
Block a user