📄 projlistmodel.c
字号:
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- *//* Main code for Project *///#define ERROR_CHECK_LEVEL 2#include <PalmOS.h>#include <DateGlue.h>#include <TxtGlue.h>#include <FntGlue.h>#include <TsmGlue.h>#include <WinGlue.h>#include "handera/Vga.h"//#include "SonyCLIE.h"#include "link.h"#include "task.h"#include "xb.h"#include "progectdb.h"#include "progectRsc.h"#include "progect.h"#include "flat.h"#include "btm.h"#include "beam.h"// icon support#include "icon.h"// ToDo export support#include "ToDoDB.h"// Memo linking support#include "MemoDB.h"// address linking support#include "AddressDB.h"// Doc export support#include "doc.h"// Category support#include "category.h"// history support#include "history.h"// hotsync support#include "aftersync.h"#include "projlistMODEL.h"// prototypes// events// app info block for Project List Databasetypedef struct { AppInfoType appInfo; UInt8 appInfoVersion; UInt8 sortOrderType; UInt16 currentCategory; UInt16 lastSentinelValue;} ProjectListAppInfoType;// staticsstatic struct ProjectListMODELGlobals *PLM_Globals=NULL;ProjectListEntry *ProjectListMODELGetRecord(UInt16 index){MemHandle dbRecord;ProjectListEntry *dbRecordStruct; dbRecord=DmQueryRecord(PLM_Globals->databaseRef,index); if (NULL == dbRecord) { // +++ FIX THIS +++ Output error in debug mode return NULL; } dbRecordStruct=MemHandleLock(dbRecord); if (NULL == dbRecordStruct) { // +++ FIX THIS +++ Output error in debug mode return NULL; } // make sure you MemPtrUnlock this... return dbRecordStruct;}void ProjectListMODELInit(void){ ProjectListMODELInitINTERNAL(&PLM_Globals);}void ProjectListMODELInitINTERNAL(struct ProjectListMODELGlobals **plGlobals){ const char *listDBName="lbPG-PROJECT_META_DATA"; Err err; LocalID dbID; Boolean initializeMetaDataDatabase=false; MemHandle h; LocalID appInfoID; ProjectListAppInfoType *appInfoP; char deleteMe[40];// DEBUG1("About to init"); // If we have already allocated arrays then just increase the refcount if (NULL != *plGlobals) { StrIToA(deleteMe, (*plGlobals)->refCount);// DEBUG2("Current ref count1 init",deleteMe); (*plGlobals)->refCount++; StrIToA(deleteMe, (*plGlobals)->refCount);// DEBUG2("Current ref count2 init",deleteMe); return; }// DEBUG1("About to create structs in init"); *plGlobals=MemPtrNew(sizeof(struct ProjectListMODELGlobals)); MemSet(*plGlobals,sizeof(struct ProjectListMODELGlobals),0); // have to start at one, because the deallocation routine assumes this (*plGlobals)->refCount=1; StrIToA(deleteMe, (*plGlobals)->refCount);// DEBUG2("Current ref count3 init",deleteMe); // // Open the database that lists all the projects we know about // dbID=DmFindDatabase((*plGlobals)->cardNumber,listDBName); if (NULL == dbID) { err=DmGetLastErr(); if (dmErrCantFind == err) { // doesn't exist, okay, then try creating it err=DmCreateDatabase((*plGlobals)->cardNumber,listDBName,'lbPG','META',false); if (err) { // +++ FIX THIS +++ // Failed to create // Bring up fatal error dialog, and quit program // +++ FIX THIS +++ DEBUG1("Failed to create project Metadata database"); return; } // let's try that find _again_ dbID=DmFindDatabase((*plGlobals)->cardNumber,listDBName); // remember we need to create the AppInfoBlock, since the database was created // and will not have one. initializeMetaDataDatabase=true; } } if (NULL == dbID) { // +++ FIX THIS +++ // Failed to find the database we need, even after we must have successfully // created it. // Bring up fatal error dialog, and quit program // +++ FIX THIS +++ DEBUG1("Failed to open project Metadata database"); return; } (*plGlobals)->databaseRef=DmOpenDatabase((*plGlobals)->cardNumber,dbID,dmModeReadWrite); if (NULL == (*plGlobals)->databaseRef) { // +++ FIX THIS +++ // Failed to open the database we need // Bring up fatal error dialog, and quit program // +++ FIX THIS +++ return; } // // Create the AppInfoBlock if required // if (initializeMetaDataDatabase) { UInt16 attributes; // set the backup bit DmDatabaseInfo((*plGlobals)->cardNumber,dbID,NULL,&attributes,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); attributes |= dmHdrAttrBackup; h=DmNewHandle((*plGlobals)->databaseRef,sizeof(ProjectListAppInfoType)); if (!h) { // +++ FIX THIS +++ // Failed to create the AppInfo Block // Bring up fatal error dialog, and quit program // +++ FIX THIS +++ return; } appInfoID=MemHandleToLocalID(h); // set the application info block err=DmSetDatabaseInfo((*plGlobals)->cardNumber,dbID,NULL,&attributes,NULL, NULL,NULL,NULL,NULL,&appInfoID,NULL,NULL,NULL); if (errNone == err) { appInfoP=(ProjectListAppInfoType *)MemHandleLock(h); // clear everything DmSet(appInfoP,0,sizeof(ProjectListAppInfoType),0); // set category info CategoryInitialize(&appInfoP->appInfo,ProjectDefaultCategoryList); // unlock MemPtrUnlock(appInfoP); } else { MemHandleFree(h); // +++ FIX THIS +++ // Failed to create the AppInfo Block // Bring up fatal error dialog, and quit program // +++ FIX THIS +++ return; } }} // void ProjectListMODELInit(void)void ProjectListMODELCleanUp(void){ ProjectListMODELCleanupINTERNAL(&PLM_Globals);}void ProjectListMODELCleanupINTERNAL(struct ProjectListMODELGlobals **plGlobals){ char deleteMe[40];// DEBUG1("About to de-init"); StrIToA(deleteMe, (*plGlobals)->refCount);// DEBUG2("Current ref count1 Cleanup",deleteMe); if (--(*plGlobals)->refCount) return;// DEBUG1("Really going to delete"); StrIToA(deleteMe, (*plGlobals)->refCount);// DEBUG2("Current ref count2 Cleanup",deleteMe); // // Close the project list database // if ((*plGlobals)->databaseRef) DmCloseDatabase((*plGlobals)->databaseRef); (*plGlobals)->databaseRef=NULL; MemPtrFree(*plGlobals); *plGlobals=NULL;// DEBUG1("All done deleting"); } // void ProjectListMODELCleanUp(void)UInt16 ProjectListMODELGetCurrentCategory(void){ ProjectListAppInfoType *appInfoP; UInt16 currentCategory; // grab the application info block and get the category appInfoP=(ProjectListAppInfoType *)MemLocalIDToLockedPtr(DmGetAppInfoID(PLM_Globals->databaseRef),PLM_Globals->cardNumber); currentCategory=appInfoP->currentCategory; MemPtrUnlock(appInfoP); return currentCategory;}void ProjectListMODELSetCurrentCategory(UInt16 currentCategory){ ProjectListAppInfoType *appInfoP; // grab the application info block and set the category appInfoP=(ProjectListAppInfoType *)MemLocalIDToLockedPtr(DmGetAppInfoID(PLM_Globals->databaseRef),PLM_Globals->cardNumber); DmWrite(appInfoP, OffsetOf(ProjectListAppInfoType, currentCategory), ¤tCategory, sizeof(UInt16)); MemPtrUnlock(appInfoP);}UInt16 ProjectListMODELGetRecordCategory(UInt16 record){ UInt16 attr; DmRecordInfo (PLM_Globals->databaseRef, record, &attr, NULL, NULL); attr &= dmRecAttrCategoryMask; return attr;}void ProjectListMODELSetRecordCategory(UInt16 record,UInt16 newCategory){ UInt16 attr; // If the category is All then set the category to unfiled. DmRecordInfo (PLM_Globals->databaseRef, record, &attr, NULL, NULL); attr &= ~dmRecAttrCategoryMask; attr |= ((dmAllCategories == newCategory) ? dmUnfiledCategory : newCategory) | dmRecAttrDirty; DmSetRecordInfo (PLM_Globals->databaseRef, record, &attr, NULL);}static UInt16 GetLastSentinelValueINTERNAL(struct ProjectListMODELGlobals **plGlobals){ ProjectListAppInfoType *appInfoP; UInt16 lastSentinelValue; // grab the application info block and get the category appInfoP=(ProjectListAppInfoType *)MemLocalIDToLockedPtr(DmGetAppInfoID((*plGlobals)->databaseRef),(*plGlobals)->cardNumber); lastSentinelValue=appInfoP->lastSentinelValue; MemPtrUnlock(appInfoP); return lastSentinelValue;}static void SetLastSentinelValueINTERNAL(struct ProjectListMODELGlobals **plGlobals, UInt16 lastSentinelValue){ ProjectListAppInfoType *appInfoP; // grab the application info block and set the category appInfoP=(ProjectListAppInfoType *)MemLocalIDToLockedPtr(DmGetAppInfoID((*plGlobals)->databaseRef),(*plGlobals)->cardNumber); DmWrite(appInfoP, OffsetOf(ProjectListAppInfoType, lastSentinelValue), &lastSentinelValue, sizeof(UInt16)); MemPtrUnlock(appInfoP);}DmOpenRef ProjectListMODELGetDBRef(void){ return PLM_Globals->databaseRef;} // DmOpenRef ProjectListMODELGetDBRef void updateAddProjectModelEntryINTERNAL(struct ProjectListMODELGlobals **plGlobals, ProjectListEntry *newEntry){UInt16 recordNumber;MemHandle dbRecord;ProjectListEntry *dbRecordStruct;UInt16 sentinelValue=GetLastSentinelValueINTERNAL(plGlobals); if (FindInSortedDatabase((*plGlobals)->databaseRef,CompareProjectEntryByCardProjectName,newEntry,&recordNumber)) { // // Already exists // dbRecord=DmGetRecord((*plGlobals)->databaseRef,recordNumber);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -