home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Developer / StopWatch / Source / SessionViewMgr.m < prev    next >
Encoding:
Text File  |  1994-02-06  |  2.5 KB  |  134 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import "SessionViewMgr.h"
  5. #import "ClientInspector.h"
  6. #import "SessionEditor.h"
  7. #import "Controller.h"
  8. #import "Preferences.h"
  9.  
  10. @interface SessionViewMgr(PRIVATE)
  11. - (void)displayTotalMins;
  12. - (void)displayClientMins;
  13. - (float)totalBillings;
  14. - (int)totalMins;
  15. @end
  16.  
  17. @implementation SessionViewMgr
  18.  
  19. - itemEditor
  20. {
  21.   return [SessionEditor new];
  22. }
  23.  
  24. /*
  25.  * Provide the add, delete and sort methods to invoke on ClientInfo objects
  26.  */
  27. - (SEL)addMethod
  28. {
  29.   return @selector(addSession:);
  30. }
  31.  
  32. - (SEL)deleteMethod
  33. {
  34.   return @selector(deleteSession:);
  35. }
  36.  
  37. - (SEL)sortMethod
  38. {
  39.   return @selector(sortSessions);
  40. }
  41.  
  42.  
  43. - info:(ClientInfo *)info itemAt:(int)position
  44. {
  45.   return [info sessionAt:position];
  46. }
  47.  
  48. - (int)itemCount:(ClientInfo *)info 
  49. {
  50.   return [info sessionCount];
  51. }
  52.  
  53. - (void)displaySummary
  54. {
  55.   [self displayClientMins];
  56.   [self displayTotalMins];
  57. }
  58.  
  59. - (void)displayTitle
  60. {
  61.   const char *title = [[Preferences new] showEndTimes] ?
  62.     "      Date          Start-End     Hrs     Description" :
  63.     "      Date          Start   Hrs    Description";
  64.  
  65.   [titleText setStringValue:title];
  66. }
  67.  
  68.  
  69. @end
  70.  
  71.  
  72. @implementation SessionViewMgr(PRIVATE)
  73.  
  74. - (float)totalBillings
  75. {
  76.   float billings = 0.0;
  77.   List *clientList = [[NXApp delegate] clientList];
  78.   int i, count = [clientList count];
  79.  
  80.   for ( i = 0; i < count; i++ )
  81.     billings += [[clientList objectAt:i] totalBillable];
  82.  
  83.   return billings;
  84. }
  85.  
  86. - (int)totalMins
  87. {
  88.   List *clientList = [[NXApp delegate] clientList];
  89.   int i, count = [clientList count];
  90.   int totalMins = 0;
  91.  
  92.   for ( i = 0; i < count; i++ )
  93.     totalMins += [[clientList objectAt:i] totalMins];
  94.  
  95.   return totalMins;
  96. }
  97.  
  98. - (void)displayClientMins
  99. {
  100.   id info = [[ClientInspector sharedInstance] selectedClient];
  101.  
  102.   if ( info ) {
  103.     char buf[50], tmp[50];
  104.     sprintf( buf, "%.2f", [info totalHours] );
  105.     [clientHoursField setStringValue:buf];
  106.  
  107.     commafyDouble( [info totalBillable], tmp );
  108.     sprintf( buf, "$%s", tmp );
  109.     [clientBillingsField setStringValue:buf];
  110.   } else {
  111.     [clientHoursField    setStringValue:""];
  112.     [clientBillingsField setStringValue:""];
  113.   }
  114. }
  115.  
  116. /*
  117.  * Display the total minutes and billings, and for the
  118.  * currently selected client.
  119.  */
  120. - (void)displayTotalMins
  121. {
  122.   char buf[50], tmp[50];
  123.   float hours = [self totalMins]/60.0;
  124.  
  125.   sprintf( buf, "%.2f", hours );
  126.   [totalHoursField setStringValue:buf];
  127.  
  128.   commafyDouble( [self totalBillings], tmp );
  129.   sprintf( buf, "$%s", tmp );
  130.   [totalBillingsField setStringValue:buf];
  131. }
  132.  
  133. @end
  134.