/*
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 "PerforceConfigurationsList.h"
#import "PerforceConfiguration.h"
@implementation PerforceConfigurationsList
- (id) init
{
self = [super init];
fActiveConfiguration = -1;
fConfigurations = [[NSMutableArray alloc] init];
return self;
}
- (void) dealloc
{
[fConfigurations release];
[super dealloc];
}
- (id)initWithCoder:(NSCoder*)coder
{
self = [super init];
fConfigurations = [[coder decodeObject] retain];
[coder decodeValueOfObjCType:@encode(int) at:&fActiveConfiguration];
return self;
}
- (void) encodeWithCoder:(NSCoder*)coder
{
[coder encodeObject:fConfigurations];
[coder encodeValueOfObjCType:@encode(int) at:&fActiveConfiguration];
}
- (id) copyWithZone:(NSZone*)zone
{
PerforceConfigurationsList* newList = [[PerforceConfigurationsList alloc] init];
newList->fActiveConfiguration = fActiveConfiguration;
int numItems = [fConfigurations count];
int n;
for ( n = 0; n < numItems; n++ )
{
PerforceConfiguration* aConfig = [[fConfigurations objectAtIndex:n] copy];
[newList->fConfigurations addObject:aConfig];
[aConfig release];
}
return newList;
}
- (void) addConfiguration:(PerforceConfiguration*)config
{
[fConfigurations addObject:config];
}
- (void) removeConfigurationAtIndex:(int)n
{
if ( n < [fConfigurations count] )
{
[fConfigurations removeObjectAtIndex:n];
}
if ( fActiveConfiguration > [fConfigurations count] )
{
if ( [fConfigurations count] > 0 )
{
fActiveConfiguration = 0;
}
else
{
fActiveConfiguration = -1;
}
}
}
- (void) setActiveConfiguration:(int)newActive
{
if ( newActive < [fConfigurations count] )
{
fActiveConfiguration = newActive;
}
}
- (int) indexOfActiveConfiguration
{
return fActiveConfiguration;
}
- (PerforceConfiguration*) activeConfiguration
{
if ( fActiveConfiguration < 0 )
{
return nil;
}
return [fConfigurations objectAtIndex:fActiveConfiguration];
}
- (int) count
{
return [fConfigurations count];
}
- (PerforceConfiguration*) configurationAtIndex:(int)n
{
if ( n < [fConfigurations count] )
{
return [fConfigurations objectAtIndex:n];
}
return nil;
}
- (int) indexOfConfigurationNamed:(NSString*)configName
{
int numItems = [fConfigurations count];
int n;
for ( n = 0; n < numItems; n++ )
{
PerforceConfiguration* config = [fConfigurations objectAtIndex:n];
if ( [[config configurationName] isEqualToString:configName] )
{
return n;
}
}
return -1;
}
- (NSString*) activePort
{
if ( fActiveConfiguration < 0 )
{
return [NSString stringWithString:@""];
}
return [[fConfigurations objectAtIndex:fActiveConfiguration] perforcePort];
}
- (NSString*) activeHost
{
if ( fActiveConfiguration < 0 )
{
return [NSString stringWithString:@""];
}
return [[fConfigurations objectAtIndex:fActiveConfiguration] perforceHost];
}
- (NSString*) activeUser
{
if ( fActiveConfiguration < 0 )
{
return [NSString stringWithString:@""];
}
return [[fConfigurations objectAtIndex:fActiveConfiguration] perforceUser];
}
- (NSString*) activeClient
{
if ( fActiveConfiguration < 0 )
{
return [NSString stringWithString:@""];
}
return [[fConfigurations objectAtIndex:fActiveConfiguration] perforceClient];
}
- (NSString*) activePasswd
{
if ( fActiveConfiguration < 0 )
{
return [NSString stringWithString:@""];
}
return [[fConfigurations objectAtIndex:fActiveConfiguration] perforcePasswd];
}
@end