Ejemplo n.º 1
0
/*
** Handle Security command
*/
static void ThumbnailDoCmdSecurity(void) {
  FormType* frm = FrmGetActiveForm();
  Boolean wasHiding = d.privateRecordStatus == hidePrivateRecords;
  UInt16 mode;

  d.privateRecordStatus = SecSelectViewStatus();

  if (wasHiding ^ (d.privateRecordStatus == hidePrivateRecords)) {
    /* We have to close the database first */
    if (DmCloseDatabase(d.dbR) != errNone) abort();

    mode = dmModeReadWrite;
    if (d.privateRecordStatus != hidePrivateRecords)
      mode |= dmModeShowSecret;

    /* Re-open the database */
    if ((d.dbR = DmOpenDatabaseByTypeCreator(DBType, AppType, mode)) == NULL)
      abort();

    /* Update cached values */
    d.records_in_cat = DmNumRecordsInCategory(d.dbR, p.category);
    if (d.privateRecordStatus == hidePrivateRecords)
      SetTopVisibleRecord(0);

    ThumbnailViewLoadRecords (frm);
  }
}
Ejemplo n.º 2
0
/********************************************************************************
 * Function: StartApplication
 * Description: This is the first function that gets called and it is 
 * responsible for initializing databases and other global variables, checking
 * to see whether private records will be shown and calculating the auto-off time
 * for the current system.
 * ******************************************************************************/ 
static Err 
StartApplication (void) 
{
	UInt16 mode = dmModeReadWrite;
	Err errors = 0;
	Boolean created;
	StripPrefType prefs;	
	UInt16 prefsSize, prefsVersion;

		// set current form to be the password opener
		currentForm = PasswordForm;
	
		// check about private records
		hideSecretRecords = PrefGetPreference (prefHidePrivateRecordsV33);
	if (!hideSecretRecords)
		mode |= dmModeShowSecret;

	/*  handle program prefrences */
	prefsSize = sizeof (StripPrefType);
	prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true);
	if (prefsVersion == noPreferenceFound) { 
        FrmCustomAlert (GenericError, "This version of StripCS is only able to convert 0.5 databases. If you're using an earlier version you must run the StripCS_0.5.prc file that came with this distro first. If you aren't upgrading, just run Strip.prc!", NULL, NULL);
		return -1;
	} else if (prefsVersion == StripVersionNumber) {
        FrmCustomAlert (GenericError, "It looks like you have already converted your databases with StripCS. You may now use the latest version of Strip.", NULL, NULL);
		return -1;
	}
	
		// open or create databases.
		errors =
		getDatabase (&SystemDB, systemDBTypeOld, StripCreator, mode, 0,
					  systemDBName, &created);

		errors =
		getDatabase (&AccountDB, accountDBTypeOld, StripCreator, mode, 0,
					  accountDBName, &created);

		errors =
		getDatabase (&PasswordDB, passwordDBTypeOld, StripCreator, mode, 0,
					  passwordDBName, &created);

	
		// if the password database does not exist, or there are no records in it note that 
		// this is the first run, so the user will be prompted to enter a new password.
		if (created 
			||(DmNumRecordsInCategory (PasswordDB, dmAllCategories) == 0))
		
	{
		firstRun = true;
	}
	
		// set up the timer stuff.  start by setting auto off time to 0. the function returns the old 
		// auto off time. If the oldAutoOffTime is 0 then the system will never shut down. this is not
		// the behavior that we want, so we reset the autoOffTime to 300. if the oldAutoOffTime is not 
		// 0 then we set it back immediatly.  Note that in the StopApplication function we 
		// set the autoOffTime back to what it was before this program started no matter what.
		return 0;
}
Ejemplo n.º 3
0
/*************************************************************************
 * Function: replaceAllAccountHashes
 * Description: regernate the hash on a all the accounts.
 * ***********************************************************************/ 
void replaceAllAccountHashes(DmOpenRef db, md_hash * SysPass) {
	int i;
	UInt16 totalAItems = DmNumRecordsInCategory (
		db, dmAllCategories);
	/* loop through the accounts and replace hashe */
	for (i = 0; i < totalAItems; i++) {
		replaceAccountHash(i, db, SysPass);
	}
}
Ejemplo n.º 4
0
/*****************************************************************
 * Function: numAccountsInSystem
 * Description: count the number of accounts for a given system 
 * ID 
 * ***************************************************************/ 
