- Timestamp:
- Jul 1, 2023, 8:17:50 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Core.pas
r167 r168 221 221 FormImport := TFormImport.Create(nil); 222 222 try 223 FormImport.ShowModal; 223 if FormImport.ShowModal = mrOK then begin 224 TVCardFile(DataFile).Modified := True; 225 UpdateFile; 226 end; 224 227 finally 225 228 FormImport.Free; -
trunk/Forms/FormExport.pas
r167 r168 36 36 Table: TTable; 37 37 RedrawPending: Boolean; 38 procedure PrepareTable;39 38 procedure UpdateFileNameExt; 40 39 procedure LoadConfig; … … 62 61 begin 63 62 TableFormat := TTableFormat(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex]); 64 SaveStringToFile(Table.GetOutput(TableFormat), EditOutputFile.Text); 63 TVCardFile(Core.Core.DataFile).VCard.ExportToFile(EditOutputFile.Text, TableFormat, 64 CheckBoxHumanReadableHeader.Checked); 65 65 end; 66 66 … … 118 118 begin 119 119 if RedrawPending then begin 120 PrepareTable; 120 TVCardFile(Core.Core.DataFile).VCard.ExportToTable(Table, 121 CheckBoxHumanReadableHeader.Checked); 121 122 Table.GetOutputListView(ListView1); 122 123 RedrawPending := False; 123 end;124 end;125 126 procedure TFormExport.PrepareTable;127 var128 Row: TRow;129 I: Integer;130 J: Integer;131 Values: TStringList;132 Index: Integer;133 Fields: TContactFields;134 Field: TContactField;135 Columns: TStringList;136 begin137 Fields := TContact.GetFields;138 Table.Clear;139 140 Values := TStringList.Create;141 Columns := TStringList.Create;142 try143 with TVCardFile(Core.Core.DataFile), VCard do begin144 Table.Title := ExtractFileNameWithoutExt(FileName);145 146 // Get all properties types147 for I := 0 to Contacts.Count - 1 do begin148 for J := 0 to Contacts[I].Properties.Count - 1 do149 if not Contacts[I].Properties[J].Name.StartsWith('PHOTO') and150 (Table.Columns.IndexOf(Contacts[I].Properties[J].Name) = -1) then begin151 Table.Columns.Add(Contacts[I].Properties[J].Name);152 Columns.Add(Contacts[I].Properties[J].Name);153 end;154 end;155 156 if CheckBoxHumanReadableHeader.Checked then begin157 for I := 0 to Table.Columns.Count - 1 do begin158 Field := Fields.GetBySysName(Table.Columns[I]);159 if Assigned(Field) then Table.Columns[I] := Field.Title;160 end;161 end;162 163 for I := 0 to Contacts.Count - 1 do begin164 Values.Clear;165 for J := 0 to Columns.Count - 1 do166 Values.Add('');167 for J := 0 to Contacts[I].Properties.Count - 1 do begin168 Index := Columns.IndexOf(Contacts[I].Properties[J].Name);169 if Index <> -1 then170 Values[Index] := Contacts[I].Properties[J].Value;171 end;172 173 Row := Table.AddRow;174 for J := 0 to Values.Count - 1 do175 Row.Cells.Add(Values[J]);176 end;177 end;178 finally179 Values.Free;180 Columns.Free;181 124 end; 182 125 end; -
trunk/Forms/FormImage.lfm
r165 r168 51 51 Anchors = [akLeft, akBottom] 52 52 Caption = 'Clear' 53 OnClick = uttonClearClick53 OnClick = ButtonClearClick 54 54 TabOrder = 2 55 55 end 56 56 object EditUrl: TEdit 57 57 Left = 84 58 Height = 3359 Top = 4 2658 Height = 43 59 Top = 416 60 60 Width = 610 61 61 Anchors = [akLeft, akRight, akBottom] … … 85 85 object Label1: TLabel 86 86 Left = 16 87 Height = 2 588 Top = 43 289 Width = 3 587 Height = 26 88 Top = 431 89 Width = 38 90 90 Anchors = [akLeft, akBottom] 91 91 Caption = 'URL:' -
trunk/Forms/FormImage.pas
r162 r168 22 22 OpenPictureDialog1: TOpenPictureDialog; 23 23 SavePictureDialog1: TSavePictureDialog; 24 procedure uttonClearClick(Sender: TObject);24 procedure ButtonClearClick(Sender: TObject); 25 25 procedure ButtonLoadClick(Sender: TObject); 26 26 procedure ButtonSaveClick(Sender: TObject); … … 67 67 end; 68 68 69 procedure TFormImage. uttonClearClick(Sender: TObject);69 procedure TFormImage.ButtonClearClick(Sender: TObject); 70 70 begin 71 71 Image.Clear; -
trunk/Forms/FormImport.lfm
r167 r168 80 80 Width = 464 81 81 Anchors = [akTop, akLeft, akRight] 82 OnChange = EditInputFileChange 82 83 TabOrder = 1 83 84 end -
trunk/Forms/FormImport.pas
r167 r168 27 27 procedure ButtonImportClick(Sender: TObject); 28 28 procedure ComboBoxInputFormatChange(Sender: TObject); 29 procedure EditInputFileChange(Sender: TObject); 29 30 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 30 31 procedure FormCreate(Sender: TObject); … … 47 48 48 49 uses 49 Core, Common, RegistryEx, VCardFile ;50 Core, Common, RegistryEx, VCardFile, VCard; 50 51 51 52 { TFormImport } … … 61 62 begin 62 63 TableFormat := TTableFormat(ComboBoxInputFormat.Items.Objects[ComboBoxInputFormat.ItemIndex]); 63 T able.SetInput(TableFormat, LoadFileToStr(EditInputFile.Text));64 Table.Title := ExtractFileNameWithoutExt(EditInputFile.Text);64 TVCardFile(Core.Core.DataFile).VCard.ImportFromFile(EditInputFile.Text, TableFormat, 65 CheckBoxHumanReadableHeader.Checked); 65 66 end; 66 67 … … 68 69 begin 69 70 UpdateTableFormat; 71 end; 72 73 procedure TFormImport.EditInputFileChange(Sender: TObject); 74 begin 75 RedrawPending := True; 70 76 end; 71 77 -
trunk/Languages/vCardStudio.cs.po
r167 r168 276 276 msgstr "Očekáváno:" 277 277 278 #: test.sexport 279 msgid "Export:" 280 msgstr "" 281 278 282 #: test.soutput 279 283 msgctxt "test.soutput" … … 975 979 msgctxt "tformexport.checkboxhumanreadableheader.caption" 976 980 msgid "Human readable header" 977 msgstr " "981 msgstr "Lidsky čitelná hlavička" 978 982 979 983 #: tformexport.label1.caption … … 1101 1105 msgctxt "tformimport.checkboxhumanreadableheader.caption" 1102 1106 msgid "Human readable header" 1103 msgstr " "1107 msgstr "Lidsky čitelná hlavička" 1104 1108 1105 1109 #: tformimport.label1.caption -
trunk/Languages/vCardStudio.pot
r167 r168 266 266 msgstr "" 267 267 268 #: test.sexport 269 msgid "Export:" 270 msgstr "" 271 268 272 #: test.soutput 269 273 msgctxt "test.soutput" -
trunk/Languages/vCardStudio.sv.po
r167 r168 277 277 msgstr "" 278 278 279 #: test.sexport 280 msgid "Export:" 281 msgstr "" 282 279 283 #: test.soutput 280 284 msgctxt "test.soutput" -
trunk/Packages/Common/Table.pas
r167 r168 281 281 282 282 procedure TTable.SetInputCsv(Text: string); 283 begin 284 283 var 284 Lines: TStringList; 285 I: Integer; 286 Row: TRow; 287 begin 288 Clear; 289 Lines := TStringList.Create; 290 try 291 Lines.Text := Text; 292 for I := 0 to Lines.Count - 1 do begin 293 if I = 0 then begin 294 Columns.StrictDelimiter := True; 295 Columns.DelimitedText := Trim(Lines[I]); 296 end else begin 297 Row := TRow.Create; 298 Row.Cells.StrictDelimiter := True; 299 Row.Cells.DelimitedText := Trim(Lines[I]); 300 Rows.Add(Row); 301 end; 302 end; 303 finally 304 FreeAndNil(Lines); 305 end; 285 306 end; 286 307 … … 296 317 297 318 procedure TTable.SetInputMediaWiki(Text: string); 298 begin 299 319 var 320 Lines: TStringList; 321 I: Integer; 322 Line: string; 323 InsideTable: Boolean; 324 Index: Integer; 325 Row: TRow; 326 begin 327 Clear; 328 Lines := TStringList.Create; 329 try 330 Lines.Text := Text; 331 Row := nil; 332 InsideTable := False; 333 for I := 0 to Lines.Count - 1 do begin 334 Line := Trim(Lines[I]); 335 if not InsideTable then begin 336 if Line.StartsWith('{|') then InsideTable := True; 337 end else begin 338 if Line.StartsWith('|}') then InsideTable := False 339 else 340 if Line.StartsWith('!') then begin 341 Delete(Line, 1, 1); 342 Line := Trim(Line); 343 repeat 344 Index := Pos('!!', Line); 345 if Index > 0 then begin 346 Columns.Add(Trim(Copy(Line, 1, Index - 1))); 347 Delete(Line, 1, Index + 1); 348 end else begin 349 Columns.Add(Trim(Line)); 350 Break; 351 end; 352 until False; 353 end else 354 if Line.StartsWith('|-') then begin 355 if Assigned(Row) then Rows.Add(Row); 356 Row := TRow.Create; 357 end else 358 if Line.StartsWith('|') then begin 359 if Assigned(Row) then begin 360 Delete(Line, 1, 1); 361 Line := Trim(Line); 362 repeat 363 Index := Pos('||', Line); 364 if Index > 0 then begin 365 Row.Cells.Add(Trim(Copy(Line, 1, Index - 1))); 366 Delete(Line, 1, Index + 1); 367 end else begin 368 Row.Cells.Add(Trim(Line)); 369 Break; 370 end; 371 until False; 372 373 while Row.Cells.Count < Columns.Count do 374 Row.Cells.Add(''); 375 end; 376 end; 377 end; 378 end; 379 if Assigned(Row) then 380 Rows.Add(Row); 381 finally 382 FreeAndNil(Lines); 383 end; 300 384 end; 301 385 -
trunk/Packages/VCard/VCard.pas
r152 r168 4 4 5 5 uses 6 Classes, SysUtils, Dialogs, LazUTF8, Base64, Graphics, Common, 6 Classes, SysUtils, Dialogs, LazUTF8, Base64, Graphics, Common, Table, 7 7 Generics.Collections, Generics.Defaults, ListViewSort; 8 8 … … 109 109 function GetBySysNameGroups(SysName: string; Groups: TStringArray): TContactField; 110 110 function GetByIndex(Index: TContactFieldIndex): TContactField; 111 function GetByTitle(Title: string): TContactField; 111 112 procedure LoadToStrings(AItems: TStrings); 112 113 end; … … 235 236 procedure SaveToFile(FileName: string); 236 237 procedure LoadFromFile(FileName: string); 238 procedure ExportToStrings(Lines: TStrings; Format: TTableFormat; HumanReadableHeader: Boolean); 239 procedure ImportFromStrings(Lines: TStrings; Format: TTableFormat; HumanReadableHeader: Boolean); 240 procedure ExportToFile(FileName: string; Format: TTableFormat; HumanReadableHeader: Boolean); 241 procedure ImportFromFile(FileName: string; Format: TTableFormat; HumanReadableHeader: Boolean); 242 procedure ExportToTable(Table: TTable; HumanReadableHeader: Boolean); 243 procedure ImportFromTable(Table: TTable; HumanReadableHeader: Boolean); 237 244 constructor Create(AOwner: TComponent); override; 238 245 destructor Destroy; override; … … 642 649 end; 643 650 651 procedure TVCard.ExportToStrings(Lines: TStrings; Format: TTableFormat; 652 HumanReadableHeader: Boolean); 653 var 654 Table: TTable; 655 begin 656 Table := TTable.Create; 657 try 658 ExportToTable(Table, HumanReadableHeader); 659 Lines.Text := Table.GetOutput(Format); 660 finally 661 FreeAndNil(Table); 662 end; 663 end; 664 665 procedure TVCard.ImportFromStrings(Lines: TStrings; Format: TTableFormat; 666 HumanReadableHeader: Boolean); 667 var 668 Table: TTable; 669 begin 670 Table := TTable.Create; 671 try 672 Table.SetInput(Format, Lines.Text); 673 ImportFromTable(Table, HumanReadableHeader); 674 finally 675 FreeAndNil(Table); 676 end; 677 end; 678 679 procedure TVCard.ExportToFile(FileName: string; Format: TTableFormat; 680 HumanReadableHeader: Boolean); 681 var 682 Lines: TStringList; 683 begin 684 Lines := TStringList.Create; 685 try 686 ExportToStrings(Lines, Format, HumanReadableHeader); 687 Lines.SaveToFile(FileName); 688 finally 689 Lines.Free; 690 end 691 end; 692 693 procedure TVCard.ImportFromFile(FileName: string; Format: TTableFormat; 694 HumanReadableHeader: Boolean); 695 var 696 Lines: TStringList; 697 begin 698 Lines := TStringList.Create; 699 Lines.LoadFromFile(FileName); 700 {$IF FPC_FULLVERSION>=30200} 701 if (Length(Lines.Text) > 0) and (Pos(VCardBegin, Lines.Text) = 0) then begin 702 Lines.LoadFromFile(FileName, TEncoding.Unicode); 703 if (Length(Lines.Text) > 0) and (Pos(VCardBegin, Lines.Text) = 0) then begin 704 Lines.LoadFromFile(FileName, TEncoding.BigEndianUnicode); 705 end; 706 end; 707 {$ENDIF} 708 try 709 ImportFromStrings(Lines, Format, HumanReadableHeader); 710 finally 711 Lines.Free; 712 end; 713 end; 714 715 procedure TVCard.ExportToTable(Table: TTable; HumanReadableHeader: Boolean); 716 var 717 Row: TRow; 718 I: Integer; 719 J: Integer; 720 Values: TStringList; 721 Index: Integer; 722 Fields: TContactFields; 723 Field: TContactField; 724 Columns: TStringList; 725 begin 726 Table.Clear; 727 728 Values := TStringList.Create; 729 Columns := TStringList.Create; 730 try 731 // Get all properties types 732 for I := 0 to Contacts.Count - 1 do begin 733 for J := 0 to Contacts[I].Properties.Count - 1 do 734 if not Contacts[I].Properties[J].Name.StartsWith('PHOTO') and 735 (Table.Columns.IndexOf(Contacts[I].Properties[J].Name) = -1) then begin 736 Table.Columns.Add(Contacts[I].Properties[J].Name); 737 Columns.Add(Contacts[I].Properties[J].Name); 738 end; 739 end; 740 741 if HumanReadableHeader then begin 742 Fields := TContact.GetFields; 743 for I := 0 to Table.Columns.Count - 1 do begin 744 Field := Fields.GetBySysName(Table.Columns[I]); 745 if Assigned(Field) then Table.Columns[I] := Field.Title; 746 end; 747 end; 748 749 for I := 0 to Contacts.Count - 1 do begin 750 Values.Clear; 751 for J := 0 to Columns.Count - 1 do 752 Values.Add(''); 753 for J := 0 to Contacts[I].Properties.Count - 1 do begin 754 Index := Columns.IndexOf(Contacts[I].Properties[J].Name); 755 if Index <> -1 then 756 Values[Index] := Contacts[I].Properties[J].Value; 757 end; 758 759 Row := Table.AddRow; 760 for J := 0 to Values.Count - 1 do 761 Row.Cells.Add(Values[J]); 762 end; 763 finally 764 Values.Free; 765 Columns.Free; 766 end; 767 end; 768 769 procedure TVCard.ImportFromTable(Table: TTable; HumanReadableHeader: Boolean); 770 var 771 Contact: TContact; 772 I: Integer; 773 J: Integer; 774 Fields: TContactFields; 775 Field: TContactField; 776 begin 777 if HumanReadableHeader then begin 778 Fields := TContact.GetFields; 779 for I := 0 to Table.Columns.Count - 1 do begin 780 Field := Fields.GetByTitle(Table.Columns[I]); 781 if Assigned(Field) then Table.Columns[I] := Field.SysName; 782 end; 783 end; 784 785 Contacts.Clear; 786 for I := 0 to Table.Rows.Count - 1 do begin 787 Contact := Contacts.AddNew; 788 for J := 0 to Table.Rows[I].Cells.Count - 1 do 789 Contact.Properties.AddNew(Table.Columns[J], Table.Rows[I].Cells[J]); 790 end; 791 end; 792 644 793 constructor TVCard.Create(AOwner: TComponent); 645 794 begin … … 1445 1594 else Result := nil; 1446 1595 end; 1596 end; 1597 1598 function TContactFields.GetByTitle(Title: string): TContactField; 1599 var 1600 I: Integer; 1601 begin 1602 I := 0; 1603 while (I < Count) and (Items[I].Title <> Title) do Inc(I); 1604 if I < Count then Result := Items[I] 1605 else Result := nil; 1447 1606 end; 1448 1607 -
trunk/Test.pas
r152 r168 4 4 5 5 uses 6 Classes, SysUtils, VCard, VCardProcessor, TestCase ;6 Classes, SysUtils, VCard, VCardProcessor, TestCase, Table; 7 7 8 8 type … … 40 40 end; 41 41 42 { TTestCaseVCardExportImport } 43 44 TTestCaseVCardExportImport = class(TTestCase) 45 Input: string; 46 Output: string; 47 Format: TTableFormat; 48 HumanReadableHeader: Boolean; 49 procedure Run; override; 50 end; 51 42 52 43 53 implementation … … 49 59 SExpected = 'Expected:'; 50 60 SOutput = 'Output:'; 61 SExport = 'Export:'; 62 63 { TTestCaseVCardExportImport } 64 65 procedure TTestCaseVCardExportImport.Run; 66 var 67 Lines: TStringList; 68 ExportedLines: TStringList; 69 begin 70 Lines := TStringList.Create; 71 ExportedLines := TStringList.Create; 72 try 73 with TVCardFile.Create(nil) do 74 try 75 Lines.Text := Input; 76 VCard.LoadFromStrings(Lines); 77 78 VCard.ExportToStrings(ExportedLines, Format, HumanReadableHeader); 79 VCard.Contacts.Clear; 80 VCard.ImportFromStrings(ExportedLines, Format, HumanReadableHeader); 81 82 Lines.Text := ''; 83 VCard.SaveToStrings(Lines); 84 Evaluate(Lines.Text = Output); 85 Log := SExpected + LineEnding + 86 '"' + Output + '"' + LineEnding + LineEnding + 87 SExport + LineEnding + 88 '"' + ExportedLines.Text + '"' + LineEnding + LineEnding + 89 SOutput + LineEnding + 90 '"' + Lines.Text + '"'; 91 finally 92 Free; 93 end; 94 finally 95 FreeAndNil(Lines); 96 FreeAndNil(ExportedLines); 97 end; 98 end; 51 99 52 100 { TTestCaseVCardProcessor } -
trunk/TestCases.pas
r152 r168 12 12 13 13 uses 14 VCard ;14 VCard, Table; 15 15 16 16 const … … 275 275 end; 276 276 277 with TTestCaseVCardExportImport(AddNew('Export/Import CSV', TTestCaseVCardExportImport)) do begin 278 Format := tfCsv; 279 HumanReadableHeader := False; 280 Input := BeginEnd( 281 'N:Surname;Name' + VCardLineEnding + 282 'FN:Name Surname' + VCardLineEnding) + 283 BeginEnd( 284 'N:Surname2;Name2' + VCardLineEnding + 285 'FN:Name2 Surname2' + VCardLineEnding); 286 Output := Input; 287 end; 288 with TTestCaseVCardExportImport(AddNew('Export/Import CSV human header', TTestCaseVCardExportImport)) do begin 289 Format := tfCsv; 290 HumanReadableHeader := True; 291 Input := BeginEnd( 292 'N:Surname;Name' + VCardLineEnding + 293 'FN:Name Surname' + VCardLineEnding) + 294 BeginEnd( 295 'N:Surname2;Name2' + VCardLineEnding + 296 'FN:Name2 Surname2' + VCardLineEnding); 297 Output := Input; 298 end; 299 with TTestCaseVCardExportImport(AddNew('Export/Import MediaWiki', TTestCaseVCardExportImport)) do begin 300 Format := tfMediaWiki; 301 HumanReadableHeader := False; 302 Input := BeginEnd( 303 'N:Surname;Name' + VCardLineEnding + 304 'FN:Name Surname' + VCardLineEnding) + 305 BeginEnd( 306 'N:Surname2;Name2' + VCardLineEnding + 307 'FN:Name2 Surname2' + VCardLineEnding); 308 Output := Input; 309 end; 310 277 311 with TTestCaseLoadSave(AddNew('Merge same cell phone', TTestCaseLoadSave)) do begin 278 312 Input := VCardBegin + MacLineEnding +
Note:
See TracChangeset
for help on using the changeset viewer.