GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: An iPhoto plugin to export photos to Gallery.
Homepage: http://zwily.com/iphoto
Clone URL: git://github.com/zwily/iphototogallery.git
fix bug where the ZSGalleryItem was being accessed after the autorelease 
pool it was in was released. whoops
zwily (author)
Mon Jun 19 22:51:03 -0700 2006
zwily (committer)
Sat May 03 09:01:47 -0700 2008
commit  8d972f68cd363191734f1b1a078029a0e0d023d9
tree    45109c4399767468bc680a1dc36e8fa482c31b73
parent  028134f407135b419659794af912df1bf2f616fb
...
933
934
935
936
 
 
937
938
 
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
968
969
970
971
972
973
 
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1010
1011
1012
1013
1014
1015
1016
 
1017
1018
1019
1020
1021
1022
1023
 
 
 
 
 
1024
1025
1026
1027
 
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
 
1041
1042
1043
...
933
934
935
 
936
937
938
 
939
940
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
 
 
 
989
 
990
991
992
993
994
995
996
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
 
 
 
 
 
 
1029
1030
 
 
 
 
 
 
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
 
 
 
 
 
 
 
 
 
 
 
 
1042
1043
1044
1045
0
@@ -933,111 +933,113 @@ static int loggingIn;
0
     ZWGalleryRemoteStatusCode status = 0;
0
     
0
     int imageNum;
