From d97209a2a33f77108594fa44d8fc8c99bdcdca47 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 11 Aug 2022 20:32:13 +0000 Subject: [PATCH] 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 --- components/tvplanit/languages/vpsr.de.po | 9 ++ components/tvplanit/languages/vpsr.en.po | 9 ++ components/tvplanit/languages/vpsr.fi.po | 9 ++ components/tvplanit/languages/vpsr.fr.po | 9 ++ components/tvplanit/languages/vpsr.nl.po | 9 ++ components/tvplanit/languages/vpsr.pl.po | 9 ++ components/tvplanit/languages/vpsr.pot | 9 ++ components/tvplanit/languages/vpsr.ru.po | 9 ++ components/tvplanit/laz_visualplanit.lpk | 6 +- components/tvplanit/source/include/vpsr.inc | 4 +- components/tvplanit/source/vpcontactgrid.pas | 25 ++- components/tvplanit/source/vpdata.pas | 70 +++++++- .../tvplanit/source/vpimportpreview_vcard.lfm | 41 +++++ .../tvplanit/source/vpimportpreview_vcard.lrj | 5 + .../tvplanit/source/vpimportpreview_vcard.pas | 150 ++++++++++++++++++ components/tvplanit/source/vpvcard.pas | 111 ++++++++++++- 16 files changed, 478 insertions(+), 6 deletions(-) create mode 100644 components/tvplanit/source/vpimportpreview_vcard.lfm create mode 100644 components/tvplanit/source/vpimportpreview_vcard.lrj create mode 100644 components/tvplanit/source/vpimportpreview_vcard.pas diff --git a/components/tvplanit/languages/vpsr.de.po b/components/tvplanit/languages/vpsr.de.po index 456d905f2..b44b933ee 100644 --- a/components/tvplanit/languages/vpsr.de.po +++ b/components/tvplanit/languages/vpsr.de.po @@ -567,6 +567,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "Zoll" @@ -775,6 +779,11 @@ msgstr "Ohne Alarm" msgid "TCanvas not assigned" msgstr "TCanvas wurde nicht zugewiesen" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "Komponente muss mit einem TVpControlLink verbunden sein" diff --git a/components/tvplanit/languages/vpsr.en.po b/components/tvplanit/languages/vpsr.en.po index daf4a5c90..aa5e14c08 100644 --- a/components/tvplanit/languages/vpsr.en.po +++ b/components/tvplanit/languages/vpsr.en.po @@ -561,6 +561,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "Inches" @@ -767,6 +771,11 @@ msgstr "No alarm" msgid "TCanvas not assigned" msgstr "TCanvas not assigned" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "Component must be linked to a TVpControlLink" diff --git a/components/tvplanit/languages/vpsr.fi.po b/components/tvplanit/languages/vpsr.fi.po index 718728320..9695e7934 100644 --- a/components/tvplanit/languages/vpsr.fi.po +++ b/components/tvplanit/languages/vpsr.fi.po @@ -558,6 +558,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "" @@ -766,6 +770,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "" diff --git a/components/tvplanit/languages/vpsr.fr.po b/components/tvplanit/languages/vpsr.fr.po index a0e534e54..e879d9889 100644 --- a/components/tvplanit/languages/vpsr.fr.po +++ b/components/tvplanit/languages/vpsr.fr.po @@ -573,6 +573,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "" @@ -781,6 +785,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "TCanvas non spécifié" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "Le composant doit être lié à un TVpControlLink" diff --git a/components/tvplanit/languages/vpsr.nl.po b/components/tvplanit/languages/vpsr.nl.po index f9c27dd15..101f0cc5a 100644 --- a/components/tvplanit/languages/vpsr.nl.po +++ b/components/tvplanit/languages/vpsr.nl.po @@ -567,6 +567,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "" @@ -775,6 +779,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "TCanvas is niet toegewezen." +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "Component moet moet met een TVpControlLink verbonden zijn" diff --git a/components/tvplanit/languages/vpsr.pl.po b/components/tvplanit/languages/vpsr.pl.po index 7e51d9975..eb786decf 100644 --- a/components/tvplanit/languages/vpsr.pl.po +++ b/components/tvplanit/languages/vpsr.pl.po @@ -567,6 +567,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "Cale" @@ -775,6 +779,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "TCanvas nie został przypisany." +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "Komponent musi być przypisany do TVpControlLink." diff --git a/components/tvplanit/languages/vpsr.pot b/components/tvplanit/languages/vpsr.pot index 3461b3b4c..8af433930 100644 --- a/components/tvplanit/languages/vpsr.pot +++ b/components/tvplanit/languages/vpsr.pot @@ -551,6 +551,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "" @@ -757,6 +761,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "" diff --git a/components/tvplanit/languages/vpsr.ru.po b/components/tvplanit/languages/vpsr.ru.po index 80e486ec1..4c29ecb3a 100644 --- a/components/tvplanit/languages/vpsr.ru.po +++ b/components/tvplanit/languages/vpsr.ru.po @@ -567,6 +567,10 @@ msgstr "" msgid "Import ICalendar Task" msgstr "" +#: vpsr.rsimportvcard +msgid "Import VCard" +msgstr "" + #: vpsr.rsinches msgid "Inches" msgstr "Дюймы" @@ -775,6 +779,11 @@ msgstr "" msgid "TCanvas not assigned" msgstr "" +#: vpsr.rsnocontactsfoundinvcard +#, object-pascal-format +msgid "No contact items found in \"%s\"." +msgstr "" + #: vpsr.rsnocontrollink msgid "Component must be linked to a TVpControlLink" msgstr "" diff --git a/components/tvplanit/laz_visualplanit.lpk b/components/tvplanit/laz_visualplanit.lpk index dc78aa752..9358d53e2 100644 --- a/components/tvplanit/laz_visualplanit.lpk +++ b/components/tvplanit/laz_visualplanit.lpk @@ -32,7 +32,7 @@ Portions created by TurboPower Software Inc. are Copyright (C) 2002 TurboPower S Contributor(s): "/> - + @@ -293,6 +293,10 @@ Contributor(s): "/> + + + + diff --git a/components/tvplanit/source/include/vpsr.inc b/components/tvplanit/source/include/vpsr.inc index 047d133db..cd39ea035 100644 --- a/components/tvplanit/source/include/vpsr.inc +++ b/components/tvplanit/source/include/vpsr.inc @@ -184,10 +184,12 @@ resourcestring RSICalFilter = 'iCalendar files (*.ical;*.ics)|*.ical;*.ics'; RSImportICalEvent = 'Import ICalendar Event'; RSImportICalTask = 'Import ICalendar Task'; + RSImportVCard = 'Import VCard'; RSRepeat = 'Repeat:'; RSNoEventItemsFoundInICAL = 'No event items found in "%s".'; RSNoTaskItemsFoundInICAL = 'No task items found in "%s".'; - + RSNoContactsFoundInVCARD = 'No contact items found in "%s".'; + {Task Specific} RSConfirmDeleteTask = 'Delete this task from your list?'; RSTaskPopupAdd = 'Add task...'; diff --git a/components/tvplanit/source/vpcontactgrid.pas b/components/tvplanit/source/vpcontactgrid.pas index 63da828ac..e90e51cfc 100644 --- a/components/tvplanit/source/vpcontactgrid.pas +++ b/components/tvplanit/source/vpcontactgrid.pas @@ -246,6 +246,8 @@ type Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime; StartLine, StopLine: Integer; UseGran: TVpGranularity; DisplayOnly: Boolean); override; + function ImportVCardFile(const AFileName: String; + APreview: Boolean = false): TVpContactArr; { - Added to support the buttonbar component. } function SelectContactByName(const Name: String): Boolean; @@ -1556,7 +1558,24 @@ begin { Allow the user to fill in all the new information } cgSpawnContactEditDialog(True); 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); var @@ -1578,6 +1597,9 @@ begin dlg.FileName := ''; dlg.Options := dlg.Options + [ofAllowMultiSelect, ofFileMustExist]; if dlg.Execute then begin + for fn in dlg.Files do + ImportVCardFile(fn, dlg.Files.Count=1); + (* Screen.Cursor := crHourGlass; Application.ProcessMessages; vcards := TVpVCards.Create; @@ -1597,6 +1619,7 @@ begin vcards.Free; Screen.Cursor := crDefault; end; + *) end; finally dlg.Free; diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index 1651ec407..49f055371 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -78,6 +78,7 @@ type TVpEventArr = array of TVpEvent; TVpTaskArr = array of TVpTask; + TVpContactArr = array of TVpContact; TVpResources = class private @@ -391,7 +392,7 @@ type function LastByDay(Date: TDateTime): TVpTask; procedure Sort; function GetTask(Index: Integer): TVpTask; - property Owner: TVpREsource read FOwner; + property Owner: TVpResource read FOwner; end; TVpTask = class @@ -494,12 +495,14 @@ type CaseInsensitive: Boolean = True): Integer; function GetContact(Index: Integer): TVpContact; function Last:TVpContact; + function ImportVCardFile(const AFileName: String; const APreview: Boolean = false): TVpContactArr; procedure Sort; property ContactsList: TList read FContactsList; property ContactSort: TVpContactSort read FContactSort write SetContactSort default csLastFirst; + property Owner: TVpResource read FOwner; end; TVpContact = class @@ -712,7 +715,7 @@ implementation uses Math, DateUtils, VpException, VpConst, VpMisc, VpBaseDS, - VpImportPreview_ICalEvent, VpImportPreview_ICalTask; + VpImportPreview_ICalEvent, VpImportPreview_ICalTask, VpImportPreview_VCard; const TIME_EPS = 1.0 / SecondsInDay; // Epsilon for comparing times @@ -2792,6 +2795,68 @@ begin 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 } @@ -3022,6 +3087,7 @@ begin if ical.ToDoCount = 0 then begin MessageDlg(Format(RSNoTaskItemsFoundInICAL, [AFileName]), mtInformation, [mbOK], 0); + SetLength(Result, 0); exit; end; if APreview then diff --git a/components/tvplanit/source/vpimportpreview_vcard.lfm b/components/tvplanit/source/vpimportpreview_vcard.lfm new file mode 100644 index 000000000..a90254590 --- /dev/null +++ b/components/tvplanit/source/vpimportpreview_vcard.lfm @@ -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 diff --git a/components/tvplanit/source/vpimportpreview_vcard.lrj b/components/tvplanit/source/vpimportpreview_vcard.lrj new file mode 100644 index 000000000..ace7c9195 --- /dev/null +++ b/components/tvplanit/source/vpimportpreview_vcard.lrj @@ -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"} +]} diff --git a/components/tvplanit/source/vpimportpreview_vcard.pas b/components/tvplanit/source/vpimportpreview_vcard.pas new file mode 100644 index 000000000..7e2633936 --- /dev/null +++ b/components/tvplanit/source/vpimportpreview_vcard.pas @@ -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. + diff --git a/components/tvplanit/source/vpvcard.pas b/components/tvplanit/source/vpvcard.pas index 8f094cb68..045e27320 100644 --- a/components/tvplanit/source/vpvcard.pas +++ b/components/tvplanit/source/vpvcard.pas @@ -47,10 +47,18 @@ type FCarPhone: String; FISDN: String; FPager: String; + + FSkip: Boolean; public constructor Create; procedure Analyze; override; 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 LastName: String read FLastName; @@ -81,6 +89,7 @@ type property Pager: String read FPager; property Version: String read FVersion; + property Skip: Boolean read FSkip write FSkip; end; TVpVCards = class @@ -193,6 +202,7 @@ var i: Integer; item: TVpVCardItem; fn, ln, t: String; + fullName: String; begin inherited; @@ -201,7 +211,9 @@ begin case item.Key of 'VERSION': FVersion := item.Value; - 'FN', 'N': + 'FN': + fullName := item.Value; + 'N': begin VCardName(item.Value, ln, fn, t); if FLastName = '' then FLastName := ln; @@ -250,6 +262,13 @@ begin FWorkPhone := IfThen(FWorkPhone = '', item.Value, FWorkPhone + ITEM_SEPARATOR + item.Value); end; end; + + if (FFirstName = '') and (FLastName = '') then + begin + FLastName := fullName; + FFirstName := ''; + FTitle := ''; + end; end; function TVpVCard.FindItem(AKey, ATags: String): TVpVCardItem; @@ -257,6 +276,96 @@ begin Result := TVpVCardItem(inherited FindItem(AKey, ATags)); 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 }