25 const Cc = Components.classes;
26 const Ci = Components.interfaces;
27 const Cu = Components.utils;
28 const Cr = Components.results;
31 const SB_HOTKEY_SERVICE_DESC =
"Songbird Global Hotkey Service";
52 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
53 Cu.import(
"resource://app/jsmodules/SBDataRemoteUtils.jsm");
54 Cu.import(
"resource://app/jsmodules/SBTimer.jsm");
64 .getService(
Ci.sbIGlobalHotkeys);
80 .getService(
Ci.sbIHotkeyActions);
96 .getService(
Ci.nsICommandLineHandler)
97 .QueryInterface(
Ci.sbICommandLineManager);
109 delete ObserverService;
110 ObserverService = Cc[
"@mozilla.org/observer-service;1"]
111 .getService(
Ci.nsIObserverService);
112 return ObserverService;
123 _dataRemoteHotkeysChanged:
null,
124 _dataRemoteHotkeysEnabled:
null,
125 _dataRemoteObserver:
null,
127 _metaKeyString:
null,
128 _hotkeyHandler:
null,
151 getHotkeys:
function() {
153 var hotkeyConfigList = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
154 .createInstance(
Ci.nsIMutableArray);
157 .createInstance(
Ci.sbIHotkeyConfiguration);
159 var keyBase =
"globalhotkey." +
i +
".";
164 if (!this._configListContainsKey(hotkeyConfigList, hotkeyConfig.key))
165 hotkeyConfigList.appendElement(hotkeyConfig,
false);
168 return hotkeyConfigList;
171 getHotkey:
function(aKey) {
172 var hotkeyConfigList = this.getHotkeys();
173 for (var
i = 0;
i < hotkeyConfigList.length;
i++) {
175 hotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
176 if (hotkeyConfig.key == aKey)
183 setHotkeys:
function(aHotkeyConfigList) {
185 for (var
i = 0;
i < aHotkeyConfigList.length;
i++) {
187 aHotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
189 var keyBase =
"globalhotkey." +
i +
".";
195 this._loadHotkeysFromPrefs();
198 addHotkey:
function(aHotkeyConfig) {
199 var hotkeyConfigList = this.getHotkeys();
200 this._removeHotkeyFromConfigList(hotkeyConfigList, aHotkeyConfig.key);
201 hotkeyConfigList.appendElement(aHotkeyConfig,
false);
202 this.setHotkeys(hotkeyConfigList);
205 removeHotkeyByKey:
function(aKey) {
206 var hotkeyConfigList = this.getHotkeys();
207 this._removeHotkeyFromConfigList(hotkeyConfigList, aKey);
208 this.setHotkeys(hotkeyConfigList);
211 removeHotkeysByAction:
function(aAction) {
212 var hotkeyConfigList = this.getHotkeys();
213 for (var
i = hotkeyConfigList.length - 1;
i >= 0;
i--) {
215 hotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
216 if (hotkeyConfig.action == aAction)
217 hotkeyConfigList.removeElementAt(
i);
219 this.setHotkeys(hotkeyConfigList);
222 get hotkeysEnabled() {
226 set hotkeysEnabled(aEnabled) {
228 this._loadHotkeysFromPrefs();
231 get hotkeysEnabledDRKey() {
232 return "globalhotkeys.enabled";
244 this._initPlatform();
245 this._initMetaKeyString();
246 this._initHotkeyHandler();
248 this._loadDefaultHotkeys();
250 this._loadHotkeysFromPrefs();
253 Cu.reportError(
"Global Hotkey Actions Service is not available.");
259 .createInstance(
Ci.sbIHotkeyActionBundle);
266 var serviceManager = Cc[
"@songbirdnest.com/Songbird/ServiceManager;1"]
267 .getService(
Ci.sbIServiceManager);
271 _shutdown:
function() {
273 var serviceManager = Cc[
"@songbirdnest.com/Songbird/ServiceManager;1"]
274 .getService(
Ci.sbIServiceManager);
278 CommandLine.removeFlagHandler(this._hotkeyHandler,
"hotkey");
281 this._hotkeyHandler =
null;
284 HotkeyManager.removeAllHotkeys();
288 _initPlatform:
function() {
291 Components.classes[
"@mozilla.org/system-info;1"]
292 .getService(Components.interfaces.nsIPropertyBag2);
293 this._platform = sysInfo.getProperty(
"name");
298 var user_agent = navigator.userAgent;
299 if (user_agent.indexOf(
"Windows") != -1)
300 this._platform =
"Windows_NT";
301 else if (user_agent.indexOf(
"Mac OS X") != -1)
302 this._platform =
"Darwin";
303 else if (user_agent.indexOf(
"Linux") != -1)
304 this._platform =
"Linux";
305 else if (user_agent.indexOf(
"SunOS") != -1)
306 this._platform =
"SunOS";
310 _initMetaKeyString:
function() {
311 switch(this._platform) {
312 case "Windows_NT": this._metaKeyString =
"win";
break;
313 case "Darwin": this._metaKeyString =
"command";
break;
314 case "Linux": this._metaKeyString =
"meta";
break;
315 default: this._metaKeyString =
"meta";
319 _initHotkeyHandler:
function() {
321 Cu.reportError(
"Command Line Handler is not available.");
325 if (!this._hotkeyHandler) {
329 this._hotkeyHandler = {
330 onHotkey:
function (aHotkeyId) {
331 aHotkeyId = aHotkeyId.toLowerCase();
336 for (var j=0;j<bundle.actionCount;j++)
338 var
id = bundle.enumActionID(j);
339 if (
id.toLowerCase() == aHotkeyId) {
347 handleFlag:
function(aFlag, aParam)
349 var ids = aParam.split(
",");
350 for (var
i = 0;
i < ids.length;
i++) {
351 this.onHotkey(ids[
i]);
358 Ci.sbICommandLineFlagHandler,
359 Ci.nsISupportsWeakReference])
363 CommandLine.addFlagHandler(this._hotkeyHandler,
"hotkey");
369 _loadHotkeysFromPrefs:
function() {
370 this._removeHotkeyBindings();
381 let root =
"globalhotkey." +
i +
".";
386 let keys = keycombo.split(
"-");
395 for (var j = 0; j < keys.length; j++) {
396 keys[j] = keys[j].toLowerCase();
398 case "alt": alt =
true;
break;
399 case "shift": shift =
true;
break;
400 case "ctrl": ctrl =
true;
break;
401 case "meta": meta =
true;
break;
402 default: keyCode = this._stringToKeyCode(keys[j]);
408 HotkeyManager.addHotkey(keyCode,
414 this._hotkeyHandler);
423 _loadDefaultHotkeys:
function() {
434 var metaKey = this._metaKeyString;
435 var hotkeyConfigList =
439 keyReadable:
"nexttrack",
440 action:
"playback.nexttrack" },
443 keyReadable:
"prevtrack",
444 action:
"playback.previoustrack" },
447 keyReadable:
"playpause",
448 action:
"playback.playpause" },
452 keyReadable: metaKey +
" - .",
453 action:
"playback.volumeup" },
456 keyReadable: metaKey +
" - ,",
457 action:
"playback.volumedown" },
460 keyReadable: metaKey +
" - ]",
461 action:
"playback.nexttrack" },
464 keyReadable: metaKey +
" - [",
465 action:
"playback.previoustrack" },
468 keyReadable: metaKey +
" - \\",
469 action:
"playback.playpause" },
473 action:
"playback.stop" }
477 var hotkeyConfigArray = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
478 .createInstance(
Ci.nsIMutableArray);
479 for (var
i = 0;
i < hotkeyConfigList.length;
i++) {
481 .createInstance(
Ci.sbIHotkeyConfiguration);
482 hotkeyConfiguration.key = hotkeyConfigList[
i].key;
483 hotkeyConfiguration.keyReadable = hotkeyConfigList[
i].keyReadable;
484 hotkeyConfiguration.action = hotkeyConfigList[
i].action;
485 hotkeyConfigArray.appendElement(hotkeyConfiguration,
false);
489 this.setHotkeys(hotkeyConfigArray);
495 _removeHotkeyBindings:
function() {
497 HotkeyManager.removeAllHotkeys();
501 _stringToKeyCode:
function(aStr) {
502 if (aStr.slice(0, 1) ==
'$') {
503 return aStr.slice(1);
509 _configListContainsKey:
function(aHotkeyConfigList, aKey) {
510 for (var
i = 0;
i < aHotkeyConfigList.length;
i++) {
512 aHotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
513 if (hotkeyConfig.key == aKey)
520 _removeHotkeyFromConfigList:
function(aHotkeyConfigList, aKey) {
521 for (var
i = aHotkeyConfigList.length - 1;
i >= 0;
i--) {
523 aHotkeyConfigList.queryElementAt(
i,
Ci.sbIHotkeyConfiguration);
524 if (hotkeyConfig.key == aKey)
525 aHotkeyConfigList.removeElementAt(
i);
535 category:
"app-startup",
536 entry: SB_HOTKEY_SERVICE_DESC,
541 Ci.sbIHotkeyService])
556 _packagename:
"playback",
558 _actions: [
"volumeup",
570 _stringbundle:
"chrome://songbird/locale/songbird.properties",
575 _localpackagename:
null,
577 _songbirdStrings:
null,
585 return this._actions.length;
588 enumActionLocaleDescription:
function (aIndex) {
589 return this._getLocalizedPackageName() +
591 this._getLocalizedActionName(this._actions[aIndex]);
594 enumActionID:
function(aIndex) {
595 return this._packagename +
"." + this._actions[aIndex];
601 onAction:
function(aIndex) {
603 case 0: this._hotkey_volumeUp();
break;
604 case 1: this._hotkey_volumeDown();
break;
605 case 2: this._hotkey_nextTrack();
break;
606 case 3: this._hotkey_previousTrack();
break;
607 case 4: this._hotkey_playPause();
break;
608 case 5: this._hotkey_pause();
break;
609 case 6: this._hotkey_stop();
break;
614 return Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
615 .getService(
Ci.sbIMediacoreManager);
618 _hotkey_volumeUp:
function() {
619 var volume = this._mm.volumeControl.volume + 0.03;
620 if (volume > 1) volume = 1;
621 this._mm.volumeControl.volume = volume;
624 _hotkey_volumeDown:
function() {
625 var volume = this._mm.volumeControl.volume - 0.03;
626 if (volume < 0) volume = 0;
627 this._mm.volumeControl.volume = volume;
630 _hotkey_nextTrack:
function() {
631 this._mm.sequencer.next();
634 _hotkey_previousTrack:
function() {
635 this._mm.sequencer.previous();
638 _hotkey_playPause:
function() {
641 if (this._mm.status.state ==
Ci.sbIMediacoreStatus.STATUS_PLAYING ||
642 this._mm.status.state ==
Ci.sbIMediacoreStatus.STATUS_BUFFERING) {
643 this._mm.playbackControl.pause();
645 else if(this._mm.status.state ==
Ci.sbIMediacoreStatus.STATUS_PAUSED) {
646 this._mm.playbackControl.play();
652 var app = Cc[
"@songbirdnest.com/Songbird/ApplicationController;1"]
653 .getService(
Ci.sbIApplicationController);
661 _hotkey_pause:
function() {
662 this._mm.playbackControl.pause();
665 _hotkey_stop:
function() {
666 this._mm.playbackControl.stop();
669 _getLocalizedString:
function(
str, defaultstr) {
672 this._sbs = Cc[
"@mozilla.org/intl/stringbundle;1"]
673 .getService(
Ci.nsIStringBundleService);
674 this._songbirdStrings = this._sbs.createBundle(this._stringbundle);
677 r = this._songbirdStrings.GetStringFromName(
str);
688 _getLocalizedPackageName:
function() {
689 if (!this._localpackage)
690 this._localpackage = this._getLocalizedString(
"hotkeys.actions." +
693 return this._localpackage;
703 _getLocalizedActionName:
function(action) {
704 return this._getLocalizedString(
"hotkeys.actions." +
716 Ci.nsISupportsWeakReference,
735 Ci.sbIHotkeyConfiguration])
const SB_HOTKEY_CONFIGURATION_DESC
sbOSDControlService prototype className
const SB_HOTKEYACTIONS_CONTRACTID
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
const SB_HOTKEY_CONFIGURATION_CONTRACTID
function SBDataGetIntValue(aKey)
Get the value of the data in integer format.
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const SB_DEFGLOBALHKACTIONS_CLASSNAME
function SBDataGetStringValue(aKey)
Get the value of the data in string format.
const SB_DEFGLOBALHKACTIONS_CID
function SBDataDeleteBranch(aKey)
Called to remove the data remote specified by aKey and all its children.
function SBDataGetBoolValue(aKey)
Get the value of the data in boolean format.
function sbHotkeyConfiguration()
function SBDataSetIntValue(aKey, aIntValue)
Set an integer value. Changes the value of the data remote to the integer passed in, regardless of its value before.
function SBDataSetBoolValue(aKey, aBoolValue)
Set a boolean value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
function sbDefaultGlobalHotkeyActions()
const SB_COMMANDLINE_CONTRACTID
const SB_HOTKEY_SERVICE_CID
const SB_HOTKEY_SERVICE_CLASSNAME
const SB_DEFGLOBALHKACTIONS_CONTRACTID
__defineGetter__("HotkeyManager", function(){delete HotkeyManager;if(SB_HOTKEYMANAGER_CONTRACTID in Cc){HotkeyManager=Cc[SB_HOTKEYMANAGER_CONTRACTID].getService(Ci.sbIGlobalHotkeys);}else{HotkeyManager=null;}return HotkeyManager;})
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
function sbHotkeyService()
function SBDataSetStringValue(aKey, aStringValue)
Set a string value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
const SB_HOTKEYMANAGER_CONTRACTID
const SB_HOTKEY_CONFIGURATION_CID
const SB_DEFGLOBALHKACTIONS_DESC
_getSelectedPageStyle s i
const SB_HOTKEY_SERVICE_CONTRACTID
const SB_HOTKEY_CONFIGURATION_CLASSNAME
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe