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

@ -567,6 +567,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "Zoll" msgstr "Zoll"
@ -775,6 +779,11 @@ msgstr "Ohne Alarm"
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "TCanvas wurde nicht zugewiesen" msgstr "TCanvas wurde nicht zugewiesen"
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "Komponente muss mit einem TVpControlLink verbunden sein" msgstr "Komponente muss mit einem TVpControlLink verbunden sein"

View File

@ -561,6 +561,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "Inches" msgstr "Inches"
@ -767,6 +771,11 @@ msgstr "No alarm"
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "TCanvas not assigned" msgstr "TCanvas not assigned"
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "Component must be linked to a TVpControlLink" msgstr "Component must be linked to a TVpControlLink"

View File

@ -558,6 +558,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "" msgstr ""
@ -766,6 +770,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "" msgstr ""
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "" msgstr ""

View File

@ -573,6 +573,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "" msgstr ""
@ -781,6 +785,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "TCanvas non spécifié" msgstr "TCanvas non spécifié"
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "Le composant doit être lié à un TVpControlLink" msgstr "Le composant doit être lié à un TVpControlLink"

View File

@ -567,6 +567,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "" msgstr ""
@ -775,6 +779,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "TCanvas is niet toegewezen." msgstr "TCanvas is niet toegewezen."
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "Component moet moet met een TVpControlLink verbonden zijn" msgstr "Component moet moet met een TVpControlLink verbonden zijn"

View File

@ -567,6 +567,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "Cale" msgstr "Cale"
@ -775,6 +779,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "TCanvas nie został przypisany." msgstr "TCanvas nie został przypisany."
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "Komponent musi być przypisany do TVpControlLink." msgstr "Komponent musi być przypisany do TVpControlLink."

View File

@ -551,6 +551,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "" msgstr ""
@ -757,6 +761,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "" msgstr ""
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "" msgstr ""

View File

@ -567,6 +567,10 @@ msgstr ""
msgid "Import ICalendar Task" msgid "Import ICalendar Task"
msgstr "" msgstr ""
#: vpsr.rsimportvcard
msgid "Import VCard"
msgstr ""
#: vpsr.rsinches #: vpsr.rsinches
msgid "Inches" msgid "Inches"
msgstr "Дюймы" msgstr "Дюймы"
@ -775,6 +779,11 @@ msgstr ""
msgid "TCanvas not assigned" msgid "TCanvas not assigned"
msgstr "" msgstr ""
#: vpsr.rsnocontactsfoundinvcard
#, object-pascal-format
msgid "No contact items found in \"%s\"."
msgstr ""
#: vpsr.rsnocontrollink #: vpsr.rsnocontrollink
msgid "Component must be linked to a TVpControlLink" msgid "Component must be linked to a TVpControlLink"
msgstr "" msgstr ""

View File

@ -32,7 +32,7 @@ Portions created by TurboPower Software Inc. are Copyright (C) 2002 TurboPower S
Contributor(s): "/> Contributor(s): "/>
<Version Major="1" Minor="7"/> <Version Major="1" Minor="7"/>
<Files Count="65"> <Files Count="66">
<Item1> <Item1>
<Filename Value="source\vpbase.pas"/> <Filename Value="source\vpbase.pas"/>
<UnitName Value="VpBase"/> <UnitName Value="VpBase"/>
@ -293,6 +293,10 @@ Contributor(s): "/>
<Filename Value="source\vpimportpreview_icaltask.pas"/> <Filename Value="source\vpimportpreview_icaltask.pas"/>
<UnitName Value="VpImportPreview_ICalTask"/> <UnitName Value="VpImportPreview_ICalTask"/>
</Item65> </Item65>
<Item66>
<Filename Value="source\vpimportpreview_vcard.pas"/>
<UnitName Value="VpImportPreview_VCard"/>
</Item66>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<i18n> <i18n>

View File

@ -184,9 +184,11 @@ resourcestring
RSICalFilter = 'iCalendar files (*.ical;*.ics)|*.ical;*.ics'; RSICalFilter = 'iCalendar files (*.ical;*.ics)|*.ical;*.ics';
RSImportICalEvent = 'Import ICalendar Event'; RSImportICalEvent = 'Import ICalendar Event';
RSImportICalTask = 'Import ICalendar Task'; RSImportICalTask = 'Import ICalendar Task';
RSImportVCard = 'Import VCard';
RSRepeat = 'Repeat:'; RSRepeat = 'Repeat:';
RSNoEventItemsFoundInICAL = 'No event items found in "%s".'; RSNoEventItemsFoundInICAL = 'No event items found in "%s".';
RSNoTaskItemsFoundInICAL = 'No task items found in "%s".'; RSNoTaskItemsFoundInICAL = 'No task items found in "%s".';
RSNoContactsFoundInVCARD = 'No contact items found in "%s".';
{Task Specific} {Task Specific}
RSConfirmDeleteTask = 'Delete this task from your list?'; RSConfirmDeleteTask = 'Delete this task from your list?';

