Skip to content

Commit

Permalink
Show error message when no private key is available [#68 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
the-kenny committed Jun 24, 2011
1 parent a9c70d8 commit 78cc205
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Source/GPGServices.h
Expand Up @@ -131,6 +131,8 @@ typedef enum {
- (void)displayOperationFinishedNotificationWithTitle:(NSString*)title message:(NSString*)body;
- (void)displayOperationFailedNotificationWithTitle:(NSString*)title message:(NSString*)body;
- (void)displaySignatureVerificationForSig:(GPGSignature*)sig;
- (void)showNoPrivateKeyErrorMessage;

- (NSString *)context:(GPGContext *)context passphraseForKey:(GPGKey *)key again:(BOOL)again;
- (IBAction)closeModalWindow:(id)sender;
- (NSURL*)getFilenameForSavingWithSuggestedPath:(NSString*)path
Expand Down
32 changes: 28 additions & 4 deletions Source/GPGServices.m
Expand Up @@ -241,7 +241,9 @@ -(NSString *)myFingerprint {
return [GPGServices isActiveValidator]((GPGKey*)evaluatedObject);
}]];

if(chosenKey == nil || availableKeys.count > 1) {
if(availableKeys.count == 0) {
[self showNoPrivateKeyErrorMessage]; return nil;
} else if(chosenKey == nil || availableKeys.count > 1) {
KeyChooserWindowController* wc = [[KeyChooserWindowController alloc] init];
[wc setKeyValidator:[GPGServices isActiveValidator]];

Expand All @@ -268,7 +270,9 @@ -(NSString *)myKey {
return [GPGServices isActiveValidator]((GPGKey*)evaluatedObject);
}]];

if(selectedPrivateKey == nil || availableKeys.count > 1) {
if(availableKeys.count == 0) {
[self showNoPrivateKeyErrorMessage]; return nil;
} else if(selectedPrivateKey == nil || availableKeys.count > 1) {
KeyChooserWindowController* wc = [[KeyChooserWindowController alloc] init];
[wc setKeyValidator:[GPGServices isActiveValidator]];

Expand Down Expand Up @@ -445,7 +449,9 @@ -(NSString *)signTextString:(NSString *)inputString
return [GPGServices canSignValidator]((GPGKey*)evaluatedObject);
}]];

if(chosenKey == nil || availableKeys.count > 1) {
if(availableKeys.count == 0) {
[self showNoPrivateKeyErrorMessage]; return nil;
} else if(chosenKey == nil || availableKeys.count > 1) {
KeyChooserWindowController* wc = [[KeyChooserWindowController alloc] init];
[wc setKeyValidator:[GPGServices canSignValidator]];

Expand Down Expand Up @@ -695,7 +701,9 @@ - (void)signFiles:(NSArray*)files {
return [GPGServices canSignValidator]((GPGKey*)evaluatedObject);
}]];

if(chosenKey == nil || availableKeys.count > 1) {
if(availableKeys.count == 0) {
[self showNoPrivateKeyErrorMessage]; return nil;
} else if(chosenKey == nil || availableKeys.count > 1) {
KeyChooserWindowController* wc = [[[KeyChooserWindowController alloc] init] autorelease];
[wc setKeyValidator:[GPGServices canSignValidator]];

Expand Down Expand Up @@ -1287,6 +1295,22 @@ - (void)displaySignatureVerificationForSig:(GPGSignature*)sig {
runModal];
}

- (void)showNoPrivateKeyErrorMessage {
NSInteger ret = [[NSAlert alertWithMessageText:NSLocalizedString(@"No Private-Key found", @"alert-box message text")
defaultButton:NSLocalizedString(@"Ok", nil)
alternateButton:NSLocalizedString(@"Help", nil)
otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"No private-key found on your system.\nClick 'Help' to open a web-browser with a tutorial.", @"alert-box informative")]
runModal];
if(ret == NSAlertAlternateReturn) {
//Open browser with help
NSString* localizedURLString = NSLocalizedString(@"http://www.dewinter.com/gnupg_howto/english/GPGMiniHowto-3.html#ss3.1",
@"URL to a good tutorial about generating keys");
NSURL* url = [NSURL URLWithString:localizedURLString];
[[NSWorkspace sharedWorkspace] openURL:url];
}
}

-(NSString *)context:(GPGContext *)context passphraseForKey:(GPGKey *)key again:(BOOL)again
{
[passphraseText setStringValue:@""];
Expand Down

0 comments on commit 78cc205

Please sign in to comment.