home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / wapuniverse-src-0.3.5.build9.tar.gz / wapuniverse-src-0.3.5.build9.tar / wapuniverse-0.3.5.build9 / WAPUniverse.c < prev    next >
C/C++ Source or Header  |  2000-11-12  |  7KB  |  254 lines

  1. // ---------------------------------------------------------------------------
  2. // WAPUniverse.c
  3. // Contains the main PalmOS specific code, including PilotMain
  4. // 
  5. // Project: WAPUniverse for PalmOS
  6. // Copyright ⌐ 1999-2000 Filip Onkelinx
  7. //
  8. // http://www.wapuniverse.com/
  9. // filip@onkelinx.com
  10. //
  11. // This program is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU General Public License
  13. // as published by the Free Software Foundation; either version 2
  14. // of the License, or (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program; if not, write to the Free Software 
  23. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  24. //
  25. // 
  26. // $Workfile: WAPUniverse.c $  
  27. // $Author: wapuniverse $  
  28. // $Date: 2000/11/11 20:51:09 $     
  29. // $Revision: 1.11 $
  30. // 
  31. // $Header: /cvsroot/wapuniverse/wapuniverse/src/WAPUniverse.c,v 1.11 2000/11/11 20:51:09 wapuniverse Exp $
  32. // 
  33. // -------------------------------------------------------------------------------
  34.  
  35.  
  36. #include    <PalmOS.h>
  37. #include    <SysEvtMgr.h>
  38. #include     "WAPUniverse.h"
  39. #include    "build.h"
  40. #include     "../res/WAPUniverse_res.h"
  41. #include    "formUrlList.h"
  42. #include    "formConnectionList.h"
  43. #include    "formEditConnection.h"
  44. #include    "formEditUrl.h"
  45. #include    "formBrowser.h"
  46. #include    "frmScroll.h"
  47. #include    "formMTSyncPrefs.h"
  48.  
  49. static UInt16 RomVersionCompatible (UInt32 requiredVersion, UInt16 launchFlags);
  50. static Boolean ApplicationHandleEvent ( EventPtr event );
  51. static int StartApplication(void);
  52. static void EventLoop(void);
  53. static void StopApplication(void);
  54.  
  55. // Following globals are needed if you do not like crashes in the network lib
  56. Int32            AppNetTimeout;
  57. UInt16           AppNetRefnum; // used by SysLibFind
  58. Err              errno;        // Berkely socketinterface 
  59.  
  60. // globals for internal use
  61. //DmOpenRef            gDbUrlDb;          // handle for URL database (bookmarks)
  62. //DmOpenRef            gDbConnDb;          // handle for Connection database 
  63. //UInt16               gCurrentView;    // id of current form
  64.  
  65.  
  66. UInt32 PilotMain(UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
  67. {
  68.     int error;
  69.  
  70.     error = RomVersionCompatible (version20, launchFlags);
  71.     if (error)
  72.        return error;
  73.        
  74.     if (cmd == sysAppLaunchCmdNormalLaunch)
  75.      {
  76.         error = StartApplication();    // Application start code
  77.         if (error) return error;
  78.         EventLoop();            // Event loop
  79.         StopApplication ();        // Application stop code
  80.     }
  81.     return 0;
  82. }        
  83.  
  84. gWAPAppInfoType gWAPAppInfo =
  85. {
  86.   // Renamed categories
  87.   0x0008,                   // set the 2nd and 3rd bits indicating those
  88.                                 // categories as changed.
  89.   {
  90.     "Unfiled",
  91.     "Business",
  92.     "Personal",
  93.     "History",
  94.     "", "", "", "",
  95.     "", "", "", "",
  96.     "", "", "", ""
  97.   },
  98.     // Category Uniq IDs
  99.   {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
  100.     // Last Uniq ID
  101.   15,
  102.     // Reserved
  103.   0, 0
  104. };
  105.  
  106.  
  107. void SwitchForm(UInt16 formID, GlobalsType *g)
  108. {
  109.     FrmGotoForm(formID);
  110.     g->CurrentView = formID;
  111. }
  112.  
  113. void DisplayLicense()
  114. {
  115. MemHandle licenseStr;
  116.         
  117.     licenseStr = DmGetResource (strRsc, strGPL);
  118.     ScrollFrm ("WAPUniverse License", licenseStr);
  119.     
  120. }
  121.  
  122. void DisplayAbout()
  123. {
  124.           ControlPtr      ctl;
  125.           FormPtr         frm;
  126.           
  127.           MenuEraseStatus (0);
  128.           // Load the info form, then display it.
  129.           frm = FrmInitForm (frmInfo);
  130.           ctl = (ControlPtr)(FrmGetObjectPtr(frm,(FrmGetObjectIndex(frm,lblVersion))));
  131.           CtlSetLabel(ctl,VERSIONSTR);
  132.           ctl = (ControlPtr)(FrmGetObjectPtr(frm,(FrmGetObjectIndex(frm,lblBuildDate))));
  133.           CtlSetLabel(ctl,BUILDSTR    );
  134.           FrmDoDialog (frm);
  135.           // Delete the info form. 
  136.           FrmDeleteForm (frm);
  137. }
  138.  
  139.  
  140. static int StartApplication(void)
  141. {
  142.   UInt16         mode;         // permissions when opening the database
  143.   GlobalsType     *g;              // all the globals
  144.  
  145.       // Check if secret record should be shown.
  146.       if (PrefGetPreference (prefHidePrivateRecordsV33))
  147.         mode = dmModeReadWrite;
  148.       else
  149.         mode = dmModeReadWrite | dmModeShowSecret;
  150.  
  151.     g = (GlobalsType *)MemPtrNew(sizeof(GlobalsType));
  152.      MemSet(g, sizeof(GlobalsType), 0);
  153.      FtrSet(wuAppType, ftrGlobals, (UInt32)g);
  154.     g->state = BS_IDLE;
  155.     g->CurrentCategory = dmAllCategories;
  156.     g->Render = true;
  157.     dbConnOpenOrCreateDB(mode,g);
  158.     dbUrlOpenOrCreateDB(mode,g);
  159.     if (dbConnNumRecords(g) >0)
  160.        g->CurrentView = frmUrlList;
  161.     else
  162.        g->CurrentView = frmConnectionList;
  163.     FrmGotoForm (g->CurrentView);
  164.     return 0;
  165. }
  166.  
  167. static Boolean ApplicationHandleEvent(EventPtr event)
  168. {
  169.     FormPtr frm;
  170.     Int16   formId;
  171.     Boolean handled = false;
  172.  
  173.     if (event->eType == frmLoadEvent) {
  174.         formId = event->data.frmLoad.formID;
  175.         frm = FrmInitForm(formId);
  176.         FrmSetActiveForm(frm);
  177.         
  178.         switch(formId) {
  179.  
  180.          case frmUrlList:
  181.              FrmSetEventHandler(frm, ehFormUrlList);
  182.              break;
  183.          case frmEditURL:
  184.              FrmSetEventHandler(frm, ehFormEditURL);
  185.              break;
  186.          case frmBrowser:
  187.              FrmSetEventHandler(frm, ehFormBrowser);
  188.              break;
  189.          case frmEditConnection:
  190.              FrmSetEventHandler(frm, ehFormEditConnection);
  191.              break;
  192.          case frmConnectionList:
  193.              FrmSetEventHandler(frm, ehFormConnectionList);
  194.              break;
  195. // 
  196.  
  197.          default:
  198.          break;
  199.             }
  200.         handled = true;
  201.         }
  202.     return handled;
  203. }
  204.  
  205. void EventLoop(void)
  206. {
  207.     EventType event;
  208.     UInt16 error;
  209.  
  210.     do {
  211.         EvtGetEvent(&event, sysTicksPerSecond/5);  
  212.         if (! SysHandleEvent(&event))
  213.             if (! MenuHandleEvent(0, &event, &error))
  214.                 if (! ApplicationHandleEvent(&event))
  215.                    FrmDispatchEvent(&event);
  216.         } while (event.eType != appStopEvent);
  217. }
  218.  
  219. static void StopApplication(void)        
  220. {
  221.   GlobalsType *g;
  222.  
  223.   // get globals reference
  224.   FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
  225.   FrmCloseAllForms ();
  226.   DmCloseDatabase (g->DbUrlDb);
  227.   DmCloseDatabase (g->DbConnDb);
  228.   MemPtrFree(g);
  229. }
  230.  
  231.  
  232. static UInt16 RomVersionCompatible (UInt32 requiredVersion, UInt16 launchFlags)
  233. {
  234.   UInt32           romVersion;
  235.   
  236.   FtrGet (sysFtrCreator, sysFtrNumROMVersion, &romVersion);
  237.   if (romVersion < requiredVersion)
  238.     {
  239.       if ((launchFlags & (sysAppLaunchFlagNewGlobals |
  240.           sysAppLaunchFlagUIApp)) ==
  241.           (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
  242.         {
  243.           FrmAlert (alRomIncompatible);
  244.           if (romVersion < 0x02000000){
  245.             AppLaunchWithCommand (sysFileCDefaultApp,
  246.                                   sysAppLaunchCmdNormalLaunch, NULL);
  247.       }
  248.         }
  249.       return (sysErrRomIncompatible);
  250.     }
  251.   return 0;
  252. }
  253.  
  254.