Permalink
Browse files

File Import: Show growl notification for files without keys in it [#5…

…6 state:resolved]
  • Loading branch information...
1 parent 043aa83 commit 0e378b64f6b8691e31d006968f58918a3018f01e @the-kenny the-kenny committed May 1, 2011
Showing with 43 additions and 14 deletions.
  1. +43 −14 Source/GPGServices.m
View
@@ -945,38 +945,67 @@ - (void)verifyFiles:(NSArray*)files {
}
- (void)importFiles:(NSArray*)files {
- NSDictionary *importedKeys = nil;
GPGContext *aContext = [[[GPGContext alloc] init] autorelease];
+ NSUInteger foundKeysCount = 0; //Track valid key-files
NSUInteger importedKeyCount = 0;
NSUInteger importedSecretKeyCount = 0;
NSUInteger newRevocationCount = 0;
for(NSString* file in files) {
+ if([[self isDirectoryPredicate] evaluateWithObject:file] == YES) {
+ [GrowlApplicationBridge notifyWithTitle:@"Can't import keys from directory"
+ description:[file lastPathComponent]
+ notificationName:gpgGrowlOperationFailedName
+ iconData:[NSData data]
+ priority:0
+ isSticky:NO
+ clickContext:file];
+
+ continue; //Shortcut all following code, go to next file
+ }
+
GPGData* inputData = [[[GPGData alloc] initWithDataNoCopy:[NSData dataWithContentsOfFile:file]] autorelease];
@try {
- importedKeys = [aContext importKeyData:inputData];
+ NSDictionary* importResults = [aContext importKeyData:inputData];
+ NSDictionary* changedKeys = [importResults valueForKey:GPGChangesKey];
- importedKeyCount += [[importedKeys valueForKey:@"importedKeyCount"] intValue];
- importedSecretKeyCount += [[importedKeys valueForKey:@"importedSecretKeyCount"] intValue];
- newRevocationCount += [[importedKeys valueForKey:@"newRevocationCount"] intValue];
+ if(changedKeys.count > 0) {
+ ++foundKeysCount;
+
+ importedKeyCount += [[importResults valueForKey:@"importedKeyCount"] unsignedIntValue];
+ importedSecretKeyCount += [[importResults valueForKey:@"importedSecretKeyCount"] unsignedIntValue];
+ newRevocationCount += [[importResults valueForKey:@"newRevocationCount"] unsignedIntValue];
+ } else {
+ //Show growl notification
+ [GrowlApplicationBridge notifyWithTitle:@"No importable Keys found"
+ description:[file lastPathComponent]
+ notificationName:gpgGrowlOperationFailedName
+ iconData:[NSData data]
+ priority:0
+ isSticky:NO
+ clickContext:file];
+ }
} @catch(NSException* localException) {
[self displayMessageWindowWithTitleText:@"Import result:"
bodyText:GPGErrorDescription([[[localException userInfo]
objectForKey:@"GPGErrorKey"] intValue])];
}
}
- [[NSAlert alertWithMessageText:@"Import result:"
- defaultButton:@"Ok"
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:@"%i key(s), %i secret key(s), %i revocation(s) ",
- importedKeyCount,
- importedSecretKeyCount,
- newRevocationCount]
- runModal];
+ //Don't show result window when there were no imported keys
+ if(foundKeysCount > 0) {
+ [[NSAlert alertWithMessageText:@"Import result:"
+ defaultButton:@"Ok"
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"%i key(s), %i secret key(s), %i revocation(s) ",
+ importedKeyCount,
+ importedSecretKeyCount,
+ newRevocationCount]
+ runModal];
+ }
}
#pragma mark - NSPredicates for filtering file arrays

0 comments on commit 0e378b6

Please sign in to comment.