ftp.nice.ch/pub/next/database/apps/Stopwatch.2.5.s.tar.gz#/Stopwatch2.5/SessionViewMgr.m

This is SessionViewMgr.m in view mode; [Download] [Up]

/*
 * For legal stuff see the file COPYRIGHT
 */
#import "SessionViewMgr.h"
#import "ClientInspector.h"
#import "SessionEditor.h"
#import "Controller.h"
#import "Preferences.h"

@interface SessionViewMgr(PRIVATE)
- (void)displayTotalMins;
- (void)displayClientMins;
- (float)totalBillings;
- (int)totalMins;
@end

@implementation SessionViewMgr

- itemEditor
{
  return [SessionEditor new];
}

/*
 * Provide the add, delete and sort methods to invoke on ClientInfo objects
 */
- (SEL)addMethod
{
  return @selector(addSession:);
}

- (SEL)deleteMethod
{
  return @selector(deleteSession:);
}

- (SEL)sortMethod
{
  return @selector(sortSessions);
}


- info:(ClientInfo *)info itemAt:(int)position
{
  return [info sessionAt:position];
}

- (int)itemCount:(ClientInfo *)info 
{
  return [info sessionCount];
}

- (void)displaySummary
{
  [self displayClientMins];
  [self displayTotalMins];
}

- (void)displayTitle
{
  const char *title = [[Preferences new] showEndTimes] ?
    "      Date          Start-End     Hrs     Description" :
    "      Date          Start   Hrs    Description";

  [titleText setStringValue:title];
}


@end


@implementation SessionViewMgr(PRIVATE)

- (float)totalBillings
{
  float billings = 0.0;
  List *clientList = [[NXApp delegate] clientList];
  int i, count = [clientList count];

  for ( i = 0; i < count; i++ )
    billings += [[clientList objectAt:i] totalBillable];

  return billings;
}

- (int)totalMins
{
  List *clientList = [[NXApp delegate] clientList];
  int i, count = [clientList count];
  int totalMins = 0;

  for ( i = 0; i < count; i++ )
    totalMins += [[clientList objectAt:i] totalMins];

  return totalMins;
}

- (void)displayClientMins
{
  id info = [[ClientInspector sharedInstance] selectedClient];

  if ( info ) {
    char buf[50], tmp[50];
    sprintf( buf, "%.2f", [info totalHours] );
    [clientHoursField setStringValue:buf];

    commafyDouble( [info totalBillable], tmp );
    sprintf( buf, "$%s", tmp );
    [clientBillingsField setStringValue:buf];
  } else {
    [clientHoursField    setStringValue:""];
    [clientBillingsField setStringValue:""];
  }
}

/*
 * Display the total minutes and billings, and for the
 * currently selected client.
 */
- (void)displayTotalMins
{
  char buf[50], tmp[50];
  float hours = [self totalMins]/60.0;

  sprintf( buf, "%.2f", hours );
  [totalHoursField setStringValue:buf];

  commafyDouble( [self totalBillings], tmp );
  sprintf( buf, "$%s", tmp );
  [totalBillingsField setStringValue:buf];
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.