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

Last change on this file since 20 was 20, checked in by Alex Taylor, 13 years ago

Finish NLV enabling code.

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