Skip to content

Commit

Permalink
Added activity window.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuther committed Aug 29, 2009
1 parent b93f3fb commit 3e706ba
Show file tree
Hide file tree
Showing 19 changed files with 2,575 additions and 37 deletions.
29 changes: 29 additions & 0 deletions ActivityDateFormatter.h
@@ -0,0 +1,29 @@
/*
* ActivityDateFormatter.h
*
* Copyright (c) 2007-2009 Kent Sutherland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <Cocoa/Cocoa.h>

@interface ActivityDateFormatter : NSDateFormatter {

}
@end
48 changes: 48 additions & 0 deletions ActivityDateFormatter.m
@@ -0,0 +1,48 @@
/*
* ActivityDateFormatter.m
*
* Copyright (c) 2007-2009 Kent Sutherland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "ActivityDateFormatter.h"

@implementation ActivityDateFormatter

- (NSString *)stringForObjectValue:(id)anObject
{
if (![anObject isKindOfClass:[NSDate class]]) {
return nil;
}

NSString *value = [super stringForObjectValue:anObject];
NSCalendar *calendar = [NSCalendar currentCalendar];

if ([[calendar components:kCFCalendarUnitDay fromDate:anObject] day] != [[calendar components:kCFCalendarUnitDay fromDate:[NSDate date]] day]) {
[self setTimeStyle:NSDateFormatterShortStyle];
[self setDateStyle:NSDateFormatterShortStyle];
value = [super stringForObjectValue:anObject];
[self setTimeStyle:NSDateFormatterShortStyle];
[self setDateStyle:NSDateFormatterNoStyle];
}

return value;
}

@end
Binary file added ActivityModel.xcdatamodel/elements
Binary file not shown.
Binary file added ActivityModel.xcdatamodel/layout
Binary file not shown.
30 changes: 30 additions & 0 deletions ActivityStatusCell.h
@@ -0,0 +1,30 @@
/*
* ActivityStatusCell.h
*
* Copyright (c) 2007-2009 Kent Sutherland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <Cocoa/Cocoa.h>

@interface ActivityStatusCell : NSTextFieldCell
{
}

@end
62 changes: 62 additions & 0 deletions ActivityStatusCell.m
@@ -0,0 +1,62 @@
/*
* ActivityStatusCell.m
*
* Copyright (c) 2007-2009 Kent Sutherland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "ActivityStatusCell.h"
#import <InstantMessage/IMService.h>

#define DOCUMENT_ICON @"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns"

static NSDictionary *_images;

@implementation ActivityStatusCell

- (id)init
{
if ( (self = [super init]) ) {
if (_images == nil) {
NSImage *document = [[NSImage alloc] initByReferencingFile:DOCUMENT_ICON];
[document setScalesWhenResized:YES];
[document setSize:NSMakeSize(13, 13)];

_images = [[NSDictionary alloc] initWithObjectsAndKeys:[NSImage imageNamed:[IMService imageNameForStatus:IMPersonStatusUnknown]], [NSNumber numberWithInt:IMPersonStatusUnknown],
[[[NSImage alloc] initByReferencingFile:[[NSBundle bundleWithIdentifier:ChaxBundleIdentifier] pathForImageResource:@"status-offline"]] autorelease], [NSNumber numberWithInt:IMPersonStatusOffline],
[NSImage imageNamed:[IMService imageNameForStatus:IMPersonStatusIdle]], [NSNumber numberWithInt:IMPersonStatusIdle],
[NSImage imageNamed:[IMService imageNameForStatus:IMPersonStatusAway]], [NSNumber numberWithInt:IMPersonStatusAway],
[NSImage imageNamed:[IMService imageNameForStatus:IMPersonStatusAvailable]], [NSNumber numberWithInt:IMPersonStatusAvailable],
document, [NSNumber numberWithInt:101],
[document autorelease], [NSNumber numberWithInt:102],
nil, nil];
}
}
return self;
}

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSImage *image = [_images objectForKey:[NSNumber numberWithInt:[[self objectValue] intValue]]];
[controlView lockFocus];
[image compositeToPoint:NSMakePoint(cellFrame.origin.x + (cellFrame.size.width - [image size].width) / 2, cellFrame.origin.y + (cellFrame.size.height + [image size].height) / 2) operation:NSCompositeSourceOver];
[controlView unlockFocus];
}

@end
19 changes: 19 additions & 0 deletions ActivityTableView.h
@@ -0,0 +1,19 @@
//
// ActivityTableView.h
// Chax
//
// Created by Kent Sutherland on 6/22/09.
// Copyright 2009 Kent Sutherland. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface ActivityTableView : NSTableView {

}

@end

@interface NSObject (ActivityTableViewDelegate)
- (void)deleteKeyPressedInTableView:(NSTableView *)tableView;
@end
24 changes: 24 additions & 0 deletions ActivityTableView.m
@@ -0,0 +1,24 @@
//
// ActivityTableView.m
// Chax
//
// Created by Kent Sutherland on 6/22/09.
// Copyright 2009 Kent Sutherland. All rights reserved.
//

#import "ActivityTableView.h"

@implementation ActivityTableView

- (void)keyDown:(NSEvent *)event
{
if ([[event characters] characterAtIndex:0] == NSDeleteCharacter || [[event characters] characterAtIndex:0] == NSDeleteCharFunctionKey || [[event characters] characterAtIndex:0] == NSDeleteFunctionKey) {
if ([self.delegate respondsToSelector:@selector(deleteKeyPressedInTableView:)]) {
[(NSObject *)self.delegate deleteKeyPressedInTableView:self];
}
} else {
[super keyDown:event];
}
}

@end
49 changes: 49 additions & 0 deletions ActivityWindowController.h
@@ -0,0 +1,49 @@
/*
* ActivityWindowController.h
*
* Copyright (c) 2007-2009 Kent Sutherland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <Cocoa/Cocoa.h>

@class ActivityTableView, Presentity;

@interface ActivityWindowController : NSWindowController <NSToolbarDelegate>
{
IBOutlet NSArrayController *_arrayController;
IBOutlet NSPopUpButton *_autoclearPopUp;
IBOutlet NSSearchField *_searchField;
IBOutlet ActivityTableView *_tableView;

NSArray *_sortDescriptors;

NSToolbar *_toolbar;
NSManagedObjectContext *_managedObjectContext;
NSDate *_lastSaveDate;

NSMutableSet *_recentActivity;
}
+ (ActivityWindowController *)sharedController;

- (void)addPresentityToActivity:(Presentity *)presentity;

- (NSString *)applicationSupportFolder;
- (NSManagedObjectContext *)managedObjectContext;
@end

0 comments on commit 3e706ba

Please sign in to comment.