0
- for (imageNum = 0; imageNum < (int)[exportManager imageCount]; imageNum++) {
0
+ BOOL cancel = NO;
0
+ for (imageNum = 0; imageNum < (int)[exportManager imageCount] && !cancel; imageNum++) {
0
         // Create our own pool so we don't use up tons of memory with autoreleased image data
0
- NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
0
+ NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init]; {
0
         
0
- NSString *imagePath = [exportManager imagePathAtIndex:imageNum];
0
- NSDictionary *imageDict = [self exportManagerImageDictionaryAtIndex:imageNum];
0
-
0
- ZWGalleryItem *item = [ZWGalleryItem itemWithAlbum:album];
0
-
0
- // add the filename
0
- [item setFilename:[imagePath lastPathComponent]];
0
-
0
- // add the image type (default to jpg)
0
- // TODO: Be smarter here. There are many more possible image types we need to handle.
0
- if ([[imagePath pathExtension] caseInsensitiveCompare:@"gif"] == NSOrderedSame)
0
- [item setImageType:@"image/gif"];
0
- else if ([[imagePath pathExtension] caseInsensitiveCompare:@"png"] == NSOrderedSame)
0
- [item setImageType:@"image/png"];
0
- else
0
- [item setImageType:@"image/jpeg"];
0
-
0
- // add the comments and description, if so desired
0
- if ([mainExportCommentsSwitch state]) {
0
- if ([imageDict objectForKey:@"Caption"])
0
- [item setCaption:[imageDict objectForKey:@"Caption"]];
0
- if ([imageDict objectForKey:@"Annotation"])
0
- [item setDescription:[imageDict objectForKey:@"Annotation"]];
0
- }
0
-
0
- // finally, add the image data
0
- NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
0
- NSImage *image = [[[NSImage alloc] initWithData:imageData] autorelease];
0
+ NSString *imagePath = [exportManager imagePathAtIndex:imageNum];
0
+ NSDictionary *imageDict = [self exportManagerImageDictionaryAtIndex:imageNum];
0
+
0
+ ZWGalleryItem *item = [ZWGalleryItem itemWithAlbum:album];
0
+
0
+ // add the filename
0
+ [item setFilename:[imagePath lastPathComponent]];
0
+
0
+ // add the image type (default to jpg)
0
+ // TODO: Be smarter here. There are many more possible image types we need to handle.
0
+ if ([[imagePath pathExtension] caseInsensitiveCompare:@"gif"] == NSOrderedSame)
0
+ [item setImageType:@"image/gif"];
0
+ else if ([[imagePath pathExtension] caseInsensitiveCompare:@"png"] == NSOrderedSame)
0
+ [item setImageType:@"image/png"];
0
+ else
0
+ [item setImageType:@"image/jpeg"];
0
+
0
+ // add the comments and description, if so desired
0
+ if ([mainExportCommentsSwitch state]) {
0
+ if ([imageDict objectForKey:@"Caption"])
0
+ [item setCaption:[imageDict objectForKey:@"Caption"]];
0
+ if ([imageDict objectForKey:@"Annotation"])
0
+ [item setDescription:[imageDict objectForKey:@"Annotation"]];
0
+ }
0
+
0
+ // finally, add the image data
0
+ NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
0
+ NSImage *image = [[[NSImage alloc] initWithData:imageData] autorelease];
0
+
0
+ currentImageIndex = imageNum;
0
+
0
+ if ([mainScaleImagesSwitch state] == NSOnState) {
0
+ NSDictionary *progressInfo = [NSDictionary dictionaryWithObjectsAndKeys:
0
+ [NSString stringWithFormat:@"Resizing %@...", [imagePath lastPathComponent]], @"UploadingTextField",
0
+ [NSString stringWithFormat:@"(Photo %i of %i)", imageNum + 1, (int)[exportManager imageCount]], @"UploadingDetailField",
0
+ [NSNumber numberWithInt:currentImageIndex], @"ProgressBarLocation",
0
+ image, @"Image",
0
+ nil];
0
+ [self performSelectorOnMainThread:@selector(updateProgress:) withObject:progressInfo waitUntilDone:NO modes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, nil]];
0
+
0
+ NSData *scaledData = [ImageResizer getScaledImageFromData:imageData toSize:NSMakeSize([mainScaleImagesWidthField intValue], [mainScaleImagesHeightField intValue])];
0
+ [item setData:scaledData];
0
+ currentImageSize = [scaledData length];
0
+ } else {
0
+ [item setData:imageData];
0
+ currentImageSize = [imageData length];
0
+ }
0
 
0
- currentImageIndex = imageNum;
0
-
0
- if ([mainScaleImagesSwitch state] == NSOnState) {
0
             NSDictionary *progressInfo = [NSDictionary dictionaryWithObjectsAndKeys:
0
- [NSString stringWithFormat:@"Resizing %@...", [imagePath lastPathComponent]], @"UploadingTextField",
0
+ [NSString stringWithFormat:@"Uploading %@...", [imagePath lastPathComponent]], @"UploadingTextField",
0
                 [NSString stringWithFormat:@"(Photo %i of %i)", imageNum + 1, (int)[exportManager imageCount]], @"UploadingDetailField",
0
                 [NSNumber numberWithInt:currentImageIndex], @"ProgressBarLocation",
0
                 image, @"Image",
0
                 nil];
0
             [self performSelectorOnMainThread:@selector(updateProgress:) withObject:progressInfo waitUntilDone:NO modes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, nil]];
0
             
0
- NSData *scaledData = [ImageResizer getScaledImageFromData:imageData toSize:NSMakeSize([mainScaleImagesWidthField intValue], [mainScaleImagesHeightField intValue])];
0
- [item setData:scaledData];
0
- currentImageSize = [scaledData length];
0
- } else {
0
- [item setData:imageData];
0
- currentImageSize = [imageData length];
0
- }
0
-
0
- NSDictionary *progressInfo = [NSDictionary dictionaryWithObjectsAndKeys:
0
- [NSString stringWithFormat:@"Uploading %@...", [imagePath lastPathComponent]], @"UploadingTextField",
0
- [NSString stringWithFormat:@"(Photo %i of %i)", imageNum + 1, (int)[exportManager imageCount]], @"UploadingDetailField",
0
- [NSNumber numberWithInt:currentImageIndex], @"ProgressBarLocation",
0
- image, @"Image",
0
- nil];
0
- [self performSelectorOnMainThread:@selector(updateProgress:) withObject:progressInfo waitUntilDone:NO modes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, nil]];
0
-
0
- [album setDelegate:self];
0
- status = [album addItemSynchronously:item];
0
-
0
- [innerPool release];
0
-
0
- if (status != GR_STAT_SUCCESS) {
0
-
0
- switch (status) {
0
- case ZW_GALLERY_OPERATION_DID_CANCEL:
0
- if (imageNum == 1)
0
- [mainStatusString setStringValue:[NSString stringWithFormat:@"Export cancelled after %i photo", imageNum]];
0
- else
0
- [mainStatusString setStringValue:[NSString stringWithFormat:@"Export cancelled after %i photos", imageNum]];
0
- break;
0
+ [album setDelegate:self];
0
+ status = [album addItemSynchronously:item];
0
+
0
+ if (status != GR_STAT_SUCCESS) {
0
+ switch (status) {
0
+ case ZW_GALLERY_OPERATION_DID_CANCEL:
0
+ if (imageNum == 1)
0
+ [mainStatusString setStringValue:[NSString stringWithFormat:@"Export cancelled after %i photo", imageNum]];
0
+ else
0
+ [mainStatusString setStringValue:[NSString stringWithFormat:@"Export cancelled after %i photos", imageNum]];
0
+ break;
0
+
0
+ case GR_STAT_UPLOAD_PHOTO_FAIL:
0
+ [mainStatusString setStringValue:@"Failed. Could not upload."];
0
+ break;
0
+
0
+ default:
0
+ NSLog(@"Export failed with error: %i", status);
0
+ [mainStatusString setStringValue:[NSString stringWithFormat:@"Export failed (error code: %i)", status]];
0
+ }
0
+
0
+ if (status != ZW_GALLERY_OPERATION_DID_CANCEL) {
0
+ [GrowlApplicationBridge notifyWithTitle:@"Export Failed"
0
+ description:[NSString stringWithFormat:@"Export to gallery failed after %i photos were uploaded",
0
+ imageNum]
0
+ notificationName:@"Export to Gallery Failed"
0
+ iconData:[item data]
0
+ priority:0
0
+ isSticky:NO
0
+ clickContext:NULL];
0
+ }
0
                 
0
- case GR_STAT_UPLOAD_PHOTO_FAIL:
0
- [mainStatusString setStringValue:@"Failed. Could not upload."];
0
- break;
0
-
0
- default:
0
- [mainStatusString setStringValue:[NSString stringWithFormat:@"Export failed (error code: %i)", status]];
0
+ cancel = YES;
0
             }
0
-
0
- if (status != ZW_GALLERY_OPERATION_DID_CANCEL)
0
- [GrowlApplicationBridge notifyWithTitle:@"Export Failed"
0
- description:[NSString stringWithFormat:@"Export to gallery failed after %i photos were uploaded",
0
- imageNum]
0
- notificationName:@"Export to Gallery Failed"
0
+ else {
0
+ [GrowlApplicationBridge notifyWithTitle:@"Photo Uploaded"
0
+ description:[NSString stringWithFormat:@"Photo %@ uploaded to Gallery",
0
+ [item filename]]
0
+ notificationName:@"Photo Uploaded to Gallery"
0
                                                iconData:[item data]
0
                                                priority:0
0
                                                isSticky:NO
0
                                            clickContext:NULL];
0
+ }
0
             
0
- break;
0
- }
0
- else {
0
- [GrowlApplicationBridge notifyWithTitle:@"Photo Uploaded"
0
- description:[NSString stringWithFormat:@"Photo %@ uploaded to Gallery",
0
- [item filename]]
0
- notificationName:@"Photo Uploaded to Gallery"
0
- iconData:[item data]
0
- priority:0
0
- isSticky:NO
0
- clickContext:NULL];
0
- }
0
+ } [innerPool release];
0
     }
