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

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

Try to handle mismatched case in model name between DRV and PPD.

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