From 7ee0fe8deb4cce4876493815df943fc69ebaa200 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Mon, 20 Jul 2009 21:52:07 +0800 Subject: [PATCH] Added thank you / error sheets, thanking user for feedback of displaying an error on connection:didFailWithError:. Added new method displayAlertMessage:withInformativeText:andAlertStyle: so both success status and failure status could be routed through the same method with different texts. Added optional Growl support, displaying thank you in Growl notification, but left error in a sheet. Signed-off-by: Jonathan 'Wolf' Rentzsch --- lib/JRFeedbackController.h | 14 ++++++++++ lib/JRFeedbackController.m | 55 +++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/lib/JRFeedbackController.h b/lib/JRFeedbackController.h index bacc622..c0fe925 100644 --- a/lib/JRFeedbackController.h +++ b/lib/JRFeedbackController.h @@ -7,6 +7,15 @@ #import +/* + OPTIONAL: use Growl to post the 'thank you' message after feedback is sent. + If your app includes the Growl framework, set USE_GROWL to 1 and JRFeedbackController.m + will include the GrowlApplicationBridge.h file required, and post a Growl message when + the feedback is sent. + NOTE: you must add an entry to your Growl Dict plist to register this new message + */ +#define USE_GROWL 0 + typedef enum { JRFeedbackController_BugReport, JRFeedbackController_FeatureRequest, @@ -42,4 +51,9 @@ typedef enum { - (void)postFeedback:(NSString*)systemProfile; - (void)setTextViewStringTo:(NSString *)details; +- (void)displayAlertMessage:(NSString *)message + withInformativeText:(NSString *)text + andAlertStyle:(NSAlertStyle)alertStyle; + + @end diff --git a/lib/JRFeedbackController.m b/lib/JRFeedbackController.m index 8e9217c..a33289e 100644 --- a/lib/JRFeedbackController.m +++ b/lib/JRFeedbackController.m @@ -10,6 +10,10 @@ #import "NSURLRequest+postForm.h" #import +#if USE_GROWL + #import +#endif + JRFeedbackController *gFeedbackController = nil; NSString *JRFeedbackType[JRFeedbackController_SectionCount] = { @@ -223,13 +227,58 @@ - (IBAction)cancelAction:(id)sender { } - (void)connectionDidFinishLoading:(NSURLConnection*)connection { - // TODO Drop Thank you sheet - [self closeFeedback]; +#if USE_GROWL + [GrowlApplicationBridge setGrowlDelegate:@""]; + [GrowlApplicationBridge notifyWithTitle:@"Thank you!" + description:@"Your feedback has been sent" + notificationName:@"Feedback Sent" + iconData:nil + priority:0 + isSticky:NO + clickContext:nil]; + [self closeFeedback]; +#else + // drop thank you sheet + [self displayAlertMessage:@"Thank you for your feedback!" + withInformativeText:@"Your feedback has been sent" + andAlertStyle:NSInformationalAlertStyle]; +#endif +} + +- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo +{ + [self closeFeedback];//moved from connectionDidFinishLoading: +} + +- (void)displayAlertMessage:(NSString *)message + withInformativeText:(NSString *)text + andAlertStyle:(NSAlertStyle)alertStyle +{ + NSAlert *thankYouAlert = [[[NSAlert alloc] init] autorelease]; + [thankYouAlert addButtonWithTitle:@"OK"]; + [thankYouAlert setMessageText:message]; + [thankYouAlert setInformativeText:text]; + [thankYouAlert setAlertStyle:alertStyle]; + + // stop the animation of the progress indicator, so user doesn't think + // something is still going on + [progress stopAnimation:self]; + + // disply thank you + [thankYouAlert beginSheetModalForWindow:[gFeedbackController window] + modalDelegate:self + didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) + contextInfo:nil]; } - (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error { NSLog(@"-[JRFeedback connection:didFailWithError:%@]", error); - [self closeFeedback]; + + // drop fail sheet + [self displayAlertMessage:@"An Error Occured" + withInformativeText:@"There was a problem sending your feedback. Please try again at another time" + andAlertStyle:NSInformationalAlertStyle]; + } - (void)windowWillClose:(NSNotification*)notification {