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

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

CleanPPD now filters out Translation strings. Check for several required programs on start. Set default paper size somewhat intelligently.

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