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

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

Try to fix occasional problems creating local printer object - no longer relying on RINSTPRN to install the printer driver.
Add support for systems without a local CUPS installation (requires providing a PPD).

File size: 59.7 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 CHK_CREATEPM_Click
104*/
105CHK_CREATEPM_Click: PROCEDURE
106 set = VRGet( "CHK_CREATEPM", "Set" )
107 CALL VRSet 'DT_PRESDRV', 'Enabled', set
108 CALL VRSet 'DDCB_PRESDRV', 'Enabled', set
109RETURN
110
111/*:VRX ConfirmAndCreate
112*/
113ConfirmAndCreate: PROCEDURE EXPOSE globals.
114
115 globals.!create = 0
116 CALL VRLoadSecondary 'SW_CREATE', 'W'
117 IF globals.!create <> 1 THEN RETURN
118
119 CALL SetPage4
120 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
121 CALL VRSet 'DT_INFO', 'Caption', 'Creating printer...'
122 ok = CreatePrinter( globals.!os2printer )
123 CALL VRSet 'DT_INFO', 'Caption', ''
124 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
125
126 IF ok <> 0 THEN DO
127 SELECT
128 WHEN ok == 1 THEN reason = 'Error importing PPD file.'
129 WHEN ok == 2 THEN reason = 'Error creating CUPS printer. See' globals.!log1 'for more information.'
130 WHEN ok == 3 THEN reason = 'Error creating printer object. See' globals.!log1 'for more information.'
131 OTHERWISE reason = 'Unknown error.'
132 END
133 CALL VRMessage VRWindow(), 'The following error occurred when trying to create the printer:' ||,
134 '0d0a0d0a'x || reason, 'Error Creating Printer', 'E'
135 CALL VRSet 'DT_INFO', 'Caption', 'The printer could not be created.'
136 CALL VRSet 'PB_NEXT', 'Caption', 'Return'
137 END
138 ELSE DO
139 CALL VRSet 'DT_INFO', 'Caption', 'The printer has been created.'
140 CALL VRSet 'PB_NEXT', 'Caption', 'Create another'
141 END
142 CALL VRSet 'PB_CANCEL', 'Caption', 'Close'
143
144 CALL LINEOUT globals.!log1, ''
145 CALL LINEOUT globals.!log1
146
147RETURN
148
149/*:VRX CreateCupsPrinter
150*/
151CreateCupsPrinter: PROCEDURE EXPOSE globals.
152
153 od = DIRECTORY()
154 CALL DIRECTORY globals.!cupsdir'\sbin'
155 cups_cmd = 'lpadmin -p' globals.!prt_name '-E'
156 IF globals.!prt_info <> '' THEN
157 cups_cmd = cups_cmd '-D "'globals.!prt_info'"'
158 IF globals.!prt_loc <> '' THEN
159 cups_cmd = cups_cmd '-L "'globals.!prt_loc'"'
160 IF globals.!prt_dev <> '' THEN
161 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m' globals.!prt_dev
162 ELSE IF globals.!mode == 2 THEN
163 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -P "'globals.!prt_ppd'"'
164 ELSE DO
165 PARSE VAR globals.!prt_ppd (globals.!cupsdir)'\share\cups\model\' model
166 IF model == '' THEN model = globals.!prt_ppd
167 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m "'model'"'
168 END
169
170 CALL LINEOUT globals.!log1, 'Creating CUPS printer using:'
171 CALL LINEOUT globals.!log1, ' ' cups_cmd
172 IF VRFileExists( globals.!log2 ) THEN DO
173 CALL LINEOUT globals.!log2, ''
174 CALL LINEOUT globals.!log2
175 END
176 ADDRESS CMD '@' cups_cmd '1>NUL 2>>' globals.!log2
177 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
178 IF rc <> 0 THEN
179 CALL LINEOUT globals.!log1, 'See' globals.!log2 'for details.'
180 CALL DIRECTORY od
181 CALL LINEOUT globals.!log1, ''
182
183RETURN rc
184
185/*:VRX CreateOS2Printer
186*/
187/* Creates an OS/2 printer port, queue, and desktop object which point to
188 * the just-created CUPS printer. Uses the RINSTPRN utility from IBM.
189 */
190CreateOS2Printer: PROCEDURE EXPOSE globals.
191 ARG prnt_drv
192
193 IF globals.!remotecups == '' THEN DO
194 host = LoopbackName()
195 printer = globals.!prt_name
196 END
197 ELSE
198 PARSE VAR globals.!remotecups host printer .
199
200 printer_title = globals.!prt_info
201 printer_model = globals.!prt_nick
202 queue_name = GetQueueName( printer_title )
203 port_name = GetNextPortName('CUPS')
204 use_drv = globals.!prdrv
205
206 /* Determine the source directories/files to pass to RINSTPRN.EXE. (Some
207 * of this logic is repeated from ImportPPD, but we have to do it again
208 * here because (a) we might not have gone through ImportPPD to get to this
209 * point, and (b) even if we did, the repository information might have
210 * changed.)
211 */
212 copied_driver = 0
213 driver_path = GetDriverSource( prnt_drv )
214
215 IF ( pmdx <> '') & ( globals.!prdrv <> '') & ( globals.!prdesc <> '') THEN DO
216 /* Printer driver is in the local repository, so we can just point
217 * to that, and use the system PRDESC.LST file.
218 */
219 use_desc = globals.!prdesc
220 use_src = globals.!repository
221 END
222 ELSE IF driver_path <> '' THEN DO
223 /* Driver is not in the repository, but was found in another designated
224 * location. Point to that location, and create a temporary PRDESC.LST
225 * file for it.
226 */
227 use_src = VRParseFilePath( driver_path, 'DP')
228 use_desc = use_src'\PRDESC.LST'
229 CALL CreateDriverList driver_path, use_desc
230 END
231 ELSE DO
232 /* Driver is not in the repository. Try to grab the installed files
233 * from under \OS2\DLL, copy them into a temporary working directory,
234 * and create a temporary PRDESC.LST file.
235 */
236 driver_path = globals.!os2dir'\DLL\'prnt_drv'\'prnt_drv'.DRV'
237
238 use_src = SysTempFileName( globals.!tmpdir'\PDR_????')
239 use_desc = use_src'\PRDESC.LST'
240
241 IF VRMkDir( use_src ) == 0 THEN DO
242 CALL LINEOUT globals.!log1, 'Failed to create working directory' use_src':' VRError()
243 RETURN 1
244 END
245 IF CopyDriverToSource( driver_path, use_src ) == 0 THEN DO
246 CALL LINEOUT globals.!log1, 'Failed to copy driver' driver_path 'to working directory' use_src'.'
247 RETURN 1
248 END
249 CALL CreateDriverList driver_path, use_desc
250 copied_driver = 1
251 END
252
253 /* Create a new CUPS port. */
254 /* TODO currently this assumes that CUPS.PDR is already installed. */
255 port_ok = AddPort_CUPS( port_name, host, printer )
256 IF port_ok > 1 THEN
257 RETURN 1
258
259 rsp_file = globals.!tmpdir'\printer.rsp'
260 CALL RSPCreatePrinter rsp_file, prnt_drv, printer_model,,
261 port_name, queue_name, printer_title
262
263 /* Install the printer driver. (We do this manually because doing it
264 * through RINSTPRN seems not to work properly on some systems.)
265 */
266 result = InstallPrintDriver( prnt_drv, driver_path, printer_model )
267 IF result == 0 THEN CALL RSPInstallDriver rsp_file, prnt_drv, printer_model
268
269 /* Now call RINSTPRN to create the printer queue/device and object.
270 */
271 result = ExecRINSTPRN( use_desc, use_drv, use_src, rsp_file )
272 IF result <> 0 THEN
273 CALL DeletePort port_name
274 ELSE IF port_ok == 1 THEN DO
275 CALL VRMessage VRWindow(),
276 'The installed version of CUPS.PDR appears to be out of ',
277 'date. As a result, the desktop printer will not be ',
278 'usable until the desktop is restarted.',,
279 'Port Driver Problem', 'W'
280 END
281
282 IF copied_driver == 1 THEN DO
283 CALL VRDeleteFile use_src'\*'
284 CALL VRRmDir use_src
285 END
286
287RETURN result
288
289/*:VRX CreatePrinter
290*/
291CreatePrinter: PROCEDURE EXPOSE globals.
292 ARG create_os2
293
294 /* Create the CUPS printer */
295 IF globals.!remotecups == '' THEN DO
296 ok = CreateCupsPrinter()
297 IF ok <> 0 THEN
298 RETURN 2 /** RC=2 Error running lpadmin **/
299 END
300
301 /* Now create the OS/2 printer object */
302 IF create_os2 == 1 THEN DO
303
304 /* Make sure the presentation driver supports the printer */
305 IF globals.!mode == 2 THEN DO
306 /* Always (re)import when a PPD is provided by the user
307 */
308 ok = ImportPPD( globals.!os2driver, globals.!prt_ppd )
309 IF ok <> 0 THEN DO
310 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
311 RETURN 1 /** RC=1 PPD import failed **/
312 END
313 END
314 ELSE IF PrinterExistsInDRV( globals.!os2driver, globals.!prt_nick ) == 0 THEN DO
315 IF globals.!prt_ppd == '' THEN
316 CALL PromptForPMName
317 ELSE DO
318 ok = ImportPPD(globals.!os2driver, globals.!prt_ppd )
319 IF ok <> 0 THEN DO
320 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
321 RETURN 1 /** RC=1 PPD import failed **/
322 END
323 END
324 END
325
326 ok = CreateOS2Printer( globals.!os2driver )
327 IF ok <> 0 THEN
328 RETURN 3 /** RC=3 Error running rinstprn **/
329 END
330
331RETURN 0
332
333/*:VRX DDCB_PROTOCOL_Change
334*/
335DDCB_PROTOCOL_Change: PROCEDURE
336
337 idx = VRGet('DDCB_PROTOCOL', 'Selected')
338 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
339 SELECT
340 WHEN which == 1 THEN DO /* IPP */
341 show_queue = 1
342 show_user = 1
343 show_pass = 1
344 CALL VRSet 'DT_SERVER', 'Caption', 'Printer or server address:'
345 CALL VRSet 'DT_QUEUE', 'Caption', 'Printer queue name:'
346 CALL VRSet 'DT_USERID', 'Caption', 'User ID:'
347 END
348 WHEN which == 2 THEN DO /* SOCKET */
349 show_queue = 0
350 show_user = 0
351 show_pass = 0
352 CALL VRSet 'DT_SERVER', 'Caption', 'Printer or server address:'
353 END
354 WHEN which == 3 THEN DO /* LPD */
355 show_queue = 1
356 show_user = 1
357 show_pass = 0
358 CALL VRSet 'DT_SERVER', 'Caption', 'Printer or server address:'
359 CALL VRSet 'DT_QUEUE', 'Caption', 'Printer queue name:'
360 CALL VRSet 'DT_USERID', 'Caption', 'User ID (if required):'
361 END
362 WHEN which == 4 THEN DO /* SMB */
363 show_queue = 1
364 show_user = 1
365 show_pass = 1
366 CALL VRSet 'DT_SERVER', 'Caption', 'Print server name:'
367 CALL VRSet 'DT_QUEUE', 'Caption', 'Shared printer name:'
368 CALL VRSet 'DT_USERID', 'Caption', 'User ID:'
369 END
370 OTHERWISE DO /* CUPS */
371 show_queue = 1
372 show_user = 0
373 show_pass = 0
374 CALL VRSet 'DT_SERVER', 'Caption', 'CUPS server name:'
375 CALL VRSet 'DT_QUEUE', 'Caption', 'CUPS printer name:'
376 END
377 END
378
379 CALL VRSet 'DT_QUEUE', 'Visible', show_queue
380 CALL VRSet 'EF_QUEUE', 'Visible', show_queue
381 CALL VRSet 'DT_USERID', 'Visible', show_user
382 CALL VRSet 'EF_USERID', 'Visible', show_user
383 CALL VRSet 'DT_PASSWORD', 'Visible', show_pass
384 CALL VRSet 'EF_PASSWORD', 'Visible', show_pass
385
386RETURN
387
388/*:VRX ExecRINSTPRN
389*/
390ExecRINSTPRN: PROCEDURE EXPOSE globals.
391 PARSE ARG dsc, drv, src, rsp
392
393 od = DIRECTORY()
394 CALL DIRECTORY src
395 rinstprn_cmd = 'rinstprn /DSC:'dsc '/DRV:'drv' /S:'src ,
396 '/T:'globals.!bootdrv '/L1:'globals.!logdir'\rinstprn.log' ,
397 '/R:'rsp
398
399 CALL LINEOUT globals.!log1, 'Creating OS/2 printer using:'
400 CALL LINEOUT globals.!log1, ' ' rinstprn_cmd
401 ADDRESS CMD '@' rinstprn_cmd '1>NUL 2>NUL'
402 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
403 IF rc <> 0 THEN
404 CALL LINEOUT globals.!log1, 'See' globals.!logdir'\rinstprn.log for details.'
405 CALL DIRECTORY od
406 CALL LINEOUT globals.!log1, ''
407
408RETURN rc
409
410/*:VRX Fini
411*/
412Fini:
413 window = VRWindow()
414 call VRSet window, "Visible", 0
415 drop window
416return 0
417
418/*:VRX GetCupsPorts
419*/
420GetCupsPorts: PROCEDURE EXPOSE globals.
421
422 CALL VRSet 'DT_INFO', 'Caption', 'Looking for connected printers. Please wait...'
423
424 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe -v |rxqueue'
425 snmp_cmd = globals.!cupsdir'\lib\cups\backend\snmp.exe |rxqueue'
426
427 _od = DIRECTORY()
428 CALL DIRECTORY globals.!cupsdir
429 listqueue = RXQUEUE('CREATE')
430 defqueue = RXQUEUE('SET', listqueue )
431
432 /* Use the SNMP backend to find network printers. We do this in addition
433 * to lpinfo because SNMP may provide the actual printer name. We'll
434 * merge this with the output of lpinfo in the next step.
435 */
436 ADDRESS CMD '@' snmp_cmd listqueue
437 DO QUEUED()
438 PARSE PULL line
439 PARSE VAR line _type _uri '"'_identifier'"' .
440 _uri = STRIP( _uri )
441 _type = STRIP( _type )
442 IF _uri == '' THEN ITERATE
443 IF _type <> 'network' THEN ITERATE
444 netnames._uri = _identifier
445 END
446
447 ADDRESS CMD '@' lpinfo_cmd listqueue
448 i = 0
449 DO QUEUED()
450 PARSE PULL line
451 PARSE VAR line _type _name
452 IF _name == '' THEN ITERATE
453 IF _type == 'network' & POS('://', _name ) > 0 THEN DO
454 PARSE VAR _name _protocol '://' _host '/' _queue
455 IF _protocol == 'socket' THEN _protocol = 'AppSocket'
456 ELSE _protocol = TRANSLATE( _protocol )
457 i = i + 1
458 IF _queue <> '' THEN _queue = '(queue '_queue')'
459 IF SYMBOL('netnames._name') == 'VAR' THEN
460 devices.i = 'Detected network printer ('_protocol') "'netnames._name'" at' _host _queue
461 ELSE
462 devices.i = 'Detected network printer ('_protocol') at' _host _queue
463 END
464 ELSE IF _type <> 'direct' THEN ITERATE
465 ELSE DO
466 IF _name == 'hp' THEN ITERATE
467 i = i + 1
468 devices.i = 'Local printer:' _name
469 END
470 ports.i = _name
471 END
472 devices.0 = i
473
474 CALL RXQUEUE 'SET', defqueue
475 CALL RXQUEUE 'DELETE', listqueue
476 CALL DIRECTORY _od
477
478 CALL VRSet 'LB_SELECT', 'Painting', 0
479 CALL VRMethod 'LB_SELECT', 'AddStringList', 'devices.',, 'ports.'
480 CALL VRMethod 'LB_SELECT', 'AddString', 'Network printer (manual configuration)',, ''
481 CALL VRSet 'LB_SELECT', 'Selected', 1
482 CALL VRSet 'LB_SELECT', 'Painting', 1
483
484 CALL VRSet 'DT_INFO', 'Caption', 'Select the connection for this printer.'
485
486RETURN
487
488/*:VRX GetCupsPrinters
489*/
490GetCupsPrinters: PROCEDURE EXPOSE globals. manufacturers.
491
492 CALL VRSet 'DT_INFO', 'Caption', 'Getting list of supported printers. Please wait...'
493
494 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe --exclude-schemes drv -m 2>&1 |rxqueue'
495
496 _od = DIRECTORY()
497 CALL DIRECTORY globals.!cupsdir
498 listqueue = RXQUEUE('CREATE')
499 defqueue = RXQUEUE('SET', listqueue )
500
501 ADDRESS CMD '@' lpinfo_cmd listqueue
502 i = 0
503 makers = ''
504 DO QUEUED()
505 PARSE PULL line
506 IF LEFT( line, 6 ) == 'drv://' THEN ITERATE
507 IF WORD( line, 1 ) == 'raw' THEN ITERATE
508 PARSE VAR line _ppd '.ppd.gz ' _name
509 _ppd = _ppd'.ppd.gz'
510 IF _name == '' THEN DO
511 PARSE VAR line _ppd '.ppd ' _name
512 _ppd = _ppd'.ppd'
513 END
514 IF _name == '' THEN DO
515 PARSE VAR line _ppd _name
516 END
517 IF _name <> '' THEN DO
518 PARSE VAR _name _brand _model
519 IF WORDPOS( _brand, makers ) == 0 THEN makers = makers || _brand' '
520 i = i + 1
521 ppds.i = _ppd
522 models.i = _name
523 END
524 END
525 ppds.0 = i
526 models.0 = i
527
528 CALL RXQUEUE 'SET', defqueue
529 CALL RXQUEUE 'DELETE', listqueue
530 CALL DIRECTORY _od
531
532/* Now build the 'manufacturers' stem.
533 * This stem takes the following format:
534 * manufacturers.0 number of manufacturers
535 * manufacturers.i.!name manufacturer name (e.g. 'Apple')
536 * manufacturers.i.!printers.0 number of printer models
537 * manufacturers.i.!printers.j.!model printer model name, short form (e.g. 'LaserWriter 330')
538 * manufacturers.i.!printers.j.!type driver version/type (e.g. 'Gutenprint v5.2.7')
539 * manufacturers.i.!printers.j.!driver the internal CUPS printer driver name (PPD or URI)
540 * - by preference this is the "simplified" version if available
541 * manufacturers.i.!printers.j.!remark any distinguishing remarks (e.g. 'Simplified')
542 * manufacturers.i.!printers.j.!driver2 alternate driver in case there is more than one (PPD or URI)
543 * - if defined this is usually the non-"simplified" driver
544 * manufacturers.i.!printers.j.!remark2 any distinguishing remarks for the alternate driver
545 */
546
547 manufacturers.0 = WORDS( makers )
548 DO i = 1 TO manufacturers.0
549 manufacturers.i.!name = WORD( makers, i )
550 manufacturers.i.!printers.0 = 0
551 END
552
553 DO i = 1 TO models.0
554 PARSE VAR models.i _brand _model ' - CUPS+' _type
555 IF _type == '' THEN DO
556 PARSE VAR models.i _brand _model ',' _type
557 IF WORD( _type, 1 ) == 'hpcups' THEN
558 _type = 'HPLIP' /* SUBWORD( _type, 2 ) */
559 ELSE IF ( _type == '') & ( LEFT( ppds.i, 3 ) == 'hp/') THEN
560 _type = 'HPLIP'
561 END
562 man = WORDPOS( _brand, makers )
563 IF man == 0 THEN ITERATE
564
565 PARSE VAR _type _version 'Simplified' .
566 _version = STRIP( _version )
567 _flag = RIGHT( _type, 10 )
568
569 count = manufacturers.man.!printers.0
570 IF count > 0 THEN DO
571 /* If there are two or more printers defined with the same model
572 * name and driver version, keep the first and last as the regular
573 * and alternate drivers; if one if them is 'Simplified', make that
574 * the regular driver by preference.
575 */
576 IF ( TRANSLATE( manufacturers.man.!printers.count.!model ) == TRANSLATE( _model )) THEN DO
577 IF ( manufacturers.man.!printers.count.!type == _version ) THEN DO
578 IF ( WORD( _version, 1 ) == 'Gutenprint') & ( _flag == 'Simplified') THEN DO
579 manufacturers.man.!printers.count.!driver2 = manufacturers.man.!printers.count.!driver
580 manufacturers.man.!printers.count.!remark2 = manufacturers.man.!printers.count.!remark
581 manufacturers.man.!printers.count.!driver = ppds.i
582 manufacturers.man.!printers.count.!remark = 'Simplified'
583 END
584 ELSE DO
585 manufacturers.man.!printers.count.!driver2 = ppds.i
586 IF _flag == 'Simplified' THEN
587 manufacturers.man.!printers.count.!remark2 = 'Simplified'
588 ELSE
589 manufacturers.man.!printers.count.!remark2 = ''
590 END
591 ITERATE
592 END
593 END
594 END
595 count = count + 1
596 manufacturers.man.!printers.count.!model = _model
597 manufacturers.man.!printers.count.!type = _version
598 manufacturers.man.!printers.count.!driver = ppds.i
599 IF _flag == 'Simplified' THEN
600 manufacturers.man.!printers.count.!remark = 'Simplified'
601 ELSE
602 manufacturers.man.!printers.count.!remark = ''
603 manufacturers.man.!printers.count.!driver2 = ''
604 manufacturers.man.!printers.count.!remark2 = ''
605 manufacturers.man.!printers.0 = count
606 END
607
608 /* Add one more category for special items ...
609 */
610 count = manufacturers.0 + 1
611 manufacturers.count.!name = '-- Custom --'
612 manufacturers.count.!printers.0 = 1
613 manufacturers.count.!printers.1.!model = '-- Other printer (requires PPD) --'
614 manufacturers.count.!printers.1.!driver = ''
615 manufacturers.count.!printers.1.!type = ''
616 manufacturers.count.!printers.1.!remark = '-- Other printer (requires PPD) --'
617 manufacturers.count.!printers.1.!driver2 = ''
618 manufacturers.count.!printers.1.!remark2 = ''
619 manufacturers.0 = count
620
621RETURN
622
623/*:VRX Halt
624*/
625Halt:
626 signal _VREHalt
627return
628
629/*:VRX ImportPPD
630*/
631ImportPPD: PROCEDURE EXPOSE globals.
632 /* Import a new PPD file into a PostScript driver.
633 */
634 ARG driver, ppdfile
635 IF driver == '' THEN driver = 'PSCRIPT'
636
637 CALL LINEOUT globals.!log1, 'Going to import PPD file into driver' driver'.'
638
639 /***
640 *** First, get our working directories and locate the driver source files.
641 ***/
642
643 mustcopy = 0
644 driver_path = GetDriverSource( driver )
645 IF driver_path == '' THEN DO
646 /* No source found. We'll have to try copying the actual installed
647 * driver files from under \OS2\DLL.
648 */
649 CALL LINEOUT globals.!log1, 'Driver source not found.'
650 driver_path = STREAM( globals.!os2dir'\DLL\'driver'\'driver'.DRV', 'C', 'QUERY EXISTS')
651 mustcopy = 1
652 END
653 IF driver_path <> '' THEN DO
654 srcdir = VRParseFilePath( driver_path, 'DP')
655 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
656 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
657 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
658 DROP srcdir
659 END
660
661 /* Driver (or one of its required files) was not found.
662 */
663 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
664 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
665 DO
666 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
667 /* TODO should prompt for installable driver package? */
668 RETURN 1 /** RC=1 Missing required driver files **/
669 END
670
671 IF mustcopy <> 0 THEN DO
672 /* Looks like the driver wasn't shipped with the OS; we have a source
673 * (either the active files from \OS2\DLL, or a package provided by
674 * the user), but we need somewhere for them to live. The user needs
675 * to tell us where, because they're going to have to specify the
676 * directory later on if they install the driver from PM.
677 */
678 pbtn.1 = 'OK'
679 pbtn.2 = 'Cancel'
680 pbtn.0 = 2
681 ptext = 'The install files for the' driver 'driver could not be ' ||,
682 'located. These files will be recreated from the driver ' ||,
683 'files which are already installed on your system.' ||,
684 '0d0a0d0a'x || 'Please enter the directory where the ' ||,
685 'install files will be placed.'
686 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
687 IF drvr_dir == '' THEN
688 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
689 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
690 'Enter Directory', 'pbtn.', 1, 2 )
691 IF ok <> 1 THEN RETURN 9 /** RC=9 User cancelled **/
692 drvr_dir = VRExpandFileName( drvr_dir )
693 DO WHILE drvr_dir == ''
694 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
695 'Enter Directory', 'pbtn.', 1, 2 )
696 drvr_dir = VRExpandFileName( drvr_dir )
697 END
698
699 /* Now create the new directory, if necessary */
700 IF VRMkDir( drvr_dir ) == 0 THEN
701 RETURN 3 /** RC=3 Failed to copy driver files **/
702 IF CopyDriverToSource( driver_path, drvr_dir ) == 0 THEN
703 RETURN 3 /** RC=3 Failed to copy driver files **/
704
705 /* Make sure we save the location (we'll need this information later) */
706 CALL VRSetIni 'PM_INSTALL', driver'_DIR', drvr_dir||'00'x, 'USER'
707
708 /* Now point to the new copy as the driver we will work on */
709 driver_path = drvr_dir'\'driver'.DRV'
710 END
711
712 workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
713 ok = VrMkDir( workdir )
714 IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
715 IF ok <> 1 THEN
716 RETURN 2 /** RC=2 Failed to create temporary directory **/
717
718 SELECT
719 WHEN driver == 'ECUPS' THEN ppddir = globals.!repository'\PPD_E'
720 WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
721 WHEN driver == 'PSPRINT' THEN ppddir = globals.!repository'\PPD_PS'
722 WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
723 WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
724 OTHERWISE ppddir = globals.!repository'\PPD'
725 END
726
727 /* Make sure ppddir (for keeping PPD files) exists */
728 CALL SysFileTree ppddir, 'dirs.', 'DO'
729 IF dirs.0 == 0 THEN DO
730 ok = VrMkDir( ppddir )
731 IF ok <> 1 THEN
732 RETURN 4 /** RC=4 Failed to create PPD directory **/
733 END
734
735 /***
736 *** Now do the actual work.
737 ***/
738
739 /* Back up the modified files (AUXPRINT.PAK and <driver>.DRV) if we're
740 * working out of the repository.
741 IF mustcopy == 0 THEN DO
742 repfiles.0 = 2
743 repfiles.1 = driver'.DRV'
744 repfiles.2 = 'AUXPRINT.PAK'
745 CALL BackupDrivers driver_path
746 END
747 */
748
749 /* Copy the needed driver files to our working directories.
750 */
751 drv_out = workdir'\OUT\'driver'.DRV'
752 pin_exe = workdir'\PIN.EXE'
753 ppd_exe = workdir'\PPDENC.EXE'
754 ok = VRCopyFile( driver_path, drv_out )
755 IF ok == 1 THEN ok = VRCopyFile( pin, pin_exe )
756 IF ok == 1 THEN ok = VRCopyFile( ppdenc, ppd_exe )
757 IF ok == 0 THEN DO
758 RETURN 3 /*** RC=3 Failed to copy driver files ***/
759 END
760
761 /* Set up the output redirection.
762 */
763 nq = RXQUEUE('CREATE')
764 oq = RXQUEUE('SET', nq )
765
766 /* If the PPD file is compressed, uncompress it.
767 */
768 IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
769 decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
770 CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
771 ADDRESS CMD '@gzip -c -d' ppdfile '| RXQUEUE' nq
772 DO QUEUED()
773 PARSE PULL line
774 CALL LINEOUT decppd, line
775 END
776 CALL LINEOUT decppd
777 ppdfile = decppd
778 END
779
780 IF VRFileExists( ppdfile ) == 0 THEN DO
781 CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
782 RETURN 5 /** RC=5 PPD import failed **/
783 END
784
785 ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
786
787 /* Now we have to clean up and validate the PPD file so PIN can use it.
788 * First, PPDENC converts the codepage if necessary, and copies the results
789 * to our working directory.
790 */
791 ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>&1 | RXQUEUE' nq
792 DO QUEUED()
793 PULL output
794 CALL LINEOUT globals.!log2, output
795 END
796 CALL LINEOUT globals.!log2, ''
797 CALL LINEOUT globals.!log2
798
799 /* Next we strip out some problematic lines used which are often encountered
800 * in (e.g.) CUPS-based PPD files.
801 */
802 CALL CleanPPD ppd_use, globals.!log1
803
804 /* Preparation complete. Now do the import.
805 */
806 count = 0
807 ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>&1 | RXQUEUE' nq
808 DO QUEUED()
809 PARSE PULL output
810 CALL LINEOUT globals.!log2, output
811 PARSE VAR output . 'OK (' nickname
812 IF nickname <> '' THEN DO
813 count = count + 1
814 newprinters.count = STRIP( nickname, 'T', ')')
815 END
816 END
817 newprinters.0 = count
818 CALL LINEOUT globals.!log2, ''
819 CALL LINEOUT globals.!log2
820
821 /* End the output redirection.
822 */
823 CALL RXQUEUE 'SET', oq
824 CALL RXQUEUE 'DELETE', nq
825
826
827 /***
828 *** Post-import processing.
829 ***/
830
831 IF newprinters.0 == 0 THEN DO
832 RETURN 5 /** RC=5 PPD import failed **/
833 END
834
835 /*IF mustcopy == 0 THEN DO*/
836 IF pmdx <> '' THEN DO
837 /* If we're working out of the repository, we need to update the
838 * driver table in PRDESC.LST to add the new driver(s).
839 */
840
841 CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with' newprinters.0 'new entries ...'
842 count = 0
843 match_drv = '('driver'.DRV)'
844 match_len = LENGTH( match_drv )
845
846 /* First, copy all lines that don't refer to the driver just updated */
847 DO WHILE LINES( globals.!prdesc )
848 _line = LINEIN( globals.!prdesc )
849 IF TRANSLATE( RIGHT( _line, LENGTH( match_len ))) == match_drv THEN ITERATE
850 count = count + 1
851 defs.count = _line
852 END
853 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
854
855 /* Next, create a new list for the updated driver and merge that in */
856 newlist = workdir'\'driver'.LST'
857 CALL CreateDriverList driver, newlist
858 DO WHILE LINES( newlist )
859 _line = LINEIN( newlist )
860 count = count + 1
861 defs.count = _line
862 END
863 defs.0 = count
864
865 /* Now sort the list and recreate PRDESC.LST */
866 CALL SysStemSort 'defs.',, 'I'
867 prdesc_tmp = workdir'\PRDESC.LST'
868 IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
869 CALL VRDeleteFile prdesc_tmp
870 DO i = 1 TO defs.0
871 CALL LINEOUT prdesc_tmp, defs.i
872 END
873 CALL LINEOUT prdesc_tmp
874 ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
875 IF ok == 0 THEN DO
876 RETURN 6 /** RC=6 Error updating PRDESC.LST **/
877 END
878 CALL VRDeleteFile prdesc_tmp
879
880 END
881
882 /* Finally, copy the updated driver files.
883 */
884 target = VRParseFilePath( driver_path, 'DP')
885 ok = VRCopyFile( workdir'\OUT\*', target )
886 IF ok == 1 THEN DO
887 /* Copy the updated files to \OS2\DLL\<driver>, replacing any
888 * existing copies. (This prevents problems if the OS/2 driver
889 * installation doesn't/fails to copy them, which can happen under
890 * some circumstances.)
891 */
892 IF VRFileExists( globals.!os2dir'\DLL\'driver ) THEN DO
893 CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
894 globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
895 CALL VRCopyFile workdir'\OUT\'driver'.DRV',,
896 globals.!os2dir'\DLL\'driver'\'driver'.DRV'
897 END
898 END
899 IF ok == 0 THEN
900 RETURN 3 /*** RC=3 Failed to copy driver files ***/
901
902 CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
903 DO i = 1 TO newprinters.0
904 CALL LINEOUT globals.!log1, ' ->' newprinters.i
905 END
906 CALL LINEOUT globals.!log1, ''
907 CALL LINEOUT globals.!log1
908
909 /* Clean up our work directories.
910 */
911 CALL VRDeleteFile workdir'\OUT\*'
912 CALL VRDeleteFile workdir'\*'
913 CALL VRRmDir( workdir'\OUT')
914 CALL VRRmDir( workdir )
915
916RETURN 0
917
918/*:VRX Init
919*/
920Init:
921 SIGNAL ON NOVALUE NAME __NoValue
922
923 CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
924 CALL SysLoadFuncs
925
926 CALL LoadSettings
927
928 IF InitArgs.0 > 0 THEN globals.!cupsdir = InitArgs.1
929
930 IF \VRIsDir( globals.!cupsdir ) THEN DO
931 IF TRANSLATE( globals.!cupsdir ) <> '/R' THEN
932 CALL VRMessage VRWindow(),,
933 'CUPS could not be located. If you wish to use ' ||,
934 'a local installation of CUPS, please specify ' ||,
935 'the path where CUPS is installed on the command '||,
936 'line to this program (e.g "CUPSWIZ F:\CUPS").' ||,
937 '0d0a0d0a'x ||,
938 'Only remote CUPS queues will be available for ' ||,
939 'printers created in this session. (To skip ' ||,
940 'this message in the future, start this program ' ||,
941 'with the /R parameter.)',,
942 'CUPS Path Not Found or Not Valid', 'E'
943 globals.!cupsdir = ''
944 END
945
946 /* Delete the error log file each time the program starts.
947 */
948 IF VRFileExists( globals.!log2 ) THEN
949 CALL VRDeleteFile globals.!log2
950
951 window = VRWindow()
952 call VRMethod window, "CenterWindow"
953 call VRSet window, "Visible", 1
954 call VRMethod window, "Activate"
955 drop window
956
957 CALL SetPage1
958
959RETURN
960
961/*:VRX InitMessageLog
962*/
963/* Initialize the message logfile. Unlike the error log, which is cleared and
964 * recreated every time the program starts, the message log is appended to
965 * until it reaches 100kB in size. If the message log is larger than 100kB when
966 * this function is called, it is renamed (with '~' appended to the name) and
967 * a new message log is started.
968 */
969InitMessageLog: PROCEDURE EXPOSE globals.
970
971 logsize = STREAM( globals.!log1, 'C', 'QUERY SIZE')
972 IF ( logsize <> '') & ( logsize > 102400 ) THEN DO
973 CALL VRCopyFile globals.!log1, globals.!log1 || '~'
974 CALL VRDeleteFile globals.!log1
975 END
976
977 datestr = DATE('L') TIME('N')
978 CALL LINEOUT globals.!log1, '--[' datestr ']' ||,
979 COPIES('-', 73 - LENGTH( datestr ))
980RETURN
981
982/*:VRX LB_BRAND_Click
983*/
984LB_BRAND_Click: PROCEDURE EXPOSE globals. manufacturers.
985
986 CALL VRSet 'WN_MAIN', 'StatusText', ''
987
988 index = VRGet('LB_BRAND', 'Selected')
989 IF index == 0 THEN RETURN
990
991 item = VRMethod('LB_BRAND', 'GetItemData', index )
992 IF item == 0 THEN RETURN
993
994 DO i = 1 TO manufacturers.item.!printers.0
995 models.i = manufacturers.item.!printers.i.!model
996 /* ppds.i = manufacturers.item.!printers.i.!driver */
997 IF manufacturers.item.!printers.i.!driver == '' THEN
998 ppds.i = ''
999 ELSE
1000 ppds.i = i
1001
1002/* DEBUG
1003say 'Model: ' manufacturers.item.!printers.i.!model
1004say 'Driver: ' manufacturers.item.!printers.i.!driver
1005say ' ' manufacturers.item.!printers.i.!longname
1006if manufacturers.item.!printers.i.!driver2 <> '' then
1007 say 'Alternate:' manufacturers.item.!printers.i.!driver2
1008if manufacturers.item.!printers.i.!longname2 <> '' then
1009 say ' ' manufacturers.item.!printers.i.!longname2
1010say 'Type: ' manufacturers.item.!printers.i.!type
1011say '---'
1012 */
1013
1014 END
1015 models.0 = manufacturers.item.!printers.0
1016 ppds.0 = manufacturers.item.!printers.0
1017
1018 CALL VRSet 'LB_SELECT', 'Painting', 0
1019 CALL VRMethod 'LB_SELECT', 'Clear'
1020 CALL VRMethod 'LB_SELECT', 'AddStringList', 'models.',, 'ppds.'
1021 CALL VRSet 'LB_SELECT', 'Painting', 1
1022/* CALL VRSet 'LB_SELECT', 'Selected', 1 */
1023
1024RETURN
1025
1026/*:VRX LB_SELECT_Click
1027*/
1028LB_SELECT_Click: PROCEDURE EXPOSE globals. manufacturers.
1029 SELECT
1030 WHEN globals.!page == 1 THEN DO
1031 CALL VRSet 'WN_MAIN', 'StatusText', ''
1032
1033 brand = VRGet('LB_BRAND', 'Selected')
1034 IF brand == 0 THEN RETURN
1035 selected = VRGet('LB_SELECT', 'Selected')
1036 IF selected == 0 THEN RETURN
1037 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1038 IF which <> '' THEN DO
1039 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1040 IF man == '' THEN RETURN
1041 make = manufacturers.man.!name
1042 model = manufacturers.man.!printers.which.!model
1043 driver = manufacturers.man.!printers.which.!type
1044 IF WORD( driver, 1 ) == 'hpcups' THEN driver = 'HPLIP'
1045 remark = manufacturers.man.!printers.which.!remark
1046 IF driver == '' THEN
1047 type = ''
1048 ELSE IF remark == '' THEN
1049 type = ' ('driver')'
1050 ELSE
1051 type = ' ('driver' - 'remark')'
1052 CALL VRSet 'WN_MAIN', 'StatusText', make model type
1053 END
1054 END
1055
1056 OTHERWISE NOP
1057 END
1058
1059 CALL VRSet 'PB_NEXT', 'Enabled', 1
1060RETURN
1061
1062/*:VRX LoadSettings
1063*/
1064LoadSettings: PROCEDURE EXPOSE globals.
1065
1066 me = VRGet('Application', 'Program')
1067 IF me == '' THEN PARSE SOURCE . . me
1068 globals.!mydir = VRParseFilePath( me, 'DP')
1069
1070 /* Get CUPS paths.
1071 */
1072 PARSE VALUE VRGetIni('eCups', 'CUPS', 'USER') WITH cupsdrv '00'x
1073 IF cupsdrv == '' THEN
1074 cupsdrv = VRParseFilePath( me, 'D') || ':'
1075 ELSE
1076 cupsdrv = STRIP( cupsdrv, 'T', '\')
1077 globals.!cupsdir = cupsdrv'\cups'
1078
1079 /* Get system paths.
1080 */
1081 globals.!bootdrv = SysBootDrive()
1082 IF globals.!bootdrv == '' THEN
1083 globals.!bootdrv = FILESPEC('DRIVE', VALUE('OS2_SHELL',,'OS2ENVIRONMENT'))
1084 globals.!os2dir = globals.!bootdrv'\OS2'
1085 globals.!tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
1086 IF globals.!tmpdir == '' THEN
1087 globals.!tmpdir = VALUE('TEMP',,'OS2ENVIRONMENT')
1088 IF globals.!tmpdir == '' THEN
1089 globals.!tmpdir = globals.!mydir
1090 globals.!logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
1091 IF globals.!logdir == '' THEN
1092 globals.!logdir = globals.!mydir
1093
1094 globals.!log1 = globals.!logdir'\cupswiz.l1'
1095 globals.!log2 = globals.!logdir'\cupswiz.l2'
1096
1097 /* Get printer-related paths.
1098 */
1099 PARSE VALUE VRGetIni('PM_INSTALL', 'PDR_DIR', 'USER') WITH repos_dir '00'x .
1100 globals.!repository = repos_dir
1101 globals.!prdrv = STREAM( globals.!os2dir'\install\prdrv.lst', 'C', 'QUERY EXISTS')
1102 globals.!prdesc = STREAM( globals.!os2dir'\install\prdesc.lst', 'C', 'QUERY EXISTS')
1103
1104RETURN 0
1105
1106/*:VRX LoopbackName
1107*/
1108/* Check to see if 'localhost' is defined in the HOSTS file. If not, we'll
1109 * have to use '127.0.0.1' instead.
1110 */
1111LoopbackName: PROCEDURE
1112
1113 lo_name = '127.0.0.1'
1114 etcdir = VALUE('ETC',,'OS2ENVIRONMENT')
1115 IF etcdir <> '' THEN DO
1116 hosts = STREAM( etcdir'\HOSTS', 'C', 'QUERY EXISTS')
1117 IF hosts <> '' THEN DO
1118 CALL LINEIN hosts, 1, 0
1119 DO WHILE LINES( hosts ) > 0
1120 _hostdef = TRANSLATE( LINEIN( hosts ))
1121 _hostdef = TRANSLATE( _hostdef, ' ', '09'x )
1122 IF WORDPOS('LOCALHOST', _hostdef ) == 2 THEN DO
1123 lo_name = 'localhost'
1124 LEAVE
1125 END
1126 END
1127 END
1128 END
1129
1130RETURN lo_name
1131
1132/*:VRX PB_ABOUT_Click
1133*/
1134PB_ABOUT_Click:
1135 CALL SW_ABOUT_Close
1136RETURN
1137
1138/*:VRX PB_CANCEL_Click
1139*/
1140PB_CANCEL_Click:
1141 CALL Quit
1142return
1143
1144/*:VRX PB_CREATECANCEL_Click
1145*/
1146PB_CREATECANCEL_Click:
1147 CALL SW_CREATE_Close
1148RETURN
1149
1150/*:VRX PB_CREATEOK_Click
1151*/
1152PB_CREATEOK_Click:
1153
1154 create_os2 = VRGet('CHK_CREATEPM', 'Set')
1155 globals.!os2printer = create_os2
1156 globals.!os2driver = VRGet('DDCB_PRESDRV', 'SelectedString')
1157 globals.!create = 1
1158
1159 CALL SW_CREATE_Close
1160
1161RETURN
1162
1163/*:VRX PB_MODELCANCEL_Click
1164*/
1165PB_MODELCANCEL_Click:
1166 CALL SW_MODEL_Close
1167 globals.!prt_nick = 'Generic PostScript Printer'
1168RETURN
1169
1170/*:VRX PB_MODELOK_Click
1171*/
1172PB_MODELOK_Click:
1173 globals.!prt_nick = VRGet( "LB_OS2MODELS", "SelectedString" )
1174 CALL SW_MODEL_Close
1175RETURN
1176
1177/*:VRX PB_NETCANCEL_Click
1178*/
1179PB_NETCANCEL_Click:
1180 CALL SW_NETWORK_Fini
1181RETURN
1182
1183/*:VRX PB_NETOK_Click
1184*/
1185PB_NETOK_Click: PROCEDURE EXPOSE globals. port
1186
1187 idx = VRGet('DDCB_PROTOCOL', 'Selected')
1188 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
1189 server = STRIP( VRGet("EF_SERVER", "Value"))
1190 pqueue = STRIP( VRGet("EF_QUEUE", "Value"))
1191 userid = STRIP( VRGet("EF_USERID", "Value"))
1192 passwd = STRIP( VRGet("EF_PASSWORD", "Value"))
1193
1194 invalid = 0
1195
1196 SELECT
1197 WHEN which == 1 THEN DO /* IPP */
1198 IF server == '' | pqueue == '' THEN invalid = 1
1199 uri = 'ipp://'
1200 IF userid <> '' THEN DO
1201 uri = uri || userid
1202 IF passwd <> '' THEN uri = uri':'passwd
1203 uri = uri'@'
1204 END
1205 uri = uri || server'/'pqueue
1206 END
1207 WHEN which == 2 THEN DO /* SOCKET */
1208 IF server == '' THEN invalid = 1
1209 uri = 'socket://'server
1210 END
1211 WHEN which == 3 THEN DO /* LPD */
1212 IF server == '' THEN invalid = 1
1213 IF pqueue == '' THEN pqueue = '*'
1214 IF userid <> '' THEN
1215 uri = 'ipp://'userid'@'server'/'pqueue
1216 ELSE
1217 uri = 'lpd://'server'/'pqueue
1218 END
1219 WHEN which == 4 THEN DO /* SMB */
1220 IF server == '' | pqueue == '' THEN invalid = 1
1221 uri = 'smb://'
1222 IF userid <> '' THEN DO
1223 uri = uri || userid
1224 IF passwd <> '' THEN uri = uri':'passwd
1225 uri = uri'@'
1226 END
1227 uri = uri || server'/'pqueue
1228 END
1229 OTHERWISE DO
1230 IF server == '' | pqueue == '' THEN invalid = 1
1231 ELSE DO
1232 globals.!remotecups = server pqueue
1233 uri = ''
1234 END
1235 END
1236 END
1237
1238 IF invalid == 1 THEN DO
1239 CALL VRMessage VRWindow(), 'Missing required value(s).', 'Missing Value(s)', 'E'
1240 RETURN
1241 END
1242
1243 port = uri
1244 CALL SW_NETWORK_Fini
1245
1246RETURN
1247
1248/*:VRX PB_NEXT_Click
1249*/
1250PB_NEXT_Click: PROCEDURE EXPOSE globals. manufacturers.
1251
1252 SELECT
1253 WHEN globals.!page == 1 THEN DO
1254 brand = VRGet('LB_BRAND', 'Selected')
1255 IF brand == 0 THEN RETURN
1256 selected = VRGet('LB_SELECT', 'Selected')
1257 IF selected == 0 THEN RETURN
1258
1259 CALL VRSet 'WN_MAIN', 'StatusText', ''
1260
1261 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1262 IF which == '' THEN DO
1263 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1264 ppd = VRFileDialog( VRWindow(), 'Select PPD', 'O', '*.ppd')
1265 IF ppd == '' THEN RETURN
1266 globals.!prt_ppd = ppd
1267 globals.!prt_dev = ''
1268 globals.!prt_nick = GetNameFromPPD( ppd )
1269 IF globals.!prt_nick == '' THEN DO
1270 CALL VRMessage VRWindow(), 'Could not read printer name '||,
1271 'from' ppd'.', 'Invalid PPD', 'E'
1272 RETURN
1273 END
1274 END
1275 ELSE DO
1276 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1277 IF man == '' THEN DO
1278 /* TODO display an error? But this shouldn't be possible... */
1279 RETURN
1280 END
1281 ppd = manufacturers.man.!printers.which.!driver
1282 globals.!mode = 1 /* Mode 1: CUPS-included model */
1283 IF POS('exe://', ppd ) > 0 THEN DO
1284 globals.!prt_ppd = ''
1285 globals.!prt_dev = ppd
1286 sel_brand = VRGet('LB_BRAND', 'SelectedString')
1287 sel_name = sel_brand VRMethod('LB_SELECT', 'GetString', selected )
1288 PARSE VAR sel_name _nick ' - CUPS' .
1289 IF _nick == '' THEN
1290 globals.!prt_nick = STRIP( sel_name )
1291 ELSE
1292 globals.!prt_nick = STRIP( _nick )
1293 END
1294 ELSE DO
1295 globals.!prt_ppd = TRANSLATE( globals.!cupsdir'/share/cups/model/'ppd, '\', '/')
1296 globals.!prt_dev = ''
1297 globals.!prt_nick = GetNameFromPPD( globals.!prt_ppd )
1298 END
1299 END
1300 globals.!remotecups = ''
1301
1302 CALL InitMessageLog
1303 IF globals.!mode == 2 THEN
1304 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1305 ELSE
1306 CALL LINEOUT globals.!log1, 'Starting printer install for built-in model:'
1307 IF globals.!prt_dev <> '' THEN
1308 CALL LINEOUT globals.!log1, ' - Device name:' globals.!prt_dev
1309 ELSE
1310 CALL LINEOUT globals.!log1, ' - PPD file: ' globals.!prt_ppd
1311 CALL LINEOUT globals.!log1, ' - Model name: ' globals.!prt_nick
1312 CALL LINEOUT globals.!log1, ''
1313
1314 CALL SetPage2
1315 END
1316
1317 WHEN globals.!page == 2 THEN DO
1318 selected = VRGet('LB_SELECT', 'Selected')
1319 IF selected == 0 THEN RETURN
1320 port = VRMethod('LB_SELECT', 'GetItemData', selected )
1321
1322 IF port == '' THEN DO
1323 /* Network printer selected; prompt for the connection details
1324 */
1325 CALL VRLoadSecondary 'SW_NETWORK', 'W'
1326 END
1327
1328 IF port == '' & globals.!remotecups == '' THEN RETURN
1329 globals.!prt_port = port
1330
1331 CALL SetPage3
1332 END
1333
1334 WHEN globals.!page == 3 THEN DO
1335 globals.!prt_name = STRIP( VRGet('EF_NAME', 'Value'))
1336 globals.!prt_loc = STRIP( VRGet('EF_LOCATION', 'Value'))
1337 globals.!prt_info = STRIP( VRGet('EF_DESC', 'Value'))
1338 IF ((( globals.!prt_name == '') |,
1339 ( globals.!prt_loc == '')) & ( globals.!remotecups == '')) |,
1340 ( globals.!prt_info == '') THEN
1341 DO
1342 IF ( globals.!remotecups <> '') THEN
1343 _errmsg = 'You must enter a description.'
1344 ELSE
1345 _errmsg = 'You must enter a name, a location, and a description.'
1346 CALL VRMessage VRWindow(), _errmsg, 'Missing Value(s)', 'E'
1347 RETURN
1348 END
1349 IF ( globals.!remotecups == '' &,
1350 ( POS( LEFT( globals.!prt_name, 1 ),,
1351 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') == 0 ) |,
1352 ( VERIFY( globals.!prt_name, '/# ' || '09'x, 'MATCH') <> 0 )) THEN
1353 DO
1354 CALL VRMessage VRWindow(), 'The printer name must start ' ||,
1355 'with a letter, and may not include "/", "#", ' ||,
1356 'space, or tab characters.', 'Invalid Name', 'E'
1357 RETURN
1358 END
1359
1360 /* TODO support other drivers
1361 */
1362 IF WORD( globals.!prt_nick, 1 ) == 'Apollo' |,
1363 WORD( globals.!prt_nick, 1 ) == 'HP' |,
1364 WORD( globals.!prt_nick, 1 ) == 'Hewlett-Packard' THEN
1365 globals.!os2driver = 'ECUPS-HP'
1366 ELSE
1367 globals.!os2driver = 'ECUPS'
1368
1369 CALL ConfirmAndCreate
1370 END
1371
1372 WHEN globals.!page == 4 THEN DO
1373 CALL VRSet 'PB_NEXT', 'Caption', 'Next >'
1374 CALL VRSet 'EF_NAME', 'Value', ''
1375 CALL VRSet 'EF_LOCATION', 'Value', ''
1376 CALL VRSet 'EF_DESC', 'Value', ''
1377 CALL SetPage1
1378 END
1379
1380 OTHERWISE NOP
1381 END
1382
1383RETURN
1384
1385/*:VRX PICT_ICON_Click
1386*/
1387PICT_ICON_Click: PROCEDURE EXPOSE globals.
1388 CALL VRLoadSecondary 'SW_ABOUT', 'W'
1389RETURN
1390
1391/*:VRX PromptForPMName
1392*/
1393PromptForPMName: PROCEDURE EXPOSE globals. models. best
1394 best = MatchPrinterModel( globals.!os2driver, globals.!prt_nick )
1395
1396 IF models.0 == 0 THEN DO
1397 /* No similar models were found in the list of supported printers.
1398 * Just use the generic PS driver.
1399 */
1400 CALL VRMessage VRWindow(),,
1401 'The printer "'globals.!prt_nick'" does not appear to' ,
1402 'be supported by the' globals.!os2driver 'driver, and' ,
1403 'no similar models were found. The generic PostScript',
1404 'driver will be used for application support.',,
1405 'Printer Name Not Found', 'E'
1406 globals.!prt_nick = 'Generic PostScript Printer'
1407 RETURN
1408 END
1409
1410 CALL VRLoadSecondary 'SW_MODEL', 'W'
1411
1412RETURN
1413
1414/*:VRX Quit
1415*/
1416Quit:
1417 window = VRWindow()
1418 call VRSet window, "Shutdown", 1
1419 drop window
1420return
1421
1422/*:VRX SetPage1
1423*/
1424SetPage1: PROCEDURE EXPOSE globals. manufacturers.
1425
1426 CALL VRSet 'PB_NEXT', 'Enabled', 0
1427 CALL VRSet 'LB_BRAND', 'Visible', 1
1428
1429 /* Resize LB_SELECT if necessary to make room for LB_BRAND */
1430 lb_x = VRGet('LB_BRAND', 'Left') + VRGet('LB_BRAND', 'Width') + 60
1431 lb_w = VRGet('GB_INFO', 'Width') - lb_x + VRGet('GB_INFO', 'Left')
1432 CALL VRSet 'LB_SELECT', 'Left', lb_x
1433 CALL VRSet 'LB_SELECT', 'Width', lb_w
1434
1435 CALL VRSet 'LB_SELECT', 'Visible', 1
1436 CALL VRSet 'GB_INFO', 'Visible', 0
1437
1438 globals.!page = 1
1439 globals.!prt_ppd = ''
1440 globals.!prt_dev = ''
1441 globals.!prt_nick = ''
1442 globals.!prt_port = ''
1443 globals.!remotecups = ''
1444 globals.!prt_name = ''
1445 globals.!prt_loc = ''
1446 globals.!prt_info = ''
1447 globals.!os2driver = ''
1448
1449 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1450 CALL VRSet 'DT_INFO', 'Caption', 'Select your printer model.'
1451
1452 /* Populate the manufacturer list */
1453 IF globals.!cupsdir == '' THEN DO
1454 manufacturers.1.!name = '-- Custom --'
1455 manufacturers.1.!printers.0 = 1
1456 manufacturers.1.!printers.1.!model = '-- Other printer (requires PPD) --'
1457 manufacturers.1.!printers.1.!driver = ''
1458 manufacturers.1.!printers.1.!type = ''
1459 manufacturers.1.!printers.1.!remark = '-- Other printer (requires PPD) --'
1460 manufacturers.1.!printers.1.!driver2 = ''
1461 manufacturers.1.!printers.1.!remark2 = ''
1462 manufacturers.0 = 1
1463 END
1464 ELSE
1465 CALL GetCupsPrinters
1466
1467 CALL VRSet 'LB_BRAND', 'Painting', 0
1468 DO i = 1 TO manufacturers.0
1469 addman.i = manufacturers.i.!name
1470 addidx.i = i
1471 END
1472 addman.0 = manufacturers.0
1473 addidx.0 = manufacturers.0
1474 CALL VRMethod 'LB_BRAND', 'AddStringList', 'addman.',, 'addidx.'
1475 CALL VRSet 'LB_BRAND', 'Painting', 1
1476
1477 CALL VRMethod 'LB_BRAND', 'SetFocus'
1478 CALL VRSet 'LB_BRAND', 'Selected', 1
1479 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1480
1481RETURN
1482
1483/*:VRX SetPage2
1484*/
1485SetPage2: PROCEDURE EXPOSE globals.
1486
1487 globals.!page = 2
1488 CALL VRSet 'LB_BRAND', 'Visible', 0
1489 CALL VRSet 'PB_NEXT', 'Enabled', 0
1490 CALL VRSet 'WN_MAIN', 'StatusText', 'Selected printer: ' globals.!prt_nick
1491
1492 /* Resize LB_SELECT to the full width of GB_INFO */
1493 lb_x = VRGet('GB_INFO', 'Left')
1494 lb_w = VRGet('GB_INFO', 'Width')
1495 CALL VRSet 'LB_SELECT', 'Left', lb_x
1496 CALL VRSet 'LB_SELECT', 'Width', lb_w
1497
1498 CALL VRMethod 'LB_SELECT', 'Clear'
1499
1500 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1501 IF globals.!cupsdir == '' THEN DO
1502 CALL VRMethod 'LB_SELECT', 'AddString', 'Network printer (manual configuration)',, ''
1503 CALL VRSet 'LB_SELECT', 'Selected', 1
1504 END
1505 ELSE
1506 CALL GetCupsPorts
1507 CALL VRMethod 'LB_SELECT', 'SetFocus'
1508 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1509
1510RETURN
1511
1512/*:VRX SetPage3
1513*/
1514SetPage3: PROCEDURE EXPOSE globals.
1515
1516 globals.!page = 3
1517 CALL VRSet 'EF_DESC', 'Value', globals.!prt_nick
1518
1519 CALL VRMethod 'LB_SELECT', 'Clear'
1520
1521 CALL VRSet 'LB_SELECT', 'Visible', 0
1522 CALL VRSet 'GB_INFO', 'Visible', 1
1523 IF globals.!remotecups == '' THEN DO
1524 CALL VRSet 'DT_INFO', 'Caption', 'Choose the printer name, and enter its location and a short description.'
1525 CALL VRSet 'DT_NAME', 'Visible', 1
1526 CALL VRSet 'EF_NAME', 'Visible', 1
1527 CALL VRSet 'DT_LOCATION', 'Visible', 1
1528 CALL VRSet 'EF_LOCATION', 'Visible', 1
1529 END
1530 ELSE
1531 CALL VRSet 'DT_INFO', 'Caption', 'Enter a short description of this printer. ',
1532 'This will be used for the printer object that appears on your desktop.'
1533 CALL VRSet 'DT_DESC', 'Visible', 1
1534 CALL VRSet 'EF_DESC', 'Visible', 1
1535
1536 CALL VRMethod 'EF_NAME', 'SetFocus'
1537
1538RETURN
1539
1540/*:VRX SetPage4
1541*/
1542SetPage4:
1543
1544 globals.!page = 4
1545 CALL VRSet 'LB_SELECT', 'Visible', 0
1546 CALL VRSet 'GB_INFO', 'Visible', 0
1547 CALL VRSet 'WN_MAIN', 'StatusText', ''
1548
1549RETURN
1550
1551/*:VRX SW_ABOUT_Close
1552*/
1553SW_ABOUT_Close:
1554 call SW_ABOUT_Fini
1555return
1556
1557/*:VRX SW_ABOUT_Create
1558*/
1559SW_ABOUT_Create:
1560 call SW_ABOUT_Init
1561return
1562
1563/*:VRX SW_ABOUT_Fini
1564*/
1565SW_ABOUT_Fini:
1566 window = VRInfo( "Window" )
1567 call VRDestroy window
1568 drop window
1569return
1570/*:VRX SW_ABOUT_Init
1571*/
1572SW_ABOUT_Init:
1573
1574 CALL VRSet 'DT_BOOTDRIVE', 'Caption', 'System boot volume:' TRANSLATE( globals.!bootdrv )
1575 CALL VRSet 'DT_CUPSPATH', 'Caption', 'Local CUPS directory:' TRANSLATE( globals.!cupsdir )
1576 CALL VRSet 'DT_REPOSITORY', 'Caption', 'Local driver repository:' TRANSLATE( globals.!repository )
1577
1578 window = VRInfo( "Object" )
1579 if( \VRIsChildOf( window, "Notebook" ) ) then do
1580 call VRMethod window, "CenterWindow"
1581 call VRSet window, "Visible", 1
1582 call VRMethod window, "Activate"
1583 end
1584 drop window
1585return
1586
1587/*:VRX SW_CREATE_Close
1588*/
1589SW_CREATE_Close:
1590 call SW_CREATE_Fini
1591return
1592
1593/*:VRX SW_CREATE_Create
1594*/
1595SW_CREATE_Create:
1596 call SW_CREATE_Init
1597return
1598
1599/*:VRX SW_CREATE_Fini
1600*/
1601SW_CREATE_Fini:
1602 window = VRInfo( "Window" )
1603 call VRDestroy window
1604 drop window
1605return
1606/*:VRX SW_CREATE_Init
1607*/
1608SW_CREATE_Init:
1609
1610 CALL VRSet 'EF_CRMODEL', 'Value', globals.!prt_nick
1611
1612 IF globals.!remotecups <> '' THEN DO
1613 /* An existing CUPS printer was indicated. This means we're not
1614 * creating a CUPS printer, but only a PM printer object (and port)
1615 * that points to it.
1616 */
1617 CALL VRSet 'DT_CREATE', 'Caption', 'Ready to create printer object with the following parameters.'
1618
1619 PARSE VAR globals.!remotecups cups_host cups_printer .
1620 CALL VRSet 'DT_CRNAME', 'Caption', 'CUPS server:'
1621 CALL VRSet 'EF_CRNAME', 'Value', cups_host
1622 CALL VRSet 'DT_CRURI', 'Caption', 'CUPS queue:'
1623 CALL VRSet 'EF_CRURI', 'Value', cups_printer
1624 CALL VRSet 'DT_CRLOC', 'Visible', 0
1625 CALL VRSet 'EF_CRLOC', 'Visible', 0
1626 CALL VRSet 'CHK_CREATEPM', 'Visible', 0
1627 END
1628 ELSE DO
1629 CALL VRSet 'EF_CRNAME', 'Value', globals.!prt_name
1630 CALL VRSet 'EF_CRURI', 'Value', globals.!prt_port
1631 CALL VRSet 'EF_CRLOC', 'Value', globals.!prt_loc
1632 END
1633 CALL VRSet 'EF_CRDESC', 'Value', globals.!prt_info
1634
1635 IF QueryAvailableDrivers() > 0 THEN DO
1636 def_idx = 1
1637 CALL VRMethod 'DDCB_PRESDRV', 'AddStringList', 'drv_list.'
1638 DO i = 1 TO drv_list.0
1639 IF drv_list.i == globals.!os2driver THEN DO
1640 def_idx = i
1641 LEAVE
1642 END
1643 END
1644 CALL VRSet 'DDCB_PRESDRV', 'Selected', def_idx
1645 END
1646 /* TODO give an error if no drivers were found */
1647
1648 window = VRInfo( "Object" )
1649 if( \VRIsChildOf( window, "Notebook" ) ) then do
1650 call VRMethod window, "CenterWindow"
1651 call VRSet window, "Visible", 1
1652 call VRMethod window, "Activate"
1653 end
1654 drop window
1655
1656RETURN
1657
1658/*:VRX SW_MODEL_Close
1659*/
1660SW_MODEL_Close:
1661 call SW_MODEL_Fini
1662return
1663
1664/*:VRX SW_MODEL_Create
1665*/
1666SW_MODEL_Create:
1667 call SW_MODEL_Init
1668return
1669
1670/*:VRX SW_MODEL_Fini
1671*/
1672SW_MODEL_Fini:
1673
1674 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1675
1676 window = VRInfo( "Window" )
1677 call VRDestroy window
1678 drop window
1679return
1680/*:VRX SW_MODEL_Init
1681*/
1682SW_MODEL_Init:
1683
1684 /* We should have a list of suggested printer models whose names at least
1685 * partially match the requested model, sorted in order with the closest
1686 * match at the top.
1687 */
1688 ok = VRMethod( "LB_OS2MODELS", "AddStringList", "models.", )
1689 IF best > 0 THEN
1690 CALL VRSet 'LP_OS2MODELS', 'Selected', best
1691
1692 CALL VRSet 'DT_MODEL1', 'Caption',,
1693 'The printer "'globals.!prt_nick'" could not be found in the' ,
1694 globals.!os2driver'.DRV driver under that name. Please choose',
1695 'the model of printer which will be reported to applications.'
1696
1697 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1698
1699 window = VRInfo( "Object" )
1700 if( \VRIsChildOf( window, "Notebook" ) ) then do
1701 call VRMethod window, "CenterWindow"
1702 call VRSet window, "Visible", 1
1703 call VRMethod window, "Activate"
1704 end
1705 drop window
1706
1707RETURN
1708
1709/*:VRX SW_NETWORK_Close
1710*/
1711SW_NETWORK_Close:
1712 call SW_NETWORK_Fini
1713return
1714
1715/*:VRX SW_NETWORK_Create
1716*/
1717SW_NETWORK_Create:
1718 call SW_NETWORK_Init
1719return
1720
1721/*:VRX SW_NETWORK_Fini
1722*/
1723SW_NETWORK_Fini:
1724 window = VRInfo( "Window" )
1725 call VRDestroy window
1726 drop window
1727return
1728/*:VRX SW_NETWORK_Init
1729*/
1730SW_NETWORK_Init:
1731
1732 IF globals.!cupsdir == '' THEN DO
1733 protos.0 = 1
1734 protos.1 = 'Existing CUPS printer (remote server)'
1735 pnums.0 = 1
1736 pnums.1 = 5
1737 END
1738 ELSE DO
1739 protos.0 = 5
1740 protos.1 = 'Internet Printing Protocol (IPP)'
1741 protos.2 = 'AppSocket/JetDirect'
1742 protos.3 = 'Line Printer Remote daemon (LPD)'
1743 protos.4 = 'Windows/SMB network'
1744 protos.5 = 'Existing CUPS printer'
1745 pnums.0 = 5
1746 pnums.1 = 1
1747 pnums.2 = 2
1748 pnums.3 = 3
1749 pnums.4 = 4
1750 pnums.5 = 5
1751 END
1752
1753 CALL VRMethod 'DDCB_PROTOCOL', 'AddStringList', 'protos.',, 'pnums.'
1754 CALL VRSet 'DDCB_PROTOCOL', 'Selected', 1
1755
1756 window = VRInfo( "Object" )
1757 if( \VRIsChildOf( window, "Notebook" ) ) then do
1758 call VRMethod window, "CenterWindow"
1759 call VRSet window, "Visible", 1
1760 call VRMethod window, "Activate"
1761 end
1762 drop window
1763return
1764
1765/*:VRX WN_MAIN_Close
1766*/
1767WN_MAIN_Close:
1768 call Quit
1769return
1770
Note: See TracBrowser for help on using the repository browser.