CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / os2 / MozSounds.cmd
blobd7836d4c5d694463bd682831452a31990c806d98
1 /* mozillasounds.cmd */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is a supplemental OS/2 script.
17 * The Initial Developer of the Original Code is
18 * Rich Walsh <dragtext@e-vertise.com>
19 * Portions created by the Initial Developer are Copyright (C) 2009
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /*****************************************************************************/
39 /* */
40 /* MozSounds.cmd enables the user to associate sounds with Mozilla events */
41 /* using the WPS Sound object in the System Setup folder. It does not set */
42 /* the sounds itself - it simply adds entries to the Sound object's list of */
43 /* events. This script only needs to be run once or twice: the first time */
44 /* to enable selected sounds, and the second time to disable most of them */
45 /* because they're so annoying. */
46 /* */
47 /* This script's design is coordinated with code in widget\os2\nsSound.cpp. */
48 /* Please don't make significant changes to it (e.g. changing the names of */
49 /* ini-file entries) without first examining nsSound.cpp. */
50 /* */
51 /* Note to Translators: everything that needs to be translated has been */
52 /* grouped together and placed toward the end of the file (a heading */
53 /* identifies where to start). Please preserve the formatting and don't */
54 /* change any of the numeric values. Thanks... */
55 /* */
56 /*****************************************************************************/
58 call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
59 call SysLoadFuncs
60 call InitVariables
61 call Main
62 exit
64 /*****************************************************************************/
66 Main:
68 /* Get the location of the MMOS2 directory. */
69 path = value('MMBASE',,'OS2ENVIRONMENT')
70 if path = '' then do
71 call SysCls
72 call EnvError
73 return
74 end
75 path = strip(path, B, ';')
77 /* Confirm that mmpm.ini can be found where we expect it to be. */
78 iniFile = path'\MMPM.INI'
79 call SysFileTree iniFile, 'stem', 'FO'
80 if stem.0 <> 1 then do
81 call SysCls
82 call IniError
83 return
84 end
86 /* Make a backup of mmpm.ini if one doesn't already exist. */
87 call SysFileTree iniFile'.BAK', 'stem', 'FO'
88 if stem.0 = 0 then
89 '@xcopy' iniFile path'\*.*.BAK /T > NUL'
91 /* Events are identified by number - MMOS2 uses 0-12. Mozilla events */
92 /* start at 800. If this conflicts with another app, the base index */
93 /* can be changed. The new value is stored in mmpm.ini where it can */
94 /* be accessed by the Mozilla apps and this script. */
95 baseIndex = SysIni(iniFile, 'MOZILLA_Events', 'BaseIndex')
96 baseIndex = strip(baseIndex, T, X2C('0'))
97 if baseIndex = 'ERROR:' | baseIndex <= '12' then
98 baseIndex = defaultIndex
100 /* The main loop: display current status & respond to commands */
101 do FOREVER
102 call SysCls
103 call GetStatus
104 call Display
105 pull cmd parms
107 select
108 when cmd = soundCmd then do
109 rc = SysOpenObject('<WP_SOUND>', 2, 'TRUE')
110 leave
113 when cmd = exitCmd then do
114 leave
117 when cmd = disableCmd then do
118 call Disable
121 when cmd = enableCmd then do
122 call Enable
125 /* this command is "undocumented" & should NOT be translated */
126 when cmd = 'BASEINDEX' then do
127 call ChangeBaseIndex
130 otherwise
134 return
136 /*****************************************************************************/
138 /* Generate a listing of Mozilla events and their status: */
139 /* 'enabled' if there's an entry, 'disabled' if not. */
141 GetStatus:
143 ctr = 1
144 show = 0
146 do nbr = 1 to events.0
147 rc = SysIni(iniFile, 'MMPM2_AlarmSounds', baseIndex + events.nbr.ndx)
148 if rc = 'ERROR:' then
149 status = disabledWord
150 else
151 status = enabledWord
153 if show = 0 then do
154 out = " "nbr". " left(events.nbr.name, 15) status
155 show = 1
157 else do
158 line.ctr = left(out, 35) " " nbr". " left(events.nbr.name, 15) status
159 ctr = ctr + 1
160 show = 0
164 if show = 1 then
165 line.ctr = left(out, 35)
167 return
169 /*****************************************************************************/
171 /* Disable an event sound by deleting its entry. */
173 Disable:
175 parse var parms nbr parms
177 if nbr = allWord then do
178 nbr = '1'
179 parms = '2 3 4 5 6 7'
182 do while nbr <> ''
183 if nbr >= '1' & nbr <= '7' then do
184 key = baseIndex + events.nbr.ndx
185 rc = SysIni(iniFile, 'MMPM2_AlarmSounds', key, 'DELETE:')
187 parse var parms nbr parms
190 return
192 /*****************************************************************************/
194 /* Enable an event sound by adding an entry whose format is: */
195 /* 'fq_soundfile#event_name#volume'. */
196 /* Since this script isn't intended to set the actual soundfile, */
197 /* it uses the same dummy value as MMOS2: 'x:\MMOS2\SOUNDS\' */
199 Enable:
201 parse var parms nbr parms
203 if nbr = allWord then do
204 nbr = '1'
205 parms = '2 3 4 5 6 7'
208 do while nbr <> ''
209 if nbr >= '1' & nbr <= '7' then do
210 key = baseIndex + events.nbr.ndx
212 /* if there's an existing entry, preserve the filename */
213 sndFile = SysIni(iniFile, 'MMPM2_AlarmSounds', key)
214 if sndFile = 'ERROR:' | left(sndFile, 1) = '#' then
215 sndFile = path'\'soundsDir'\'
216 else
217 parse var sndFile sndFile '#' .
218 value = sndFile'#'events.nbr.name' (Mozilla)#80'X2C('0')
220 rc = SysIni(iniFile, 'MMPM2_AlarmSounds', key, value)
222 parse var parms nbr parms
225 return
227 /*****************************************************************************/
229 /* An "undocumented" function to change & restore the base index. */
230 /* It renumbers existing entries using the new base & adds or deletes */
231 /* a 'MOZILLA_Events\BaseIndex' entry depending on the new value. */
233 ChangeBaseIndex:
235 parse var parms newIndex parms
237 /* Ignore invalid values. */
238 if newIndex = '' | newIndex <= '12' then
239 return
241 /* Do NOT translate this. */
242 if newIndex = 'DEFAULT' then
243 newIndex = defaultIndex
245 /* If there's no change, exit after deleting the entry if it's the default */
246 if newIndex = baseIndex then do
247 if baseIndex = defaultIndex then
248 rc SysIni(iniFile, 'MOZILLA_Events', 'BaseIndex', 'DELETE:')
249 return
252 /* Move existing entries from the old index to the new index. */
253 do nbr = 1 to events.0
254 value = SysIni(iniFile, 'MMPM2_AlarmSounds', baseIndex + events.nbr.ndx)
255 if value = 'ERROR:' then
256 iterate
258 rc = SysIni(iniFile, 'MMPM2_AlarmSounds', baseIndex + events.nbr.ndx, 'DELETE:')
259 rc = SysIni(iniFile, 'MMPM2_AlarmSounds', newIndex + events.nbr.ndx, value)
262 /* If the new index is the default, delete the ini entry; */
263 /* otherwise, add or update the entry with the new value. */
264 if newIndex = defaultIndex then
265 rc = SysIni(iniFile, 'MOZILLA_Events', 'BaseIndex', 'DELETE:')
266 else
267 rc = SysIni(iniFile, 'MOZILLA_Events', 'BaseIndex', newIndex||X2C('0'))
269 baseIndex = newIndex
271 return
273 /*****************************************************************************/
274 /* All strings that need to be translated appear below */
275 /*****************************************************************************/
277 /* Just like it says, init variables. */
279 InitVariables:
281 events.0 = 7
282 events.1.ndx = 0
283 events.1.name = 'New Mail'
284 events.2.ndx = 1
285 events.2.name = 'Alert Dialog'
286 events.3.ndx = 2
287 events.3.name = 'Confirm Dialog'
288 events.4.ndx = 3
289 events.4.name = 'Prompt Dialog'
290 events.5.ndx = 4
291 events.5.name = 'Select Dialog'
292 events.6.ndx = 5
293 events.6.name = 'Menu Execute'
294 events.7.ndx = 6
295 events.7.name = 'Menu Popup'
297 enabledWord = 'enabled'
298 disabledWord = 'disabled'
299 allWord = 'ALL'
300 soundsDir = 'SOUNDS'
302 enableCmd = 'E'
303 disableCmd = 'D'
304 soundCmd = 'S'
305 exitCmd = 'X'
307 defaultIndex = '800'
309 return
311 /*****************************************************************************/
313 /* Display event status & command info. */
315 Display:
318 say " MozSounds.cmd lets you use the WPS Sound object in your System Setup"
319 say " folder to assign sounds to the Mozilla events listed below. It does"
320 say " NOT set the sound itself - it just adds and deletes entries in Sound."
321 say " New or changed sounds take effect after the Mozilla app is restarted."
323 say " Event Status Event Status"
324 say " ----------- -------- ----------- --------"
325 say line.1
326 say line.2
327 say line.3
328 say line.4
330 say " Commands:"
331 say " E - enable event sound(s) example: 'E 1' or 'E 3 5 7' or 'E All'"
332 say " D - disable event sound(s) example: 'D 2' or 'D 1 4 6' or 'D All'"
333 say " S - open the WPS Sound object"
334 say " X - exit this script"
336 call charout ," Enter a command > "
338 return
340 /*****************************************************************************/
342 /* Display an error message */
344 EnvError:
346 say ""
347 say "ERROR: the 'MMBASE' environment variable is missing or invalid!"
348 say " Your Mozilla app won't be able to play system sounds without it."
349 say " Please add a line to config.sys like the following, then reboot."
350 say " SET MMBASE=x:\MMOS2 (where 'x' is the correct drive)"
352 return
354 /*****************************************************************************/
356 /* Display an error message */
358 IniError:
360 say ""
361 say "ERROR: file '"iniFile"' is missing or invalid!"
362 say " Your Mozilla app won't be able to play system sounds without it."
363 say " Please confirm that the 'SET MMBASE=' line in config.sys points"
364 say " at your MMOS2 directory and that it contains 'MMPM.INI'."
366 return
368 /*****************************************************************************/