0
     
0
     [NSApp endSheet:progressPanel];
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
66
67
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
70
71
...
286
287
288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
290
291
...
300
301
302
 
 
 
 
 
 
 
 
303
304
305
0
@@ -13,19 +13,6 @@
0
       buildPhases = (
0
         FF50DA400863D122005E37D9 /* ShellScript */,
0
       );
0
- buildSettings = {
0
- OPTIMIZATION_CFLAGS = "";
0
- OTHER_CFLAGS = "";
0
- OTHER_LDFLAGS = "";
0
- OTHER_REZFLAGS = "";
0
- PRODUCT_NAME = "iPhotoToGallery Install";
0
- SECTORDER_FLAGS = "";
0
- WARNING_CFLAGS = (
0
- "-Wmost",
0
- "-Wno-four-char-constants",
0
- "-Wno-unknown-pragmas",
0
- );
0
- };
0
       dependencies = (
0
         FF50DA430863D128005E37D9 /* PBXTargetDependency */,
0
       );
0
@@ -79,38 +66,6 @@
0
     };
0
 /* End PBXBuildRule section */
0
 
0
-/* Begin PBXBuildStyle section */
0
- 014CEA420018CDE011CA2923 /* Development */ = {
0
- isa = PBXBuildStyle;
0
- buildSettings = {
0
- COPY_PHASE_STRIP = NO;
0
- DEBUGGING_SYMBOLS = YES;
0
- FRAMEWORK_SEARCH_PATHS = "";
0
- GCC_DYNAMIC_NO_PIC = NO;
0
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
0
- GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
0
- GCC_OPTIMIZATION_LEVEL = 0;
0
- HEADER_SEARCH_PATHS = "";
0
- LIBRARY_SEARCH_PATHS = "";
0
- LIBRARY_STYLE = Bundle;
0
- MACOSX_DEPLOYMENT_TARGET = 10.2;
0
- OPTIMIZATION_CFLAGS = "-O0";
0
- OTHER_LDFLAGS = "";
0
- ZERO_LINK = NO;
0
- };
0
- name = Development;
0
- };
0
- 014CEA430018CDE011CA2923 /* Deployment */ = {
0
- isa = PBXBuildStyle;
0
- buildSettings = {
0
- COPY_PHASE_STRIP = YES;
0
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
0
- ZERO_LINK = NO;
0
- };
0
- name = Deployment;
0
- };
0
-/* End PBXBuildStyle section */
0
-
0
 /* Begin PBXContainerItemProxy section */
