From 7a586f0eb1934d9b894c197bfdf424380afc195a Mon Sep 17 00:00:00 2001 From: GRMrGecko Date: Mon, 27 Sep 2010 08:10:24 -0500 Subject: [PATCH] Fixed issues with going to sleep, getting Google Contacts, quitting, and SMS Sound notifications. --- Classes/VoiceBase/SIP/MGMSIP.h | 2 +- Classes/VoiceBase/SIP/MGMSIP.m | 17 +++++++++-------- Classes/VoiceBase/XML/MGMXMLElement.m | 4 ++++ Classes/VoiceBase/XML/MGMXMLNode.h | 2 ++ Classes/VoiceBase/XML/MGMXMLNode.m | 17 +++++++++++++++-- Classes/VoiceMac/MGMVoiceUser.m | 5 +++++ Classes/VoiceMac/Preferences/MGMAccountsPane.m | 4 ++-- Classes/VoiceMac/Preferences/MGMSIPPane.m | 6 +++--- Classes/VoiceMac/SIP/MGMSIPUser.m | 5 +++++ Classes/VoiceMac/SMS/MGMSMSManager.m | 17 +++++++++++------ Classes/VoiceMac/SMS/MGMSMSMessageView.h | 2 +- Classes/VoiceMac/SMS/MGMSMSMessageView.m | 11 +++++++---- 12 files changed, 65 insertions(+), 27 deletions(-) diff --git a/Classes/VoiceBase/SIP/MGMSIP.h b/Classes/VoiceBase/SIP/MGMSIP.h index 07b5e9c..cc7d199 100644 --- a/Classes/VoiceBase/SIP/MGMSIP.h +++ b/Classes/VoiceBase/SIP/MGMSIP.h @@ -153,7 +153,7 @@ typedef enum { #if !TARGET_OS_IPHONE - (BOOL)setInputSoundDevice:(int)theInputDevice outputSoundDevice:(int)theOutputDevice; -- (BOOL)stopSound; +- (BOOL)stopAudio; - (void)updateAudioDevices; - (NSArray *)audioDevices; #endif diff --git a/Classes/VoiceBase/SIP/MGMSIP.m b/Classes/VoiceBase/SIP/MGMSIP.m index 512c3d8..c7e9ca3 100644 --- a/Classes/VoiceBase/SIP/MGMSIP.m +++ b/Classes/VoiceBase/SIP/MGMSIP.m @@ -617,19 +617,20 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void - (void)computerSleep { restartAccounts = [accounts copy]; - [self stopBackground]; + [accounts makeObjectsPerformSelector:@selector(logout)]; +#if !TARGET_OS_IPHONE + [self stopAudio]; +#endif } - (void)computerWake { +#if !TARGET_OS_IPHONE + [self updateAudioDevices]; +#endif if (restartAccounts!=nil) { - for (int i=0; i<[restartAccounts count]; i++) { - if (![accounts containsObject:[restartAccounts objectAtIndex:i]]) - [accounts addObject:[restartAccounts objectAtIndex:i]]; - } + [restartAccounts makeObjectsPerformSelector:@selector(login)]; [restartAccounts release]; restartAccounts = nil; } - - [self start]; } - (void)registerThread:(pj_thread_desc *)thePJThreadDesc { @@ -845,7 +846,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void bzero(&PJThreadDesc, sizeof(pj_thread_desc)); return (status==PJ_SUCCESS); } -- (BOOL)stopSound { +- (BOOL)stopAudio { if (state!=MGMSIPStartedState) return NO; diff --git a/Classes/VoiceBase/XML/MGMXMLElement.m b/Classes/VoiceBase/XML/MGMXMLElement.m index c84ecfd..233a6e6 100644 --- a/Classes/VoiceBase/XML/MGMXMLElement.m +++ b/Classes/VoiceBase/XML/MGMXMLElement.m @@ -60,6 +60,10 @@ NSString *prefix = [[self class] prefixForName:name]; NSString *uri = nil; if (prefix!=nil) { + if (MGMXMLNodePtr->doc==NULL) { + NSLog(@"You may not search for elements with a namespace if there is no document."); + return nil; + } xmlNsPtr namespace = xmlSearchNs(MGMXMLNodePtr->doc, MGMXMLNodePtr, [prefix xmlString]); if (namespace!=NULL) uri = [NSString stringWithXMLString:namespace->href]; diff --git a/Classes/VoiceBase/XML/MGMXMLNode.h b/Classes/VoiceBase/XML/MGMXMLNode.h index 2425465..54c0065 100644 --- a/Classes/VoiceBase/XML/MGMXMLNode.h +++ b/Classes/VoiceBase/XML/MGMXMLNode.h @@ -71,6 +71,7 @@ struct _xmlCom { xmlNsPtr namespaceXML; xmlNodePtr parentNode; MGMXMLNodeKind type; + MGMXMLNode *documentNode; } + (id)nodeWithTypeXMLPtr:(xmlTypPtr)theXMLPtr; - (id)initWithTypeXMLPtr:(xmlTypPtr)theXMLPtr; @@ -81,6 +82,7 @@ struct _xmlCom { + (void)removeChildrenFromNode:(xmlNodePtr)theNode; + (void)freeNode:(xmlNodePtr)theNode; - (void)setTypeXMLPtr:(xmlTypPtr)theXMLPtr; +- (void)releaseDocument; + (BOOL)isNode:(MGMXMLNodeKind)theType; - (BOOL)isNode; + (NSError *)lastError; diff --git a/Classes/VoiceBase/XML/MGMXMLNode.m b/Classes/VoiceBase/XML/MGMXMLNode.m index be35558..8ed85ca 100644 --- a/Classes/VoiceBase/XML/MGMXMLNode.m +++ b/Classes/VoiceBase/XML/MGMXMLNode.m @@ -84,6 +84,8 @@ static void MGMXMLErrorHandler(void *userData, xmlErrorPtr error) { parentNode = NULL; } if (commonXML!=NULL) { + if (type!=MGMXMLDocumentKind) + [self releaseDocument]; commonXML->_private = NULL; if (commonXML->parent==NULL) { @@ -91,7 +93,7 @@ static void MGMXMLErrorHandler(void *userData, xmlErrorPtr error) { xmlNodePtr child = commonXML->children; while (child!=NULL) { xmlNodePtr nextChild = child->next; - if (child->type == XML_ELEMENT_NODE) { + if (child->type==MGMXMLElementKind) { if (child->prev!=NULL) child->prev->next = child->next; if (child->next!=NULL) @@ -199,7 +201,10 @@ static void MGMXMLErrorHandler(void *userData, xmlErrorPtr error) { theNode->parent = NULL; theNode->prev = NULL; theNode->next = NULL; - if (theNode->doc!=NULL) [self stripDocumentFromNode:theNode]; + if (theNode->doc!=NULL) { + [(MGMXMLNode *)theNode->_private releaseDocument]; + [self stripDocumentFromNode:theNode]; + } } } } @@ -219,6 +224,14 @@ static void MGMXMLErrorHandler(void *userData, xmlErrorPtr error) { self->isa = [MGMXMLDocument class]; else if (type==MGMXMLElementKind && [self isMemberOfClass:[MGMXMLNode class]]) self->isa = [MGMXMLElement class]; + if (type!=MGMXMLDocumentKind) + documentNode = [[MGMXMLNode alloc] initWithTypeXMLPtr:(xmlTypPtr)commonXML->doc]; + } +} +- (void)releaseDocument { + if (documentNode!=nil) { + [documentNode release]; + documentNode = nil; } } + (BOOL)isNode:(MGMXMLNodeKind)theType { diff --git a/Classes/VoiceMac/MGMVoiceUser.m b/Classes/VoiceMac/MGMVoiceUser.m index 909de25..1845a32 100644 --- a/Classes/VoiceMac/MGMVoiceUser.m +++ b/Classes/VoiceMac/MGMVoiceUser.m @@ -60,6 +60,11 @@ NSString *MGMLastUserPhoneKey = @"MGMLastUserPhone"; } } - (void)dealloc { + if (progressFadeAnimation!=nil) { + [progressFadeAnimation stopAnimation]; + [progressFadeAnimation release]; + progressFadeAnimation = nil; + } [super dealloc]; if (instance!=nil) { [instance setDelegate:nil]; diff --git a/Classes/VoiceMac/Preferences/MGMAccountsPane.m b/Classes/VoiceMac/Preferences/MGMAccountsPane.m index 495a38b..d2fda81 100644 --- a/Classes/VoiceMac/Preferences/MGMAccountsPane.m +++ b/Classes/VoiceMac/Preferences/MGMAccountsPane.m @@ -83,7 +83,7 @@ NSString * const MGMLogout = @"Logout"; if ([[tableColumn identifier] isEqual:@"username"]) { #if MGMSIPENABLED NSArray *users = [MGMUser users]; - if ([users count]>=row) + if ([users count]<=row) return nil; MGMUser *user = [MGMUser userWithID:[users objectAtIndex:row]]; if ([[user settingForKey:MGMSAccountType] isEqual:MGMSSIP]) { @@ -94,7 +94,7 @@ NSString * const MGMLogout = @"Logout"; return [[MGMUser userNames] objectAtIndex:row]; } else if ([[tableColumn identifier] isEqual:@"state"]) { NSDictionary *users = [MGMUser usersPlist]; - if ([[users allKeys] count]>=row) + if ([[users allKeys] count]<=row) return nil; return ([[users objectForKey:[[users allKeys] objectAtIndex:row]] boolValue] ? @"✓" : @""); } diff --git a/Classes/VoiceMac/Preferences/MGMSIPPane.m b/Classes/VoiceMac/Preferences/MGMSIPPane.m index 8ca50a3..fe39c50 100644 --- a/Classes/VoiceMac/Preferences/MGMSIPPane.m +++ b/Classes/VoiceMac/Preferences/MGMSIPPane.m @@ -61,7 +61,7 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; if (shouldRestart) { - /*NSAlert *alert = [[NSAlert new] autorelease]; + NSAlert *alert = [[NSAlert new] autorelease]; [alert setMessageText:@"Restart Required"]; [alert setInformativeText:@"You have changed some settings that requires you to restart VoiceMac for them to take place, do you want to restart VoiceMac now?"]; [alert addButtonWithTitle:@"Yes"]; @@ -73,8 +73,8 @@ NSString *relaunchPath = [[[NSBundle bundleWithIdentifier:@"org.andymatuschak.Sparkle"] resourcePath] stringByAppendingPathComponent:@"relaunch"]; [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]]; [[NSApplication sharedApplication] terminate:self]; - }*/ - [[MGMSIP sharedSIP] restart]; + } + //[[MGMSIP sharedSIP] restart]; } if (mainView!=nil) [mainView release]; diff --git a/Classes/VoiceMac/SIP/MGMSIPUser.m b/Classes/VoiceMac/SIP/MGMSIPUser.m index 47bdf68..ffc365b 100644 --- a/Classes/VoiceMac/SIP/MGMSIPUser.m +++ b/Classes/VoiceMac/SIP/MGMSIPUser.m @@ -62,6 +62,11 @@ NSString * const MGMSIPUserAreaCode = @"MGMVSIPUserAreaCode"; } } - (void)dealloc { + if (progressFadeAnimation!=nil) { + [progressFadeAnimation stopAnimation]; + [progressFadeAnimation release]; + progressFadeAnimation = nil; + } [super dealloc]; if (calls!=nil) { [calls removeAllObjects]; diff --git a/Classes/VoiceMac/SMS/MGMSMSManager.m b/Classes/VoiceMac/SMS/MGMSMSManager.m index f6d24cb..b2134b1 100644 --- a/Classes/VoiceMac/SMS/MGMSMSManager.m +++ b/Classes/VoiceMac/SMS/MGMSMSManager.m @@ -144,6 +144,7 @@ const float updateTimeInterval = 300.0; } NSDate *newestDate = [NSDate distantPast]; BOOL newMessage = NO; + BOOL newTab = NO; for (unsigned int i=0; i<[theMessages count]; i++) { if ([lastDates objectForKey:[theInstance userNumber]]==nil || (![[lastDates objectForKey:[theInstance userNumber]] isEqual:[[theMessages objectAtIndex:i] objectForKey:MGMITime]] && [[lastDates objectForKey:[theInstance userNumber]] earlierDate:[[theMessages objectAtIndex:i] objectForKey:MGMITime]]==[lastDates objectForKey:[theInstance userNumber]])) { NSMutableDictionary *messageInfo = [NSMutableDictionary dictionaryWithDictionary:[theMessages objectAtIndex:i]]; @@ -151,16 +152,18 @@ const float updateTimeInterval = 300.0; [messageInfo removeObjectForKey:MGMIMessages]; [messageInfo setObject:[[theInstance contacts] nameForNumber:[messageInfo objectForKey:MGMIPhoneNumber]] forKey:MGMTInName]; [messageInfo setObject:[theInstance userNumber] forKey:MGMTUserNumber]; - BOOL window = NO; + BOOL tab = NO; for (unsigned int m=0; m<[SMSMessages count]; m++) { if ([[[[SMSMessages objectAtIndex:m] messageInfo] objectForKey:MGMIPhoneNumber] isEqual:[messageInfo objectForKey:MGMIPhoneNumber]] && ([[[[SMSMessages objectAtIndex:m] messageInfo] objectForKey:MGMIID] isEqual:[messageInfo objectForKey:MGMIID]] || [[[[SMSMessages objectAtIndex:m] messageInfo] objectForKey:MGMIID] isEqual:@""]) && [[SMSMessages objectAtIndex:m] instance]==theInstance) { - window = YES; - [[SMSMessages objectAtIndex:m] updateWithMessages:messages messageInfo:messageInfo]; + tab = YES; + if ([[SMSMessages objectAtIndex:m] updateWithMessages:messages messageInfo:messageInfo]) + newMessage = YES; break; } } - if (!window && ![[[theMessages objectAtIndex:i] objectForKey:MGMIRead] boolValue]) { + if (!tab && ![[[theMessages objectAtIndex:i] objectForKey:MGMIRead] boolValue]) { newMessage = YES; + newTab = YES; [SMSMessages addObject:[MGMSMSMessageView viewWithManager:self messages:messages messageInfo:messageInfo instance:theInstance]]; } if ([newestDate earlierDate:[[theMessages objectAtIndex:i] objectForKey:MGMITime]]==newestDate) @@ -168,10 +171,12 @@ const float updateTimeInterval = 300.0; } } if (newMessage) { - [self loadWindow]; [lastDates setObject:newestDate forKey:[theInstance userNumber]]; - [self reloadData]; [[controller themeManager] playSound:MGMTSSMSMessage]; + } + if (newTab) { + [self loadWindow]; + [self reloadData]; [SMSWindow makeKeyAndOrderFront:self]; } } diff --git a/Classes/VoiceMac/SMS/MGMSMSMessageView.h b/Classes/VoiceMac/SMS/MGMSMSMessageView.h index b20a771..64f4a0f 100644 --- a/Classes/VoiceMac/SMS/MGMSMSMessageView.h +++ b/Classes/VoiceMac/SMS/MGMSMSMessageView.h @@ -41,7 +41,7 @@ - (void)sendNotifications; -- (void)updateWithMessages:(NSArray *)theMessages messageInfo:(NSDictionary *)theMessageInfo; +- (BOOL)updateWithMessages:(NSArray *)theMessages messageInfo:(NSDictionary *)theMessageInfo; - (void)buildHTML; - (void)addMessage:(NSDictionary *)theMessage; diff --git a/Classes/VoiceMac/SMS/MGMSMSMessageView.m b/Classes/VoiceMac/SMS/MGMSMSMessageView.m index ca2e1e7..3d641d2 100644 --- a/Classes/VoiceMac/SMS/MGMSMSMessageView.m +++ b/Classes/VoiceMac/SMS/MGMSMSMessageView.m @@ -97,27 +97,30 @@ } } -- (void)updateWithMessages:(NSArray *)theMessages messageInfo:(NSDictionary *)theMessageInfo { +- (BOOL)updateWithMessages:(NSArray *)theMessages messageInfo:(NSDictionary *)theMessageInfo { + BOOL newIncomingMessages = NO; if (![[theMessageInfo objectForKey:MGMITime] isEqual:[messageInfo objectForKey:MGMITime]]) { if (messageInfo!=nil) [messageInfo release]; messageInfo = [theMessageInfo mutableCopy]; - BOOL read = [[messageInfo objectForKey:MGMIRead] boolValue]; - [self setRead:read]; + [self setRead:[[messageInfo objectForKey:MGMIRead] boolValue]]; BOOL rebuild = [[[[manager themeManager] variant] objectForKey:MGMTRebuild] boolValue]; BOOL newMessages = NO; for (unsigned int i=[messages count]; i<[theMessages count]; i++) { newMessages = YES; [messages addObject:[theMessages objectAtIndex:i]]; + if (![[[theMessages objectAtIndex:i] objectForKey:MGMIYou] boolValue]) + newIncomingMessages = YES; if (!rebuild) [self addMessage:[messages lastObject]]; } if (newMessages && rebuild) [self buildHTML]; - if (!read) + if (newIncomingMessages) [self sendNotifications]; } + return newIncomingMessages; } - (void)updatedTheme:(NSNotification *)theNotification {