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

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

Try to auto-detect CUPS queue names when 'existing CUPS printer' is selected.

File size: 74.2 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.
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 CALL VRMethod 'DDCB_CUPSQUEUES', 'AddStringList', 'cupsdest.'
491RETURN
492
493/*:VRX ExecRINSTPRN
494*/
495ExecRINSTPRN: PROCEDURE EXPOSE globals.
496 PARSE ARG dsc, drv, src, rsp
497
498 od = DIRECTORY()
499 CALL DIRECTORY src
500 rinstprn_cmd = 'rinstprn /DSC:'dsc '/DRV:'drv' /S:'src ,
501 '/T:'globals.!bootdrv '/L1:'globals.!logdir'\rinstprn.log' ,
502 '/R:'rsp
503
504 CALL LINEOUT globals.!log1, 'Creating OS/2 printer using:'
505 CALL LINEOUT globals.!log1, ' ' rinstprn_cmd
506 ADDRESS CMD '@' rinstprn_cmd '1>NUL 2>NUL'
507 CALL LINEOUT globals.!log1, 'Return code: 0x' || D2X( rc, 4 )
508 IF rc <> 0 THEN
509 CALL LINEOUT globals.!log1, 'See' globals.!logdir'\rinstprn.log for details.'
510 CALL DIRECTORY od
511 CALL LINEOUT globals.!log1, ''
512
513RETURN rc
514
515/*:VRX Fini
516*/
517Fini:
518 window = VRWindow()
519 call VRSet window, "Visible", 0
520 drop window
521return 0
522
523/*:VRX GetCupsPorts
524*/
525GetCupsPorts: PROCEDURE EXPOSE globals.
526
527 CALL NLSSetText 'DT_INFO', 'Caption', 30 /* 30: Looking for connected printers. Please wait... */
528
529 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe -v 2>&1 |rxqueue'
530 snmp_cmd = globals.!cupsdir'\lib\cups\backend\snmp.exe 2>&1 |rxqueue'
531
532 _od = DIRECTORY()
533 CALL DIRECTORY globals.!cupsdir
534 listqueue = RXQUEUE('CREATE')
535 defqueue = RXQUEUE('SET', listqueue )
536
537 /* Use the SNMP backend to find network printers. We do this in addition
538 * to lpinfo because SNMP may provide the actual printer name. We'll
539 * merge this with the output of lpinfo in the next step.
540 */
541 ADDRESS CMD '@' snmp_cmd listqueue
542 DO QUEUED()
543 PARSE PULL line
544 PARSE VAR line _type _uri '"'_identifier'"' .
545 _uri = STRIP( _uri )
546 _type = STRIP( _type )
547 IF _uri == '' THEN ITERATE
548 IF _type <> 'network' THEN ITERATE
549 netnames._uri = _identifier
550 END
551
552 ADDRESS CMD '@' lpinfo_cmd listqueue
553 i = 0
554 DO QUEUED()
555 PARSE PULL line
556 PARSE VAR line _type _name
557 IF _name == '' THEN ITERATE
558 IF _type == 'network' & POS('://', _name ) > 0 THEN DO
559 PARSE VAR _name _protocol '://' _host '/' _queue
560 IF _protocol == 'socket' THEN _protocol = 'AppSocket'
561 ELSE _protocol = TRANSLATE( _protocol )
562 i = i + 1
563 IF _queue <> '' THEN _queue = '(queue '_queue')'
564 IF SYMBOL('netnames._name') == 'VAR' THEN
565 devices.i = NLSGetMessage( 32, _protocol, netnames._name, _host _queue ) /* 32: Detected network printer (%1) "%2" at %3 */
566 ELSE
567 devices.i = NLSGetMessage( 33, _protocol, _host _queue ) /* 33: Detected network printer (%1) at %2 */
568 END
569 ELSE IF _type <> 'direct' THEN ITERATE
570 ELSE DO
571 IF _name == 'hp' THEN ITERATE
572 i = i + 1
573 devices.i = NLSGetMessage( 35, _name ) /* 35: Local printer: %1 */
574 END
575 ports.i = _name
576 END
577 devices.0 = i
578
579 CALL RXQUEUE 'SET', defqueue
580 CALL RXQUEUE 'DELETE', listqueue
581 CALL DIRECTORY _od
582
583 CALL VRSet 'LB_SELECT', 'Painting', 0
584 CALL VRMethod 'LB_SELECT', 'AddStringList', 'devices.',, 'ports.'
585 CALL VRMethod 'LB_SELECT', 'AddString', NLSGetMessage( 34 ),, '' /* 34: Network printer (manual configuration) */
586 CALL VRSet 'LB_SELECT', 'Selected', 1
587 CALL VRSet 'LB_SELECT', 'Painting', 1
588
589 CALL VRSet 'DT_INFO', 'Caption', NLSGetMessage( 31 ) /* 31: Select the connection for this printer. */
590
591RETURN
592
593/*:VRX GetCupsPrinters
594*/
595GetCupsPrinters: PROCEDURE EXPOSE globals. manufacturers.
596
597 CALL NLSSetText 'DT_INFO', 'Caption', 20 /* 20: Getting list of supported printers. Please wait... */
598
599 lpinfo_cmd = globals.!cupsdir'\sbin\lpinfo.exe --exclude-schemes drv -m 2>&1 |rxqueue'
600
601 _od = DIRECTORY()
602 CALL DIRECTORY globals.!cupsdir
603 listqueue = RXQUEUE('CREATE')
604 defqueue = RXQUEUE('SET', listqueue )
605
606 ADDRESS CMD '@' lpinfo_cmd listqueue
607 i = 0
608 makers = ''
609 DO QUEUED()
610 PARSE PULL line
611 IF LEFT( line, 6 ) == 'drv://' THEN ITERATE
612 IF WORD( line, 1 ) == 'raw' THEN ITERATE
613 PARSE VAR line _ppd '.ppd.gz ' _name
614 _ppd = _ppd'.ppd.gz'
615 IF _name == '' THEN DO
616 PARSE VAR line _ppd '.ppd ' _name
617 _ppd = _ppd'.ppd'
618 END
619 IF _name == '' THEN DO
620 PARSE VAR line _ppd _name
621 END
622 IF _name <> '' THEN DO
623 PARSE VAR _name _brand _model
624 IF WORDPOS( _brand, makers ) == 0 THEN makers = makers || _brand' '
625 i = i + 1
626 ppds.i = _ppd
627 models.i = _name
628 END
629 END
630 ppds.0 = i
631 models.0 = i
632
633 CALL RXQUEUE 'SET', defqueue
634 CALL RXQUEUE 'DELETE', listqueue
635 CALL DIRECTORY _od
636
637/* Now build the 'manufacturers' stem.
638 * This stem takes the following format:
639 * manufacturers.0 number of manufacturers
640 * manufacturers.i.!name manufacturer name (e.g. 'Apple')
641 * manufacturers.i.!printers.0 number of printer models
642 * manufacturers.i.!printers.j.!model printer model name, short form (e.g. 'LaserWriter 330')
643 * manufacturers.i.!printers.j.!type driver version/type (e.g. 'Gutenprint v5.2.7')
644 * manufacturers.i.!printers.j.!driver the internal CUPS printer driver name (PPD or URI)
645 * - by preference this is the "simplified" version if available
646 * manufacturers.i.!printers.j.!remark any distinguishing remarks (e.g. 'Simplified')
647 * manufacturers.i.!printers.j.!driver2 alternate driver in case there is more than one (PPD or URI)
648 * - if defined this is usually the non-"simplified" driver
649 * manufacturers.i.!printers.j.!remark2 any distinguishing remarks for the alternate driver
650 */
651 manufacturers.0 = WORDS( makers )
652 DO i = 1 TO manufacturers.0
653 manufacturers.i.!name = WORD( makers, i )
654 manufacturers.i.!printers.0 = 0
655 END
656
657 DO i = 1 TO models.0
658 PARSE VAR models.i _brand _model ' - CUPS+' _type
659 IF _type == '' THEN DO
660 PARSE VAR models.i _brand _model ',' _type
661 IF WORD( _type, 1 ) == 'hpcups' THEN
662 _type = 'HPLIP' /* SUBWORD( _type, 2 ) */
663 ELSE IF ( _type == '') & ( LEFT( ppds.i, 3 ) == 'hp/') THEN
664 _type = 'HPLIP'
665 END
666 man = WORDPOS( _brand, makers )
667 IF man == 0 THEN ITERATE
668
669 PARSE VAR _type _version 'Simplified' .
670 _version = STRIP( _version )
671 _flag = RIGHT( _type, 10 )
672
673 count = manufacturers.man.!printers.0
674 IF count > 0 THEN DO
675 /* If there are two or more printers defined with the same model
676 * name and driver version, keep the first and last as the regular
677 * and alternate drivers; if one if them is 'Simplified', make that
678 * the regular driver by preference.
679 */
680 IF ( TRANSLATE( manufacturers.man.!printers.count.!model ) == TRANSLATE( _model )) THEN DO
681 IF ( manufacturers.man.!printers.count.!type == _version ) THEN DO
682 IF ( WORD( _version, 1 ) == 'Gutenprint') & ( _flag == 'Simplified') THEN DO
683 manufacturers.man.!printers.count.!driver2 = manufacturers.man.!printers.count.!driver
684 manufacturers.man.!printers.count.!remark2 = manufacturers.man.!printers.count.!remark
685 manufacturers.man.!printers.count.!driver = ppds.i
686 manufacturers.man.!printers.count.!remark = 'Simplified'
687 END
688 ELSE DO
689 manufacturers.man.!printers.count.!driver2 = ppds.i
690 IF _flag == 'Simplified' THEN
691 manufacturers.man.!printers.count.!remark2 = 'Simplified'
692 ELSE
693 manufacturers.man.!printers.count.!remark2 = ''
694 END
695 ITERATE
696 END
697 END
698 END
699 count = count + 1
700 manufacturers.man.!printers.count.!model = _model
701 manufacturers.man.!printers.count.!type = _version
702 manufacturers.man.!printers.count.!driver = ppds.i
703 IF _flag == 'Simplified' THEN
704 manufacturers.man.!printers.count.!remark = 'Simplified'
705 ELSE
706 manufacturers.man.!printers.count.!remark = ''
707 manufacturers.man.!printers.count.!driver2 = ''
708 manufacturers.man.!printers.count.!remark2 = ''
709 manufacturers.man.!printers.0 = count
710 END
711
712 /* Add one more category for special items ...
713 */
714 count = manufacturers.0 + 1
715 manufacturers.count.!name = NLSGetMessage( 22 ) /* 22: -- Custom -- */
716 manufacturers.count.!printers.0 = 1
717 manufacturers.count.!printers.1.!model = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
718 manufacturers.count.!printers.1.!driver = ''
719 manufacturers.count.!printers.1.!type = ''
720 manufacturers.count.!printers.1.!remark = manufacturers.count.!printers.1.!model
721 manufacturers.count.!printers.1.!driver2 = ''
722 manufacturers.count.!printers.1.!remark2 = ''
723 manufacturers.0 = count
724
725RETURN
726
727/*:VRX GetCupsQueues
728*/
729GetCupsQueues: PROCEDURE EXPOSE globals. cupsdest.
730 ARG hostaddr
731
732 /* Try to find lpstat.exe */
733 lpstat_exe = STREAM( globals.!cupsdir'\bin\lpstat.exe', 'C', 'QUERY EXISTS')
734 IF lpstat_exe == '' THEN lpstat_exe = STREAM( globals.!mydir'\lpstat.exe', 'C', 'QUERY EXISTS')
735 IF lpstat_exe == '' THEN lpstat_exe = STREAM( DIRECTORY()'\lpstat.exe', 'C', 'QUERY EXISTS')
736 IF lpstat_exe == '' THEN lpstat_exe = SysSearchPath('PATH', 'lpstat.exe')
737 IF lpstat_exe == '' THEN RETURN 0
738
739 sq = RXQUEUE('CREATE')
740 oq = RXQUEUE('SET', sq )
741
742 CALL VRSet VRWindow(), 'Pointer', 'WAIT'
743 ADDRESS CMD '@'lpstat_exe '-h' hostaddr '-p -c 2>&1 |rxqueue' sq
744 CALL VRSet VRWindow(), 'Pointer', '<default>'
745
746 _count = 0
747 DO QUEUED()
748 PARSE PULL _info
749 IF _info == '' THEN ITERATE
750 IF _info == 'lpstat: Connection refused' THEN LEAVE
751 IF WORD( _info, 1 ) == 'printer' THEN
752 PARSE VAR _info 'printer' _qname .
753 ELSE IF WORD( info, 1 ) == 'class' THEN
754 PARSE VAR _info 'class' _qname .
755 ELSE ITERATE
756 IF _qname == '' THEN ITERATE
757 _count = _count + 1
758 cupsdest._count = _qname
759 END
760 CALL RXQUEUE 'DELETE', sq
761 CALL RXQUEUE 'SET', oq
762
763 cupsdest.0 = _count
764
765RETURN _count
766
767/*:VRX Halt
768*/
769Halt:
770 signal _VREHalt
771return
772
773/*:VRX ImportPPD
774*/
775ImportPPD: PROCEDURE EXPOSE globals.
776 /* Import a new PPD file into a PostScript driver.
777 */
778 ARG driver, ppdfile
779 IF driver == '' THEN driver = 'PSCRIPT'
780
781 CALL LINEOUT globals.!log1, 'Going to import PPD file into driver' driver'.'
782
783 /***
784 *** First, get our working directories and locate the driver source files.
785 ***/
786
787 mustcopy = 0
788 driver_path = GetDriverSource( driver )
789 IF driver_path == '' THEN DO
790 /* No source found. We'll have to try copying the actual installed
791 * driver files from under \OS2\DLL.
792 */
793 CALL LINEOUT globals.!log1, 'Driver source not found.'
794 driver_path = STREAM( globals.!os2dir'\DLL\'driver'\'driver'.DRV', 'C', 'QUERY EXISTS')
795 mustcopy = 1
796 END
797 IF driver_path <> '' THEN DO
798 srcdir = VRParseFilePath( driver_path, 'DP')
799 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
800 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
801 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
802 DROP srcdir
803 END
804
805 /* Driver (or one of its required files) was not found.
806 */
807 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
808 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
809 DO
810 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
811 /* TODO should prompt for installable driver package? */
812 RETURN 1 /** RC=1 Missing required driver files **/
813 END
814
815 IF mustcopy <> 0 THEN DO
816 /* Looks like the driver wasn't shipped with the OS; we have a source
817 * (either the active files from \OS2\DLL, or a package provided by
818 * the user), but we need somewhere for them to live. The user needs
819 * to tell us where, because they're going to have to specify the
820 * directory later on if they install the driver from PM.
821 */
822 pbtn.1 = NLSGetMessage( 2 ) /* 2: OK */
823 pbtn.2 = NLSGetMessage( 3 ) /* 3: Cancel */
824 pbtn.0 = 2
825 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. */
826 '0d0a0d0a'x || NLSGetMessage( 64 ) /* 64: Please enter the directory where the install files will be placed. */
827
828 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
829 IF drvr_dir == '' THEN
830 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
831 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir', NLSGetMessage( 59 ), 'pbtn.', 1, 2 ) /* 59: Enter Directory */
832 IF ok <> 1 THEN RETURN 9 /** RC=9 User cancelled **/
833 drvr_dir = VRExpandFileName( drvr_dir )
834 DO WHILE drvr_dir == ''
835 ok = VRPrompt('WN_MAIN', ptext, 'drvr_dir',,
836 'Enter Directory', 'pbtn.', 1, 2 )
837 drvr_dir = VRExpandFileName( drvr_dir )
838 END
839
840 /* Now create the new directory, if necessary */
841 IF VRMkDir( drvr_dir ) == 0 THEN
842 RETURN 3 /** RC=3 Failed to copy driver files **/
843 IF CopyDriverToSource( driver_path, drvr_dir ) == 0 THEN
844 RETURN 3 /** RC=3 Failed to copy driver files **/
845
846 /* Make sure we save the location (we'll need this information later) */
847 CALL VRSetIni 'PM_INSTALL', driver'_DIR', drvr_dir||'00'x, 'USER'
848
849 /* Now point to the new copy as the driver we will work on */
850 driver_path = drvr_dir'\'driver'.DRV'
851 END
852
853 workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
854 ok = VrMkDir( workdir )
855 IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
856 IF ok <> 1 THEN
857 RETURN 2 /** RC=2 Failed to create temporary directory **/
858
859 SELECT
860 WHEN driver == 'ECUPS' THEN ppddir = globals.!repository'\PPD_E'
861 WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
862 WHEN driver == 'PSPRINT' THEN ppddir = globals.!repository'\PPD_PS'
863 WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
864 WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
865 OTHERWISE ppddir = globals.!repository'\PPD'
866 END
867
868 /* Make sure ppddir (for keeping PPD files) exists */
869 CALL SysFileTree ppddir, 'dirs.', 'DO'
870 IF dirs.0 == 0 THEN DO
871 ok = VrMkDir( ppddir )
872 IF ok <> 1 THEN
873 RETURN 4 /** RC=4 Failed to create PPD directory **/
874 END
875
876 /***
877 *** Now do the actual work.
878 ***/
879
880 /* Back up the modified files (AUXPRINT.PAK and <driver>.DRV) if we're
881 * working out of the repository.
882 IF mustcopy == 0 THEN DO
883 repfiles.0 = 2
884 repfiles.1 = driver'.DRV'
885 repfiles.2 = 'AUXPRINT.PAK'
886 CALL BackupDrivers driver_path
887 END
888 */
889
890 /* Copy the needed driver files to our working directories.
891 */
892 drv_out = workdir'\OUT\'driver'.DRV'
893 pin_exe = workdir'\PIN.EXE'
894 ppd_exe = workdir'\PPDENC.EXE'
895 ok = VRCopyFile( driver_path, drv_out )
896 IF ok == 1 THEN ok = VRCopyFile( pin, pin_exe )
897 IF ok == 1 THEN ok = VRCopyFile( ppdenc, ppd_exe )
898 IF ok == 0 THEN DO
899 RETURN 3 /*** RC=3 Failed to copy driver files ***/
900 END
901
902 /* Set up the output redirection.
903 */
904 nq = RXQUEUE('CREATE')
905 oq = RXQUEUE('SET', nq )
906
907 /* If the PPD file is compressed, uncompress it.
908 */
909 IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
910 decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
911 CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
912 ADDRESS CMD '@gzip -c -d' ppdfile '| RXQUEUE' nq
913 DO QUEUED()
914 PARSE PULL line
915 CALL LINEOUT decppd, line
916 END
917 CALL LINEOUT decppd
918 ppdfile = decppd
919 END
920
921 IF VRFileExists( ppdfile ) == 0 THEN DO
922 CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
923 RETURN 5 /** RC=5 PPD import failed **/
924 END
925
926 ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
927
928 /* Now we have to clean up and validate the PPD file so PIN can use it.
929 * First, PPDENC converts the codepage if necessary, and copies the results
930 * to our working directory.
931 */
932 CALL LINEOUT globals.!log1, 'Converting PPD with:' ppd_exe ppdfile ppd_use
933 ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>NUL | RXQUEUE' nq
934 DO QUEUED()
935 PULL output
936 CALL LINEOUT globals.!log2, output
937 END
938 CALL LINEOUT globals.!log2, ''
939 CALL LINEOUT globals.!log2
940
941 IF VRFileExists( ppd_use ) == 0 THEN DO
942 CALL LINEOUT globals.!log1, 'Hmm,' ppd_use 'was not created. Copying manually.'
943 CALL VRCopyFile ppdfile, ppd_use
944 END
945
946 /* Next we strip out some problematic lines used which are often encountered
947 * in (e.g.) CUPS-based PPD files.
948 */
949 CALL CleanPPD ppd_use, globals.!log1
950
951 /* Preparation complete. Now do the import.
952 */
953 count = 0
954 ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>NUL | RXQUEUE' nq
955 DO QUEUED()
956 PARSE PULL output
957 CALL LINEOUT globals.!log2, output
958 PARSE VAR output . 'OK (' nickname
959 IF nickname <> '' THEN DO
960 count = count + 1
961 newprinters.count = STRIP( nickname, 'T', ')')
962 END
963 END
964 newprinters.0 = count
965 CALL LINEOUT globals.!log2, ''
966 CALL LINEOUT globals.!log2
967
968 /* End the output redirection.
969 */
970 CALL RXQUEUE 'SET', oq
971 CALL RXQUEUE 'DELETE', nq
972
973
974 /***
975 *** Post-import processing.
976 ***/
977
978 IF newprinters.0 == 0 THEN DO
979 RETURN 5 /** RC=5 PPD import failed **/
980 END
981
982 /*IF mustcopy == 0 THEN DO*/
983 IF pmdx <> '' THEN DO
984 /* If we're working out of the repository, we need to update the
985 * driver table in PRDESC.LST to add the new driver(s).
986 */
987
988 CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with' newprinters.0 'new entries ...'
989 count = 0
990 match_drv = '('driver'.DRV)'
991 match_len = LENGTH( match_drv )
992
993 /* First, copy all lines that don't refer to the driver just updated */
994 DO WHILE LINES( globals.!prdesc )
995 _line = LINEIN( globals.!prdesc )
996 IF TRANSLATE( RIGHT( _line, LENGTH( match_len ))) == match_drv THEN ITERATE
997 count = count + 1
998 defs.count = _line
999 END
1000 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
1001
1002 /* Next, create a new list for the updated driver and merge that in */
1003 newlist = workdir'\'driver'.LST'
1004 CALL CreateDriverList driver, newlist
1005 DO WHILE LINES( newlist )
1006 _line = LINEIN( newlist )
1007 count = count + 1
1008 defs.count = _line
1009 END
1010 defs.0 = count
1011
1012 /* Now sort the list and recreate PRDESC.LST */
1013 CALL SysStemSort 'defs.',, 'I'
1014 prdesc_tmp = workdir'\PRDESC.LST'
1015 IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
1016 CALL VRDeleteFile prdesc_tmp
1017 DO i = 1 TO defs.0
1018 CALL LINEOUT prdesc_tmp, defs.i
1019 END
1020 CALL LINEOUT prdesc_tmp
1021 ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
1022 IF ok == 0 THEN DO
1023 RETURN 6 /** RC=6 Error updating PRDESC.LST **/
1024 END
1025 CALL VRDeleteFile prdesc_tmp
1026
1027 END
1028
1029 /* Finally, copy the updated driver files.
1030 */
1031 target = VRParseFilePath( driver_path, 'DP')
1032 CALL LINEOUT globals.!log1, 'Copying files from' workdir'\OUT to' target
1033 ADDRESS CMD '@UNLOCK' target'\'driver'.DRV 2>NUL 1>NUL'
1034 ok = VRCopyFile( workdir'\OUT\'driver'.DRV', target'\'driver'.DRV')
1035 IF ok == 1 THEN
1036 ok = VRCopyFile( workdir'\OUT\AUXPRINT.PAK', target'\AUXPRINT.PAK')
1037 IF ok == 1 THEN DO
1038 /* Copy the updated files to \OS2\DLL\<driver>, replacing any
1039 * existing copies. (This prevents problems if the OS/2 driver
1040 * installation doesn't/fails to copy them, which can happen under
1041 * some circumstances.)
1042 */
1043 IF VRFileExists( globals.!os2dir'\DLL\'driver ) THEN DO
1044 CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
1045 globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
1046 ADDRESS CMD '@UNLOCK' workdir'\OUT\'driver'.DRV 2>NUL 1>NUL'
1047 CALL VRCopyFile workdir'\OUT\'driver'.DRV',,
1048 globals.!os2dir'\DLL\'driver'\'driver'.DRV'
1049 END
1050 END
1051 IF ok == 0 THEN DO
1052 CALL LINEOUT globals.!log1, VRError()
1053 RETURN 3 /*** RC=3 Failed to copy driver files ***/
1054 END
1055
1056 CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
1057 DO i = 1 TO newprinters.0
1058 CALL LINEOUT globals.!log1, ' ->' newprinters.i
1059 END
1060 CALL LINEOUT globals.!log1, ''
1061 CALL LINEOUT globals.!log1
1062
1063 /* Clean up our work directories.
1064 */
1065 CALL VRDeleteFile workdir'\OUT\*'
1066 CALL VRDeleteFile workdir'\*'
1067 CALL VRRmDir( workdir'\OUT')
1068 CALL VRRmDir( workdir )
1069
1070RETURN 0
1071
1072/*:VRX Init
1073*/
1074Init:
1075 SIGNAL ON NOVALUE NAME __NoValue
1076
1077 /* Hide the VX-REXX console window
1078 */
1079 CALL VRSet 'Console', 'WindowListTitle', ''
1080
1081 CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
1082 CALL SysLoadFuncs
1083
1084 CALL LoadSettings
1085 CALL SetLanguage
1086 CALL CheckPrograms
1087
1088 IF InitArgs.0 > 0 THEN globals.!cupsdir = InitArgs.1
1089
1090 IF \VRIsDir( globals.!cupsdir ) THEN DO
1091 IF TRANSLATE( globals.!cupsdir ) <> '/R' THEN
1092 CALL VRMessage VRWindow(),
1093 NLSGetMessage( 65, 'CUPSWIZ F:\CUPS') ||, /* 65: CUPS could not be located ... on the command line to this program (e.g "%1"). */
1094 '0d0a0d0a'x || NLSGetMessage( 66 ),, /* 66: Only remote CUPS queues ... start this program with the /R parameter.) */
1095 NLSGetMessage( 28 ), 'E' /* 28: CUPS Path Not Found or Not Valid */
1096 globals.!cupsdir = ''
1097 END
1098
1099 /* Delete the error log file each time the program starts.
1100 */
1101 IF VRFileExists( globals.!log2 ) THEN
1102 CALL VRDeleteFile globals.!log2
1103
1104 window = VRWindow()
1105 call VRMethod window, "CenterWindow"
1106 call VRSet window, "Visible", 1
1107 call VRMethod window, "Activate"
1108 drop window
1109
1110 manufacturers.0 = 0
1111 CALL SetPage1
1112
1113RETURN
1114
1115/*:VRX InitMessageLog
1116*/
1117/* Initialize the message logfile. Unlike the error log, which is cleared and
1118 * recreated every time the program starts, the message log is appended to
1119 * until it reaches 100kB in size. If the message log is larger than 100kB when
1120 * this function is called, it is renamed (with '~' appended to the name) and
1121 * a new message log is started.
1122 */
1123InitMessageLog: PROCEDURE EXPOSE globals.
1124
1125 logsize = STREAM( globals.!log1, 'C', 'QUERY SIZE')
1126 IF ( logsize <> '') & ( logsize > 102400 ) THEN DO
1127 CALL VRCopyFile globals.!log1, globals.!log1 || '~'
1128 CALL VRDeleteFile globals.!log1
1129 END
1130
1131 datestr = DATE('L') TIME('N')
1132 CALL LINEOUT globals.!log1, '--[' datestr ']' ||,
1133 COPIES('-', 73 - LENGTH( datestr ))
1134RETURN
1135
1136/*:VRX LB_BRAND_Click
1137*/
1138LB_BRAND_Click: PROCEDURE EXPOSE globals. manufacturers.
1139
1140 CALL VRSet 'WN_MAIN', 'StatusText', ''
1141
1142 index = VRGet('LB_BRAND', 'Selected')
1143 IF index == 0 THEN RETURN
1144
1145 item = VRMethod('LB_BRAND', 'GetItemData', index )
1146 IF item == 0 THEN RETURN
1147
1148 DO i = 1 TO manufacturers.item.!printers.0
1149 models.i = manufacturers.item.!printers.i.!model
1150 /* ppds.i = manufacturers.item.!printers.i.!driver */
1151 IF manufacturers.item.!printers.i.!driver == '' THEN
1152 ppds.i = ''
1153 ELSE
1154 ppds.i = i
1155
1156/* DEBUG
1157say 'Model: ' manufacturers.item.!printers.i.!model
1158say 'Driver: ' manufacturers.item.!printers.i.!driver
1159say ' ' manufacturers.item.!printers.i.!longname
1160if manufacturers.item.!printers.i.!driver2 <> '' then
1161 say 'Alternate:' manufacturers.item.!printers.i.!driver2
1162if manufacturers.item.!printers.i.!longname2 <> '' then
1163 say ' ' manufacturers.item.!printers.i.!longname2
1164say 'Type: ' manufacturers.item.!printers.i.!type
1165say '---'
1166 */
1167
1168 END
1169 models.0 = manufacturers.item.!printers.0
1170 ppds.0 = manufacturers.item.!printers.0
1171
1172 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1173 CALL VRMethod 'LB_SELECT', 'Clear'
1174 CALL VRSet 'LB_SELECT', 'Painting', 0
1175 CALL VRMethod 'LB_SELECT', 'AddStringList', 'models.',, 'ppds.'
1176 CALL VRSet 'LB_SELECT', 'Painting', 1
1177 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1178/* CALL VRSet 'LB_SELECT', 'Selected', 1 */
1179
1180RETURN
1181
1182/*:VRX LB_SELECT_Click
1183*/
1184LB_SELECT_Click: PROCEDURE EXPOSE globals. manufacturers.
1185 SELECT
1186 WHEN globals.!page == 1 THEN DO
1187 CALL VRSet 'WN_MAIN', 'StatusText', ''
1188
1189 brand = VRGet('LB_BRAND', 'Selected')
1190 IF brand == 0 THEN RETURN
1191 selected = VRGet('LB_SELECT', 'Selected')
1192 IF selected == 0 THEN RETURN
1193 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1194 IF which <> '' THEN DO
1195 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1196 IF man == '' THEN RETURN
1197 make = manufacturers.man.!name
1198 model = manufacturers.man.!printers.which.!model
1199 driver = manufacturers.man.!printers.which.!type
1200 IF WORD( driver, 1 ) == 'hpcups' THEN driver = 'HPLIP'
1201 remark = manufacturers.man.!printers.which.!remark
1202 IF driver == '' THEN
1203 type = ''
1204 ELSE IF remark == '' THEN
1205 type = ' ('driver')'
1206 ELSE
1207 type = ' ('driver' - 'remark')'
1208 CALL VRSet 'WN_MAIN', 'StatusText', make model type
1209 END
1210 END
1211
1212 OTHERWISE NOP
1213 END
1214
1215 CALL VRSet 'PB_NEXT', 'Enabled', 1
1216RETURN
1217
1218/*:VRX LoadSettings
1219*/
1220LoadSettings: PROCEDURE EXPOSE globals.
1221
1222 me = VRGet('Application', 'Program')
1223 IF me == '' THEN PARSE SOURCE . . me
1224 globals.!mydir = VRParseFilePath( me, 'DP')
1225
1226 /* Get CUPS paths.
1227 */
1228 PARSE VALUE VRGetIni('eCups', 'CUPS', 'USER') WITH cupsdrv '00'x
1229 IF cupsdrv == '' THEN
1230 cupsdrv = VRParseFilePath( me, 'D') || ':'
1231 ELSE
1232 cupsdrv = STRIP( cupsdrv, 'T', '\')
1233 globals.!cupsdir = cupsdrv'\cups'
1234
1235 /* Get system paths.
1236 */
1237 globals.!bootdrv = SysBootDrive()
1238 IF globals.!bootdrv == '' THEN
1239 globals.!bootdrv = FILESPEC('DRIVE', VALUE('OS2_SHELL',,'OS2ENVIRONMENT'))
1240 globals.!os2dir = globals.!bootdrv'\OS2'
1241 globals.!tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
1242 IF globals.!tmpdir == '' THEN
1243 globals.!tmpdir = VALUE('TEMP',,'OS2ENVIRONMENT')
1244 IF globals.!tmpdir == '' THEN
1245 globals.!tmpdir = globals.!mydir
1246 globals.!logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
1247 IF globals.!logdir == '' THEN
1248 globals.!logdir = globals.!mydir
1249
1250 globals.!log1 = globals.!logdir'\cupswiz.l1'
1251 globals.!log2 = globals.!logdir'\cupswiz.l2'
1252
1253 /* Get printer-related paths.
1254 */
1255 PARSE VALUE VRGetIni('PM_INSTALL', 'PDR_DIR', 'USER') WITH repos_dir '00'x .
1256 globals.!repository = repos_dir
1257 globals.!prdrv = STREAM( globals.!os2dir'\install\prdrv.lst', 'C', 'QUERY EXISTS')
1258 globals.!prdesc = STREAM( globals.!os2dir'\install\prdesc.lst', 'C', 'QUERY EXISTS')
1259
1260 /* Set the language file name.
1261 */
1262 globals.!nlsfile = 'cupswz'
1263
1264RETURN 0
1265
1266/*:VRX LoopbackName
1267*/
1268/* Check to see if 'localhost' is defined in the HOSTS file. If not, we'll
1269 * have to use '127.0.0.1' instead.
1270 */
1271LoopbackName: PROCEDURE
1272
1273 lo_name = '127.0.0.1'
1274 etcdir = VALUE('ETC',,'OS2ENVIRONMENT')
1275 IF etcdir <> '' THEN DO
1276 hosts = STREAM( etcdir'\HOSTS', 'C', 'QUERY EXISTS')
1277 IF hosts <> '' THEN DO
1278 CALL LINEIN hosts, 1, 0
1279 DO WHILE LINES( hosts ) > 0
1280 _hostdef = TRANSLATE( LINEIN( hosts ))
1281 _hostdef = TRANSLATE( _hostdef, ' ', '09'x )
1282 IF WORDPOS('LOCALHOST', _hostdef ) == 2 THEN DO
1283 lo_name = 'localhost'
1284 LEAVE
1285 END
1286 END
1287 END
1288 END
1289
1290RETURN lo_name
1291
1292/*:VRX PB_ABOUT_Click
1293*/
1294PB_ABOUT_Click:
1295 CALL SW_ABOUT_Close
1296RETURN
1297
1298/*:VRX PB_CANCEL_Click
1299*/
1300PB_CANCEL_Click:
1301 CALL Quit
1302return
1303
1304/*:VRX PB_CREATECANCEL_Click
1305*/
1306PB_CREATECANCEL_Click:
1307 CALL SW_CREATE_Close
1308RETURN
1309
1310/*:VRX PB_CREATEOK_Click
1311*/
1312PB_CREATEOK_Click:
1313
1314 create_os2 = VRGet('CHK_CREATEPM', 'Set')
1315 globals.!os2printer = create_os2
1316 globals.!os2driver = VRGet('DDCB_PRESDRV', 'SelectedString')
1317 globals.!create = 1
1318
1319 CALL SW_CREATE_Close
1320
1321RETURN
1322
1323/*:VRX PB_MODELCANCEL_Click
1324*/
1325PB_MODELCANCEL_Click:
1326 CALL SW_MODEL_Close
1327 globals.!prt_nick = 'Generic PostScript Printer'
1328RETURN
1329
1330/*:VRX PB_MODELOK_Click
1331*/
1332PB_MODELOK_Click:
1333 globals.!prt_nick = VRGet( "LB_OS2MODELS", "SelectedString" )
1334 CALL SW_MODEL_Close
1335RETURN
1336
1337/*:VRX PB_NETCANCEL_Click
1338*/
1339PB_NETCANCEL_Click:
1340 CALL SW_NETWORK_Fini
1341RETURN
1342
1343/*:VRX PB_NETOK_Click
1344*/
1345PB_NETOK_Click: PROCEDURE EXPOSE globals. port
1346
1347 idx = VRGet('DDCB_PROTOCOL', 'Selected')
1348 which = VRMethod('DDCB_PROTOCOL', 'GetItemData', idx )
1349 server = STRIP( VRGet("EF_SERVER", "Value"))
1350 pqueue = STRIP( VRGet("EF_QUEUE", "Value"))
1351 cqueue = STRIP( VRGet("DDCB_CUPSQUEUE", "Value"))
1352 userid = STRIP( VRGet("EF_USERID", "Value"))
1353 passwd = STRIP( VRGet("EF_PASSWORD", "Value"))
1354
1355 invalid = 0
1356
1357 SELECT
1358 WHEN which == 1 THEN DO /* IPP */
1359 IF server == '' | pqueue == '' THEN invalid = 1
1360 uri = 'ipp://'
1361 IF userid <> '' THEN DO
1362 uri = uri || userid
1363 IF passwd <> '' THEN uri = uri':'passwd
1364 uri = uri'@'
1365 END
1366 uri = uri || server'/'pqueue
1367 END
1368 WHEN which == 2 THEN DO /* SOCKET */
1369 IF server == '' THEN invalid = 1
1370 uri = 'socket://'server
1371 END
1372 WHEN which == 3 THEN DO /* LPD */
1373 IF server == '' THEN invalid = 1
1374 IF pqueue == '' THEN pqueue = '*'
1375 IF userid <> '' THEN
1376 uri = 'ipp://'userid'@'server'/'pqueue
1377 ELSE
1378 uri = 'lpd://'server'/'pqueue
1379 END
1380 WHEN which == 4 THEN DO /* SMB */
1381 IF server == '' | pqueue == '' THEN invalid = 1
1382 uri = 'smb://'
1383 IF userid <> '' THEN DO
1384 uri = uri || userid
1385 IF passwd <> '' THEN uri = uri':'passwd
1386 uri = uri'@'
1387 END
1388 uri = uri || server'/'pqueue
1389 END
1390 OTHERWISE DO /* Existing CUPS */
1391 IF server == '' | cqueue == '' THEN invalid = 1
1392 ELSE DO
1393 globals.!remotecups = server cqueue
1394 uri = ''
1395 END
1396 END
1397 END
1398
1399 IF invalid == 1 THEN DO
1400 CALL VRMessage VRWindow(), NLSGetMessage( 74 ),, /* 74: Missing required value(s). */
1401 NLSGetMessage( 75 ), 'E' /* 75: Missing Value(s) */
1402 RETURN
1403 END
1404
1405 port = uri
1406 CALL SW_NETWORK_Fini
1407
1408RETURN
1409
1410/*:VRX PB_NEXT_Click
1411*/
1412PB_NEXT_Click: PROCEDURE EXPOSE globals. manufacturers.
1413
1414 SELECT
1415 WHEN globals.!page == 1 THEN DO
1416 brand = VRGet('LB_BRAND', 'Selected')
1417 IF brand == 0 THEN RETURN
1418 selected = VRGet('LB_SELECT', 'Selected')
1419 IF selected == 0 THEN RETURN
1420
1421 CALL VRSet 'WN_MAIN', 'StatusText', ''
1422
1423 which = VRMethod('LB_SELECT', 'GetItemData', selected )
1424 IF which == '' THEN DO
1425 globals.!mode = 2 /* Mode 2: user-selected PPD file */
1426 ppd = VRFileDialog( VRWindow(), NLSGetMessage( 24 ), 'O', '*.ppd') /* 24: Select PPD */
1427 IF ppd == '' THEN RETURN
1428 globals.!prt_ppd = ppd
1429 globals.!prt_dev = ''
1430 globals.!prt_nick = GetNameFromPPD( ppd )
1431 IF globals.!prt_nick == '' THEN DO
1432 CALL VRMessage VRWindow(), NLSGetMessage( 76, ppd ),, /* 76: Could not read printer name from %1. */
1433 NLSGetMessage( 77 ), 'E' /* 77: Invalid PPD */
1434 RETURN
1435 END
1436 END
1437 ELSE DO
1438 man = VRMethod('LB_BRAND', 'GetItemData', brand )
1439 IF man == '' THEN DO
1440 /* TODO display an error? But this shouldn't be possible... */
1441 RETURN
1442 END
1443 ppd = manufacturers.man.!printers.which.!driver
1444 globals.!mode = 1 /* Mode 1: CUPS-included model */
1445 IF POS('exe://', ppd ) > 0 THEN DO
1446 globals.!prt_ppd = ''
1447 globals.!prt_dev = ppd
1448 sel_brand = VRGet('LB_BRAND', 'SelectedString')
1449 sel_name = sel_brand VRMethod('LB_SELECT', 'GetString', selected )
1450 PARSE VAR sel_name _nick ' - CUPS' .
1451 IF _nick == '' THEN
1452 globals.!prt_nick = STRIP( sel_name )
1453 ELSE
1454 globals.!prt_nick = STRIP( _nick )
1455 END
1456 ELSE DO
1457 globals.!prt_ppd = TRANSLATE( globals.!cupsdir'/share/cups/model/'ppd, '\', '/')
1458 globals.!prt_dev = ''
1459 globals.!prt_nick = GetNameFromPPD( globals.!prt_ppd )
1460 END
1461 END
1462 globals.!remotecups = ''
1463
1464 CALL InitMessageLog
1465 IF globals.!mode == 2 THEN
1466 CALL LINEOUT globals.!log1, 'Starting printer install with user-provided PPD:'
1467 ELSE
1468 CALL LINEOUT globals.!log1, 'Starting printer install for built-in model:'
1469 IF globals.!prt_dev <> '' THEN
1470 CALL LINEOUT globals.!log1, ' - Device name:' globals.!prt_dev
1471 ELSE
1472 CALL LINEOUT globals.!log1, ' - PPD file: ' globals.!prt_ppd
1473 CALL LINEOUT globals.!log1, ' - Model name: ' globals.!prt_nick
1474 CALL LINEOUT globals.!log1, ''
1475
1476 CALL SetPage2
1477 END
1478
1479 WHEN globals.!page == 2 THEN DO
1480 selected = VRGet('LB_SELECT', 'Selected')
1481 IF selected == 0 THEN RETURN
1482 port = VRMethod('LB_SELECT', 'GetItemData', selected )
1483
1484 IF port == '' THEN DO
1485 /* Network printer selected; prompt for the connection details
1486 */
1487 CALL VRLoadSecondary 'SW_NETWORK', 'W'
1488 END
1489
1490 IF port == '' & globals.!remotecups == '' THEN RETURN
1491 globals.!prt_port = port
1492
1493 CALL SetPage3
1494 END
1495
1496 WHEN globals.!page == 3 THEN DO
1497 globals.!prt_name = STRIP( VRGet('EF_NAME', 'Value'))
1498 globals.!prt_loc = STRIP( VRGet('EF_LOCATION', 'Value'))
1499 globals.!prt_info = STRIP( VRGet('EF_DESC', 'Value'))
1500 IF ((( globals.!prt_name == '') |,
1501 ( globals.!prt_loc == '')) & ( globals.!remotecups == '')) |,
1502 ( globals.!prt_info == '') THEN
1503 DO
1504 IF ( globals.!remotecups <> '') THEN
1505 _errmsg = NLSGetMessage( 42 ) /* 42: You must enter a description. */
1506 ELSE
1507 _errmsg = NLSGetMessage( 43 ) /* 43: You must enter a name, a location, and a description. */
1508 CALL VRMessage VRWindow(), _errmsg, NLSGetMessage( 75 ), 'E' /* 75: Missing Value(s) */
1509 RETURN
1510 END
1511 IF ( globals.!remotecups == '' &,
1512 ( POS( LEFT( globals.!prt_name, 1 ),,
1513 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') == 0 ) |,
1514 ( VERIFY( globals.!prt_name, '/# ' || '09'x, 'MATCH') <> 0 )) THEN
1515 DO
1516 CALL VRMessage VRWindow(), NLSGetMessage( 44 ),, /* 44: The printer name must start with ... or tab characters. */
1517 NLSGetMessage( 45 ), 'E' /* 45: Invalid Name */
1518 RETURN
1519 END
1520
1521 /* TODO support other drivers
1522 */
1523 IF WORD( globals.!prt_nick, 1 ) == 'Apollo' |,
1524 WORD( globals.!prt_nick, 1 ) == 'HP' |,
1525 WORD( globals.!prt_nick, 1 ) == 'Hewlett-Packard' THEN
1526 globals.!os2driver = 'ECUPS-HP'
1527 ELSE
1528 globals.!os2driver = 'ECUPS'
1529
1530 CALL ConfirmAndCreate
1531 END
1532
1533 WHEN globals.!page == 4 THEN DO
1534 CALL NLSSetText 'PB_NEXT', 'Caption', 5 /* 5: Next > */
1535 CALL VRSet 'EF_NAME', 'Value', ''
1536 CALL VRSet 'EF_LOCATION', 'Value', ''
1537 CALL VRSet 'EF_DESC', 'Value', ''
1538 CALL SetPage1
1539 END
1540
1541 OTHERWISE NOP
1542 END
1543
1544RETURN
1545
1546/*:VRX PICT_ICON_Click
1547*/
1548PICT_ICON_Click: PROCEDURE EXPOSE globals.
1549 CALL VRLoadSecondary 'SW_ABOUT', 'W'
1550RETURN
1551
1552/*:VRX PromptForPMName
1553*/
1554PromptForPMName: PROCEDURE EXPOSE globals. models. best
1555 best = MatchPrinterModel( globals.!os2driver, globals.!prt_nick )
1556
1557 IF models.0 == 0 THEN DO
1558 /* No similar models were found in the list of supported printers.
1559 * Just use the generic PS driver.
1560 */
1561 CALL VRMessage VRWindow(), NLSGetMessage( 67, globals.!prt_nick, globals.!os2driver ),, /* 67: The printer "%1" does not ... application support. */
1562 NLSGetMessage( 68 ), 'W' /* 68: Printer Name Not Found */
1563 globals.!prt_nick = 'Generic PostScript Printer'
1564 RETURN
1565 END
1566
1567 CALL VRLoadSecondary 'SW_MODEL', 'W'
1568
1569RETURN
1570
1571/*:VRX Quit
1572*/
1573Quit:
1574 window = VRWindow()
1575 call VRSet window, "Shutdown", 1
1576 drop window
1577return
1578
1579/*:VRX SetLanguage
1580*/
1581SetLanguage: PROCEDURE EXPOSE globals.
1582 PARSE ARG locale
1583
1584 /*
1585 * This function locates the proper language files, and uses the message
1586 * file to sets all UI text. If the language could not be determined, we
1587 * default to English.
1588 */
1589 execPath = VRGet('Application', 'Program')
1590 execDir = VRParseFileName( execPath, 'DP')
1591
1592 /*
1593 * First, figure out what language/message file to use.
1594 */
1595 IF locale <> '' THEN
1596 syslanguage = locale
1597 ELSE
1598 syslanguage = VALUE('LANG',,'OS2ENVIRONMENT')
1599
1600 SELECT
1601 WHEN TRANSLATE( syslanguage ) == 'ZH_TW' THEN nlv = 'tw'
1602 WHEN TRANSLATE( syslanguage ) == 'ZH_CN' THEN nlv = 'cx'
1603 OTHERWISE PARSE VAR syslanguage nlv '_' .
1604 END
1605 nlvfile = globals.!nlsfile || nlv
1606 IF ( STREAM( execDir'\'nlvfile'.msg', 'C', 'QUERY EXISTS') \= '') | ( SysSearchPath('DPATH', nlvfile'.msg') \= '') THEN DO
1607 globals.!messages = nlvfile'.msg'
1608 helpfile = nlvfile'.hlp'
1609 CALL VRSet 'WN_MAIN', 'HelpFile', helpfile
1610 END
1611 ELSE DO
1612 globals.!messages = globals.!nlsfile || 'en.msg'
1613 helpfile = globals.!nlsfile || 'en.hlp'
1614 CALL VRSet 'WN_MAIN', 'HelpFile', helpfile
1615 END
1616
1617 /*
1618 * If the message file is missing or unreadable, display an error and then exit.
1619 */
1620 IF NLSGetMessage( 1 ) == '' THEN DO
1621 CALL VRMessage VRWindow(), 'Language file' TRANSLATE( globals.!messages ) 'could not be loaded.', 'Cannot Continue', 'E'
1622 RETURN 0
1623 END
1624
1625 /*
1626 * Now set the captions for the UI controls on the main window, according
1627 * to the specified language.
1628 */
1629 CALL NLSSetText 'WN_MAIN', 'Caption', 1 /* 1: Create CUPS Printer */
1630 CALL NLSSetText 'PB_NEXT', 'Caption', 5 /* 5: Next > */
1631 CALL NLSSetText 'PB_CANCEL', 'Caption', 3 /* 3: Cancel */
1632 CALL NLSSetText 'PB_REFRESH', 'Caption', 6 /* 6: Refresh */
1633
1634RETURN 1
1635
1636/*:VRX SetPage1
1637*/
1638SetPage1: PROCEDURE EXPOSE globals. manufacturers.
1639
1640 CALL VRMethod 'LB_BRAND', 'Clear'
1641 CALL VRSet 'PB_NEXT', 'Enabled', 0
1642 CALL VRSet 'LB_BRAND', 'Visible', 1
1643
1644 /* Resize LB_SELECT if necessary to make room for LB_BRAND */
1645 lb_x = VRGet('LB_BRAND', 'Left') + VRGet('LB_BRAND', 'Width') + 60
1646 lb_w = VRGet('GB_INFO', 'Width') - lb_x + VRGet('GB_INFO', 'Left')
1647 CALL VRSet 'LB_SELECT', 'Left', lb_x
1648 CALL VRSet 'LB_SELECT', 'Width', lb_w
1649
1650 CALL VRSet 'LB_SELECT', 'Visible', 1
1651 CALL VRSet 'GB_INFO', 'Visible', 0
1652
1653 globals.!page = 1
1654 globals.!prt_ppd = ''
1655 globals.!prt_dev = ''
1656 globals.!prt_nick = ''
1657 globals.!prt_port = ''
1658 globals.!remotecups = ''
1659 globals.!prt_name = ''
1660 globals.!prt_loc = ''
1661 globals.!prt_info = ''
1662 globals.!os2driver = ''
1663
1664 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1665
1666 IF manufacturers.0 == 0 THEN DO
1667
1668 /* Populate the manufacturer list */
1669 IF globals.!cupsdir == '' THEN DO
1670 manufacturers.1.!name = NLSGetMessage( 22 ) /* 22: -- Custom -- */
1671 manufacturers.1.!printers.0 = 1
1672 manufacturers.1.!printers.1.!model = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
1673 manufacturers.1.!printers.1.!driver = ''
1674 manufacturers.1.!printers.1.!type = ''
1675 manufacturers.1.!printers.1.!remark = NLSGetMessage( 23 ) /* 23: -- Other printer (requires PPD) -- */
1676 manufacturers.1.!printers.1.!driver2 = ''
1677 manufacturers.1.!printers.1.!remark2 = ''
1678 manufacturers.0 = 1
1679 END
1680 ELSE
1681 CALL GetCupsPrinters
1682
1683 END
1684 CALL NLSSetText 'DT_INFO', 'Caption', 21 /* 21: Select the printer manufacturer and model from the list below. */
1685
1686 CALL VRSet 'LB_BRAND', 'Painting', 0
1687 DO i = 1 TO manufacturers.0
1688 addman.i = manufacturers.i.!name
1689 addidx.i = i
1690 END
1691 addman.0 = manufacturers.0
1692 addidx.0 = manufacturers.0
1693 CALL VRMethod 'LB_BRAND', 'AddStringList', 'addman.',, 'addidx.'
1694 CALL VRSet 'LB_BRAND', 'Painting', 1
1695
1696 CALL VRMethod 'LB_BRAND', 'SetFocus'
1697 CALL VRSet 'LB_BRAND', 'Selected', 1
1698 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1699
1700RETURN
1701
1702/*:VRX SetPage2
1703*/
1704SetPage2: PROCEDURE EXPOSE globals.
1705
1706 globals.!page = 2
1707 CALL VRSet 'LB_BRAND', 'Visible', 0
1708 CALL VRSet 'PB_NEXT', 'Enabled', 0
1709 CALL NLSSetText 'WN_MAIN', 'StatusText', 29, globals.!prt_nick /* 29: Selected printer: %1 */
1710
1711 /* Resize LB_SELECT to the full width of GB_INFO */
1712 lb_x = VRGet('GB_INFO', 'Left')
1713 lb_w = VRGet('GB_INFO', 'Width')
1714 CALL VRSet 'LB_SELECT', 'Left', lb_x
1715 CALL VRSet 'LB_SELECT', 'Width', lb_w
1716
1717 CALL VRMethod 'LB_SELECT', 'Clear'
1718
1719 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1720 IF globals.!cupsdir == '' THEN DO
1721 CALL VRMethod 'LB_SELECT', 'AddString', NLSGetMessage( 34 ),, '' /* 34: Network printer (manual configuration) */
1722 CALL VRSet 'LB_SELECT', 'Selected', 1
1723 END
1724 ELSE
1725 CALL GetCupsPorts
1726 CALL VRMethod 'LB_SELECT', 'SetFocus'
1727 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1728
1729RETURN
1730
1731/*:VRX SetPage3
1732*/
1733SetPage3: PROCEDURE EXPOSE globals.
1734
1735 globals.!page = 3
1736 CALL VRSet 'EF_DESC', 'Value', globals.!prt_nick
1737 CALL NLSSetText DT_NAME, 'Caption', 103 /* 103: Name: */
1738 CALL NLSSetText DT_LOCATION, 'Caption', 105 /* 105: Location: */
1739 CALL NLSSetText DT_DESC, 'Caption', 106 /* 106: Description: */
1740
1741 CALL VRMethod 'LB_SELECT', 'Clear'
1742
1743 CALL VRSet 'LB_SELECT', 'Visible', 0
1744 CALL VRSet 'GB_INFO', 'Visible', 1
1745 IF globals.!remotecups == '' THEN DO
1746 CALL NLSSetText 'DT_INFO', 'Caption', 40 /* 40: Choose the printer name, and enter its location and a short description. */
1747 CALL VRSet 'DT_NAME', 'Visible', 1
1748 CALL VRSet 'EF_NAME', 'Visible', 1
1749 CALL VRSet 'DT_LOCATION', 'Visible', 1
1750 CALL VRSet 'EF_LOCATION', 'Visible', 1
1751 END
1752 ELSE
1753 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. */
1754 CALL VRSet 'DT_DESC', 'Visible', 1
1755 CALL VRSet 'EF_DESC', 'Visible', 1
1756
1757 CALL VRMethod 'EF_NAME', 'SetFocus'
1758
1759RETURN
1760
1761/*:VRX SetPage4
1762*/
1763SetPage4:
1764
1765 globals.!page = 4
1766 CALL VRSet 'LB_SELECT', 'Visible', 0
1767 CALL VRSet 'GB_INFO', 'Visible', 0
1768 CALL VRSet 'WN_MAIN', 'StatusText', ''
1769
1770RETURN
1771
1772/*:VRX SW_ABOUT_Close
1773*/
1774SW_ABOUT_Close:
1775 call SW_ABOUT_Fini
1776return
1777
1778/*:VRX SW_ABOUT_Create
1779*/
1780SW_ABOUT_Create:
1781 call SW_ABOUT_Init
1782return
1783
1784/*:VRX SW_ABOUT_Fini
1785*/
1786SW_ABOUT_Fini:
1787 window = VRInfo( "Window" )
1788 call VRDestroy window
1789 drop window
1790return
1791/*:VRX SW_ABOUT_Init
1792*/
1793SW_ABOUT_Init:
1794
1795 CALL NLSSetText 'SW_ABOUT', 'Caption', 10 /* 10: Product Information */
1796 CALL NLSSetText 'DT_ABOUT1', 'Caption', 11 /* 11: eCups Printer Install Utility */
1797 CALL NLSSetText 'DT_ABOUT2', 'Caption', 12, '1.02' /* 12: Version %1 */
1798 CALL NLSSetText 'DT_ABOUT3', 'Caption', 13, '2010, 2013' /* 13: (C) %1 Alex Taylor */
1799 CALL NLSSetText 'PB_ABOUT', 'Caption', 2 /* 10: Product Information */
1800
1801 CALL NLSSetText 'DT_BOOTDRIVE', 'Caption', 14, TRANSLATE( globals.!bootdrv ) /* 14: System boot volume: %1 */
1802 CALL NLSSetText 'DT_CUPSPATH', 'Caption', 15, TRANSLATE( globals.!cupsdir ) /* 15: Local CUPS directory: %1 */
1803 CALL NLSSetText 'DT_REPOSITORY', 'Caption', 16, TRANSLATE( globals.!repository ) /* 16: Local driver repository: %1 */
1804
1805 window = VRInfo( "Object" )
1806 if( \VRIsChildOf( window, "Notebook" ) ) then do
1807 call VRMethod window, "CenterWindow"
1808 call VRSet window, "Visible", 1
1809 call VRMethod window, "Activate"
1810 end
1811 drop window
1812return
1813
1814/*:VRX SW_CREATE_Close
1815*/
1816SW_CREATE_Close:
1817 call SW_CREATE_Fini
1818return
1819
1820/*:VRX SW_CREATE_Create
1821*/
1822SW_CREATE_Create:
1823 call SW_CREATE_Init
1824return
1825
1826/*:VRX SW_CREATE_Fini
1827*/
1828SW_CREATE_Fini:
1829 window = VRInfo( "Window" )
1830 call VRDestroy window
1831 drop window
1832return
1833/*:VRX SW_CREATE_Init
1834*/
1835SW_CREATE_Init:
1836
1837 CALL NLSSetText 'SW_CREATE', 'Caption', 115 /* 115: Confirm Create Printer */
1838 CALL NLSSetText 'DT_CRMODEL', 'Caption', 102 /* 102: Model: */
1839 CALL NLSSetText 'DT_CRLOC', 'Caption', 105 /* 105: Location: */
1840 CALL NLSSetText 'DT_CRDESC', 'Caption', 106 /* 106: Description: */
1841
1842 CALL NLSSetText 'CHK_CREATEPM', 'Caption', 109 /* 109: Create printer object */
1843 CALL NLSSetText 'DT_PRESDRV', 'Caption', 110 /* 110: Presentation driver: */
1844 CALL NLSSetText 'PB_CREATEOK', 'Caption', 111 /* 111: Create */
1845 CALL NLSSetText 'PB_CREATECANCEL', 'Caption', 3 /* 3: Cancel */
1846 CALL NLSSetText 'PB_CREATEHELP', 'Caption', 4 /* 4: ~Help */
1847
1848 CALL VRSet 'EF_CRMODEL', 'Value', globals.!prt_nick
1849
1850 IF globals.!remotecups <> '' THEN DO
1851 /* An existing CUPS printer was indicated. This means we're not
1852 * creating a CUPS printer, but only a PM printer object (and port)
1853 * that points to it.
1854 */
1855 CALL NLSSetText 'DT_CREATE', 'Caption', 101 /* 101: Ready to create printer object with the following parameters. */
1856
1857 PARSE VAR globals.!remotecups cups_host cups_printer .
1858 CALL NLSSetText 'DT_CRNAME', 'Caption', 107 /* 107: CUPS server: */
1859 CALL NLSSetText 'DT_CRURI', 'Caption', 108 /* 108: CUPS queue: */
1860 CALL VRSet 'DT_CRLOC', 'Visible', 0
1861 CALL VRSet 'EF_CRNAME', 'Value', cups_host
1862 CALL VRSet 'EF_CRURI', 'Value', cups_printer
1863 CALL VRSet 'EF_CRLOC', 'Visible', 0
1864 CALL VRSet 'CHK_CREATEPM', 'Visible', 0
1865 END
1866 ELSE DO
1867 CALL NLSSetText 'DT_CREATE', 'Caption', 100 /* 100: Ready to create CUPS printer with the following parameters. */
1868 CALL NLSSetText 'DT_CRNAME', 'Caption', 103 /* 103: Name: */
1869 CALL NLSSetText 'DT_CRURI', 'Caption', 104 /* 104: URI: */
1870 CALL VRSet 'EF_CRNAME', 'Value', globals.!prt_name
1871 CALL VRSet 'EF_CRURI', 'Value', globals.!prt_port
1872 CALL VRSet 'EF_CRLOC', 'Value', globals.!prt_loc
1873 END
1874 CALL VRSet 'EF_CRDESC', 'Value', globals.!prt_info
1875
1876 IF QueryAvailableDrivers() > 0 THEN DO
1877 def_idx = 1
1878 CALL VRMethod 'DDCB_PRESDRV', 'AddStringList', 'drv_list.'
1879 DO i = 1 TO drv_list.0
1880 IF drv_list.i == globals.!os2driver THEN DO
1881 def_idx = i
1882 LEAVE
1883 END
1884 END
1885 CALL VRSet 'DDCB_PRESDRV', 'Selected', def_idx
1886 END
1887 ELSE DO /* 112: No eCups-compatible OS/2 presentation drivers are installed. */
1888 /* 113: Please install the ECUPS or ECUPS-HP printer driver before continuing. */
1889 CALL VRMessage VRWindow(),
1890 NLSGetMessage( 112 ) || '0d0a0d0a'x || NLSGetMessage( 113 ),,
1891 NLSGetMessage( 114 ), 'E' /* 114: Missing PM Driver */
1892 CALL VRSet 'PB_CREATEOK', 'Enabled', 0
1893 /* TODO give an error if no drivers were found */
1894 END
1895
1896 window = VRInfo( "Object" )
1897 if( \VRIsChildOf( window, "Notebook" ) ) then do
1898 call VRMethod window, "CenterWindow"
1899 call VRSet window, "Visible", 1
1900 call VRMethod window, "Activate"
1901 end
1902 drop window
1903
1904RETURN
1905
1906/*:VRX SW_MODEL_Close
1907*/
1908SW_MODEL_Close:
1909 call SW_MODEL_Fini
1910return
1911
1912/*:VRX SW_MODEL_Create
1913*/
1914SW_MODEL_Create:
1915 call SW_MODEL_Init
1916return
1917
1918/*:VRX SW_MODEL_Fini
1919*/
1920SW_MODEL_Fini:
1921
1922 CALL VRSet 'WN_MAIN', 'Pointer', 'WAIT'
1923
1924 window = VRInfo( "Window" )
1925 call VRDestroy window
1926 drop window
1927return
1928/*:VRX SW_MODEL_Init
1929*/
1930SW_MODEL_Init:
1931
1932 CALL NLSSetText 'SW_MODEL', 'Caption', 120 /* 120: Select Printer Model */
1933
1934 /* We should have a list of suggested printer models whose names at least
1935 * partially match the requested model, sorted in order with the closest
1936 * match at the top.
1937 */
1938 ok = VRMethod( "LB_OS2MODELS", "AddStringList", "models.", )
1939 IF best > 0 THEN
1940 CALL VRSet 'LB_OS2MODELS', 'Selected', best
1941
1942 CALL NLSSetText 'DT_MODEL1', 'Caption',,
1943 121, globals.!prt_nick, globals.!os2driver /* 121: The printer "%1" could not ... to applications. */
1944 CALL NLSSetText 'DT_MODEL2', 'Caption', 122 /* 122: You can select one of ... use a generic driver. */
1945
1946 CALL NLSSetText 'PB_MODELOK', 'Caption', 2 /* 2: OK */
1947 CALL NLSSetText 'PB_MODELCANCEL', 'Caption', 3 /* 3: Cancel */
1948
1949 CALL VRSet 'WN_MAIN', 'Pointer', '<default>'
1950
1951 window = VRInfo( "Object" )
1952 if( \VRIsChildOf( window, "Notebook" ) ) then do
1953 call VRMethod window, "CenterWindow"
1954 call VRSet window, "Visible", 1
1955 call VRMethod window, "Activate"
1956 end
1957 drop window
1958
1959RETURN
1960
1961/*:VRX SW_NETWORK_Close
1962*/
1963SW_NETWORK_Close:
1964 call SW_NETWORK_Fini
1965return
1966
1967/*:VRX SW_NETWORK_Create
1968*/
1969SW_NETWORK_Create:
1970 call SW_NETWORK_Init
1971return
1972
1973/*:VRX SW_NETWORK_Fini
1974*/
1975SW_NETWORK_Fini:
1976 window = VRInfo( "Window" )
1977 call VRDestroy window
1978 drop window
1979return
1980/*:VRX SW_NETWORK_Init
1981*/
1982SW_NETWORK_Init:
1983
1984 CALL NLSSetText 'SW_NETWORK', 'Caption', 80 /* 80: Network Printer */
1985 CALL NLSSetText 'DT_PROTOCOL', 'Caption', 81 /* 81: Network protocol: */
1986 CALL NLSSetText 'DT_PASSWORD', 'Caption', 90 /* 90: Password: */
1987 CALL NLSSetText 'PB_NETOK', 'Caption', 2 /* 2: OK */
1988 CALL NLSSetText 'PB_NETCANCEL', 'Caption', 3 /* 3: Cancel */
1989 CALL NLSSetText 'PB_NETHELP', 'Caption', 4 /* 4: ~Help */
1990
1991 IF globals.!cupsdir == '' THEN DO
1992 protos.0 = 1
1993 protos.1 = NLSGetMessage( 91 ) /* 91: Existing CUPS printer (remote server) */
1994 pnums.0 = 1
1995 pnums.1 = 5
1996 END
1997 ELSE DO
1998 protos.0 = 5
1999 protos.1 = NLSGetMessage( 92 ) /* 92: Internet Printing Protocol (IPP) */
2000 protos.2 = NLSGetMessage( 93 ) /* 93: AppSocket/JetDirect */
2001 protos.3 = NLSGetMessage( 94 ) /* 94: Line Printer Remote daemon (LPD) */
2002 protos.4 = NLSGetMessage( 95 ) /* 95: Windows/SMB network */
2003 protos.5 = NLSGetMessage( 96 ) /* 96: Existing CUPS printer */
2004 pnums.0 = 5
2005 pnums.1 = 1
2006 pnums.2 = 2
2007 pnums.3 = 3
2008 pnums.4 = 4
2009 pnums.5 = 5
2010 END
2011
2012 CALL VRMethod 'DDCB_PROTOCOL', 'AddStringList', 'protos.',, 'pnums.'
2013 CALL VRSet 'DDCB_PROTOCOL', 'Selected', 1
2014
2015 window = VRInfo( "Object" )
2016 if( \VRIsChildOf( window, "Notebook" ) ) then do
2017 call VRMethod window, "CenterWindow"
2018 call VRSet window, "Visible", 1
2019 call VRMethod window, "Activate"
2020 end
2021 drop window
2022return
2023
2024/*:VRX WN_MAIN_Close
2025*/
2026WN_MAIN_Close:
2027 call Quit
2028return
2029
Note: See TracBrowser for help on using the repository browser.