/*
Copyright (C) 2002-2003, Jeffrey D. Argast.
The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.
Permission is hereby granted to use, copy, modify, and distribute this
software or portions thereof for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code is distributed, then this
statement must be included, with this copyright and no-warranty notice
unaltered.
(2) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.
*/
#import "PerforceJob.h"
#import "AppController.h"
#import "ReadOnlyEditorController.h"
#import "PerforceActionJob.h"
@implementation PerforceJob
+ (PerforceJob*) jobWithString: (NSString*) string
{
return [[[PerforceJob alloc] initWithString: string] autorelease];
}
- (id) initWithString: (NSString*) string
{
if (self = [super init])
{
NSScanner* scanner = [NSScanner scannerWithString: string];
[scanner scanUpToString:@" on "intoString:&fName];
[scanner scanString:@"on " intoString:nil];
[scanner scanUpToString:@" by " intoString:&fDate];
[scanner scanString:@"by " intoString:nil];
[scanner scanUpToString:@" *" intoString:&fUser];
[scanner scanString:@"*" intoString:nil];
[scanner scanUpToString:@"* " intoString:&fStatus];
[scanner scanUpToString:@"'" intoString:nil];
NSRange range;
range.location = [scanner scanLocation] + 1;
if ( range.location < [string length] )
{
range.length = [string length] - range.location - 1;
fDescription = [string substringWithRange: range];
}
[fName retain];
[fDate retain];
[fUser retain];
[fStatus retain];
[fDescription retain];
}
return self;
}
- (void) dealloc
{
[fName release];
[fStatus release];
[fUser release];
[fDate release];
[fDescription release];
[super dealloc];
}
- (NSString*) getJobName;
{
return fName;
}
- (NSString*) getJobStatus;
{
return fStatus;
}
- (NSString*) getJobUser;
{
return fUser;
}
- (NSString*) getJobDate;
{
return fDate;
}
- (NSString*) getJobDescription;
{
return fDescription;
}
- (NSComparisonResult) comparegetJobNameAscending: (PerforceJob*) rhs
{
return [fName caseInsensitiveCompare:rhs->fName];
}
- (NSComparisonResult) comparegetJobNameDescending: (PerforceJob*) rhs
{
return [rhs->fName caseInsensitiveCompare:fName];
}
- (NSComparisonResult) comparegetJobStatusAscending: (PerforceJob*) rhs
{
return [fStatus caseInsensitiveCompare:rhs->fStatus];
}
- (NSComparisonResult) comparegetJobStatusDescending: (PerforceJob*) rhs
{
return [rhs->fStatus caseInsensitiveCompare:fStatus];
}
- (NSComparisonResult) comparegetJobUserAscending: (PerforceJob*) rhs
{
return [fUser caseInsensitiveCompare:rhs->fUser];
}
- (NSComparisonResult) comparegetJobUserDescending: (PerforceJob*) rhs
{
return [rhs->fUser caseInsensitiveCompare:fUser];
}
- (NSComparisonResult) comparegetJobDateAscending: (PerforceJob*) rhs
{
return [fDate caseInsensitiveCompare:rhs->fDate];
}
- (NSComparisonResult) comparegetJobDateDescending: (PerforceJob*) rhs
{
return [rhs->fDate caseInsensitiveCompare:fDate];
}
- (NSComparisonResult) comparegetJobDescriptionAscending: (PerforceJob*) rhs
{
return [fDescription caseInsensitiveCompare:rhs->fDescription];
}
- (NSComparisonResult) comparegetJobDescriptionDescending: (PerforceJob*) rhs
{
return [rhs->fDescription caseInsensitiveCompare:fDescription];
}
// The enablement
- (BOOL) canEdit
{
return YES;
}
- (BOOL) canDescribe
{
return YES;
}
- (BOOL) canDelete
{
return YES;
}
// The actions
- (void) doEdit
{
[PerforceActionJobGet defaultRunFor:[NSApp delegate] selector:@selector(resultFromPerforceJobOut:) identifier:fName];
}
- (void) doDescribe
{
[PerforceActionJobGet defaultRunFor:self selector:@selector(resultFromDescribe:) identifier:fName];
}
- (void) doDelete
{
int isOK = NSRunAlertPanel (@"Delete",
@"Are you sure you want to delete job %s?",
@"OK",
@"Cancel",
nil,
[fName cString]);
if ( isOK )
{
[PerforceActionJobDelete defaultRunFor:nil selector:nil identifier:fName];
}
}
- (void) resultFromDescribe:(PerforceActionJobGet*)action
{
if ( [action wasSuccess] )
{
NSMutableString* titleString = [NSMutableString stringWithString:@"Description of Job "];
[titleString appendString:[action getIdentifier]];
[ReadOnlyEditorController showWindowWith:[action getOutput] title:titleString];
}
}
@end