Skip to content

Commit

Permalink
Merge from canonical repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ddribin committed May 25, 2009
2 parents 0c5f868 + be73d79 commit 1979d4c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 83 deletions.
9 changes: 9 additions & 0 deletions README.markdown
Expand Up @@ -14,6 +14,15 @@ Please [report bugs and request features](http://rentzsch.lighthouseapp.com/proj

##Version History

* **1.5**
* [NEW] Use SystemConfiguration.framework to ensure feedback host reachablity before presenting panel. (rentzsch)

* [NEW] Disable contact fields, when "Include contact info:" is unchecked. Switch to bindings for include email address. (Dave Dribin)

* [CHANGE] Put user name in seperate field since PHP's `is_valid_email()` doesn't understand proper RFC-822. Don't POST name, email or systemProfile fields if they're empty. Finally: s/includeEmailAddress/includeContactInfo ivar and IBOutlet. (rentzsch)

* [FIX] Condition inversion in jrfeedback.php dealing with email addresses. (rentzsch)

* **1.4**
* [NEW] Add field for the submitter's name, auto-populated from the address book. (Victoria Wang)

Expand Down
6 changes: 3 additions & 3 deletions demo/Info.plist
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
Expand All @@ -24,7 +24,7 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>JRFeedbackURL</key>
<string>http://localhost/~wolf/jrfeedback.php</string>
<key>JRFeedbackURL</key>
<string>http://localhost/~wolf/jrfeedback.php</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions demo/JRFeedbackProvider.xcodeproj/project.pbxproj
Expand Up @@ -12,6 +12,7 @@
795A7F92099D0E3600450061 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 795A7F91099D0E3600450061 /* AppController.m */; };
796F33960DAE7686005201F5 /* JRFeedbackController.m in Sources */ = {isa = PBXBuildFile; fileRef = 796F33950DAE7686005201F5 /* JRFeedbackController.m */; };
797DF7F10DCA61E0006A6500 /* JRFeedbackProvider.xib in Resources */ = {isa = PBXBuildFile; fileRef = 797DF7F00DCA61E0006A6500 /* JRFeedbackProvider.xib */; };
79E889440FAE38A100EFE883 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 79E889430FAE38A100EFE883 /* SystemConfiguration.framework */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
Expand All @@ -35,6 +36,7 @@
796F33940DAE7686005201F5 /* JRFeedbackController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JRFeedbackController.h; path = ../lib/JRFeedbackController.h; sourceTree = "<group>"; };
796F33950DAE7686005201F5 /* JRFeedbackController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JRFeedbackController.m; path = ../lib/JRFeedbackController.m; sourceTree = "<group>"; };
797DF7F00DCA61E0006A6500 /* JRFeedbackProvider.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = JRFeedbackProvider.xib; path = ../lib/JRFeedbackProvider.xib; sourceTree = "<group>"; };
79E889430FAE38A100EFE883 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* JRFeedbackProvider.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JRFeedbackProvider.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand All @@ -46,6 +48,7 @@
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
793C54BF0DC1281400E810BB /* AddressBook.framework in Frameworks */,
79E889440FAE38A100EFE883 /* SystemConfiguration.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -68,6 +71,7 @@
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
79E889430FAE38A100EFE883 /* SystemConfiguration.framework */,
793C54BE0DC1281400E810BB /* AddressBook.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
Expand Down
4 changes: 2 additions & 2 deletions jrfeedback.php
Expand Up @@ -22,9 +22,9 @@
// TODO: It'd be nice to make sure the string looks like a
// real email address but I'll assume everyone is playing nice.
if ($_REQUEST['email'] == '') {
$email = $_REQUEST['email'];
} else {
$email = 'YOUR_EMAIL_ADDRESS_HERE@gmail.com';
} else {
$email = $_REQUEST['email'];
}
$feedback = $_REQUEST['feedback'];
$bundleID = $_REQUEST['bundleID'];
Expand Down
14 changes: 7 additions & 7 deletions lib/JRFeedbackController.h
@@ -1,9 +1,9 @@
/*******************************************************************************
JRFeedbackController.h
Copyright (c) 2008-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
JRFeedbackController.h
Copyright (c) 2008-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
***************************************************************************/

