From 1b146107adad49ef2030dba6f0cf200c4786842a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 30 Jul 2020 21:50:35 +0000 Subject: [PATCH] fpspreadsheet: Allow multiple authors in metadata. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7592 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/other/metadata/demo_metadata.lpr | 3 +- .../source/common/fpsopendocument.pas | 7 ++++ .../fpspreadsheet/source/common/fpstypes.pas | 32 +++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr b/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr index 7ad702e35..09c713278 100644 --- a/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr +++ b/components/fpspreadsheet/examples/other/metadata/demo_metadata.lpr @@ -63,6 +63,7 @@ begin book := TsWorkbook.Create; try book.MetaData.CreatedBy := 'Donald Duck'; + book.MetaData.Authors.Add('Donald Duck II'); book.MetaData.DateCreated := EncodeDate(2020, 1, 1) + EncodeTime(12, 30, 40, 20); book.MetaData.DateLastModified := Now(); book.MetaData.LastModifiedBy := 'Dagobert Duck'; @@ -71,7 +72,7 @@ begin book.MetaData.Comments.Add('This is a test of spreadsheet metadata.'); book.MetaData.Comments.Add('Assign the author to the field CreatedBy.'); book.MetaData.Comments.Add('Assign the creation date to the field CreatedAt.'); - book.MetaData.Keywords.Add('Test'); + book.MetaData.Keywords.Add('Test1,Test2'); book.MetaData.Keywords.Add('FPSpreadsheet'); book.MetaData.AddCustom('Comparny', 'Disney'); book.MetaData.AddCustom('Status', 'finished'); diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index 6d2fe7ba4..284afa5d6 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -1984,6 +1984,9 @@ begin 'meta:keyword': if s <> '' then book.MetaData.KeyWords.Add(s); + '': + if s <> '' then + book.MetaData.LastModifiedBy := s; 'dc:date': if s <> '' then book.MetaData.DateLastModified := ISO8601StrToDateTime(s); @@ -5888,6 +5891,10 @@ begin AppendToStream(FSMeta, Format( '%s', [book.MetaData.CreatedBy])); + if book.MetaData.LastModifiedBy <> '' then + AppendToStream(FSMeta, Format( + '%s', [book.Metadata.LastMofifiedBy])); + if book.MetaData.DateCreated > 0 then begin // ODS stored the creation date in UTC. diff --git a/components/fpspreadsheet/source/common/fpstypes.pas b/components/fpspreadsheet/source/common/fpstypes.pas index 447fa00c3..2fe1987ec 100644 --- a/components/fpspreadsheet/source/common/fpstypes.pas +++ b/components/fpspreadsheet/source/common/fpstypes.pas @@ -968,27 +968,30 @@ type {@@ Meta data for the workbook} TsMetaData = class private - FCreatedBy: String; FDateCreated: TDateTime; FDateLastModified: TDateTime; FLastModifiedBy: String; FTitle: String; FSubject: String; + FAuthors: TStrings; FComments: TStrings; FKeywords: TStrings; FCustom: TStrings; + function GetCreatedBy: String; + procedure SetCreatedBy(AValue: String); public constructor Create; destructor Destroy; override; function AddCustom(AName, AValue: String): Integer; procedure Clear; function IsEmpty: Boolean; - property CreatedBy: String read FCreatedBy write FCreatedBy; + property CreatedBy: String read GetCreatedBy write SetCreatedBy; property LastModifiedBy: String read FLastModifiedBy write FLastModifiedBy; property DateCreated: TDateTime read FDateCreated write FDateCreated; property DateLastModified: TDatetime read FDateLastModified write FDateLastModified; property Subject: String read FSubject write FSubject; property Title: String read FTitle write FTitle; + property Authors: TStrings read FAuthors write FAuthors; property Comments: TStrings read FComments write FComments; property Custom: TStrings read FCustom write FCustom; property Keywords: TStrings read FKeywords write FKeywords; @@ -1201,6 +1204,9 @@ end; constructor TsMetaData.Create; begin inherited; + FAuthors := TStringList.Create; + FAuthors.StrictDelimiter := true; + FAuthors.Delimiter := ';'; FComments := TStringList.Create; FKeywords := TStringList.Create; FCustom := TStringList.Create; @@ -1208,6 +1214,7 @@ end; destructor TsMetaData.Destroy; begin + FAuthors.Free; FComments.Free; FKeywords.Free; FCustom.Free; @@ -1218,10 +1225,10 @@ procedure TsMetaData.Clear; begin FTitle := ''; FSubject := ''; - FCreatedBy := ''; FLastModifiedBy := ''; FDateCreated := 0; FDateLastModified := 0; + FAuthors.Clear; FComments.Clear; FKeywords.Clear; FCustom.Clear; @@ -1236,12 +1243,23 @@ begin Result := FCustom.Add(AName + '=' + AValue); end; +function TsMetaData.GetCreatedBy: String; +begin + Result := FAuthors.DelimitedText; +end; + function TsMetaData.IsEmpty: Boolean; begin - Result := (FCreatedBy = '') and (FLastModifiedBy = '') and - (FTitle = '') and (FSubject = '') and - (FComments.Count = 0) and (FKeywords.Count = 0) and (FCustom.Count = 0) and - (FDateCreated = 0) and (FDateLastModified = 0); + Result := (FLastModifiedBy = '') and (FTitle = '') and (FSubject = '') and + (FAuthors.Count = 0) and (FComments.Count = 0) and (FKeywords.Count = 0) and + (FCustom.Count = 0) and (FDateCreated = 0) and (FDateLastModified = 0); +end; + +{ Provide initial author. In case of multiple authors, separate the names by + semicolons. } +procedure TsMetaData.SetCreatedBy(AValue: String); +begin + FAuthors.DelimitedText := AValue; end;