home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / pc / os2 / rme101 / rmndclas.cpp < prev    next >
C/C++ Source or Header  |  1995-01-27  |  4KB  |  131 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Reminder Item Class - Member Functions
  4. //
  5. // Written By Eric A. Wolf
  6. // Copyright (C) 1995 - All Rights Reserved
  7. //
  8. ////////////////////////////////////////////////////////////////////////////////
  9. #include "rmndclas.h"
  10. #include <string.h>
  11.  
  12.  
  13. ////////////////////////////////////////////////////////////////////////////////
  14. // function prototype
  15. ////////////////////////////////////////////////////////////////////////////////
  16. void setItem( char **, char * );
  17. char numberOfDaysInMonth( char, short );
  18.  
  19.  
  20. ////////////////////////////////////////////////////////////////////////////////
  21. // ReminderItem - create a new reminder item.  Fill in month/day/year, time and
  22. //                text for reminder when called
  23. ////////////////////////////////////////////////////////////////////////////////
  24.  
  25.  
  26. ReminderItem::ReminderItem( char todo, char itemDone, char numShow, char month,
  27.                             char day, short year, char hour, char minute,
  28.                             char reminder, char reminderType, char minBefore,
  29.                             char minsBefore, char daysBefore, char *sound,
  30.                             char *txt )
  31. {
  32.     soundFile = 0;
  33.     itemText = 0;
  34.     setToDo( todo );
  35.     setItemDone( itemDone );
  36.     setNumToShow( numShow );
  37.     setMonth( month );
  38.     setDay( day );
  39.     setYear( year );
  40.     setHour( hour );
  41.     setMinute( minute );
  42.     setReminder( reminder );
  43.     setReminderType( reminderType );
  44.     setMinBefore( minBefore );
  45.     setMinsBefore( minsBefore );
  46.     setDaysBefore( daysBefore );
  47.     setSoundFile( sound );
  48.     setText( txt );
  49.     setTimeOfOccurence();
  50.     setReminderTime();
  51. }
  52.  
  53.  
  54. ////////////////////////////////////////////////////////////////////////////////
  55. // when deleteing a reminder item, delete any dynamic string space
  56. ////////////////////////////////////////////////////////////////////////////////
  57. ReminderItem::~ReminderItem()
  58. {
  59.     if( itemText )
  60.         delete( itemText );
  61.     if( soundFile )
  62.         delete( soundFile );
  63. }
  64.  
  65.  
  66. ////////////////////////////////////////////////////////////////////////////////
  67. // give ordanilty to all unique integer time and dates possible
  68. ////////////////////////////////////////////////////////////////////////////////
  69. void ReminderItem::setTimeOfOccurence( void )
  70. {
  71.     timeOfOccurence = calcTimeOfOccurence( year, month, day, hour, minute );
  72. }
  73.  
  74.  
  75. ////////////////////////////////////////////////////////////////////////////////
  76. // calculate the time when the flash reminder is supposed to go off
  77. ////////////////////////////////////////////////////////////////////////////////
  78. void ReminderItem::setReminderTime( void )
  79. {
  80.     short yr;
  81.     char mo, dy, hr, mn;
  82.  
  83.     yr = getYear();
  84.     mo = getMonth();
  85.     dy = getDay();
  86.     hr = getHour();
  87.     mn = getMinute();
  88.  
  89.     if ( getMinBefore() )
  90.         mn = mn - getMinsBefore();
  91.     else
  92.         dy = dy - getDaysBefore();
  93.  
  94.     if ( mn < 0 ) {
  95.         mn = mn + 60;
  96.         hr--;
  97.         }
  98.     if ( hr < 0 ) {
  99.         hr = hr + 24;
  100.         dy--;
  101.         }
  102.     if ( dy < 1 ) {
  103.         mo--;
  104.         if( mo < 1 ) {
  105.             mo = mo + 12;
  106.             yr--;
  107.             }
  108.         dy = dy + numberOfDaysInMonth( mo, yr );
  109.         }
  110.  
  111.     timeOfReminder = calcTimeOfOccurence( yr, mo, dy, hr, mn );
  112. }
  113.  
  114.  
  115. ////////////////////////////////////////////////////////////////////////////////
  116. // an intelligent strcpy routine for use with dynamic strings
  117. ////////////////////////////////////////////////////////////////////////////////
  118. void setItem( char **destination, char *source ) {
  119.     if (*destination)
  120.         delete *destination;
  121.     if (source == 0) {
  122.         *destination = new char[2];
  123.         strcpy( *destination, "" );
  124.         }
  125.     else {
  126.         *destination = new char[ strlen( source )+1 ];
  127.         strcpy( *destination, source );
  128.         }
  129. }
  130.  
  131.