#import <Cocoa/Cocoa.h>

Expand All @@ -23,14 +23,14 @@ typedef enum {

NSAttributedString *sectionStrings[JRFeedbackController_SectionCount];
JRFeedbackController_Section currentSection;
BOOL includeEmailAddress;
BOOL includeContactInfo;
}

+ (void)showFeedback;
+ (void)showFeedbackWithBugDetails:(NSString *)details;

- (BOOL)includeEmailAddress;
- (void)setIncludeEmailAddress:(BOOL)flag;
- (BOOL)includeContactInfo;
- (void)setIncludeContactInfo:(BOOL)flag;

- (IBAction)switchSectionAction:(NSSegmentedControl*)sender;
- (IBAction)submitAction:(id)sender;
Expand Down
142 changes: 86 additions & 56 deletions lib/JRFeedbackController.m
@@ -1,15 +1,14 @@
/*******************************************************************************
JRFeedbackController.m
Copyright (c) 2008-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
JRFeedbackController.m
Copyright (c) 2008-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
***************************************************************************/

#import "JRFeedbackController.h"
#import <AddressBook/AddressBook.h>
#import "NSURLRequest+postForm.h"

// TODO Sys Config network presensce
#import <SystemConfiguration/SCNetwork.h>

JRFeedbackController *gFeedbackController = nil;

Expand All @@ -19,29 +18,57 @@
@"SUPPORT" // JRFeedbackController_SupportRequest
};

@interface JRFeedbackController ()
+ (NSURL*)postURL;
@end

@implementation JRFeedbackController

+ (void)showFeedback {
if (!gFeedbackController) {
gFeedbackController = [[JRFeedbackController alloc] init];
}
[gFeedbackController showWindow:self];
[self showFeedbackWithBugDetails:nil];
}

+ (void)showFeedbackWithBugDetails:(NSString *)details {
if (!gFeedbackController) {
gFeedbackController = [[JRFeedbackController alloc] init];
SCNetworkConnectionFlags reachabilityFlags;
Boolean reachabilityResult = SCNetworkCheckReachabilityByName([[[JRFeedbackController postURL] host] UTF8String], &reachabilityFlags);

//NSLog(@"reachabilityFlags: %lx", reachabilityFlags);
BOOL showFeedbackWindow = reachabilityResult
&& (reachabilityFlags & kSCNetworkFlagsReachable)
&& !(reachabilityFlags & kSCNetworkFlagsConnectionRequired)
&& !(reachabilityFlags & kSCNetworkFlagsConnectionAutomatic)
&& !(reachabilityFlags & kSCNetworkFlagsInterventionRequired);

if (!showFeedbackWindow) {
int alertResult = [[NSAlert alertWithMessageText:@"Feedback Host Not Reachable"
defaultButton:@"Proceed Anyway"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"You may not be able to send feedback because %@ isn't reachable.\n\nPlease ensure you have a network connection before proceeding.\n", [[JRFeedbackController postURL] host]
] runModal];
if (NSAlertDefaultReturn == alertResult) {
showFeedbackWindow = YES;
}
}

if (showFeedbackWindow) {
if (!gFeedbackController) {
gFeedbackController = [[JRFeedbackController alloc] init];
}
[gFeedbackController showWindow:self];

// There is an assumption here that bug report is the first and default view of the window.
if (details) {
[gFeedbackController setTextViewStringTo:details];
}
}
[gFeedbackController showWindow:self];
// There is an assumption here that bug report is the first and default view of the window.
[gFeedbackController setTextViewStringTo:details];
}

- (id)init {
self = [super initWithWindowNibName:@"JRFeedbackProvider"];
if (self) {
//[self window];
includeEmailAddress = YES;
includeContactInfo = YES;
}
return self;
}
Expand Down Expand Up @@ -83,11 +110,11 @@ - (void)windowDidLoad {
}
}

