Permalink
Browse files

Always keep sign|encrypt buttons, status and security method accessor…

…y view in sync

- Fix a problem where ForceSign and ForceEncrypt was not in sync with the image.
- Implemented setImage:forSegment to first check SetSign, overwrite it with ForceSign
  and again overwrite it with CanSign. That order makes sense.
  (Might be able to implement it with less code though.)

[#460 state:fixed]
  • Loading branch information...
1 parent 849b003 commit 67a5f098f21a0d722e2b7c44903ba279f4b07e6b @lukele lukele committed Mar 1, 2012
Showing with 26 additions and 5 deletions.
  1. +17 −3 Source/ComposeBackEnd+GPGMail.m
  2. +9 −2 Source/GMSecurityControl.m
@@ -40,9 +40,16 @@ - (void)MASetEncryptIfPossible:(BOOL)encryptIfPossible {
if([self ivarExists:@"SetEncrypt"]) {
encryptIfPossible = [[self getIvar:@"SetEncrypt"] boolValue];
}
- if([self ivarExists:@"ForceEncrypt"])
- encryptIfPossible = [[self getIvar:@"ForceEncrypt"] boolValue];
+ // Force Encrypt contains the user choice.
+ // It overrides SetEncrypt, which is checked when
+ // displaying the correct image, so it has to
+ // be reset, if ForceSign is set, otherwise the wrong
+ // image could be shown.
+ if([self ivarExists:@"ForceEncrypt"]) {
+ encryptIfPossible = [[self getIvar:@"ForceEncrypt"] boolValue];
+ [self setIvar:@"SetEncrypt" value:[NSNumber numberWithBool:encryptIfPossible]];
+ }
// If SetEncrypt and CanEncrypt don't match, use CanEncrypt,
// since that's more important.
if(![[self getIvar:@"EncryptIsPossible"] boolValue])
@@ -58,8 +65,15 @@ - (void)MASetSignIfPossible:(BOOL)signIfPossible {
signIfPossible = [[self getIvar:@"SetSign"] boolValue];
}
- if([self ivarExists:@"ForceSign"])
+ // Force Sign contains the user choice.
+ // It overrides SetSign, which is checked when
+ // displaying the correct image, so it has to
+ // be reset, if ForceSign is set, otherwise the wrong
+ // image could be shown.
+ if([self ivarExists:@"ForceSign"]) {
signIfPossible = [[self getIvar:@"ForceSign"] boolValue];
+ [self setIvar:@"SetSign" value:[NSNumber numberWithBool:signIfPossible]];
+ }
// If SetSign and CanSign don't match, use CanSign,
// since that's more important.
View
@@ -82,11 +82,18 @@ - (void)setImage:(id)image forSegment:(NSInteger)segment {
NSString *imageName = nil;
if(self.securityTag == SECURITY_BUTTON_SIGN_TAG) {
- BOOL setSign = [[backEnd getIvar:@"SetSign"] boolValue];
+ BOOL setSign = [backEnd ivarExists:@"ForceSign"] ? [[backEnd getIvar:@"ForceSign"] boolValue] : [[backEnd getIvar:@"SetSign"] boolValue];
+ if(setSign && ![[backEnd getIvar:@"SignIsPossible"] boolValue])
+ setSign = NO;
+
imageName = setSign ? SIGN_ON_IMAGE : SIGN_OFF_IMAGE;
}
else if(self.securityTag == SECURITY_BUTTON_ENCRYPT_TAG) {
- BOOL setEncrypt = [[backEnd getIvar:@"SetEncrypt"] boolValue];
+ BOOL setEncrypt = [backEnd ivarExists:@"ForceEncrypt"] ? [[backEnd getIvar:@"ForceEncrypt"] boolValue] : [[backEnd getIvar:@"SetEncrypt"] boolValue];
+
+ if(setEncrypt && ![[backEnd getIvar:@"EncryptIsPossible"] boolValue])
+ setEncrypt = NO;
+
imageName = setEncrypt ? ENCRYPT_LOCK_LOCKED_IMAGE : ENCRYPT_LOCK_UNLOCKED_IMAGE;
}
[self.control setImage:[NSImage imageNamed:imageName] forSegment:0];

0 comments on commit 67a5f09

Please sign in to comment.