0
     FF50DA420863D128005E37D9 /* PBXContainerItemProxy */ = {
0
       isa = PBXContainerItemProxy;
0
@@ -331,29 +286,6 @@
0
         FF1297A30853E87F000929B0 /* PBXBuildRule */,
0
         FF1297A20853E85E000929B0 /* PBXBuildRule */,
0
       );
0
- buildSettings = {
0
- GCC_DEBUGGING_SYMBOLS = full;
0
- GCC_ENABLE_TRIGRAPHS = NO;
0
- GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
0
- GCC_OPTIMIZATION_LEVEL = s;
0
- GCC_PRECOMPILE_PREFIX_HEADER = YES;
0
- GCC_PREFIX_HEADER = iPhotoToGallery_Prefix.pch;
0
- GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
0
- GCC_WARN_UNKNOWN_PRAGMAS = NO;
0
- INFOPLIST_FILE = Info.plist;
0
- INSTALL_PATH = /Applications/iPhoto.app/Contents/Plugins;
0
- LIBRARY_SEARCH_PATHS = "";
0
- OTHER_CFLAGS = "";
0
- OTHER_REZFLAGS = "";
0
- PRODUCT_NAME = iPhotoToGallery;
0
- SECTORDER_FLAGS = "";
0
- WARNING_CFLAGS = (
0
- "-Wmost",
0
- "-Wno-four-char-constants",
0
- "-Wno-unknown-pragmas",
0
- );
0
- WRAPPER_EXTENSION = iPhotoExporter;
0
- };
0
       dependencies = (
0
       );
0
       name = iPhotoToGallery;
0
@@ -368,14 +300,6 @@
0
     089C1669FE841209C02AAC07 /* Project object */ = {
0
       isa = PBXProject;
0
       buildConfigurationList = FF93797D08553AA800831A51 /* Build configuration list for PBXProject "iPhotoToGallery" */;
0
- buildSettings = {
0
- MACOSX_DEPLOYMENT_TARGET = 10.2;
0
- SDKROOT = /Developer/SDKs/MacOSX10.2.8.sdk;
0
- };
0
- buildStyles = (
0
- 014CEA420018CDE011CA2923 /* Development */,
0
- 014CEA430018CDE011CA2923 /* Deployment */,
0
- );
0
       hasScannedForEncodings = 1;
0
       mainGroup = 089C166AFE841209C02AAC07 /* iPhotoToGallery */;
0
       projectDirPath = "";

Comments

    No one has commented yet.