From 40b735ef5acf37363402c7228a95309b3a9d6fc6 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 16 Sep 2012 11:02:17 +0200 Subject: [PATCH 1/2] change default values for video policiy. --- Resources/linphonerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Resources/linphonerc b/Resources/linphonerc index 5057f2f02..d5d14881f 100644 --- a/Resources/linphonerc +++ b/Resources/linphonerc @@ -17,7 +17,8 @@ show_local=0 enabled=1 size=qvga display_filter_auto_rotate=1 - +automatically_initiate=0 +automatically_accept=0 [default_values] From 93e61518b5c1b1b377a65ac7d33f0a8653b3e349 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Mon, 17 Sep 2012 09:48:27 +0200 Subject: [PATCH 2/2] Factorize ImagePicker code --- Classes/ChatRoomViewController.h | 3 +- Classes/ChatRoomViewController.m | 79 +++++-------------- ...ntroller.h => ImagePickerViewController.h} | 10 ++- ...ntroller.m => ImagePickerViewController.m} | 32 ++++++-- Classes/ImageViewController.m | 2 + Classes/LinphoneUI/UIContactDetailsHeader.h | 4 +- Classes/LinphoneUI/UIContactDetailsHeader.m | 23 ++++-- Classes/PhoneMainView.h | 2 +- linphone.xcodeproj/project.pbxproj | 16 ++-- 9 files changed, 82 insertions(+), 89 deletions(-) rename Classes/{ContactDetailsImagePickerController.h => ImagePickerViewController.h} (69%) rename Classes/{ContactDetailsImagePickerController.m => ImagePickerViewController.m} (67%) diff --git a/Classes/ChatRoomViewController.h b/Classes/ChatRoomViewController.h index 282d2087e..47f44bfc5 100644 --- a/Classes/ChatRoomViewController.h +++ b/Classes/ChatRoomViewController.h @@ -24,10 +24,11 @@ #import "ChatRoomTableViewController.h" #import "HPGrowingTextView.h" #import "ChatModel.h" +#import "ImagePickerViewController.h" #include "linphonecore.h" -@interface ChatRoomViewController : UIViewController { +@interface ChatRoomViewController : UIViewController { @private LinphoneChatRoom *chatRoom; NSURLConnection* uploadContext; diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index 746adb0c3..e72461314 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -19,10 +19,12 @@ #import "ChatRoomViewController.h" #import "PhoneMainView.h" +#import "DTActionSheet.h" + #import #import #import -#import "DTActionSheet.h" + @implementation ChatRoomViewController @@ -411,45 +413,24 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta - (IBAction)onPictureClick:(id)event { [messageField resignFirstResponder]; - DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select picture source",nil)] autorelease]; - if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { - [sheet addButtonWithTitle:NSLocalizedString(@"Camera",nil) block:^(){ - UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; - mediaUI.sourceType = UIImagePickerControllerSourceTypeCamera; + [ImagePickerViewController promptSelectSource:^(UIImagePickerControllerSourceType type) { + UICompositeViewDescription *description = [[[ImagePickerViewController compositeViewDescription] copy] autorelease]; + description.tabBar = nil; // Disable default tarbar + description.tabBarEnabled = false; + ImagePickerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:description push:TRUE], ImagePickerViewController); + if(controller != nil) { + controller.sourceType = type; // Displays a control that allows the user to choose picture or // movie capture, if both are available: - mediaUI.mediaTypes = - [UIImagePickerController availableMediaTypesForSourceType: - UIImagePickerControllerSourceTypeCamera]; + controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:type]; // Hides the controls for moving & scaling pictures, or for // trimming movies. To instead show the controls, use YES. - mediaUI.allowsEditing = NO; - mediaUI.delegate = self; - [self presentModalViewController: mediaUI animated: YES]; - }]; - } - if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { - [sheet addButtonWithTitle:NSLocalizedString(@"Photo library",nil) block:^(){ - UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; - mediaUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; - - // Displays saved pictures and movies, if both are available, from the - // Camera Roll album. - mediaUI.mediaTypes = - [UIImagePickerController availableMediaTypesForSourceType: - UIImagePickerControllerSourceTypePhotoLibrary]; - - // Hides the controls for moving & scaling pictures, or for - // trimming movies. To instead show the controls, use YES. - mediaUI.allowsEditing = NO; - mediaUI.delegate = self; - [self presentModalViewController: mediaUI animated: YES]; - }]; - } - [sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel",nil)]; - [sheet showInView:self.view]; + controller.allowsEditing = NO; + controller.imagePickerDelegate = self; + } + }]; } - (IBAction)onTransferCancelClick:(id)event { @@ -663,36 +644,16 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta return [NSURLConnection connectionWithRequest:(NSURLRequest *)request delegate:self]; } -#pragma mark UIImagePickerControllerDelegate -- (void)imagePickerControllerDidCancel:(UIImagePickerController *) picker { - [self dismissModalViewControllerAnimated: YES]; - [picker release]; -} +#pragma mark ImpagePickerDelegate -- (void)imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info { - NSURL *imageURL = [info valueForKey: UIImagePickerControllerReferenceURL]; - UIImage* imageToUse = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage]; - NSString* imageName; - if (imageURL) { - // extract id from asset-url ex: assets-library://asset/asset.JPG?id=1645156-6151-1513&ext=JPG - NSArray *parameters = [[imageURL query] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"=&"]]; - for (int i = 0; i < [parameters count]; i=i+2) { - if ([(NSString*)[parameters objectAtIndex:i] isEqualToString:@"id"]) { - imageName=[NSString stringWithFormat:@"%@.jpg",(NSString*)[parameters objectAtIndex:i+1]]; - } - } - } else { - // must be "unique" - imageName=[NSString stringWithFormat:@"%i.jpg",[imageToUse hash]]; - } - uploadContext = [self uploadImage:imageToUse Named: imageName]; +- (void)imagePickerDelegateImage:(UIImage*)image { + NSString *imageName = [NSString stringWithFormat:@"%i.jpg", [image hash]]; + uploadContext = [self uploadImage:image Named: imageName]; [self startUpload]; - - [picker.presentingViewController dismissModalViewControllerAnimated: YES]; - [picker release]; } + #pragma mark - Keyboard Event Functions - (void)keyboardWillHide:(NSNotification *)notif { diff --git a/Classes/ContactDetailsImagePickerController.h b/Classes/ImagePickerViewController.h similarity index 69% rename from Classes/ContactDetailsImagePickerController.h rename to Classes/ImagePickerViewController.h index 3e0fcff72..91eb9c07d 100644 --- a/Classes/ContactDetailsImagePickerController.h +++ b/Classes/ImagePickerViewController.h @@ -19,15 +19,17 @@ #import "UICompositeViewController.h" -@protocol ContactDetailsImagePickerDelegate +@protocol ImagePickerDelegate -- (void)changeContactImage:(UIImage*)image; +- (void)imagePickerDelegateImage:(UIImage*)image; @end -@interface ContactDetailsImagePickerController : UIImagePickerController { +@interface ImagePickerViewController : UIImagePickerController { } -@property (nonatomic, retain) id imagePickerDelegate; +@property (nonatomic, retain) id imagePickerDelegate; + ++ (void)promptSelectSource:(void (^)(UIImagePickerControllerSourceType))block; @end diff --git a/Classes/ContactDetailsImagePickerController.m b/Classes/ImagePickerViewController.m similarity index 67% rename from Classes/ContactDetailsImagePickerController.m rename to Classes/ImagePickerViewController.m index 0b68fcf1b..dad0a57a1 100644 --- a/Classes/ContactDetailsImagePickerController.m +++ b/Classes/ImagePickerViewController.m @@ -17,10 +17,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#import "ContactDetailsImagePickerController.h" +#import "ImagePickerViewController.h" #import "PhoneMainView.h" +#import "DTActionSheet.h" -@implementation ContactDetailsImagePickerController +@implementation ImagePickerViewController @synthesize imagePickerDelegate; @@ -31,8 +32,8 @@ static UICompositeViewDescription *compositeDescription = nil; + (UICompositeViewDescription *)compositeViewDescription { if(compositeDescription == nil) { - compositeDescription = [[UICompositeViewDescription alloc] init:@"ContactDetailsImage" - content:@"ContactDetailsImagePickerController" + compositeDescription = [[UICompositeViewDescription alloc] init:@"ImagePicker" + content:@"ImagePickerViewController" stateBar:nil stateBarEnabled:false tabBar:@"UIMainBar" @@ -56,11 +57,28 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - - (void)dismiss { - if([[[PhoneMainView instance] currentView] equal:[ContactDetailsImagePickerController compositeViewDescription]]) { + if([[[PhoneMainView instance] currentView] equal:[ImagePickerViewController compositeViewDescription]]) { [[PhoneMainView instance] popCurrentView]; } } ++ (void)promptSelectSource:(void (^)(UIImagePickerControllerSourceType))block { + DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select picture source",nil)] autorelease]; + if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { + [sheet addButtonWithTitle:NSLocalizedString(@"Camera",nil) block:^(){ + block(UIImagePickerControllerSourceTypeCamera); + }]; + } + if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { + [sheet addButtonWithTitle:NSLocalizedString(@"Photo library",nil) block:^(){ + block(UIImagePickerControllerSourceTypePhotoLibrary); + }]; + } + [sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel",nil)]; + + [sheet showInView:[PhoneMainView instance].view]; +} + #pragma mark - UIImagePickerControllerDelegate Functions @@ -69,8 +87,8 @@ static UICompositeViewDescription *compositeDescription = nil; if(image == nil) { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } - if(image != nil) { - [imagePickerDelegate changeContactImage:image]; + if(image != nil && imagePickerDelegate != nil) { + [imagePickerDelegate imagePickerDelegateImage:image]; } [self dismiss]; } diff --git a/Classes/ImageViewController.m b/Classes/ImageViewController.m index e71d91e89..225ca9a4f 100644 --- a/Classes/ImageViewController.m +++ b/Classes/ImageViewController.m @@ -30,6 +30,7 @@ @synthesize backButton; @synthesize image; + #pragma mark - UICompositeViewDelegate Functions static UICompositeViewDescription *compositeDescription = nil; @@ -49,6 +50,7 @@ static UICompositeViewDescription *compositeDescription = nil; return compositeDescription; } + #pragma mark - Property Functions - (void)setImage:(UIImage *)aimage { diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.h b/Classes/LinphoneUI/UIContactDetailsHeader.h index a9279f002..af82ed75a 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.h +++ b/Classes/LinphoneUI/UIContactDetailsHeader.h @@ -20,10 +20,10 @@ #import #import -#import "ContactDetailsImagePickerController.h" +#import "ImagePickerViewController.h" #import "ContactDetailsDelegate.h" -@interface UIContactDetailsHeader : UIViewController { +@interface UIContactDetailsHeader : UIViewController { @private NSArray *propertyList; BOOL editing; diff --git a/Classes/LinphoneUI/UIContactDetailsHeader.m b/Classes/LinphoneUI/UIContactDetailsHeader.m index 24221d60a..3a2544958 100644 --- a/Classes/LinphoneUI/UIContactDetailsHeader.m +++ b/Classes/LinphoneUI/UIContactDetailsHeader.m @@ -243,19 +243,28 @@ - (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]; - } + [ImagePickerViewController promptSelectSource:^(UIImagePickerControllerSourceType type) { + ImagePickerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ImagePickerViewController compositeViewDescription] push:TRUE], ImagePickerViewController); + if(controller != nil) { + controller.sourceType = type; + + // Displays a control that allows the user to choose picture or + // movie capture, if both are available: + controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:type]; + + // Hides the controls for moving & scaling pictures, or for + // trimming movies. To instead show the controls, use YES. + controller.allowsEditing = NO; + controller.imagePickerDelegate = self; + } + }]; } } #pragma mark - ContactDetailsImagePickerDelegate Functions -- (void)changeContactImage:(UIImage*)image { +- (void)imagePickerDelegateImage:(UIImage*)image { NSError* error = NULL; if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) { [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index e92f28834..f76e3cb6a 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -30,7 +30,7 @@ #import "ContactsViewController.h" #import "ContactDetailsViewController.h" #import "ContactDetailsLabelViewController.h" -#import "ContactDetailsImagePickerController.h" +#import "ImagePickerViewController.h" #import "HistoryViewController.h" #import "HistoryDetailsViewController.h" #import "InCallViewController.h" diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 15ef38c86..1906d3515 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -655,8 +655,8 @@ D377BBFA15A19DA6002B696B /* video_on_disabled.png in Resources */ = {isa = PBXBuildFile; fileRef = D377BBF915A19DA6002B696B /* video_on_disabled.png */; }; D378906515AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; }; D378906615AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */; }; - D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; }; - D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */; }; + D378AB2A15DCDB4A0098505D /* ImagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ImagePickerViewController.m */; }; + D378AB2B15DCDB4A0098505D /* ImagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D378AB2915DCDB490098505D /* ImagePickerViewController.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 */; }; @@ -1707,8 +1707,8 @@ D377BBF915A19DA6002B696B /* video_on_disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = video_on_disabled.png; path = Resources/video_on_disabled.png; sourceTree = ""; }; 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 = ""; }; - 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 = ""; }; + D378AB2815DCDB480098505D /* ImagePickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImagePickerViewController.h; sourceTree = ""; }; + D378AB2915DCDB490098505D /* ImagePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImagePickerViewController.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 = ""; }; @@ -2236,8 +2236,6 @@ 22E0A81F111C44E100B04932 /* ConsoleViewController.m */, 22E0A81E111C44E100B04932 /* ConsoleViewController.xib */, D30BBD1215D3EFEB000F93DD /* ContactDetailsDelegate.h */, - D378AB2815DCDB480098505D /* ContactDetailsImagePickerController.h */, - D378AB2915DCDB490098505D /* ContactDetailsImagePickerController.m */, D378906215AC373B00BD776C /* ContactDetailsLabelViewController.h */, D378906315AC373B00BD776C /* ContactDetailsLabelViewController.m */, D38187B815FE341B00C3EDCA /* ContactDetailsLabelViewController.xib */, @@ -2266,6 +2264,8 @@ D3ED3EB515873928006C0DE4 /* HistoryViewController.h */, D3ED3EB615873929006C0DE4 /* HistoryViewController.m */, D38187D415FE346B00C3EDCA /* HistoryViewController.xib */, + D378AB2815DCDB480098505D /* ImagePickerViewController.h */, + D378AB2915DCDB490098505D /* ImagePickerViewController.m */, 22405EFD1601C19000B92522 /* ImageViewController.h */, 22405EFE1601C19100B92522 /* ImageViewController.m */, D37EE11016035793003608A6 /* ImageViewController.xib */, @@ -4458,7 +4458,7 @@ D380800215C2894A005BE9BC /* IASKTextField.m in Sources */, D380800515C28A7A005BE9BC /* UILinphone.m in Sources */, D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, - D378AB2A15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */, + D378AB2A15DCDB4A0098505D /* ImagePickerViewController.m in Sources */, 22405F001601C19200B92522 /* ImageViewController.m in Sources */, D3ED40191602172200BF332B /* HPGrowingTextView.m in Sources */, D3ED401B1602172200BF332B /* HPTextViewInternal.m in Sources */, @@ -4552,7 +4552,7 @@ D380800315C2894A005BE9BC /* IASKTextField.m in Sources */, D380800615C28A7A005BE9BC /* UILinphone.m in Sources */, D380801415C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, - D378AB2B15DCDB4A0098505D /* ContactDetailsImagePickerController.m in Sources */, + D378AB2B15DCDB4A0098505D /* ImagePickerViewController.m in Sources */, 22405F011601C19200B92522 /* ImageViewController.m in Sources */, D3ED401A1602172200BF332B /* HPGrowingTextView.m in Sources */, D3ED401C1602172200BF332B /* HPTextViewInternal.m in Sources */,