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

Last change on this file since 95 was 95, checked in by Alex Taylor, 3 years ago

Font scaling logic. Support for CUPS-PDF printer

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