View File

@ -246,6 +246,8 @@ type
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime; Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
StartLine, StopLine: Integer; UseGran: TVpGranularity; StartLine, StopLine: Integer; UseGran: TVpGranularity;
DisplayOnly: Boolean); override; DisplayOnly: Boolean); override;
function ImportVCardFile(const AFileName: String;
APreview: Boolean = false): TVpContactArr;
{ - Added to support the buttonbar component. } { - Added to support the buttonbar component. }
function SelectContactByName(const Name: String): Boolean; function SelectContactByName(const Name: String): Boolean;
@ -1556,7 +1558,24 @@ begin
{ Allow the user to fill in all the new information } { Allow the user to fill in all the new information }
cgSpawnContactEditDialog(True); cgSpawnContactEditDialog(True);
end; end;
{=====}
function TVpContactGrid.ImportVCardFile(const AFileName: String;
APreview: Boolean = false): TVpContactArr;
begin
if ReadOnly or (not CheckCreateResource) or
(not Assigned(Datastore)) or (not Assigned(Datastore.Resource))
then
exit(nil);
Result := Datastore.Resource.Contacts.ImportVCardFile(AFileName, APreview);
if Length(Result) > 0 then
begin
FActiveContact := Result[High(Result)];
Datastore.PostContacts;
Datastore.NotifyDependents;
Invalidate;
end;
end;
procedure TVpContactGrid.PopupAddVCards(Sender: TObject); procedure TVpContactGrid.PopupAddVCards(Sender: TObject);
var var
@ -1578,6 +1597,9 @@ begin
dlg.FileName := ''; dlg.FileName := '';
dlg.Options := dlg.Options + [ofAllowMultiSelect, ofFileMustExist]; dlg.Options := dlg.Options + [ofAllowMultiSelect, ofFileMustExist];
if dlg.Execute then begin if dlg.Execute then begin
for fn in dlg.Files do
ImportVCardFile(fn, dlg.Files.Count=1);
(*
Screen.Cursor := crHourGlass; Screen.Cursor := crHourGlass;
Application.ProcessMessages; Application.ProcessMessages;
vcards := TVpVCards.Create; vcards := TVpVCards.Create;
@ -1597,6 +1619,7 @@ begin
vcards.Free; vcards.Free;
Screen.Cursor := crDefault; Screen.Cursor := crDefault;
end; end;
*)
end; end;
finally finally
dlg.Free; dlg.Free;

View File