UInt16 numAccountsInSystem (DmOpenRef AccountDB, UInt16 id) {
	UInt16 i, acid;
	UInt16 totalItems = DmNumRecordsInCategory (AccountDB, dmAllCategories);
	UInt16 numAccounts = 0;
	
	/* iterate through the records, increment when we find a match */
	for (i = 0; i < totalItems; i++) {
		acid = getSIDFromAccountIndex (AccountDB, i);
		if (acid == id) numAccounts++;
	}
	return numAccounts;
}
Ejemplo n.º 5
0
/*******************************************************************
 * Function: getUniqueAccountID
 * Description: return a unique account id that can be assigned to a
 * new account.
 * ****************************************************************/ 
UInt16 getUniqueAccountID (DmOpenRef AccountDB) {
	UInt16 i, id;
	
	/*	get the number of account records. note that we cant just
		use totalItems++ because account can be added and deleted and
		they are in alphabetical sort order, not is AccountID order. */
	UInt16 totalItems = DmNumRecordsInCategory (AccountDB, dmAllCategories);
	UInt16 max = 0;
	
	/*	iterate through the records, and we will return the highest 
		one it higher than the highest current value. */
	for (i = 0; i < totalItems; i++) {
		id = getAIDFromAccountIndex (AccountDB, i);
		if (id > max) max = id;
	}
	return max + 1;
}
Ejemplo n.º 6
0
/*************************************************************************
 * Function: getIndexForAccountID
 * Description: get the selection index for the specified account ID.
 * **********************************************************************/ 
UInt16 getIndexForAccountID (DmOpenRef AccountDB, UInt16 currentSID, UInt16 aid) {
	UInt16 i, id, index = 0, counter = 0;
	UInt16 totalItems = DmNumRecordsInCategory (AccountDB, dmAllCategories);
	Boolean cont = true;
	
	/*	iterate through the accounts, till we find the nth account for
		the current systemID. */
	for (i = 0; (i < totalItems) && cont; i++) {
		/* note: getSIDFromAccountIndex is fast because it doesnt need 
		to decrypt anything. */
		id = getSIDFromAccountIndex (AccountDB, i);
		if (id == currentSID) {
			if(aid == getAIDFromAccountIndex(AccountDB, i) ) {
				index = counter;
				cont = false;
			}	
			counter++;
		}
	}
	return index;
}
Ejemplo n.º 7
0
/*******************************************************************
 * Function: getIndexForSystemID
 * Description: return an index for a unique system id.
 * ****************************************************************/ 
UInt16 getIndexForSystemID (DmOpenRef SystemDB, UInt16 sysid) {
	UInt16 i, id, index = 0;
	
	/*	get the number of system records. note that we cant just
		use totalItems++ because systems can be added and deleted
		at will... */
	UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	Boolean stop = false;
	
	/*	iterate through the records, and we will return the highest 
		one it higher than the highest current value. */
	for (i = 0; i < totalItems && !stop; i++) {
		MemHandle scr;
		if ((scr = MemHandleNew (1))) {
			id = getSIDForSystemIndex (SystemDB, i);
			if (id == sysid) index = i;
			freeHandle (scr);
		}
	}
	return index;
}
Ejemplo n.º 8
0
/*******************************************************************
 * Function: getUniqueSystemID
 * Description: return a unique system id that can be assigned to a
 * new system.
 * Note: SystemID 0 is reserved for the Unfiled system. Unfiled is 
 * where beamed accounts go when they are first received if they
 * dont have anywhere else to go.
 * ****************************************************************/ 
