adium 2417:3853ea84d682: Update the window with the current uplo...

commits at adium.im commits at adium.im
Sun May 31 03:16:19 UTC 2009


details:	http://hg.adium.im/adium/rev/3853ea84d682
revision:	2417:3853ea84d682
author:		Zachary West <zacw at adium.im>
date:		Sat May 30 23:16:11 2009 -0400

Update the window with the current upload progress (X KB of X KB). Use a JPG if it's smaller, otherwise us a PNG. This helps us upload pictures as 300kb instead of, you know, 1.5mb.

diffs (200 lines):

diff -r 0eb4e7fbf3ba -r 3853ea84d682 Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.h
--- a/Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.h	Sat May 30 21:33:27 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.h	Sat May 30 23:16:11 2009 -0400
@@ -66,7 +66,7 @@
 @end
 
 @protocol AIProgressDataUploaderDelegate
-- (void)updateUploadPercent:(CGFloat)percent context:(id)context;
+- (void)updateUploadProgress:(NSUInteger)uploaded total:(NSUInteger)total context:(id)context;
 - (void)uploadCompleted:(id)context result:(NSData *)result;
 - (void)uploadFailed:(id)context;
 @end
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.m
--- a/Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.m	Sat May 30 21:33:27 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIProgressDataUploader.m	Sat May 30 23:16:11 2009 -0400
@@ -230,7 +230,8 @@
 	if (bytesWritten > bytesSent) {		
 		bytesSent = bytesWritten;
 
-		[delegate updateUploadPercent:(CGFloat)bytesSent/(CGFloat)totalSize
+		[delegate updateUploadProgress:bytesSent
+								 total:totalSize
 							  context:context];
 		
 		[timeoutTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:TIMEOUT_INTERVAL]];
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/AIImageUploaderPlugin.h
--- a/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.h	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.h	Sat May 30 23:16:11 2009 -0400
@@ -29,7 +29,7 @@
 
 - (void)errorWithMessage:(NSString *)message forChat:(AIChat *)chat;
 - (void)uploadedURL:(NSString *)url forChat:(AIChat *)chat;
-- (void)updateProgressPercent:(CGFloat)percent forChat:(AIChat *)chat;
+- (void)updateProgress:(NSUInteger)uploaded total:(NSUInteger)total forChat:(AIChat *)chat;
 - (void)cancelForChat:(AIChat *)chat;
 
 @end
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m
--- a/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m	Sat May 30 23:16:11 2009 -0400
@@ -273,13 +273,14 @@
 /*!
  * @brief Update the progress's percent
  *
- * @param percent The percent value, between 0.0-1.0, of the upload.
+ * @param uploaded The uploaded amount in bytes
+ * @param total The total amount in bytes
  * @param chat The AIChat for the upload
  */
-- (void)updateProgressPercent:(CGFloat)percent forChat:(AIChat *)chat
+- (void)updateProgress:(NSUInteger)uploaded total:(NSUInteger)total forChat:(AIChat *)chat;
 {
 	[[windowControllers objectForKey:chat.internalObjectID] setIndeterminate:NO];
-	[[windowControllers objectForKey:chat.internalObjectID] setProgress:percent];
+	[[windowControllers objectForKey:chat.internalObjectID] updateProgress:uploaded total:total];
 }
 
 /*!
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/AIImageUploaderWindowController.h
--- a/Plugins/Image Uploading Plugin/AIImageUploaderWindowController.h	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIImageUploaderWindowController.h	Sat May 30 23:16:11 2009 -0400
@@ -11,6 +11,7 @@
 
 @interface AIImageUploaderWindowController : AIWindowController {
 	IBOutlet NSTextField			*label_uploadingImage;
+	IBOutlet NSTextField			*label_uploadProgress;
 	IBOutlet NSProgressIndicator	*progressIndicator;
 	IBOutlet NSButton				*button_cancel;
 	
@@ -19,11 +20,11 @@
 }
 
 @property (nonatomic) BOOL indeterminate;
- at property (nonatomic) CGFloat progress;
 
 + (id)displayProgressInWindow:(NSWindow *)window
 					 delegate:(id)inDelegate
 						 chat:(AIChat *)inChat;
 - (IBAction)cancel:(id)sender;
+- (void)updateProgress:(NSUInteger)uploaded total:(NSUInteger)total;
 
 @end
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/AIImageUploaderWindowController.m
--- a/Plugins/Image Uploading Plugin/AIImageUploaderWindowController.m	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIImageUploaderWindowController.m	Sat May 30 23:16:11 2009 -0400
@@ -57,6 +57,7 @@
 {
 	[super windowDidLoad];
 	
+	[label_uploadProgress setLocalizedString:[AILocalizedString(@"Preparing", nil) stringByAppendingEllipsis]];
 	[label_uploadingImage setLocalizedString:[AILocalizedString(@"Uploading image to server", nil) stringByAppendingEllipsis]];
 	[button_cancel setLocalizedString:AILocalizedStringFromTable(@"Cancel", @"Buttons", nil)];
 }
@@ -82,14 +83,11 @@
 	[progressIndicator setIndeterminate:indeterminate];
 }
 
-- (CGFloat)progress
+- (void)updateProgress:(NSUInteger)uploaded total:(NSUInteger)total
 {
-	return progressIndicator.doubleValue;
-}
-
-- (void)setProgress:(CGFloat)percent
-{
-	[progressIndicator setDoubleValue:percent];
+	progressIndicator.doubleValue = (CGFloat)uploaded/(CGFloat)total;
+	
+	[label_uploadProgress setLocalizedString:[NSString stringWithFormat:AILocalizedString(@"%.1f KB of %.1f KB", nil), (CGFloat)uploaded/1024.0, (CGFloat)total/1024.0]];
 }
 
 @end
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/AIPicImImageUploader.m
--- a/Plugins/Image Uploading Plugin/AIPicImImageUploader.m	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIPicImImageUploader.m	Sat May 30 23:16:11 2009 -0400
@@ -64,9 +64,9 @@
 }
 
 #pragma mark Data uploader delegate
-- (void)updateUploadPercent:(CGFloat)percent context:(id)context
+- (void)updateUploadProgress:(NSUInteger)uploaded total:(NSUInteger)total context:(id)context
 {
-	[uploader updateProgressPercent:percent forChat:chat];
+	[uploader updateProgress:uploaded total:total forChat:chat];
 }
 
 - (void)uploadCompleted:(id)context result:(NSData *)result
@@ -89,7 +89,18 @@
 {
 	NSMutableData *body = [NSMutableData data];
 	
-	NSData *imageRepresentation = [image representationWithFileType:NSPNGFileType maximumFileSize:PIC_IM_MAX_SIZE];
+	NSBitmapImageFileType bestType;
+	
+	NSData *pngRepresentation = [[image largestBitmapImageRep] representationUsingType:NSPNGFileType properties:nil];
+	NSData *jpgRepresentation = [[image largestBitmapImageRep] representationUsingType:NSJPEGFileType properties:nil];
+
+	if (pngRepresentation.length > jpgRepresentation.length) {
+		bestType = NSJPEGFileType;
+	} else {
+		bestType = NSPNGFileType;
+	}
+	
+	NSData *imageRepresentation = [image representationWithFileType:bestType maximumFileSize:PIC_IM_MAX_SIZE];
 	
 	if (!imageRepresentation) {
 		[uploader errorWithMessage:AILocalizedString(@"Unable to upload", nil) forChat:chat];
@@ -98,7 +109,7 @@
 	
 	[body appendData:[[NSString stringWithFormat:@"--%@\r\n", MULTIPART_FORM_BOUNDARY] dataUsingEncoding:NSUTF8StringEncoding]];
 	[body appendData:[@"Content-Disposition: form-data; name=\"media\"; filename=\"image.png\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
-	[body appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
+	[body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", (bestType == NSJPEGFileType) ? @"image/jpeg" : @"image/png"] dataUsingEncoding:NSUTF8StringEncoding]];
 	[body appendData:imageRepresentation];
 	[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", MULTIPART_FORM_BOUNDARY] dataUsingEncoding:NSUTF8StringEncoding]];
 
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/ImageUploaderProgress.nib/classes.nib
--- a/Plugins/Image Uploading Plugin/ImageUploaderProgress.nib/classes.nib	Sat May 30 21:33:27 2009 -0400
+++ b/Plugins/Image Uploading Plugin/ImageUploaderProgress.nib/classes.nib	Sat May 30 23:16:11 2009 -0400
@@ -34,14 +34,6 @@
 			<string>NSControl</string>
 		</dict>
 		<dict>
-			<key>CLASS</key>
-			<string>RBSplitSubview</string>
-			<key>LANGUAGE</key>
-			<string>ObjC</string>
-			<key>SUPERCLASS</key>
-			<string>NSView</string>
-		</dict>
-		<dict>
 			<key>ACTIONS</key>
 			<dict>
 				<key>cancel</key>
@@ -57,6 +49,8 @@
 				<string>NSButton</string>
 				<key>delegate</key>
 				<string>id</string>
+				<key>label_uploadProgress</key>
+				<string>NSTextField</string>
 				<key>label_uploadingImage</key>
 				<string>NSTextField</string>
 				<key>progressIndicator</key>
@@ -67,6 +61,14 @@
 		</dict>
 		<dict>
 			<key>CLASS</key>
+			<string>RBSplitSubview</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSView</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
 			<string>NSMenu</string>
 			<key>LANGUAGE</key>
 			<string>ObjC</string>
diff -r 0eb4e7fbf3ba -r 3853ea84d682 Plugins/Image Uploading Plugin/ImageUploaderProgress.nib/keyedobjects.nib
Binary file Plugins/Image Uploading Plugin/ImageUploaderProgress.nib/keyedobjects.nib has changed




More information about the commits mailing list