28 const Cc = Components.classes;
29 const Cu = Components.utils;
30 const Ci = Components.interfaces;
31 const Cr = Components.results;
32 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
33 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
34 Cu.import(
"resource://app/jsmodules/DebugUtils.jsm");
40 const LOG = DebugUtils.generateLogFunction(
"ngEqualizerPresetProviderManager", 2);
52 LOG(
"Initializing equalizer preset provider manager");
55 XPCOMUtils.defineLazyServiceGetter(
this,
"_mainProvider",
56 "@getnightingale.com/equalizer-presets/main-provider;1",
57 "ngIMainEqualizerPresetProvider");
58 XPCOMUtils.defineLazyServiceGetter(
this,
"_observerService",
59 "@mozilla.org/observer-service;1",
"nsIObserverService");
64 classID: Components.ID(
"{fead9fed-346b-49f1-94ca-21edd9e5fbf8}"),
65 contractID:
"@getnightingale.com/equalizer-presets/manager;1",
67 Ci.ngIEqualizerPresetCollection,
70 category:
'app-startup',
71 entry:
"ngEqualizerPresetProviderManager",
74 _observerService:
null,
77 if(aTopic ==
"app-startup") {
78 this._observerService.addObserver(
this,
"profile-after-change",
false);
80 else if(aTopic ==
"profile-after-change") {
81 this._observerService.removeObserver(
this,
"profile-after-change");
83 LOG(
"Adding the default presets");
84 var dProvider =
Cc[
"@getnightingale.com/equalizer-presets/defaults;1"]
85 .getService(
Ci.ngIEqualizerPresetProvider);
86 if(!this._providers.length)
87 this.registerPresetProvider(dProvider);
89 this._providers.splice(0, 0, dProvider);
91 LOG(
"Adding the user set presets");
93 this._addPresetsFromProvider(this._mainProvider);
95 this._observerService.addObserver(
this,
"equalizer-preset-saved",
false);
96 this._observerService.addObserver(
this,
"equalizer-preset-deleted",
false);
98 else if(aTopic ==
"equalizer-preset-saved"
99 || aTopic ==
"equalizer-preset-deleted") {
100 this._regeneratePresetsList();
109 if(this._providers) {
110 LOG(
"Adding the main provider to the presets and returning them in reverse.");
111 var providers = this._providers;
113 providers.push(this._mainProvider.QueryInterface(
Ci.ngIEqualizerPresetProvider));
114 return ArrayConverter.nsIArray(providers.reverse());
117 throw Cr.NS_ERROR_UNEXPECTED;
121 return ArrayConverter.nsIArray(this._presets);
123 throw Cr.NS_ERROR_UNEXPECTED;
125 getPresetByName:
function(
aName) {
127 this._presets.some(
function(
p) {
136 hasPresetNamed:
function(
aName) {
137 return this.getPresetByName(
aName) !=
null;
139 registerPresetProvider:
function(aNewProvider) {
140 if(this._providers.indexOf(aNewProvider) == -1 ) {
143 LOG(
"Adding a new equalizer provider");
144 this._providers.push(aNewProvider);
146 this._addPresetsFromProvider(aNewProvider);
147 LOG(
"Nearly done adding the provider, just need to notify observers!");
151 LOG(
"Provider already registered");
154 unregisterPresetProvider:
function(aProvider) {
155 var index = this._providers.indexOf(aProvider);
158 LOG(
"Removed equalizer preset provider");
159 this._providers.splice(index, 1);
161 this._regeneratePresetsList();
164 _regeneratePresetsList:
function() {
165 LOG(
"Regenerating presets array");
167 this._providers.forEach(
function(provider) {
168 this._addPresetsFromProvider(provider);
170 this._addPresetsFromProvider(this._mainProvider);
171 this._presets.sort(
function(a, b) {
172 return a.name.localeCompare(b.name);
177 _addPresetsFromProvider:
function(aProvider) {
178 LOG(
"Adding presets from provider");
179 var providerPresets = aProvider.presets.enumerate(),
181 while(providerPresets.hasMoreElements()) {
182 preset = providerPresets.getNext().QueryInterface(
Ci.ngIEqualizerPreset);
184 if(aProvider instanceof
Ci.ngIMainEqualizerPresetProvider ||
185 (
this._mainProvider &&
186 !
this._mainProvider.QueryInterface(
Ci.ngIEqualizerPresetCollection)
187 .hasPresetNamed(preset.name)))
188 this._presets.push(preset);
190 LOG(
"Presets added");
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const PRESETS_CHANGED_TOPIC
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
_updateTextAndScrollDataForFrame aData
function ngEqualizerPresetProviderManager()
sbDeviceFirmwareAutoCheckForUpdate prototype observe