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

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

Eliminate need for RINSTPRN. Try to import PPD from \cups\etc\cups\ppd if it doesn't exist in OS/2 driver. Some minor UI-related fixes.

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