home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / linkmaster-src-1.0.4.tar.gz / linkmaster-src-1.0.4.tar / linkmaster-1.0.4 / hack / code03e9.c < prev    next >
C/C++ Source or Header  |  2000-09-05  |  3KB  |  121 lines

  1. /* code03e9.c - SysUIAppSwitch handler
  2.    Copyright ⌐ 1999 Ben Darnell
  3.    This file is a part of LinkMaster,
  4.    which is distributed under the GNU GPL.
  5.    Based on SampleHack by Roger Chaplin <foursquaredev@att.net>
  6. */
  7.  
  8. #include <Pilot.h>
  9. #include <FeatureMgr.h>
  10.  
  11. #include "linkhistoryhack.h"
  12. #include "linkhistoryhackRsc.h"
  13. #define NO_LINKHISTORY
  14. #define NO_LINKSIMPLE
  15. #define NO_LINKCONTAINER
  16. #include "linkaware.h"
  17.  
  18. /* copied from linkmaster/proxy/al/proxyapp.c */
  19. typedef struct {
  20.    DWord creator;
  21.    DWord app_creator;
  22. } LaunchLinkInfoType;
  23. typedef LaunchLinkInfoType* LaunchLinkInfoPtr;
  24.  
  25. static LaunchLinkInfoPtr LaunchLinkNew(DWord creator, CharPtr title);
  26. static void LinkHistoryPush(LinkInfoPtr linkinfo);
  27.      
  28. Err SysUIAppSwitchHandler(UInt cardno, LocalID dbid, Word cmd, Ptr cmdPBP)
  29. {
  30.    DWord temp;
  31.    Err (*oldTrap)(UInt,LocalID,Word,Ptr);
  32.  
  33.    ULong creator, type;
  34.    Char name[33];
  35.    MyPrefsType prefs;
  36.    Word prefssize=sizeof(prefs);
  37.    SWord prefsver;
  38.  
  39.    FtrGet(MYCRID, 0x3e9, &temp);
  40.    oldTrap=(Err(*)(UInt,LocalID,Word,Ptr))temp;
  41.  
  42.    /* check prefs */
  43.    prefsver=PrefGetAppPreferences('LMHH', 0, &prefs, &prefssize, true);
  44.    if (prefsver<1)
  45.       prefs.trackapps=1;
  46.  
  47.    if (prefs.trackapps) {
  48.       /* get creator id of app being launched */
  49.       DmDatabaseInfo(cardno, dbid, name,NULL,NULL,NULL,NULL,
  50.              NULL,NULL,NULL,NULL, &type, &creator);
  51.  
  52.       /* ignore prefs panels */
  53.       if (type!='panl') {
  54.      /* publish the link */
  55.      LinkHistoryPush((LinkInfoPtr)LaunchLinkNew(creator, name));
  56.       }
  57.    }
  58.  
  59.    return oldTrap(cardno, dbid, cmd, cmdPBP);
  60. }
  61.  
  62. /* this function taken from linkmaster/proxy/al/proxyapp.c */
  63. static LaunchLinkInfoPtr LaunchLinkNew(DWord creator, CharPtr title)
  64. {
  65.    LaunchLinkInfoPtr linkinfo;
  66.  
  67.    if (title) {
  68.       /* title is truncated to 32 chars or at the first \n */
  69.       int titlelen=32;
  70.       int tmp;
  71.  
  72.       tmp=StrLen(title);
  73.       if (tmp<titlelen) titlelen=tmp;
  74.  
  75.       tmp=StrChr(title, '\n')-title;
  76.       if ((tmp>0)&&(tmp<titlelen)) titlelen=tmp;
  77.  
  78.       linkinfo=MemPtrNew(65+titlelen);
  79.       if (!linkinfo) return NULL;
  80.       MemSet(linkinfo, 65+titlelen, 0);
  81.       StrNCopy(((CharPtr)linkinfo)+64, title, titlelen);
  82.       ((CharPtr)linkinfo)[64+titlelen]=0;
  83.    } else {
  84.       linkinfo=MemPtrNew(64);
  85.       MemSet(linkinfo, 64, 0);
  86.    };
  87.  
  88.    linkinfo->creator='LPal';
  89.    linkinfo->app_creator=creator;
  90.  
  91.    return linkinfo;
  92. }
  93.  
  94. /* copied from linkmaster/linkaware.c */
  95. void LinkHistoryPush(LinkInfoPtr linkinfo)
  96. {
  97.    Err err;
  98.    DmSearchStateType searchstate;
  99.    UInt cardno;
  100.    LocalID dbid;
  101.    DWord result;
  102.  
  103.    if (!linkinfo)
  104.       return;
  105.    
  106.    /*if (!LinkCheck()) {
  107.      MemPtrFree(linkinfo);
  108.      return;
  109.      }*/
  110.    
  111.    err=DmGetNextDatabaseByTypeCreator(true, &searchstate, 'appl', 'Link', true,
  112.                       &cardno, &dbid);
  113.    if (err) {
  114.       MemPtrFree(linkinfo);
  115.       return;
  116.    };
  117.    MemPtrSetOwner(linkinfo, 0);
  118.    SysAppLaunch(cardno, dbid, 0, linkAppLaunchHistoryPush,
  119.         (Ptr)linkinfo, &result);
  120. }
  121.