home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / utilities / amipop116.lha / AmiPOP116 / source / pop_cx.c < prev    next >
C/C++ Source or Header  |  1995-01-04  |  3KB  |  156 lines

  1.  
  2. #include "pop.h"
  3.  
  4. struct Library *CxBase;
  5.  
  6. int setupcx(void)
  7. {
  8.     LONG berrors;
  9.  
  10.     CxObj *filter, *sender, *translate;
  11.  
  12.     DoFmt(cxname,"AmiPOP(%s)",FilePart(mailbox));
  13.     newbroker.nb_Name=cxname;
  14.  
  15.     DoFmt(cxdesc,"Mailbox for \"%s@%s\"",username,pophost);
  16.     newbroker.nb_Descr=cxdesc;
  17.  
  18.     if (CxBase = OpenLibrary("commodities.library", 37L) )
  19.     {
  20.         if (amipop_mp = CreateMsgPort() )
  21.         {
  22.             newbroker.nb_Port = amipop_mp;
  23.             broker = CxBroker(&newbroker, &berrors);
  24.             if ( berrors != CBERR_OK  )
  25.             {
  26.                 closecx();
  27.                 return(0);
  28.             }
  29.  
  30.             if (hotkey)
  31.             {
  32.                 if ( filter=CxFilter(hotkey) )
  33.                 {
  34.                     AttachCxObj(broker, filter);
  35.                     if ( sender=CxSender(amipop_mp, EVT_HOTKEY) )
  36.                     {
  37.                         AttachCxObj(filter,sender);
  38.                         if (translate= CxTranslate(NULL))
  39.                         {
  40.                             AttachCxObj(filter,translate);
  41.                             ActivateCxObj(broker, 1L);
  42.                         }
  43.                         else
  44.                         {
  45.                             closecx();
  46.                             return(0);
  47.                         }
  48.                     }
  49.                     else
  50.                     {
  51.                         closecx();
  52.                         return(0);
  53.                     }
  54.                 }
  55.                 else
  56.                 {
  57.                     closecx();
  58.                     return(0);
  59.                 }
  60.             }
  61.  
  62.             cxsigflag = 1L << amipop_mp->mp_SigBit;
  63.         }
  64.         else
  65.         {
  66.             closecx();
  67.             return(0);
  68.         }
  69.  
  70.         return(1);
  71.     }
  72.     else
  73.     {
  74.         closecx();
  75.         return(0);
  76.     }
  77. }
  78.  
  79. void closecx( void )
  80. {
  81.  
  82.     CxMsg *msg;
  83.  
  84.     if (amipop_mp)
  85.     {
  86.            if (broker) DeleteCxObjAll(broker);
  87.  
  88.         while (msg = (CxMsg *)GetMsg(amipop_mp) )
  89.         {
  90.             ReplyMsg( (struct Message *)msg );
  91.         }
  92.  
  93.         DeleteMsgPort(amipop_mp);
  94.     }
  95.  
  96.     if (CxBase) CloseLibrary(CxBase);
  97.  
  98.     cxsigflag=NULL;
  99.     amipop_mp=NULL;
  100.     CxBase=NULL;
  101.     broker=NULL;
  102. }
  103.  
  104. int docx (void)
  105. {
  106.     CxMsg *msg;
  107.     ULONG msgid;
  108.     int keepgoing=1;
  109.  
  110.     while (msg = (CxMsg *)GetMsg(amipop_mp) )
  111.     {
  112.         msgid = CxMsgID(msg);
  113.         ReplyMsg( (struct Message *)msg);
  114.  
  115.         switch(msgid)
  116.         {
  117.             case CXCMD_DISABLE:
  118.                 checkper=FALSE;
  119.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_TIME], Project0Wnd, NULL, GA_Disabled, !checkper,TAG_END);
  120.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_CRONCHECK], Project0Wnd, NULL, GTCB_Checked, checkper,TAG_END);
  121.  
  122.                 break;
  123.  
  124.             case CXCMD_ENABLE:
  125.                 checkper=TRUE;
  126.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_TIME], Project0Wnd, NULL, GA_Disabled, !checkper,TAG_END);
  127.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_CRONCHECK], Project0Wnd, NULL, GTCB_Checked, checkper,TAG_END);
  128.  
  129.                 break;
  130.  
  131.             case CXCMD_KILL:
  132.                 keepgoing=0;
  133.                 break;
  134.  
  135.             case CXCMD_APPEAR:
  136.                 if (winop==FALSE) openup();
  137.                 break;
  138.  
  139.             case CXCMD_DISAPPEAR:
  140.                 if (winop) closedown();
  141.                 break;
  142.  
  143.             case CXCMD_UNIQUE:
  144.                 if (winop==FALSE) openup();
  145.                 /*keepgoing=0;*/
  146.                 break;
  147.  
  148.             case EVT_HOTKEY:
  149.                 if (winop==FALSE) openup();
  150.                 break;
  151.         }
  152.     }
  153.     return(keepgoing);
  154. }
  155.  
  156.