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

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

Improved CUPSWIZ command-line parameter parsing logic.

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