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

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

Accept a PPD as command line argument (in which case Page 1 is skipped).
Begun work on help file.

File size: 75.8 KB
Line 
1/*:VRX Main
2*/
3/* Main
4*/
5Main:
6/* Process the arguments.
7 Get the parent window.
8*/
9 parse source . calledAs .
10 parent = ""
11 argCount = arg()
12 argOff = 0
13 if( calledAs \= "COMMAND" )then do
14 if argCount >= 1 then do
15 parent = arg(1)
16 argCount = argCount - 1
17 argOff = 1
18 end
19 end; else do
20 call VROptions 'ImplicitNames'
21 call VROptions 'NoEchoQuit'
22 end
23 InitArgs.0 = argCount
24 if( argCount > 0 )then do i = 1 to argCount
25 InitArgs.i = arg( i + argOff )
26 end
27 drop calledAs argCount argOff
28
29/* Load the windows
30*/
31 call VRInit
32 parse source . . spec
33 _VREPrimaryWindowPath = ,
34 VRParseFileName( spec, "dpn" ) || ".VRW"
35 _VREPrimaryWindow = ,
36 VRLoad( parent, _VREPrimaryWindowPath )
37 drop parent spec
38 if( _VREPrimaryWindow == "" )then do
39 call VRMessage "", "Cannot load window:" VRError(), ,
40 "Error!"
41 _VREReturnValue = 32000
42 signal _VRELeaveMain
43 end
44
45/* Process events
46*/
47 call Init
48 signal on halt
49 do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
50 _VREEvent = VREvent()
51 interpret _VREEvent
52 end
53_VREHalt:
54 _VREReturnValue = Fini()
55 call VRDestroy _VREPrimaryWindow
56_VRELeaveMain:
57 call VRFini
58exit _VREReturnValue
59
60VRLoadSecondary:
61 __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
62 if __vrlsWait then do
63 call VRFlush
64 end
65 __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
66 if __vrlsHWnd = '' then signal __vrlsDone
67 if __vrlsWait \= 1 then signal __vrlsDone
68 call VRSet __vrlsHWnd, 'WindowMode', 'Modal'
69 __vrlsTmp = __vrlsWindows.0
70 if( DataType(__vrlsTmp) \= 'NUM' ) then do
71 __vrlsTmp = 1
72 end
73 else do
74 __vrlsTmp = __vrlsTmp + 1
75 end
76 __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
77 __vrlsWindows.0 = __vrlsTmp
78 do while( VRIsValidObject( VRWindow() ) = 1 )
79 __vrlsEvent = VREvent()
80 interpret __vrlsEvent
81 end
82 __vrlsTmp = __vrlsWindows.0
83 __vrlsWindows.0 = __vrlsTmp - 1
84 call VRWindow __vrlsWindows.__vrlsTmp
85 __vrlsHWnd = ''
86__vrlsDone:
87return __vrlsHWnd
88
89/*:VRX __NoValue
90*/
91__NoValue:
92 SAY FORMAT( sigl, 6 ) '+++' SOURCELINE( sigl )
93 SAY FORMAT( sigl, 6 ) '+++ Uninitialized variable'
94EXIT sigl
95
96/*:VRX __VXREXX____APPENDS__
97*/
98__VXREXX____APPENDS__:
99/*
100#append ..\..\Shared\PrintUtl.VRS
101*/
102return
103/*:VRX CheckPrograms
104*/
105CheckPrograms: PROCEDURE EXPOSE globals.
106
107 /* Make sure CUPS.PDR is installed.
108 */
109 cups_pdr = VRGetIni('PM_PORT_DRIVER', 'CUPS', 'System')
110 IF cups_pdr == '' THEN DO
111 cups_pdr = STREAM( globals.!bootdrv'\OS2\DLL\CUPS.PDR', 'C', 'QUERY EXISTS')
112 IF cups_pdr == '' THEN DO
113 CALL VRMessage VRWindow(),,
114 NLSGetMessage( 78, globals.!bootdrv'\OS2\DLL\CUPS.PDR'),, /* 78: The required program %1 is not installed... */
115 NLSGetMessage( 79 ), 'E' /* 79: Missing File */
116 CALL Quit
117 END
118 ELSE CALL VRSetIni('PM_PORT_DRIVER', 'CUPS', cups_pdr, 'System')
119 END
120
121 /* Make sure \TCPIP\BIN\CUPSLPR.EXE (required by CUPS.PDR) is installed.
122 */
123 tcpipbin = SysSearchPath('PATH', 'inetd.exe')
124 IF tcpipbin <> '' THEN
125 tcpipbin = VRParseFileName( tcpipbin, 'DP')
126 ELSE
127 tcpipbin = globals.!bootdrv'\TCPIP\BIN'
128 IF \VRFileExists( tcpipbin'\cupslpr.exe') & (SysSearchPath('PATH', 'cupslpr.exe') == '') THEN DO
129 CALL VRMessage VRWindow(),,
130 NLSGetMessage( 78, 'CUPSLPR.EXE'),,
131 NLSGetMessage( 79 ), 'E'
132 CALL Quit
133 END
134
135 /* Make sure GZIP.EXE is installed (required for unpacking PPDs).
136 */
137 gzip_exe = SysSearchPath('PATH', 'gzip.exe')
138 IF gzip_exe == '' THEN gzip_exe = STREAM( DIRECTORY() || '\gzip.exe', 'C', 'QUERY EXISTS')
139 IF gzip_exe == '' THEN DO
140 CALL VRMessage VRWindow(), NLSGetMessage( 78, 'GZIP.EXE'), NLSGetMessage( 79 ), 'E'
141 CALL Quit
142 END
143
144 /* Make sure CUPSPORT.EXE is installed.
145 */
146 port_exe = SysSearchPath('PATH', 'cupsport.exe')
147 IF port_exe == '' THEN port_exe = STREAM( DIRECTORY() || '\cupsport.exe', 'C', 'QUERY EXISTS')
148 IF port_exe == '' THEN DO
149 CALL VRMessage VRWindow(), NLSGetMessage( 78, 'CUPSPORT.EXE'), NLSGetMessage( 79 ), 'E'
150 CALL Quit
151 END
152
153 /* Make sure PRNTOBJ.EXE is installed.
154 */
155 prntobj_exe = SysSearchPath('PATH', 'prntobj.exe')
156 IF prntobj_exe == '' THEN prntobj_exe = STREAM( DIRECTORY() || '\prntobj.exe', 'C', 'QUERY EXISTS')
157 IF prntobj_exe == '' THEN DO
158 CALL VRMessage VRWindow(), NLSGetMessage( 78, 'PRNTOBJ.EXE'), NLSGetMessage( 79 ), 'E'
159 CALL Quit
160 END
161
162RETURN
163
164/*:VRX CHK_CREATEPM_Click
165*/
166CHK_CREATEPM_Click: PROCEDURE
167 set = VRGet( "CHK_CREATEPM", "Set" )
168 CALL VRSet 'DT_PRESDRV', 'Enabled', set
169 CALL VRSet 'DDCB_PRESDRV', 'Enabled', set
170RETURN
171
172/*:VRX ConfirmAndCreate
173*/
174ConfirmAndCreate: PROCEDURE EXPOSE globals.
175
176 globals.!create = 0
177 CALL VRLoadSecondary 'SW_CREATE', 'W'
178 IF globals.!create <> 1 THEN RETURN
179
180 CALL SetPage4
181 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
182 CALL NLSSetText 'DT_INFO', 'Caption', 50 /* 50: Creating printer... */
183 ok = CreatePrinter( globals.!os2printer )
184
185 CALL VRSet 'DT_INFO', 'Caption', ''
186 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
187
188 IF ok <> 0 THEN DO
189 SELECT
190 WHEN ok == 1 THEN reason = NLSGetMessage( 70 ) /* 70: Error importing PPD file. */
191 WHEN ok == 2 THEN reason = NLSGetMessage( 71, globals.!log1 ) /* 71: Error creating CUPS printer. See %1 for more information. */
192 WHEN ok == 3 THEN reason = NLSGetMessage( 72, globals.!log1 ) /* 72: Error creating printer object. See %1 for more information. */
193 OTHERWISE reason = NLSGetMessage( 73) /* 73: Unknown error. */
194 END
195 CALL VRMessage VRWindow(), NLSGetMessage( 60 ) ||, /* 60: The following error occurred when trying to create the printer: */
196 '0d0a0d0a'x || reason, NLSGetMessage( 56 ), 'E' /* 56: Error Creating Printer */
197 CALL NLSSetText 'DT_INFO', 'Caption', 52 /* 52: The printer could not be created. */
198 CALL NLSSetText 'PB_NEXT', 'Caption', 54 /* 54: Return */
199 END
200 ELSE DO
201 CALL NLSSetText 'DT_INFO', 'Caption', 51 /* 51: The printer has been created. */
202 CALL NLSSetText 'PB_NEXT', 'Caption', 53 /* 53: Create another */
203 END
204 CALL NLSSetText 'PB_CANCEL', 'Caption', 55 /* 55: Close */
205
206 CALL LINEOUT globals.!log1, ''
207 CALL LINEOUT globals.!log1
208
209RETURN
210
211/*:VRX CreateCupsPrinter
212*/
213CreateCupsPrinter: PROCEDURE EXPOSE globals.
214
215 od = DIRECTORY()
216 CALL DIRECTORY globals.!cupsdir'\sbin'
217 cups_cmd = 'lpadmin -p' globals.!prt_name '-E'
218 IF globals.!prt_info <> '' THEN
219 cups_cmd = cups_cmd '-D "'globals.!prt_info'"'
220 IF globals.!prt_loc <> '' THEN
221 cups_cmd = cups_cmd '-L "'globals.!prt_loc'"'
222 IF globals.!prt_dev <> '' THEN
223 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m' globals.!prt_dev
224 ELSE IF globals.!mode == 2 THEN
225 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -P "'globals.!prt_ppd'"'
226 ELSE DO
227 PARSE VAR globals.!prt_ppd (globals.!cupsdir)'\share\cups\model\' model
228 IF model == '' THEN model = globals.!prt_ppd
229 cups_cmd = cups_cmd '-v "'globals.!prt_port'" -m "'model'"'
230 END
231
232 /* Temporary until we can offer user configuration:
233 */
234 PARSE UPPER VALUE VALUE('LANG',,'OS2ENVIRONMENT') WITH 1 . 4 _ctry 6 .
235 IF ( WORDPOS( _ctry, 'US CA MX BO CO VE PH CL') > 0 ) THEN
236 page = 'Letter'
237 ELSE
238 page = 'A4'
239 cups_cmd = cups_cmd '-o media='page
240
241 CALL LINEOUT globals.!log1, 'Creating CUPS printer using:'
242 CALL LINEOUT globals.!log1, ' ' cups_cmd
243 IF VRFileExists( globals.!log2 ) THEN DO
244 CALL LINEOUT globals.!log2, ''
245 CALL LINEOUT globals.!log2
246 END
247 ADDRESS CMD '@' cups_cmd '1>NUL 2>>' globals.!log2
248 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
249 IF rc <> 0 THEN
250 CALL LINEOUT globals.!log1, 'See' globals.!log2 'for details.'
251 CALL DIRECTORY od
252 CALL LINEOUT globals.!log1, ''
253
254RETURN rc
255
256/*:VRX CreateOS2Printer
257*/
258/* Creates an OS/2 printer port, queue, and desktop object which point to
259 * the just-created CUPS printer. Uses the RINSTPRN utility from IBM.
260 */
261CreateOS2Printer: PROCEDURE EXPOSE globals.
262 ARG prnt_drv
263
264 IF globals.!remotecups == '' THEN DO
265 host = LoopbackName()
266 printer = globals.!prt_name
267 END
268 ELSE
269 PARSE VAR globals.!remotecups host printer .
270
271 printer_title = globals.!prt_info
272 printer_model = globals.!prt_nick
273 queue_name = GetQueueName( printer_title )
274 port_name = GetNextPortName('CUPS')
275
276 /* Determine the printer driver source directories/files. Yes, this is
277 * repeated from ImportPPD, but we have to do it again here because
278 * (a) we might not have gone through ImportPPD to get to this point, and
279 * (b) even if we did, the repository information might have changed.
280 */
281 driver_path = GetDriverSource( prnt_drv )
282 IF driver_path == '' THEN
283 /* Driver was not found in the repository. Check for a previously-
284 * installed copy under \OS2\DLL.
285 */
286 driver_path = STREAM( globals.!os2dir'\DLL\'prnt_drv'\'prnt_drv'.DRV', 'C', 'QUERY EXISTS')
287
288 IF driver_path == '' THEN DO
289 /* TODO allow the user to browse for the driver on their system */
290 CALL VRMessage VRWindow(),,
291 NLSGetMessage( 61, prnt_drv, globals.!os2dir'\DLL\'prnt_drv ),, /* 61: The printer driver %1 could not be located. If you have the driver files, please copy them to the directory %2 and then try again. */
292 NLSGetMessage( 57 ), 'E' /* 57: Driver Not Found */
293 RETURN 1
294 END
295
296 /* Create a new CUPS port.
297 */
298 port_ok = AddPort_CUPS( port_name, host, printer )
299 IF port_ok > 1 THEN
300 RETURN 1
301
302 /* New logic to create the printer ourselves (instead of using RINSTPRN).
303 * There are two necessary steps: make sure the driver is installed, and
304 * then create the printer object (which causes the underlying device and
305 * queue to be created automatically as well).
306 */
307
308 ok = InstallPrintDriver( prnt_drv, driver_path, printer_model )
309 CALL LINEOUT globals.!log1, 'InstallPrintDriver(' prnt_drv',' driver_path',' printer_model ') RC =' ok
310
311 IF ok == 0 THEN DO
312 ok = CreatePrinterObject( prnt_drv, printer_model,,
313 port_name, queue_name, printer_title )
314 CALL LINEOUT globals.!log1, 'CreatePrinterObject(' prnt_drv',' printer_model,
315 ',' port_name',' queue_name',' printer_title ') RC =' ok
316 IF ok <> 0 THEN DO
317 CALL LINEOUT globals.!log1, 'Failed to create printer object; trying again with generic driver.'
318 ok = CreatePrinterObject( prnt_drv, 'Generic Postscript Printer',,
319 port_name, queue_name, printer_title )
320 CALL LINEOUT globals.!log1, 'CreatePrinterObject(' prnt_drv', Generic Postscript Printer',
321 ',' port_name',' queue_name',' printer_title ') RC =' ok
322 END
323 END
324
325 IF ok <> 0 THEN DO
326 CALL LINEOUT globals.!log1, 'Printer object creation failed.'
327 IF SysIni('SYSTEM', 'PM_SPOOLER_PRINTER', 'ALL:', 'prt_keys.') == '' THEN DO
328 DO i = 1 TO prt_keys.0
329 key_val = SysIni('SYSTEM', 'PM_SPOOLER_PRINTER', prt_keys.0 )
330 PARSE VAR key_val _kport ';' _ktitle ';' .
331 IF ( _kport == port_name ) & ( _ktitle == printer_title ) THEN DO
332 CALL LINEOUT globals.!log1, 'Cleaning INI entry:' prt_keys.0 '=' key_val
333 CALL SysIni 'SYSTEM', 'PM_SPOOLER_PRINTER_DESCR', prt_keys.0, 'DELETE:'
334 CALL LINEOUT globals.!log1, 'Cleaning INI entry:' prt_keys.0 '=' key_val
335 CALL SysIni 'SYSTEM', 'PM_SPOOLER_PRINTER', prt_keys.0, 'DELETE:'
336 LEAVE
337 END
338 END
339 END
340 CALL LINEOUT globals.!log1, 'Deleting port' port_name
341 CALL DeletePort port_name
342 END
343 ELSE IF port_ok == 1 THEN DO
344 CALL VRMessage VRWindow(),,
345 NLSGetMessage( 62 ),, /* 62: The installed version of CUPS.PDR appears to be out of date. As a result, the desktop printer will not be usable until the desktop is restarted. */
346 NLSGetMessage( 58 ), 'W' /* 58: Port Driver Problem */
347 END
348
349RETURN ok
350
351/*:VRX CreatePrinter
352*/
353CreatePrinter: PROCEDURE EXPOSE globals.
354 ARG create_os2
355
356 /* Create the CUPS printer */
357 IF globals.!remotecups == '' THEN DO
358 ok = CreateCupsPrinter()
359 IF ok <> 0 THEN
360 RETURN 2 /** RC=2 Error running lpadmin **/
361 END
362
363 /* Now create the OS/2 printer object */
364 IF create_os2 == 1 & globals.!os2driver <> '' THEN DO
365
366 /* Make sure the presentation driver supports the printer */
367 IF globals.!mode == 2 THEN DO
368 /* Always (re)import when a PPD is provided by the user
369 */
370 ok = ImportPPD( globals.!os2driver, globals.!prt_ppd )
371 IF ok <> 0 THEN DO
372 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
373 buttons.1 = NLSGetMessage( 2 ) /* 2: OK */
374 buttons.2 = NLSGetMessage( 3 ) /* 3: Cancel */
375 buttons.0 = 2
376 ok = VRMessage( VRWindow(), NLSGetMessage( 69 ),, /* 69: The printer parameters could not ... PPD file. */
377 NLSGetMessage( 70 ), 'W',, /* 70: Error importing PPD file */
378 'buttons.', 1, 2 )
379 IF ok == 1 THEN
380 CALL PromptForPMName
381 ELSE
382 RETURN 1 /* RC=1 PPD import failed **/
383 END
384 END
385 ELSE IF PrinterExistsInDRV( globals.!os2driver, globals.!prt_nick ) == 0 THEN DO
386 cups_ppd = globals.!prt_ppd
387 IF cups_ppd == '' THEN
388 cups_ppd = STREAM( globals.!cupsdir'\etc\cups\ppd\'globals.!prt_name'.ppd', 'C', 'QUERY EXISTS')
389 IF cups_ppd == '' THEN
390 CALL PromptForPMName
391 ELSE DO
392 ok = ImportPPD(globals.!os2driver, cups_ppd )
393 IF ok <> 0 THEN DO
394 CALL LINEOUT globals.!log1, 'PPD import failed:' ok
395 CALL VRMessage VRWindow(), NLSGetMessage( 69 ), NLSGetMessage( 70 ), 'W'
396 CALL PromptForPMName
397 /* RETURN 1 RC=1 PPD import failed **/
398 END
399 END
400 END
401
402 ok = CreateOS2Printer( globals.!os2driver )
403 IF ok <> 0 THEN
404 RETURN 3 /** RC=3 Error running rinstprn **/
405 END
406
407RETURN 0
408
409/*:VRX DDCB_PROTOCOL_Change
410*/
411DDCB_PROTOCOL_Change: PROCEDURE EXPOSE globals.
412
413 idx = VRGet('DDCB_PROTOCOL', 'Selected')
414 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
415 SELECT
416 WHEN which == 1 THEN DO /* IPP */
417 show_queue = 1
418 show_user = 1
419 show_pass = 1
420 show_pick = 0
421 server_caption = 82 /* 82: Printer or server address: */
422 queue_caption = 84 /* 84: Printer queue name: */
423 userid_caption = 86 /* 86: User ID: */
424 END
425 WHEN which == 2 THEN DO /* SOCKET */
426 show_queue = 0
427 show_user = 0
428 show_pass = 0
429 show_pick = 0
430 server_caption = 82 /* 82: Printer or server address: */
431 queue_caption = 84 /* 84: Printer queue name: */
432 userid_caption = 86 /* 86: User ID: */
433 END
434 WHEN which == 3 THEN DO /* LPD */
435 show_queue = 1
436 show_user = 1
437 show_pass = 0
438 show_pick = 0
439 server_caption = 82 /* 82: Printer or server address: */
440 queue_caption = 84 /* 84: Printer queue name: */
441 userid_caption = 87 /* 87: User ID (if required): */
442 END
443 WHEN which == 4 THEN DO /* SMB */
444 show_queue = 1
445 show_user = 1
446 show_pass = 1
447 show_pick = 0
448 server_caption = 83 /* 83: Print server name: */
449 queue_caption = 85 /* 85: Shared printer name: */
450 userid_caption = 86 /* 86: User ID: */
451 END
452 OTHERWISE DO /* CUPS */
453 show_queue = 0
454 show_user = 0
455 show_pass = 0
456 show_pick = 1
457 server_caption = 88 /* 88: CUPS server name: */
458 queue_caption = 89 /* 89: CUPS printer name: */
459 userid_caption = 86 /* 86: User ID: */
460 END
461 END
462
463 r = NLSSetText('DT_SERVER', 'Caption', server_caption )
464 r = NLSSetText('DT_QUEUE', 'Caption', queue_caption )
465 r = NLSSetText('DT_USERID', 'Caption', userid_caption )
466
467 CALL VRSet 'DT_QUEUE', 'Visible', show_queue | show_pick
468 CALL VRSet 'EF_QUEUE', 'Visible', show_queue
469 CALL VRSet 'DT_USERID', 'Visible', show_user
470 CALL VRSet 'EF_USERID', 'Visible', show_user
471 CALL VRSet 'DT_PASSWORD', 'Visible', show_pass
472 CALL VRSet 'EF_PASSWORD', 'Visible', show_pass
473 CALL VRSet 'DDCB_CUPSQUEUES','Visible', show_pick
474
475RETURN
476
477/*:VRX EF_SERVER_LostFocus
478*/
479EF_SERVER_LostFocus: PROCEDURE EXPOSE globals. network_dialog
480
481 idx = VRGet('DDCB_PROTOCOL', 'Selected')
482 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
483 IF which <> 5 THEN RETURN
484
485 CALL VRMethod 'DDCB_CUPSQUEUES', 'Clear'
486 server = STRIP( VRGet("EF_SERVER", "Value"))
487 IF server == '' THEN RETURN
488
489 IF GetCupsQueues( server ) == 0 THEN RETURN
490
491 /* Sanity check to make sure the dialog wasn't dismissed before lpstat returned */
492 IF network_dialog <> 1 THEN RETURN
493
494 CALL VRMethod 'DDCB_CUPSQUEUES', 'AddStringList', 'cupsdest.'
495RETURN
496
497/*:VRX ExecRINSTPRN
498*/
499ExecRINSTPRN: PROCEDURE EXPOSE globals.
500 PARSE ARG dsc, drv, src, rsp
501
502 od = DIRECTORY()
503 CALL DIRECTORY src
504 rinstprn_cmd = 'rinstprn /DSC:'dsc '/DRV:'drv' /S:'src ,
505 '/T:'globals.!bootdrv '/L1:'globals.!logdir'\rinstprn.log' ,
506 '/R:'rsp
507
508 CALL LINEOUT globals.!log1, 'Creating OS/2 printer using:'
509 CALL LINEOUT globals.!log1, ' ' rinstprn_cmd
510 ADDRESS CMD '@' rinstprn_cmd '1>NUL 2>NUL'
511 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
512 IF rc <> 0 THEN
513 CALL LINEOUT globals.!log1, 'See' globals.!logdir'\rinstprn.log for details.'
514 CALL DIRECTORY od
515 CALL LINEOUT globals.!log1, ''
516
517RETURN rc
518
519/*:VRX Fini
520*/
521Fini:
522 window = VRWindow()
523 call VRSet window, "Visible", 0
524 drop window
525return 0
526
527/*:VRX GetCupsPorts
528*/
529GetCupsPorts: PROCEDURE EXPOSE globals.
530
531 CALL NLSSetText 'DT_INFO', 'Caption', 30 /* 30: Looking for connected printers. Please wait... */
532
533 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe -v 2>&1 |rxqueue'
534 snmp_cmd = globals.!cupsdir'\lib\cups\backend\snmp.exe 2>&1 |rxqueue'
535
536 _od = DIRECTORY()
537 CALL DIRECTORY globals.!cupsdir
538 listqueue = RXQUEUE('CREATE')
539 defqueue = RXQUEUE('SET', listqueue )
540
541 /* Use the SNMP backend to find network printers. We do this in addition
542 * to lpinfo because SNMP may provide the actual printer name. We'll
543 * merge this with the output of lpinfo in the next step.
544 */
545 ADDRESS CMD '@' snmp_cmd listqueue
546 DO QUEUED()
547 PARSE PULL line
548 PARSE VAR line _type _uri '"'_identifier'"' .
549 _uri = STRIP( _uri )
550 _type = STRIP( _type )
551 IF _uri == '' THEN ITERATE
552 IF _type <> 'network' THEN ITERATE
553 netnames._uri = _identifier
554 END
555
556 ADDRESS CMD '@' lpinfo_cmd listqueue
557 i = 0
558 DO QUEUED()
559 PARSE PULL line
560 PARSE VAR line _type _name
561 IF _name == '' THEN ITERATE
562 IF _type == 'network' & POS('://', _name ) > 0 THEN DO
563 PARSE VAR _name _protocol '://' _host '/' _queue
564 IF _protocol == 'socket' THEN _protocol = 'AppSocket'
565 ELSE _protocol = TRANSLATE( _protocol )
566 i = i + 1
567 IF _queue <> '' THEN _queue = '(queue '_queue')'
568 IF SYMBOL('netnames._name') == 'VAR' THEN
569 devices.i = NLSGetMessage( 32, _protocol, netnames._name, _host _queue ) /* 32: Detected network printer (%1) "%2" at %3 */
570 ELSE
571 devices.i = NLSGetMessage( 33, _protocol, _host _queue ) /* 33: Detected network printer (%1) at %2 */
572 END
573 ELSE IF _type <> 'direct' THEN ITERATE
574 ELSE DO
575 IF _name == 'hp' THEN ITERATE
576 i = i + 1
577 devices.i = NLSGetMessage( 35, _name ) /* 35: Local printer: %1 */
578 END
579 ports.i = _name
580 END
581 devices.0 = i
582
583 CALL RXQUEUE 'SET', defqueue
584 CALL RXQUEUE 'DELETE', listqueue
585 CALL DIRECTORY _od
586
587 CALL VRSet 'LB_SELECT', 'Painting', 0
588 CALL VRMethod 'LB_SELECT', 'AddStringList', 'devices.',, 'ports.'
589 CALL VRMethod 'LB_SELECT', 'AddString', NLSGetMessage( 34 ),, '' /* 34: Network printer (manual configuration) */
590 CALL VRSet 'LB_SELECT', 'Selected', 1
591 CALL VRSet 'LB_SELECT', 'Painting', 1
592
593 CALL VRSet 'DT_INFO', 'Caption', NLSGetMessage( 31 ) /* 31: Select the connection for this printer. */
594
595RETURN
596
597/*:VRX GetCupsPrinters
598*/
599GetCupsPrinters: PROCEDURE EXPOSE globals. manufacturers.
600
601 CALL NLSSetText 'DT_INFO', 'Caption', 20 /* 20: Getting list of supported printers. Please wait... */
602
603 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe --exclude-schemes drv -m 2>&1 |rxqueue'
604
605 _od = DIRECTORY()
606 CALL DIRECTORY globals.!cupsdir
607 listqueue = RXQUEUE('CREATE')
608 defqueue = RXQUEUE('SET', listqueue )
609
610 ADDRESS CMD '@' lpinfo_cmd listqueue
611 i = 0
612 makers = ''
613 DO QUEUED()
614 PARSE PULL line
615 IF LEFT( line, 6 ) == 'drv://' THEN ITERATE
616 IF WORD( line, 1 ) == 'raw' THEN ITERATE
617 PARSE VAR line _ppd '.ppd.gz ' _name
618 _ppd = _ppd'.ppd.gz'
619 IF _name == '' THEN DO
620 PARSE VAR line _ppd '.ppd ' _name
621 _ppd = _ppd'.ppd'
622 END
623 IF _name == '' THEN DO
624 PARSE VAR line _ppd _name
625 END
626 IF _name <> '' THEN DO
627 PARSE VAR _name _brand _model
628 IF WORDPOS( _brand, makers ) == 0 THEN makers = makers || _brand' '
629 i = i + 1
630 ppds.i = _ppd
631 models.i = _name
632 END
633 END
634 ppds.0 = i
635 models.0 = i
636
637 CALL RXQUEUE 'SET', defqueue
638 CALL RXQUEUE 'DELETE', listqueue
639 CALL DIRECTORY _od
640
641/* Now build the 'manufacturers' stem.
642 * This stem takes the following format:
643 * manufacturers.0 number of manufacturers
644 * manufacturers.i.!name manufacturer name (e.g. 'Apple')
645 * manufacturers.i.!printers.0 number of printer models
646 * manufacturers.i.!printers.j.!model printer model name, short form (e.g. 'LaserWriter 330')
647 * manufacturers.i.!printers.j.!type driver version/type (e.g. 'Gutenprint v5.2.7')
648 * manufacturers.i.!printers.j.!driver the internal CUPS printer driver name (PPD or URI)
649 * - by preference this is the "simplified" version if available
650 * manufacturers.i.!printers.j.!remark any distinguishing remarks (e.g. 'Simplified')
651 * manufacturers.i.!printers.j.!driver2 alternate driver in case there is more than one (PPD or URI)
652 * - if defined this is usually the non-"simplified" driver
653 * manufacturers.i.!printers.j.!remark2 any distinguishing remarks for the alternate driver
654 */
655 manufacturers.0 = WORDS( makers )
656 DO i = 1 TO manufacturers.0
657 manufacturers.i.!name = WORD( makers, i )
658 manufacturers.i.!printers.0 = 0
659 END
660
661 DO i = 1 TO models.0
662 PARSE VAR models.i _brand _model ' - CUPS+' _type
663 IF _type == '' THEN DO
664 PARSE VAR models.i _brand _model ',' _type
665 IF WORD( _type, 1 ) == 'hpcups' THEN
666 _type = 'HPLIP' /* SUBWORD( _type, 2 ) */
667 ELSE IF ( _type == '') & ( LEFT( ppds.i, 3 ) == 'hp/') THEN
668 _type = 'HPLIP'
669 END
670 man = WORDPOS( _brand, makers )
671 IF man == 0 THEN ITERATE
672
673 PARSE VAR _type _version 'Simplified' .
674 _version = STRIP( _version )
675 _flag = RIGHT( _type, 10 )
676
677 count = manufacturers.man.!printers.0
678 IF count > 0 THEN DO
679 /* If there are two or more printers defined with the same model
680 * name and driver version, keep the first and last as the regular
681 * and alternate drivers; if one if them is 'Simplified', make that
682 * the regular driver by preference.
683 */
684 IF ( TRANSLATE( manufacturers.man.!printers.count.!model ) == TRANSLATE( _model )) THEN DO
685 IF ( manufacturers.man.!printers.count.!type == _version ) THEN DO
686 IF ( WORD( _version, 1 ) == 'Gutenprint') & ( _flag == 'Simplified') THEN DO
687 manufacturers.man.!printers.count.!driver2 = manufacturers.man.!printers.count.!driver
688 manufacturers.man.!printers.count.!remark2 = manufacturers.man.!printers.count.!remark
689 manufacturers.man.!printers.count.!driver = ppds.i
690 manufacturers.man.!printers.count.!remark = 'Simplified'
691 END
692 ELSE DO
693 manufacturers.man.!printers.count.!driver2 = ppds.i
694 IF _flag == 'Simplified' THEN
695 manufacturers.man.!printers.count.!remark2 = 'Simplified'
696 ELSE
697 manufacturers.man.!printers.count.!remark2 = ''
698 END
699 ITERATE
700 END
701 END
702 END
703 count = count + 1
704 manufacturers.man.!printers.count.!model = _model
705 manufacturers.man.!printers.count.!type = _version
706 manufacturers.man.!printers.count.!driver = ppds.i
707 IF _flag == 'Simplified' THEN
708 manufacturers.man.!printers.count.!remark = 'Simplified'
709 ELSE
710 manufacturers.man.!printers.count.!remark = ''
711 manufacturers.man.!printers.count.!driver2 = ''
712 manufacturers.man.!printers.count.!remark2 = ''
713 manufacturers.man.!printers.0 = count
714 END
715
716 /* Add one more category for special items ...
717 */
718 count = manufacturers.0 + 1
719 manufacturers.count.!name = NLSGetMessage( 22 ) /* 22: -- Custom -- */
720 manufacturers.count.!printers.0 = 1
721 manufacturers.count.!printers.1.!model = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
722 manufacturers.count.!printers.1.!driver = ''
723 manufacturers.count.!printers.1.!type = ''
724 manufacturers.count.!printers.1.!remark = manufacturers.count.!printers.1.!model
725 manufacturers.count.!printers.1.!driver2 = ''
726 manufacturers.count.!printers.1.!remark2 = ''
727 manufacturers.0 = count
728
729RETURN
730
731/*:VRX GetCupsQueues
732*/
733GetCupsQueues: PROCEDURE EXPOSE globals. cupsdest.
734 ARG hostaddr
735
736 /* Try to find lpstat.exe */
737 lpstat_exe = STREAM( globals.!cupsdir'\bin\lpstat.exe', 'C', 'QUERY EXISTS')
738 IF lpstat_exe == '' THEN lpstat_exe = STREAM( globals.!mydir'\lpstat.exe', 'C', 'QUERY EXISTS')
739 IF lpstat_exe == '' THEN lpstat_exe = STREAM( DIRECTORY()'\lpstat.exe', 'C', 'QUERY EXISTS')
740 IF lpstat_exe == '' THEN lpstat_exe = SysSearchPath('PATH', 'lpstat.exe')
741 IF lpstat_exe == '' THEN RETURN 0
742
743 sq = RXQUEUE('CREATE')
744 oq = RXQUEUE('SET', sq )
745
746 CALL VRSet VRWindow(), 'Pointer', 'WAIT'
747 ADDRESS CMD '@'lpstat_exe '-h' hostaddr '-p -c 2>&1 |rxqueue' sq
748 CALL VRSet VRWindow(), 'Pointer', '<default>'
749
750 _count = 0
751 DO QUEUED()
752 PARSE PULL _info
753 IF _info == '' THEN ITERATE
754 IF _info == 'lpstat: Connection refused' THEN LEAVE
755 IF WORD( _info, 1 ) == 'printer' THEN
756 PARSE VAR _info 'printer' _qname .
757 ELSE IF WORD( info, 1 ) == 'class' THEN
758 PARSE VAR _info 'class' _qname .
759 ELSE ITERATE
760 IF _qname == '' THEN ITERATE
761 _count = _count + 1
762 cupsdest._count = _qname
763 END
764 CALL RXQUEUE 'DELETE', sq
765 CALL RXQUEUE 'SET', oq
766
767 cupsdest.0 = _count
768
769RETURN _count
770
771/*:VRX Halt
772*/
773Halt:
774 signal _VREHalt
775return
776
777/*:VRX ImportPPD
778*/
779ImportPPD: PROCEDURE EXPOSE globals.
780 /* Import a new PPD file into a PostScript driver.
781 */
782 ARG driver, ppdfile
783 IF driver == '' THEN driver = 'PSCRIPT'
784
785 CALL LINEOUT globals.!log1, 'Going to import PPD file into driver' driver'.'
786
787 /***
788 *** First, get our working directories and locate the driver source files.
789 ***/
790
791 mustcopy = 0
792 driver_path = GetDriverSource( driver )
793 IF driver_path == '' THEN DO
794 /* No source found. We'll have to try copying the actual installed
795 * driver files from under \OS2\DLL.
796 */
797 CALL LINEOUT globals.!log1, 'Driver source not found.'
798 driver_path = STREAM( globals.!os2dir'\DLL\'driver'\'driver'.DRV', 'C', 'QUERY EXISTS')
799 mustcopy = 1
800 END
801 IF driver_path <> '' THEN DO
802 srcdir = VRParseFilePath( driver_path, 'DP')
803 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
804 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
805 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
806 DROP srcdir
807 END
808
809 /* Driver (or one of its required files) was not found.
810 */
811 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
812 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
813 DO
814 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
815 /* TODO should prompt for installable driver package? */
816 RETURN 1 /** RC=1 Missing required driver files **/
817 END
818
819 IF mustcopy <> 0 THEN DO
820 /* Looks like the driver wasn't shipped with the OS; we have a source
821 * (either the active files from \OS2\DLL, or a package provided by
822 * the user), but we need somewhere for them to live. The user needs
823 * to tell us where, because they're going to have to specify the
824 * directory later on if they install the driver from PM.
825 */
826 pbtn.1 = NLSGetMessage( 2 ) /* 2: OK */
827 pbtn.2 = NLSGetMessage( 3 ) /* 3: Cancel */
828 pbtn.0 = 2
829 ptext = NLSGetMessage( 63, driver ) ||, /* 63: The install files for the %1 driver could not be located. These files will be recreated from the driver files which are already installed on your system. */
830 '0d0a0d0a'x || NLSGetMessage( 64 ) /* 64: Please enter the directory where the install files will be placed. */
831
832 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
833 IF drvr_dir == '' THEN
834 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
835 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir', NLSGetMessage( 59 ), 'pbtn.', 1, 2 ) /* 59: Enter Directory */
836 IF ok <> 1 THEN RETURN 9 /** RC=9 User cancelled **/
837 drvr_dir = VRExpandFileName( drvr_dir )
838 DO WHILE drvr_dir == ''
839 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
840 'Enter Directory', 'pbtn.', 1, 2 )
841 drvr_dir = VRExpandFileName( drvr_dir )
842 END
843
844 /* Now create the new directory, if necessary */
845 IF VRMkDir( drvr_dir ) == 0 THEN
846 RETURN 3 /** RC=3 Failed to copy driver files **/
847 IF CopyDriverToSource( driver_path, drvr_dir ) == 0 THEN
848 RETURN 3 /** RC=3 Failed to copy driver files **/
849
850 /* Make sure we save the location (we'll need this information later) */
851 CALL VRSetIni 'PM_INSTALL', driver'_DIR', drvr_dir||'00'x, 'USER'
852
853 /* Now point to the new copy as the driver we will work on */
854 driver_path = drvr_dir'\'driver'.DRV'
855 END
856
857 workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
858 ok = VrMkDir( workdir )
859 IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
860 IF ok <> 1 THEN
861 RETURN 2 /** RC=2 Failed to create temporary directory **/
862
863 SELECT
864 WHEN driver == 'ECUPS' THEN ppddir = globals.!repository'\PPD_E'
865 WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
866 WHEN driver == 'PSPRINT' THEN ppddir = globals.!repository'\PPD_PS'
867 WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
868 WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
869 OTHERWISE ppddir = globals.!repository'\PPD'
870 END
871
872 /* Make sure ppddir (for keeping PPD files) exists */
873 CALL SysFileTree ppddir, 'dirs.', 'DO'
874 IF dirs.0 == 0 THEN DO
875 ok = VrMkDir( ppddir )
876 IF ok <> 1 THEN
877 RETURN 4 /** RC=4 Failed to create PPD directory **/
878 END
879
880 /***
881 *** Now do the actual work.
882 ***/
883
884 /* Back up the modified files (AUXPRINT.PAK and <driver>.DRV) if we're
885 * working out of the repository.
886 IF mustcopy == 0 THEN DO
887 repfiles.0 = 2
888 repfiles.1 = driver'.DRV'
889 repfiles.2 = 'AUXPRINT.PAK'
890 CALL BackupDrivers driver_path
891 END
892 */
893
894 /* Copy the needed driver files to our working directories.
895 */
896 drv_out = workdir'\OUT\'driver'.DRV'
897 pin_exe = workdir'\PIN.EXE'
898 ppd_exe = workdir'\PPDENC.EXE'
899 ok = VRCopyFile( driver_path, drv_out )
900 IF ok == 1 THEN ok = VRCopyFile( pin, pin_exe )
901 IF ok == 1 THEN ok = VRCopyFile( ppdenc, ppd_exe )
902 IF ok == 0 THEN DO
903 RETURN 3 /*** RC=3 Failed to copy driver files ***/
904 END
905
906 /* Set up the output redirection.
907 */
908 nq = RXQUEUE('CREATE')
909 oq = RXQUEUE('SET', nq )
910
911 /* If the PPD file is compressed, uncompress it.
912 */
913 IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
914 decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
915 CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
916 ADDRESS CMD '@gzip -c -d' ppdfile '| RXQUEUE' nq
917 DO QUEUED()
918 PARSE PULL line
919 CALL LINEOUT decppd, line
920 END
921 CALL LINEOUT decppd
922 ppdfile = decppd
923 END
924
925 IF VRFileExists( ppdfile ) == 0 THEN DO
926 CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
927 RETURN 5 /** RC=5 PPD import failed **/
928 END
929
930 ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
931
932 /* Now we have to clean up and validate the PPD file so PIN can use it.
933 * First, PPDENC converts the codepage if necessary, and copies the results
934 * to our working directory.
935 */
936 CALL LINEOUT globals.!log1, 'Converting PPD with:' ppd_exe ppdfile ppd_use
937 ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>NUL | RXQUEUE' nq
938 DO QUEUED()
939 PULL output
940 CALL LINEOUT globals.!log2, output
941 END
942 CALL LINEOUT globals.!log2, ''
943 CALL LINEOUT globals.!log2
944
945 IF VRFileExists( ppd_use ) == 0 THEN DO
946 CALL LINEOUT globals.!log1, 'Hmm,' ppd_use 'was not created. Copying manually.'
947 CALL VRCopyFile ppdfile, ppd_use
948 END
949
950 /* Next we strip out some problematic lines used which are often encountered
951 * in (e.g.) CUPS-based PPD files.
952 */
953 CALL CleanPPD ppd_use, globals.!log1
954
955 /* Preparation complete. Now do the import.
956 */
957 count = 0
958 ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>NUL | RXQUEUE' nq
959 DO QUEUED()
960 PARSE PULL output
961 CALL LINEOUT globals.!log2, output
962 PARSE VAR output . 'OK (' nickname
963 IF nickname <> '' THEN DO
964 count = count + 1
965 newprinters.count = STRIP( nickname, 'T', ')')
966 END
967 END
968 newprinters.0 = count
969 CALL LINEOUT globals.!log2, ''
970 CALL LINEOUT globals.!log2
971
972 /* End the output redirection.
973 */
974 CALL RXQUEUE 'SET', oq
975 CALL RXQUEUE 'DELETE', nq
976
977
978 /***
979 *** Post-import processing.
980 ***/
981
982 IF newprinters.0 == 0 THEN DO
983 RETURN 5 /** RC=5 PPD import failed **/
984 END
985
986 /*IF mustcopy == 0 THEN DO*/
987 IF pmdx <> '' THEN DO
988 /* If we're working out of the repository, we need to update the
989 * driver table in PRDESC.LST to add the new driver(s).
990 */
991
992 CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with' newprinters.0 'new entries ...'
993 count = 0
994 match_drv = '('driver'.DRV)'
995 match_len = LENGTH( match_drv )
996
997 /* First, copy all lines that don't refer to the driver just updated */
998 DO WHILE LINES( globals.!prdesc )
999 _line = LINEIN( globals.!prdesc )
1000 IF TRANSLATE( RIGHT( _line, LENGTH( match_len ))) == match_drv THEN ITERATE
1001 count = count + 1
1002 defs.count = _line
1003 END
1004 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
1005
1006 /* Next, create a new list for the updated driver and merge that in */
1007 newlist = workdir'\'driver'.LST'
1008 CALL CreateDriverList driver, newlist
1009 DO WHILE LINES( newlist )
1010 _line = LINEIN( newlist )
1011 count = count + 1
1012 defs.count = _line
1013 END
1014 defs.0 = count
1015
1016 /* Now sort the list and recreate PRDESC.LST */
1017 CALL SysStemSort 'defs.',, 'I'
1018 prdesc_tmp = workdir'\PRDESC.LST'
1019 IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
1020 CALL VRDeleteFile prdesc_tmp
1021 DO i = 1 TO defs.0
1022 CALL LINEOUT prdesc_tmp, defs.i
1023 END
1024 CALL LINEOUT prdesc_tmp
1025 ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
1026 IF ok == 0 THEN DO
1027 RETURN 6 /** RC=6 Error updating PRDESC.LST **/
1028 END
1029 CALL VRDeleteFile prdesc_tmp
1030
1031 END
1032
1033 /* Finally, copy the updated driver files.
1034 */
1035 target = VRParseFilePath( driver_path, 'DP')
1036 CALL LINEOUT globals.!log1, 'Copying files from' workdir'\OUT to' target
1037 ADDRESS CMD '@UNLOCK' target'\'driver'.DRV 2>NUL 1>NUL'
1038 ok = VRCopyFile( workdir'\OUT\'driver'.DRV', target'\'driver'.DRV')
1039 IF ok == 1 THEN
1040 ok = VRCopyFile( workdir'\OUT\AUXPRINT.PAK', target'\AUXPRINT.PAK')
1041 IF ok == 1 THEN DO
1042 /* Copy the updated files to \OS2\DLL\<driver>, replacing any
1043 * existing copies. (This prevents problems if the OS/2 driver
1044 * installation doesn't/fails to copy them, which can happen under
1045 * some circumstances.)
1046 */
1047 IF VRFileExists( globals.!os2dir'\DLL\'driver ) THEN DO
1048 CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
1049 globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
1050 ADDRESS CMD '@UNLOCK' workdir'\OUT\'driver'.DRV 2>NUL 1>NUL'
1051 CALL VRCopyFile workdir'\OUT\'driver'.DRV',,
1052 globals.!os2dir'\DLL\'driver'\'driver'.DRV'
1053 END
1054 END
1055 IF ok == 0 THEN DO
1056 CALL LINEOUT globals.!log1, VRError()
1057 RETURN 3 /*** RC=3 Failed to copy driver files ***/
1058 END
1059
1060 CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
1061 DO i = 1 TO newprinters.0
1062 CALL LINEOUT globals.!log1, ' ->' newprinters.i
1063 END
1064 CALL LINEOUT globals.!log1, ''
1065 CALL LINEOUT globals.!log1
1066
1067 /* Clean up our work directories.
1068 */
1069 CALL VRDeleteFile workdir'\OUT\*'
1070 CALL VRDeleteFile workdir'\*'
1071 CALL VRRmDir( workdir'\OUT')
1072 CALL VRRmDir( workdir )
1073
1074RETURN 0
1075
1076/*:VRX Init
1077*/
1078Init:
1079 SIGNAL ON NOVALUE NAME __NoValue
1080
1081 /* Hide the VX-REXX console window
1082 */
1083 CALL VRSet 'Console', 'WindowListTitle', ''
1084
1085 CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
1086 CALL SysLoadFuncs
1087
1088 CALL LoadSettings
1089 CALL SetLanguage
1090 CALL CheckPrograms
1091
1092 _force_remote = 0
1093 globals.!prt_ppd = ''
1094 IF InitArgs.0 > 0 THEN
1095 DO i = 1 TO InitArgs.0
1096 InitArgs.i = TRANSLATE( InitArgs.i )
1097 IF VRIsDir( InitArgs.i ) THEN
1098 globals.!cupsdir = InitArgs.1
1099 ELSE IF InitArgs.i == '/R' THEN DO
1100 globals.!cupsdir = ''
1101 _force_remote = 1
1102 END
1103 ELSE IF VRFileExists( InitArgs.i ) THEN DO
1104 _filetype = VRParseFileName( InitArgs.i, 'E')
1105 IF _filetype == 'PPD' THEN
1106 globals.!prt_ppd = InitArgs.i
1107 END
1108 END
1109
1110 IF globals.!cupsdir == '' & \_force_remote THEN
1111 CALL VRMessage VRWindow(),,
1112 NLSGetMessage( 65, 'CUPSWIZ F:\CUPS') ||, /* 65: CUPS could not be located ... on the command line to this program (e.g "%1"). */
1113 '0d0a0d0a'x || NLSGetMessage( 66 ),, /* 66: Only remote CUPS queues ... start this program with the /R parameter.) */
1114 NLSGetMessage( 28 ), 'E' /* 28: CUPS Path Not Found or Not Valid */
1115
1116 /* Delete the error log file each time the program starts.
1117 */
1118 IF VRFileExists( globals.!log2 ) THEN
1119 CALL VRDeleteFile globals.!log2
1120
1121 window = VRWindow()
1122 call VRMethod window, "CenterWindow"
1123 call VRSet window, "Visible", 1
1124 call VRMethod window, "Activate"
1125 drop window
1126
1127 manufacturers.0 = 0
1128 CALL SetPage1
1129
1130RETURN
1131
1132/*:VRX InitMessageLog
1133*/
1134/* Initialize the message logfile. Unlike the error log, which is cleared and
1135 * recreated every time the program starts, the message log is appended to
1136 * until it reaches 100kB in size. If the message log is larger than 100kB when
1137 * this function is called, it is renamed (with '~' appended to the name) and
1138 * a new message log is started.
1139 */
1140InitMessageLog: PROCEDURE EXPOSE globals.
1141
1142 logsize = STREAM( globals.!log1, 'C', 'QUERY SIZE')
1143 IF ( logsize <> '') & ( logsize > 102400 ) THEN DO
1144 CALL VRCopyFile globals.!log1, globals.!log1 || '~'
1145 CALL VRDeleteFile globals.!log1
1146 END
1147
1148 datestr = DATE('L') TIME('N')
1149 CALL LINEOUT globals.!log1, '--[' datestr ']' ||,
1150 COPIES('-', 73 - LENGTH( datestr ))
1151RETURN
1152
1153/*:VRX LB_BRAND_Click
1154*/
1155LB_BRAND_Click: PROCEDURE EXPOSE globals. manufacturers.
1156
1157 CALL VRSet 'WN_MAIN', 'StatusText', ''
1158
1159 index = VRGet('LB_BRAND', 'Selected')
1160 IF index == 0 THEN RETURN
1161
1162 item = VRMethod('LB_BRAND', 'GetItemData', index )
1163 IF item == 0 THEN RETURN
1164
1165 DO i = 1 TO manufacturers.item.!printers.0
1166 models.i = manufacturers.item.!printers.i.!model
1167 /* ppds.i = manufacturers.item.!printers.i.!driver */
1168 IF manufacturers.item.!printers.i.!driver == '' THEN
1169 ppds.i = ''
1170 ELSE
1171 ppds.i = i
1172
1173/* DEBUG
1174say 'Model: ' manufacturers.item.!printers.i.!model
1175say 'Driver: ' manufacturers.item.!printers.i.!driver
1176say ' ' manufacturers.item.!printers.i.!longname
1177if manufacturers.item.!printers.i.!driver2 <> '' then
1178 say 'Alternate:' manufacturers.item.!printers.i.!driver2
1179if manufacturers.item.!printers.i.!longname2 <> '' then
1180 say ' ' manufacturers.item.!printers.i.!longname2
1181say 'Type: ' manufacturers.item.!printers.i.!type
1182say '---'
1183 */
1184
1185 END
1186 models.0 = manufacturers.item.!printers.0
1187 ppds.0 = manufacturers.item.!printers.0
1188
1189 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1190 CALL VRMethod 'LB_SELECT', 'Clear'
1191 CALL VRSet 'LB_SELECT', 'Painting', 0
1192 CALL VRMethod 'LB_SELECT', 'AddStringList', 'models.',, 'ppds.'
1193 CALL VRSet 'LB_SELECT', 'Painting', 1
1194 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1195/* CALL VRSet 'LB_SELECT', 'Selected', 1 */
1196
1197RETURN
1198
1199/*:VRX LB_SELECT_Click
1200*/
1201LB_SELECT_Click: PROCEDURE EXPOSE globals. manufacturers.
1202 SELECT
1203 WHEN globals.!page == 1 THEN DO
1204 CALL VRSet 'WN_MAIN', 'StatusText', ''
1205
1206 brand = VRGet('LB_BRAND', 'Selected')
1207 IF brand == 0 THEN RETURN
1208 selected = VRGet('LB_SELECT', 'Selected')
1209 IF selected == 0 THEN RETURN
1210 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1211 IF which <> '' THEN DO
1212 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1213 IF man == '' THEN RETURN
1214 make = manufacturers.man.!name
1215 model = manufacturers.man.!printers.which.!model
1216 driver = manufacturers.man.!printers.which.!type
1217 IF WORD( driver, 1 ) == 'hpcups' THEN driver = 'HPLIP'
1218 remark = manufacturers.man.!printers.which.!remark
1219 IF driver == '' THEN
1220 type = ''
1221 ELSE IF remark == '' THEN
1222 type = ' ('driver')'
1223 ELSE
1224 type = ' ('driver' - 'remark')'
1225 CALL VRSet 'WN_MAIN', 'StatusText', make model type
1226 END
1227 END
1228
1229 OTHERWISE NOP
1230 END
1231
1232 CALL VRSet 'PB_NEXT', 'Enabled', 1
1233RETURN
1234
1235/*:VRX LoadSettings
1236*/
1237LoadSettings: PROCEDURE EXPOSE globals.
1238
1239 me = VRGet('Application', 'Program')
1240 IF me == '' THEN PARSE SOURCE . . me
1241 globals.!mydir = VRParseFilePath( me, 'DP')
1242
1243 /* Get CUPS paths.
1244 */
1245 PARSE VALUE VRGetIni('eCups', 'CUPS', 'USER') WITH cupsdrv '00'x
1246 IF cupsdrv == '' THEN
1247 cupsdrv = VRParseFilePath( me, 'D') || ':'
1248 ELSE
1249 cupsdrv = STRIP( cupsdrv, 'T', '\')
1250 globals.!cupsdir = cupsdrv'\cups'
1251
1252 /* Get system paths.
1253 */
1254 globals.!bootdrv = SysBootDrive()
1255 IF globals.!bootdrv == '' THEN
1256 globals.!bootdrv = FILESPEC('DRIVE', VALUE('OS2_SHELL',,'OS2ENVIRONMENT'))
1257 globals.!os2dir = globals.!bootdrv'\OS2'
1258 globals.!tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
1259 IF globals.!tmpdir == '' THEN
1260 globals.!tmpdir = VALUE('TEMP',,'OS2ENVIRONMENT')
1261 IF globals.!tmpdir == '' THEN
1262 globals.!tmpdir = globals.!mydir
1263 globals.!logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
1264 IF globals.!logdir == '' THEN
1265 globals.!logdir = globals.!mydir
1266
1267 globals.!log1 = globals.!logdir'\cupswiz.l1'
1268 globals.!log2 = globals.!logdir'\cupswiz.l2'
1269
1270 /* Get printer-related paths.
1271 */
1272 PARSE VALUE VRGetIni('PM_INSTALL', 'PDR_DIR', 'USER') WITH repos_dir '00'x .
1273 globals.!repository = repos_dir
1274 globals.!prdrv = STREAM( globals.!os2dir'\install\prdrv.lst', 'C', 'QUERY EXISTS')
1275 globals.!prdesc = STREAM( globals.!os2dir'\install\prdesc.lst', 'C', 'QUERY EXISTS')
1276
1277 /* Set the language file name.
1278 */
1279 globals.!nlsfile = 'cupswz'
1280
1281RETURN 0
1282
1283/*:VRX LoopbackName
1284*/
1285/* Check to see if 'localhost' is defined in the HOSTS file. If not, we'll
1286 * have to use '127.0.0.1' instead.
1287 */
1288LoopbackName: PROCEDURE
1289
1290 lo_name = '127.0.0.1'
1291 etcdir = VALUE('ETC',,'OS2ENVIRONMENT')
1292 IF etcdir <> '' THEN DO
1293 hosts = STREAM( etcdir'\HOSTS', 'C', 'QUERY EXISTS')
1294 IF hosts <> '' THEN DO
1295 CALL LINEIN hosts, 1, 0
1296 DO WHILE LINES( hosts ) > 0
1297 _hostdef = TRANSLATE( LINEIN( hosts ))
1298 _hostdef = TRANSLATE( _hostdef, ' ', '09'x )
1299 IF WORDPOS('LOCALHOST', _hostdef ) == 2 THEN DO
1300 lo_name = 'localhost'
1301 LEAVE
1302 END
1303 END
1304 END
1305 END
1306
1307RETURN lo_name
1308
1309/*:VRX PB_ABOUT_Click
1310*/
1311PB_ABOUT_Click:
1312 CALL SW_ABOUT_Close
1313RETURN
1314
1315/*:VRX PB_CANCEL_Click
1316*/
1317PB_CANCEL_Click:
1318 CALL Quit
1319return
1320
1321/*:VRX PB_CREATECANCEL_Click
1322*/
1323PB_CREATECANCEL_Click:
1324 CALL SW_CREATE_Close
1325RETURN
1326
1327/*:VRX PB_CREATEOK_Click
1328*/
1329PB_CREATEOK_Click:
1330
1331 create_os2 = VRGet('CHK_CREATEPM', 'Set')
1332 globals.!os2printer = create_os2
1333 globals.!os2driver = VRGet('DDCB_PRESDRV', 'SelectedString')
1334 globals.!create = 1
1335
1336 CALL SW_CREATE_Close
1337
1338RETURN
1339
1340/*:VRX PB_MODELCANCEL_Click
1341*/
1342PB_MODELCANCEL_Click:
1343 CALL SW_MODEL_Close
1344 globals.!prt_nick = 'Generic PostScript Printer'
1345RETURN
1346
1347/*:VRX PB_MODELOK_Click
1348*/
1349PB_MODELOK_Click:
1350 globals.!prt_nick = VRGet( "LB_OS2MODELS", "SelectedString" )
1351 CALL SW_MODEL_Close
1352RETURN
1353
1354/*:VRX PB_NETCANCEL_Click
1355*/
1356PB_NETCANCEL_Click:
1357 CALL SW_NETWORK_Fini
1358RETURN
1359
1360/*:VRX PB_NETOK_Click
1361*/
1362PB_NETOK_Click: PROCEDURE EXPOSE globals. port
1363
1364 idx = VRGet('DDCB_PROTOCOL', 'Selected')
1365 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
1366 server = STRIP( VRGet("EF_SERVER", "Value"))
1367 pqueue = STRIP( VRGet("EF_QUEUE", "Value"))
1368 cqueue = STRIP( VRGet("DDCB_CUPSQUEUES","Value"))
1369 userid = STRIP( VRGet("EF_USERID", "Value"))
1370 passwd = STRIP( VRGet("EF_PASSWORD", "Value"))
1371
1372 invalid = 0
1373
1374 SELECT
1375 WHEN which == 1 THEN DO /* IPP */
1376 IF server == '' | pqueue == '' THEN invalid = 1
1377 uri = 'ipp://'
1378 IF userid <> '' THEN DO
1379 uri = uri || userid
1380 IF passwd <> '' THEN uri = uri':'passwd
1381 uri = uri'@'
1382 END
1383 uri = uri || server'/'pqueue
1384 END
1385 WHEN which == 2 THEN DO /* SOCKET */
1386 IF server == '' THEN invalid = 1
1387 uri = 'socket://'server
1388 END
1389 WHEN which == 3 THEN DO /* LPD */
1390 IF server == '' THEN invalid = 1
1391 IF pqueue == '' THEN pqueue = '*'
1392 IF userid <> '' THEN
1393 uri = 'ipp://'userid'@'server'/'pqueue
1394 ELSE
1395 uri = 'lpd://'server'/'pqueue
1396 END
1397 WHEN which == 4 THEN DO /* SMB */
1398 IF server == '' | pqueue == '' THEN invalid = 1
1399 uri = 'smb://'
1400 IF userid <> '' THEN DO
1401 uri = uri || userid
1402 IF passwd <> '' THEN uri = uri':'passwd
1403 uri = uri'@'
1404 END
1405 uri = uri || server'/'pqueue
1406 END
1407 OTHERWISE DO /* Existing CUPS */
1408 IF server == '' | cqueue == '' THEN invalid = 1
1409 ELSE DO
1410 globals.!remotecups = server cqueue
1411 uri = ''
1412 END
1413 END
1414 END
1415
1416 IF invalid == 1 THEN DO
1417 CALL VRMessage VRWindow(), NLSGetMessage( 74 ),, /* 74: Missing required value(s). */
1418 NLSGetMessage( 75 ), 'E' /* 75: Missing Value(s) */
1419 RETURN
1420 END
1421
1422 port = uri
1423 CALL SW_NETWORK_Fini
1424
1425RETURN
1426
1427/*:VRX PB_NEXT_Click
1428*/
1429PB_NEXT_Click: PROCEDURE EXPOSE globals. manufacturers.
1430
1431 SELECT
1432 WHEN globals.!page == 1 THEN DO
1433 brand = VRGet('LB_BRAND', 'Selected')
1434 IF brand == 0 THEN RETURN
1435 selected = VRGet('LB_SELECT', 'Selected')
1436 IF selected == 0 THEN RETURN
1437
1438 CALL VRSet 'WN_MAIN', 'StatusText', ''
1439
1440 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1441 IF which == '' THEN DO
1442 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1443 ppd = VRFileDialog( VRWindow(), NLSGetMessage( 24 ), 'O', '*.ppd') /* 24: Select PPD */
1444 IF ppd == '' THEN RETURN
1445 globals.!prt_ppd = ppd
1446 globals.!prt_dev = ''
1447 globals.!prt_nick = GetNameFromPPD( ppd )
1448 IF globals.!prt_nick == '' THEN DO
1449 CALL VRMessage VRWindow(), NLSGetMessage( 76, ppd ),, /* 76: Could not read printer name from %1. */
1450 NLSGetMessage( 77 ), 'E' /* 77: Invalid PPD */
1451 RETURN
1452 END
1453 END
1454 ELSE DO
1455 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1456 IF man == '' THEN DO
1457 /* TODO display an error? But this shouldn't be possible... */
1458 RETURN
1459 END
1460 ppd = manufacturers.man.!printers.which.!driver
1461 globals.!mode = 1 /* Mode 1: CUPS-included model */
1462 IF POS('exe://', ppd ) > 0 THEN DO
1463 globals.!prt_ppd = ''
1464 globals.!prt_dev = ppd
1465 sel_brand = VRGet('LB_BRAND', 'SelectedString')
1466 sel_name = sel_brand VRMethod('LB_SELECT', 'GetString', selected )
1467 PARSE VAR sel_name _nick ' - CUPS' .
1468 IF _nick == '' THEN
1469 globals.!prt_nick = STRIP( sel_name )
1470 ELSE
1471 globals.!prt_nick = STRIP( _nick )
1472 END
1473 ELSE DO
1474 globals.!prt_ppd = TRANSLATE( globals.!cupsdir'/share/cups/model/'ppd, '\', '/')
1475 globals.!prt_dev = ''
1476 globals.!prt_nick = GetNameFromPPD( globals.!prt_ppd )
1477 END
1478 END
1479 globals.!remotecups = ''
1480
1481 CALL InitMessageLog
1482 IF globals.!mode == 2 THEN
1483 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1484 ELSE
1485 CALL LINEOUT globals.!log1, 'Starting printer install for built-in model:'
1486 IF globals.!prt_dev <> '' THEN
1487 CALL LINEOUT globals.!log1, ' - Device name:' globals.!prt_dev
1488 ELSE
1489 CALL LINEOUT globals.!log1, ' - PPD file: ' globals.!prt_ppd
1490 CALL LINEOUT globals.!log1, ' - Model name: ' globals.!prt_nick
1491 CALL LINEOUT globals.!log1, ''
1492
1493 CALL SetPage2
1494 END
1495
1496 WHEN globals.!page == 2 THEN DO
1497 selected = VRGet('LB_SELECT', 'Selected')
1498 IF selected == 0 THEN RETURN
1499 port = VRMethod('LB_SELECT', 'GetItemData', selected )
1500
1501 IF port == '' THEN DO
1502 /* Network printer selected; prompt for the connection details
1503 */
1504 CALL VRLoadSecondary 'SW_NETWORK', 'W'
1505 END
1506
1507 IF port == '' & globals.!remotecups == '' THEN RETURN
1508 globals.!prt_port = port
1509
1510 CALL SetPage3
1511 END
1512
1513 WHEN globals.!page == 3 THEN DO
1514 globals.!prt_name = STRIP( VRGet('EF_NAME', 'Value'))
1515 globals.!prt_loc = STRIP( VRGet('EF_LOCATION', 'Value'))
1516 globals.!prt_info = STRIP( VRGet('EF_DESC', 'Value'))
1517 IF ((( globals.!prt_name == '') |,
1518 ( globals.!prt_loc == '')) & ( globals.!remotecups == '')) |,
1519 ( globals.!prt_info == '') THEN
1520 DO
1521 IF ( globals.!remotecups <> '') THEN
1522 _errmsg = NLSGetMessage( 42 ) /* 42: You must enter a description. */
1523 ELSE
1524 _errmsg = NLSGetMessage( 43 ) /* 43: You must enter a name, a location, and a description. */
1525 CALL VRMessage VRWindow(), _errmsg, NLSGetMessage( 75 ), 'E' /* 75: Missing Value(s) */
1526 RETURN
1527 END
1528 IF ( globals.!remotecups == '' &,
1529 ( POS( LEFT( globals.!prt_name, 1 ),,
1530 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') == 0 ) |,
1531 ( VERIFY( globals.!prt_name, '/# ' || '09'x, 'MATCH') <> 0 )) THEN
1532 DO
1533 CALL VRMessage VRWindow(), NLSGetMessage( 44 ),, /* 44: The printer name must start with ... or tab characters. */
1534 NLSGetMessage( 45 ), 'E' /* 45: Invalid Name */
1535 RETURN
1536 END
1537
1538 /* TODO support other drivers
1539 */
1540 IF WORD( globals.!prt_nick, 1 ) == 'Apollo' |,
1541 WORD( globals.!prt_nick, 1 ) == 'HP' |,
1542 WORD( globals.!prt_nick, 1 ) == 'Hewlett-Packard' THEN
1543 globals.!os2driver = 'ECUPS-HP'
1544 ELSE
1545 globals.!os2driver = 'ECUPS'
1546
1547 CALL ConfirmAndCreate
1548 END
1549
1550 WHEN globals.!page == 4 THEN DO
1551 CALL NLSSetText 'PB_NEXT', 'Caption', 5 /* 5: Next > */
1552 CALL VRSet 'EF_NAME', 'Value', ''
1553 CALL VRSet 'EF_LOCATION', 'Value', ''
1554 CALL VRSet 'EF_DESC', 'Value', ''
1555
1556 globals.!prt_ppd = ''
1557 CALL SetPage1
1558 END
1559
1560 OTHERWISE NOP
1561 END
1562
1563RETURN
1564
1565/*:VRX PICT_ICON_Click
1566*/
1567PICT_ICON_Click: PROCEDURE EXPOSE globals.
1568 CALL VRLoadSecondary 'SW_ABOUT', 'W'
1569RETURN
1570
1571/*:VRX PromptForPMName
1572*/
1573PromptForPMName: PROCEDURE EXPOSE globals. models. best
1574 best = MatchPrinterModel( globals.!os2driver, globals.!prt_nick )
1575
1576 IF models.0 == 0 THEN DO
1577 /* No similar models were found in the list of supported printers.
1578 * Just use the generic PS driver.
1579 */
1580 CALL VRMessage VRWindow(), NLSGetMessage( 67, globals.!prt_nick, globals.!os2driver ),, /* 67: The printer "%1" does not ... application support. */
1581 NLSGetMessage( 68 ), 'W' /* 68: Printer Name Not Found */
1582 globals.!prt_nick = 'Generic PostScript Printer'
1583 RETURN
1584 END
1585
1586 CALL VRLoadSecondary 'SW_MODEL', 'W'
1587
1588RETURN
1589
1590/*:VRX Quit
1591*/
1592Quit:
1593 window = VRWindow()
1594 call VRSet window, "Shutdown", 1
1595 drop window
1596return
1597
1598/*:VRX SetLanguage
1599*/
1600SetLanguage: PROCEDURE EXPOSE globals.
1601 PARSE ARG locale
1602
1603 /*
1604 * This function locates the proper language files, and uses the message
1605 * file to sets all UI text. If the language could not be determined, we
1606 * default to English.
1607 */
1608 execPath = VRGet('Application', 'Program')
1609 execDir = VRParseFileName( execPath, 'DP')
1610
1611 /*
1612 * First, figure out what language/message file to use.
1613 */
1614 IF locale <> '' THEN
1615 syslanguage = locale
1616 ELSE
1617 syslanguage = VALUE('LANG',,'OS2ENVIRONMENT')
1618
1619 SELECT
1620 WHEN TRANSLATE( syslanguage ) == 'ZH_TW' THEN nlv = 'tw'
1621 WHEN TRANSLATE( syslanguage ) == 'ZH_CN' THEN nlv = 'cx'
1622 OTHERWISE PARSE VAR syslanguage nlv '_' .
1623 END
1624 nlvfile = globals.!nlsfile || nlv
1625 IF ( STREAM( execDir'\'nlvfile'.msg', 'C', 'QUERY EXISTS') \= '') | ( SysSearchPath('DPATH', nlvfile'.msg') \= '') THEN DO
1626 globals.!messages = nlvfile'.msg'
1627 helpfile = nlvfile'.hlp'
1628 CALL VRSet 'WN_MAIN', 'HelpFile', helpfile
1629 END
1630 ELSE DO
1631 globals.!messages = globals.!nlsfile || 'en.msg'
1632 helpfile = globals.!nlsfile || 'en.hlp'
1633 CALL VRSet 'WN_MAIN', 'HelpFile', helpfile
1634 END
1635
1636 /*
1637 * If the message file is missing or unreadable, display an error and then exit.
1638 */
1639 IF NLSGetMessage( 1 ) == '' THEN DO
1640 CALL VRMessage VRWindow(), 'Language file' TRANSLATE( globals.!messages ) 'could not be loaded.', 'Cannot Continue', 'E'
1641 RETURN 0
1642 END
1643
1644 /*
1645 * Now set the captions for the UI controls on the main window, according
1646 * to the specified language.
1647 */
1648 CALL NLSSetText 'WN_MAIN', 'Caption', 1 /* 1: Create CUPS Printer */
1649 CALL NLSSetText 'PB_NEXT', 'Caption', 5 /* 5: Next > */
1650 CALL NLSSetText 'PB_CANCEL', 'Caption', 3 /* 3: Cancel */
1651 CALL NLSSetText 'PB_REFRESH', 'Caption', 6 /* 6: Refresh */
1652
1653RETURN 1
1654
1655/*:VRX SetPage1
1656*/
1657SetPage1: PROCEDURE EXPOSE globals. manufacturers.
1658
1659 CALL VRMethod 'LB_BRAND', 'Clear'
1660
1661 globals.!page = 1
1662 globals.!prt_port = ''
1663 globals.!remotecups = ''
1664 globals.!prt_name = ''
1665 globals.!prt_loc = ''
1666 globals.!prt_info = ''
1667 globals.!os2driver = ''
1668
1669 /* If a PPD was passed on the command line, skip to page 2 */
1670 IF globals.!prt_ppd <> '' THEN DO
1671 globals.!prt_dev = ''
1672 globals.!prt_nick = GetNameFromPPD( globals.!prt_ppd )
1673 IF globals.!prt_nick == '' THEN DO
1674 CALL VRMessage VRWindow(), NLSGetMessage( 76, globals.!prt_ppd ),, /* 76: Could not read printer name from %1. */
1675 NLSGetMessage( 77 ), 'E' /* 77: Invalid PPD */
1676 END
1677 ELSE DO
1678 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1679 globals.!remotecups = ''
1680 CALL InitMessageLog
1681 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1682 CALL LINEOUT globals.!log1, ''
1683 CALL SetPage2
1684 RETURN
1685 END
1686 END
1687
1688 globals.!prt_ppd = ''
1689 globals.!prt_dev = ''
1690 globals.!prt_nick = ''
1691
1692 CALL VRSet 'PB_NEXT', 'Enabled', 0
1693 CALL VRSet 'LB_BRAND', 'Visible', 1
1694
1695 /* Resize LB_SELECT if necessary to make room for LB_BRAND */
1696 lb_x = VRGet('LB_BRAND', 'Left') + VRGet('LB_BRAND', 'Width') + 60
1697 lb_w = VRGet('GB_INFO', 'Width') - lb_x + VRGet('GB_INFO', 'Left')
1698 CALL VRSet 'LB_SELECT', 'Left', lb_x
1699 CALL VRSet 'LB_SELECT', 'Width', lb_w
1700
1701 CALL VRSet 'LB_SELECT', 'Visible', 1
1702 CALL VRSet 'GB_INFO', 'Visible', 0
1703
1704 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1705
1706 IF manufacturers.0 == 0 THEN DO
1707
1708 /* Populate the manufacturer list */
1709 IF globals.!cupsdir == '' THEN DO
1710 manufacturers.1.!name = NLSGetMessage( 22 ) /* 22: -- Custom -- */
1711 manufacturers.1.!printers.0 = 1
1712 manufacturers.1.!printers.1.!model = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
1713 manufacturers.1.!printers.1.!driver = ''
1714 manufacturers.1.!printers.1.!type = ''
1715 manufacturers.1.!printers.1.!remark = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
1716 manufacturers.1.!printers.1.!driver2 = ''
1717 manufacturers.1.!printers.1.!remark2 = ''
1718 manufacturers.0 = 1
1719 END
1720 ELSE
1721 CALL GetCupsPrinters
1722
1723 END
1724 CALL NLSSetText 'DT_INFO', 'Caption', 21 /* 21: Select the printer manufacturer and model from the list below. */
1725
1726 CALL VRSet 'LB_BRAND', 'Painting', 0
1727 DO i = 1 TO manufacturers.0
1728 addman.i = manufacturers.i.!name
1729 addidx.i = i
1730 END
1731 addman.0 = manufacturers.0
1732 addidx.0 = manufacturers.0
1733 CALL VRMethod 'LB_BRAND', 'AddStringList', 'addman.',, 'addidx.'
1734 CALL VRSet 'LB_BRAND', 'Painting', 1
1735
1736 CALL VRMethod 'LB_BRAND', 'SetFocus'
1737 CALL VRSet 'LB_BRAND', 'Selected', 1
1738 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1739
1740RETURN
1741
1742/*:VRX SetPage2
1743*/
1744SetPage2: PROCEDURE EXPOSE globals.
1745
1746 globals.!page = 2
1747 CALL VRSet 'LB_BRAND', 'Visible', 0
1748 CALL VRSet 'PB_NEXT', 'Enabled', 0
1749 CALL NLSSetText 'WN_MAIN', 'StatusText', 29, globals.!prt_nick /* 29: Selected printer: %1 */
1750
1751 /* Resize LB_SELECT to the full width of GB_INFO */
1752 lb_x = VRGet('GB_INFO', 'Left')
1753 lb_w = VRGet('GB_INFO', 'Width')
1754 CALL VRSet 'LB_SELECT', 'Left', lb_x
1755 CALL VRSet 'LB_SELECT', 'Width', lb_w
1756
1757 CALL VRMethod 'LB_SELECT', 'Clear'
1758
1759 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1760 IF globals.!cupsdir == '' THEN DO
1761 CALL VRMethod 'LB_SELECT', 'AddString', NLSGetMessage( 34 ),, '' /* 34: Network printer (manual configuration) */
1762 CALL VRSet 'LB_SELECT', 'Selected', 1
1763 END
1764 ELSE
1765 CALL GetCupsPorts
1766 CALL VRMethod 'LB_SELECT', 'SetFocus'
1767 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1768
1769RETURN
1770
1771/*:VRX SetPage3
1772*/
1773SetPage3: PROCEDURE EXPOSE globals.
1774
1775 globals.!page = 3
1776 CALL VRSet 'EF_DESC', 'Value', globals.!prt_nick
1777 CALL NLSSetText DT_NAME, 'Caption', 103 /* 103: Name: */
1778 CALL NLSSetText DT_LOCATION, 'Caption', 105 /* 105: Location: */
1779 CALL NLSSetText DT_DESC, 'Caption', 106 /* 106: Description: */
1780
1781 CALL VRMethod 'LB_SELECT', 'Clear'
1782
1783 CALL VRSet 'LB_SELECT', 'Visible', 0
1784 CALL VRSet 'GB_INFO', 'Visible', 1
1785 IF globals.!remotecups == '' THEN DO
1786 CALL NLSSetText 'DT_INFO', 'Caption', 40 /* 40: Choose the printer name, and enter its location and a short description. */
1787 CALL VRSet 'DT_NAME', 'Visible', 1
1788 CALL VRSet 'EF_NAME', 'Visible', 1
1789 CALL VRSet 'DT_LOCATION', 'Visible', 1
1790 CALL VRSet 'EF_LOCATION', 'Visible', 1
1791 END
1792 ELSE
1793 CALL NLSSetText 'DT_INFO', 'Caption', 41 /* 41: Enter a short description of this printer. This will be used for the printer object that appears on your desktop. */
1794 CALL VRSet 'DT_DESC', 'Visible', 1
1795 CALL VRSet 'EF_DESC', 'Visible', 1
1796
1797 CALL VRMethod 'EF_NAME', 'SetFocus'
1798
1799RETURN
1800
1801/*:VRX SetPage4
1802*/
1803SetPage4:
1804
1805 globals.!page = 4
1806 CALL VRSet 'LB_SELECT', 'Visible', 0
1807 CALL VRSet 'GB_INFO', 'Visible', 0
1808 CALL VRSet 'WN_MAIN', 'StatusText', ''
1809
1810RETURN
1811
1812/*:VRX SW_ABOUT_Close
1813*/
1814SW_ABOUT_Close:
1815 call SW_ABOUT_Fini
1816return
1817
1818/*:VRX SW_ABOUT_Create
1819*/
1820SW_ABOUT_Create:
1821 call SW_ABOUT_Init
1822return
1823
1824/*:VRX SW_ABOUT_Fini
1825*/
1826SW_ABOUT_Fini:
1827 window = VRInfo( "Window" )
1828 call VRDestroy window
1829 drop window
1830return
1831/*:VRX SW_ABOUT_Init
1832*/
1833SW_ABOUT_Init:
1834
1835 CALL NLSSetText 'SW_ABOUT', 'Caption', 10 /* 10: Product Information */
1836 CALL NLSSetText 'DT_ABOUT1', 'Caption', 11 /* 11: eCups Printer Install Utility */
1837 CALL NLSSetText 'DT_ABOUT2', 'Caption', 12, '1.04' /* 12: Version %1 */
1838 CALL NLSSetText 'DT_ABOUT3', 'Caption', 13, '2010, 2013' /* 13: (C) %1 Alex Taylor */
1839 CALL NLSSetText 'PB_ABOUT', 'Caption', 2 /* 10: Product Information */
1840
1841 CALL NLSSetText 'DT_BOOTDRIVE', 'Caption', 14, TRANSLATE( globals.!bootdrv ) /* 14: System boot volume: %1 */
1842 CALL NLSSetText 'DT_CUPSPATH', 'Caption', 15, TRANSLATE( globals.!cupsdir ) /* 15: Local CUPS directory: %1 */
1843 CALL NLSSetText 'DT_REPOSITORY', 'Caption', 16, TRANSLATE( globals.!repository ) /* 16: Local driver repository: %1 */
1844
1845 window = VRInfo( "Object" )
1846 if( \VRIsChildOf( window, "Notebook" ) ) then do
1847 call VRMethod window, "CenterWindow"
1848 call VRSet window, "Visible", 1
1849 call VRMethod window, "Activate"
1850 end
1851 drop window
1852return
1853
1854/*:VRX SW_CREATE_Close
1855*/
1856SW_CREATE_Close:
1857 call SW_CREATE_Fini
1858return
1859
1860/*:VRX SW_CREATE_Create
1861*/
1862SW_CREATE_Create:
1863 call SW_CREATE_Init
1864return
1865
1866/*:VRX SW_CREATE_Fini
1867*/
1868SW_CREATE_Fini:
1869 window = VRInfo( "Window" )
1870 call VRDestroy window
1871 drop window
1872return
1873/*:VRX SW_CREATE_Init
1874*/
1875SW_CREATE_Init:
1876
1877 CALL NLSSetText 'SW_CREATE', 'Caption', 115 /* 115: Confirm Create Printer */
1878 CALL NLSSetText 'DT_CRMODEL', 'Caption', 102 /* 102: Model: */
1879 CALL NLSSetText 'DT_CRLOC', 'Caption', 105 /* 105: Location: */
1880 CALL NLSSetText 'DT_CRDESC', 'Caption', 106 /* 106: Description: */
1881
1882 CALL NLSSetText 'CHK_CREATEPM', 'Caption', 109 /* 109: Create printer object */
1883 CALL NLSSetText 'DT_PRESDRV', 'Caption', 110 /* 110: Presentation driver: */
1884 CALL NLSSetText 'PB_CREATEOK', 'Caption', 111 /* 111: Create */
1885 CALL NLSSetText 'PB_CREATECANCEL', 'Caption', 3 /* 3: Cancel */
1886 CALL NLSSetText 'PB_CREATEHELP', 'Caption', 4 /* 4: ~Help */
1887
1888 CALL VRSet 'EF_CRMODEL', 'Value', globals.!prt_nick
1889
1890 IF globals.!remotecups <> '' THEN DO
1891 /* An existing CUPS printer was indicated. This means we're not
1892 * creating a CUPS printer, but only a PM printer object (and port)
1893 * that points to it.
1894 */
1895 CALL NLSSetText 'DT_CREATE', 'Caption', 101 /* 101: Ready to create printer object with the following parameters. */
1896
1897 PARSE VAR globals.!remotecups cups_host cups_printer .
1898 CALL NLSSetText 'DT_CRNAME', 'Caption', 107 /* 107: CUPS server: */
1899 CALL NLSSetText 'DT_CRURI', 'Caption', 108 /* 108: CUPS queue: */
1900 CALL VRSet 'DT_CRLOC', 'Visible', 0
1901 CALL VRSet 'EF_CRNAME', 'Value', cups_host
1902 CALL VRSet 'EF_CRURI', 'Value', cups_printer
1903 CALL VRSet 'EF_CRLOC', 'Visible', 0
1904 CALL VRSet 'CHK_CREATEPM', 'Visible', 0
1905 END
1906 ELSE DO
1907 CALL NLSSetText 'DT_CREATE', 'Caption', 100 /* 100: Ready to create CUPS printer with the following parameters. */
1908 CALL NLSSetText 'DT_CRNAME', 'Caption', 103 /* 103: Name: */
1909 CALL NLSSetText 'DT_CRURI', 'Caption', 104 /* 104: URI: */
1910 CALL VRSet 'EF_CRNAME', 'Value', globals.!prt_name
1911 CALL VRSet 'EF_CRURI', 'Value', globals.!prt_port
1912 CALL VRSet 'EF_CRLOC', 'Value', globals.!prt_loc
1913 END
1914 CALL VRSet 'EF_CRDESC', 'Value', globals.!prt_info
1915
1916 IF QueryAvailableDrivers() > 0 THEN DO
1917 def_idx = 1
1918 CALL VRMethod 'DDCB_PRESDRV', 'AddStringList', 'drv_list.'
1919 DO i = 1 TO drv_list.0
1920 IF drv_list.i == globals.!os2driver THEN DO
1921 def_idx = i
1922 LEAVE
1923 END
1924 END
1925 CALL VRSet 'DDCB_PRESDRV', 'Selected', def_idx
1926 END
1927 ELSE DO /* 112: No eCups-compatible OS/2 presentation drivers are installed. */
1928 /* 113: Please install the ECUPS or ECUPS-HP printer driver before continuing. */
1929 CALL VRMessage VRWindow(),
1930 NLSGetMessage( 112 ) || '0d0a0d0a'x || NLSGetMessage( 113 ),,
1931 NLSGetMessage( 114 ), 'E' /* 114: Missing PM Driver */
1932 CALL VRSet 'PB_CREATEOK', 'Enabled', 0
1933 /* TODO give an error if no drivers were found */
1934 END
1935
1936 window = VRInfo( "Object" )
1937 if( \VRIsChildOf( window, "Notebook" ) ) then do
1938 call VRMethod window, "CenterWindow"
1939 call VRSet window, "Visible", 1
1940 call VRMethod window, "Activate"
1941 end
1942 drop window
1943
1944RETURN
1945
1946/*:VRX SW_MODEL_Close
1947*/
1948SW_MODEL_Close:
1949 call SW_MODEL_Fini
1950return
1951
1952/*:VRX SW_MODEL_Create
1953*/
1954SW_MODEL_Create:
1955 call SW_MODEL_Init
1956return
1957
1958/*:VRX SW_MODEL_Fini
1959*/
1960SW_MODEL_Fini:
1961
1962 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1963
1964 window = VRInfo( "Window" )
1965 call VRDestroy window
1966 drop window
1967return
1968/*:VRX SW_MODEL_Init
1969*/
1970SW_MODEL_Init:
1971
1972 CALL NLSSetText 'SW_MODEL', 'Caption', 120 /* 120: Select Printer Model */
1973
1974 /* We should have a list of suggested printer models whose names at least
1975 * partially match the requested model, sorted in order with the closest
1976 * match at the top.
1977 */
1978 ok = VRMethod( "LB_OS2MODELS", "AddStringList", "models.", )
1979 IF best > 0 THEN
1980 CALL VRSet 'LB_OS2MODELS', 'Selected', best
1981
1982 CALL NLSSetText 'DT_MODEL1', 'Caption',,
1983 121, globals.!prt_nick, globals.!os2driver /* 121: The printer "%1" could not ... to applications. */
1984 CALL NLSSetText 'DT_MODEL2', 'Caption', 122 /* 122: You can select one of ... use a generic driver. */
1985
1986 CALL NLSSetText 'PB_MODELOK', 'Caption', 2 /* 2: OK */
1987 CALL NLSSetText 'PB_MODELCANCEL', 'Caption', 3 /* 3: Cancel */
1988
1989 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1990
1991 window = VRInfo( "Object" )
1992 if( \VRIsChildOf( window, "Notebook" ) ) then do
1993 call VRMethod window, "CenterWindow"
1994 call VRSet window, "Visible", 1
1995 call VRMethod window, "Activate"
1996 end
1997 drop window
1998
1999RETURN
2000
2001/*:VRX SW_NETWORK_Close
2002*/
2003SW_NETWORK_Close:
2004 call SW_NETWORK_Fini
2005return
2006
2007/*:VRX SW_NETWORK_Create
2008*/
2009SW_NETWORK_Create:
2010 call SW_NETWORK_Init
2011return
2012
2013/*:VRX SW_NETWORK_Fini
2014*/
2015SW_NETWORK_Fini:
2016
2017 network_dialog = 0
2018
2019 window = VRInfo( "Window" )
2020 call VRDestroy window
2021 drop window
2022return
2023/*:VRX SW_NETWORK_Init
2024*/
2025SW_NETWORK_Init:
2026
2027 /* Flag to keep track of whether dialog is open */
2028 network_dialog = 1
2029
2030 CALL NLSSetText 'SW_NETWORK', 'Caption', 80 /* 80: Network Printer */
2031 CALL NLSSetText 'DT_PROTOCOL', 'Caption', 81 /* 81: Network protocol: */
2032 CALL NLSSetText 'DT_PASSWORD', 'Caption', 90 /* 90: Password: */
2033 CALL NLSSetText 'PB_NETOK', 'Caption', 2 /* 2: OK */
2034 CALL NLSSetText 'PB_NETCANCEL', 'Caption', 3 /* 3: Cancel */
2035 CALL NLSSetText 'PB_NETHELP', 'Caption', 4 /* 4: ~Help */
2036
2037 IF globals.!cupsdir == '' THEN DO
2038 protos.0 = 1
2039 protos.1 = NLSGetMessage( 91 ) /* 91: Existing CUPS printer (remote server) */
2040 pnums.0 = 1
2041 pnums.1 = 5
2042 END
2043 ELSE DO
2044 protos.0 = 5
2045 protos.1 = NLSGetMessage( 92 ) /* 92: Internet Printing Protocol (IPP) */
2046 protos.2 = NLSGetMessage( 93 ) /* 93: AppSocket/JetDirect */
2047 protos.3 = NLSGetMessage( 94 ) /* 94: Line Printer Remote daemon (LPD) */
2048 protos.4 = NLSGetMessage( 95 ) /* 95: Windows/SMB network */
2049 protos.5 = NLSGetMessage( 96 ) /* 96: Existing CUPS printer */
2050 pnums.0 = 5
2051 pnums.1 = 1
2052 pnums.2 = 2
2053 pnums.3 = 3
2054 pnums.4 = 4
2055 pnums.5 = 5
2056 END
2057
2058 CALL VRMethod 'DDCB_PROTOCOL', 'AddStringList', 'protos.',, 'pnums.'
2059 CALL VRSet 'DDCB_PROTOCOL', 'Selected', 1
2060
2061 window = VRInfo( "Object" )
2062 if( \VRIsChildOf( window, "Notebook" ) ) then do
2063 call VRMethod window, "CenterWindow"
2064 call VRSet window, "Visible", 1
2065 call VRMethod window, "Activate"
2066 end
2067 drop window
2068return
2069
2070/*:VRX WN_MAIN_Close
2071*/
2072WN_MAIN_Close:
2073 call Quit
2074return
2075
Note: See TracBrowser for help on using the repository browser.