Subversion Repositories TruePreview

[/] [trunk/] [Source/] [TruePreviewMessageViewer.m] - Diff between revs 42 and 51

Show entire file | Ignore whitespace | Details | Blame | View Log

Rev 42 Rev 51
Line 34... Line 34...
@implementation TruePreviewMessageViewer
@implementation TruePreviewMessageViewer
 
 
#pragma mark Class methods
#pragma mark Class methods
 
 
+ (NSMutableDictionary*)truePreviewTimers {
+ (NSMutableDictionary*)truePreviewTimers {
 
  TRUEPREVIEW_LOG();
 
 
  static NSMutableDictionary* sTimers = nil;
  static NSMutableDictionary* sTimers = nil;
 
 
  if (sTimers == nil) {
  if (sTimers == nil) {
    sTimers = [[NSMutableDictionary alloc] initWithCapacity:1];
    sTimers = [[NSMutableDictionary alloc] initWithCapacity:1];
  }
  }
Line 46... Line 48...
}
}
 
 
#pragma mark Swizzled instance methods
#pragma mark Swizzled instance methods
 
 
- (void)truePreviewDealloc {
- (void)truePreviewDealloc {
 
  TRUEPREVIEW_LOG();
 
 
  [self truePreviewReset];
  [self truePreviewReset];
  [[[self class] truePreviewTimers]
  [[[self class] truePreviewTimers]
    removeObjectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)self]
    removeObjectForKey:[NSNumber numberWithUnsignedLongLong:(unsigned long long)self]
  ];
  ];
  [self truePreviewDealloc];
  [self truePreviewDealloc];
}
}
 
 
- (void)truePreviewForwardAsAttachment:(id)inSender {
- (void)truePreviewForwardAsAttachment:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  id theMessage = [self currentDisplayedMessage];
  id theMessage = [self currentDisplayedMessage];
 
 
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
    NSDictionary* theSettings = [theMessage truePreviewSettings];
    NSDictionary* theSettings = [theMessage truePreviewSettings];
   
   
    if ([[theSettings objectForKey:@"forward"] boolValue]) {
    if ([[theSettings objectForKey:@"forward"] boolValue]) {
      [self truePreviewReset];
      [self truePreviewReset];
      [theMessage truePreviewMarkAsViewed];
      [self truePreviewMarkMessagesAsViewed:[NSArray arrayWithObject:theMessage]];
    }
    }
  }
  }
 
 
  [self truePreviewForwardAsAttachment:inSender];
  [self truePreviewForwardAsAttachment:inSender];
}
}
 
 
- (void)truePreviewForwardMessage:(id)inSender {
- (void)truePreviewForwardMessage:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  id theMessage = [self currentDisplayedMessage];
  id theMessage = [self currentDisplayedMessage];
 
 
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
    NSDictionary* theSettings = [theMessage truePreviewSettings];
    NSDictionary* theSettings = [theMessage truePreviewSettings];
   
   
    if ([[theSettings objectForKey:@"forward"] boolValue]) {
    if ([[theSettings objectForKey:@"forward"] boolValue]) {
      [self truePreviewReset];
      [self truePreviewReset];
      [theMessage truePreviewMarkAsViewed];
      [self truePreviewMarkMessagesAsViewed:[NSArray arrayWithObject:theMessage]];
    }
    }
  }
  }
 
 
  [self truePreviewForwardMessage:inSender];
  [self truePreviewForwardMessage:inSender];
}
}
 
 
- (void)truePreviewMarkAsRead:(id)inSender {
- (void)truePreviewMarkAsRead:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  [self truePreviewReset];
  [self truePreviewReset];
  [self truePreviewMarkAsRead:inSender];
  [self truePreviewMarkAsRead:inSender];
}
}
 
 
- (void)truePreviewMarkAsUnread:(id)inSender {
- (void)truePreviewMarkAsUnread:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  [self truePreviewReset];
  [self truePreviewReset];
  [self truePreviewMarkAsUnread:inSender];
  [self truePreviewMarkAsUnread:inSender];
}
}
 
 
- (void)truePreviewMessageNoLongerDisplayedInTextView:(NSNotification*)inNotification {
- (void)truePreviewMarkMessageAsViewed:(id)inMessage {
  [self truePreviewMessageNoLongerDisplayedInTextView:inNotification];
  TRUEPREVIEW_LOG(@"%@", inMessage);
 
 
  // we receive notifications from all MessageContentControllers
 
  if ([inNotification object] != object_getIvar(self, class_getInstanceVariable([self class], "_contentController"))) {
 
    return;
 
  }
 
 
 
  [self truePreviewReset];
  [self truePreviewCreateTimer:inMessage];
 
}
 
 
 
- (void)truePreviewMarkMessagesAsViewed:(NSArray*)inMessages  {
 
  TRUEPREVIEW_LOG(@"%@", inMessages);
 
 
 
  [self truePreviewCreateTimer:inMessages];
}
}
 
 
- (void)truePreviewMessageWasDisplayedInTextView:(NSNotification*)inNotification {
- (void)truePreviewMessageWasDisplayedInTextView:(NSNotification*)inNotification {
  [self truePreviewMessageWasDisplayedInTextView:inNotification];
  TRUEPREVIEW_LOG(@"%@", inNotification);
 
 
 
  [self truePreviewMessageWasDisplayedInTextView:inNotification];  
 
  [self truePreviewReset];
 
/* TODO: IN PROGRESS
  // we receive notifications from all MessageContentControllers
  // we receive notifications from all MessageContentControllers
  if ([inNotification object] != object_getIvar(self, class_getInstanceVariable([self class], "_contentController"))) {
  if ([inNotification object] != object_getIvar(self, class_getInstanceVariable([self class], "_contentController"))) {
    return;
    return;
  }
  }
 
 
Line 125... Line 141...
        [[theSettings objectForKey:@"window"] boolValue]
        [[theSettings objectForKey:@"window"] boolValue]
        && [self isKindOfClass:NSClassFromString(@"SingleMessageViewer")]
        && [self isKindOfClass:NSClassFromString(@"SingleMessageViewer")]
      )        
      )        
    ) {
    ) {
      [self truePreviewReset];
      [self truePreviewReset];
      [theMessage truePreviewMarkAsViewed];
      [self truePreviewMarkMessagesAsViewed:[NSArray arrayWithObject:theMessage]];
     
     
      return;
      return;
    }
    }
 
 
    float theDelay = [[theSettings objectForKey:@"delay"] floatValue];
    float theDelay = [[theSettings objectForKey:@"delay"] floatValue];
Line 166... Line 182...
        name:NSViewBoundsDidChangeNotification
        name:NSViewBoundsDidChangeNotification
        object:[[[[object_getIvar(self, class_getInstanceVariable([self class], "_contentController")) currentDisplay] contentView] enclosingScrollView] contentView]
        object:[[[[object_getIvar(self, class_getInstanceVariable([self class], "_contentController")) currentDisplay] contentView] enclosingScrollView] contentView]
      ];
      ];
    }    
    }    
  }
  }
 
*/
}
}
 
 
- (void)truePreviewReplyAllMessage:(id)inSender {
- (void)truePreviewReplyAllMessage:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  id theMessage = [self currentDisplayedMessage];
  id theMessage = [self currentDisplayedMessage];
 
 
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
    NSDictionary* theSettings = [theMessage truePreviewSettings];
    NSDictionary* theSettings = [theMessage truePreviewSettings];
   
   
    if ([[theSettings objectForKey:@"reply"] boolValue]) {
    if ([[theSettings objectForKey:@"reply"] boolValue]) {
      [self truePreviewReset];
      [self truePreviewReset];
      [theMessage truePreviewMarkAsViewed];
      [self truePreviewMarkMessagesAsViewed:[NSArray arrayWithObject:theMessage]];
    }
    }
  }
  }
 
 
  [self truePreviewReplyAllMessage:inSender];
  [self truePreviewReplyAllMessage:inSender];
}
}
 
 
- (void)truePreviewReplyMessage:(id)inSender {
- (void)truePreviewReplyMessage:(id)inSender {
 
  TRUEPREVIEW_LOG(@"%@", inSender);
 
 
  id theMessage = [self currentDisplayedMessage];
  id theMessage = [self currentDisplayedMessage];
 
 
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
  if ([theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
    NSDictionary* theSettings = [theMessage truePreviewSettings];
    NSDictionary* theSettings = [theMessage truePreviewSettings];
 
 
    if ([[theSettings objectForKey:@"reply"] boolValue]) {
    if ([[theSettings objectForKey:@"reply"] boolValue]) {
      [self truePreviewReset];
      [self truePreviewReset];
      [theMessage truePreviewMarkAsViewed];
      [self truePreviewMarkMessagesAsViewed:[NSArray arrayWithObject:theMessage]];
    }
    }
  }
  }
 
 
  [self truePreviewReplyMessage:inSender];
  [self truePreviewReplyMessage:inSender];
 
}
 
 
 
- (void)truePreviewSelectedMessagesDidChangeInMessageList {
 
  TRUEPREVIEW_LOG();
 
 
 
  [self truePreviewReset];
 
  [self truePreviewSelectedMessagesDidChangeInMessageList];
}
}
 
 
#pragma mark Accessors
#pragma mark Accessors
 
 
- (NSTimer*)truePreviewTimer {
- (NSTimer*)truePreviewTimer {
 
  TRUEPREVIEW_LOG();
 
 
  return [[[self class] truePreviewTimers]
  return [[[self class] truePreviewTimers]
    objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)self]
    objectForKey:[NSNumber numberWithUnsignedLongLong:(unsigned long long)self]
  ];
  ];
}
}
 
 
- (void)truePreviewSetTimer:(NSTimer*)inTimer {
- (void)truePreviewSetTimer:(NSTimer*)inTimer {
 
  TRUEPREVIEW_LOG(@"%@ (userInfo: %@)", inTimer, [inTimer userInfo]);
 
 
  [[[self class] truePreviewTimers]
  [[[self class] truePreviewTimers]
    setObject:inTimer
    setObject:inTimer
    forKey:[NSNumber numberWithUnsignedLong:(unsigned long)self]
    forKey:[NSNumber numberWithUnsignedLongLong:(unsigned long long)self]
  ];
  ];
}
}
 
 
#pragma mark Instance methods
#pragma mark Instance methods
 
 
 
- (void)truePreviewCreateTimer:(id)inMessages {
 
  TRUEPREVIEW_LOG(@"%@", inMessages);
 
 
 
  if (![inMessages isKindOfClass:[NSArray class]]) {
 
    inMessages = [NSArray arrayWithObject:inMessages];
 
  }
 
  else {
 
    inMessages = [[inMessages copy] autorelease];
 
  }
 
 
 
  id theMessage = [inMessages objectAtIndex:0];
 
 
 
  if (
 
    ![theMessage isKindOfClass:NSClassFromString(@"LibraryMessage")]
 
    || ![[self currentDisplayedMessage] isKindOfClass:NSClassFromString(@"LibraryMessage")]
 
  ) {
 
    return;
 
  }
 
 
 
  NSDictionary* theSettings = [theMessage truePreviewSettings];
 
 
 
  if (
 
    ([[theSettings objectForKey:@"delay"] floatValue] == TRUEPREVIEW_DELAY_IMMEDIATE)
 
    || (
 
      [[theSettings objectForKey:@"window"] boolValue]
 
      && [self isKindOfClass:NSClassFromString(@"SingleMessageViewer")]
 
    )        
 
  ) {
 
    [self truePreviewReset];
 
    [self truePreviewMarkMessagesAsViewed:inMessages];
 
   
 
    return;
 
  }
 
 
 
  float theDelay = [[theSettings objectForKey:@"delay"] floatValue];
 
 
 
  if (theDelay > TRUEPREVIEW_DELAY_IMMEDIATE) {
 
    [self truePreviewReset];
 
    [self
 
      truePreviewSetTimer:[NSTimer
 
        scheduledTimerWithTimeInterval:theDelay
 
        target:self
 
        selector:@selector(truePreviewTimerFired:)
 
        userInfo:inMessages
 
        repeats:NO
 
      ]
 
    ];
 
  }
 
}
 
 
- (void)truePreviewReset {
- (void)truePreviewReset {
 
  TRUEPREVIEW_LOG();
 
 
  NSTimer* theTimer = [self truePreviewTimer];
  NSTimer* theTimer = [self truePreviewTimer];
 
 
  if ((theTimer != nil) && [theTimer isValid]) {
  if ((theTimer != nil) && [theTimer isValid]) {
    [theTimer invalidate];
    [theTimer invalidate];
  }
  }
Line 236... Line 320...
    object:[[[[object_getIvar(self, class_getInstanceVariable([self class], "_contentController")) currentDisplay] contentView] enclosingScrollView] contentView]
    object:[[[[object_getIvar(self, class_getInstanceVariable([self class], "_contentController")) currentDisplay] contentView] enclosingScrollView] contentView]
  ];
  ];
}
}
 
 
- (void)truePreviewTimerFired:(NSTimer*)inTimer {
- (void)truePreviewTimerFired:(NSTimer*)inTimer {
  [self truePreviewReset];
  TRUEPREVIEW_LOG(@"%@ (userInfo: %@)", inTimer, [inTimer userInfo]);
 
 
  if ([[self currentDisplayedMessage] isKindOfClass:NSClassFromString(@"LibraryMessage")]) {
  id theMessages = [inTimer userInfo];
    [[self currentDisplayedMessage] truePreviewMarkAsViewed];
 
  }
  [self truePreviewReset];
 
  [self truePreviewMarkMessagesAsViewed:theMessages];
}
}
 
 
- (void)truePreviewMessageClickedOrScrolled:(NSNotification*)inNotification {
- (void)truePreviewMessageClickedOrScrolled:(NSNotification*)inNotification {
 
  TRUEPREVIEW_LOG(@"%@", inNotification);
 
 
  // ignore the first time we get the notification; it may be an initial scroll
  // ignore the first time we get the notification; it may be an initial scroll
  // to the origin after changing messages
  // to the origin after changing messages
  static BOOL sIsFirstTime = YES;
  static BOOL sIsFirstTime = YES;
 
 
  if ([NSViewBoundsDidChangeNotification isEqualToString:[inNotification name]] && sIsFirstTime) {
  if ([NSViewBoundsDidChangeNotification isEqualToString:[inNotification name]] && sIsFirstTime) {