/* Main code for AN Proxy
   Copyright (C) Mitch Blevins, 2000
   <mblevin@debian.org>
   http://blevins.simplenet.com/palm/
   Licensed under the GNU GPL
   http://gnu.org/copyleft/gpl.html
*/

#include <Pilot.h>

typedef struct {
    UInt32 view;
    UInt32 mode;
    UInt32 reserved;
} ANLaunchParams;

#define ANCustomLaunch 0x8000

#ifdef VIEWAGENDA
#define CUSTOMVIEW 0
#endif

#ifdef VIEWWEEK
#define CUSTOMVIEW 1
#endif

#ifdef VIEWMONTH
#define CUSTOMVIEW 2
#endif

#ifdef VIEWQUARTER
#define CUSTOMVIEW 3
#endif

#ifdef VIEWCONTACT
#define CUSTOMVIEW 4
#endif

DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
{
    Word err;
    ANLaunchParams *params;
    DmSearchStateType searchstate;
    UInt cardNo;
    LocalID dbID;

    if (cmd == sysAppLaunchCmdNormalLaunch) {
        params = MemPtrNew(sizeof(ANLaunchParams));
        if (!params) return 0;
        MemSet(params, sizeof(ANLaunchParams), 0);
        params->view = CUSTOMVIEW;
        err = DmGetNextDatabaseByTypeCreator(true, &searchstate,
                        sysFileTApplication, 'Actn', true, &cardNo, &dbID);
        if (err) {
            MemPtrFree(params);
        }
        else {
            MemPtrSetOwner(params, 0);
            SysUIAppSwitch(cardNo, dbID, ANCustomLaunch, (Ptr)params);
        }
    }

    return 0;
}
