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

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

More minor modifications for compatibility with RPM-installed CUPS.

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