home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
linuxmafia.com 2016
/
linuxmafia.com.tar
/
linuxmafia.com
/
pub
/
palmos
/
progect-src-0.20.tar.gz
/
progect-src-0.20.tar
/
progect-0.20
/
progectdb.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-10-26
|
24KB
|
976 lines
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- */
#include "task.h"
#include "progect.h"
#include "progectdb.h"
#include "progectRsc.h"
/****************************************************************************
* Name : AddRecord
* Desc : add a record to the database
* In : database, record to add
* Out : new index
* Auth : lb, 27.07.2000
* Mod : lb, 03.08.2000
* support to insert as a brother of selected task
* Mod : lb, 22.08.2000
* added field for note
* Rem : doesn't handle err codes
***************************************************************************/
Err AddRecord(DmOpenRef dbP, TaskTypePtr task, UInt16 *index)
{
MemHandle h;
TaskRecordType *p;
UInt32 size = TaskRecordTypeSize;
Err Err = errNone;
UInt16 realIndex;
// pack this in a newly allocated record
// calc the needed size
size += (StrLen(task->description) + StrLen(task->note));
// get a handle on a newly created record
// new one always comes after actual
if (DmNumRecords(dbP) == 0)
{
realIndex = 0;
}
else if (DmNumRecords(dbP) > 1 && TaskGetHasChild(dbP, gParentTask))
{
realIndex = TaskGetNextRelativeIndex(dbP, *index); // place of new one
}
else
{
realIndex = gParentTask + 1;
}
if (!realIndex)
{
realIndex = dmMaxRecordIndex;
}
h = DmNewRecord(dbP, &realIndex, size);
task->attr.allBits = 0;
task->attr.bits.opened = 1;
//now fixed by task defaults dialog
//task->priority = 6;
task->dueDate.year = 0;
task->dueDate.month = 0;
task->dueDate.day = 0;
// if index = 0, this is the first one
// it's not a real task !!!
if (realIndex == 0)
{
task->attr.bits.hasChild = 0;
}
else
{
// retrieve info about user of previous index
// this sets : level, next
if (*index == 0 || !TaskGetHasChild(dbP, gParentTask))
{
// this is a first child
task->attr.bits.level = gRefLevel + 1;
TaskSetHasChild(dbP, gParentTask, true);
}
else
{
task->attr.bits.level = TaskGetLevel(dbP, *index);
task->attr.bits.hasPrev = 1;
task->attr.bits.hasNext = TaskGetHasNext(dbP, *index);
// update hasNext field in previous
TaskSetHasNext(dbP, *index, true);
if (gProjectPrefs.useFatherStatus)
{
if ((task->attr.bits.level) != FIRST_LEVEL)
{
UInt16 father = TaskGetFatherIndex(dbP, realIndex);
task->dueDate = TaskGetDueDate(dbP, father);
task->priority = TaskGetPriority(dbP, father);
}
}
}
}
// no date by default
//task->dueDate = Today();
// get a pointer on the record
p = MemHandleLock(h);
// write the data
DmWrite(p, 0, task, OffsetOf(TaskRecordType, description));
DmStrCopy(p, OffsetOf(TaskRecordType, description), task->description);
DmStrCopy(p, OffsetOf(TaskRecordType, description) + StrLen(task->description) + 1, task->note);
//DEBUG2("Creating with task note : ", task->note);
// unlock the pointer
MemHandleUnlock(h);
// unlock the record
DmReleaseRecord(dbP, realIndex, true);
*index = realIndex;
return Err;
} // static Err AddRecord(DmOpenRef dbP, TaskTypePtr task, UInt16 *index)
/****************************************************************************
* Name : AddRecordSub
* Desc : add a record to the database, as subtask of index
* In : database, record to add, index
* Out : new index
* Auth : lb, 04.08.2000
* Rem : doesn't handle err codes
* Mod : lb, 13.08.2000
* fix bug, can now create more subtasks. Subtasks always created
* as last child
* Mod : lb, 22.08.2000
* added field for note
***************************************************************************/
Err AddRecordSub(DmOpenRef dbP, TaskTypePtr task, UInt16 *index)
{
MemHandle h;
TaskRecordType *p;
UInt32 size = TaskRecordTypeSize;
Err Err = errNone;
UInt16 realIndex;
// pack this in a newly allocated record
// calc the needed size
size += (StrLen(task->description) + StrLen(task->note));
// get a handle on a newly created record
// new one always comes after actual
realIndex = TaskGetNextRelativeIndex(dbP, *index); // place of new one
if (!realIndex)
{
realIndex = dmMaxRecordIndex;
}
h = DmNewRecord(dbP, &realIndex, size);
// retrieve info about user of previous index
// this sets : level, next
task->attr.allBits = 0;
task->attr.bits.level = TaskGetLevel(dbP, *index) + 1;
task->attr.bits.opened = 1;
task->attr.bits.hasPrev = TaskGetHasChild(dbP, *index);
//task->priority = 6;
task->dueDate.year = 0;
task->dueDate.month = 0;
task->dueDate.day = 0;
if (gProjectPrefs.useFatherStatus)
{
if ((task->attr.bits.level) != FIRST_LEVEL)
{
UInt16 father = TaskGetFatherIndex(dbP, realIndex);
task->dueDate = TaskGetDueDate(dbP, father);
task->priority = TaskGetPriority(dbP, father);
}
}
// if father had children already
if (TaskGetHasChild(dbP, *index))
{
// old last child has now a next
TaskSetHasNext(dbP, realIndex - 1, true);
}
// update hasChild field in father
TaskSetHasChild(dbP, *index, true);
// get a pointer on the record
p = MemHandleLock(h);
// write the data
DmWrite(p, 0, task, OffsetOf(TaskRecordType, description));
DmStrCopy(p, OffsetOf(TaskRecordType, description), task->description);
DmStrCopy(p, OffsetOf(TaskRecordType, description) + StrLen(task->description) + 1, task->note);
// unlock the pointer
MemHandleUnlock(h);
// unlock the record
DmReleaseRecord(dbP, realIndex, true);
*index = realIndex;
return Err;
} // static Err AddRecordSub(DmOpenRef dbP, TaskTypePtr task, UInt16 *index)
/****************************************************************************
* Name : CreateDB
* Desc : create a database
* In :
* -> name without prepanding !
* Out : -
* Auth : lb, 26.07.2000
* Rem : doesn't handle err codes
* Mod : lb, 17.08.2000
* - prepand "lbPG-" to the dbname
***************************************************************************/
Err CreateDB(const char *nameP)
{
UInt16 cardNo = 0;
Char dbname[32];
Err Err = errNone;
LocalID dbID;
TaskType task0;
UInt16 index = 0;
StrCopy(dbname, gPrepend);
StrCat(dbname, nameP);
dbID = DmFindDatabase(cardNo, dbname);
// if database doesn't exist, create it
if (!dbID)
{
Err = DmCreateDatabase(cardNo, dbname, CREATOR, 'DATA', false);
// debug code to initialise a test DB
// OpenDB takes a name without prepend
OpenDB(nameP, &gdbP);
task0 = gEmptyTask;
AddRecord(gdbP, &task0, &index);
CloseDB(gdbP);
gdbP = NULL;
} else
Err = dmErrAlreadyExists;
return Err;
} // static Err CreateDB(const char *nameP)
/****************************************************************************
* Name : RemoveDB
* Desc : remove a database
* In : name of database to remove
* Out : Err code
* Auth : lb, 27.07.2000
* Mod : lb, 17.08.2000
* prepending support
* control of CREATOR ID
***************************************************************************/
Err RemoveDB(const char *nameP)
{
UInt16 cardNo = 0;
Err Err = errNone;
LocalID dbID;
char dbname[32];
UInt32 creatorID;
// try to prepend the name
StrCopy(dbname, gPrepend);
StrCat(dbname, nameP);
dbID = DmFindDatabase(cardNo, dbname);
// if database exists, delete it
if (dbID)
{
DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, &creatorID);
if (creatorID == CREATOR)
{
Err = DmDeleteDatabase(cardNo, dbID);
}
}
else
{
dbID = DmFindDatabase(cardNo, nameP);
// if database exists, delete it
if (dbID)
{
DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, &creatorID);
if (creatorID == CREATOR)
{
Err = DmDeleteDatabase(cardNo, dbID);
}
}
}
return Err;
} // static Err RemoveDB(const char *nameP)
/****************************************************************************
* Name : OpenDB
* Desc : open a database by name
* Prm :
* -> name of the db to open without prepending
* <-> database reference
* Out : Err code
* Auth : lb, 27.07.2000
* Mod : lb, 14.08.2000
* to save app current state
* lb, 17.08.2000
* try to prepend
* lb, 24.08.2000
* fix without prepending mode that caused a crash after two
* come backs
***************************************************************************/
Err OpenDB(const char* nameP, DmOpenRef *dbP)
{
UInt16 cardNo = 0;
UInt16 mode = dmModeReadWrite;
Err Err = 0;
char dbname[32];
// try to prepend the name
StrCopy(dbname, gPrepend);
StrCat(dbname, nameP);
// find the database
gdbID = DmFindDatabase(cardNo, dbname);
if (!gdbID)
{
// try without prepending (for databases before V0.10)
// find the database
StrCopy(dbname, nameP);
gdbID = DmFindDatabase(cardNo, dbname);
// if found
if (!gdbID)
{
return DmGetLastErr();
}
}
// open it
*dbP = DmOpenDatabase(cardNo, gdbID, mode);
// if it failed
if (!*dbP)
{
// get error code
Err = DmGetLastErr();
}
else
{
StrCopy(gCurrentPrefs.openDBName, dbname);
gCurrentPrefs.openDB = true;
LoadDBPrefs(*dbP);
if (gProjectPrefs.autoSyncToDo)
{
TaskSyncAll();
}
// save/restore the pointer have no meaning,
// and it will be crash program.
// NOTE: fix BUG#115440
// "Newly created task/note has garbage text in it"
MemMove((MemPtr)&gEmptyTask,
(MemPtr)&gProjectPrefs.taskDefaults,
(UInt8*)&(gEmptyTask.description) - (UInt8*)&gEmptyTask);
// gEmptyTask = gProjectPrefs.taskDefaults;
}
return Err;
} // static Err OpenDB(const char* nameP, DmOpenRef *dbP)
/****************************************************************************
* Name : OpenDBByID
* Desc : open a database by cardNo and dbID
* Prm :
* -> card no
* -> database id
* <-> database reference
* Out : Err code
***************************************************************************/
Err OpenDBByID(UInt16 cardNo, LocalID dbID, DmOpenRef* dbP)
{
// Open
Char* name;
DmOpenRef pDB = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);
if (! pDB)
return DmGetLastErr();
// close current opend DB
if (*dbP)
CloseDB(*dbP);
// setting up global status.
*dbP = pDB;
gdbID = dbID;
name = MemPtrNew(32);
DmDatabaseInfo(cardNo, dbID, name, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
StrCopy(gCurrentPrefs.openDBName, name);
MemPtrFree(name);
gCurrentPrefs.openDB = true;
LoadDBPrefs(pDB);
if (gProjectPrefs.autoSyncToDo)
TaskSyncAll();
return 0;
} // static Err OpenDB(const char* nameP, DmOpenRef *dbP)
/****************************************************************************
* Name : CloseDB
* Desc : close the database
* In : pointer to the database to close
* Out : Err code
* Auth : lb, 27.07.2000
* Mod : lb, 14.08.2000
* to save app current state
***************************************************************************/
Err CloseDB(DmOpenRef dbP)
{
Err Err;
SaveDBPrefs(dbP);
// close the database
Err = DmCloseDatabase(dbP);
gCurrentPrefs.openDB = false;
gCurrentPrefs.topTask = -1;
gdbID = 0;
gdbP = NULL;
return Err;
} // static Err CloseDB(DmOpenRef dbP)
/****************************************************************************
* Name : RenameDB
* Desc : rename a database
* In :
* -> old name (with or without prepending)
* -> new name (with or without prepending)
* Out : -
* Auth : lb, 23.08.2000
***************************************************************************/
Err RenameDB(Char* oldName, Char* newName)
{
UInt16 cardNo = 0;
LocalID dbID;
Prepend(newName);
// find the database (without prepending)
dbID = DmFindDatabase(cardNo, oldName);
if (!dbID)
{
// try with prepending
// find the database
Prepend(oldName);
dbID = DmFindDatabase(cardNo, oldName);
if (!dbID)
return DmGetLastErr();
}
return DmSetDatabaseInfo(cardNo, dbID, newName, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
} // static Err RenameDB(Char* oldName, Char* newName)
/****************************************************************************
* Name : SaveDBPrefs
* Desc : save the database preferences
* In :
* Out : -
* Auth : lb, 17.08.2000
***************************************************************************/
void SaveDBPrefs(DmOpenRef dbP)
{
LocalID appInfoID;
DBInfoType* p;
MemHandle h;
appInfoID = DmGetAppInfoID(dbP);
// if there is no appInfoID, create it
if (! appInfoID)
{
h = DmNewHandle(dbP, sizeof(DBInfoType));
if (!h)
return;
appInfoID = MemHandleToLocalID(h);
DmSetDatabaseInfo(0, gdbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&appInfoID, NULL, NULL, NULL);
p = MemLocalIDToLockedPtr(appInfoID, 0);
DmSet(p, 0, sizeof(DBInfoType), 0);
CategoryInitialize(&p->appInfo, InitialCategory);
}
else
p = MemLocalIDToLockedPtr(appInfoID, 0);
// test the size
// if it's not good, the next LoadDBPrefs will correct it
if (MemPtrSize(p) == sizeof(DBInfoType))
{
// write the new prefs
DmWrite(p, OffsetOf(DBInfoType, pref),
&gProjectPrefs, sizeof(ProjectPrefsType));
}
// unlock
MemPtrUnlock(p);
} // static void SaveDBPrefs(void)
/****************************************************************************
* Name : LoadDBPrefs
* Desc : load the database preferences
* In :
* Out : false = no prefs
* true = ok
* Auth : lb, 17.08.2000
* Mod : lb, 17.08.2000
* - pass db, because when OpenDB calls, gdbp is not set !
***************************************************************************/
Boolean LoadDBPrefs(DmOpenRef dbP)
{
DBInfoType *p;
LocalID appInfoID;
LocalID oldInfoID = 0;
appInfoID = DmGetAppInfoID(dbP);
if (appInfoID)
{
p = MemLocalIDToLockedPtr(appInfoID, 0);
if (MemPtrSize(p) < 30 && *(UInt8*)p < 11)
{
DEBUG1("Old database version (<=0.11) conversion, please click OK and wait...");
MemPtrUnlock(p);
ConvertDB(11);
}
if (MemPtrSize(p) != sizeof(DBInfoType) )
{
MessageBox(StrPrefsHasBeenDeleted);
oldInfoID = appInfoID;
appInfoID = 0;
MemPtrUnlock(p);
}
}
if (! appInfoID)
{
// create new prefs
MemHandle h = DmNewHandle(dbP, sizeof(DBInfoType));
if (! h)
return false;
appInfoID = MemHandleToLocalID(h);
DmSetDatabaseInfo(0, gdbID, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, &appInfoID, NULL, NULL, NULL);
// get a pointer
p = MemLocalIDToLockedPtr(appInfoID, 0);
// write the new prefs
DmSet(p, 0, sizeof(DBInfoType), 0);
CategoryInitialize(&p->appInfo, InitialCategory);
if (oldInfoID)
{ // copy original categories
AppInfoType* pp = MemLocalIDToLockedPtr(oldInfoID, 0);
if (MemPtrSize(pp) > sizeof(AppInfoType) + 20)
DmWrite(p, 0, pp, sizeof(AppInfoType));
MemPtrUnlock(pp);
}
DmWrite(p, OffsetOf(DBInfoType, pref),
&gProjectPrefs, sizeof(ProjectPrefsType));
}
// this produced an overlocked pointer => crash every 8th start
//else
//p = MemLocalIDToLockedPtr(appInfoID, 0);
MemMove(&gProjectPrefs, &p->pref, sizeof(ProjectPrefsType));
MemPtrUnlock(p);
if (oldInfoID)
{
// ... ??? how to delete old ID ???
}
return true;
} // static Boolean LoadDBPrefs(DmOpenRef dbP)
/****************************************************************************
* Name : SaveAppPrefs
* Desc : save the application preferences
* In :
* -> saved : true for saved prefs, false for current prefs
* Out : -
* Auth : lb, 14.08.2000
* Mod : lb, 17.08.2000
* support for saved prefs
***************************************************************************/
void SaveAppPrefs(Boolean saved)
{
PrefSetAppPreferences(CREATOR, 0, 1,
saved ? (void*)&gSavedPrefs : (void*)&gCurrentPrefs,
saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType),
saved);
} // static void SaveAppPrefs(Boolean saved)
/****************************************************************************
* Name : LoadAppPrefs
* Desc : load the application preferences
* In :
* -> saved : true for saved prefs, false for current prefs
* Out : false = no prefs
* true = ok
* Auth : lb, 14.08.2000
* Mod : lb, 17.08.2000
* support for saved prefs
***************************************************************************/
Boolean LoadAppPrefs(Boolean saved)
{
UInt16 size = saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType);
UInt16 status;
status = PrefGetAppPreferences(CREATOR, 0,
saved ? (void*)&gSavedPrefs : (void*)&gCurrentPrefs, &size, saved);
status = (size ==
(saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType))) ? status : noPreferenceFound;
return status == noPreferenceFound ? false : true;
} // static Boolean LoadAppPrefs(Boolean saved)
/****************************************************************************
* Name : ConvertDB
* Desc : convert an old DB to the actual format
* In :
* -> old format
* Out : -
* Auth : lb, 22.08.2000
***************************************************************************/
void ConvertDB(UInt8 format)
{
Char dbname[32];
Char tmp[32];
UInt16 recNum;
Char* tmpName = "lbPG-tmpConvertProcess";
LocalID newID, oldID;
DmOpenRef newDB, oldDB;
MemHandle hOld, hNew;
UInt16 i;
UInt16 fakeIndex;
UInt32 size;
UInt16 cardNo = 0;
TaskFormatType taskFormat = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
TaskAttrType attr;
StrCopy(dbname, gCurrentPrefs.openDBName);
switch (format)
{
case 11:
DmCloseDatabase(gdbP);
RenameDB(dbname, tmpName);
// if the name was prepended
if (StrStr(dbname, gPrepend) == dbname)
{
// create, pass the name without prepending
CreateDB(&dbname[5]);
// open (prepended name)
newID = DmFindDatabase(cardNo, dbname);
}
else
{
// create, pass the name
CreateDB(dbname);
// prepend for opening
StrCopy(tmp, gPrepend);
StrCat(tmp, dbname);
StrCopy(dbname, tmp);
newID = DmFindDatabase(cardNo, dbname);
}
// open the databases
oldID = DmFindDatabase(cardNo, tmpName);
newDB = DmOpenDatabase(cardNo, newID, dmModeReadWrite);
oldDB = DmOpenDatabase(cardNo, oldID, dmModeReadOnly);
// get the number of records
recNum = DmNumRecords(oldDB);
taskFormat.hasDueDate = 1;
taskFormat.newFormat = 1;
// convert each record (except task0)
for (i = 1; i < recNum; i++)
{
TaskRecordTypeV011 *pOld;
TaskRecordType *pNew;
// get the old one
hOld = DmQueryRecord(oldDB, i);
pOld = MemHandleLock(hOld);
fakeIndex = dmMaxRecordIndex;
// calc the size of the new one
size = TaskRecordTypeSize + StrLen(&pOld->description);
// create a record
hNew = DmNewRecord(newDB, &fakeIndex, size);
// reget the pointer
MemHandleUnlock(hOld);
pOld = MemHandleLock(hOld);
// convert attributes
attr.level = pOld->level;
attr.hasNext = pOld->hasNext;
attr.hasChild = pOld->hasChild;
attr.opened = pOld->opened;
attr.hasPrev = !pOld->firstChild;
pNew = MemHandleLock(hNew);
// write
// first, reset it (to have the note be \0)
DmSet(pNew, 0, size, 0);
DmWrite(pNew, OffsetOf(TaskRecordType, attr), &attr,
sizeof(UInt16));
DmWrite(pNew, OffsetOf(TaskRecordType, format), &taskFormat,
sizeof(UInt16));
DmWrite(pNew, OffsetOf(TaskRecordType, priority),
&pOld->priority, sizeof(UInt8));
DmWrite(pNew, OffsetOf(TaskRecordType, completed),
&pOld->completed, sizeof(UInt8));
DmWrite(pNew, OffsetOf(TaskRecordType, dueDate),
&pOld->dueDate, sizeof(DateType));
DmStrCopy(pNew, OffsetOf(TaskRecordType, description),
&pOld->description);
MemHandleUnlock(hOld);
MemHandleUnlock(hNew);
DmReleaseRecord(newDB, fakeIndex, true);
}
gdbP = newDB;
gdbID = newID;
DmCloseDatabase(oldDB);
DmDeleteDatabase(cardNo, oldID);
break;
default:
break;
}
} // static void ConvertDB(UInt8 format)
/****************************************************************************
* Name : Prepend
* Desc : check if a name is prepended, if not, prepend it
* In :
* <-> name
* Out : -
* Auth : lb, 26.08.2000
***************************************************************************/
void Prepend(Char* name)
{
Char tmp[32];
// if the name is not prepended
if (StrStr(name, gPrepend) != name)
{
// prepend the name
StrCopy(tmp, gPrepend);
StrCat(tmp, name);
StrCopy(name, tmp);
}
} // void Prepend(Char* name)
/****************************************************************************
* Name : DuplicateDB
* Desc : duplicate a project
* In :
* -> source (with or without prepending)
* -> dest ( " " " )
* Out : -
* Auth : lb, 27.08.2000
***************************************************************************/
Err DuplicateDB(Char* src, Char* dbname)
{
Char tmp[32];
UInt16 recNum;
LocalID newID, oldID;
DmOpenRef newDB, oldDB;
MemHandle hOld, hNew;
TaskRecordType *pOld, *pNew;
UInt16 i;
UInt16 index;
UInt16 cardNo = 0;
Err err;
// if the name was prepended
if (StrStr(dbname, gPrepend) == dbname)
{
// create, pass the name without prepending
err = CreateDB(&dbname[5]);
// open (prepended name)
if (!err)
newID = DmFindDatabase(cardNo, dbname);
else
return err;
}
else
{
// create, pass the name
err = CreateDB(dbname);
// prepend for opening
if (!err) {
StrCopy(tmp, gPrepend);
StrCat(tmp, dbname);
StrCopy(dbname, tmp);
newID = DmFindDatabase(cardNo, dbname);
} else
return err;
}
// prepend (if needed)
Prepend(src);
// open the databases
oldID = DmFindDatabase(cardNo, src);
newDB = DmOpenDatabase(cardNo, newID, dmModeReadWrite);
oldDB = DmOpenDatabase(cardNo, oldID, dmModeReadOnly);
// get the number of records
recNum = DmNumRecords(oldDB);
// copy each record (except task0)
for (i = 1; i < recNum; i++)
{
index = dmMaxRecordIndex;
hOld = DmQueryRecord(oldDB, i);
pOld = MemHandleLock(hOld);
hNew = DmNewRecord(newDB, &index, MemPtrSize(pOld));
pNew = MemHandleLock(hNew);
DmWrite(pNew, 0, pOld, MemPtrSize(pOld));
MemHandleUnlock(hNew);
MemHandleUnlock(hOld);
DmReleaseRecord(newDB, index, true);
}
DmCloseDatabase(oldDB);
DmCloseDatabase(newDB);
return errNone;
} // void DuplicateDB(Char* src, Char* dbname)
/****************************************************************************
* Name : OpenClipboard
* Desc : open the clipboard, create it if it doesn't exist
* In :
* Out : -
* Auth : lb, 04.09.2000
***************************************************************************/
pgErr OpenClipboard(void)
{
UInt16 cardNo = 0;
Err err = errNone;
LocalID dbID;
char dbname[] = "lbPG-Clipboard";
UInt16 index = 0;
dbID = DmFindDatabase(cardNo, dbname);
// if database doesn't exist, create it
if (!dbID)
{
err = DmCreateDatabase(cardNo, dbname, CREATOR, 'CLIP', false);
if (err)
{
DEBUG1("Cannot create a clipboard database.");
return pgError;
}
dbID = DmFindDatabase(cardNo, dbname);
}
gClip = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);
if (DmNumRecords(gClip) == 0)
{
DEBUG1("Adding task 0");
AddRecord(gClip, &gEmptyTask, &index);
}
return pgOK;
} // pgErr OpenClipboard(void)
/****************************************************************************
* Name : CloseClipboard
* Desc : close the clipboard
* In :
* Out : -
* Auth : lb, 04.09.2000
***************************************************************************/
pgErr CloseClipboard(void)
{
if (gClip)
{
DmCloseDatabase(gClip);
gClip = NULL;
}
return pgOK;
} // pgErr CloseClipboard(void)
/****************************************************************************
* Name : NewClipboard
* Desc : close the clipboard, remove it, create a new one, open it
* In :
* Out : -
* Auth : lb, 05.09.2000
***************************************************************************/
pgErr NewClipboard(void)
{
UInt16 cardNo = 0;
Err err = errNone;
LocalID dbID;
char dbname[] = "lbPG-Clipboard";
UInt16 index = 0;
CloseClipboard();
dbID = DmFindDatabase(cardNo, dbname);
// if database exists, remove it
if (dbID)
{
DmDeleteDatabase(cardNo, dbID);
}
err = DmCreateDatabase(cardNo, dbname, CREATOR, 'CLIP', false);
if (err)
return pgError;
dbID = DmFindDatabase(cardNo, dbname);
gClip = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);
AddRecord(gClip, &gEmptyTask, &index);
return pgOK;
} // pgErr NewClipboard(void)