UInt16 getUniqueSystemID (DmOpenRef SystemDB) {
	UInt16 i, id;
	
	/*	get the number of system records. note that we cant just
		use totalItems++ because systems can be added and deleted
		at will... */
	UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	UInt16 max = 0;
	
	/*	iterate through the records, and we will return the highest 
		one it higher than the highest current value. */
	for (i = 0; i < totalItems; i++) {
		MemHandle scr;
		if ((scr = MemHandleNew (1))) {
			id = getSIDForSystemIndex (SystemDB, i);
			if (id > max) max = id;
			freeHandle (scr);
		}
	}
	return max + 1;
}
Ejemplo n.º 9
0
Boolean
CourseListHandleEvent(EventPtr event)
{
  FormPtr frm=FrmGetActiveForm();
  Boolean handled = false;
  ListType *lstP=GetObjectPtr(LIST_courses);
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  if (event->eType == ctlSelectEvent) {
    // button handling
    switch (event->data.ctlSelect.controlID) {
      case BUTTON_courselist_back:
        handled=true;
        FrmGotoForm(FORM_main);
        break;

      case BUTTON_courselist_del:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          DeleteCourse(gCourseInd[LstGetSelection(lstP)]);
          CleanupCourselist();
          DrawCourses(lstP);
          FrmDrawForm(FrmGetActiveForm());
        }
        break;

      case BUTTON_courselist_add:
        handled=true;
        gMenuCurrentForm=FORM_courselist;
        AddCourse();
        break;

      case BUTTON_courselist_edit:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          gMenuCurrentForm=FORM_courselist;
          EditCourse(gCourseInd[LstGetSelection(lstP)]);
        }
        break;

      case BUTTON_courselist_beam:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          BeamCourse(gCourseInd[LstGetSelection(lstP)]);
        }
        break;


      case LIST_cl_cat_trigger:
        handled=true;
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_cl_cat_trigger, LIST_cl_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_cl_cat_trigger);
          CategoryGetName(DatabaseGetRef(), category, gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName);
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw) {
          CleanupCourselist();
          DrawCourses(lstP);
          FrmDrawForm(FrmGetActiveForm());
        }
        if (recordList != NULL)  MemPtrFree((MemPtr)recordList);
        break;



      default:
        break;
    }
  } else if (event->eType == keyDownEvent) {
    // We have a hard button assigned and it was pressed
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
        FrmGotoForm(FORM_main);
        handled = true;
      }
    } else if (EvtKeydownIsVirtual(event)) {
      // Up or down keys pressed
      ListType *lst=GetObjectPtr(LIST_courses);
      switch (event->data.keyDown.chr) {
        case vchrPageUp:
          if (LstGetSelection(lst) == noListSelection) {
            LstSetSelection(lst, gNumCourses-1);
            CourseListHandleSelection();
          } else if (LstGetSelection(lst) > 0) {
            LstSetSelection(lst, LstGetSelection(lst)-1);
            CourseListHandleSelection();
          }
          handled=true;
          break;
        
        case vchrPageDown:
          if (LstGetSelection(lst) == noListSelection) {
            LstSetSelection(lst, 0);
            CourseListHandleSelection();
          } else if (LstGetSelection(lst) < (gNumCourses-1)) {
            LstSetSelection(lst, LstGetSelection(lst)+1);
            CourseListHandleSelection();
          }
          handled=true;
          break;

        default:
          break;
      }
    }
  } else if (event->eType == lstSelectEvent) {
    return CourseListHandleSelection();
  } else if (event->eType == menuOpenEvent) {
    return HandleMenuOpenEvent(event);
  } else if (event->eType == menuEvent) {
    // forwarding of menu events
    return HandleMenuEvent(event->data.menu.itemID);
  } else if (event->eType == frmOpenEvent) {
    // initializes and draws the form
    ControlType *ctl;

    frm = FrmGetActiveForm();
    lstP=GetObjectPtr(LIST_courses);
    FrmDrawForm (frm);
    DrawCourses(lstP);
    FrmDrawForm (frm);

    ctl = GetObjectPtr(LIST_cl_cat_trigger);
    CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
    CategorySetTriggerLabel (ctl, gCategoryName); 

    WinDrawLine(1, 140, 158, 140);
    
    handled = true;
  } else if (event->eType == frmUpdateEvent) {
    // redraws the form if needed
    CleanupCourselist();
    DrawCourses(GetObjectPtr(LIST_courses));
    FrmDrawForm (frm);
    WinDrawLine(1, 140, 158, 140);
    handled = false;
  } else if (event->eType == frmCloseEvent) {
    // this is done if form is closed
    CleanupCourselist();
  }

  return (handled);

}
Ejemplo n.º 10
0
Boolean
ExamsFormHandleEvent(EventPtr event)
{
  FormPtr frm=FrmGetActiveForm();
  Boolean handled = false;
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  if (event->eType == ctlSelectEvent) {
    // button handling
    switch (event->data.ctlSelect.controlID) {
      case BUTTON_ex_back:
        handled=true;
        FrmGotoForm(FORM_main);
        break;

      case BUTTON_ex_add:
        handled=true;
        if (CountCourses() > 0) {
          gExamsLastSelRowUID=0;
          FrmPopupForm(FORM_exam_details);
        } else {
          FrmAlert(ALERT_nocourses);
        }
        break;

      case BUTTON_ex_edit:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        FrmPopupForm(FORM_exam_details);
        break;

      case BUTTON_ex_note:
      {
        UInt16 index=0;

        handled=true;

        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
        NoteSet(index, FORM_exams);
        FrmPopupForm(NewNoteView);
        break;
      }

      case BUTTON_ex_del:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamDelete();
        break;

      case BUTTON_ex_beam:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamBeam();
        break;

      case LIST_ex_cat_trigger:
        handled=true;
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_ex_cat_trigger, LIST_ex_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_ex_cat_trigger);
          CategoryGetName(DatabaseGetRef(), category, gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName);
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw) {
          gExamsOffset=0;
          gExamsSelRow=0;
          FrmUpdateForm(FORM_exams, frmRedrawUpdateCode);
        }
        if (recordList != NULL)  MemPtrFree((MemPtr)recordList);
        break;

      default:
        break;
    }
  } else if (event->eType == tblEnterEvent) {
    UInt16 i;
    
    if (event->data.tblEnter.column == EXCOL_DONE) {
      handled=false;
    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      MemHandle m;
      Boolean hasNote=false;

      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }


      m = DmQueryRecord(DatabaseGetRefN(DB_MAIN), TblGetRowID(event->data.tblEnter.pTable, event->data.tblEnter.row));
      if (m) {
        ExamDBRecord *ex = (ExamDBRecord *)MemHandleLock(m);
        if (ex->note) hasNote = true;
        else          hasNote = false;
        MemHandleUnlock(m);
      }

      if (hasNote) {
        Coord newPointX, newPointY;
        Boolean isPenDown=false, drawn=false;
        RectangleType fieldBounds;
        IndexedColorType curForeColor, curBackColor, curTextColor;
        Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 };
        FontID oldFont;
  
  
        EvtGetPen(&newPointX, &newPointY, &isPenDown);
        TblGetItemBounds(event->data.tblEnter.pTable, event->data.tblEnter.row, EXCOL_NOTE, &fieldBounds);
  
        oldFont = FntSetFont(symbolFont);
        while (isPenDown){
          if (! drawn && RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectSelectedFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = true;
          } else if (drawn && ! RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = false;
          }
          EvtGetPen(&newPointX, &newPointY, &isPenDown);
        }
        FntSetFont(oldFont);
      } else {
        handled = true;
      }
    } else {
      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }
      handled=true;
    }
  } else if (event->eType == tblSelectEvent) {
    if (event->data.tblEnter.column == EXCOL_DONE) {
      MemHandle mex;
      ExamDBRecord *ex;
      Boolean done=(TblGetItemInt(event->data.tblSelect.pTable, event->data.tblSelect.row, event->data.tblSelect.column) == 0) ? false : true;
      UInt16 flags, index=TblGetRowID(event->data.tblSelect.pTable, event->data.tblSelect.row);

      mex=DmGetRecord(DatabaseGetRefN(DB_MAIN), index);
      ex = MemHandleLock(mex);
      flags = ex->flags;

      if (done) {
        flags |= EX_FLAG_DONE;
      } else {
        flags &= (EX_FLAG_DONE ^ 0xFFFF);
      }

      DmWrite(ex, offsetof(ExamDBRecord, flags), &flags, sizeof(flags));
      DmReleaseRecord(DatabaseGetRefN(DB_MAIN), index, false);

      TblMarkRowInvalid(event->data.tblSelect.pTable, event->data.tblSelect.row);
      TblRedrawTable(event->data.tblSelect.pTable);

      MemHandleUnlock(mex);

    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      ControlType *ctl=GetObjectPtr(BUTTON_ex_note);
      // Don't need code twice, just read ctlSelect Event for BUTTON_ex_note
      CtlHitControl(ctl);
    }
    handled=true;
  } else if (event->eType == ctlRepeatEvent) {
    // Repeat buttons pressed
    if( event->data.ctlRepeat.controlID == REPEAT_ex_up )
      gExamsOffset -= 1;
    else
      gExamsOffset += 1;

    ExamsTableInit();
    TblMarkTableInvalid(GetObjectPtr(TABLE_exams));
    TblRedrawTable(GetObjectPtr(TABLE_exams));
  } else if (event->eType == keyDownEvent) {
    // We have a hard button assigned and it was pressed
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
        FrmGotoForm(FORM_main);
        handled = true;
      }
    }
  } else if (event->eType == menuOpenEvent) {
    return HandleMenuOpenEvent(event);
  } else if (event->eType == menuEvent) {
    // forwarding of menu events
    return HandleMenuEvent(event->data.menu.itemID);
  } else if (event->eType == frmOpenEvent) {
    // initializes and draws the form
    ControlType *ctl;

    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm (frm);

    ctl = GetObjectPtr(LIST_ex_cat_trigger);
    CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
    CategorySetTriggerLabel (ctl, gCategoryName); 

    handled = true;
  } else if (event->eType == frmUpdateEvent) {
    // redraws the form if needed
    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm(frm);
    handled = false;
  } else if (event->eType == frmCloseEvent) {
    // this is done if form is closed
    // TblEraseTable(GetObjectPtr(TABLE_exams));
    // ExamsFormFree();
    FrmEraseForm(frm);
  }

  return (handled);

}
Ejemplo n.º 11
0
/***********************************************************************
 * handling for form and control actions
 * menu actions are forwarded to MainFormDoCommand
 ***********************************************************************/
