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

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

Various minor fixes.

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