Revision: 4495
http://skim-app.svn.sourceforge.net/skim-app/?rev=4495&view=rev
Author: hofman
Date: 2008-09-01 11:21:26 +0000 (Mon, 01 Sep 2008)
Log Message:
-----------
Fix KVO in remote control classes.
Modified Paths:
--------------
trunk/vendorsrc/martinkahr/RemoteControlWrapper/HIDRemoteControlDevice.m
trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.h
trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.m
Modified:
trunk/vendorsrc/martinkahr/RemoteControlWrapper/HIDRemoteControlDevice.m
===================================================================
--- trunk/vendorsrc/martinkahr/RemoteControlWrapper/HIDRemoteControlDevice.m
2008-09-01 11:01:49 UTC (rev 4494)
+++ trunk/vendorsrc/martinkahr/RemoteControlWrapper/HIDRemoteControlDevice.m
2008-09-01 11:21:26 UTC (rev 4495)
@@ -169,6 +169,9 @@
io_object_t hidDevice = [[self class] findRemoteDevice];
if (hidDevice == 0) return;
+ // be KVO friendly
+ [self willChangeValueForKey:@"listeningToRemote"];
+
if ([self createInterfaceForDevice:hidDevice] == NULL) {
goto error;
}
@@ -180,16 +183,15 @@
if ([self openDevice]==NO) {
goto error;
}
- // be KVO friendly
- [self willChangeValueForKey:@"listeningToRemote"];
- [self didChangeValueForKey:@"listeningToRemote"];
goto cleanup;
error:
+ [self didChangeValueForKey:@"listeningToRemote"];
[self stopListening:self];
DisableSecureEventInput();
cleanup:
+ [self didChangeValueForKey:@"listeningToRemote"];
IOObjectRelease(hidDevice);
}
@@ -198,6 +200,9 @@
BOOL sendNotification = NO;
+ // be KVO friendly
+ [self willChangeValueForKey:@"listeningToRemote"];
+
if (eventSource != NULL) {
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventSource,
kCFRunLoopDefaultMode);
CFRelease(eventSource);
@@ -237,8 +242,7 @@
if ([self isOpenInExclusiveMode] && sendNotification) {
[[self class] sendFinishedNotifcationForAppIdentifier: nil];
}
- // be KVO friendly
- [self willChangeValueForKey:@"listeningToRemote"];
+
[self didChangeValueForKey:@"listeningToRemote"];
}
Modified:
trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.h
===================================================================
--- trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.h
2008-09-01 11:01:49 UTC (rev 4494)
+++ trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.h
2008-09-01 11:21:26 UTC (rev 4495)
@@ -30,6 +30,7 @@
@interface RemoteControlContainer : RemoteControl {
NSMutableArray* remoteControls;
+ BOOL listeningToRemote;
}
- (BOOL) instantiateAndAddRemoteControlDeviceWithClass: (Class) clazz;
Modified:
trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.m
===================================================================
--- trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.m
2008-09-01 11:01:49 UTC (rev 4494)
+++ trunk/vendorsrc/martinkahr/RemoteControlWrapper/RemoteControlContainer.m
2008-09-01 11:21:26 UTC (rev 4495)
@@ -27,12 +27,14 @@
#import "RemoteControlContainer.h"
+NSString *RemoteControlContainerObservationContext =
@"RemoteControlContainerObservationContext";
@implementation RemoteControlContainer
- (id) initWithDelegate: (id) _remoteControlDelegate {
if (self = [super initWithDelegate:_remoteControlDelegate]) {
remoteControls = [[NSMutableArray alloc] init];
+ listeningToRemote = NO;
}
return self;
}
@@ -47,13 +49,27 @@
[super dealloc];
}
+- (void) reset {
+ [self willChangeValueForKey:@"listeningToRemote"];
+ listeningToRemote = NO;
+ unsigned int i;
+ for(i=0; i < [remoteControls count]; i++) {
+ if ([[remoteControls objectAtIndex: i] isListeningToRemote]) {
+ listeningToRemote = YES;
+ break;
+ }
+ }
+ [self didChangeValueForKey:@"listeningToRemote"];
+}
+
- (BOOL) instantiateAndAddRemoteControlDeviceWithClass: (Class) clazz {
RemoteControl* remoteControl = [[clazz alloc] initWithDelegate:
delegate];
if (remoteControl) {
[remoteControls addObject: remoteControl];
- [remoteControl addObserver: self
forKeyPath:@"listeningToRemote" options:NSKeyValueObservingOptionNew
context:nil];
+ [remoteControl addObserver: self
forKeyPath:@"listeningToRemote" options:0
context:RemoteControlContainerObservationContext];
[remoteControl release];
- return YES;
+ [self reset];
+ return YES;
}
return NO;
}
@@ -62,13 +78,12 @@
return [remoteControls count];
}
-- (void) reset {
- [self willChangeValueForKey:@"listeningToRemote"];
- [self didChangeValueForKey:@"listeningToRemote"];
-}
-
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
- [self reset];
+ if (context == RemoteControlContainerObservationContext) {
+ [self reset];
+ } else {
+ [super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
+ }
}
- (void) setListeningToRemote: (BOOL) value {
@@ -79,13 +94,7 @@
if (value && value != [self isListeningToRemote]) [self
performSelector:@selector(reset) withObject:nil afterDelay:0.01];
}
- (BOOL) isListeningToRemote {
- unsigned int i;
- for(i=0; i < [remoteControls count]; i++) {
- if ([[remoteControls objectAtIndex: i] isListeningToRemote]) {
- return YES;
- }
- }
- return NO;
+ return listeningToRemote;
}
- (IBAction) startListening: (id) sender {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit