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

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

Printer list is now split by manufacturer/model, and model names are more concise. Only 'Simplified' drivers are shown by default. ECUPS-HP and PSPRINT drivers now supported.

File size: 53.8 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. manufacturers.
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 makers = ''
455 DO QUEUED()
456 PARSE PULL line
457 IF LEFT( line, 6 ) == 'drv://' THEN ITERATE
458 IF WORD( line, 1 ) == 'raw' THEN ITERATE
459 PARSE VAR line _ppd '.ppd.gz ' _name
460 _ppd = _ppd'.ppd.gz'
461 IF _name == '' THEN DO
462 PARSE VAR line _ppd '.ppd ' _name
463 _ppd = _ppd'.ppd'
464 END
465 IF _name == '' THEN DO
466 PARSE VAR line _ppd _name
467 END
468 IF _name <> '' THEN DO
469 PARSE VAR _name _brand _model
470 IF WORDPOS( _brand, makers ) == 0 THEN makers = makers || _brand' '
471 i = i + 1
472 ppds.i = _ppd
473 models.i = _name
474 END
475 END
476 ppds.0 = i
477 models.0 = i
478
479 CALL RXQUEUE 'SET', defqueue
480 CALL RXQUEUE 'DELETE', listqueue
481 CALL DIRECTORY _od
482
483/* Now build the 'manufacturers' stem.
484 * This stem takes the following format:
485 * manufacturers.0 number of manufacturers
486 * manufacturers.i.!name manufacturer name (e.g. 'Apple')
487 * manufacturers.i.!printers.0 number of printer models
488 * manufacturers.i.!printers.j.!model printer model name, short form (e.g. 'LaserWriter 330')
489 * manufacturers.i.!printers.j.!type driver version/type (e.g. 'Gutenprint v5.2.7')
490 * manufacturers.i.!printers.j.!driver the internal CUPS printer driver name (PPD or URI)
491 * - by preference this is the "simplified" version if available
492 * manufacturers.i.!printers.j.!remark any distinguishing remarks (e.g. 'Simplified')
493 * manufacturers.i.!printers.j.!driver2 alternate driver in case there is more than one (PPD or URI)
494 * - if defined this is usually the non-"simplified" driver
495 * manufacturers.i.!printers.j.!remark2 any distinguishing remarks for the alternate driver
496 */
497
498 manufacturers.0 = WORDS( makers )
499 DO i = 1 TO manufacturers.0
500 manufacturers.i.!name = WORD( makers, i )
501 manufacturers.i.!printers.0 = 0
502 END
503
504 DO i = 1 TO models.0
505 PARSE VAR models.i _brand _model ' - CUPS+' _type
506 man = WORDPOS( _brand, makers )
507 IF man == 0 THEN ITERATE
508
509 PARSE VAR _type _version 'Simplified' .
510 _version = STRIP( _version )
511 _flag = RIGHT( _type, 10 )
512
513 count = manufacturers.man.!printers.0
514 IF count > 0 THEN DO
515 /* If there are two or more printers defined with the same model
516 * name and driver version, keep the first and last as the regular
517 * and alternate drivers; if one if them is 'Simplified', make that
518 * the regular driver by preference.
519 */
520 IF ( manufacturers.man.!printers.count.!model == _model ) & ,
521 ( manufacturers.man.!printers.count.!type == _version ) THEN
522 DO
523 IF ( WORD( _version, 1 ) == 'Gutenprint') & ( _flag == 'Simplified') THEN DO
524 manufacturers.man.!printers.count.!driver2 = manufacturers.man.!printers.count.!driver
525 manufacturers.man.!printers.count.!remark2 = manufacturers.man.!printers.count.!remark
526 manufacturers.man.!printers.count.!driver = ppds.i
527 manufacturers.man.!printers.count.!remark = 'Simplified'
528 END
529 ELSE DO
530 manufacturers.man.!printers.count.!driver2 = ppds.i
531 IF _flag == 'Simplified' THEN
532 manufacturers.man.!printers.count.!remark2 = 'Simplified'
533 ELSE
534 manufacturers.man.!printers.count.!remark2 = ''
535 END
536 ITERATE
537 END
538 END
539 count = count + 1
540 manufacturers.man.!printers.count.!model = _model
541 manufacturers.man.!printers.count.!type = _version
542 manufacturers.man.!printers.count.!driver = ppds.i
543 IF _flag == 'Simplified' THEN
544 manufacturers.man.!printers.count.!remark = 'Simplified'
545 ELSE
546 manufacturers.man.!printers.count.!remark = ''
547 manufacturers.man.!printers.count.!driver2 = ''
548 manufacturers.man.!printers.count.!remark2 = ''
549 manufacturers.man.!printers.0 = count
550 END
551
552 /* Add one more category for special items ...
553 */
554 count = manufacturers.0 + 1
555 manufacturers.count.!name = '-- Custom --'
556 manufacturers.count.!printers.0 = 1
557 manufacturers.count.!printers.1.!model = '-- Other printer (requires PPD) --'
558 manufacturers.count.!printers.1.!driver = ''
559 manufacturers.count.!printers.1.!type = ''
560 manufacturers.count.!printers.1.!remark = '-- Other printer (requires PPD) --'
561 manufacturers.count.!printers.1.!driver2 = ''
562 manufacturers.count.!printers.1.!remark2 = ''
563 manufacturers.0 = count
564
565RETURN
566
567/*:VRX Halt
568*/
569Halt:
570 signal _VREHalt
571return
572
573/*:VRX ImportPPD
574*/
575ImportPPD: PROCEDURE EXPOSE globals.
576 /* Import a new PPD file into a PostScript PrinterPak driver.
577 */
578 ARG driver, ppdfile
579 IF driver == '' THEN driver = 'PSCRIPT'
580
581 CALL LINEOUT globals.!log1, 'Going to import PPD file into driver' driver'.'
582
583 /***
584 *** First, get our working directories and locate the driver source files.
585 ***/
586
587 mustcopy = 0
588 driver_path = GetDriverSource( driver )
589 IF driver_path == '' THEN DO
590 /* No source found. We'll have to try copying the actual installed
591 * driver files from under \OS2\DLL.
592 */
593 CALL LINEOUT globals.!log1, 'Driver source not found.'
594 driver_path = STREAM( globals.!os2dir'\DLL\'driver'\'driver'.DRV', 'C', 'QUERY EXISTS')
595 mustcopy = 1
596 END
597 IF driver_path <> '' THEN DO
598 srcdir = VRParseFilePath( driver_path, 'DP')
599 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
600 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
601 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
602 DROP srcdir
603 END
604
605 /* Driver (or one of its required files) was not found.
606 */
607 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
608 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
609 DO
610 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
611 /* TODO should prompt for installable driver package? */
612 RETURN 1 /** RC=1 Missing required driver files **/
613 END
614
615 IF mustcopy <> 0 THEN DO
616 /* Looks like the driver wasn't shipped with the OS; we have a source
617 * (either the active files from \OS2\DLL, or a package provided by
618 * the user), but we need somewhere for them to live. The user needs
619 * to tell us where, because they're going to have to specify the
620 * directory later on if they install the driver from PM.
621 */
622 pbtn.1 = 'OK'
623 pbtn.2 = 'Cancel'
624 pbtn.0 = 2
625 ptext = 'The install files for the' driver 'driver could not be ' ||,
626 'located. These files will be recreated from the driver ' ||,
627 'files which are already installed on your system.' ||,
628 '0d0a0d0a'x || 'Please enter the directory where the ' ||,
629 'install files will be placed.'
630 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
631 IF drvr_dir == '' THEN
632 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
633 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
634 'Enter Directory', 'pbtn.', 1, 2 )
635 IF ok <> 1 THEN RETURN 9 /** RC=9 User cancelled **/
636 drvr_dir = VRExpandFileName( drvr_dir )
637 DO WHILE drvr_dir == ''
638 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
639 'Enter Directory', 'pbtn.', 1, 2 )
640 drvr_dir = VRExpandFileName( drvr_dir )
641 END
642
643 /* Now create the new directory, if necessary */
644 IF VRMkDir( drvr_dir ) == 0 THEN
645 RETURN 3 /** RC=3 Failed to copy driver files **/
646 IF CopyDriverToSource( driver_path, drvr_dir ) == 0 THEN
647 RETURN 3 /** RC=3 Failed to copy driver files **/
648
649 /* Make sure we save the location (we'll need this information later) */
650 CALL VRSetIni 'PM_INSTALL', driver'_DIR', drvr_dir||'00'x, 'USER'
651
652 /* Now point to the new copy as the driver we will work on */
653 driver_path = drvr_dir'\'driver'.DRV'
654 END
655
656 workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
657 ok = VrMkDir( workdir )
658 IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
659 IF ok <> 1 THEN
660 RETURN 2 /** RC=2 Failed to create temporary directory **/
661
662 SELECT
663 WHEN driver == 'ECUPS' THEN ppddir = globals.!repository'\PPD_E'
664 WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
665 WHEN driver == 'PSPRINT' THEN ppddir = globals.!repository'\PPD_PS'
666 WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
667 WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
668 OTHERWISE ppddir = globals.!repository'\PPD'
669 END
670
671 /* Make sure ppddir (for keeping PPD files) exists */
672 CALL SysFileTree ppddir, 'dirs.', 'DO'
673 IF dirs.0 == 0 THEN DO
674 ok = VrMkDir( ppddir )
675 IF ok <> 1 THEN
676 RETURN 4 /** RC=4 Failed to create PPD directory **/
677 END
678
679 /***
680 *** Now do the actual work.
681 ***/
682
683 /* Back up the modified files (AUXPRINT.PAK and <driver>.DRV) if we're
684 * working out of the repository.
685 IF mustcopy == 0 THEN DO
686 repfiles.0 = 2
687 repfiles.1 = driver'.DRV'
688 repfiles.2 = 'AUXPRINT.PAK'
689 CALL BackupDrivers driver_path
690 END
691 */
692
693 /* Copy the needed driver files to our working directories.
694 */
695 drv_out = workdir'\OUT\'driver'.DRV'
696 pin_exe = workdir'\PIN.EXE'
697 ppd_exe = workdir'\PPDENC.EXE'
698 ok = VRCopyFile( driver_path, drv_out )
699 IF ok == 1 THEN ok = VRCopyFile( pin, pin_exe )
700 IF ok == 1 THEN ok = VRCopyFile( ppdenc, ppd_exe )
701 IF ok == 0 THEN DO
702 RETURN 3 /*** RC=3 Failed to copy driver files ***/
703 END
704
705 /* Set up the output redirection.
706 */
707 nq = RXQUEUE('CREATE')
708 oq = RXQUEUE('SET', nq )
709
710 /* If the PPD file is compressed, uncompress it.
711 */
712 IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
713 decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
714 CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
715 ADDRESS CMD '@gzip -c -d' ppdfile '| RXQUEUE' nq
716 DO QUEUED()
717 PARSE PULL line
718 CALL LINEOUT decppd, line
719 END
720 CALL LINEOUT decppd
721 ppdfile = decppd
722 END
723
724 IF VRFileExists( ppdfile ) == 0 THEN DO
725 CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
726 RETURN 5 /** RC=5 PPD import failed **/
727 END
728
729 ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
730
731 /* Now we have to clean up and validate the PPD file so PIN can use it.
732 * First, PPDENC converts the codepage if necessary, and copies the results
733 * to our working directory.
734 */
735 ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>&1 | RXQUEUE' nq
736 DO QUEUED()
737 PULL output
738 CALL LINEOUT globals.!log2, output
739 END
740 CALL LINEOUT globals.!log2, ''
741 CALL LINEOUT globals.!log2
742
743 /* Next we strip out some problematic lines used which are often encountered
744 * in (e.g.) CUPS-based PPD files.
745 */
746 CALL CleanPPD ppd_use, globals.!log1
747
748 /* Preparation complete. Now do the import.
749 */
750 count = 0
751 ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>&1 | RXQUEUE' nq
752 DO QUEUED()
753 PARSE PULL output
754 CALL LINEOUT globals.!log2, output
755 PARSE VAR output . 'OK (' nickname
756 IF nickname <> '' THEN DO
757 count = count + 1
758 newprinters.count = STRIP( nickname, 'T', ')')
759 END
760 END
761 newprinters.0 = count
762 CALL LINEOUT globals.!log2, ''
763 CALL LINEOUT globals.!log2
764
765 /* End the output redirection.
766 */
767 CALL RXQUEUE 'SET', oq
768 CALL RXQUEUE 'DELETE', nq
769
770
771 /***
772 *** Post-import processing.
773 ***/
774
775 IF newprinters.0 == 0 THEN DO
776 RETURN 5 /** RC=5 PPD import failed **/
777 END
778
779 IF mustcopy == 0 THEN DO
780 /* If we're working out of the repository, we need to update the
781 * driver table in PRDESC.LST to add the new driver(s).
782 */
783 CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with' newprinters.0 'new entries ...'
784 count = 0
785 match_drv = '('driver'.DRV)'
786 match_len = LENGTH( match_drv )
787
788 /* First, copy all lines that don't refer to the driver just updated */
789 DO WHILE LINES( globals.!prdesc )
790 _line = LINEIN( globals.!prdesc )
791 IF TRANSLATE( RIGHT( _line, LENGTH( match_len ))) == match_drv THEN ITERATE
792 count = count + 1
793 defs.count = _line
794 END
795 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
796
797 /* Next, create a new list for the updated driver and merge that in */
798 newlist = workdir'\'driver'.LST'
799 CALL CreateDriverList driver, newlist
800 DO WHILE LINES( newlist )
801 _line = LINEIN( newlist )
802 count = count + 1
803 defs.count = _line
804 END
805 defs.0 = count
806
807 /* Now sort the list and recreate PRDESC.LST */
808 CALL SysStemSort 'defs.',, 'I'
809 prdesc_tmp = workdir'\PRDESC.LST'
810 IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
811 CALL VRDeleteFile prdesc_tmp
812 DO i = 1 TO defs.0
813 CALL LINEOUT prdesc_tmp, defs.i
814 END
815 CALL LINEOUT prdesc_tmp
816 ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
817 IF ok == 0 THEN DO
818 RETURN 6 /** RC=6 Error updating PRDESC.LST **/
819 END
820 CALL VRDeleteFile prdesc_tmp
821
822 END
823
824 /* Finally, copy the updated driver files.
825 */
826 target = VRParseFilePath( driver_path, 'DP')
827 ok = VRCopyFile( workdir'\OUT\*', target )
828 IF ok == 1 THEN DO
829 /* Copy the updated files to \OS2\DLL\<driver>, replacing any
830 * existing copies. (This prevents problems if the OS/2 driver
831 * installation doesn't/fails to copy them, which can happen under
832 * some circumstances.)
833 */
834 IF VRFileExists( globals.!os2dir'\DLL\'driver ) THEN DO
835 CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
836 globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
837 CALL VRCopyFile workdir'\OUT\'driver'.DRV',,
838 globals.!os2dir'\DLL\'driver'\'driver'.DRV'
839 END
840 END
841 IF ok == 0 THEN
842 RETURN 3 /*** RC=3 Failed to copy driver files ***/
843
844 CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
845 DO i = 1 TO newprinters.0
846 CALL LINEOUT globals.!log1, ' ->' newprinters.i
847 END
848 CALL LINEOUT globals.!log1, ''
849 CALL LINEOUT globals.!log1
850
851 /* Clean up our work directories.
852 */
853 CALL VRDeleteFile workdir'\OUT\*'
854 CALL VRDeleteFile workdir'\*'
855 CALL VRRmDir( workdir'\OUT')
856 CALL VRRmDir( workdir )
857
858RETURN 0
859
860/*:VRX Init
861*/
862Init:
863 SIGNAL ON NOVALUE NAME __NoValue
864
865 CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
866 CALL SysLoadFuncs
867
868 CALL LoadSettings
869
870 IF InitArgs.0 > 0 THEN globals.!cupsdir = InitArgs.1
871
872 IF \VRIsDir( globals.!cupsdir ) THEN DO
873 CALL VRMessage VRWindow(), 'Please specify the path where CUPS is installed as follows:' ||,
874 '0d0a0d0a'x || 'CUPSWIZ <cups-path>',,
875 'Unknown or Invalid CUPS Path', 'E'
876 EXIT
877 END
878
879 /* Delete the error log file each time the program starts.
880 */
881 IF VRFileExists( globals.!log2 ) THEN
882 CALL VRDeleteFile globals.!log2
883
884 window = VRWindow()
885 call VRMethod window, "CenterWindow"
886 call VRSet window, "Visible", 1
887 call VRMethod window, "Activate"
888 drop window
889
890 CALL SetPage1
891
892RETURN
893
894/*:VRX InitMessageLog
895*/
896/* Initialize the message logfile. Unlike the error log, which is cleared and
897 * recreated every time the program starts, the message log is appended to
898 * until it reaches 100kB in size. If the message log is larger than 100kB when
899 * this function is called, it is renamed (with '~' appended to the name) and
900 * a new message log is started.
901 */
902InitMessageLog: PROCEDURE EXPOSE globals.
903
904 logsize = STREAM( globals.!log1, 'C', 'QUERY SIZE')
905 IF ( logsize <> '') & ( logsize > 102400 ) THEN DO
906 CALL VRCopyFile globals.!log1, globals.!log1 || '~'
907 CALL VRDeleteFile globals.!log1
908 END
909
910 datestr = DATE('L') TIME('N')
911 CALL LINEOUT globals.!log1, '--[' datestr ']' ||,
912 COPIES('-', 73 - LENGTH( datestr ))
913RETURN
914
915/*:VRX LB_BRAND_Click
916*/
917LB_BRAND_Click: PROCEDURE EXPOSE globals. manufacturers.
918
919 CALL VRSet 'WN_MAIN', 'StatusText', ''
920
921 index = VRGet('LB_BRAND', 'Selected')
922 IF index == 0 THEN RETURN
923
924 item = VRMethod('LB_BRAND', 'GetItemData', index )
925 IF item == 0 THEN RETURN
926
927 DO i = 1 TO manufacturers.item.!printers.0
928 models.i = manufacturers.item.!printers.i.!model
929 /* ppds.i = manufacturers.item.!printers.i.!driver */
930 IF manufacturers.item.!printers.i.!driver == '' THEN
931 ppds.i = ''
932 ELSE
933 ppds.i = i
934
935/* DEBUG
936say 'Model: ' manufacturers.item.!printers.i.!model
937say 'Driver: ' manufacturers.item.!printers.i.!driver
938say ' ' manufacturers.item.!printers.i.!longname
939if manufacturers.item.!printers.i.!driver2 <> '' then
940 say 'Alternate:' manufacturers.item.!printers.i.!driver2
941if manufacturers.item.!printers.i.!longname2 <> '' then
942 say ' ' manufacturers.item.!printers.i.!longname2
943say 'Type: ' manufacturers.item.!printers.i.!type
944say '---'
945 */
946
947 END
948 models.0 = manufacturers.item.!printers.0
949 ppds.0 = manufacturers.item.!printers.0
950
951 CALL VRSet 'LB_SELECT', 'Painting', 0
952 CALL VRMethod 'LB_SELECT', 'Clear'
953 CALL VRMethod 'LB_SELECT', 'AddStringList', 'models.',, 'ppds.'
954 CALL VRSet 'LB_SELECT', 'Painting', 1
955
956RETURN
957
958/*:VRX LB_SELECT_Click
959*/
960LB_SELECT_Click: PROCEDURE EXPOSE globals. manufacturers.
961 SELECT
962 WHEN globals.!page == 1 THEN DO
963 CALL VRSet 'WN_MAIN', 'StatusText', ''
964
965 brand = VRGet('LB_BRAND', 'Selected')
966 IF brand == 0 THEN RETURN
967 selected = VRGet('LB_SELECT', 'Selected')
968 IF selected == 0 THEN RETURN
969 which = VRMethod('LB_SELECT', 'GetItemData', selected )
970 IF which == '' THEN RETURN
971 man = VRMethod('LB_BRAND', 'GetItemData', brand )
972 IF man == '' THEN RETURN
973
974 make = manufacturers.man.!name
975 model = manufacturers.man.!printers.which.!model
976 driver = manufacturers.man.!printers.which.!type
977 remark = manufacturers.man.!printers.which.!remark
978 IF remark == '' THEN
979 type = ' ('driver')'
980 ELSE
981 type = ' ('driver' - 'remark')'
982
983 CALL VRSet 'WN_MAIN', 'StatusText', make model type
984 END
985
986 OTHERWISE NOP
987 END
988
989RETURN
990
991/*:VRX LoadSettings
992*/
993LoadSettings: PROCEDURE EXPOSE globals.
994
995 me = VRGet('Application', 'Program')
996 IF me == '' THEN PARSE SOURCE . . me
997 globals.!mydir = VRParseFilePath( me, 'DP')
998
999 /* Get CUPS paths.
1000 */
1001 globals.!cupsdir = ''
1002 cupsdrv = VRParseFilePath( me, 'D')
1003 cupsdir = cupsdrv':\cups'
1004
1005 globals.!cupsdir = cupsdir
1006
1007 /* Get system paths.
1008 */
1009 globals.!bootdrv = SysBootDrive()
1010 IF globals.!bootdrv == '' THEN
1011 globals.!bootdrv = FILESPEC('DRIVE', VALUE('OS2_SHELL',,'OS2ENVIRONMENT'))
1012 globals.!os2dir = globals.!bootdrv'\OS2'
1013 globals.!tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
1014 IF globals.!tmpdir == '' THEN
1015 globals.!tmpdir = VALUE('TEMP',,'OS2ENVIRONMENT')
1016 IF globals.!tmpdir == '' THEN
1017 globals.!tmpdir = globals.!mydir
1018 globals.!logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
1019 IF globals.!logdir == '' THEN
1020 globals.!logdir = globals.!mydir
1021
1022 globals.!log1 = globals.!logdir'\cupswiz.l1'
1023 globals.!log2 = globals.!logdir'\cupswiz.l2'
1024
1025 /* Get printer-related paths.
1026 */
1027 PARSE VALUE VRGetIni('PM_INSTALL', 'PDR_DIR', 'USER') WITH repos_dir '00'x .
1028 globals.!repository = repos_dir
1029 globals.!prdrv = STREAM( globals.!os2dir'\install\prdrv.lst', 'C', 'QUERY EXISTS')
1030 globals.!prdesc = STREAM( globals.!os2dir'\install\prdesc.lst', 'C', 'QUERY EXISTS')
1031
1032RETURN 0
1033
1034/*:VRX LoopbackName
1035*/
1036/* Check to see if 'localhost' is defined in the HOSTS file. If not, we'll
1037 * have to use '127.0.0.1' instead.
1038 */
1039LoopbackName: PROCEDURE
1040
1041 lo_name = '127.0.0.1'
1042 etcdir = VALUE('ETC',,'OS2ENVIRONMENT')
1043 IF etcdir <> '' THEN DO
1044 hosts = STREAM( etcdir'\HOSTS', 'C', 'QUERY EXISTS')
1045 IF hosts <> '' THEN DO
1046 CALL LINEIN hosts, 1, 0
1047 DO WHILE LINES( hosts ) > 0
1048 _hostdef = TRANSLATE( LINEIN( hosts ))
1049 _hostdef = TRANSLATE( _hostdef, ' ', '09'x )
1050 IF WORDPOS('LOCALHOST', _hostdef ) == 2 THEN DO
1051 lo_name = 'localhost'
1052 LEAVE
1053 END
1054 END
1055 END
1056 END
1057
1058RETURN lo_name
1059
1060/*:VRX PB_ABOUT_Click
1061*/
1062PB_ABOUT_Click:
1063 CALL SW_ABOUT_Close
1064RETURN
1065
1066/*:VRX PB_CANCEL_Click
1067*/
1068PB_CANCEL_Click:
1069 CALL Quit
1070return
1071
1072/*:VRX PB_CREATECANCEL_Click
1073*/
1074PB_CREATECANCEL_Click:
1075 CALL SW_CREATE_Close
1076RETURN
1077
1078/*:VRX PB_CREATEOK_Click
1079*/
1080PB_CREATEOK_Click:
1081
1082 create_os2 = VRGet('CHK_CREATEPM', 'Set')
1083 globals.!os2printer = create_os2
1084 globals.!os2driver = VRGet('DDCB_PRESDRV', 'SelectedString')
1085 globals.!create = 1
1086
1087 CALL SW_CREATE_Close
1088
1089RETURN
1090
1091/*:VRX PB_MODELCANCEL_Click
1092*/
1093PB_MODELCANCEL_Click:
1094 CALL SW_MODEL_Close
1095 globals.!prt_nick = 'Generic PostScript Printer'
1096RETURN
1097
1098/*:VRX PB_MODELOK_Click
1099*/
1100PB_MODELOK_Click:
1101 globals.!prt_nick = VRGet( "LB_OS2MODELS", "SelectedString" )
1102 CALL SW_MODEL_Close
1103RETURN
1104
1105/*:VRX PB_NETCANCEL_Click
1106*/
1107PB_NETCANCEL_Click:
1108 CALL SW_NETWORK_Fini
1109RETURN
1110
1111/*:VRX PB_NETOK_Click
1112*/
1113PB_NETOK_Click: PROCEDURE EXPOSE globals. port
1114 which = VRGet('DDCB_PROTOCOL', 'Selected')
1115 server = STRIP( VRGet("EF_SERVER", "Value"))
1116 pqueue = STRIP( VRGet("EF_QUEUE", "Value"))
1117 userid = STRIP( VRGet("EF_USERID", "Value"))
1118 passwd = STRIP( VRGet("EF_PASSWORD", "Value"))
1119
1120 invalid = 0
1121
1122 SELECT
1123 WHEN which == 1 THEN DO /* IPP */
1124 IF server == '' | pqueue == '' THEN invalid = 1
1125 uri = 'ipp://'
1126 IF userid <> '' THEN DO
1127 uri = uri || userid
1128 IF passwd <> '' THEN uri = uri':'passwd
1129 uri = uri'@'
1130 END
1131 uri = uri || server'/'pqueue
1132 END
1133 WHEN which == 2 THEN DO /* SOCKET */
1134 IF server == '' THEN invalid = 1
1135 uri = 'socket://'server
1136 END
1137 WHEN which == 3 THEN DO /* LPD */
1138 IF server == '' THEN invalid = 1
1139 IF pqueue == '' THEN pqueue = '*'
1140 IF userid <> '' THEN
1141 uri = 'ipp://'userid'@'server'/'pqueue
1142 ELSE
1143 uri = 'lpd://'server'/'pqueue
1144 END
1145 WHEN which == 4 THEN DO /* SMB */
1146 IF server == '' | pqueue == '' THEN invalid = 1
1147 uri = 'smb://'
1148 IF userid <> '' THEN DO
1149 uri = uri || userid
1150 IF passwd <> '' THEN uri = uri':'passwd
1151 uri = uri'@'
1152 END
1153 uri = uri || server'/'pqueue
1154 END
1155 OTHERWISE DO
1156 IF server == '' | pqueue == '' THEN invalid = 1
1157 ELSE DO
1158 globals.!remotecups = server pqueue
1159 uri = ''
1160 END
1161 END
1162 END
1163
1164 IF invalid == 1 THEN DO
1165 CALL VRMessage VRWindow(), 'Missing required value(s).', 'Missing Value(s)', 'E'
1166 RETURN
1167 END
1168
1169 port = uri
1170 CALL SW_NETWORK_Fini
1171
1172RETURN
1173
1174/*:VRX PB_NEXT_Click
1175*/
1176PB_NEXT_Click: PROCEDURE EXPOSE globals. manufacturers.
1177
1178 SELECT
1179 WHEN globals.!page == 1 THEN DO
1180 brand = VRGet('LB_BRAND', 'Selected')
1181 IF brand == 0 THEN RETURN
1182 selected = VRGet('LB_SELECT', 'Selected')
1183 IF selected == 0 THEN RETURN
1184
1185 CALL VRSet 'WN_MAIN', 'StatusText', ''
1186
1187 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1188 IF which == '' THEN DO
1189 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1190 ppd = VRFileDialog( VRWindow(), 'Select PPD', 'O', '*.ppd')
1191 IF ppd == '' THEN RETURN
1192 globals.!prt_ppd = ppd
1193 globals.!prt_dev = ''
1194 globals.!prt_nick = GetNameFromPPD( ppd )
1195 END
1196 ELSE DO
1197 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1198 IF man == '' THEN DO
1199 /* TODO display an error? But this shouldn't be possible... */
1200 RETURN
1201 END
1202 ppd = manufacturers.man.!printers.which.!driver
1203 globals.!mode = 1 /* Mode 1: CUPS-included model */
1204 IF POS('exe://', ppd ) > 0 THEN DO
1205 globals.!prt_ppd = ''
1206 globals.!prt_dev = ppd
1207 sel_brand = VRGet('LB_BRAND', 'SelectedString')
1208 sel_name = sel_brand VRMethod('LB_SELECT', 'GetString', selected )
1209 PARSE VAR sel_name _nick ' - CUPS' .
1210 IF _nick == '' THEN
1211 globals.!prt_nick = STRIP( sel_name )
1212 ELSE
1213 globals.!prt_nick = STRIP( _nick )
1214 END
1215 ELSE DO
1216 globals.!prt_ppd = TRANSLATE( globals.!cupsdir'/share/cups/model/'ppd, '\', '/')
1217 globals.!prt_dev = ''
1218 globals.!prt_nick = GetNameFromPPD( ppd )
1219 END
1220 END
1221 globals.!remotecups = ''
1222
1223 CALL InitMessageLog
1224 IF globals.!mode == 2 THEN
1225 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1226 ELSE
1227 CALL LINEOUT globals.!log1, 'Starting printer install for built-in model:'
1228 IF globals.!prt_dev <> '' THEN
1229 CALL LINEOUT globals.!log1, ' - Device name:' globals.!prt_dev
1230 ELSE
1231 CALL LINEOUT globals.!log1, ' - PPD file: ' globals.!prt_ppd
1232 CALL LINEOUT globals.!log1, ' - Model name: ' globals.!prt_nick
1233 CALL LINEOUT globals.!log1, ''
1234
1235 CALL SetPage2
1236 END
1237
1238 WHEN globals.!page == 2 THEN DO
1239 selected = VRGet('LB_SELECT', 'Selected')
1240 IF selected == 0 THEN RETURN
1241 port = VRMethod('LB_SELECT', 'GetItemData', selected )
1242
1243 IF port == '' THEN DO
1244 /* Network printer selected; prompt for the connection details
1245 */
1246 CALL VRLoadSecondary 'SW_NETWORK', 'W'
1247 END
1248
1249 IF port == '' & globals.!remotecups == '' THEN RETURN
1250 globals.!prt_port = port
1251
1252 CALL SetPage3
1253 END
1254
1255 WHEN globals.!page == 3 THEN DO
1256 globals.!prt_name = STRIP( VRGet('EF_NAME', 'Value'))
1257 globals.!prt_loc = STRIP( VRGet('EF_LOCATION', 'Value'))
1258 globals.!prt_info = STRIP( VRGet('EF_DESC', 'Value'))
1259 IF ((( globals.!prt_name == '') |,
1260 ( globals.!prt_loc == '')) & ( globals.!remotecups == '')) |,
1261 ( globals.!prt_info == '') THEN
1262 DO
1263 IF ( globals.!remotecups <> '') THEN
1264 _errmsg = 'You must enter a description.'
1265 ELSE
1266 _errmsg = 'You must enter a name, a location, and a description.'
1267 CALL VRMessage VRWindow(), _errmsg, 'Missing Value(s)', 'E'
1268 RETURN
1269 END
1270 IF ( globals.!remotecups == '' &,
1271 ( POS( LEFT( globals.!prt_name, 1 ),,
1272 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') == 0 ) |,
1273 ( VERIFY( globals.!prt_name, '/# ' || '09'x, 'MATCH') <> 0 )) THEN
1274 DO
1275 CALL VRMessage VRWindow(), 'The printer name must start ' ||,
1276 'with a letter, and may not include "/", "#", ' ||,
1277 'space, or tab characters.', 'Invalid Name', 'E'
1278 RETURN
1279 END
1280
1281 /* TODO support other drivers
1282 */
1283 IF WORD( globals.!prt_nick, 1 ) == 'Apollo' |,
1284 WORD( globals.!prt_nick, 1 ) == 'HP' |,
1285 WORD( globals.!prt_nick, 1 ) == 'Hewlett-Packard' THEN
1286 globals.!os2driver = 'ECUPS-HP'
1287 ELSE
1288 globals.!os2driver = 'ECUPS'
1289
1290 CALL ConfirmAndCreate
1291 END
1292
1293 WHEN globals.!page == 4 THEN DO
1294 CALL VRSet 'PB_NEXT', 'Caption', 'Next >'
1295 CALL VRSet 'EF_NAME', 'Value', ''
1296 CALL VRSet 'EF_LOCATION', 'Value', ''
1297 CALL VRSet 'EF_DESC', 'Value', ''
1298 CALL SetPage1
1299 END
1300
1301 OTHERWISE NOP
1302 END
1303
1304RETURN
1305
1306/*:VRX PICT_ICON_Click
1307*/
1308PICT_ICON_Click: PROCEDURE EXPOSE globals.
1309 CALL VRLoadSecondary 'SW_ABOUT', 'W'
1310RETURN
1311
1312/*:VRX PromptForPMName
1313*/
1314PromptForPMName: PROCEDURE EXPOSE globals. models. best
1315 best = MatchPrinterModel( globals.!os2driver, globals.!prt_nick )
1316
1317 IF models.0 == 0 THEN DO
1318 /* No similar models were found in the list of supported printers.
1319 * Just use the generic PS driver.
1320 */
1321 CALL VRMessage VRWindow(),,
1322 'The printer "'globals.!prt_nick'" does not appear to' ,
1323 'be supported by the' globals.!os2driver 'driver, and' ,
1324 'no similar models were found. The generic PostScript',
1325 'driver will be used for application support.',,
1326 'Printer Name Not Found', 'E'
1327 globals.!prt_nick = 'Generic PostScript Printer'
1328 RETURN
1329 END
1330
1331 CALL VRLoadSecondary 'SW_MODEL', 'W'
1332
1333RETURN
1334
1335/*:VRX Quit
1336*/
1337Quit:
1338 window = VRWindow()
1339 call VRSet window, "Shutdown", 1
1340 drop window
1341return
1342
1343/*:VRX SetPage1
1344*/
1345SetPage1: PROCEDURE EXPOSE globals. manufacturers.
1346
1347 CALL VRSet 'LB_BRAND', 'Visible', 1
1348
1349 /* Resize LB_SELECT if necessary to make room for LB_BRAND */
1350 lb_x = VRGet('LB_BRAND', 'Left') + VRGet('LB_BRAND', 'Width') + 60
1351 lb_w = VRGet('GB_INFO', 'Width') - lb_x + VRGet('GB_INFO', 'Left')
1352 CALL VRSet 'LB_SELECT', 'Left', lb_x
1353 CALL VRSet 'LB_SELECT', 'Width', lb_w
1354
1355 CALL VRSet 'LB_SELECT', 'Visible', 1
1356 CALL VRSet 'GB_INFO', 'Visible', 0
1357
1358 globals.!page = 1
1359 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1360 CALL GetCupsPrinters
1361
1362 CALL VRSet 'DT_INFO', 'Caption', 'Select your printer model.'
1363
1364 /* Populate the manufacturer list */
1365 CALL VRSet 'LB_BRAND', 'Painting', 0
1366 DO i = 1 TO manufacturers.0
1367 addman.i = manufacturers.i.!name
1368 addidx.i = i
1369 END
1370 addman.0 = manufacturers.0
1371 addidx.0 = manufacturers.0
1372 CALL VRMethod 'LB_BRAND', 'AddStringList', 'addman.',, 'addidx.'
1373 CALL VRSet 'LB_BRAND', 'Painting', 1
1374
1375 CALL VRMethod 'LB_SELECT', 'SetFocus'
1376 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1377
1378RETURN
1379
1380/*:VRX SetPage2
1381*/
1382SetPage2: PROCEDURE EXPOSE globals.
1383
1384 globals.!page = 2
1385 CALL VRSet 'LB_BRAND', 'Visible', 0
1386 CALL VRSet 'WN_MAIN', 'StatusText', 'Selected printer: ' globals.!prt_nick
1387
1388 /* Resize LB_SELECT to the full width of GB_INFO */
1389 lb_x = VRGet('GB_INFO', 'Left')
1390 lb_w = VRGet('GB_INFO', 'Width')
1391 CALL VRSet 'LB_SELECT', 'Left', lb_x
1392 CALL VRSet 'LB_SELECT', 'Width', lb_w
1393
1394 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1395 CALL GetCupsPorts
1396 CALL VRMethod 'LB_SELECT', 'SetFocus'
1397 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1398
1399RETURN
1400
1401/*:VRX SetPage3
1402*/
1403SetPage3: PROCEDURE EXPOSE globals.
1404
1405 globals.!page = 3
1406 CALL VRSet 'EF_DESC', 'Value', globals.!prt_nick
1407
1408 CALL VRMethod 'LB_SELECT', 'Clear'
1409
1410 CALL VRSet 'LB_SELECT', 'Visible', 0
1411 CALL VRSet 'GB_INFO', 'Visible', 1
1412 IF globals.!remotecups == '' THEN DO
1413 CALL VRSet 'DT_INFO', 'Caption', 'Choose the printer name, and enter its location and a short description.'
1414 CALL VRSet 'DT_NAME', 'Visible', 1
1415 CALL VRSet 'EF_NAME', 'Visible', 1
1416 CALL VRSet 'DT_LOCATION', 'Visible', 1
1417 CALL VRSet 'EF_LOCATION', 'Visible', 1
1418 END
1419 ELSE
1420 CALL VRSet 'DT_INFO', 'Caption', 'Enter a short description of this printer. ',
1421 'This will be used for the printer object that appears on your desktop.'
1422 CALL VRSet 'DT_DESC', 'Visible', 1
1423 CALL VRSet 'EF_DESC', 'Visible', 1
1424
1425 CALL VRMethod 'EF_NAME', 'SetFocus'
1426
1427RETURN
1428
1429/*:VRX SetPage4
1430*/
1431SetPage4:
1432
1433 globals.!page = 4
1434 CALL VRSet 'LB_SELECT', 'Visible', 0
1435 CALL VRSet 'GB_INFO', 'Visible', 0
1436 CALL VRSet 'WN_MAIN', 'StatusText', ''
1437
1438RETURN
1439
1440/*:VRX SW_ABOUT_Close
1441*/
1442SW_ABOUT_Close:
1443 call SW_ABOUT_Fini
1444return
1445
1446/*:VRX SW_ABOUT_Create
1447*/
1448SW_ABOUT_Create:
1449 call SW_ABOUT_Init
1450return
1451
1452/*:VRX SW_ABOUT_Fini
1453*/
1454SW_ABOUT_Fini:
1455 window = VRInfo( "Window" )
1456 call VRDestroy window
1457 drop window
1458return
1459/*:VRX SW_ABOUT_Init
1460*/
1461SW_ABOUT_Init:
1462
1463 CALL VRSet 'DT_BOOTDRIVE', 'Caption', 'System boot volume:' TRANSLATE( globals.!bootdrv )
1464 CALL VRSet 'DT_CUPSPATH', 'Caption', 'Local CUPS directory:' TRANSLATE( globals.!cupsdir )
1465 CALL VRSet 'DT_REPOSITORY', 'Caption', 'Local driver repository:' TRANSLATE( globals.!repository )
1466
1467 window = VRInfo( "Object" )
1468 if( \VRIsChildOf( window, "Notebook" ) ) then do
1469 call VRMethod window, "CenterWindow"
1470 call VRSet window, "Visible", 1
1471 call VRMethod window, "Activate"
1472 end
1473 drop window
1474return
1475
1476/*:VRX SW_CREATE_Close
1477*/
1478SW_CREATE_Close:
1479 call SW_CREATE_Fini
1480return
1481
1482/*:VRX SW_CREATE_Create
1483*/
1484SW_CREATE_Create:
1485 call SW_CREATE_Init
1486return
1487
1488/*:VRX SW_CREATE_Fini
1489*/
1490SW_CREATE_Fini:
1491 window = VRInfo( "Window" )
1492 call VRDestroy window
1493 drop window
1494return
1495/*:VRX SW_CREATE_Init
1496*/
1497SW_CREATE_Init:
1498
1499 CALL VRSet 'EF_CRMODEL', 'Value', globals.!prt_nick
1500
1501 IF globals.!remotecups <> '' THEN DO
1502 /* An existing CUPS printer was indicated. This means we're not
1503 * creating a CUPS printer, but only a PM printer object (and port)
1504 * that points to it.
1505 */
1506 CALL VRSet 'DT_CREATE', 'Caption', 'Ready to create printer object with the following parameters.'
1507
1508 PARSE VAR globals.!remotecups cups_host cups_printer .
1509 CALL VRSet 'DT_CRNAME', 'Caption', 'CUPS server:'
1510 CALL VRSet 'EF_CRNAME', 'Value', cups_host
1511 CALL VRSet 'DT_CRURI', 'Caption', 'CUPS queue:'
1512 CALL VRSet 'EF_CRURI', 'Value', cups_printer
1513 CALL VRSet 'DT_CRLOC', 'Visible', 0
1514 CALL VRSet 'EF_CRLOC', 'Visible', 0
1515 CALL VRSet 'CHK_CREATEPM', 'Visible', 0
1516 END
1517 ELSE DO
1518 CALL VRSet 'EF_CRNAME', 'Value', globals.!prt_name
1519 CALL VRSet 'EF_CRURI', 'Value', globals.!prt_port
1520 CALL VRSet 'EF_CRLOC', 'Value', globals.!prt_loc
1521 END
1522 CALL VRSet 'EF_CRDESC', 'Value', globals.!prt_info
1523
1524 IF QueryAvailableDrivers() > 0 THEN DO
1525 def_idx = 1
1526 CALL VRMethod 'DDCB_PRESDRV', 'AddStringList', 'drv_list.'
1527 DO i = 1 TO drv_list.0
1528 IF drv_list.i == globals.!os2driver THEN DO
1529 def_idx = i
1530 LEAVE
1531 END
1532 END
1533 CALL VRSet 'DDCB_PRESDRV', 'Selected', def_idx
1534 END
1535 /* TODO give an error if no drivers were found */
1536
1537 window = VRInfo( "Object" )
1538 if( \VRIsChildOf( window, "Notebook" ) ) then do
1539 call VRMethod window, "CenterWindow"
1540 call VRSet window, "Visible", 1
1541 call VRMethod window, "Activate"
1542 end
1543 drop window
1544
1545RETURN
1546
1547/*:VRX SW_MODEL_Close
1548*/
1549SW_MODEL_Close:
1550 call SW_MODEL_Fini
1551return
1552
1553/*:VRX SW_MODEL_Create
1554*/
1555SW_MODEL_Create:
1556 call SW_MODEL_Init
1557return
1558
1559/*:VRX SW_MODEL_Fini
1560*/
1561SW_MODEL_Fini:
1562
1563 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1564
1565 window = VRInfo( "Window" )
1566 call VRDestroy window
1567 drop window
1568return
1569/*:VRX SW_MODEL_Init
1570*/
1571SW_MODEL_Init:
1572
1573 /* We should have a list of suggested printer models whose names at least
1574 * partially match the requested model, sorted in order with the closest
1575 * match at the top.
1576 */
1577 ok = VRMethod( "LB_OS2MODELS", "AddStringList", "models.", )
1578 IF best > 0 THEN
1579 CALL VRSet 'LP_OS2MODELS', 'Selected', best
1580
1581 CALL VRSet 'DT_MODEL1', 'Caption',,
1582 'The printer "'globals.!prt_nick'" could not be found in the' ,
1583 globals.!os2driver'.DRV driver under that name. Please choose',
1584 'the model of printer which will be reported to applications.'
1585
1586 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1587
1588 window = VRInfo( "Object" )
1589 if( \VRIsChildOf( window, "Notebook" ) ) then do
1590 call VRMethod window, "CenterWindow"
1591 call VRSet window, "Visible", 1
1592 call VRMethod window, "Activate"
1593 end
1594 drop window
1595
1596RETURN
1597
1598/*:VRX SW_NETWORK_Close
1599*/
1600SW_NETWORK_Close:
1601 call SW_NETWORK_Fini
1602return
1603
1604/*:VRX SW_NETWORK_Create
1605*/
1606SW_NETWORK_Create:
1607 call SW_NETWORK_Init
1608return
1609
1610/*:VRX SW_NETWORK_Fini
1611*/
1612SW_NETWORK_Fini:
1613 window = VRInfo( "Window" )
1614 call VRDestroy window
1615 drop window
1616return
1617/*:VRX SW_NETWORK_Init
1618*/
1619SW_NETWORK_Init:
1620
1621 CALL VRSet 'DDCB_PROTOCOL', 'Selected', 1
1622
1623 window = VRInfo( "Object" )
1624 if( \VRIsChildOf( window, "Notebook" ) ) then do
1625 call VRMethod window, "CenterWindow"
1626 call VRSet window, "Visible", 1
1627 call VRMethod window, "Activate"
1628 end
1629 drop window
1630return
1631
1632/*:VRX WN_MAIN_Close
1633*/
1634WN_MAIN_Close:
1635 call Quit
1636return
1637
Note: See TracBrowser for help on using the repository browser.