home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 954 / SaveNewsforMacro5.sis / SaveNews.opl (.txt) < prev    next >
Encoding:
EPOC OPL Source  |  2000-10-05  |  10.2 KB  |  387 lines

  1.  
  2.  
  3. REM Macro SaveNews v1.00
  4.  
  5. REM To be used with Macro5 (from v2.37)
  6. REM and RMRNews News Reader for EPOC (v1.00F English)
  7. REM by S.Alisi - sergioalisi@geocities.com
  8. REM http://www.geocities.com/siliconvalley/bridge/1492
  9.  
  10. CONST AppName$="SaveNews"
  11. CONST AppVersion$=" v1.00"
  12. CONST DataUID&=&10000086
  13. CONST NewsUID&=&100004A1
  14. CONST IniFile$="C:\System\SaveNews.ini"
  15. CONST SourceBoxName$="SaveNews.box"
  16. CONST YesBtn$="Y"    rem "Yes button" shortcut in RMRNews
  17.  
  18. PROC Main:
  19.     GLOBAL News$(255),Data$(255)
  20.     GLOBAL NewsRSC$(255),DataRSC$(255)
  21.     GLOBAL MultiBox%,UserDialog%,MacroNew%
  22.     GLOBAL NumMsg&,NumMsg%,DelMsg%
  23.     GLOBAL Date$(30),From$(250),Subject$(250),Body$(250)
  24.  
  25.     Macro5Test:
  26.     Macro5Ver:
  27.     NumMsg&=1 :NumMsg%=1
  28.     if IniSetup%: :return :endif
  29.     if StartNews%: :return :endif
  30.     GetFocus:
  31.     if MultiBox%
  32.         if MultiBoxProc%:(1) :return :endif
  33.     endif
  34.     if UserDialog%
  35.         if UserDialogProc%: :return :endif
  36.     endif
  37.     StartData:
  38.     while NumMsg%<=NumMsg&
  39.         if CopyFromNews%: :return :endif
  40.         AdjustDate:
  41.         PasteToData:
  42.         Report:
  43.         NumMsg%=NumMsg%+1
  44.     endwh
  45. ENDP
  46.  
  47. PROC Macro5Test:
  48.     rem check if SaveNews is launched from Macro5 and as a macro
  49.     onerr No_Macro::
  50.     News$=GetApp$:(NewsUID&)    rem for S5 & Geofox
  51.     goto Yes_Macro::
  52.     No_Macro::
  53.     onerr off
  54.     alert(AppName$+" Macro"+AppVersion$,"To be launched as a macro with Macro5")
  55.     stop
  56.     Yes_Macro::
  57. ENDP
  58.  
  59. PROC Macro5Ver:
  60.     rem check which version of Macro5 is currently installed
  61.     onerr Old_Macro::
  62.     if LibVersion%: >=240
  63.         MacroNew%=-1
  64.     endif
  65.     goto Done::
  66.     Old_Macro::
  67.     onerr off
  68.     MacroNew%=0
  69.     stop
  70.     Done::
  71. ENDP
  72.  
  73. PROC IniSetup%:
  74.     if News$=""
  75.         alert(AppName$+" Macro"+AppVersion$,"Sorry, I can't find RMRNews.app")
  76.         return -1
  77.     endif
  78.     NewsRSC$=Left$(News$,Len(News$)-3)+"rsc"
  79.     if not exist (IniFile$)
  80.         Data$="*"+Right$(SourceBoxName$,4)
  81.         DataRSC$="Z:\System\Apps\Data\Data.rsc"    rem for Psion S5
  82.         if not exist (DataRSC$)
  83.             DataRSC$="Z:\System\Apps\Data\Data.ruk"    rem for Geofox
  84.             if not exist (DataRSC$)
  85.                 alert(AppName$+" Macro"+AppVersion$,"Sorry, I can't find Data.rsc/ruk")
  86.                 return -1
  87.             endif
  88.         endif
  89.         dinit AppName$+" Setup (step 1 of 3) ..."
  90.         dtext "","- your RMRNews.app is located on drive """+Left$(News$,1)+""""
  91.         if MacroNew%
  92.             dtext "","- your Macro5 version is "+gen$(LibVersion%:/100,2)+"."+right$(gen$(LibVersion%:,4),2)
  93.         else
  94.             dtext "","- SaveNews is not tested with Macro5 versions prior to 2.37"
  95.         endif
  96.         dbuttons "Cancel",27,"Continue",13
  97.         if dialog
  98.         else
  99.             alert(AppName$+" Setup aborted...","Relaunch the macro to complete")
  100.             return -1
  101.         endif
  102.         if MultiBoxProc%:(0)
  103.             alert(AppName$+" Setup aborted...","Relaunch the macro to complete")
  104.             return -1
  105.         endif
  106.         dinit AppName$+" Setup (step 3 of 3)"
  107.         dtext "","Each time you launch SaveNews you can ..."
  108.         dcheckbox MultiBox%,"- have a choice of the target Data file"
  109.         dtext "","- open a dialog window to automate the process"
  110.         dcheckbox UserDialog%,"of archiving/deleting a group of articles"
  111.         dbuttons "Cancel",27,"Continue",13
  112.         if dialog
  113.         else
  114.             alert(AppName$+" Setup aborted...","Relaunch the macro to complete")
  115.             return -1
  116.         endif
  117.         create IniFile$,a,Data$,DataRSC$,MultiBox%,UserDialog%
  118.         a.Data$=Data$
  119.         a.DataRSC$=DataRSC$
  120.         a.MultiBox%=MultiBox%
  121.         a.UserDialog%=UserDialog%
  122.         append
  123.         close
  124.         alert(AppName$+" Setup successfully completed...","Now you can relaunch the macro")
  125.         return -1
  126.     else
  127.         open IniFile$,a,Data$,DataRSC$,MultiBox%,UserDialog%
  128.         Data$=a.Data$
  129.         DataRSC$=a.DataRSC$
  130.         MultiBox%=a.MultiBox%
  131.         UserDialog%=a.UserDialog%
  132.         close
  133.     endif
  134. ENDP
  135.  
  136. PROC StartNews%:
  137.     if MacroNew%    rem Macro5 v2.40 or later installed
  138.         busy "Opening RMRNews, please wait ...",3,1
  139.         if (FgApp%:(News$))=1
  140.             busy off
  141.             GetFocus:
  142.             alert("SaveNews has opened your RMRNews program...","Now highlight an article header and relaunch")
  143.             return -1
  144.         endif
  145.         busy off
  146.     else    rem Macro5 v2.37 installed
  147.         if (FgApp%:(News$))=1
  148.             GetFocus:
  149.             giprint "Opening RMRNews, please wait..."
  150.             pause 90
  151.             alert("SaveNews is opening RMRNews program...","Highlight an article header and relaunch")
  152.             return -1
  153.         endif
  154.     endif
  155. ENDP
  156.  
  157. PROC StartData:
  158.     if MacroNew%=0    rem Macro5 v2.37 installed
  159.         if (FgApp%:(Data$))=1
  160.             GetFocus:
  161.             giprint "Opening NewsBox file, please wait..."
  162.             pause 150
  163.         endif
  164.         FgApp%:(News$)
  165.     endif
  166. ENDP
  167.  
  168. PROC MultiBoxProc%:(Type%)
  169.     LOCAL Button%,SetDefault%,SourceBox$(255)
  170.     Startup::
  171.     SourceBox$=Macros$+SourceBoxName$
  172.     if Type%=1    rem call from Main: procedure
  173.         dinit AppName$+AppVersion$
  174.         dtext "","Select the location of your target Data file:"
  175.     else    rem call from IniSetup%: procedure
  176.         dinit AppName$+" Setup (step 2 of 3) ..."
  177.         dtext "","Select the location of your default NewsBox Data file:"
  178.     endif
  179.     dfile Data$,"File,Folder,Disk",128+8+32,0,0,DataUID&
  180.     dtext "","... or choose New to create a new NewsBox Data file"
  181.     if Type%=1
  182.         dbuttons "New",%N,"Relaunch Setup",%S,"Cancel",27,"Continue",13
  183.     else
  184.         dbuttons "New",%N,"Cancel",27,"Continue",13
  185.     endif
  186.     Button%=dialog
  187.     if Button%=13
  188.         if Data$=""
  189.             Data$="*"+Right$(SourceBoxName$,4)
  190.             giprint "No taget file selected"
  191.             goto Startup::
  192.         endif
  193.     elseif Button%=%s
  194.         dinit AppName$+AppVersion$
  195.         dtext "","Relaunch the Setup procedure?"
  196.         dtext "","(you will loose the current settings)"
  197.         dbuttons "Cancel",27,"Continue",13
  198.         if dialog
  199.             delete IniFile$
  200.             if IniSetup%: :return -1 :endif
  201.         else
  202.             goto Startup::
  203.         endif
  204.     elseif Button%=%n
  205.         if exist (SourceBox$)
  206.             Data$=Right$(SourceBoxName$,4)
  207.             dinit AppName$+AppVersion$
  208.             dtext "","Create new NewsBox Data file:"
  209.             dfile Data$,"File,Folder,Disk",1+8
  210.             if Type%=1
  211.                 dcheckbox SetDefault%,"Set as default"
  212.             endif
  213.             dbuttons "Cancel",27,"Continue",13
  214.             if dialog
  215.                 copy SourceBox$,Data$
  216.                 if SetDefault% and Type%=1
  217.                     open IniFile$,a,Data$,DataRSC$,MultiBox%,UserDialog%
  218.                     a.Data$=Data$
  219.                     update
  220.                     close
  221.                 endif
  222.             else
  223.                 goto Startup::
  224.             endif
  225.         else
  226.             Data$="*"+Right$(SourceBoxName$,4)
  227.             giprint "NEW option not available"
  228.             goto Startup::
  229.         endif
  230.     else
  231.         return -1
  232.     endif
  233.     giprint "Target file is "+Data$
  234.     pause 20
  235. ENDP
  236.  
  237. PROC UserDialogProc%:
  238.     LOCAL Button%
  239.     dinit AppName$+AppVersion$
  240.     dlong NumMsg&,"Number of articles to archive",1,100
  241.     dtext "","(starting from the highlighted one and going down)",$200
  242.     dcheckbox DelMsg%,"Delete original article from RMRNews"
  243.     dtext "","(use with care, no undelete options available...)",$200
  244.     dbuttons "Cancel",27,"Continue",13
  245.     if dialog
  246.     else
  247.         return -1
  248.     endif
  249.     if DelMsg%
  250.         dinit "Please read carefully:"
  251.         dtext "","You have chosen the ""Auto-Delete"" option, so:"
  252.         dtext "","- DO NOT touch the keyboard and"
  253.         dtext "","- DO NOT switch to any other program"
  254.         dtext "","while the macro is running, as this could also lead to"
  255.         dtext "","the loss of all your articles...",$200
  256.         dtext "","A dialog box will inform you when the task has ended."
  257.         dbuttons "Disable",%D,"Abort",27,"Continue",13
  258.         Button%=dialog
  259.         if Button%=%d
  260.             DelMsg%=0
  261.             giprint """Auto-Delete"" option disabled"
  262.             pause 20
  263.         elseif Button%<>13
  264.             return -1
  265.         endif
  266.     endif
  267. ENDP
  268.  
  269. PROC CopyFromNews%:
  270.     LOCAL Dummy$(255)
  271.     FgApp%:(News$)
  272.     SendKey:("Enter")    rem open the article
  273.     pause 10
  274.     SendKey:("Ctrl+a")    rem select all (from BODY field)
  275.     Dummy$=Copy$:
  276.     if Len(Dummy$)=0    rem article not available off-line
  277.         beep:
  278.         GetFocus:
  279.         giprint "Stop"
  280.         pause 20
  281.         if NumMsg%>1    rem other articles already stored
  282.             FgApp%:(Data$)
  283.             pause 10
  284.             SendKey:("Esc")    rem exit from "new entry mode"
  285.             FgApp%:(News$)
  286.         endif
  287.         return -1
  288.     else
  289.         SendKey:("Fn+Up,Fn+Up")    rem move to NewsGroups field
  290.         SendKey:("Ctrl+a")    rem select all
  291.         Dummy$=Copy$:
  292.         From$=Left$(Dummy$,250)
  293.         SendKey:("Down")    rem move to SUBJECT field
  294.         SendKey:("Ctrl+a")    rem select all
  295.         Dummy$=Copy$:
  296.         Subject$=Left$(Dummy$,250)
  297.         SendKey:("Down")    rem move to BODY field
  298.         pause 20
  299.         Dummy$=Copy$:
  300.         Body$=Left$(Dummy$,250)
  301.         SendKey:("Ctrl+c")    rem this copies more than 255 chars
  302.         SendKey:("Esc")    rem close article
  303.         pause 20
  304.     endif
  305. ENDP
  306.  
  307. PROC AdjustDate:
  308.     rem the following code simply puts the time of archiving
  309.     rem to the date field of the target data file
  310.     Date$=gen$(year,4)+"/"+right$("0"+gen$(month,2),2)+"/"+right$("0"+gen$(day,2),2)
  311.     Date$=Date$+" "+right$("0"+gen$(hour,2),2)+":"+right$("0"+gen$(minute,2),2)+" (*)"
  312. ENDP
  313.  
  314. PROC PasteToData:
  315.     FgApp%:(Data$)
  316.     pause 20
  317.     if NumMsg%=1    rem first article (or single article) to store
  318.         SendRscMenu:(DataRSC$,4,&D)    rem new entry ("Ctrl+Shift+n" for UK/USA)
  319.     endif
  320.     pause 20
  321.     SendKey:("Tab,Tab,Tab,Tab,Tab")    rem move to BODY field
  322.     SendKey:("Ctrl+v")
  323.     pause 20
  324.     SendKey:("Shift+Tab")    rem move to CC/BCC field
  325.     SendKey:("Shift+Tab")    rem move to TO field
  326.     SendKey:("Shift+Tab")    rem move to FROM field
  327.     Paste:(From$)
  328.     pause 20
  329.     SendKey:("Shift+Tab")    rem move to DATE field
  330.     Paste:(Date$)
  331.     pause 20
  332.     SendKey:("Shift+Tab")    rem move to TITLE field
  333.     if Subject$<>""
  334.         Paste:(Subject$)
  335.     endif
  336.     pause 20
  337.     SendRscMenu:(DataRSC$,4,&16)    rem save article ("Ctrl+s" for UK/USA)
  338.     if NumMsg%=NumMsg&    rem last article (or single article) stored
  339.         SendKey:("Esc")    rem exit from "new entry mode"
  340.     endif
  341. ENDP
  342.  
  343. PROC Report:
  344.     GetFocus:
  345.     if Len(From$)=250 or Len(Subject$)=250
  346.         dinit AppName$+" warning"
  347.         dtext "","Check if the last saved article contains one of the"
  348.         dtext "","From or Subject fields exceeding the 250 chars limit"
  349.         if NumMsg&>1
  350.             NumMsg%=NumMsg&
  351.             dtext "","The archiving procedure has been stopped..."
  352.         endif
  353.         if DelMsg%
  354.             dtext "","The original article won't be deleted from┬áRMRNews"
  355.         endif
  356.         dbuttons "Continue",13
  357.         dialog
  358.         SendKey:("Esc")    rem exit from "new entry mode" (if necessary)
  359.     else
  360.         if NumMsg&>1    rem storing a group of articles
  361.             giprint "Article "+gen$(NumMsg%,3)+" of "+gen$(NumMsg&,3)+" stored"
  362.         else
  363.             giprint "New article stored"
  364.         endif
  365.         pause 20
  366.         FgApp%:(News$)
  367.         pause 20
  368.         if DelMsg%
  369.             Sendkey:("Del")    rem delete current article
  370.             Sendkey:(YesBtn$)    rem confirm deletion with "Yes" button
  371.             pause 20
  372.         else
  373.             SendKey:("Down")    rem move down to the next article
  374.         endif
  375.         if NumMsg%=NumMsg& and (NumMsg&>1 or DelMsg%)    rem last article of a group
  376.             GetFocus:
  377.             dinit AppName$+AppVersion$
  378.             dtext "",gen$(NumMsg&,3)+" article(s) successfully stored to:"
  379.             dtext "",Data$
  380.             dbuttons "Continue",13
  381.             dialog
  382.         endif
  383.     endif
  384. ENDP
  385.  
  386.  
  387.