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

Last change on this file since 53 was 53, checked in by Alex Taylor, 9 years ago

Commit v1.1 sources.

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