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

Last change on this file since 59 was 59, checked in by Alex Taylor, 8 years ago

CUPSWIZ version 1.13, various fixes for changes in backend (esp installing drv:// type models).

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