@ -78,6 +78,7 @@ type
TVpEventArr = array of TVpEvent; TVpEventArr = array of TVpEvent;
TVpTaskArr = array of TVpTask; TVpTaskArr = array of TVpTask;
TVpContactArr = array of TVpContact;
TVpResources = class TVpResources = class
private private
@ -391,7 +392,7 @@ type
function LastByDay(Date: TDateTime): TVpTask; function LastByDay(Date: TDateTime): TVpTask;
procedure Sort; procedure Sort;
function GetTask(Index: Integer): TVpTask; function GetTask(Index: Integer): TVpTask;
property Owner: TVpREsource read FOwner; property Owner: TVpResource read FOwner;
end; end;
TVpTask = class TVpTask = class
@ -494,12 +495,14 @@ type
CaseInsensitive: Boolean = True): Integer; CaseInsensitive: Boolean = True): Integer;
function GetContact(Index: Integer): TVpContact; function GetContact(Index: Integer): TVpContact;
function Last:TVpContact; function Last:TVpContact;
function ImportVCardFile(const AFileName: String; const APreview: Boolean = false): TVpContactArr;
procedure Sort; procedure Sort;
property ContactsList: TList property ContactsList: TList
read FContactsList; read FContactsList;
property ContactSort: TVpContactSort property ContactSort: TVpContactSort
read FContactSort write SetContactSort default csLastFirst; read FContactSort write SetContactSort default csLastFirst;
property Owner: TVpResource read FOwner;
end; end;
TVpContact = class TVpContact = class
@ -712,7 +715,7 @@ implementation
uses uses
Math, DateUtils, Math, DateUtils,
VpException, VpConst, VpMisc, VpBaseDS, VpException, VpConst, VpMisc, VpBaseDS,
VpImportPreview_ICalEvent, VpImportPreview_ICalTask; VpImportPreview_ICalEvent, VpImportPreview_ICalTask, VpImportPreview_VCard;
const const
TIME_EPS = 1.0 / SecondsInDay; // Epsilon for comparing times TIME_EPS = 1.0 / SecondsInDay; // Epsilon for comparing times
@ -2792,6 +2795,68 @@ begin
end; end;
end; end;
function TVpContacts.ImportVCardFile(const AFileName: String;
const APreview: Boolean = false): TVpContactArr;
const
BLOCK_SIZE = 10;
var
vCards: TVpVCards;
lContact: TVpContact;
contactCounter: Integer;
i: Integer;
id: Integer;
datastore: TVpCustomDatastore;
previewForm: TVpImportPreviewVCardForm;
begin
Result := nil;
SetLength(Result, BLOCK_SIZE);
contactCounter := 0;
datastore := Owner.Owner.Owner as TVpCustomDatastore;
vcards := TVpVCards.Create;
try
vCards.LoadFromFile(AFileName);
if vCards.Count = 0 then
begin
MessageDlg(Format(RSNoContactsFoundInVCARD, [AFileName]), mtInformation, [mbOK], 0);
SetLength(Result, 0);
exit;
end;
if APreview then
begin
previewForm := TVPImportPreviewVCardForm.Create(nil);
previewForm.Position := poMainFormcenter;
previewForm.VCards := vCards;
if not previewForm.Execute then
begin
SetLength(Result, 0);
exit;
end;
end;
for i := 0 to vcards.Count-1 do begin
if vCards[i].Skip then
Continue;
id := datastore.GetNextID(ContactsTableName);
lContact := AddContact(id);
lContact.LoadFromVCard(vcards[i]);
Result[contactCounter] := lContact;
inc(contactCounter);
if contactCounter mod BLOCK_SIZE = 0 then
SetLength(Result, contactCounter + BLOCK_SIZE);
end;
SetLength(Result, contactCounter);
if Length(Result) = 0 then
MessageDlg(Format(RSNoContactsFoundInVCARD, [AFileName]), mtInformation, [mbOK], 0);
finally
if APreview then
previewForm.Free;
vCards.Free;
end;
end;
(*****************************************************************************) (*****************************************************************************)
{ TVpTask } { TVpTask }
@ -3022,6 +3087,7 @@ begin
if ical.ToDoCount = 0 then if ical.ToDoCount = 0 then
begin begin
MessageDlg(Format(RSNoTaskItemsFoundInICAL, [AFileName]), mtInformation, [mbOK], 0); MessageDlg(Format(RSNoTaskItemsFoundInICAL, [AFileName]), mtInformation, [mbOK], 0);
SetLength(Result, 0);
exit; exit;
end; end;
if APreview then if APreview then

View File

@ -0,0 +1,41 @@
inherited VpImportPreviewVCardForm: TVpImportPreviewVCardForm
Height = 400
Width = 667
Caption = ''
ClientHeight = 400
ClientWidth = 667
inherited Grid: TDrawGrid
Height = 363
Width = 667
Columns = <
item
Alignment = taCenter
ButtonStyle = cbsCheckboxColumn
PickList.Strings = ( )
SizePriority = 0
Title.Caption = ''
Width = 33
end
item
PickList.Strings = ( )
ReadOnly = True
Title.Caption = 'Items'
Width = 634
end>
ColWidths = (
33
634
)
end
inherited ButtonPanel: TPanel
Top = 369
Width = 655
ClientWidth = 655
inherited btnExecute: TButton
Left = 439
end
inherited btnCancel: TButton
Left = 580
end
end
end

View File

