⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#task.c.1.29

📁 个人日程管理系统
💻 29
📖 第 1 页 / 共 5 页
字号:
 * Mod	: lb, 2001-09-09 * 		  	adapt to 0.23 db format ***************************************************************************/DateType TaskGetDueDate(DmOpenRef dbP, UInt16 index){	MemHandle h;	TaskExtendedRecordType *p;	DateType date;	DBGMSG((DBB, "TaskGetDueDate"));	h = DmQueryRecord(dbP, index);	if (h)	{		p = MemHandleLock(h);		if (p)			date = StdFields(p)->dueDate;		MemHandleUnlock(h);	}	return date;} // void TaskGetDueDate(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskSetNote * Desc : set the note of a task * Parm :  * 			-> database pointer * 			-> index of the record * 			-> pointer to the note (will be copied), "" to remove the note * Out  :  * Auth : lb, 22.08.2000 * Mod	: lb, 2001-09-09 * 		  	adapt to 0.23 db format ***************************************************************************/pgErr TaskSetNote(DmOpenRef dbP, UInt16 index, Char* note){	MemHandle h;	TaskExtendedRecordType *p;	UInt16 newSize, noteSize, descSize;	TaskFormatType format;	Char* desc;	DBGMSG((DBB, "TaskSetNote"));	noteSize = StrLen(note);	// TODO : this will crash when trying to add a note to a direct link	desc = TaskGetDescription(dbP, index);	descSize = StrLen(desc);	MemPtrFree(desc);	desc=NULL;	h = DmGetRecord(dbP, index);	newSize = MemHandleSize(h) - StrLen(TaskGetNote(dbP, index)) + noteSize;	h = DmResizeRecord(dbP, index, newSize);	p = MemHandleLock(h);	DmStrCopy(p, 		StdFieldsOffset(p) + OffsetOf(TaskStandardFields, description) +		descSize + 1, note);	format = p->format.bits;	format.hasNote = noteSize ? 1 : 0;	DmWrite(p, OffsetOf(TaskExtendedRecordType, format), &format, 		sizeof(TaskFormatType));	MemHandleUnlock(h);	DmReleaseRecord(dbP, index, true);	return pgOK;} // pgErr TaskSetNote(DmOpenRef dbP, UInt16 index, Char* note)/**************************************************************************** * Name : TaskSetDescription * Desc : set the description of a task * Parm :  * 			-> database pointer * 			-> index of the record * 			-> pointer to the description (will be copied) * Out  :  * Auth : lb, 2001-09-09 * Mod	: lb, 2001-11-25 * 		  	adapt to 0.23 db format ***************************************************************************/pgErr TaskSetDescription(DmOpenRef dbP, UInt16 index, Char* desc){	MemHandle h;	TaskExtendedRecordType *p;	UInt16 newSize, noteSize, newDescSize, oldSize, oldDescSize;	Char *oldDesc = NULL;	DBGMSG((DBB, "TaskSetDescription"));	h = DmGetRecord(dbP, index);	noteSize = StrLen(TaskGetNote(dbP, index));	oldSize = MemHandleSize(h);	newDescSize = StrLen(desc);	oldDesc = TaskGetDescription(dbP, index);	oldDescSize = StrLen(oldDesc);	MemPtrFree(oldDesc);	newSize = oldSize - oldDescSize + newDescSize;	DBGMSG((DBB, "oldSize : %hu", oldSize));	DBGMSG((DBB, "noteSize : %hu", noteSize));	DBGMSG((DBB, "newDescSize : %hu", newDescSize));	DBGMSG((DBB, "oldDescSize : %hu", oldDescSize));	DBGMSG((DBB, "newSize : %hu", newSize));	DBGMSG((DBB, "Before resizing the record"));	dbgPrintTask(dbP, index);	if (newSize > oldSize)	{		h = DmResizeRecord(dbP, index, newSize);		if (!h)		{			MessageBox(StrNoMemorySpaces);			return pgError;		}	}	p = MemHandleLock(h);	DBGMSG((DBB, "After resize, before moving the note"));	dbgPrintTask(dbP, index);	// move the note	if (newSize != oldSize)	{		Char *oldNote = NULL;		Char *oldNoteBak = NULL;		oldNoteBak = MemPtrNew(noteSize + 1);		oldNote = TaskGetNote(dbP, index); // buffer is not locked, get it again		SafeCopy(oldNoteBak,oldNote,noteSize+1);		DmWrite(p, 			StdFieldsOffset(p) + OffsetOf(TaskStandardFields, description)			+ newDescSize + 1, oldNoteBak, noteSize + 1);//		DBGMSG((DBB,"Moved note"));//		DBGMSG((DBB,"old note [%s]",oldNoteBak));//		DBGMSG((DBB,"Len of moved note : %d", noteSize));		MemPtrFree(oldNoteBak);	}	DBGMSG((DBB, "After moving the note"));	dbgPrintTask(dbP, index);	// write description	DmStrCopy(p, 		StdFieldsOffset(p) + OffsetOf(TaskStandardFields, description), desc);	DBGMSG((DBB, "After writing the description"));	dbgPrintTask(dbP, index);	if (oldSize > newSize)	{		h = DmResizeRecord(dbP, index, newSize);	}	DBGMSG((DBB, "After final resize"));	dbgPrintTask(dbP, index);	MemHandleUnlock(h);	DmReleaseRecord(dbP, index, true);	DBGMSG((DBB,"TaskSetDesc OK"));	return pgOK;} // pgErr TaskSetDescription(DmOpenRef dbP, UInt16 index, Char* desc)/**************************************************************************** * Name : TaskGetDescriptionEmpty * Desc : get the description of a task * Parm :  * 			-> database pointer * 			-> index of the record * Out  : Boolean *  * Auth : rp, 13.08.2003 * This is a very inneficient way to find out if the description is empty, * however, the code to get the description is very complex, and it is not * a good idea to duplicate it. * ***************************************************************************/Boolean TaskGetDescriptionEmpty(DmOpenRef dbP, UInt16 index){	char* desc = NULL;	Boolean descriptionIsEmpty;	DBGMSG((DBB, "TaskGetDescriptionEmpty"));	desc = TaskGetDescription(dbP,index);	if (*desc)		descriptionIsEmpty=False;	else		descriptionIsEmpty=True;	MemPtrFree(desc);		return descriptionIsEmpty;} // Char* TaskGetDescription(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskGetDescription * Desc : get the description of a task * Parm :  * 			-> database pointer * 			-> index of the record * Out  : pointer to the desc, use it immediately, it could becomme invalid * 		  reading only !!! * Auth : lb, 22.09.2000 *        seagull, 9.10.2000 *           - allocate tmp buffer (because unlocked ptr make warnning *             under POSE) *           - support direct linked task. ***************************************************************************/Char* TaskGetDescription(DmOpenRef dbP, UInt16 index){	char* desc = NULL;	MemHandle h = NULL;	TaskExtendedRecordType* pTask;	DBGMSG((DBB, "TaskGetDescription"));	h = DmQueryRecord(dbP, index);	if (h)	{		pTask = MemHandleLock(h);		if (pTask)		{			desc = TaskGetDescriptionByTaskPtr(pTask);			MemHandleUnlock(h);		}	}	return desc;} // Char* TaskGetDescription(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskGetDescriptionByTaskPtr * Desc : get the description of a task * Parm :  * 			-> Task pointer * Out  : pointer to the desc. must be freed by the caller. * Auth : seagull, 9.10.2000 * 		  burgbach, 2001-08-03 * 		  	- added first name to the address desc * Mod	: lb, 2001-09-10 * 		  	adapt to 0.23 db format ***************************************************************************/Char* TaskGetDescriptionByTaskPtr(TaskExtendedRecordType* pTask){	DmOpenRef db = NULL;	MemHandle hLink = NULL;	Char* desc = NULL;	Char* result = NULL;	Boolean freeDesc = 0;	DBGMSG((DBB, "TaskGetDescriptionByTaskPtr"));	if (pTask->format.bits.itemType == linkType)	{		UInt16 index;		UInt16 attr;		AddrDBRecordType item;				if (pTask->fields.link.builtin)		{			if (pTask->fields.link.dbID == memoLink)			{				if (! MemoGetDatabase(&db, dmModeReadOnly) &&					! DmFindRecordByID(db, pTask->fields.link.uniqueID, &index) &&					! DmRecordInfo(db, index, &attr, NULL, NULL) &&					! (attr & dmRecAttrDelete)  )				{					hLink = DmQueryRecord(db, index);					desc = MemHandleLock(hLink);				}			}			else if (pTask->fields.link.dbID == addressLink)			{				if (! AddrGetDatabase(&db, dmModeReadWrite) &&					! DmFindRecordByID(db, pTask->fields.link.uniqueID, &index) &&					! DmRecordInfo(db, index, &attr, NULL, NULL) &&					! (attr & dmRecAttrDelete)  )				{					UInt16 lenNeeded = 0;					AddrGetRecord(db, index, &item, &hLink);					if (item.fields[name])						lenNeeded = StrLen(item.fields[name]);					if (item.fields[firstName])						lenNeeded += StrLen(item.fields[firstName]);					desc = MemPtrNew(lenNeeded + 2 + 1);					desc[0]=chrNull;					if (item.fields[name])						StrCat(desc, item.fields[name]);					if (item.fields[name] && item.fields[firstName])						StrCat(desc, ", ");					if (item.fields[firstName])						StrCat(desc, item.fields[firstName]);					freeDesc = 1;				}			}		}		else // not builtin		{			// TODO : complete for not builtin link		}	}	else	{		desc = &(StdFields(pTask)->description);	}		if (desc)	{		UInt16 len;		Char* pp = desc;		// because the title of a memo ends with a \n		while (*pp && *pp != '\0' && *pp != '\n') pp++;		len = pp - desc;				result = MemPtrNew(len + 1);		MemMove(result, desc, len);		result[len] = '\0';	}		if (db) DmCloseDatabase(db);	if (hLink) MemHandleUnlock(hLink);	if (freeDesc) MemPtrFree(desc);	return result;} // Char* TaskGetDescriptionByTaskPtr(TaskExtendedRecordType* pTask)/**************************************************************************** * Name : TaskGetNote * Desc : get the note of a task * Parm :  * 			-> database pointer * 			-> index of the record * Out  : pointer to the note, use it immediately, it could becomme invalid * 		  reading only !!! * Auth : lb, 22.08.2000 * Mod	: lb, 2001-09-09 * 		  	adapt to 0.23 db format ***************************************************************************/Char* TaskGetNote(DmOpenRef dbP, UInt16 index){	MemHandle h;	TaskExtendedRecordType *p;	Char* note = NULL;	DBGMSG((DBB, "TaskGetNote"));	h = DmQueryRecord(dbP, index);	if (h)	{		p = MemHandleLock(h);		if (!p)			return NULL;		note = &StdFields(p)->description;		// go to the note field		note += StrLen(note) + 1;		if (note > (Char*)p + MemHandleSize(h))		{			note = NULL;		}		MemHandleUnlock(h);	}	DBGMSG((DBB, "TaskGetNote Exit"));	return note;} // Char* TaskGetNote(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskGetToDoUniqueID * Desc : get the uniqueID of the sync ToDo task * Parm :  * 			-> database pointer * 			-> index of the record * Out  : uniqueID * Auth : lb, 31.08.2000 ***************************************************************************/UInt32 TaskGetToDoUniqueID(DmOpenRef dbP, UInt16 index){	UInt32 uniqueID = 0;	UInt16 size = sizeof(uniqueID);	DBGMSG((DBB, "TaskGetToDoUniqueID"));	if (! TaskGetFormat(dbP, index).hasToDo)		return 0;	TaskGetExtraChunk(dbP, index, Extra_Link_ToDo, 0xff, 		(MemPtr)(&uniqueID), &size);	return uniqueID;} // UInt32 TaskGetToDoUniqueID(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskInputDueDate * Desc : ask user for a due date * Parm :  * 			-> database pointer * 			-> index of the record * Out  :  * Auth : lb, 03.08.2000 * Rem  : bad err handling * TODO : better error handling ***************************************************************************/pgErr TaskInputDueDate(DmOpenRef dbP, UInt16 index){	//TaskRecordType *p;	//MemHandle h;	DateType date;	Boolean selected;	UInt16 month, day, year;	DBGMSG((DBB, "TaskInputDueDate"));	date = TaskGetDueDate(dbP, index);	if (date.month == 0)	{		date = gToday;	}	month = date.month;	day = date.day;	year = date.year + YEAR_OFFSET; // year offset	selected = SelectDay(selectDayByDay, &month, &day, &year, "Choose a due date");	if (selected)	{		date.month = month;		date.day = day;		date.year = year - YEAR_OFFSET;		TaskSetDueDate(dbP, index, date);		// This caused a bug with the new db format of 0.23		//h = DmGetRecord(dbP, index);		//p = MemHandleLock(h);		//DmWrite(p, OffsetOf(TaskRecordType, dueDate), &date, sizeof(DateType));		//MemHandleUnlock(h);		//DmReleaseRecord(dbP, index, true);	}	return pgOK;} // pgErr TaskInputDueDate(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskSave * Desc : (temporarily) save a record (copy it and create as last index) * In   :  * 			-> record to save * Out  :  * Auth : lb, 03.08.2000 * Rem  : doesn't handle err codes * Mod  : lb, 07.09.2000 * 			- keep the same uniqueID and attr ***************************************************************************/pgErr TaskSave(UInt16 index){	MemHandle hNew, hOld;	TaskRecordType *pNew, *pOld;	UInt32 size = TaskRecordTypeSize, uniqueID;	UInt16 realIndex = dmMaxRecordIndex, attr;	DBGMSG((DBB, "TaskSave"));	// get a handle on the record to save	hOld = DmQueryRecord(gdbP, index);	// calc the needed size	size = MemHandleSize(hOld);	// get a handle on a newly created record	hNew = DmNewRecord(gdbP, &realIndex, size);	// get a pointer on the record	pNew = MemHandleLock(hNew);	// get a pointer on it	pOld = MemHandleLock(hOld);	// write the data	DmWrite(pNew, 0, pOld, size);	// unlock the pointers	MemHandleUnlock(hNew);	MemHandleUnlock(hOld);	// unlock the record	DmReleaseRecord(gdbP, realIndex, true);	// to allow sync	// get the unique ID of original task	DmRecordInfo(gdbP, index, &attr, &uniqueID, NULL);	// set the unique ID of the new task	DmSetRecordInfo(gdbP, realIndex, &attr, &uniqueID);	return pgOK;} // pgErr TaskSave(UInt16 index)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -