Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@property (retain) Repository *repository;

+ (Commit *) commitFromDictionary: (NSDictionary *) dictionary;
+ (NSArray *) chooseRelevantCommits: (NSArray *) commits forUser: (NSString *) userEmail;
+ (NSArray *) chooseRelevantCommits: (NSArray *) commits forUserEmails: (NSArray *) userEmails;

- (BOOL) isMergeCommit;
- (NSDictionary *) toDictionary;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Commit.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ + (NSArray *) propertyList {
return PSArray(@"authorName", @"authorEmail", @"subject", @"gitHash", @"date", @"repository");
}

+ (NSArray *) chooseRelevantCommits: (NSArray *) commits forUser: (NSString *) userEmail {
+ (NSArray *) chooseRelevantCommits: (NSArray *) commits forUserEmails: (NSArray *) userEmails {
BOOL ignoreMerges = [GitifierDefaults boolForKey: IgnoreMergesKey];
BOOL ignoreOwnCommits = [GitifierDefaults boolForKey: IgnoreOwnCommitsKey];
NSMutableArray *relevantCommits = [NSMutableArray arrayWithCapacity: commits.count];

for (Commit *commit in commits) {
if (ignoreMerges && [commit isMergeCommit]) continue;
if (ignoreOwnCommits && [commit.authorEmail isEqualToString: userEmail]) continue;
if (ignoreOwnCommits && [userEmails containsObject:commit.authorEmail]) continue;

[relevantCommits addObject: commit];
}
Expand Down
5 changes: 3 additions & 2 deletions Classes/GitifierAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
@class StatusBarController;

@interface GitifierAppDelegate : NSObject <NSApplicationDelegate> {
NSString *userEmail;
NSString *userEmailFromGit;
NSMutableArray *repositoryList;
Monitor *monitor;
StatusBarController *statusBarController;
PreferencesWindowController *preferencesWindowController;
RepositoryListController *repositoryListController;
}

@property (readonly) NSString *userEmail;
@property (assign) NSMutableArray *repositoryList;
@property IBOutlet Monitor *monitor;
@property IBOutlet StatusBarController *statusBarController;
@property IBOutlet PreferencesWindowController *preferencesWindowController;
@property IBOutlet RepositoryListController *repositoryListController;

@property (nonatomic, readonly, retain) NSArray *userEmailAddresses;

// public
- (IBAction) showPreferences: (id) sender;
- (IBAction) quit: (id) sender;
Expand Down
60 changes: 55 additions & 5 deletions Classes/GitifierAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
#import "RepositoryListController.h"
#import "StatusBarController.h"

#import <AddressBook/AddressBook.h>

static NSString *SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
static NSString *SUSendProfileInfoKey = @"SUSendProfileInfo";
static CGFloat IntervalBetweenGrowls = 0.05;

@implementation GitifierAppDelegate

@synthesize monitor, userEmail, preferencesWindowController, statusBarController, repositoryListController,
@synthesize monitor, preferencesWindowController, statusBarController, repositoryListController,
repositoryList;

// --- initialization and termination ---
Expand Down Expand Up @@ -138,7 +140,7 @@ - (IBAction) quit: (id) sender {
// --- user email management ---

- (void) updateUserEmail {
if (!userEmail && [Git gitExecutable]) {
if (!userEmailFromGit && [Git gitExecutable]) {
Git *git = [[Git alloc] initWithDelegate: self];
[git runCommand: @"config" withArguments: PSArray(@"user.email") inPath: NSHomeDirectory()];
}
Expand Down Expand Up @@ -211,8 +213,8 @@ - (void) rejectGitPath {
- (void) commandCompleted: (NSString *) command output: (NSString *) output {
if ([command isEqual: @"config"]) {
if (output && output.length > 0) {
userEmail = [output psTrimmedString];
PSNotifyWithData(UserEmailChangedNotification, PSHash(@"email", userEmail));
userEmailFromGit = [output psTrimmedString];
PSNotifyWithData(UserEmailChangedNotification, PSHash(@"emails", self.userEmailAddresses));
}
} else if ([command isEqual: @"version"]) {
if (!output || ![output isMatchedByRegex: @"^git version \\d"]) {
Expand All @@ -227,13 +229,61 @@ - (void) commandFailed: (NSString *) command output: (NSString *) output {
}
}

- (NSArray *)userEmailsFromAddressBook
{
ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
ABPerson *mePerson = [addressBook me];
NSMutableArray *userEmailsToReturn = nil;
if (mePerson != nil) {
ABMultiValue *emailMultiValue = [mePerson valueForProperty:kABEmailProperty];
for (NSString *identifier in emailMultiValue)
{
NSString *emailAddress = [[emailMultiValue valueForIdentifier:identifier] psTrimmedString];
if ([emailAddress length] > 0) {
if (userEmailsToReturn == nil) {
userEmailsToReturn = [NSMutableArray array];
}
[userEmailsToReturn addObject:emailAddress];
}
}
}
return userEmailsToReturn;
}

- (NSArray *)userEmailAddresses
{
NSMutableArray *emailsToReturn = nil;
NSString *gitEmail = userEmailFromGit;
if (gitEmail != nil) {
if (emailsToReturn == nil) {
emailsToReturn = [NSMutableArray array];
}
[emailsToReturn addObject:gitEmail];
}

NSArray *addressBookEmails = [self userEmailsFromAddressBook];
if ([addressBookEmails count] > 0)
{
for (NSString *emailFromAddressBook in addressBookEmails) {
if (emailsToReturn == nil) {
emailsToReturn = [NSMutableArray array];
}
if ([emailsToReturn containsObject:emailFromAddressBook] == NO) {
[emailsToReturn addObject:emailFromAddressBook];
}
}
}
return emailsToReturn;
}


// --- repository callbacks ---

- (void) commitsReceived: (NSArray *) commits inRepository: (Repository *) repository {
BOOL hasNotificationLimit = [GitifierDefaults boolForKey: NotificationLimitEnabledKey];
NSInteger notificationLimit = [GitifierDefaults integerForKey: NotificationLimitValueKey];

NSArray *relevantCommits = [Commit chooseRelevantCommits: commits forUser: userEmail];
NSArray *relevantCommits = [Commit chooseRelevantCommits: commits forUserEmails: self.userEmailAddresses];
NSArray *displayedCommits, *remainingCommits;

if (hasNotificationLimit && relevantCommits.count > notificationLimit) {
Expand Down
4 changes: 0 additions & 4 deletions Classes/NotificationsPanelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
@property IBOutlet NSButton *ignoreOwnEmailsField;
@property IBOutlet NSView *growlInfoPanel;

// public
- (IBAction) getGrowlButtonPressed: (id) sender;
- (void) updateGrowlInfoPanel;

// private
- (void) updateUserEmailText: (NSString *) email;

@end
22 changes: 16 additions & 6 deletions Classes/NotificationsPanelController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
static NSString *IgnoreMyCommitsText = @"Ignore my own commits";
static NSString *GrowlAppStoreURL = @"macappstore://itunes.apple.com/us/app/growl/id467939042";

@interface NotificationsPanelController ()
- (void)updateUserEmailText:(NSArray *)emailAddresses;
@end

@implementation NotificationsPanelController
@synthesize growlInfoPanel, ignoreOwnEmailsField;

Expand All @@ -21,7 +25,7 @@ - (id) init {
}

- (void) awakeFromNib {
[self updateUserEmailText: [[NSApp delegate] userEmail]];
[self updateUserEmailText:[[NSApp delegate] userEmailAddresses]];
PSObserve(nil, UserEmailChangedNotification, userEmailChanged:);
}

Expand All @@ -38,13 +42,13 @@ - (NSString *) toolbarItemLabel {
}

- (void) userEmailChanged: (NSNotification *) notification {
NSString *email = [notification.userInfo objectForKey: @"email"];
[self updateUserEmailText: email];
NSArray *userEmailAddresses = [notification.userInfo objectForKey:@"emails"];
[self updateUserEmailText:userEmailAddresses];
}

- (void) updateUserEmailText: (NSString *) email {
if (email) {
NSString *title = PSFormat(@"%@ (%@)", IgnoreMyCommitsText, email);
- (void) updateUserEmailText:(NSArray *)emailAddresses {
if ([emailAddresses count] > 0) {
NSString *title = PSFormat(@"%@ (%@)", IgnoreMyCommitsText, [emailAddresses componentsJoinedByString:@","]);
NSInteger labelLength = IgnoreMyCommitsText.length;
NSRange labelRange = NSMakeRange(0, labelLength);
NSRange emailRange = NSMakeRange(labelLength, title.length - labelLength);
Expand All @@ -57,6 +61,12 @@ - (void) updateUserEmailText: (NSString *) email {
[text addAttribute: NSFontAttributeName value: standardFont range: labelRange];
[text addAttribute: NSFontAttributeName value: smallerFont range: emailRange];
[text addAttribute: NSForegroundColorAttributeName value: gray range: emailRange];

NSMutableParagraphStyle *paragraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];

[text addAttribute: NSParagraphStyleAttributeName value:paragraphStyle range: NSMakeRange(0, [text length])];

ignoreOwnEmailsField.attributedTitle = text;
} else {
ignoreOwnEmailsField.title = IgnoreMyCommitsText;
Expand Down
6 changes: 6 additions & 0 deletions Gitifier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
D46B06921595581A00E42A1F /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D46B06911595581A00E42A1F /* AddressBook.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -222,6 +223,7 @@
58E81DC3128B2B7000062F15 /* LinkLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LinkLabel.m; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Gitifier-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Gitifier-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Gitifier.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Gitifier.app; sourceTree = BUILT_PRODUCTS_DIR; };
D46B06911595581A00E42A1F /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -237,6 +239,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D46B06921595581A00E42A1F /* AddressBook.framework in Frameworks */,
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
58DEC0591242B6EB00DE7C7E /* libicucore.dylib in Frameworks */,
58DEC0C61242C16600DE7C7E /* Growl.framework in Frameworks */,
Expand All @@ -251,6 +254,7 @@
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
D46B06911595581A00E42A1F /* AddressBook.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
Expand Down Expand Up @@ -286,8 +290,10 @@
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
indentWidth = 2;
name = Gitifier;
sourceTree = "<group>";
tabWidth = 4;
};
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
Expand Down
28 changes: 15 additions & 13 deletions NotificationsPreferencesPanel.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1070</int>
<string key="IBDocument.SystemVersion">11C74</string>
<string key="IBDocument.InterfaceBuilderVersion">1938</string>
<string key="IBDocument.AppKitVersion">1138.23</string>
<string key="IBDocument.HIToolboxVersion">567.00</string>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">1938</string>
<string key="NS.object.0">2182</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -59,6 +59,7 @@
<string key="NSFrame">{{0, 18}, {485, 5}}</string>
<reference key="NSSuperview" ref="99672514"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="996414272"/>
<string key="NSOffsets">{0, 0}</string>
<object class="NSTextFieldCell" key="NSTitleCell">
<int key="NSCellFlags">67239424</int>
Expand Down Expand Up @@ -265,7 +266,7 @@
<string>nilSymbol</string>
<string>positiveInfinitySymbol</string>
</object>
<object class="NSMutableArray" key="dict.values">
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<boolean value="YES"/>
<integer value="1040"/>
Expand Down Expand Up @@ -358,6 +359,7 @@
<string key="NSFrame">{{163, 18}, {196, 18}}</string>
<reference key="NSSuperview" ref="185234335"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="492552876">
<int key="NSCellFlags">-2080244224</int>
Expand Down Expand Up @@ -450,8 +452,8 @@
<reference key="NSNextKeyView" ref="601672583"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="545050183">
<int key="NSCellFlags">-2080244224</int>
<int key="NSCellFlags2">0</int>
<int key="NSCellFlags">-2080244160</int>
<int key="NSCellFlags2">2304</int>
<string key="NSContents">Ignore my own commits</string>
<reference key="NSSupport" ref="1057182896"/>
<reference key="NSControlView" ref="69059234"/>
Expand Down Expand Up @@ -493,7 +495,7 @@
<string key="NSFrameSize">{525, 327}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="996414272"/>
<reference key="NSNextKeyView" ref="99672514"/>
<string key="NSClassName">NSView</string>
</object>
<object class="NSUserDefaultsController" id="983611490">
Expand Down Expand Up @@ -983,7 +985,7 @@
<string>65.IBPluginDependency</string>
<string>85.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand Down Expand Up @@ -1061,7 +1063,7 @@
<string>growlInfoPanel</string>
<string>ignoreOwnEmailsField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSView</string>
<string>NSButton</string>
Expand All @@ -1074,7 +1076,7 @@
<string>growlInfoPanel</string>
<string>ignoreOwnEmailsField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">growlInfoPanel</string>
Expand Down Expand Up @@ -1108,7 +1110,7 @@
<string>NSSwitch</string>
<string>growl_icon</string>
</object>
<object class="NSMutableArray" key="dict.values">
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{15, 15}</string>
<string>{64, 64}</string>
Expand Down