static Boolean
MainFormHandleEvent (EventPtr event)
{
  FormType *frm;
  Boolean handled = false;
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  
  if (event->eType == ctlSelectEvent) {
    // button handling
    handled = true;
    switch (event->data.ctlSelect.controlID) {
      // the ok button - this leaves the application

      case LIST_cat_trigger:
        frm = FrmGetActiveForm();
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_cat_trigger, LIST_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_cat_trigger);
          CategoryGetName(DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName); 
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw)  {
          GadgetSetNeedsCompleteRedraw(true);
          FrmDrawForm(frm);
        }
        if (recordList != NULL)    MemPtrFree((MemPtr)recordList);
        break;

      case BUTTON_beam:
        BeamCourse(GadgetGetHintCourseIndex());
        break;

      case BUTTON_edit:
        gMenuCurrentForm=FORM_main;
        EditTime();
        break;

      case BUTTON_next:
        GadgetDrawHintNext();
        break;

      default:
        break;
      }
    } else if (event->eType == keyDownEvent) {
      // We have a hard button assigned and it was pressed
      if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
        if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
          GadgetDrawHintNext();
          handled = true;
        }
      } else if (EvtKeydownIsVirtual(event)) {
        // Up or down keys pressed
        switch (event->data.keyDown.chr) {
          case vchrPageUp:
            if (event->data.keyDown.modifiers & autoRepeatKeyMask) {
              if (! gMainRepeat) {
                GadgetSwitchScreen();
                gMainRepeat = true;
              }
            } else {
              GadgetDrawStep(winUp);
              gMainRepeat = false;
            }
            handled=true;
            break;

          case vchrPageDown:
            if (event->data.keyDown.modifiers & autoRepeatKeyMask) {
              if (! gMainRepeat) {
                GadgetSwitchScreen();
                gMainRepeat = true;
              }
            } else {
              GadgetDrawStep(winDown);
              gMainRepeat = false;
            }
            handled=true;
            break;

          case vchrSendData:
            BeamCourse(GadgetGetHintCourseIndex());
            handled=true;
            break;

          default:
            break;
        }
      }
    } else if (event->eType == menuEvent) {
      // forwarding of menu events
      return HandleMenuEvent(event->data.menu.itemID);
    } else if (event->eType == menuOpenEvent) {
      return HandleMenuOpenEvent(event);
    } else if (event->eType == frmUpdateEvent) {
      // redraws the form if needed
      frm = FrmGetActiveForm();
      FrmDrawForm(frm);
      // GadgetDrawHintNext();
      handled = true;
    } else if (event->eType == frmOpenEvent) {
      ControlType *ctl;
      LocalID dbID;
      UInt16 cardNo;
      Boolean newKeyP4=false;
      UInt16 newKeyP2=0xFFFF;

      // initializes and draws the form at program launch
      frm = FrmGetActiveForm();

      GadgetSet(frm, GADGET_main, GADGET_hint);
      FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_main), GadgetHandler);
      FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_hint), GadgetHintHandler);

      FrmDrawForm(frm);
      GadgetDrawHintNext();

      ctl = GetObjectPtr(LIST_cat_trigger);
      CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
      CategorySetTriggerLabel (ctl, gCategoryName); 

      DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL);
      SysNotifyRegister(cardNo, dbID, sysNotifyLateWakeupEvent, HandleNotification, sysNotifyNormalPriority, NULL);

    	KeyRates(false,&gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4);
	    KeyRates(true, &gKeyP1, &newKeyP2, &gKeyP3, &newKeyP4);

      handled = true;
    } else if (event->eType == frmCloseEvent) {
      // this is done if program is closed
      LocalID dbID;
      UInt16 cardNo;
      DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL);
      SysNotifyUnregister(cardNo, dbID, sysNotifyLateWakeupEvent, sysNotifyNormalPriority);
      // Restore original key rates
	    KeyRates(true, &gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4);
    }

  return (handled);
}
Ejemplo n.º 12
0
/***************************************************************************
 * Function: cryptSwitch
 * Description: handles changing the system password based upon the 
 * password change screen. Basically checks that current password is correct,
 * checks that the new password was entered correctly, then re-encrypts the
 * databases based upon the new password.
 * ************************************************************************/ 
