Skip to content
Browse files

Fix memory leaks

1. Fixed some memory leaks (forgot to override dealloc)
2. Improved the reputation changes menu
  • Loading branch information...
1 parent 7126ea0 commit f765b32fbd44df1b4237b98742a242f778880c6d @BinyaminSharet committed May 1, 2012
View
1 SONotifier/Globals.h
@@ -45,6 +45,7 @@
// Reputation changes response
#define API_KEY_REPUTATION_CHANGE @"reputation_change"
#define API_KEY_REPUTATION_TITLE @"title"
+#define API_KEY_REPUTATION_POST_ID @"post_id"
// User info response
#define API_KEY_USER_ID @"user_id"
#define API_KEY_USER_TYPE @"user_type"
View
7 SONotifier/LinkMenuItem.m
@@ -33,6 +33,7 @@ - (NSAttributedString *) createTitleFromDictionary:(NSDictionary *)dict
NSColor * repColor;
NSNumber * reputation = [dict objectForKey:API_KEY_REPUTATION_CHANGE];
repColor = ([reputation intValue] > 0) ? [NSColor greenColor] : [NSColor redColor];
+ repColor = ([reputation intValue] == 0) ? [NSColor blackColor] : repColor;
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Helvetica" size:15], NSFontAttributeName,
repColor, NSForegroundColorAttributeName,
@@ -67,6 +68,12 @@ - (id) initFromDictionary:(NSDictionary *) dict
return self;
}
+- (void) dealloc
+{
+ [self setUrl:nil];
+ [super dealloc];
+}
+
- (IBAction)openUrl:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self url]]];
View
6 SONotifier/QuestionMenuItem.m
@@ -44,6 +44,12 @@ - (id) initFromDictionary:(NSDictionary *) dict
return self;
}
+- (void) dealloc
+{
+ [self setUrl:nil];
+ [super dealloc];
+}
+
- (IBAction)openUrl:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self url]]];
View
19 SONotifier/SettingsWindowController.m
@@ -30,29 +30,28 @@ - (id)init
self = [super initWithWindowNibName:@"SettingsWindow"];
if (self)
{
-
+ [super windowDidLoad];
+ [[self window] setDelegate:self];
+ storedLaunchState = ([@"YES" compare:[PersistantData retrieveFromUserDefaults:DATA_KEY_LAUNCH_AT_STARTUP]] == NSOrderedSame) ? NSOnState : NSOffState;
+ [launchAtStartUp setState:storedLaunchState];
+ NSNumber * intervals = [PersistantData retrieveFromUserDefaults:DATA_KEY_UPDATE_INTERVAL];
+ intervals = [NSNumber numberWithInt:[intervals intValue] / 60];
+ [updateIntervals setStringValue:[intervals stringValue]];
+ [[self window] center];
+ [[self window] setLevel:NSFloatingWindowLevel];
}
return self;
}
- (void)windowDidLoad
{
- [super windowDidLoad];
- [[self window] setDelegate:self];
- storedLaunchState = ([@"YES" compare:[PersistantData retrieveFromUserDefaults:DATA_KEY_LAUNCH_AT_STARTUP]] == NSOrderedSame) ? NSOnState : NSOffState;
- [launchAtStartUp setState:storedLaunchState];
- NSNumber * intervals = [PersistantData retrieveFromUserDefaults:DATA_KEY_UPDATE_INTERVAL];
- intervals = [NSNumber numberWithInt:[intervals intValue] / 60];
- [updateIntervals setStringValue:[intervals stringValue]];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
- (IBAction)showWindow:(id)sender
{
[super showWindow:sender];
- [[self window] center];
- [[self window] setLevel:NSFloatingWindowLevel];
}
- (IBAction)saveAndClose:(id)sender
View
2 SONotifier/UpdateManager.m
@@ -102,7 +102,7 @@ - (void) bgUpdate
}
NSLog(@"[UpdateManager/bgUpdate] Getting reputation changes");
- apiRequest = [NSString stringWithFormat:@"/users/%@/reputation?page=1&pagesize=7&site=stackoverflow&filter=!amIOctbmUQ-Bx0", userId];
+ apiRequest = [NSString stringWithFormat:@"/users/%@/reputation?page=1&pagesize=14&site=stackoverflow&filter=!amIOctbmUQ-Bx0", userId];
responseStr = [self getDataForApiRequest:apiRequest];
if (responseStr != nil)
View
20 SONotifier/UserData.m
@@ -59,9 +59,25 @@ - (BOOL) updateLastChangesFromJsonString:(NSString *)jsonString
NSArray * repArray = [data objectForKey:@"items"];
[reputationFromQuestions removeAllObjects];
[reputationFromAnswers removeAllObjects];
- for (NSDictionary * dict in repArray)
+ for (NSDictionary * origDict in repArray)
{
- if ([(NSNumber*)[dict objectForKey:API_KEY_REPUTATION_CHANGE] compare:[NSNumber numberWithInt:0]] != NSOrderedSame)
+ NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:origDict];
+ BOOL found = NO;
+ NSNumber * post_id = [dict objectForKey:API_KEY_REPUTATION_POST_ID];
+ for (NSMutableDictionary * addedDict in reputationFromAnswers)
+ {
+ if ([post_id compare:[addedDict objectForKey:API_KEY_REPUTATION_POST_ID]] == NSOrderedSame)
+ {
+ NSNumber * new_val = [NSNumber numberWithInt:
+ [[dict objectForKey:API_KEY_REPUTATION_CHANGE] intValue] +
+ [[addedDict objectForKey:API_KEY_REPUTATION_CHANGE] intValue]];
+ [addedDict setValue:new_val forKey:API_KEY_REPUTATION_CHANGE];
+ found = YES;
+ break;
+ }
+ }
+ if (found == NO)
+// if ([(NSNumber*)[dict objectForKey:API_KEY_REPUTATION_CHANGE] compare:[NSNumber numberWithInt:0]] != NSOrderedSame)
{
[reputationFromAnswers addObject:dict];
}

0 comments on commit f765b32

Please sign in to comment.
Something went wrong with that request. Please try again.