diff --git a/Classes/Base.lproj/ContactDetailsView.xib b/Classes/Base.lproj/ContactDetailsView.xib index e2b413c1d..6e6060525 100644 --- a/Classes/Base.lproj/ContactDetailsView.xib +++ b/Classes/Base.lproj/ContactDetailsView.xib @@ -1,9 +1,9 @@ - + - + @@ -19,6 +19,7 @@ + @@ -122,8 +123,15 @@ + - + diff --git a/Classes/Contact.h b/Classes/Contact.h index 2cb44a5e2..46e664337 100644 --- a/Classes/Contact.h +++ b/Classes/Contact.h @@ -31,6 +31,7 @@ @property(nonatomic, retain) NSString *identifier; @property(nonatomic, retain) NSString *firstName; @property(nonatomic, retain) NSString *lastName; +@property(nonatomic, retain) NSString *organizationName; @property(nonatomic, retain) NSString *displayName; @property(nonatomic, strong) NSMutableArray *sipAddresses; @property(nonatomic, strong) NSMutableArray *emails; diff --git a/Classes/Contact.m b/Classes/Contact.m index 204df42db..19f021d20 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -44,6 +44,7 @@ _identifier = _person.identifier; _firstName = _person.givenName; _lastName = _person.familyName; + _organizationName = _person.organizationName; _displayName = [NSString stringWithFormat:@"%@ %@", _firstName, _lastName]; for (CNLabeledValue *phoneNumber in _person.phoneNumbers) { [_phones addObject:phoneNumber.value.stringValue]; @@ -84,6 +85,9 @@ for (NSString *phone in _phones) { linphone_friend_add_phone_number(_friend, phone.UTF8String); } + if (_organizationName) { + linphone_friend_set_organization(_friend, [_organizationName UTF8String]); + } if (_friend) { linphone_friend_enable_subscribes(_friend, FALSE); linphone_friend_set_inc_subscribe_policy(_friend, LinphoneSPDeny); diff --git a/Classes/ContactDetailsTableView.h b/Classes/ContactDetailsTableView.h index 28bfd13a1..38ab1c19a 100644 --- a/Classes/ContactDetailsTableView.h +++ b/Classes/ContactDetailsTableView.h @@ -27,6 +27,7 @@ typedef enum _ContactSections { ContactSections_None = 0, // first section is empty because we cannot set header for first section ContactSections_FirstName, ContactSections_LastName, + ContactSections_Organization, ContactSections_Sip, ContactSections_Number, ContactSections_Email, diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index 2556fbebc..15c0bb13e 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -139,7 +139,7 @@ } - (BOOL)isValid { - BOOL hasName = (_contact.firstName.length + _contact.lastName.length > 0); + BOOL hasName = (_contact.firstName.length + _contact.lastName.length + _contact.organizationName.length > 0); BOOL hasAddr = (_contact.phones.count + _contact.sipAddresses.count) > 0; return hasName && hasAddr; @@ -156,7 +156,7 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - if (section == ContactSections_FirstName || section == ContactSections_LastName) { + if (section == ContactSections_FirstName || section == ContactSections_LastName || section == ContactSections_Organization) { /*first and last name only when editting */ return (self.tableView.isEditing) ? 1 : 0; } else if (section == ContactSections_Sip) { @@ -192,6 +192,9 @@ } else if (indexPath.section == ContactSections_LastName) { value = _contact.lastName; [cell hideDeleteButton:YES]; + } else if (indexPath.section == ContactSections_Organization) { + value = _contact.organizationName; + [cell hideDeleteButton:YES]; } else if ([indexPath section] == ContactSections_Number) { value = _contact.phones[indexPath.row]; [cell.editTextfield setKeyboardType:UIKeyboardTypePhonePad]; @@ -279,6 +282,9 @@ } else if (section == ContactSections_LastName && self.tableView.isEditing) { text = NSLocalizedString(@"Last name", nil); canAddEntry = NO; + } else if (section == ContactSections_Organization && self.tableView.isEditing) { + text = NSLocalizedString(@"Organization", nil); + canAddEntry = NO; } else if ([self getSectionData:section].count > 0 || self.tableView.isEditing) { if (section == ContactSections_Number) { text = NSLocalizedString(@"Phone numbers", nil); @@ -358,7 +364,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0 || - (!self.tableView.isEditing && (section == ContactSections_FirstName || section == ContactSections_LastName))) { + (!self.tableView.isEditing && (section == ContactSections_FirstName || section == ContactSections_LastName || section == ContactSections_LastName))) { return 1e-5; } return [self tableView:tableView viewForHeaderInSection:section].frame.size.height; @@ -390,6 +396,9 @@ case ContactSections_LastName: _contact.lastName = value; break; + case ContactSections_Organization: + _contact.organizationName = value; + break; case ContactSections_Sip: [_contact setSipAddress:value atIndex:path.row]; value = _contact.sipAddresses[path.row]; // in case of reformatting diff --git a/Classes/ContactDetailsView.h b/Classes/ContactDetailsView.h index e546c1bee..cfa5bff21 100644 --- a/Classes/ContactDetailsView.h +++ b/Classes/ContactDetailsView.h @@ -37,6 +37,7 @@ @property(nonatomic, strong) IBOutlet UIButton *cancelButton; @property(weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage; @property(weak, nonatomic) IBOutlet UILabel *nameLabel; +@property(weak, nonatomic) IBOutlet UILabel *organizationLabel; @property(weak, nonatomic) IBOutlet UIToggleButton *deleteButton; @property(weak, nonatomic) IBOutlet UIScrollView *contentView; @property(weak, nonatomic) IBOutlet UILabel *emptyLabel; diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 7975b7e4c..9ab632e07 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -91,24 +91,25 @@ [PhoneMainView.instance popCurrentView]; return; } - PhoneMainView.instance.currentName = _contact.displayName; - _nameLabel.text = PhoneMainView.instance.currentName; - - // fix no sipaddresses in contact.friend - const MSList *sips = linphone_friend_get_addresses(_contact.friend); - while (sips) { - linphone_friend_remove_address(_contact.friend, sips->data); - sips = sips->next; - } - - for (NSString *sipAddr in _contact.sipAddresses) { - LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true); - if (addr) { - linphone_friend_add_address(_contact.friend, addr); - linphone_address_destroy(addr); - } - } - [LinphoneManager.instance.fastAddressBook saveContact:_contact]; + PhoneMainView.instance.currentName = _contact.displayName; + _nameLabel.text = PhoneMainView.instance.currentName; + _organizationLabel.text = _contact.organizationName; + + // fix no sipaddresses in contact.friend + const MSList *sips = linphone_friend_get_addresses(_contact.friend); + while (sips) { + linphone_friend_remove_address(_contact.friend, sips->data); + sips = sips->next; + } + + for (NSString *sipAddr in _contact.sipAddresses) { + LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true); + if (addr) { + linphone_friend_add_address(_contact.friend, addr); + linphone_address_destroy(addr); + } + } + [LinphoneManager.instance.fastAddressBook saveContact:_contact]; } - (void)selectContact:(Contact *)acontact andReload:(BOOL)reload { @@ -124,6 +125,7 @@ [_avatarImage setImage:[FastAddressBook imageForContact:_contact] bordered:NO withRoundedRadius:YES]; [ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact]; + _organizationLabel.text = _contact.organizationName; [_tableController setContact:_contact]; if (reload) { @@ -319,6 +321,7 @@ _deleteButton.hidden = TRUE; } _nameLabel.hidden = self.tableController.isEditing; + _organizationLabel.hidden = self.tableController.isEditing; [self updateBackOrCancelButton]; [self recomputeTableViewSize:self.tableController.isEditing]; } @@ -405,7 +408,9 @@ static UICompositeViewDescription *compositeDescription = nil; _cancelButton.hidden = !editing; _backButton.hidden = editing; _nameLabel.hidden = editing; + _organizationLabel.hidden = editing; [ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact]; + _organizationLabel.text = _contact.organizationName; [self recomputeTableViewSize:editing]; @@ -417,7 +422,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)recomputeTableViewSize:(BOOL)editing { CGRect frame = _tableController.tableView.frame; if ([self viewIsCurrentlyPortrait] && !editing) { - frame.origin.y = _nameLabel.frame.origin.y + _nameLabel.frame.size.height; + frame.origin.y = _organizationLabel.frame.origin.y + _organizationLabel.frame.size.height; } else { frame.origin.y = _avatarImage.frame.size.height + _avatarImage.frame.origin.y; } diff --git a/Classes/LinphoneUI/Base.lproj/UIContactCell.xib b/Classes/LinphoneUI/Base.lproj/UIContactCell.xib index 7b39d696e..b4710cafe 100644 --- a/Classes/LinphoneUI/Base.lproj/UIContactCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIContactCell.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -14,37 +12,47 @@ + - + - - + + - + - - + + diff --git a/Classes/LinphoneUI/UIContactCell.h b/Classes/LinphoneUI/UIContactCell.h index 5a5a095d8..b35913dbc 100644 --- a/Classes/LinphoneUI/UIContactCell.h +++ b/Classes/LinphoneUI/UIContactCell.h @@ -24,6 +24,7 @@ @interface UIContactCell : UITableViewCell @property(nonatomic, strong) IBOutlet UILabel *nameLabel; +@property(nonatomic, strong) IBOutlet UILabel *organizationLabel; @property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage; @property(weak, nonatomic) IBOutlet UIImageView *linphoneImage; @property(nonatomic, assign) Contact *contact; diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index c73937e6e..cf960b591 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -79,6 +79,7 @@ _linphoneImage.hidden = TRUE; if(_contact) { [ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact]; + _organizationLabel.text = [FastAddressBook ogrganizationForContact:_contact]; _linphoneImage.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"hide_linphone_contacts" inSection:@"app"] || ! ((_contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(_contact.friend)) == LinphonePresenceBasicStatusOpen) || [FastAddressBook contactHasValidSipDomain:_contact]); } diff --git a/Classes/Utils/FastAddressBook.h b/Classes/Utils/FastAddressBook.h index f960b1e65..a51d824ae 100644 --- a/Classes/Utils/FastAddressBook.h +++ b/Classes/Utils/FastAddressBook.h @@ -55,6 +55,7 @@ + (BOOL)isSipURIValid:(NSString*)addr; + (NSString *)displayNameForContact:(Contact *)person; ++ (NSString *)ogrganizationForContact:(Contact *)person; + (NSString *)displayNameForAddress:(const LinphoneAddress *)addr; + (BOOL)isSipURI:(NSString *)address; diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index c0339e9dd..5b2be7d05 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -338,6 +338,9 @@ + (NSString *)displayNameForContact:(Contact *)contact { return contact.displayName; } ++ (NSString *)ogrganizationForContact:(Contact *)contact { + return contact.organizationName; +} + (NSString *)displayNameForAddress:(const LinphoneAddress *)addr { Contact *contact = [FastAddressBook getContactWithAddress:addr]; @@ -365,7 +368,7 @@ CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey, CNContactIdentifierKey, CNContactInstantMessageAddressesKey, - CNInstantMessageAddressUsernameKey, CNContactImageDataKey + CNInstantMessageAddressUsernameKey, CNContactImageDataKey, CNContactOrganizationNameKey ]; CNMutableContact *mCNContact = [[store unifiedContactWithIdentifier:acontact.identifier @@ -450,42 +453,42 @@ } - (BOOL)saveCNContact:(CNContact *)cNContact contact:(Contact *)contact { - CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init]; - NSArray *keysToFetch = @[ - CNContactEmailAddressesKey, CNContactPhoneNumbersKey, - CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey, - CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey, - CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey - ]; - CNMutableContact *mCNContact = - [[store unifiedContactWithIdentifier:contact.identifier - keysToFetch:keysToFetch - error:nil] mutableCopy]; + CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init]; + NSArray *keysToFetch = @[ + CNContactEmailAddressesKey, CNContactPhoneNumbersKey, + CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey, + CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey, + CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey, CNContactOrganizationNameKey + ]; + CNMutableContact *mCNContact = + [[store unifiedContactWithIdentifier:contact.identifier + keysToFetch:keysToFetch + error:nil] mutableCopy]; if(mCNContact == NULL){ [saveRequest addContact:[cNContact mutableCopy] toContainerWithIdentifier:nil]; }else{ - [mCNContact setGivenName:contact.firstName]; - [mCNContact setFamilyName:contact.lastName]; - [mCNContact setNickname:contact.displayName]; - [mCNContact setPhoneNumbers:contact.person.phoneNumbers]; - [mCNContact setEmailAddresses:contact.person.emailAddresses]; - [mCNContact - setInstantMessageAddresses:contact.person.instantMessageAddresses]; - [mCNContact setImageData:UIImageJPEGRepresentation(contact.avatar, 0.9f)]; - - [saveRequest updateContact:mCNContact]; + [mCNContact setGivenName:contact.firstName]; + [mCNContact setFamilyName:contact.lastName]; + [mCNContact setNickname:contact.displayName]; + [mCNContact setOrganizationName:contact.organizationName]; + [mCNContact setPhoneNumbers:contact.person.phoneNumbers]; + [mCNContact setEmailAddresses:contact.person.emailAddresses]; + [mCNContact setInstantMessageAddresses:contact.person.instantMessageAddresses]; + [mCNContact setImageData:UIImageJPEGRepresentation(contact.avatar, 0.9f)]; + + [saveRequest updateContact:mCNContact]; + } + NSError *saveError; + @try { + [self updateFriend:contact]; + [LinphoneManager.instance setContactsUpdated:TRUE]; + NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:&saveError]); + } @catch (NSException *exception) { + NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@", [exception description]); + return FALSE; } - NSError *saveError; - @try { - [self updateFriend:contact]; - [LinphoneManager.instance setContactsUpdated:TRUE]; - NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:&saveError]); - } @catch (NSException *exception) { - NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@", [exception description]); - return FALSE; - } [self fetchContactsInBackGroundThread]; - return TRUE; + return TRUE; } -(void)updateFriend:(Contact*) contact{ diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings index 488bda1dd..fb8f4da1d 100644 Binary files a/Resources/en.lproj/Localizable.strings and b/Resources/en.lproj/Localizable.strings differ diff --git a/Resources/fr.lproj/Localizable.strings b/Resources/fr.lproj/Localizable.strings index 791066e50..558d5482a 100644 Binary files a/Resources/fr.lproj/Localizable.strings and b/Resources/fr.lproj/Localizable.strings differ