static void 
cryptSwitch (int v) 
{
	
		// total number of records to re-write
	UInt16 totalAItems = DmNumRecordsInCategory (AccountDB, dmAllCategories);
	UInt16 totalSItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	MemPtr pac = NULL, scratch = NULL, scratch2 = NULL;
	UInt16 i = 0, senc = 0, aenc = 0;
	MemHandle rH;
	char s[5], a[5];
	StripPrefType prefs;	
	UInt16 prefsSize, prefsVersion;

	FormType *preF = FrmGetActiveForm ();
	FormType *f = FrmInitForm (pleaseWait);
	FrmDrawForm (f);
	
		// re-encrypt the password 
	if ((rH = DmGetRecord (PasswordDB, 0)))	
	{
		if ((scratch = MemPtrNew (getSCSize(sizeof(md_hash)))))			
		{
			PackPassword (scratch, &NewSysPass);			
			writeRecord (scratch, rH);
			MemPtrFree (scratch);
		}
		DmReleaseRecord (PasswordDB, 0, true);
	}
	
		// loop through the systems and re-encrypt
	for (i = 0; i < totalSItems; i++)
	{
		System_old sys;
		if ((rH = DmGetRecord (SystemDB, i)))	
		{
			pac = MemHandleLock (rH);
			if ((scratch = MemPtrNew (MemPtrSize (pac))))	
			{	
					// decrypt the system with old password
				switch (v)	
				{
					case 0:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 1);
										
						scratch2 = MemPtrNew (getSystemSize((System *)&sys, true));
						break;
					case 1:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 2);
						scratch2 = MemPtrNew (getSystemSize ((System *)&sys,true) );
						break;
					case 2:
						UnpackSystem_old (&sys, pac, scratch, SysPass,
										MemHandleSize (rH), true, 0);
						scratch2 = MemPtrNew (getSystemSize ((System *)&sys, true ));
						break;
				}
				if (scratch2)				
				{			
					PackSystem(scratch2, *((System *) &sys), &NewSysPass, true);
					MemHandleUnlock (rH);
					writeRecord (scratch2, rH);
					senc++;
					MemPtrFree (scratch2);
				}
				MemPtrFree (scratch);
			}
			DmReleaseRecord (SystemDB, i, true);
		}
	}
	
		// loop through the accounts and re-encrypt
	for (i = 0; i < totalAItems; i++)	
	{
		Account_old ac;
		Account ac_new;
		if ((rH = DmGetRecord (AccountDB, i)))
			
		{
			pac = MemHandleLock (rH);
			if ((scratch = MemPtrNew (MemPtrSize (pac))))
				
			{
				
					// decrypt the system with old password
				switch (v)	
				{
					case 0:
						UnpackAccount_old(&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 1);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new, true));
						break; 
					case 1:
						UnpackAccount_old (&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 2);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new, true));
						break; 
					case 2:
						UnpackAccount_old(&ac, pac, scratch, SysPass,
										 MemHandleSize (rH), true, true, 0);
						ChangeAccountFormat(i, &ac, &ac_new);
						scratch2 = MemPtrNew (getAccountSize(&ac_new,true));
						break; 
				}

				if (scratch2)
				{
					PackAccount(scratch2, ac_new, &NewSysPass, true);
					MemHandleUnlock (rH);
					writeRecord (scratch2, rH);
					aenc++;
					MemPtrFree (scratch2);
				}
				MemPtrFree (scratch);
			}
			DmReleaseRecord (AccountDB, i, true);
		}
	}
	FrmEraseForm (f);
	FrmDeleteForm (f);
	FrmSetActiveForm (preF);
		// close databases.
	DmCloseDatabase (SystemDB);
	DmCloseDatabase (AccountDB);
	DmCloseDatabase (PasswordDB);

	{
		UInt16 cardNo;
		UInt32 type;
		LocalID dbID;
		DmSearchStateType search;

		type = systemDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, systemDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL, &type, NULL);
	
		type = accountDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, accountDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL, &type, NULL);

		type = passwordDBType;
		DmGetNextDatabaseByTypeCreator(true, &search, passwordDBTypeOld, 
			StripCreator, true, &cardNo, &dbID);
		DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
			NULL, NULL, NULL, NULL,  &type, NULL);

	}

	prefsSize = sizeof (StripPrefType);
	prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true);
    if  (prefsVersion != StripVersionNumber) {
        prefs.smart_beaming = false;
        PrefSetAppPreferences (StripCreator, StripPrefID, StripVersionNumber,
            &prefs, sizeof (StripPrefType), true);
        prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID,
            &prefs, &prefsSize, true);
	} 

	StrIToA (s, senc);
	StrIToA (a, aenc);
	FrmCustomAlert (infoDialog, s, a, NULL);

	StopApplication ();
	SysReset ();
}
Ejemplo n.º 13
0
/** 
 * @brief
 * @param dbP Happydays DB pointer
 * @param AddrCategory The category of Address to be displayed
 * @param start Start position
 * @return The number of total Item
 * @remarks
 * @endif
 */
UInt16 AddrGetHappyDays(DmOpenRef dbP, UInt16 AddrCategory, DateType start)
{
    UInt16 totalItems;
    UInt16 recordNum = 0;
    MemHandle recordH = 0;
    LineItemPtr ptr;
    PackedHappyDays* rp;
    HappyDays r;
    DateType converted;          
    UInt16 currindex = 0;
	Int16 age;

    // if exist, free the memory
    //
    if (gTableRowHandle) {
        MemHandleFree(gTableRowHandle);
        gTableRowHandle = 0;
    }
    
    totalItems = DmNumRecordsInCategory(dbP, AddrCategory);
    if (totalItems > 0) {
        gTableRowHandle = MemHandleNew(sizeof(LineItemType)* totalItems);
        ErrFatalDisplayIf(!gTableRowHandle, "Out of memory");
        
        if ((ptr = MemHandleLock(gTableRowHandle))) {
            for (recordNum = 0; recordNum < totalItems; recordNum++) {
                if ((recordH = DmQueryNextInCategory(dbP, &currindex,
                                                     (UInt16)AddrCategory))) {
                
                    ptr[recordNum].birthRecordNum = currindex;

                    rp = (PackedHappyDays *) MemHandleLock(recordH);
                    /*
                     * Build the unpacked structure for an AddressDB
                     * record.  It is just a bunch of pointers into the rp
                     * structure.
                     */
                    UnpackHappyDays(&r, rp);

                    // original r(in MainDB) not changed
                    //     local change for LineItemType
                    //
					converted = r.date;

                    if (r.flag.bits.nthdays) {
                        int syear, smonth, sday;

                        if (r.flag.bits.lunar || r.flag.bits.lunar_leap) {
                            if  (lunarL2S(lunarRefNum, converted.year + firstYear,
                                          converted.month, converted.day,
                                          r.flag.bits.lunar_leap, &syear, &smonth, &sday) != errNone) {
                                MemHandleUnlock(recordH);
                                currindex++;
                                recordNum--;
                                totalItems--;

                                continue;
                            }
                            converted.day = sday;
                            converted.month = smonth;
                            converted.year = syear - firstYear;
                        }
                        DateAdjust(&converted, r.nth);

                        if (DateToDays(converted) < DateToDays(start)) {
                        	MemHandleUnlock(recordH);
                        	currindex++;
                            recordNum--;
                            totalItems--;

                            continue;
                        }
                        
                    }
                    else if (r.flag.bits.lunar || r.flag.bits.lunar_leap) {

                        if (!FindNearLunar(&converted, start,
                                           r.flag.bits.lunar_leap)) {
                            // ignore the records
                            //
                            converted.year = INVALID_CONV_DATE;
                            // max year(for sorting)
                            //   indicate for invalid date
                            
                        }
                    }
                    else if (r.flag.bits.solar) {
                        int maxtry = 4;
						DateType dt;

						dt = start;

                        DateToInt(dt) = 
							(DateToInt(dt) > DateToInt(converted))
                            ? DateToInt(dt) : DateToInt(converted);

                        if (converted.month < dt.month ||
                            ( converted.month == dt.month
                              && converted.day < dt.day)) {
                            // birthdate is in last year?
                            while (DaysInMonth(converted.month, ++dt.year) < converted.day
                                   && maxtry-- > 0) 
                                ;
                        }
                        else {
                            while (DaysInMonth(converted.month, dt.year) < converted.day
                                   && maxtry-- >0) {
                                dt.year++;
                            }
                            
                        }

                        if (maxtry >0) converted.year = dt.year;
                        else {
                            converted.year = INVALID_CONV_DATE;
                            // max year
                            //   indicate for invalid date
                        }
                    }
        
					if (converted.year != INVALID_CONV_DATE
                        && !r.flag.bits.nthdays 
						&& r.flag.bits.year 
						&& (age = CalculateAge(converted, r.date, r.flag)) >= 0) {
						// calculate age if year exists
						//
						ptr[recordNum].age = age;
					}
					else {
						ptr[recordNum].age = -1;
					}

                    // save the converted data
                    //
                    ptr[recordNum].date = converted;

                    MemHandleUnlock(recordH);
                    currindex++;
                }
            }
            
            // sort the order if sort order is converted date
            //
            if (gPrefsR.sort == 1) {      	// date sort
                SysInsertionSort(ptr, totalItems, sizeof(LineItemType),
                                 (_comparF *)CompareHappyDaysFunc, 1L);
            }
			else if (gPrefsR.sort == 3) {  	// age sort
                SysInsertionSort(ptr, totalItems, sizeof(LineItemType),
                                 (_comparF *)CompareAgeFunc, 1L);
            }
			else if (gPrefsR.sort == 2) {	    // age sort(re)
                SysInsertionSort(ptr, totalItems, sizeof(LineItemType),
                                 (_comparF *)CompareAgeFunc, -1L);
            }
            
            MemPtrUnlock(ptr);
        } else return 0;
    }
    
    return totalItems;
}