]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/sound.js
optional sound queue so we can reduce sound collisions, plus some debugging info
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / sound.js
1 dump('entering util/sound.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.sound = function (interval) {
5
6     try {
7
8         /* We're going to turn this guy into a singleton, at least for a given window, and look for it in xulG */
9         if (! window.xulG) { window.xulG = {}; }
10         if (window.xulG._sound) { return window.xulG._sound; }
11
12         /* So we can queue up sounds and put a pause between them instead of having them trample over each other */
13         /* Limitation: interval only gets set once for a singleton */
14         if (interval) {
15             this._queue = true;
16             this._funcs = [];
17             JSAN.use('util.exec'); this._exec = new util.exec(); this._exec.timer( this._funcs, interval || 500 );
18         }
19
20         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
21         var SOUNDContractID = "@mozilla.org/sound;1";
22         var SOUNDIID        = Components.interfaces.nsISound;
23         this.SOUND          = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
24         this.SOUND.init(); // not necessary, but helps avoid delays?
25
26         this.origin = location.pathname;
27
28         window.xulG._sound = this;
29         return this;
30
31     } catch(E) {
32         dump('error in util.sound constructor: ' + E + '\n');
33         return this;
34     }
35 };
36
37 util.sound.prototype = {
38
39     'xp_url_init' : function (aURL) {
40         try {
41             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
42             var URLContractID   = "@mozilla.org/network/standard-url;1";
43             var URLIID          = Components.classes[URLContractID].createInstance( );
44             var URL             = URLIID.QueryInterface(Components.interfaces.nsIURL);
45             if (aURL) {
46                 URL.spec = aURL;
47             }
48             return URL;
49         } catch(E) {
50             alert('xp_url_init(): ' + E);
51         }
52     },
53
54     'play_url' : function(url) {
55
56         if (!url) { return; /* sound of silence */ }
57
58         var obj = this;
59         try {
60             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
61             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
62             var url2 = obj.xp_url_init( data.server + url );
63             dump('SOUND: file = ' + url + '\n');
64             if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
65
66                 if (obj._queue) {
67                     obj._funcs.push( function() { obj.SOUND.play( url2 ); } );
68                 } else {
69                     obj.SOUND.play( url2 );
70                 }
71             }
72         } catch(E) {
73             try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) { 
74                 dump('beep(): ' + F + '\n');
75             }
76             dump('play_url(): ' + E + '\n');
77         }
78     },
79
80     'event' : function event(evt) {
81         var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
82         dump('SOUND: key = ' + key + '\n');
83         this.play_url( urls[key] );
84     },
85
86     'good' : function good(e){
87         var key = 'AUDIO_' + arguments.callee.name;
88         dump('SOUND: key = ' + key + '\n');
89         this.play_url( urls[key] );
90     },
91
92     'bad' : function bad(e){
93         var key = 'AUDIO_' + arguments.callee.name;
94         dump('SOUND: key = ' + key + '\n');
95         this.play_url( urls[key] );
96     },
97
98     'horrible' : function horrible(e){
99         var key = 'AUDIO_' + arguments.callee.name;
100         dump('SOUND: key = ' + key + '\n');
101         this.play_url( urls[key] );
102     },
103
104     'circ_good' : function circ_good(e){
105         var key = 'AUDIO_' + arguments.callee.name;
106         dump('SOUND: key = ' + key + '\n');
107         this.play_url( urls[key] );
108     },
109
110     'circ_bad' : function circ_bad(e){
111         var key = 'AUDIO_' + arguments.callee.name;
112         dump('SOUND: key = ' + key + '\n');
113         this.play_url( urls[key] );
114     }
115 }
116
117 dump('exiting util/sound.js\n');