@ -0,0 +1,5 @@
{"version":1,"strings":[
{"hash":4294967295,"name":"tvpimportpreviewvcardform.caption","sourcebytes":[],"value":""},
{"hash":4294967295,"name":"tvpimportpreviewvcardform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
{"hash":5286979,"name":"tvpimportpreviewvcardform.grid.columns[1].title.caption","sourcebytes":[73,116,101,109,115],"value":"Items"}
]}

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.

View File

@ -47,11 +47,19 @@ type
FCarPhone: String; FCarPhone: String;
FISDN: String; FISDN: String;
FPager: String; FPager: String;
FSkip: Boolean;
public public
constructor Create; constructor Create;
procedure Analyze; override; procedure Analyze; override;
function FindItem(AKey, ATags: String): TVpVCardItem; function FindItem(AKey, ATags: String): TVpVCardItem;
function GetEMail: String;
function GetFullName: String;
function GetHomeAddress: String;
function GetPhone: String;
function GetWorkAddress: String;
property FirstName: String read FFirstName; property FirstName: String read FFirstName;
property LastName: String read FLastName; property LastName: String read FLastName;
property Title: String read FTitle; property Title: String read FTitle;
@ -81,6 +89,7 @@ type
property Pager: String read FPager; property Pager: String read FPager;
property Version: String read FVersion; property Version: String read FVersion;
property Skip: Boolean read FSkip write FSkip;
end; end;
TVpVCards = class TVpVCards = class
@ -193,6 +202,7 @@ var
i: Integer; i: Integer;
item: TVpVCardItem; item: TVpVCardItem;
fn, ln, t: String; fn, ln, t: String;
fullName: String;
begin begin
inherited; inherited;
@ -201,7 +211,9 @@ begin
case item.Key of case item.Key of
'VERSION': 'VERSION':
FVersion := item.Value; FVersion := item.Value;
'FN', 'N': 'FN':
fullName := item.Value;
'N':
begin begin
VCardName(item.Value, ln, fn, t); VCardName(item.Value, ln, fn, t);
if FLastName = '' then FLastName := ln; if FLastName = '' then FLastName := ln;
@ -250,6 +262,13 @@ begin
FWorkPhone := IfThen(FWorkPhone = '', item.Value, FWorkPhone + ITEM_SEPARATOR + item.Value); FWorkPhone := IfThen(FWorkPhone = '', item.Value, FWorkPhone + ITEM_SEPARATOR + item.Value);
end; end;
end; end;
if (FFirstName = '') and (FLastName = '') then
begin
FLastName := fullName;
FFirstName := '';
FTitle := '';
end;
end; end;
function TVpVCard.FindItem(AKey, ATags: String): TVpVCardItem; function TVpVCard.FindItem(AKey, ATags: String): TVpVCardItem;
@ -257,6 +276,96 @@ begin
Result := TVpVCardItem(inherited FindItem(AKey, ATags)); Result := TVpVCardItem(inherited FindItem(AKey, ATags));
end; end;
function TVpVCard.GetEMail: String;
var
sw, sh: String;
begin
if WorkEMail <> '' then sw := Format('%s (work)', [WorkEMail]) else sw := '';
if HomeEMail <> '' then sh := Format('%s (home)', [HomeEMail]) else sh := '';
if (sw <> '') and (sh <> '') then
Result := sw + '; ' + sh
else if (sw <> '') then
Result := sw
else if (sh <> '') then
Result := sh
else
Result := '';
end;
function TVpVCard.GetFullName: String;
begin
Result := LastName;
if FirstName <> '' then Result := FirstName + ' ' + Result;
if Title <> '' then Result := Result + ', ' + Title;
end;
function TVpVCard.GetHomeAddress: String;
begin
Result := '';
if (HomeAddress = '') and (HomeZip = '') and (HomeCity = '') then
exit;
Result := HomeAddress + ', ' + HomeZip + ' ' + HomeCity;
if HomeState <> '' then
Result := Result + ', ' + HomeState;
if HomeCountry <> '' then
Result := Result + ', ' + HomeCountry;
end;
function TVpVCard.GetPhone: String;
var
sw, sh: String;
begin
if WorkPhone <> '' then sw := Format('%s (work)', [WorkPhone]) else sw := '';
if HomePhone <> '' then sh := Format('%s (home)', [HomePhone]) else sh := '';
if (sw <> '') and (sh <> '') then
Result := sw + '; ' + sh
else if (sw <> '') then
Result := sw
else if (sh <> '') then
Result := sh
else
Result := '';
end;
function TVpVCard.GetWorkAddress: String;
begin
Result := '';
if (Company = '') and (WorkAddress = '') and (WorkZip = '') and (WorkCity = '') then
exit;
Result := Company + ', ' + WorkAddress + ', ' + WorkZip + ' ' + WorkCity;
if WorkState <> '' then
Result := Result + ', ' + WorkState;
if WorkCountry <> '' then
Result := Result + ', ' + WorkCountry;
end;
(*
function GetHomeAddress: String;
function GetWorkAddress: String;
property FirstName: String read FFirstName;
property LastName: String read FLastName;
property Title: String read FTitle;
property Company: String read FCompany;
property WorkAddress: String read FWorkAddress;
property WorkCity: String read FWorkCity;
property WorkZip: String read FWorkZip;
property WorkState: String read FWorkState;
property WorkCountry: String read FWorkCountry;
property WorkEMail: String read FWorkEMail;
property WorkPhone: String read FWorkPhone;
property WorkFax: String read FWorkFax;
property HomeAddress: String read FHomeAddress;
property HomeCity: String read FHomeCity;
property HomeZip: String read FHomeZip;
property HomeState: String read FHomeState;
property HomeCountry: String read FHomeCountry;
property HomeEMail: String read FHomeEMail;
property HomePhone: String read FHomePhone;
property HomeFax: String read FHomeFax;
*)
{==============================================================================} {==============================================================================}
{ TVpCards } { TVpCards }