source: trunk/guitools/smbprint/smbprint.VRX@ 1036

Last change on this file since 1036 was 1034, checked in by Herwig Bauernfeind, 8 years ago

Ticket #318 fix in smbprint (Spoolfile did not get deleted anymore because of delay before spoolfile is closed)

File size: 5.9 KB
Line 
1/*:VRX Main
2*/
3/* Poor man's Samba print utility
4Copyright (C) 2007-2017 Herwig Bauernfeind for bww bitwise works GmbH.
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/* Main
21*/
22Main:
23/* Process the arguments.
24 Get the parent window.
25*/
26 parse source . calledAs .
27 parent = ""
28 argCount = arg()
29 argOff = 0
30 if( calledAs \= "COMMAND" )then do
31 if argCount >= 1 then do
32 parent = arg(1)
33 argCount = argCount - 1
34 argOff = 1
35 end
36 end; else do
37 call VROptions 'ImplicitNames'
38 call VROptions 'NoEchoQuit'
39 end
40 InitArgs.0 = argCount
41 if( argCount > 0 )then do i = 1 to argCount
42 InitArgs.i = arg( i + argOff )
43 end
44 drop calledAs argCount argOff
45
46/* Load the windows
47*/
48 call VRInit
49 parse source . . spec
50 _VREPrimaryWindowPath = ,
51 VRParseFileName( spec, "dpn" ) || ".VRW"
52 _VREPrimaryWindow = ,
53 VRLoad( parent, _VREPrimaryWindowPath )
54 drop parent spec
55 if( _VREPrimaryWindow == "" )then do
56 call VRMessage "", "Cannot load window:" VRError(), ,
57 "Error!"
58 _VREReturnValue = 32000
59 signal _VRELeaveMain
60 end
61
62/* Process events
63*/
64 call Init
65 signal on halt
66 do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
67 _VREEvent = VREvent()
68 interpret _VREEvent
69 end
70_VREHalt:
71 _VREReturnValue = Fini()
72 call VRDestroy _VREPrimaryWindow
73_VRELeaveMain:
74 call VRFini
75exit _VREReturnValue
76
77VRLoadSecondary:
78 __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
79 if __vrlsWait then do
80 call VRFlush
81 end
82 __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
83 if __vrlsHWnd = '' then signal __vrlsDone
84 if __vrlsWait \= 1 then signal __vrlsDone
85 call VRSet __vrlsHWnd, 'WindowMode', 'Modal'
86 __vrlsTmp = __vrlsWindows.0
87 if( DataType(__vrlsTmp) \= 'NUM' ) then do
88 __vrlsTmp = 1
89 end
90 else do
91 __vrlsTmp = __vrlsTmp + 1
92 end
93 __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
94 __vrlsWindows.0 = __vrlsTmp
95 do while( VRIsValidObject( VRWindow() ) = 1 )
96 __vrlsEvent = VREvent()
97 interpret __vrlsEvent
98 end
99 __vrlsTmp = __vrlsWindows.0
100 __vrlsWindows.0 = __vrlsTmp - 1
101 call VRWindow __vrlsWindows.__vrlsTmp
102 __vrlsHWnd = ''
103__vrlsDone:
104return __vrlsHWnd
105
106/*:VRX _ShowMsg
107*/
108_ShowMsg:
109 Buttons.1 = "OK"
110 Buttons.0 = 1
111 id = VRMessage( VRWindow(), Msg.Text, Msg.Title, Msg.Type, "Buttons.", buttons.1, buttons.1 )
112return/*:VRX Fini
113*/
114Fini:
115 window = VRWindow()
116 call VRSet window, "Visible", 0
117 drop window
118return 0
119
120/*:VRX Halt
121*/
122Halt:
123 signal _VREHalt
124return
125
126/*:VRX Init
127*/
128Init:
129 window = VRWindow()
130/* call VRMethod window, "CenterWindow" */
131 call VRSet window, "Visible", 1
132 call VRMethod window, "Activate"
133 drop window
134return
135
136/*:VRX Main_Close
137*/
138Main_Close:
139 call Quit
140return
141
142/*:VRX Main_Create
143*/
144Main_Create:
145 debug = 0
146 if debug = 1 then ok = VRRedirectStdIO("ON")
147 else ok = VRRedirectStdIO("OFF")
148 PrintParms = VRGet("Application","Commandline")
149 spooldir = directory()
150 if debug = 1 then say 'Printparms: "'Printparms'"'
151 if debug = 1 then say 'Length : 'length(PrintParms)
152 if PrintParms <> "" then do
153 parse var PrintParms '"'spoolfile'" "'smbprintername'" "'Jobname'" "'pages'" "'JobSize'"'
154 if debug = 1 then say 'Directory: "'spooldir'"'
155 if debug = 1 then say 'Spoolfile: "'spoolfile'"'
156 if debug = 1 then say 'Smbprinter: "'smbprintername'"'
157
158 ok = VRMethod( "Application", "ListPrinters", "printer." )
159 FoundQueue = 0
160 if ok = 1 then do
161 do i = 1 to printer.0
162 if debug = 1 then say printer.i
163 parse value printer.i with PName';'PQueue';'Rest
164 if debug = 1 then say 'Queue: 'PName'<-->'PQueue
165 if translate(PQueue) = translate(smbprintername) then do
166 FoundQueue = 1
167 leave
168 end
169 end
170 end
171
172 if FoundQueue then do
173 ok = VRset("DT_Job","Caption", 'Print "'Jobname'" ('Pages', 'JobSize' bytes) to "'PName'"')
174 ok = VRPrintFile( smbprintername, spooldir'\'spoolfile, , JobName )
175 if debug = 1 then say " ->"smbprintername", "spooldir"\"spoolfile", , "JobName
176 ok = SysSleep(10)
177 if debug = 1 then ok = VRRedirectStdIO("OFF")
178 end
179 else do
180 Msg.Title = "Samba Print Command for OS/2"
181 Msg.Type = "E"
182 Msg.Text = 'Invalid (non existent) print queue specified in smb.conf: "'smbprintername'"'
183 call _ShowMsg
184 end
185 ok = -255
186 do while ok <> 0
187 ok = SysSleep(2)
188 ok = SysFileDelete(Spoolfile)
189 end
190 end
191 else do
192 Msg.Title = "Samba Print Command for OS/2"
193 Msg.Type = "I"
194 Msg.Text = 'smbprint.exe "spoolfile" "printerqueue" "jobname" "pages" "jobsize"'
195 call _ShowMsg
196 end
197 call Quit
198return
199
200/*:VRX Quit
201*/
202Quit:
203 window = VRWindow()
204 call VRSet window, "Shutdown", 1
205 drop window
206return
207
Note: See TracBrowser for help on using the repository browser.