Changeset 40 for trunk/UContact.pas
- Timestamp:
- Dec 1, 2021, 11:41:48 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r39 r40 16 16 17 17 TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTitleBefore, 18 cfTitleAfter, cfFullName, cfTelCell, cfTelHome, cfTelHome2, cfTelWork, cfTelVoip, 19 cfTelMain, cfEmail, cfTel, cfUid, cfUrlHome, cfUrlWork, 20 cfEmailHome, cfEmailInternet, cfNickName, cfNote, cfRole, cfTitle, 18 cfTitleAfter, cfFullName, 19 cfTel, cfTelCell, cfTelFax, cfTelPager, cfTelHome2, cfTelVoip, cfTelMain, 20 cfTelHome, cfTelCellHome, cfTelFaxHome, cfTelPagerHome, 21 cfTelWork, cfTelCellWork, cfTelFaxWork, cfTelPagerWork, 22 cfEmail, cfUid, cfUrl, cfUrlHome, cfUrlWork, 23 cfEmailHome, cfEmailWork, cfEmailInternet, cfNickName, cfNote, cfRole, cfTitle, 21 24 cfCategories, cfOrganization, cfDepartment, 22 25 cfHomeAddressStreet, cfHomeAddressStreetExtended, cfHomeAddressCity, cfHomeAddressCountry, … … 25 28 cfWorkAddressPostalCode, cfWorkAddressRegion, cfWorkAddressPostOfficeBox, 26 29 cfXTimesContacted, cfXLastTimeContacted, cfPhoto, cfXJabber, cfDayOfBirth, cfRevision, 27 cfVersion );30 cfVersion, cfAnniversary); 28 31 29 32 TContactField = class 30 33 SysName: string; 31 34 Groups: TStringArray; 35 NoGroups: TStringArray; 32 36 Title: string; 33 37 Index: TContactFieldIndex; … … 39 43 40 44 TContactFields = class(TFPGObjectList<TContactField>) 41 function AddNew(Name: string; Groups: array of string; Title: string; Index: TContactFieldIndex; DataType: 45 function AddNew(Name: string; Groups: array of string; NoGroups: array of string; 46 Title: string; Index: TContactFieldIndex; DataType: 42 47 TDataType; ValueIndex: Integer = -1): TContactField; 43 48 function GetByIndex(Index: TContactFieldIndex): TContactField; … … 55 60 procedure EvaluateAttributes; 56 61 function GetDecodedValue: string; 57 function MatchNameGroups(AName: string; Groups: TStringArray): Boolean; 62 function MatchNameGroups(AName: string; Groups: TStringArray; 63 NoGroups: TStringArray): Boolean; 58 64 procedure Assign(Source: TContactProperty); 59 65 constructor Create; … … 66 72 procedure AssignToList(List: TFPGObjectList<TObject>); 67 73 function GetByName(Name: string): TContactProperty; 68 function GetByNameGroups(Name: string; Groups: TStringArray): TContactProperty; 69 function GetByNameGroupsMultiple(Name: string; Groups: TStringArray): TContactProperties; 74 function GetByNameGroups(Name: string; Groups: TStringArray; 75 NoGroups: TStringArray): TContactProperty; 76 function GetByNameGroupsMultiple(Name: string; Groups: TStringArray; 77 NoGroups: TStringArray): TContactProperties; 70 78 end; 71 79 … … 126 134 resourcestring 127 135 SVCardFile = 'vCard file'; 128 SUnsupportedContactFieldsIndex = 'Unsupported contact field index';129 SUnknownCommand = 'Unknown command: %s';130 136 SFoundPropertiesBeforeBlockStart = 'Found properties before the start of block'; 131 137 SFoundBlockEndWithoutBlockStart = 'Found block end without block start'; … … 138 144 SFullName = 'Full Name'; 139 145 STelephone = 'Telephone'; 140 SCellPhone = 'Cell phone'; 146 SMobilePhone = 'Mobile phone'; 147 SPager = 'Pager'; 148 SFax = 'Fax'; 141 149 SHomePhone = 'Home phone'; 150 SHomeMobile = 'Home mobile'; 151 SHomeFax = 'Home fax'; 152 SHomePager = 'Home pager'; 153 SWorkPhone = 'Work phone'; 154 SWorkFax = 'Work fax'; 155 SWorkPager = 'Work pager'; 156 SWorkMobile = 'Work mobile'; 142 157 SHomePhone2 = 'Home phone 2'; 143 SWorkPhone = 'Work phone';144 158 SVoipPhone = 'VoIP phone'; 145 159 SMainPhone = 'Main phone'; 146 160 SEmail = 'E-mail'; 147 SHomeEmail = 'Home Email'; 148 SInternetEmail = 'Internet Email'; 149 SNickName = 'Nick Name'; 161 SHomeEmail = 'Home E-mail'; 162 SWorkEmail = 'Work E-mail'; 163 SInternetEmail = 'Internet E-mail'; 164 SNickName = 'Nick name'; 150 165 SNote = 'Note'; 151 166 SRole = 'Role'; … … 173 188 SJabber = 'Jabber'; 174 189 SDayOfBirth = 'Day of birth'; 190 SAnniversary = 'Anniversary'; 175 191 SRevision = 'Revision'; 176 192 SUniqueIdentifier = 'Unique identifier'; 193 SWebAddress = 'Web address'; 177 194 SWebAddressHome = 'Web address home'; 178 195 SWebAddressWork = 'Web address work'; … … 223 240 end; 224 241 225 function TContactProperties.GetByNameGroups(Name: string; Groups: TStringArray 226 ): TContactProperty;242 function TContactProperties.GetByNameGroups(Name: string; Groups: TStringArray; 243 NoGroups: TStringArray): TContactProperty; 227 244 var 228 245 I: Integer; 229 246 begin 230 247 I := 0; 231 while (I < Count) and not Items[I].MatchNameGroups(Name, Groups ) do Inc(I);248 while (I < Count) and not Items[I].MatchNameGroups(Name, Groups, NoGroups) do Inc(I); 232 249 if I < Count then Result := Items[I] 233 250 else Result := nil; … … 235 252 236 253 function TContactProperties.GetByNameGroupsMultiple(Name: string; 237 Groups: TStringArray ): TContactProperties;254 Groups: TStringArray; NoGroups: TStringArray): TContactProperties; 238 255 var 239 256 I: Integer; … … 241 258 Result := TContactProperties.Create(False); 242 259 for I := 0 to Count - 1 do 243 if Items[I].MatchNameGroups(Name, Groups ) then260 if Items[I].MatchNameGroups(Name, Groups, NoGroups) then 244 261 Result.Add(Items[I]); 245 262 end; … … 283 300 end; 284 301 285 function TContactProperty.MatchNameGroups(AName: string; Groups: TStringArray 286 ): Boolean; 287 var 288 I: Integer; 289 begin 302 function TContactProperty.MatchNameGroups(AName: string; Groups: TStringArray; 303 NoGroups: TStringArray): Boolean; 304 var 305 I: Integer; 306 Attr: string; 307 begin 308 Attr := Attributes.DelimitedText; 290 309 Result := Name = AName; 291 if Result then begin310 if Result and (Length(Groups) > 0) then begin 292 311 for I := 0 to Length(Groups) - 1 do 293 if Attributes.IndexOf(Groups[I]) = -1 then begin 312 if (Attributes.IndexOf(Groups[I]) = -1) and 313 (Attributes.IndexOf('TYPE=' + Groups[I]) = -1) then begin 314 Result := False; 315 Break; 316 end; 317 end; 318 if Result and (Length(NoGroups) > 0) then begin 319 for I := 0 to Length(NoGroups) - 1 do 320 if (Attributes.IndexOf(NoGroups[I]) <> -1) or 321 (Attributes.IndexOf('TYPE=' + NoGroups[I]) <> -1) then begin 294 322 Result := False; 295 323 Break; … … 368 396 { TContactFields } 369 397 370 function TContactFields.AddNew(Name: string; Groups: array of string; Title: string; Index: TContactFieldIndex; 398 function TContactFields.AddNew(Name: string; Groups: array of string; 399 NoGroups: array of string; Title: string; Index: TContactFieldIndex; 371 400 DataType: TDataType; ValueIndex: Integer = -1): TContactField; 372 401 var … … 378 407 for I := 0 to Length(Groups) - 1 do 379 408 Result.Groups[I] := Groups[I]; 409 SetLength(Result.NoGroups, Length(NoGroups)); 410 for I := 0 to Length(NoGroups) - 1 do 411 Result.NoGroups[I] := NoGroups[I]; 380 412 Result.Title := Title; 381 413 Result.Index := Index; … … 431 463 Field := Parent.Fields.GetByIndex(Index); 432 464 if Assigned(Field) then begin 433 Prop := Properties.GetByNameGroups(Field.SysName, Field.Groups );434 if not Assigned(Prop) then begin465 Prop := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups); 466 if (not Assigned(Prop)) and (AValue <> '') then begin 435 467 Prop := TContactProperty.Create; 436 468 Prop.Name := Field.SysName; … … 439 471 Properties.Add(Prop); 440 472 end; 441 if Field.ValueIndex <> -1 then begin 442 while Prop.Values.Count <= Field.ValueIndex do Prop.Values.Add(''); 443 Prop.Values.Strings[Field.ValueIndex] := AValue 444 end else Prop.Values.DelimitedText := AValue; 473 if Assigned(Prop) then begin 474 if Field.ValueIndex <> -1 then begin 475 // Extend subitems count 476 while Prop.Values.Count <= Field.ValueIndex do 477 Prop.Values.Add(''); 478 479 Prop.Values.Strings[Field.ValueIndex] := AValue; 480 end else Prop.Values.DelimitedText := AValue; 481 482 // Remove empty items 483 while (Prop.Values.Count > 0) and (Prop.Values.Strings[Prop.Values.Count - 1] = '') do 484 Prop.Values.Delete(Prop.Values.Count - 1); 485 486 // Remove if empty 487 if Prop.Values.Text = '' then begin 488 Properties.Remove(Prop); 489 end; 490 end; 445 491 end else raise Exception.Create(SFieldIndexNotDefined); 446 492 end; … … 453 499 Field := Parent.Fields.GetByIndex(Index); 454 500 if Assigned(Field) then begin 455 Result := Properties.GetByNameGroups(Field.SysName, Field.Groups );501 Result := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups); 456 502 end else raise Exception.Create(SFieldIndexNotDefined); 457 503 end; … … 501 547 begin 502 548 with Fields do begin 503 AddNew('N', [], SLastName, cfLastName, dtString, 0); 504 AddNew('N', [], SFirstName, cfFirstName, dtString, 1); 505 AddNew('N', [], SMiddleName, cfMiddleName, dtString, 2); 506 AddNew('N', [], STitleBefore, cfTitleBefore, dtString, 3); 507 AddNew('N', [], STitleAfter, cfTitleAfter, dtString, 4); 508 AddNew('FN', [], SFullName, cfFullName, dtString); 509 AddNew('TEL', [], STelephone, cfTel, dtString); 510 AddNew('TEL', ['CELL'], SCellPhone, cfTelCell, dtString); 511 AddNew('TEL', ['HOME'], SHomePhone, cfTelHome, dtString); 512 AddNew('TEL', ['HOME2'], SHomePhone2, cfTelHome2, dtString); 513 AddNew('TEL', ['WORK'], SWorkPhone, cfTelWork, dtString); 514 AddNew('TEL', ['VOIP'], SVoipPhone, cfTelVoip, dtString); 515 AddNew('TEL', ['MAIN'], SMainPhone, cfTelMain, dtString); 516 AddNew('EMAIL', [], SEmail, cfEmail, dtString); 517 AddNew('EMAIL', ['HOME'], SHomeEmail, cfEmailHome, dtString); 518 AddNew('EMAIL', ['INTERNET'], SInternetEmail, cfEmailInternet, dtString); 519 AddNew('NICKNAME', [], SNickName, cfNickName, dtString); 520 AddNew('NOTE', [], SNote, cfNote, dtString); 521 AddNew('ROLE', [], SRole, cfRole, dtString); 522 AddNew('TITLE', [], STitle, cfTitle, dtString); 523 AddNew('CATEGORIES', [], SCategories, cfCategories, dtString); 524 AddNew('ORG', [], SOrganization, cfOrganization, dtString, 0); 525 AddNew('ORG', [], SDepartement, cfDepartment, dtString, 1); 526 AddNew('ADR', ['HOME'], SHomeAddressPostOfficeBox, cfHomeAddressPostOfficeBox, dtString, 0); 527 AddNew('ADR', ['HOME'], SHomeAddressStreetExtended, cfHomeAddressStreetExtended, dtString, 1); 528 AddNew('ADR', ['HOME'], SHomeAddressStreet, cfHomeAddressStreet, dtString, 2); 529 AddNew('ADR', ['HOME'], SHomeAddressCity, cfHomeAddressCity, dtString, 3); 530 AddNew('ADR', ['HOME'], SHomeAddressRegion, cfHomeAddressRegion, dtString, 4); 531 AddNew('ADR', ['HOME'], SHomeAddressPostalCode, cfHomeAddressPostalCode, dtString, 5); 532 AddNew('ADR', ['HOME'], SHomeAddressCountry, cfHomeAddressCountry, dtString, 6); 533 AddNew('ADR', ['WORK'], SWorkAddressPostOfficeBox, cfWorkAddressPostOfficeBox, dtString, 0); 534 AddNew('ADR', ['WORK'], SWorkAddressStreetExtended, cfWorkAddressStreetExtended, dtString, 1); 535 AddNew('ADR', ['WORK'], SWorkAddressStreet, cfWorkAddressStreet, dtString, 2); 536 AddNew('ADR', ['WORK'], SWorkAddressCity, cfWorkAddressCity, dtString, 3); 537 AddNew('ADR', ['WORK'], SWorkAddressRegion, cfWorkAddressRegion, dtString, 4); 538 AddNew('ADR', ['WORK'], SWorkAddressPostalCode, cfWorkAddressPostalCode, dtString, 5); 539 AddNew('ADR', ['WORK'], SWorkAddressCountry, cfWorkAddressCountry, dtString, 6); 540 AddNew('X-TIMES_CONTACTED', [], STimesContacted, cfXTimesContacted, dtString); 541 AddNew('X-LAST_TIME_CONTACTED', [], SLastTimeContacted, cfXLastTimeContacted, dtString); 542 AddNew('PHOTO', [], SPhoto, cfPhoto, dtString); 543 AddNew('X-JABBER', [], SJabber, cfXJabber, dtString); 544 AddNew('BDAY', [], SDayOfBirth, cfDayOfBirth, dtString); 545 AddNew('REV', [], SRevision, cfRevision, dtString); 546 AddNew('UID', [], SUniqueIdentifier, cfUid, dtString); 547 AddNew('URL', ['HOME'], SWebAddressHome, cfUrlHome, dtString); 548 AddNew('URL', ['WORK'], SWebAddressWork, cfUrlWork, dtString); 549 AddNew('N', [], [], SLastName, cfLastName, dtString, 0); 550 AddNew('N', [], [], SFirstName, cfFirstName, dtString, 1); 551 AddNew('N', [], [], SMiddleName, cfMiddleName, dtString, 2); 552 AddNew('N', [], [], STitleBefore, cfTitleBefore, dtString, 3); 553 AddNew('N', [], [], STitleAfter, cfTitleAfter, dtString, 4); 554 AddNew('FN', [], [], SFullName, cfFullName, dtString); 555 AddNew('TEL', [], ['CELL', 'FAX', 'PAGER', 'WORK', 'HOME'], STelephone, cfTel, dtString); 556 AddNew('TEL', ['CELL'], ['WORK', 'HOME'], SMobilePhone, cfTelCell, dtString); 557 AddNew('TEL', ['FAX'], ['WORK', 'HOME'], SFax, cfTelFax, dtString); 558 AddNew('TEL', ['PAGER'], ['WORK', 'HOME'], SPager, cfTelPager, dtString); 559 AddNew('TEL', ['HOME'], ['CELL', 'FAX', 'PAGER'], SHomePhone, cfTelHome, dtString); 560 AddNew('TEL', ['HOME', 'CELL'], [], SHomeMobile, cfTelCellHome, dtString); 561 AddNew('TEL', ['HOME', 'FAX'], [], SHomeFax, cfTelFaxHome, dtString); 562 AddNew('TEL', ['HOME', 'PAGER'], [], SHomePager, cfTelPagerHome, dtString); 563 AddNew('TEL', ['WORK'], ['CELL', 'FAX', 'PAGER'], SWorkPhone, cfTelWork, dtString); 564 AddNew('TEL', ['WORK', 'CELL'], [], SWorkMobile, cfTelCellWork, dtString); 565 AddNew('TEL', ['WORK', 'FAX'], [], SWorkFax, cfTelFaxWork, dtString); 566 AddNew('TEL', ['WORK', 'PAGER'], [], SWorkPager, cfTelPagerWork, dtString); 567 AddNew('TEL', ['HOME2'], [], SHomePhone2, cfTelHome2, dtString); 568 AddNew('TEL', ['VOIP'], [], SVoipPhone, cfTelVoip, dtString); 569 AddNew('TEL', ['MAIN'], [], SMainPhone, cfTelMain, dtString); 570 AddNew('EMAIL', [], ['HOME', 'WORK', 'INTERNET'], SEmail, cfEmail, dtString); 571 AddNew('EMAIL', ['HOME'], [], SHomeEmail, cfEmailHome, dtString); 572 AddNew('EMAIL', ['WORK'], [], SWorkEmail, cfEmailWork, dtString); 573 AddNew('EMAIL', ['INTERNET'], [], SInternetEmail, cfEmailInternet, dtString); 574 AddNew('NICKNAME', [], [], SNickName, cfNickName, dtString); 575 AddNew('NOTE', [], [], SNote, cfNote, dtString); 576 AddNew('ROLE', [], [], SRole, cfRole, dtString); 577 AddNew('TITLE', [], [], STitle, cfTitle, dtString); 578 AddNew('CATEGORIES', [], [], SCategories, cfCategories, dtString); 579 AddNew('ORG', [], [], SOrganization, cfOrganization, dtString, 0); 580 AddNew('ORG', [], [], SDepartement, cfDepartment, dtString, 1); 581 AddNew('ADR', ['HOME'], [], SHomeAddressPostOfficeBox, cfHomeAddressPostOfficeBox, dtString, 0); 582 AddNew('ADR', ['HOME'], [], SHomeAddressStreetExtended, cfHomeAddressStreetExtended, dtString, 1); 583 AddNew('ADR', ['HOME'], [], SHomeAddressStreet, cfHomeAddressStreet, dtString, 2); 584 AddNew('ADR', ['HOME'], [], SHomeAddressCity, cfHomeAddressCity, dtString, 3); 585 AddNew('ADR', ['HOME'], [], SHomeAddressRegion, cfHomeAddressRegion, dtString, 4); 586 AddNew('ADR', ['HOME'], [], SHomeAddressPostalCode, cfHomeAddressPostalCode, dtString, 5); 587 AddNew('ADR', ['HOME'], [], SHomeAddressCountry, cfHomeAddressCountry, dtString, 6); 588 AddNew('ADR', ['WORK'], [], SWorkAddressPostOfficeBox, cfWorkAddressPostOfficeBox, dtString, 0); 589 AddNew('ADR', ['WORK'], [], SWorkAddressStreetExtended, cfWorkAddressStreetExtended, dtString, 1); 590 AddNew('ADR', ['WORK'], [], SWorkAddressStreet, cfWorkAddressStreet, dtString, 2); 591 AddNew('ADR', ['WORK'], [], SWorkAddressCity, cfWorkAddressCity, dtString, 3); 592 AddNew('ADR', ['WORK'], [], SWorkAddressRegion, cfWorkAddressRegion, dtString, 4); 593 AddNew('ADR', ['WORK'], [], SWorkAddressPostalCode, cfWorkAddressPostalCode, dtString, 5); 594 AddNew('ADR', ['WORK'], [], SWorkAddressCountry, cfWorkAddressCountry, dtString, 6); 595 AddNew('X-TIMES_CONTACTED', [], [], STimesContacted, cfXTimesContacted, dtString); 596 AddNew('X-LAST_TIME_CONTACTED', [], [], SLastTimeContacted, cfXLastTimeContacted, dtString); 597 AddNew('PHOTO', [], [], SPhoto, cfPhoto, dtString); 598 AddNew('X-JABBER', [], [], SJabber, cfXJabber, dtString); 599 AddNew('BDAY', [], [], SDayOfBirth, cfDayOfBirth, dtString); 600 AddNew('ANNIVERSARY', [], [], SAnniversary, cfAnniversary, dtString); 601 AddNew('REV', [], [], SRevision, cfRevision, dtString); 602 AddNew('UID', [], [], SUniqueIdentifier, cfUid, dtString); 603 AddNew('URL', [], ['HOME', 'WORK'], SWebAddress, cfUrl, dtString); 604 AddNew('URL', ['HOME'], [], SWebAddressHome, cfUrlHome, dtString); 605 AddNew('URL', ['WORK'], [], SWebAddressWork, cfUrlWork, dtString); 549 606 end; 550 607 end;
Note:
See TracChangeset
for help on using the changeset viewer.