source: trunk/gui/printer/cupswiz/cupswiz.VRX@ 11

Last change on this file since 11 was 11, checked in by Alex Taylor, 14 years ago

Add support for drivers other than ECUPS.DRV.

File size: 44.6 KB
Line 
1/*:VRX Main
2*/
3/* Main
4*/
5Main:
6/* Process the arguments.
7 Get the parent window.
8*/
9 parse source . calledAs .
10 parent = ""
11 argCount = arg()
12 argOff = 0
13 if( calledAs \= "COMMAND" )then do
14 if argCount >= 1 then do
15 parent = arg(1)
16 argCount = argCount - 1
17 argOff = 1
18 end
19 end; else do
20 call VROptions 'ImplicitNames'
21 call VROptions 'NoEchoQuit'
22 end
23 InitArgs.0 = argCount
24 if( argCount > 0 )then do i = 1 to argCount
25 InitArgs.i = arg( i + argOff )
26 end
27 drop calledAs argCount argOff
28
29/* Load the windows
30*/
31 call VRInit
32 parse source . . spec
33 _VREPrimaryWindowPath = ,
34 VRParseFileName( spec, "dpn" ) || ".VRW"
35 _VREPrimaryWindow = ,
36 VRLoad( parent, _VREPrimaryWindowPath )
37 drop parent spec
38 if( _VREPrimaryWindow == "" )then do
39 call VRMessage "", "Cannot load window:" VRError(), ,
40 "Error!"
41 _VREReturnValue = 32000
42 signal _VRELeaveMain
43 end
44
45/* Process events
46*/
47 call Init
48 signal on halt
49 do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
50 _VREEvent = VREvent()
51 interpret _VREEvent
52 end
53_VREHalt:
54 _VREReturnValue = Fini()
55 call VRDestroy _VREPrimaryWindow
56_VRELeaveMain:
57 call VRFini
58exit _VREReturnValue
59
60VRLoadSecondary:
61 __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
62 if __vrlsWait then do
63 call VRFlush
64 end
65 __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
66 if __vrlsHWnd = '' then signal __vrlsDone
67 if __vrlsWait \= 1 then signal __vrlsDone
68 call VRSet __vrlsHWnd, 'WindowMode', 'Modal'
69 __vrlsTmp = __vrlsWindows.0
70 if( DataType(__vrlsTmp) \= 'NUM' ) then do
71 __vrlsTmp = 1
72 end
73 else do
74 __vrlsTmp = __vrlsTmp + 1
75 end
76 __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
77 __vrlsWindows.0 = __vrlsTmp
78 do while( VRIsValidObject( VRWindow() ) = 1 )
79 __vrlsEvent = VREvent()
80 interpret __vrlsEvent
81 end
82 __vrlsTmp = __vrlsWindows.0
83 __vrlsWindows.0 = __vrlsTmp - 1
84 call VRWindow __vrlsWindows.__vrlsTmp
85 __vrlsHWnd = ''
86__vrlsDone:
87return __vrlsHWnd
88
89/*:VRX __NoValue
90*/
91__NoValue:
92 SAY FORMAT( sigl, 6 ) '+++' SOURCELINE( sigl )
93 SAY FORMAT( sigl, 6 ) '+++ Uninitialized variable'
94EXIT sigl
95
96/*:VRX __VXREXX____APPENDS__
97*/
98__VXREXX____APPENDS__:
99/*
100#append ..\..\Shared\PrintUtl.VRS
101*/
102return
103/*:VRX ConfirmAndCreate
104*/
105ConfirmAndCreate: PROCEDURE EXPOSE globals.
106
107 globals.!create = 0
108 CALL VRLoadSecondary 'SW_CREATE', 'W'
109 IF globals.!create <> 1 THEN RETURN
110
111 CALL SetPage4
112 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
113 CALL VRSet 'DT_INFO', 'Caption', 'Creating printer...'
114 ok = CreatePrinter( globals.!os2printer )
115 CALL VRSet 'DT_INFO', 'Caption', ''
116 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
117
118 IF ok <> 0 THEN DO
119 SELECT
120 WHEN ok == 1 THEN reason = 'Error importing PPD file.'
121 WHEN ok == 2 THEN reason = 'Error creating CUPS printer. See' globals.!log1 'for more information.'
122 WHEN ok == 3 THEN reason = 'Error creating printer object. See' globals.!log1 'for more information.'
123 OTHERWISE reason = 'Unknown error.'
124 END
125 CALL VRMessage VRWindow(), 'The following error occurred when trying to create the printer:' ||,
126 '0d0a0d0a'x || reason, 'Error Creating Printer', 'E'
127 CALL VRSet 'DT_INFO', 'Caption', 'The printer could not be created.'
128 CALL VRSet 'PB_NEXT', 'Caption', 'Return'
129 END
130 ELSE DO
131 CALL VRSet 'DT_INFO', 'Caption', 'The printer has been created.'
132 CALL VRSet 'PB_NEXT', 'Caption', 'Create another'
133 END
134 CALL VRSet 'PB_CANCEL', 'Caption', 'Close'
135
136 CALL LINEOUT globals.!log1, ''
137 CALL LINEOUT globals.!log1
138
139RETURN
140
141/*:VRX CreateCupsPrinter
142*/
143CreateCupsPrinter: PROCEDURE EXPOSE globals.
144
145 od = DIRECTORY()
146 CALL DIRECTORY globals.!cupsdir'\sbin'
147 cups_cmd = 'lpadmin -p' globals.!prt_name '-E'
148 IF globals.!prt_info <> '' THEN
149 cups_cmd = cups_cmd '-D "'globals.!prt_info'"'
150 IF globals.!prt_loc <> '' THEN
151 cups_cmd = cups_cmd '-L "'globals.!prt_loc'"'
152 IF globals.!prt_dev <> '' THEN
153 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m' globals.!prt_dev
154 ELSE
155 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m "'globals.!prt_ppd'"'
156
157
158 CALL LINEOUT globals.!log1, 'Creating CUPS printer using:'
159 CALL LINEOUT globals.!log1, ' ' cups_cmd
160 IF VRFileExists( globals.!log2 ) THEN DO
161 CALL LINEOUT globals.!log2, ''
162 CALL LINEOUT globals.!log2
163 END
164 ADDRESS CMD '@' cups_cmd '1>NUL 2>>' globals.!log2
165 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
166 IF rc <> 0 THEN
167 CALL LINEOUT globals.!log1, 'See' globals.!log2 'for details.'
168 CALL DIRECTORY od
169 CALL LINEOUT globals.!log1, ''
170
171RETURN rc
172
173/*:VRX CreateOS2Printer
174*/
175/* Creates an OS/2 printer port, queue, and desktop object which point to
176 * the just-created CUPS printer. Uses the RINSTPRN utility from IBM.
177 */
178CreateOS2Printer: PROCEDURE EXPOSE globals.
179 ARG prnt_drv
180
181 IF globals.!remotecups == '' THEN DO
182 host = LoopbackName()
183 printer = globals.!prt_name
184 END
185 ELSE
186 PARSE VAR globals.!remotecups host printer .
187
188 printer_title = globals.!prt_info
189 printer_model = globals.!prt_nick
190 queue_name = GetQueueName( printer_title )
191 port_name = GetNextPortName('CUPS')
192 use_drv = globals.!prdrv
193
194 /* Determine the source directories/files to pass to RINSTPRN.EXE. (Some
195 * of this logic is repeated from ImportPPD, but we have to do it again
196 * here because (a) we might not have gone through ImportPPD to get to this
197 * point, and (b) even if we did, the repository information might have
198 * changed.)
199 */
200 copied_driver = 0
201 driver_path = GetDriverSource( prnt_drv )
202
203 IF ( pmdx <> '') & ( globals.!prdrv <> '') & ( globals.!prdesc <> '') THEN DO
204 /* Printer driver is in the local repository, so we can just point
205 * to that, and use the system PRDESC.LST file.
206 */
207 use_desc = globals.!prdesc
208 use_src = globals.!repository
209 END
210 ELSE IF driver_path <> '' THEN DO
211 /* Driver is not in the repository, but was found in another designated
212 * location. Point to that location, and create a temporary PRDESC.LST
213 * file for it.
214 */
215 use_src = VRParseFilePath( driver_path, 'DP')
216 use_desc = use_src'\PRDESC.LST'
217 CALL CreateDriverList driver_path'\'prnt_drv'.DRV', use_desc
218 END
219 ELSE DO
220 /* Driver is not in the repository. Try to grab the installed files
221 * from under \OS2\DLL, copy them into a temporary working directory,
222 * and create a temporary PRDESC.LST file.
223 */
224 driver_path = globals.!os2dir'\DLL\'prnt_drv'\'prnt_drv'.DRV'
225
226 use_src = SysTempFileName( globals.!tmpdir'\PDR_????')
227 use_desc = use_src'\PRDESC.LST'
228
229 IF VRMkDir( use_src ) == 0 THEN DO
230 CALL LINEOUT globals.!log1, 'Failed to create working directory' use_src':' VRError()
231 RETURN 1
232 END
233 IF CopyDriverToSource( driver_path, use_src ) == 0 THEN DO
234 CALL LINEOUT globals.!log1, 'Failed to copy driver' driver_path 'to working directory' use_src'.'
235 RETURN 1
236 END
237 CALL CreateDriverList driver_path, use_desc
238 copied_driver = 1
239 END
240
241 /* Create a new CUPS port. */
242 /* TODO currently this assumes that CUPS.PDR is already installed. */
243 port_ok = AddPort_CUPS( port_name, host, printer )
244 IF port_ok > 1 THEN
245 RETURN 1
246
247 rsp_file = globals.!tmpdir'\printer.rsp'
248 CALL RSPCreatePrinter rsp_file, prnt_drv, printer_model,,
249 port_name, queue_name, printer_title
250 result = ExecRINSTPRN( use_desc, use_drv, use_src, rsp_file )
251
252 IF result <> 0 THEN
253 CALL DeletePort port_name
254 ELSE IF port_ok == 1 THEN DO
255 CALL VRMessage VRWindow(),
256 'The installed version of CUPS.PDR appears to be out of ',
257 'date. As a result, the desktop printer will not be ',
258 'useable until the desktop is restarted.',,
259 'Port Driver Problem', 'W'
260 END
261
262 IF copied_driver == 1 THEN DO
263 CALL VRDeleteFile use_src'\*'
264 CALL VRRmDir use_src
265 END
266
267RETURN result
268
269/*:VRX CreatePrinter
270*/
271CreatePrinter: PROCEDURE EXPOSE globals.
272 ARG create_os2
273
274 /* Create the CUPS printer */
275 IF globals.!remotecups == '' THEN DO
276 ok = CreateCupsPrinter()
277 IF ok <> 0 THEN
278 RETURN 2 /** RC=2 Error running lpadmin **/
279 END
280
281 /* Now create the OS/2 printer object */
282 IF create_os2 == 1 THEN DO
283
284 /* Make sure the presentation driver supports the printer */
285 IF globals.!mode == 2 THEN DO
286 /* Always (re)import when a PPD is provided by the user
287 */
288 ok = ImportPPD( globals.!os2driver, globals.!prt_ppd )
289 IF ok <> 0 THEN DO
290 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
291 RETURN 1 /** RC=1 PPD import failed **/
292 END
293 END
294 ELSE IF PrinterExistsInDRV( globals.!os2driver, globals.!prt_nick ) == 0 THEN DO
295 IF globals.!prt_ppd == '' THEN
296 CALL PromptForPMName
297 ELSE DO
298 ok = ImportPPD(globals.!os2driver, globals.!prt_ppd )
299 IF ok <> 0 THEN DO
300 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
301 RETURN 1 /** RC=1 PPD import failed **/
302 END
303 END
304 END
305
306 ok = CreateOS2Printer( globals.!os2driver )
307 IF ok <> 0 THEN
308 RETURN 3 /** RC=3 Error running rinstprn **/
309 END
310
311RETURN 0
312
313/*:VRX DDCB_PROTOCOL_Change
314*/
315DDCB_PROTOCOL_Change: PROCEDURE
316
317 which = VRGet('DDCB_PROTOCOL', 'Selected')
318 SELECT
319 WHEN which == 1 THEN DO /* IPP */
320 show_queue = 1
321 show_user = 1
322 show_pass = 1
323 END
324 WHEN which == 2 THEN DO /* SOCKET */
325 show_queue = 0
326 show_user = 0
327 show_pass = 0
328 END
329 WHEN which == 3 THEN DO /* LPD */
330 show_queue = 1
331 show_user = 1
332 show_pass = 0
333 /* CALL VRSet 'DT_USERID', 'Caption', 'User ID (if required):' */
334 END
335 WHEN which == 4 THEN DO /* SMB */
336 show_queue = 1
337 show_user = 1
338 show_pass = 1
339 /* CALL VRSet 'DT_QUEUE', 'Caption', 'Shared printer name:' */
340 END
341 OTHERWISE DO /* CUPS */
342 show_queue = 1
343 show_user = 0
344 show_pass = 0
345 END
346 END
347
348 CALL VRSet 'DT_QUEUE', 'Visible', show_queue
349 CALL VRSet 'EF_QUEUE', 'Visible', show_queue
350 CALL VRSet 'DT_USERID', 'Visible', show_user
351 CALL VRSet 'EF_USERID', 'Visible', show_user
352 CALL VRSet 'DT_PASSWORD', 'Visible', show_pass
353 CALL VRSet 'EF_PASSWORD', 'Visible', show_pass
354
355RETURN
356
357/*:VRX ExecRINSTPRN
358*/
359ExecRINSTPRN: PROCEDURE EXPOSE globals.
360 PARSE ARG dsc, drv, src, rsp
361
362 od = DIRECTORY()
363 CALL DIRECTORY src
364 rinstprn_cmd = 'rinstprn /DSC:'dsc '/DRV:'drv' /S:'src ,
365 '/T:'globals.!bootdrv '/L1:'globals.!logdir'\rinstprn.log' ,
366 '/R:'rsp
367
368 CALL LINEOUT globals.!log1, 'Creating OS/2 printer using:'
369 CALL LINEOUT globals.!log1, ' ' rinstprn_cmd
370 ADDRESS CMD '@' rinstprn_cmd '1>NUL 2>NUL'
371 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
372 IF rc <> 0 THEN
373 CALL LINEOUT globals.!log1, 'See' globals.!logdir'\rinstprn.log for details.'
374 CALL DIRECTORY od
375 CALL LINEOUT globals.!log1, ''
376
377RETURN rc
378
379/*:VRX Fini
380*/
381Fini:
382 window = VRWindow()
383 call VRSet window, "Visible", 0
384 drop window
385return 0
386
387/*:VRX GetCupsPorts
388*/
389GetCupsPorts: PROCEDURE EXPOSE globals.
390
391 CALL VRSet 'DT_INFO', 'Caption', 'Looking for connected printers. Please wait...'
392 CALL VRMethod 'LB_SELECT', 'Clear'
393
394 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe -v |rxqueue'
395
396 _od = DIRECTORY()
397 CALL DIRECTORY globals.!cupsdir
398 listqueue = RXQUEUE('CREATE')
399 defqueue = RXQUEUE('SET', listqueue )
400
401 ADDRESS CMD '@' lpinfo_cmd listqueue
402 i = 0
403 DO QUEUED()
404 PARSE PULL line
405 PARSE VAR line _type _name
406 IF _name == '' THEN ITERATE
407 IF _type == 'network' & POS('://', _name ) > 0 THEN DO
408 PARSE VAR _name _protocol '://' _host '/' _queue
409 IF _protocol == 'socket' THEN _protocol = 'AppSocket'
410 ELSE _protocol = TRANSLATE( _protocol )
411 i = i + 1
412 IF _queue == '' THEN _desc = '('_protocol')'
413 ELSE _desc = _queue '('_protocol')'
414 devices.i = 'Detected network printer' _desc 'at' _host
415 END
416 ELSE IF _type <> 'direct' THEN ITERATE
417 ELSE DO
418 i = i + 1
419 devices.i = 'Local printer:' _name
420 END
421 ports.i = _name
422 END
423 devices.0 = i
424
425 CALL RXQUEUE 'SET', defqueue
426 CALL RXQUEUE 'DELETE', listqueue
427 CALL DIRECTORY _od
428
429 CALL VRSet 'LB_SELECT', 'Painting', 0
430 CALL VRMethod 'LB_SELECT', 'AddStringList', 'devices.',, 'ports.'
431 CALL VRMethod 'LB_SELECT', 'AddString', 'Network printer (manual configuration)',, ''
432 CALL VRSet 'LB_SELECT', 'Selected', 1
433 CALL VRSet 'LB_SELECT', 'Painting', 1
434
435 CALL VRSet 'DT_INFO', 'Caption', 'Select the connection for this printer.'
436
437RETURN
438
439/*:VRX GetCupsPrinters
440*/
441GetCupsPrinters: PROCEDURE EXPOSE globals.
442
443 CALL VRSet 'DT_INFO', 'Caption', 'Getting list of supported printers. Please wait...'
444
445 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe --exclude-schemes drv -m |rxqueue'
446
447 _od = DIRECTORY()
448 CALL DIRECTORY globals.!cupsdir
449 listqueue = RXQUEUE('CREATE')
450 defqueue = RXQUEUE('SET', listqueue )
451
452 ADDRESS CMD '@' lpinfo_cmd listqueue
453 i = 0
454 DO QUEUED()
455 PARSE PULL line
456 IF LEFT( line, 6 ) == 'drv://' THEN ITERATE
457 PARSE VAR line _ppd '.ppd.gz ' _name
458 _ppd = _ppd'.ppd.gz'
459 IF _name == '' THEN DO
460 PARSE VAR line _ppd '.ppd ' _name
461 _ppd = _ppd'.ppd'
462 END
463 IF _name == '' THEN DO
464 PARSE VAR line _ppd _name
465 END
466 IF _name <> '' THEN DO
467 i = i + 1
468 ppds.i = _ppd
469 models.i = _name
470 END
471 END
472 ppds.0 = i
473 models.0 = i
474
475 CALL RXQUEUE 'SET', defqueue
476 CALL RXQUEUE 'DELETE', listqueue
477 CALL DIRECTORY _od
478
479 CALL VRSet 'LB_SELECT', 'Painting', 0
480 CALL VRMethod 'LB_SELECT', 'AddString', '-- Other printer (requires PPD) --',, ''
481 CALL VRMethod 'LB_SELECT', 'AddStringList', 'models.',, 'ppds.'
482 CALL VRSet 'LB_SELECT', 'Selected', 1
483 CALL VRSet 'LB_SELECT', 'Painting', 1
484
485 CALL VRSet 'DT_INFO', 'Caption', 'Select your printer model.'
486
487RETURN
488
489/*:VRX Halt
490*/
491Halt:
492 signal _VREHalt
493return
494
495/*:VRX ImportPPD
496*/
497ImportPPD: PROCEDURE EXPOSE globals.
498 /* Import a new PPD file into a PostScript PrinterPak driver.
499 */
500 ARG driver, ppdfile
501 IF driver == '' THEN driver = 'PSCRIPT'
502
503 CALL LINEOUT globals.!log1, 'Going to import PPD file into driver' driver'.'
504
505 /***
506 *** First, get our working directories and locate the driver source files.
507 ***/
508
509 mustcopy = 0
510 driver_path = GetDriverSource( driver )
511 IF driver_path == '' THEN DO
512 /* No source found. We'll have to try copying the actual installed
513 * driver files from under \OS2\DLL.
514 */
515 CALL LINEOUT globals.!log1, 'Driver source not found.'
516 driver_path = STREAM( globals.!os2dir'\DLL\'driver'\'driver'.DRV', 'C', 'QUERY EXISTS')
517 mustcopy = 1
518 END
519 IF driver_path <> '' THEN DO
520 srcdir = VRParseFilePath( driver_path, 'DP')
521 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
522 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
523 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
524 DROP srcdir
525 END
526
527 /* Driver (or one of its required files) was not found.
528 */
529 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
530 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
531 DO
532 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
533 /* TODO should prompt for installable driver package? */
534 RETURN 1 /** RC=1 Missing required driver files **/
535 END
536
537 IF mustcopy <> 0 THEN DO
538 /* Looks like the driver wasn't shipped with the OS; we have a source
539 * (either the active files from \OS2\DLL, or a package provided by
540 * the user), but we need somewhere for them to live. The user needs
541 * to tell us where, because they're going to have to specify the
542 * directory later on if they install the driver from PM.
543 */
544 pbtn.1 = 'OK'
545 pbtn.2 = 'Cancel'
546 pbtn.0 = 2
547 ptext = 'The install files for the' driver 'driver could not be ' ||,
548 'located. These files will be recreated from the driver ' ||,
549 'files which are already installed on your system.' ||,
550 '0d0a0d0a'x || 'Please enter the directory where the ' ||,
551 'install files will be placed.'
552 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
553 IF drvr_dir == '' THEN
554 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
555 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
556 'Enter Directory', 'pbtn.', 1, 2 )
557 IF ok <> 1 THEN RETURN 9 /** RC=9 User cancelled **/
558 drvr_dir = VRExpandFileName( drvr_dir )
559 DO WHILE drvr_dir == ''
560 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
561 'Enter Directory', 'pbtn.', 1, 2 )
562 drvr_dir = VRExpandFileName( drvr_dir )
563 END
564
565 /* Now create the new directory, if necessary */
566 IF VRMkDir( drvr_dir ) == 0 THEN
567 RETURN 3 /** RC=3 Failed to copy driver files **/
568 IF CopyDriverToSource( driver_path, drvr_dir ) == 0 THEN
569 RETURN 3 /** RC=3 Failed to copy driver files **/
570
571 /* Make sure we save the location (we'll need this information later) */
572 CALL VRSetIni 'PM_INSTALL', driver'_DIR', drvr_dir||'00'x, 'USER'
573
574 /* Now point to the new copy as the driver we will work on */
575 driver_path = drvr_dir'\'driver'.DRV'
576 END
577
578 workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
579 ok = VrMkDir( workdir )
580 IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
581 IF ok <> 1 THEN
582 RETURN 2 /** RC=2 Failed to create temporary directory **/
583
584 SELECT
585 WHEN driver == 'ECUPS' THEN ppddir = globals.!repository'\PPD_E'
586 WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
587 WHEN driver == 'PSPRINT' THEN ppddir = globals.!repository'\PPD_PS'
588 WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
589 WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
590 OTHERWISE ppddir = globals.!repository'\PPD'
591 END
592
593 /* Make sure ppddir (for keeping PPD files) exists */
594 CALL SysFileTree ppddir, 'dirs.', 'DO'
595 IF dirs.0 == 0 THEN DO
596 ok = VrMkDir( ppddir )
597 IF ok <> 1 THEN
598 RETURN 4 /** RC=4 Failed to create PPD directory **/
599 END
600
601 /***
602 *** Now do the actual work.
603 ***/
604
605 /* Back up the modified files (AUXPRINT.PAK and <driver>.DRV) if we're
606 * working out of the repository.
607 IF mustcopy == 0 THEN DO
608 repfiles.0 = 2
609 repfiles.1 = driver'.DRV'
610 repfiles.2 = 'AUXPRINT.PAK'
611 CALL BackupDrivers driver_path
612 END
613 */
614
615 /* Copy the needed driver files to our working directories.
616 */
617 drv_out = workdir'\OUT\'driver'.DRV'
618 pin_exe = workdir'\PIN.EXE'
619 ppd_exe = workdir'\PPDENC.EXE'
620 ok = VRCopyFile( driver_path, drv_out )
621 IF ok == 1 THEN ok = VRCopyFile( pin, pin_exe )
622 IF ok == 1 THEN ok = VRCopyFile( ppdenc, ppd_exe )
623 IF ok == 0 THEN DO
624 RETURN 3 /*** RC=3 Failed to copy driver files ***/
625 END
626
627 /* Set up the output redirection.
628 */
629 nq = RXQUEUE('CREATE')
630 oq = RXQUEUE('SET', nq )
631
632 /* If the PPD file is compressed, uncompress it.
633 */
634 IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
635 decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
636 CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
637 ADDRESS CMD '@gzip -c -d' ppdfile '| RXQUEUE' nq
638 DO QUEUED()
639 PARSE PULL line
640 CALL LINEOUT decppd, line
641 END
642 CALL LINEOUT decppd
643 ppdfile = decppd
644 END
645
646 IF VRFileExists( ppdfile ) == 0 THEN DO
647 CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
648 RETURN 5 /** RC=5 PPD import failed **/
649 END
650
651 ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
652
653 /* Now we have to clean up and validate the PPD file so PIN can use it.
654 * First, PPDENC converts the codepage if necessary, and copies the results
655 * to our working directory.
656 */
657 ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>&1 | RXQUEUE' nq
658 DO QUEUED()
659 PULL output
660 CALL LINEOUT globals.!log2, output
661 END
662 CALL LINEOUT globals.!log2, ''
663 CALL LINEOUT globals.!log2
664
665 /* Next we strip out some problematic lines used which are often encountered
666 * in (e.g.) CUPS-based PPD files.
667 */
668 CALL CleanPPD ppd_use, globals.!log1
669
670 /* Preparation complete. Now do the import.
671 */
672 count = 0
673 ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>&1 | RXQUEUE' nq
674 DO QUEUED()
675 PARSE PULL output
676 CALL LINEOUT globals.!log2, output
677 PARSE VAR output . 'OK (' nickname
678 IF nickname <> '' THEN DO
679 count = count + 1
680 newprinters.count = STRIP( nickname, 'T', ')')
681 END
682 END
683 newprinters.0 = count
684 CALL LINEOUT globals.!log2, ''
685 CALL LINEOUT globals.!log2
686
687 /* End the output redirection.
688 */
689 CALL RXQUEUE 'SET', oq
690 CALL RXQUEUE 'DELETE', nq
691
692
693 /***
694 *** Post-import processing.
695 ***/
696
697 IF newprinters.0 == 0 THEN DO
698 RETURN 5 /** RC=5 PPD import failed **/
699 END
700
701 IF mustcopy == 0 THEN DO
702 /* If we're working out of the repository, we need to update the
703 * driver table in PRDESC.LST to add the new driver(s).
704 */
705 CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with' newprinters.0 'new entries ...'
706 count = 0
707 match_drv = '('driver'.DRV)'
708 match_len = LENGTH( match_drv )
709
710 /* First, copy all lines that don't refer to the driver just updated */
711 DO WHILE LINES( globals.!prdesc )
712 _line = LINEIN( globals.!prdesc )
713 IF TRANSLATE( RIGHT( _line, LENGTH( match_len ))) == match_drv THEN ITERATE
714 count = count + 1
715 defs.count = _line
716 END
717 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
718
719 /* Next, create a new list for the updated driver and merge that in */
720 newlist = workdir'\'driver'.LST'
721 CALL CreateDriverList driver, newlist
722 DO WHILE LINES( newlist )
723 _line = LINEIN( newlist )
724 count = count + 1
725 defs.count = _line
726 END
727 defs.0 = count
728
729 /* Now sort the list and recreate PRDESC.LST */
730 CALL SysStemSort 'defs.',, 'I'
731 prdesc_tmp = workdir'\PRDESC.LST'
732 IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
733 CALL VRDeleteFile prdesc_tmp
734 DO i = 1 TO defs.0
735 CALL LINEOUT prdesc_tmp, defs.i
736 END
737 CALL LINEOUT prdesc_tmp
738 ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
739 IF ok == 0 THEN DO
740 RETURN 6 /** RC=6 Error updating PRDESC.LST **/
741 END
742 CALL VRDeleteFile prdesc_tmp
743
744 END
745
746 /* Finally, copy the updated driver files.
747 */
748 target = VRParseFilePath( driver_path, 'DP')
749 ok = VRCopyFile( workdir'\OUT\*', target )
750 IF ok == 1 THEN DO
751 /* Copy the updated files to \OS2\DLL\<driver>, replacing any
752 * existing copies. (This prevents problems if the OS/2 driver
753 * installation doesn't/fails to copy them, which can happen under
754 * some circumstances.)
755 */
756 IF VRFileExists( globals.!os2dir'\DLL\'driver ) THEN DO
757 CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
758 globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
759 CALL VRCopyFile workdir'\OUT\'driver'.DRV',,
760 globals.!os2dir'\DLL\'driver'\'driver'.DRV'
761 END
762 END
763 IF ok == 0 THEN
764 RETURN 3 /*** RC=3 Failed to copy driver files ***/
765
766 CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
767 DO i = 1 TO newprinters.0
768 CALL LINEOUT globals.!log1, ' ->' newprinters.i
769 END
770 CALL LINEOUT globals.!log1, ''
771 CALL LINEOUT globals.!log1
772
773 /* Clean up our work directories.
774 */
775 CALL VRDeleteFile workdir'\OUT\*'
776 CALL VRDeleteFile workdir'\*'
777 CALL VRRmDir( workdir'\OUT')
778 CALL VRRmDir( workdir )
779
780RETURN 0
781
782/*:VRX Init
783*/
784Init:
785 SIGNAL ON NOVALUE NAME __NoValue
786
787 CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
788 CALL SysLoadFuncs
789
790 CALL LoadSettings
791
792 IF InitArgs.0 > 0 THEN globals.!cupsdir = InitArgs.1
793
794 IF \VRIsDir( globals.!cupsdir ) THEN DO
795 CALL VRMessage VRWindow(), 'Please specify the path where CUPS is installed as follows:' ||,
796 '0d0a0d0a'x || 'CUPSWIZ <cups-path>',,
797 'Unknown or Invalid CUPS Path', 'E'
798 EXIT
799 END
800
801 /* Delete the error log file each time the program starts.
802 */
803 IF VRFileExists( globals.!log2 ) THEN
804 CALL VRDeleteFile globals.!log2
805
806 window = VRWindow()
807 call VRMethod window, "CenterWindow"
808 call VRSet window, "Visible", 1
809 call VRMethod window, "Activate"
810 drop window
811
812 CALL SetPage1
813
814RETURN
815
816/*:VRX InitMessageLog
817*/
818/* Initialize the message logfile. Unlike the error log, which is cleared and
819 * recreated every time the program starts, the message log is appended to
820 * until it reaches 100kB in size. If the message log is larger than 100kB when
821 * this function is called, it is renamed (with '~' appended to the name) and
822 * a new message log is started.
823 */
824InitMessageLog: PROCEDURE EXPOSE globals.
825
826 logsize = STREAM( globals.!log1, 'C', 'QUERY SIZE')
827 IF ( logsize <> '') & ( logsize > 102400 ) THEN DO
828 CALL VRCopyFile globals.!log1, globals.!log1 || '~'
829 CALL VRDeleteFile globals.!log1
830 END
831
832 datestr = DATE('L') TIME('N')
833 CALL LINEOUT globals.!log1, '--[' datestr ']' ||,
834 COPIES('-', 73 - LENGTH( datestr ))
835RETURN
836
837/*:VRX LoadSettings
838*/
839LoadSettings: PROCEDURE EXPOSE globals.
840
841 me = VRGet('Application', 'Program')
842 IF me == '' THEN PARSE SOURCE . . me
843 globals.!mydir = VRParseFilePath( me, 'DP')
844
845 /* Get CUPS paths.
846 */
847 globals.!cupsdir = ''
848 cupsdrv = VRParseFilePath( me, 'D')
849 cupsdir = cupsdrv':\cups'
850
851 globals.!cupsdir = cupsdir
852
853 /* Get system paths.
854 */
855 globals.!bootdrv = SysBootDrive()
856 IF globals.!bootdrv == '' THEN
857 globals.!bootdrv = FILESPEC('DRIVE', VALUE('OS2_SHELL',,'OS2ENVIRONMENT'))
858 globals.!os2dir = globals.!bootdrv'\OS2'
859 globals.!tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
860 IF globals.!tmpdir == '' THEN
861 globals.!tmpdir = VALUE('TEMP',,'OS2ENVIRONMENT')
862 IF globals.!tmpdir == '' THEN
863 globals.!tmpdir = globals.!mydir
864 globals.!logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
865 IF globals.!logdir == '' THEN
866 globals.!logdir = globals.!mydir
867
868 globals.!log1 = globals.!logdir'\cupswiz.l1'
869 globals.!log2 = globals.!logdir'\cupswiz.l2'
870
871 /* Get printer-related paths.
872 */
873 PARSE VALUE VRGetIni('PM_INSTALL', 'PDR_DIR', 'USER') WITH repos_dir '00'x .
874 globals.!repository = repos_dir
875 globals.!prdrv = STREAM( globals.!os2dir'\install\prdrv.lst', 'C', 'QUERY EXISTS')
876 globals.!prdesc = STREAM( globals.!os2dir'\install\prdesc.lst', 'C', 'QUERY EXISTS')
877
878RETURN 0
879
880/*:VRX LoopbackName
881*/
882/* Check to see if 'localhost' is defined in the HOSTS file. If not, we'll
883 * have to use '127.0.0.1' instead.
884 */
885LoopbackName: PROCEDURE
886
887 lo_name = '127.0.0.1'
888 etcdir = VALUE('ETC',,'OS2ENVIRONMENT')
889 IF etcdir <> '' THEN DO
890 hosts = STREAM( etcdir'\HOSTS', 'C', 'QUERY EXISTS')
891 IF hosts <> '' THEN DO
892 CALL LINEIN hosts, 1, 0
893 DO WHILE LINES( hosts ) > 0
894 _hostdef = TRANSLATE( LINEIN( hosts ))
895 _hostdef = TRANSLATE( _hostdef, ' ', '09'x )
896 IF WORDPOS('LOCALHOST', _hostdef ) == 2 THEN DO
897 lo_name = 'localhost'
898 LEAVE
899 END
900 END
901 END
902 END
903
904RETURN lo_name
905
906/*:VRX PB_CANCEL_Click
907*/
908PB_CANCEL_Click:
909 CALL Quit
910return
911
912/*:VRX PB_CREATECANCEL_Click
913*/
914PB_CREATECANCEL_Click:
915 CALL SW_CREATE_Close
916RETURN
917
918/*:VRX PB_CREATEOK_Click
919*/
920PB_CREATEOK_Click:
921
922 create_os2 = VRGet('CHK_CREATEPM', 'Set')
923 globals.!os2printer = create_os2
924 globals.!os2driver = VRGet('DDCB_PRESDRV', 'SelectedString')
925 globals.!create = 1
926
927 CALL SW_CREATE_Close
928
929RETURN
930
931/*:VRX PB_MODELCANCEL_Click
932*/
933PB_MODELCANCEL_Click:
934 CALL SW_MODEL_Close
935 globals.!prt_nick = 'Generic PostScript Printer'
936RETURN
937
938/*:VRX PB_MODELOK_Click
939*/
940PB_MODELOK_Click:
941 globals.!prt_nick = VRGet( "LB_OS2MODELS", "SelectedString" )
942 CALL SW_MODEL_Close
943RETURN
944
945/*:VRX PB_NETCANCEL_Click
946*/
947PB_NETCANCEL_Click:
948 CALL SW_NETWORK_Fini
949RETURN
950
951/*:VRX PB_NETOK_Click
952*/
953PB_NETOK_Click: PROCEDURE EXPOSE globals. port
954 which = VRGet('DDCB_PROTOCOL', 'Selected')
955 server = STRIP( VRGet("EF_SERVER", "Value"))
956 pqueue = STRIP( VRGet("EF_QUEUE", "Value"))
957 userid = STRIP( VRGet("EF_USERID", "Value"))
958 passwd = STRIP( VRGet("EF_PASSWORD", "Value"))
959
960 invalid = 0
961
962 SELECT
963 WHEN which == 1 THEN DO /* IPP */
964 IF server == '' | pqueue == '' THEN invalid = 1
965 uri = 'ipp://'
966 IF userid <> '' THEN DO
967 uri = uri || userid
968 IF passwd <> '' THEN uri = uri':'passwd
969 uri = uri'@'
970 END
971 uri = uri || server'/'pqueue
972 END
973 WHEN which == 2 THEN DO /* SOCKET */
974 IF server == '' THEN invalid = 1
975 uri = 'socket://'server
976 END
977 WHEN which == 3 THEN DO /* LPD */
978 IF server == '' THEN invalid = 1
979 IF pqueue == '' THEN pqueue = '*'
980 IF userid <> '' THEN
981 uri = 'ipp://'userid'@'server'/'pqueue
982 ELSE
983 uri = 'lpd://'server'/'pqueue
984 END
985 WHEN which == 4 THEN DO /* SMB */
986 IF server == '' | pqueue == '' THEN invalid = 1
987 uri = 'smb://'
988 IF userid <> '' THEN DO
989 uri = uri || userid
990 IF passwd <> '' THEN uri = uri':'passwd
991 uri = uri'@'
992 END
993 uri = uri || server'/'pqueue
994 END
995 OTHERWISE DO
996 IF server == '' | pqueue == '' THEN invalid = 1
997 ELSE DO
998 globals.!remotecups = server pqueue
999 uri = ''
1000 END
1001 END
1002 END
1003
1004 IF invalid == 1 THEN DO
1005 CALL VRMessage VRWindow(), 'Missing required value(s).', 'Missing Value(s)', 'E'
1006 RETURN
1007 END
1008
1009 port = uri
1010 CALL SW_NETWORK_Fini
1011
1012RETURN
1013
1014/*:VRX PB_NEXT_Click
1015*/
1016PB_NEXT_Click: PROCEDURE EXPOSE globals.
1017
1018 SELECT
1019 WHEN globals.!page == 1 THEN DO
1020 selected = VRGet('LB_SELECT', 'Selected')
1021 IF selected == 0 THEN RETURN
1022
1023 ppd = VRMethod('LB_SELECT', 'GetItemData', selected )
1024 IF ppd == '' THEN DO
1025 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1026 ppd = VRFileDialog( VRWindow(), 'Select PPD', 'O', '*.ppd')
1027 IF ppd == '' THEN RETURN
1028 globals.!prt_ppd = ppd
1029 globals.!prt_dev = ''
1030 globals.!prt_nick = GetNameFromPPD( ppd )
1031 END
1032 ELSE DO
1033 globals.!mode = 1 /* Mode 1: CUPS-included model */
1034 IF POS('exe://', ppd ) > 0 THEN DO
1035 globals.!prt_ppd = ''
1036 globals.!prt_dev = ppd
1037 sel_name = VRMethod('LB_SELECT', 'GetString', selected )
1038 PARSE VAR sel_name _nick ' - CUPS' .
1039 IF _nick == '' THEN
1040 globals.!prt_nick = STRIP( sel_name )
1041 ELSE
1042 globals.!prt_nick = STRIP( _nick )
1043 END
1044 ELSE DO
1045 globals.!prt_ppd = TRANSLATE( globals.!cupsdir'/share/cups/model/'ppd, '\', '/')
1046 globals.!prt_dev = ''
1047 globals.!prt_nick = GetNameFromPPD( ppd )
1048 END
1049 END
1050 globals.!remotecups = ''
1051
1052 CALL InitMessageLog
1053 IF globals.!mode ==2 THEN
1054 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1055 ELSE
1056 CALL LINEOUT globals.!log1, 'Starting printer install for built-in model:'
1057 IF globals.!prt_dev <> '' THEN
1058 CALL LINEOUT globals.!log1, ' - Device name:' globals.!prt_dev
1059 ELSE
1060 CALL LINEOUT globals.!log1, ' - PPD file: ' globals.!prt_ppd
1061 CALL LINEOUT globals.!log1, ' - Model name: ' globals.!prt_nick
1062 CALL LINEOUT globals.!log1, ''
1063
1064 CALL SetPage2
1065 END
1066
1067 WHEN globals.!page == 2 THEN DO
1068 selected = VRGet('LB_SELECT', 'Selected')
1069 IF selected == 0 THEN RETURN
1070 port = VRMethod('LB_SELECT', 'GetItemData', selected )
1071
1072 IF port == '' THEN DO
1073 /* Network printer selected; prompt for the connection details
1074 */
1075 CALL VRLoadSecondary 'SW_NETWORK', 'W'
1076 END
1077
1078 IF port == '' & globals.!remotecups == '' THEN RETURN
1079 globals.!prt_port = port
1080
1081 CALL SetPage3
1082 END
1083
1084 WHEN globals.!page == 3 THEN DO
1085 globals.!prt_name = STRIP( VRGet('EF_NAME', 'Value'))
1086 globals.!prt_loc = STRIP( VRGet('EF_LOCATION', 'Value'))
1087 globals.!prt_info = STRIP( VRGet('EF_DESC', 'Value'))
1088 IF ((( globals.!prt_name == '') |,
1089 ( globals.!prt_loc == '')) & ( globals.!remotecups == '')) |,
1090 ( globals.!prt_info == '') THEN
1091 DO
1092 IF ( globals.!remotecups <> '') THEN
1093 _errmsg = 'You must enter a description.'
1094 ELSE
1095 _errmsg = 'You must enter a name, a location, and a description.'
1096 CALL VRMessage VRWindow(), _errmsg, 'Missing Value(s)', 'E'
1097 RETURN
1098 END
1099 IF ( globals.!remotecups == '' &,
1100 ( POS( LEFT( globals.!prt_name, 1 ),,
1101 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') == 0 ) |,
1102 ( VERIFY( globals.!prt_name, '/# ' || '09'x, 'MATCH') <> 0 )) THEN
1103 DO
1104 CALL VRMessage VRWindow(), 'The printer name must start ' ||,
1105 'with a letter, and may not include "/", "#", ' ||,
1106 'space, or tab characters.', 'Invalid Name', 'E'
1107 RETURN
1108 END
1109
1110 /* TODO support other drivers
1111 */
1112 IF WORD( globals.!prt_nick, 1 ) == 'Apollo' |,
1113 WORD( globals.!prt_nick, 1 ) == 'HP' |,
1114 WORD( globals.!prt_nick, 1 ) == 'Hewlett-Packard' THEN
1115 globals.!os2driver = 'ECUPS-HP'
1116 ELSE
1117 globals.!os2driver = 'ECUPS'
1118
1119 CALL ConfirmAndCreate
1120 END
1121
1122 WHEN globals.!page == 4 THEN DO
1123 CALL VRSet 'PB_NEXT', 'Caption', 'Next >'
1124 CALL VRSet 'EF_NAME', 'Value', ''
1125 CALL VRSet 'EF_LOCATION', 'Value', ''
1126 CALL VRSet 'EF_DESC', 'Value', ''
1127 CALL SetPage1
1128 END
1129
1130 OTHERWISE NOP
1131 END
1132
1133RETURN
1134
1135/*:VRX PromptForPMName
1136*/
1137PromptForPMName: PROCEDURE EXPOSE globals. models. best
1138 best = MatchPrinterModel( globals.!os2driver, globals.!prt_nick )
1139
1140 IF models.0 == 0 THEN DO
1141 /* No similar models were found in the list of supported printers.
1142 * Just use the generic PS driver.
1143 */
1144 CALL VRMessage VRWindow(),,
1145 'The printer "'globals.!prt_nick'" does not appear to' ,
1146 'be supported by the' globals.!os2driver 'driver, and' ,
1147 'no similar models were found. The generic PostScript',
1148 'driver will be used for application support.',,
1149 'Printer Name Not Found', 'E'
1150 globals.!prt_nick = 'Generic PostScript Printer'
1151 RETURN
1152 END
1153
1154 CALL VRLoadSecondary 'SW_MODEL', 'W'
1155
1156RETURN
1157
1158/*:VRX Quit
1159*/
1160Quit:
1161 window = VRWindow()
1162 call VRSet window, "Shutdown", 1
1163 drop window
1164return
1165
1166/*:VRX SetPage1
1167*/
1168SetPage1: PROCEDURE EXPOSE globals.
1169
1170 CALL VRSet 'LB_SELECT', 'Visible', 1
1171 CALL VRSet 'GB_INFO', 'Visible', 0
1172
1173 globals.!page = 1
1174 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1175 CALL GetCupsPrinters
1176 CALL VRMethod 'LB_SELECT', 'SetFocus'
1177 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1178RETURN
1179
1180/*:VRX SetPage2
1181*/
1182SetPage2: PROCEDURE EXPOSE globals.
1183
1184 globals.!page = 2
1185 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1186 CALL GetCupsPorts
1187 CALL VRMethod 'LB_SELECT', 'SetFocus'
1188 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1189
1190RETURN
1191
1192/*:VRX SetPage3
1193*/
1194SetPage3: PROCEDURE EXPOSE globals.
1195
1196 globals.!page = 3
1197 CALL VRSet 'EF_DESC', 'Value', globals.!prt_nick
1198
1199 CALL VRMethod 'LB_SELECT', 'Clear'
1200
1201 CALL VRSet 'LB_SELECT', 'Visible', 0
1202 CALL VRSet 'GB_INFO', 'Visible', 1
1203 IF globals.!remotecups == '' THEN DO
1204 CALL VRSet 'DT_INFO', 'Caption', 'Choose the printer name, and enter its location and a short description.'
1205 CALL VRSet 'DT_NAME', 'Visible', 1
1206 CALL VRSet 'EF_NAME', 'Visible', 1
1207 CALL VRSet 'DT_LOCATION', 'Visible', 1
1208 CALL VRSet 'EF_LOCATION', 'Visible', 1
1209 END
1210 ELSE
1211 CALL VRSet 'DT_INFO', 'Caption', 'Enter a short description of this printer. ',
1212 'This will be used for the printer object that appears on your desktop.'
1213 CALL VRSet 'DT_DESC', 'Visible', 1
1214 CALL VRSet 'EF_DESC', 'Visible', 1
1215
1216 CALL VRMethod 'EF_NAME', 'SetFocus'
1217
1218RETURN
1219
1220/*:VRX SetPage4
1221*/
1222SetPage4:
1223
1224 globals.!page = 4
1225 CALL VRSet 'LB_SELECT', 'Visible', 0
1226 CALL VRSet 'GB_INFO', 'Visible', 0
1227
1228RETURN
1229
1230/*:VRX SW_CREATE_Close
1231*/
1232SW_CREATE_Close:
1233 call SW_CREATE_Fini
1234return
1235
1236/*:VRX SW_CREATE_Create
1237*/
1238SW_CREATE_Create:
1239 call SW_CREATE_Init
1240return
1241
1242/*:VRX SW_CREATE_Fini
1243*/
1244SW_CREATE_Fini:
1245 window = VRInfo( "Window" )
1246 call VRDestroy window
1247 drop window
1248return
1249/*:VRX SW_CREATE_Init
1250*/
1251SW_CREATE_Init:
1252
1253 CALL VRSet 'EF_CRMODEL', 'Value', globals.!prt_nick
1254
1255 IF globals.!remotecups <> '' THEN DO
1256 /* An existing CUPS printer was indicated. This means we're not
1257 * creating a CUPS printer, but only a PM printer object (and port)
1258 * that points to it.
1259 */
1260 CALL VRSet 'DT_CREATE', 'Caption', 'Ready to create printer object with the following parameters.'
1261
1262 PARSE VAR globals.!remotecups cups_host cups_printer .
1263 CALL VRSet 'DT_CRNAME', 'Caption', 'CUPS server:'
1264 CALL VRSet 'EF_CRNAME', 'Value', cups_host
1265 CALL VRSet 'DT_CRURI', 'Caption', 'CUPS queue:'
1266 CALL VRSet 'EF_CRURI', 'Value', cups_printer
1267 CALL VRSet 'DT_CRLOC', 'Visible', 0
1268 CALL VRSet 'EF_CRLOC', 'Visible', 0
1269 CALL VRSet 'CHK_CREATEPM', 'Visible', 0
1270 END
1271 ELSE DO
1272 CALL VRSet 'EF_CRNAME', 'Value', globals.!prt_name
1273 CALL VRSet 'EF_CRURI', 'Value', globals.!prt_port
1274 CALL VRSet 'EF_CRLOC', 'Value', globals.!prt_loc
1275 END
1276 CALL VRSet 'EF_CRDESC', 'Value', globals.!prt_info
1277
1278 IF QueryAvailableDrivers() > 0 THEN DO
1279 def_idx = 1
1280 CALL VRMethod 'DDCB_PRESDRV', 'AddStringList', 'drv_list.'
1281 DO i = 1 TO drv_list.0
1282 IF drv_list.i == globals.!os2driver THEN DO
1283 def_idx = i
1284 LEAVE
1285 END
1286 END
1287 CALL VRSet 'DDCB_PRESDRV', 'Selected', def_idx
1288 END
1289 /* TODO give an error if no drivers were found */
1290
1291 window = VRInfo( "Object" )
1292 if( \VRIsChildOf( window, "Notebook" ) ) then do
1293 call VRMethod window, "CenterWindow"
1294 call VRSet window, "Visible", 1
1295 call VRMethod window, "Activate"
1296 end
1297 drop window
1298
1299RETURN
1300
1301/*:VRX SW_MODEL_Close
1302*/
1303SW_MODEL_Close:
1304 call SW_MODEL_Fini
1305return
1306
1307/*:VRX SW_MODEL_Create
1308*/
1309SW_MODEL_Create:
1310 call SW_MODEL_Init
1311return
1312
1313/*:VRX SW_MODEL_Fini
1314*/
1315SW_MODEL_Fini:
1316
1317 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1318
1319 window = VRInfo( "Window" )
1320 call VRDestroy window
1321 drop window
1322return
1323/*:VRX SW_MODEL_Init
1324*/
1325SW_MODEL_Init:
1326
1327 /* We should have a list of suggested printer models whose names at least
1328 * partially match the requested model, sorted in order with the closest
1329 * match at the top.
1330 */
1331 ok = VRMethod( "LB_OS2MODELS", "AddStringList", "models.", )
1332 IF best > 0 THEN
1333 CALL VRSet 'LP_OS2MODELS', 'Selected', best
1334
1335 CALL VRSet 'DT_MODEL1', 'Caption',,
1336 'The printer "'globals.!prt_nick'" could not be found in the' ,
1337 globals.!os2driver'.DRV driver under that name. Please choose',
1338 'the model of printer which will be reported to applications.'
1339
1340 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1341
1342 window = VRInfo( "Object" )
1343 if( \VRIsChildOf( window, "Notebook" ) ) then do
1344 call VRMethod window, "CenterWindow"
1345 call VRSet window, "Visible", 1
1346 call VRMethod window, "Activate"
1347 end
1348 drop window
1349
1350RETURN
1351
1352/*:VRX SW_NETWORK_Close
1353*/
1354SW_NETWORK_Close:
1355 call SW_NETWORK_Fini
1356return
1357
1358/*:VRX SW_NETWORK_Create
1359*/
1360SW_NETWORK_Create:
1361 call SW_NETWORK_Init
1362return
1363
1364/*:VRX SW_NETWORK_Fini
1365*/
1366SW_NETWORK_Fini:
1367 window = VRInfo( "Window" )
1368 call VRDestroy window
1369 drop window
1370return
1371/*:VRX SW_NETWORK_Init
1372*/
1373SW_NETWORK_Init:
1374
1375 CALL VRSet 'DDCB_PROTOCOL', 'Selected', 1
1376
1377 window = VRInfo( "Object" )
1378 if( \VRIsChildOf( window, "Notebook" ) ) then do
1379 call VRMethod window, "CenterWindow"
1380 call VRSet window, "Visible", 1
1381 call VRMethod window, "Activate"
1382 end
1383 drop window
1384return
1385
1386/*:VRX WN_MAIN_Close
1387*/
1388WN_MAIN_Close:
1389 call Quit
1390return
1391
Note: See TracBrowser for help on using the repository browser.