Skip to content

Commit

Permalink
Added thank you / error sheets, thanking user for feedback of display…
Browse files Browse the repository at this point in the history
…ing 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 <jwr.git@redshed.net>
  • Loading branch information
catsby authored and rentzsch committed Jul 21, 2009
1 parent 86b6ed6 commit 7ee0fe8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/JRFeedbackController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

#import <Cocoa/Cocoa.h>

/*
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,
Expand Down Expand Up @@ -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
55 changes: 52 additions & 3 deletions lib/JRFeedbackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#import "NSURLRequest+postForm.h"
#import <SystemConfiguration/SCNetwork.h>

#if USE_GROWL
#import <Growl/GrowlApplicationBridge.h>
#endif

JRFeedbackController *gFeedbackController = nil;

NSString *JRFeedbackType[JRFeedbackController_SectionCount] = {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7ee0fe8

Please sign in to comment.