diff --git a/Classes/ContactDetailsImagePickerController.h b/Classes/ContactDetailsImagePickerController.h new file mode 100644 index 000000000..eea057bf5 --- /dev/null +++ b/Classes/ContactDetailsImagePickerController.h @@ -0,0 +1,35 @@ +/* ContactDetailsImagePickerController.h + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "UICompositeViewController.h" + +@protocol ContactDetailsImagePickerDelegate + +- (void)changeContactImage:(UIImage*)image; + +@end + +@interface ContactDetailsImagePickerController : UIImagePickerController { +@private + id imagePickerDelegate; +} + +@property (nonatomic, retain) id imagePickerDelegate; + +@end diff --git a/Classes/ContactDetailsImagePickerController.m b/Classes/ContactDetailsImagePickerController.m new file mode 100644 index 000000000..3f321ce45 --- /dev/null +++ b/Classes/ContactDetailsImagePickerController.m @@ -0,0 +1,81 @@ +/* ContactDetailsImagePickerController.m + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "ContactDetailsImagePickerController.h" +#import "PhoneMainView.h" + +@implementation ContactDetailsImagePickerController + +@synthesize imagePickerDelegate; + +#pragma mark - UICompositeViewDelegate Functions + +static UICompositeViewDescription *compositeDescription = nil; + ++ (UICompositeViewDescription *)compositeViewDescription { + if(compositeDescription == nil) { + compositeDescription = [[UICompositeViewDescription alloc] init:@"ContactDetailsImage" + content:@"ContactDetailsImagePickerController" + stateBar:nil + stateBarEnabled:false + tabBar:@"UIMainBar" + tabBarEnabled:true + fullscreen:false + landscapeMode:[LinphoneManager runningOnIpad] + portraitMode:true]; + } + return compositeDescription; +} + + +#pragma mark - ViewController Functions + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setDelegate:self]; +} + + +#pragma mark - + +- (void)dismiss { + if([[[PhoneMainView instance] currentView] equal:[ContactDetailsImagePickerController compositeViewDescription]]) { + [[PhoneMainView instance] popCurrentView]; + } +} + + +#pragma mark - UIImagePickerControllerDelegate Functions + +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { + UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; + if(image == nil) { + image = [info objectForKey:UIImagePickerControllerOriginalImage]; + } + if(image != nil) { + [imagePickerDelegate changeContactImage:image]; + } + [self dismiss]; +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { + [self dismiss]; +} + +@end diff --git a/Classes/ContactDetailsLabelViewController.m b/Classes/ContactDetailsLabelViewController.m index be5a95f12..c63b70abf 100644 --- a/Classes/ContactDetailsLabelViewController.m +++ b/Classes/ContactDetailsLabelViewController.m @@ -64,7 +64,7 @@ static UICompositeViewDescription *compositeDescription = nil; tabBar:@"UIMainBar" tabBarEnabled:true fullscreen:false - landscapeMode:true + landscapeMode:[LinphoneManager runningOnIpad] portraitMode:true]; } return compositeDescription; @@ -79,6 +79,7 @@ static UICompositeViewDescription *compositeDescription = nil; } } + #pragma mark - Property Functions - (void)setDataList:(NSDictionary *)adatalist { diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index 580772ff8..f0cee1c8d 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -490,7 +490,7 @@ static const int contactSections[ContactSections_MAX] = {ContactSections_None, C } else { // Go to Chat room view [[PhoneMainView instance] popToView:[ChatViewController compositeViewDescription]]; - ChatRoomViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ChatRoomViewController compositeViewDescription] push:TRUE], ChatRoomViewController); + ChatRoomViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ChatRoomViewController compositeViewDescription]], ChatRoomViewController); if(controller != nil) { [controller setRemoteAddress:dest]; } diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.h b/Classes/LinphoneUI/UIContactDetailsHeader.h index 7e45e9514..79cb1dd1b 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.h +++ b/Classes/LinphoneUI/UIContactDetailsHeader.h @@ -20,9 +20,10 @@ #import #import +#import "ContactDetailsImagePickerController.h" #import "ContactDetailsDelegate.h" -@interface UIContactDetailsHeader : UIViewController { +@interface UIContactDetailsHeader : UIViewController { UILabel *addressLabel; UIImageView *avatarImage; UIView *normalView; @@ -45,7 +46,9 @@ @property (nonatomic, retain) IBOutlet UITableView *tableView; @property (nonatomic, retain) IBOutlet id contactDetailsDelegate; -@property(nonatomic,getter=isEditing) BOOL editing; +@property(nonatomic,getter=isEditing) BOOL editing; + +- (IBAction)onAvatarClick:(id)event; + (CGFloat)height:(BOOL)editing; diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.m b/Classes/LinphoneUI/UIContactDetailsHeader.m index 5e0de1c51..c7e0dce04 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.m +++ b/Classes/LinphoneUI/UIContactDetailsHeader.m @@ -22,6 +22,7 @@ #import "UIEditableTableViewCell.h" #import "FastAddressBook.h" #import "UILinphone.h" +#import "PhoneMainView.h" @implementation UIContactDetailsHeader @@ -231,6 +232,40 @@ } +#pragma mark - Action Functions + +- (IBAction)onAvatarClick:(id)event { + if(self.isEditing) { + ContactDetailsImagePickerController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ContactDetailsImagePickerController compositeViewDescription] push:TRUE], ContactDetailsImagePickerController); + if(controller != nil) { + [controller setAllowsEditing:TRUE]; + [controller setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; + [controller setImagePickerDelegate:self]; + } + } +} + + +#pragma mark - ContactDetailsImagePickerDelegate Functions + +- (void)changeContactImage:(UIImage*)image { + NSError* error = NULL; + if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) { + [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; + } + NSData *dataRef = UIImagePNGRepresentation(image); + CFDataRef cfdata = CFDataCreate(NULL,[dataRef bytes], [dataRef length]); + + if(!ABPersonSetImageData(contact, cfdata, (CFErrorRef*)error)) { + [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; + } + + CFRelease(cfdata); + + [self update]; +} + + #pragma mark - UITableViewDelegate Functions - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.xib b/Classes/LinphoneUI/UIContactDetailsHeader.xib index 2ad58ddc6..ee6cd04d7 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.xib +++ b/Classes/LinphoneUI/UIContactDetailsHeader.xib @@ -12,6 +12,7 @@ IBProxyObject + IBUIButton IBUIImageView IBUILabel IBUITableView @@ -58,7 +59,7 @@ {{20, 6}, {65, 65}} - + _NS:9 NO IBCocoaTouchFramework @@ -67,6 +68,40 @@ avatar_unknown_small.png + + + 292 + {{20, 6}, {65, 65}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + 290 @@ -277,6 +312,15 @@ AAgACAAIAAEAAQABAAE 19 + + + onAvatarClick: + + + 7 + + 23 + @@ -305,6 +349,7 @@ AAgACAAIAAEAAQABAAE + @@ -349,6 +394,12 @@ AAgACAAIAAEAAQABAAE + + 22 + + + avatarButton + @@ -359,6 +410,7 @@ AAgACAAIAAEAAQABAAE com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -368,13 +420,24 @@ AAgACAAIAAEAAQABAAE - 21 + 23 UIContactDetailsHeader UIViewController + + onImageClick: + id + + + onImageClick: + + onImageClick: + id + + UILabel UIImageView diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 6217ae92d..68e4bf9f2 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -29,6 +29,8 @@ #import "DialerViewController.h" #import "ContactsViewController.h" #import "ContactDetailsViewController.h" +#import "ContactDetailsLabelViewController.h" +#import "ContactDetailsImagePickerController.h" #import "HistoryViewController.h" #import "HistoryDetailsViewController.h" #import "InCallViewController.h" diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index d809609ee..7c435be7b 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -674,6 +674,8 @@ D378906515AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; }; D378906615AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; }; D378906715AC373B00BD776C /* ContactDetailsLabelViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */; }; + D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; }; + D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; }; D37B96B715A1A6F20005CCD2 /* call_state_delete_default.png in Resources */ = {isa = PBXBuildFile; fileRef = D37B96B515A1A6F20005CCD2 /* call_state_delete_default.png */; }; D37B96B915A1A6F20005CCD2 /* call_state_delete_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D37B96B615A1A6F20005CCD2 /* call_state_delete_over.png */; }; D37C638E15AAD251009D0BAC /* contact_number_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D37C638C15AAD251009D0BAC /* contact_number_over.png */; }; @@ -1674,6 +1676,8 @@ D378906215AC373B00BD776C /* ContactDetailsLabelViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsLabelViewController.h; sourceTree = ""; }; D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsLabelViewController.m; sourceTree = ""; }; D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContactDetailsLabelViewController.xib; sourceTree = ""; }; + D378AB2815DCDB480098505D /* ContactDetailsImagePickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsImagePickerController.h; sourceTree = ""; }; + D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsImagePickerController.m; sourceTree = ""; }; D37B96B515A1A6F20005CCD2 /* call_state_delete_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = call_state_delete_default.png; path = Resources/call_state_delete_default.png; sourceTree = ""; }; D37B96B615A1A6F20005CCD2 /* call_state_delete_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = call_state_delete_over.png; path = Resources/call_state_delete_over.png; sourceTree = ""; }; D37C638C15AAD251009D0BAC /* contact_number_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = contact_number_over.png; path = Resources/contact_number_over.png; sourceTree = ""; }; @@ -2152,6 +2156,8 @@ 22E0A81F111C44E100B04932 /* ConsoleViewController.m */, 22E0A81E111C44E100B04932 /* ConsoleViewController.xib */, D30BBD1215D3EFEB000F93DD /* ContactDetailsDelegate.h */, + D378AB2815DCDB480098505D /* ContactDetailsImagePickerController.h */, + D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */, D378906215AC373B00BD776C /* ContactDetailsLabelViewController.h */, D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */, D378906415AC373B00BD776C /* ContactDetailsLabelViewController.xib */, @@ -4312,6 +4318,7 @@ D380800215C2894A005BE9BC /* IASKTextField.m in Sources */, D380800515C28A7A005BE9BC /* UILinphone.m in Sources */, D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, + D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4401,6 +4408,7 @@ D380800315C2894A005BE9BC /* IASKTextField.m in Sources */, D380800615C28A7A005BE9BC /* UILinphone.m in Sources */, D380801415C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, + D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };