Skip to content

Commit

Permalink
Improvements to Codeux-Software#307
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Aug 7, 2012
1 parent a62ce8d commit 70d4afb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 325 deletions.
20 changes: 12 additions & 8 deletions Classes/Headers/IRCWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,20 @@

- (void)destroyAllEvidence;

- (void)updateReadinessState:(TVCLogController *)controller;

- (TVCLogController *)createLogWithClient:(IRCClient *)client channel:(IRCChannel *)channel;
@end

#pragma mark -

@interface TKMessageBlockOperation : NSOperation
@property (nonatomic, retain) TVCLogController *controller;
@property (nonatomic, assign) BOOL special;
+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
withSpecialPriority:(BOOL)special;
+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller;
+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block;
@property (nonatomic, weak) TVCLogController *controller;

+ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
withSpecialPriority:(BOOL)special;

+ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller;
@end
3 changes: 0 additions & 3 deletions Classes/Headers/TPCPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ typedef enum TXHostmaskBanFormat : NSInteger {

+ (NSString *)gitBuildReference;

+ (TXNSDouble)viewLoopConsoleDelay;
+ (TXNSDouble)viewLoopChannelDelay;

+ (NSDictionary *)textualInfoPlist;
+ (NSDictionary *)systemInfoPlist;

Expand Down
93 changes: 64 additions & 29 deletions Classes/IRC/IRCWorld.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ - (id)init
self.clients = [NSMutableArray new];

self.messageOperationQueue = [NSOperationQueue new];

self.messageOperationQueue.name = @"IRCWordMessageOperationQueue";
self.messageOperationQueue.maxConcurrentOperationCount = 1;
// Only 1 at a time or else we get a race condition and out of order messages
}

return self;
Expand Down Expand Up @@ -1353,51 +1353,86 @@ - (void)serverListKeyDown:(NSEvent *)e
[self logKeyDown:e];
}

@end
#pragma mark -

@implementation TKMessageBlockOperation
+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
withSpecialPriority:(BOOL)special
{
TKMessageBlockOperation * retval = [TKMessageBlockOperation new];
retval.completionBlock = block;
retval.controller = controller;
retval.special = special;
retval.queuePriority = retval.priority;
return retval;
- (void)updateReadinessState:(TVCLogController *)controller
{
NSArray *queues = [self.messageOperationQueue operations];

for (TKMessageBlockOperation *op in queues) {
if (op.controller == controller) {
[op willChangeValueForKey:@"isReady"];
[op didChangeValueForKey:@"isReady"];
}
}
}

+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
{ return [self operationWithBlock:block forController:controller withSpecialPriority:NO]; }
@end

+ (TKMessageBlockOperation *) operationWithBlock:(void(^)(void))block
{ return [self operationWithBlock:block forController:nil withSpecialPriority:NO]; }
#pragma mark -

- (id) init
@interface TKMessageBlockOperation () /* @private */
@property (nonatomic, assign) BOOL isSpecial;
@end

@implementation TKMessageBlockOperation

+ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
withSpecialPriority:(BOOL)special
{
if (self = [super init]) {
self.special = NO;
if (PointerIsEmpty(controller) || PointerIsEmpty(block)) {
return nil;
}
return self;

TKMessageBlockOperation *retval = [TKMessageBlockOperation new];

retval.controller = controller;
retval.isSpecial = special;

retval.queuePriority = retval.priority;
retval.completionBlock = block;

return retval;
}

- (NSOperationQueuePriority) priority
+ (TKMessageBlockOperation *)operationWithBlock:(void(^)(void))block
forController:(TVCLogController *)controller
{
if (!self.controller) return NSOperationQueuePriorityVeryHigh;
id target = self.controller.channel ?: self.controller.client;
return [self operationWithBlock:block forController:controller withSpecialPriority:NO];
}

- (NSOperationQueuePriority)priority
{
id target = self.controller.channel;
id selected = self.controller.world.selected;

if (PointerIsEmpty(target)) {
target = self.controller.client;
}

// ---- //

NSOperationQueuePriority retval = NSOperationQueuePriorityLow;

if ((target || selected) && target == selected) retval += 4L;
if (self.special) retval += 4L;
// ---- //

if ((target || selected) && target == selected) {
retval += 4L;
}

if (self.isSpecial) {
retval += 4L;
}

// ---- //

return retval;
}

- (BOOL) isReady
- (BOOL)isReady
{
if (!self.controller) return YES;
return ([self.controller.view isLoading] == NO);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ + (void)convertExistingGlobalPreferences
[self.class migrateGlobalPreference:@"LogHighlights" from:@"Preferences.General.log_highlights"];
[self.class migrateGlobalPreference:@"LogTranscript" from:@"Preferences.General.log_transcript"];
[self.class migrateGlobalPreference:@"LogTranscriptDestination" from:@"Preferences.General.transcript_folder"];
[self.class migrateGlobalPreference:@"LogViewMessageQueueLoopDelay -> Channel" from:@"Preferences.Experimental.view_loop_channel_delay"];
[self.class migrateGlobalPreference:@"LogViewMessageQueueLoopDelay -> Console" from:@"Preferences.Experimental.view_loop_console_delay"];
[self.class migrateGlobalPreference:@"MainWindowTransparencyLevel" from:@"Preferences.Theme.transparency"];
[self.class migrateGlobalPreference:@"NicknameHighlightMatchingType" from:@"Preferences.Keyword.matching_method"];
[self.class migrateGlobalPreference:@"OpenClickedLinksInBackgroundBrowser" from:@"Preferences.General.open_browser_in_background"];
Expand Down
12 changes: 0 additions & 12 deletions Classes/Preferences/TPCPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -732,16 +732,6 @@ + (TXHostmaskBanFormat)banFormat
return (TXHostmaskBanFormat)[_NSUserDefaults() integerForKey:@"DefaultBanCommandHostmaskFormat"];
}

+ (TXNSDouble)viewLoopConsoleDelay
{
return [_NSUserDefaults() doubleForKey:@"LogViewMessageQueueLoopDelay -> Console"];
}

+ (TXNSDouble)viewLoopChannelDelay
{
return [_NSUserDefaults() doubleForKey:@"LogViewMessageQueueLoopDelay -> Channel"];
}

+ (BOOL)displayDockBadge
{
return [_NSUserDefaults() boolForKey:@"DisplayDockBadges"];
Expand Down Expand Up @@ -1390,8 +1380,6 @@ + (void)initPreferences
[d setInteger:TXNoticeSendServerConsoleType forKey:@"DestinationOfNonserverNotices"];
[d setInteger:TXUserDoubleClickQueryAction forKey:@"UserListDoubleClickAction"];

[d setDouble:0.05 forKey:@"LogViewMessageQueueLoopDelay -> Console"];
[d setDouble:0.07 forKey:@"LogViewMessageQueueLoopDelay -> Channel"];
[d setDouble:12.0 forKey:@"Theme -> Font Size"];
[d setDouble:1.0 forKey:@"MainWindowTransparencyLevel"];

Expand Down
38 changes: 23 additions & 15 deletions Classes/Views/Channel View/TVCLogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ - (void)writeLine:(id)line
if (PointerIsEmpty(body)) return nil;

// ---- //

if ([line isKindOfClass:GRMustacheTemplate.class]) {
attrs[@"lineNumber"] = @(self.lineNumber);

Expand All @@ -875,19 +875,19 @@ - (void)writeLine:(id)line

// ---- //

if (self.maxLines > 0 && (self.count - 10) > self.maxLines) {
[self setNeedsLimitNumberOfLines];
}
if (isSpecial == NO) {
if (self.maxLines > 0 && (self.count - 10) > self.maxLines) {
[self setNeedsLimitNumberOfLines];
}

if ([attrs[@"highlightAttributeRepresentation"] isEqualToString:@"true"]) {
[self.highlightedLineNumbers safeAddObject:@(self.lineNumber)];
}
if ([attrs[@"highlightAttributeRepresentation"] isEqualToString:@"true"]) {
[self.highlightedLineNumbers safeAddObject:@(self.lineNumber)];
}

[self executeScriptCommand:@"newMessagePostedToDisplay" withArguments:@[@(self.lineNumber)]];
[self executeScriptCommand:@"newMessagePostedToDisplay" withArguments:@[@(self.lineNumber)]];

// ---- //
// ---- //

if (isSpecial == NO) {
[self.logFile writePropertyListEntry:[context dictionaryValue]
toKey:[NSNumberWithInteger(self.lineNumber) integerWithLeadingZero:10]];
}
Expand All @@ -896,14 +896,17 @@ - (void)writeLine:(id)line
}

// ---- //

return nil;
} copy];

[self enqueueMessageBlock:messageBlock fromSender:self isSpecial:isSpecial];
}

- (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)sender
{ [self enqueueMessageBlock:messageBlock fromSender:sender isSpecial:NO]; }
{
[self enqueueMessageBlock:messageBlock fromSender:sender isSpecial:NO];
}

- (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)sender isSpecial:(BOOL)special
{
Expand All @@ -912,7 +915,7 @@ - (void)enqueueMessageBlock:(id)messageBlock fromSender:(TVCLogController *)send
} forController:sender withSpecialPriority:special]];
}

- (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special
- (void)handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special
{
// Internally, TVCLogMessageBlock should only return a
// BOOL as NSValue or NSString absolute value.
Expand All @@ -930,10 +933,11 @@ - (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special
// ---- //

if ([stslt isKindOfClass:NSString.class]) {
if (PointerIsNotEmpty(stslt)) {
if (NSObjectIsNotEmpty(stslt)) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self appendToDocumentBody:stslt];
}];

rrslt = YES;
}
} else {
Expand All @@ -942,7 +946,9 @@ - (void) handleMessageBlock:(id)messageBlock isSpecial:(BOOL)special

// ---- //

if (!rrslt) [self enqueueMessageBlock:messageBlock fromSender:self isSpecial:special];
if (rrslt == NO) {
[self enqueueMessageBlock:messageBlock fromSender:self isSpecial:special];
}
}

#pragma mark -
Expand Down Expand Up @@ -1104,6 +1110,8 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
[self executeScriptCommand:@"viewFinishedLoading" withArguments:@[]];

[self.world updateReadinessState:self];

self.loaded = YES;
self.loadingImages = 0;

Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
<string>12291</string>
<string>12318</string>
<key>TXBundleBuildReference</key>
<string>2.1.1-276-g6e71f93-debug</string>
<string>2.1.1-280-ga62ce8d-debug</string>
</dict>
</plist>
Loading

0 comments on commit 70d4afb

Please sign in to comment.