- (BOOL)includeEmailAddress {
return includeEmailAddress;
- (BOOL)includeContactInfo {
return includeContactInfo;
}
- (void)setIncludeEmailAddress:(BOOL)flag {
includeEmailAddress = flag;
- (void)setIncludeContactInfo:(BOOL)flag {
includeContactInfo = flag;
}

- (IBAction)switchSectionAction:(NSSegmentedControl*)sender {
Expand All @@ -100,7 +127,7 @@ - (IBAction)switchSectionAction:(NSSegmentedControl*)sender {
[textView moveDown:self];

if (JRFeedbackController_SupportRequest == currentSection) {
[self setIncludeEmailAddress:YES];
[self setIncludeContactInfo:YES];
}
}

Expand All @@ -112,13 +139,13 @@ - (IBAction)submitAction:(id)sender {
[progress startAnimation:self];

// if they checked not to include hardware, don't scan. Post right away.
if ([includeHardwareDetailsCheckbox intValue] == 1) {
[NSThread detachNewThreadSelector:@selector(system_profilerThread:)
toTarget:self
withObject:nil];
} else {
[self postFeedback:@"<systemProfile suppressed>"];
}
if ([includeHardwareDetailsCheckbox intValue] == 1) {
[NSThread detachNewThreadSelector:@selector(system_profilerThread:)
toTarget:self
withObject:nil];
} else {
[self postFeedback:@"<systemProfile suppressed>"];
}
}

- (void)system_profilerThread:(id)ignored {
Expand Down Expand Up @@ -146,28 +173,27 @@ - (void)system_profilerThread:(id)ignored {
}

- (void)postFeedback:(NSString*)systemProfile {
NSString *postURL = [[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"JRFeedbackURL"];
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"JRFeedbackURL"]) {
postURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"JRFeedbackURL"];
}

NSString *email = @"<email suppressed>";
NSString *name = @"<name suppressed>";
if ([self includeEmailAddress]) {
email = [emailAddressComboBox stringValue];
name = [nameTextField stringValue];
NSMutableDictionary *form = [NSMutableDictionary dictionaryWithObjectsAndKeys:
JRFeedbackType[currentSection], @"feedbackType",
[sectionStrings[currentSection] string], @"feedback",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleName"], @"appName",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleIdentifier"], @"bundleID",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleVersion"], @"version",
nil];
if (systemProfile) {
[form setObject:systemProfile forKey:@"systemProfile"];
}
NSDictionary *form = [NSDictionary dictionaryWithObjectsAndKeys:
JRFeedbackType[currentSection], @"feedbackType",
[sectionStrings[currentSection] string], @"feedback",
email, @"email",
name, @"name",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleName"], @"appName",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleIdentifier"], @"bundleID",
[[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleVersion"], @"version",
systemProfile, @"systemProfile",
nil];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:postURL] postForm:form];
if ([self includeContactInfo]) {
if ([[emailAddressComboBox stringValue] length]) {
[form setObject:[emailAddressComboBox stringValue] forKey:@"email"];
}
if ([[nameTextField stringValue] length]) {
[form setObject:[nameTextField stringValue] forKey:@"name"];
}
}

NSURLRequest *request = [NSURLRequest requestWithURL:[JRFeedbackController postURL] postForm:form];
[NSURLConnection connectionWithRequest:request delegate:self];
}

Expand Down Expand Up @@ -200,14 +226,18 @@ - (void)windowWillClose:(NSNotification*)notification {

- (void)setTextViewStringTo:(NSString *)details
{
// TODO: doing this makes all the text bold, I'm not hip to the attr string stuff done in this class
// so it's not easy for me to fix.
[textView setString:details];
// TODO: doing this makes all the text bold, I'm not hip to the attr string stuff done in this class
// so it's not easy for me to fix.
[textView setString:details];
}

@end
+ (NSURL*)postURL {
NSString *postURLString = [[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"JRFeedbackURL"];
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"JRFeedbackURL"]) {
postURLString = [[NSUserDefaults standardUserDefaults] stringForKey:@"JRFeedbackURL"];
}
NSAssert(postURLString, @"JRFeedbackURL not defined");
return [NSURL URLWithString:postURLString];
}

#if 0
#import <SystemConfiguration/SCNetwork.h>
SCNetworkCheckReachabilityByName
#endif
@end

0 comments on commit 1979d4c

Please sign in to comment.