mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 08:07:59 +01:00
Port Xulmus/Muttator. Not tested yet.
This commit is contained in:
@@ -3,17 +3,13 @@
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
function Addressbook() { //{{{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
const abManager = Cc["@mozilla.org/abmanager;1"].getService(Ci.nsIAbManager);
|
||||
const rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
||||
const Addressbook = Module("addressbook", {
|
||||
init: function () {
|
||||
},
|
||||
|
||||
// TODO: add option for a format specifier, like:
|
||||
// :set displayname=%l, %f
|
||||
function generateDisplayName(firstName, lastName) {
|
||||
generateDisplayName: function (firstName, lastName) {
|
||||
if (firstName && lastName)
|
||||
return lastName + ", " + firstName;
|
||||
else if (firstName)
|
||||
@@ -22,88 +18,13 @@ function Addressbook() { //{{{
|
||||
return lastName;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
function getDirectoryFromURI(uri) services.get("rdf").GetResource(uri).QueryInterface(Ci.nsIAbDirectory)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var myModes = config.mailModes;
|
||||
|
||||
mappings.add(myModes, ["a"],
|
||||
"Open a prompt to save a new addressbook entry for the sender of the selected message",
|
||||
function () {
|
||||
try {
|
||||
var to = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor;
|
||||
}
|
||||
catch (e) {
|
||||
liberator.beep();
|
||||
}
|
||||
|
||||
if (!to)
|
||||
return;
|
||||
|
||||
let address = to.substring(to.indexOf("<") + 1, to.indexOf(">"));
|
||||
|
||||
let displayName = to.substr(0, to.indexOf("<") - 1);
|
||||
if (/^\S+\s+\S+\s*$/.test(displayName)) {
|
||||
let names = displayName.split(/\s+/);
|
||||
displayName = "-firstname=" + names[0].replace(/"/g, "")
|
||||
+ " -lastname=" + names[1].replace(/"/g, "");
|
||||
}
|
||||
else
|
||||
displayName = "-name=\"" + displayName.replace(/"/g, "") + "\"";
|
||||
|
||||
commandline.open(":", "contact " + address + " " + displayName, modes.EX);
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
commands.add(["con[tact]"],
|
||||
"Add an address book entry",
|
||||
function (args) {
|
||||
let mailAddr = args[0]; // TODO: support more than one email address
|
||||
let firstName = args["-firstname"] || null;
|
||||
let lastName = args["-lastname"] || null;
|
||||
let displayName = args["-name"] || null;
|
||||
if (!displayName)
|
||||
displayName = generateDisplayName(firstName, lastName);
|
||||
|
||||
if (addressbook.add(mailAddr, firstName, lastName, displayName))
|
||||
liberator.echomsg("Added address: " + displayName + " <" + mailAddr + ">", 1, commandline.FORCE_SINGLELINE);
|
||||
else
|
||||
liberator.echoerr("Exxx: Could not add contact `" + mailAddr + "'", commandline.FORCE_SINGLELINE);
|
||||
|
||||
},
|
||||
{
|
||||
argCount: "+",
|
||||
options: [[["-firstname", "-f"], commands.OPTION_STRING],
|
||||
[["-lastname", "-l"], commands.OPTION_STRING],
|
||||
[["-name", "-n"], commands.OPTION_STRING]]
|
||||
});
|
||||
|
||||
commands.add(["contacts", "addr[essbook]"],
|
||||
"List or open multiple addresses",
|
||||
function (args) { addressbook.list(args.string, args.bang); },
|
||||
{ bang: true });
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
getDirectoryFromURI: function (uri) services.get("rdf").GetResource(uri).QueryInterface(Ci.nsIAbDirectory),
|
||||
|
||||
add: function (address, firstName, lastName, displayName) {
|
||||
const personalAddressbookURI = "moz-abmdbdirectory://abook.mab";
|
||||
let directory = getDirectoryFromURI(personalAddressbookURI);
|
||||
let directory = this.getDirectoryFromURI(personalAddressbookURI);
|
||||
let card = Cc["@mozilla.org/addressbook/cardproperty;1"].createInstance(Ci.nsIAbCard);
|
||||
|
||||
if (!address || !directory || !card)
|
||||
@@ -131,7 +52,7 @@ function Addressbook() { //{{{
|
||||
//var mail = card.primaryEmail || ""; //XXX
|
||||
let displayName = card.displayName;
|
||||
if (!displayName)
|
||||
displayName = generateDisplayName(card.firstName, card.lastName);
|
||||
displayName = this.generateDisplayName(card.firstName, card.lastName);
|
||||
|
||||
if (displayName.toLowerCase().indexOf(lowerFilter) > -1
|
||||
|| card.primaryEmail.toLowerCase().indexOf(lowerFilter) > -1)
|
||||
@@ -164,8 +85,67 @@ function Addressbook() { //{{{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}, {
|
||||
}, {
|
||||
commands: function () {
|
||||
commands.add(["con[tact]"],
|
||||
"Add an address book entry",
|
||||
function (args) {
|
||||
let mailAddr = args[0]; // TODO: support more than one email address
|
||||
let firstName = args["-firstname"] || null;
|
||||
let lastName = args["-lastname"] || null;
|
||||
let displayName = args["-name"] || null;
|
||||
if (!displayName)
|
||||
displayName = this.generateDisplayName(firstName, lastName);
|
||||
|
||||
if (addressbook.add(mailAddr, firstName, lastName, displayName))
|
||||
liberator.echomsg("Added address: " + displayName + " <" + mailAddr + ">", 1, commandline.FORCE_SINGLELINE);
|
||||
else
|
||||
liberator.echoerr("Exxx: Could not add contact `" + mailAddr + "'", commandline.FORCE_SINGLELINE);
|
||||
|
||||
},
|
||||
{
|
||||
argCount: "+",
|
||||
options: [[["-firstname", "-f"], commands.OPTION_STRING],
|
||||
[["-lastname", "-l"], commands.OPTION_STRING],
|
||||
[["-name", "-n"], commands.OPTION_STRING]]
|
||||
});
|
||||
|
||||
commands.add(["contacts", "addr[essbook]"],
|
||||
"List or open multiple addresses",
|
||||
function (args) { addressbook.list(args.string, args.bang); },
|
||||
{ bang: true });
|
||||
},
|
||||
mappings: function () {
|
||||
var myModes = config.mailModes;
|
||||
|
||||
mappings.add(myModes, ["a"],
|
||||
"Open a prompt to save a new addressbook entry for the sender of the selected message",
|
||||
function () {
|
||||
try {
|
||||
var to = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor;
|
||||
}
|
||||
catch (e) {
|
||||
liberator.beep();
|
||||
}
|
||||
|
||||
if (!to)
|
||||
return;
|
||||
|
||||
let address = to.substring(to.indexOf("<") + 1, to.indexOf(">"));
|
||||
|
||||
let displayName = to.substr(0, to.indexOf("<") - 1);
|
||||
if (/^\S+\s+\S+\s*$/.test(displayName)) {
|
||||
let names = displayName.split(/\s+/);
|
||||
displayName = "-firstname=" + names[0].replace(/"/g, "")
|
||||
+ " -lastname=" + names[1].replace(/"/g, "");
|
||||
}
|
||||
else
|
||||
displayName = "-name=\"" + displayName.replace(/"/g, "") + "\"";
|
||||
|
||||
commandline.open(":", "contact " + address + " " + displayName, modes.EX);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -3,24 +3,12 @@
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
const config = (function () { //{{{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var name = "Muttator";
|
||||
var host = "Thunderbird";
|
||||
var tabmail;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
const config = { //{{{
|
||||
/*** required options, no checks done if they really exist, so be careful ***/
|
||||
name: name,
|
||||
hostApplication: host, // TODO: can this be found out otherwise? gBrandBundle.getString("brandShortName");
|
||||
name: "Muttator",
|
||||
hostApplication: "Thunderbird", // TODO: can this be found out otherwise? gBrandBundle.getString("brandShortName");
|
||||
// Yes, but it will be localized unlike all other strings. So, it's best left until we i18n liberator. --djk
|
||||
|
||||
get mainWindowId() this.isComposeWindow ? "msgcomposeWindow" : "messengerWindow",
|
||||
|
||||
/*** optional options, there are checked for existence and a fallback provided ***/
|
||||
@@ -28,7 +16,7 @@ const config = (function () { //{{{
|
||||
defaults: {
|
||||
guioptions: "frb",
|
||||
showtabline: 1,
|
||||
titlestring: name
|
||||
titlestring: "Muttator"
|
||||
},
|
||||
|
||||
guioptions: {
|
||||
@@ -48,15 +36,14 @@ const config = (function () { //{{{
|
||||
"chrome://messenger/content/messengercompose/messengercompose.xul"],
|
||||
|
||||
autocommands: [["DOMLoad", "Triggered when a page's DOM content has fully loaded"],
|
||||
["FolderLoad", "Triggered after switching folders in " + host],
|
||||
["FolderLoad", "Triggered after switching folders in Thunderbird"],
|
||||
["PageLoadPre", "Triggered after a page load is initiated"],
|
||||
["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
||||
[name + "Enter", "Triggered after " + host + " starts"],
|
||||
[name + "Leave", "Triggered before exiting " + host],
|
||||
[name + "LeavePre", "Triggered before exiting " + host]],
|
||||
|
||||
["MuttatorEnter", "Triggered after Thunderbird starts"],
|
||||
["MuttatorLeave", "Triggered before exiting Thunderbird"],
|
||||
["MuttatorLeavePre", "Triggered before exiting Thunderbird"]],
|
||||
dialogs: [
|
||||
["about", "About " + host,
|
||||
["about", "About Thunderbird",
|
||||
function () { window.openAboutDialog(); }],
|
||||
["addons", "Manage Add-ons",
|
||||
function () { window.openAddonsMgr(); }],
|
||||
@@ -82,7 +69,7 @@ const config = (function () { //{{{
|
||||
function () { BrowserPageInfo(); }],
|
||||
["pagesource", "View page source",
|
||||
function () { BrowserViewSourceOfDocument(content.document); }],*/
|
||||
["preferences", "Show " + host + " preferences dialog",
|
||||
["preferences", "Show Thunderbird preferences dialog",
|
||||
function () { openOptionsDialog(); }],
|
||||
/*["printpreview", "Preview the page before printing",
|
||||
function () { PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview); }],*/
|
||||
@@ -111,14 +98,13 @@ const config = (function () { //{{{
|
||||
},
|
||||
|
||||
getBrowser: function () {
|
||||
if (!tabmail) {
|
||||
tabmail = { __proto__: document.getElementById("tabmail") };
|
||||
var tabmail = { __proto__: document.getElementById("tabmail") };
|
||||
tabmail.__defineGetter__("mTabContainer", function () this.tabContainer);
|
||||
tabmail.__defineGetter__("mTabs", function () this.tabContainer.childNodes);
|
||||
tabmail.__defineGetter__("mCurrentTab", function () this.tabContainer.selectedItem);
|
||||
tabmail.__defineGetter__("mStrip", function () this.tabStrip);
|
||||
tabmail.__defineGetter__("browsers", function () [browser for (browser in Iterator(this.mTabs))]);
|
||||
}
|
||||
config.getBrowser = function () tabmail;
|
||||
return tabmail;
|
||||
},
|
||||
|
||||
@@ -157,11 +143,9 @@ const config = (function () { //{{{
|
||||
return document.getElementById("appcontent").boxObject.height;
|
||||
},
|
||||
|
||||
scripts: [
|
||||
get scripts() this.isComposeWindow() ? ["compose/compose.js"] : [
|
||||
"addressbook.js",
|
||||
"compose/compose.js",
|
||||
"mail.js",
|
||||
"tabs.js"
|
||||
],
|
||||
|
||||
// to allow Vim to :set ft=mail automatically
|
||||
@@ -171,18 +155,6 @@ const config = (function () { //{{{
|
||||
// don't wait too long when selecting new messages
|
||||
// GetThreadTree()._selectDelay = 300; // TODO: make configurable
|
||||
|
||||
// load Muttator specific modules
|
||||
if (this.isComposeWindow)
|
||||
// TODO: this should probably be "composer"
|
||||
liberator.loadModule("compose", Compose);
|
||||
else {
|
||||
liberator.loadModule("mail", Mail);
|
||||
liberator.loadModule("addressbook", Addressbook);
|
||||
liberator.loadModule("tabs", Tabs);
|
||||
liberator.loadModule("marks", Marks);
|
||||
liberator.loadModule("hints", Hints);
|
||||
}
|
||||
|
||||
commands.add(["pref[erences]", "prefs"],
|
||||
"Show " + config.hostApplication + " preferences",
|
||||
function () { window.openOptionsDialog(); },
|
||||
@@ -211,6 +183,5 @@ const config = (function () { //{{{
|
||||
//}}}
|
||||
}
|
||||
}; //}}}
|
||||
})(); //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -221,18 +221,6 @@ const config = { //{{{
|
||||
context.completions = displayPanes; // FIXME: useful description etc
|
||||
};
|
||||
|
||||
// load Xulmus specific modules
|
||||
liberator.loadModule("browser", Browser);
|
||||
liberator.loadModule("finder", Finder);
|
||||
liberator.loadModule("bookmarks", Bookmarks);
|
||||
liberator.loadModule("history", History);
|
||||
liberator.loadModule("tabs", Tabs);
|
||||
liberator.loadModule("marks", Marks);
|
||||
liberator.loadModule("quickmarks", QuickMarks);
|
||||
liberator.loadModule("hints", Hints);
|
||||
liberator.loadModule("player", Player);
|
||||
liberator.loadModule("library", Library);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// STYLES //////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
@@ -251,10 +239,6 @@ const config = { //{{{
|
||||
delete img;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
@@ -4,36 +4,20 @@
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
|
||||
function Library() { //{{{
|
||||
const Library = Module("library", {
|
||||
init: function () {
|
||||
this.MAIN_LIBRARY = LibraryUtils.mainLibrary;
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
const MAIN_LIBRARY = LibraryUtils.mainLibrary;
|
||||
|
||||
function toJSArray(enum) ArrayConverter.JSArray(enum)
|
||||
|
||||
function getArtistsArray() {
|
||||
return toJSArray(MAIN_LIBRARY.getDistinctValuesForProperty(SBProperties.artistName));
|
||||
}
|
||||
|
||||
// Get the artist names before hand.
|
||||
let artists = getArtistsArray();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
_toJSArray: function (enum) ArrayConverter.JSArray(enum),
|
||||
|
||||
// TODO: return some actually useful objects. ;-)
|
||||
return {
|
||||
|
||||
/**
|
||||
* Returns an array of all the artist names in the main library.
|
||||
*
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getArtists: function getArtists() artists,
|
||||
getArtists: function getArtists() this._toJSArray(this.MAIN_LIBRARY.getDistinctValuesForProperty(SBProperties.artistName)),
|
||||
|
||||
// FIXME: ken do we really want to remove duplicates? If so, why not tracks too? --djk
|
||||
/**
|
||||
@@ -44,7 +28,7 @@ function Library() { //{{{
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getAlbums: function getAlbums(artist) {
|
||||
let albums = toJSArray(MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
|
||||
let albums = this._toJSArray(this.MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
|
||||
.map(function (track) track.getProperty(SBProperties.albumName));
|
||||
return util.Array.uniq(albums);
|
||||
},
|
||||
@@ -64,12 +48,11 @@ function Library() { //{{{
|
||||
properties.appendProperty(SBProperties.artistName, artist);
|
||||
properties.appendProperty(SBProperties.albumName, album);
|
||||
|
||||
return toJSArray(MAIN_LIBRARY.getItemsByProperties(properties))
|
||||
return this._toJSArray(this.MAIN_LIBRARY.getItemsByProperties(properties))
|
||||
.map(function (track) track.getProperty(SBProperties.trackName));
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
}, {
|
||||
}, {
|
||||
});
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -4,38 +4,32 @@
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
|
||||
function Player() { //{{{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
let lastSearchString = "";
|
||||
let lastSearchIndex = 0;
|
||||
let lastSearchView = _SBGetCurrentView();
|
||||
const Player = Module("player", {
|
||||
init: function () {
|
||||
this._lastSearchString = "";
|
||||
this._lastSearchIndex = 0;
|
||||
this._lastSearchView = _SBGetCurrentView();
|
||||
|
||||
// Get the focus to the visible playlist first
|
||||
//window._SBShowMainLibrary();
|
||||
|
||||
services.add("mediaPageManager", "@songbirdnest.com/Songbird/MediaPageManager;1", Ci.sbIMediaPageManager);
|
||||
services.add("propertyManager","@songbirdnest.com/Songbird/Properties/PropertyManager;1", Ci.sbIPropertyManager);
|
||||
|
||||
// Register Callbacks for searching.
|
||||
commandline.registerCallback("change", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchKeyPress(str); });
|
||||
commandline.registerCallback("submit", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchSubmit(str); });
|
||||
commandline.registerCallback("cancel", modes.SEARCH_VIEW_FORWARD, function () { player.onSearchCancel(); });
|
||||
gMM.addListener(this._mediaCoreListener);
|
||||
},
|
||||
destroy: function () {
|
||||
gMM.removeListener(this._mediaCoreListener);
|
||||
},
|
||||
|
||||
// interval (milliseconds)
|
||||
function seek(interval, direction) {
|
||||
_seek: function (interval, direction) {
|
||||
let position = gMM.playbackControl ? gMM.playbackControl.position : 0;
|
||||
player.seekTo(position + (direction ? interval : -interval));
|
||||
}
|
||||
},
|
||||
|
||||
function focusTrack(mediaItem) {
|
||||
_focusTrack: function (mediaItem) {
|
||||
SBGetBrowser().mediaTab.mediaPage.highlightItem(_SBGetCurrentView().getIndexForItem(mediaItem));
|
||||
}
|
||||
},
|
||||
|
||||
var mediaCoreListener = {
|
||||
_mediaCoreListener: {
|
||||
onMediacoreEvent: function (event) {
|
||||
switch (event.type) {
|
||||
case Ci.sbIMediacoreEvent.BEFORE_TRACK_CHANGE:
|
||||
@@ -71,136 +65,313 @@ function Player() { //{{{
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
// TODO: check bounds and round, 0 - 1 or 0 - 100?
|
||||
/**
|
||||
* @property {string} The player volume as a percentage.
|
||||
*/
|
||||
get volume() gMM.volumeControl.volume,
|
||||
set volume(value) {
|
||||
gMM.volumeControl.volume = value;
|
||||
},
|
||||
|
||||
gMM.addListener(mediaCoreListener);
|
||||
liberator.registerObserver("shutdown", function () {
|
||||
gMM.removeListener(mediaCoreListener);
|
||||
});
|
||||
// FIXME: can't be called from non-media tabs since 840e78
|
||||
play: function play() {
|
||||
// Check if there is any selection in place, else play first item of the visible view.
|
||||
if (_SBGetCurrentView().selection.count != 0) {
|
||||
// Play the selection.
|
||||
gMM.sequencer.playView(_SBGetCurrentView(), _SBGetCurrentView().getIndexForItem(_SBGetCurrentView().selection.currentMediaItem));
|
||||
this._focusTrack(gMM.sequencer.currentItem);
|
||||
}
|
||||
else {
|
||||
gMM.sequencer.playView(SBGetBrowser().currentMediaListView, 0);
|
||||
this._focusTrack(gMM.sequencer.currentItem);
|
||||
}
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
stop: function stop() {
|
||||
gMM.sequencer.stop();
|
||||
},
|
||||
|
||||
options.add(["repeat"],
|
||||
"Set the playback repeat mode",
|
||||
"number", 0,
|
||||
{
|
||||
setter: function (value) gMM.sequencer.repeatMode = value,
|
||||
getter: function () gMM.sequencer.repeatMode,
|
||||
completer: function (context) [
|
||||
["0", "Repeat none"],
|
||||
["1", "Repeat one"],
|
||||
["2", "Repeat all"]
|
||||
],
|
||||
validator: Option.validateCompleter
|
||||
});
|
||||
next: function next() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_next");
|
||||
gSongbirdWindowController.doCommand("cmd_find_current_track");
|
||||
},
|
||||
|
||||
options.add(["shuffle"],
|
||||
"Play tracks in shuffled order",
|
||||
"boolean", false,
|
||||
{
|
||||
setter: function (value) value ? gMM.sequencer.mode = gMM.sequencer.MODE_SHUFFLE :
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_FORWARD,
|
||||
getter: function () gMM.sequencer.mode == gMM.sequencer.MODE_SHUFFLE
|
||||
});
|
||||
previous: function previous() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_previous");
|
||||
gSongbirdWindowController.doCommand("cmd_find_current_track");
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
togglePlayPause: function togglePlayPause() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_playpause");
|
||||
this._focusTrack(gMM.sequencer.currentItem);
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["x"], "Play track",
|
||||
function () { player.play(); });
|
||||
toggleShuffle: function toggleShuffle() {
|
||||
if (gMM.sequencer.mode != gMM.sequencer.MODE_SHUFFLE)
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_SHUFFLE;
|
||||
else
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_FORWARD;
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["z"], "Previous track",
|
||||
function () { player.previous(); });
|
||||
// FIXME: not really toggling - good enough for now.
|
||||
toggleRepeat: function toggleRepeat() {
|
||||
switch (gMM.sequencer.repeatMode) {
|
||||
case gMM.sequencer.MODE_REPEAT_NONE:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ONE;
|
||||
break;
|
||||
case gMM.sequencer.MODE_REPEAT_ONE:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ALL;
|
||||
break;
|
||||
case gMM.sequencer.MODE_REPEAT_ALL:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_NONE;
|
||||
break;
|
||||
default:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_NONE;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["c"], "Pause/unpause track",
|
||||
function () { player.togglePlayPause(); });
|
||||
/**
|
||||
* Seek forward <b>interval</b> milliseconds in the currently playing
|
||||
* track.
|
||||
*
|
||||
* @param {number} interval The time interval (ms) to advance the
|
||||
* current track.
|
||||
*/
|
||||
seekForward: function seekForward(interval) {
|
||||
this._seek(interval, true);
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["b"], "Next track",
|
||||
function () { player.next(); });
|
||||
/**
|
||||
* Seek backwards <b>interval</b> milliseconds in the currently
|
||||
* playing track.
|
||||
*
|
||||
* @param {number} interval The time interval (ms) to rewind the
|
||||
* current track.
|
||||
*/
|
||||
seekBackward: function seekBackward(interval) {
|
||||
this._seek(interval, false);
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["v"], "Stop track",
|
||||
function () { player.stop(); });
|
||||
/**
|
||||
* Seek to a specific position in the currently playing track.
|
||||
*
|
||||
* @param {number} The new position (ms) in the track.
|
||||
*/
|
||||
seekTo: function seekTo(position) {
|
||||
// FIXME: if not playing
|
||||
if (!gMM.playbackControl)
|
||||
this.play();
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["Q"], "Queue tracks by artist/album/track",
|
||||
function () { commandline.open(":", "queue ", modes.EX); });
|
||||
let min = 0;
|
||||
let max = gMM.playbackControl.duration - 5000; // TODO: 5s buffer like cmus desirable?
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["f"], "Loads current view filtered by the keywords",
|
||||
function () { commandline.open(":", "filter ", modes.EX); });
|
||||
gMM.playbackControl.position = util.Math.constrain(position, min, max);
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["i"], "Select current track",
|
||||
function () { gSongbirdWindowController.doCommand("cmd_find_current_track"); });
|
||||
// FIXME: 10% ?
|
||||
// I think just general increments of say 0.05 might be better --djk
|
||||
increaseVolume: function increaseVolume() {
|
||||
gMM.volumeControl.volume = gMM.volumeControl.volume * 1.1;
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["s"], "Toggle shuffle",
|
||||
function () { player.toggleShuffle(); });
|
||||
decreaseVolume: function decreaseVolume() {
|
||||
if (gMM.volumeControl.volume == 0)
|
||||
gMM.volumeControl.volume = 0.1;
|
||||
else
|
||||
gMM.volumeControl.volume = gMM.volumeControl.volume * 0.9;
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["r"], "Toggle repeat",
|
||||
function () { player.toggleRepeat(); });
|
||||
focusPlayingTrack :function focusPlayingTrack() {
|
||||
this._focusTrack(gMM.sequencer.currentItem);
|
||||
},
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["h", "<Left>"], "Seek -10s",
|
||||
function (count) { player.seekBackward(Math.max(1, count) * 10000); },
|
||||
{ count: true });
|
||||
listTracks: function listTracks(view) {
|
||||
//let myView = LibraryUtils.createStandardMediaListView(LibraryUtils.mainLibrary, args);
|
||||
let length = view.length;
|
||||
let tracksList = [];
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["l", "<Right>"], "Seek +10s",
|
||||
function (count) { player.seekForward(Math.max(1, count) * 10000); },
|
||||
{ count: true });
|
||||
for (let i = 0; i < length; i++) {
|
||||
let mediaItem = view.getItemByIndex(i);
|
||||
let trackName = mediaItem.getProperty(SBProperties.trackName);
|
||||
let albumName = mediaItem.getProperty(SBProperties.albumName);
|
||||
let artistName = mediaItem.getProperty(SBProperties.artistName);
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["H", "<S-Left>"], "Seek -1m",
|
||||
function (count) { player.seekBackward(Math.max(1, count) * 60000); },
|
||||
{ count: true });
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["L", "<S-Right>"], "Seek +1m",
|
||||
function (count) { player.seekForward(Math.max(1, count) * 60000); },
|
||||
{ count: true });
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["=", "+"], "Increase volume by 10%",
|
||||
function () { player.increaseVolume(); });
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["-"], "Decrease volume by 10%",
|
||||
function () { player.decreaseVolume(); });
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["/"], "Search forward for a track",
|
||||
function (args) { commandline.open("/", "", modes.SEARCH_VIEW_FORWARD); });
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["n"], "Find the next track",
|
||||
function () { player.searchViewAgain(false);});
|
||||
|
||||
mappings.add([modes.PLAYER],
|
||||
["N"], "Find the previous track",
|
||||
function () { player.searchViewAgain(true);});
|
||||
|
||||
for (let i in util.range(0, 6)) {
|
||||
let (rating = i) {
|
||||
mappings.add([modes.PLAYER],
|
||||
["<C-" + rating + ">"], "Rate the current media item " + rating,
|
||||
function () { player.rateMediaItem(rating); });
|
||||
};
|
||||
tracksList[i] = [trackName, "Album : " + albumName + " Artist : " + artistName];
|
||||
}
|
||||
|
||||
////////////////// ///////////////////////////////////////////////////////////}}}
|
||||
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
return tracksList;
|
||||
},
|
||||
|
||||
searchView: function searchView(args) {
|
||||
let currentView = _SBGetCurrentView();
|
||||
let mediaItemList = currentView.mediaList;
|
||||
let search = _getSearchString(currentView);
|
||||
let searchString = "";
|
||||
|
||||
if (search != "")
|
||||
searchString = args + " " + search;
|
||||
else
|
||||
searchString = args;
|
||||
|
||||
this._lastSearchString = searchString;
|
||||
|
||||
let mySearchView = LibraryUtils.createStandardMediaListView(mediaItemList, searchString);
|
||||
|
||||
if (mySearchView.length) {
|
||||
this._lastSearchView = mySearchView;
|
||||
this._lastSearchIndex = 0;
|
||||
this._focusTrack(mySearchView.getItemByIndex(this._lastSearchIndex));
|
||||
}
|
||||
else
|
||||
liberator.echoerr("E486 Pattern not found: " + searchString, commandline.FORCE_SINGLELINE);
|
||||
},
|
||||
|
||||
searchViewAgain: function searchViewAgain(reverse) {
|
||||
function echo(str) {
|
||||
setTimeout(function () {
|
||||
commandline.echo(str, commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES | commandline.FORCE_SINGLELINE);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
if (this._lastSearchIndex == 0) {
|
||||
this._lastSearchIndex = this._lastSearchView.length - 1;
|
||||
echo("Search hit TOP, continuing at BOTTOM");
|
||||
}
|
||||
else
|
||||
this._lastSearchIndex = this._lastSearchIndex - 1;
|
||||
}
|
||||
else {
|
||||
if (this._lastSearchIndex == (this._lastSearchView.length - 1)) {
|
||||
this._lastSearchIndex = 0;
|
||||
echo("Search hit BOTTOM, continuing at TOP");
|
||||
}
|
||||
else
|
||||
this._lastSearchIndex = this._lastSearchIndex + 1;
|
||||
}
|
||||
|
||||
// FIXME: Implement for "?" --ken
|
||||
commandline.echo("/" + this._lastSearchString, null, commandline.FORCE_SINGLELINE);
|
||||
this._focusTrack(this._lastSearchView.getItemByIndex(this._lastSearchIndex));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog keypress callback.
|
||||
*
|
||||
* @param {string} str The contents of the search dialog.
|
||||
*/
|
||||
onSearchKeyPress: function (str) {
|
||||
if (options["incsearch"])
|
||||
this.searchView(str);
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog submit callback.
|
||||
*
|
||||
* @param {string} str The contents of the search dialog.
|
||||
*/
|
||||
onSearchSubmit: function (str) {
|
||||
this.searchView(str);
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog cancel callback.
|
||||
*/
|
||||
onSearchCancel: function () {
|
||||
// TODO: restore the view state if altered by an 'incsearch' search
|
||||
},
|
||||
|
||||
getPlaylists: function getPlaylists() {
|
||||
let mainLibrary = LibraryUtils.mainLibrary;
|
||||
let playlists = [mainLibrary];
|
||||
let listener = {
|
||||
onEnumerationBegin: function () { },
|
||||
onEnumerationEnd: function () { },
|
||||
onEnumeratedItem: function (list, item) {
|
||||
// FIXME: why are there null items and duplicates?
|
||||
if (!playlists.some(function (list) list.name == item.name) && item.name != null)
|
||||
playlists.push(item);
|
||||
return Ci.sbIMediaListEnumerationListener.CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
mainLibrary.enumerateItemsByProperty("http://songbirdnest.com/data/1.0#isList", "1", listener);
|
||||
|
||||
return playlists;
|
||||
},
|
||||
|
||||
// Play track at 'row' in 'playlist'
|
||||
playPlaylist: function playPlaylist(playlist, row) {
|
||||
gMM.sequencer.playView(playlist.createView(), row);
|
||||
},
|
||||
|
||||
getMediaPages: function getMediaPages() {
|
||||
let list = gBrowser.currentMediaPage.mediaListView.mediaList;
|
||||
let pages = services.get("mediaPageManager").getAvailablePages(list);
|
||||
return ArrayConverter.JSArray(pages).map(function (page) page.QueryInterface(Ci.sbIMediaPageInfo));
|
||||
},
|
||||
|
||||
loadMediaPage: function loadMediaList(page, list, view) {
|
||||
services.get("mediaPageManager").setPage(list, page);
|
||||
gBrowser.loadMediaList(list, null, null, view, null);
|
||||
},
|
||||
|
||||
rateMediaItem: function rateMediaItem(rating) {
|
||||
if (gMM.sequencer.currentItem)
|
||||
gMM.sequencer.currentItem.setProperty(SBProperties.rating, rating);
|
||||
},
|
||||
|
||||
getUserViewable: function getUserViewable() {
|
||||
let propManager = services.get("propertyManager");
|
||||
let propEnumerator = propManager.propertyIDs;
|
||||
let properties = [];
|
||||
|
||||
while (propEnumerator.hasMore()) {
|
||||
let propertyId = propEnumerator.getNext();
|
||||
|
||||
if (propManager.getPropertyInfo(propertyId).userViewable) {
|
||||
//liberator.dump("propertyId - " + propManager.getPropertyInfo(propertyId).id);
|
||||
properties.push(propManager.getPropertyInfo(propertyId).displayName);
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
},
|
||||
|
||||
sortBy: function sortBy(property, order) {
|
||||
let pa = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"].createInstance(Ci.sbIMutablePropertyArray);
|
||||
liberator.dump("Property: " + property);
|
||||
|
||||
switch (property.string) {
|
||||
case "#":
|
||||
case "Title":
|
||||
pa.appendProperty(SBProperties.trackName, "a");
|
||||
break;
|
||||
case "Rating":
|
||||
pa.appendProperty(SBProperties.rating, 1);
|
||||
break;
|
||||
case "Album":
|
||||
pa.appendProperty(SBProperties.albumName, "a");
|
||||
break;
|
||||
default:
|
||||
pa.appendProperty(SBProperties.trackName, "a");
|
||||
break;
|
||||
}
|
||||
|
||||
_SBGetCurrentView().setSort(pa);
|
||||
}
|
||||
}, {
|
||||
}, {
|
||||
commandline: function () {
|
||||
commandline.registerCallback("change", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchKeyPress(str); });
|
||||
commandline.registerCallback("submit", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchSubmit(str); });
|
||||
commandline.registerCallback("cancel", modes.SEARCH_VIEW_FORWARD, function () { player.onSearchCancel(); });
|
||||
},
|
||||
commands: function () {
|
||||
commands.add(["f[ilter]"],
|
||||
"Filter tracks based on keywords {genre/artist/album/track}",
|
||||
function (args) {
|
||||
@@ -212,8 +383,8 @@ function Player() { //{{{
|
||||
else {
|
||||
SBGetBrowser().loadMediaList(LibraryUtils.mainLibrary, null, null, view,
|
||||
"chrome://songbird/content/mediapages/filtersPage.xul");
|
||||
// TODO: make this focusTrack work ?
|
||||
focusTrack(view.getItemByIndex(0));
|
||||
// TODO: make this this._focusTrack work ?
|
||||
this._focusTrack(view.getItemByIndex(0));
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -234,7 +405,7 @@ function Player() { //{{{
|
||||
for ([i, list] in Iterator(playlists)) {
|
||||
if (util.compareIgnoreCase(arg, list.name) == 0) {
|
||||
SBGetBrowser().loadMediaList(playlists[i]);
|
||||
focusTrack(_SBGetCurrentView().getItemByIndex(0));
|
||||
this._focusTrack(_SBGetCurrentView().getItemByIndex(0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -388,11 +559,8 @@ function Player() { //{{{
|
||||
player.volume = util.Math.constrain(level, 0, 1);
|
||||
},
|
||||
{ argCount: "1" });
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// COMPLETIONS /////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
},
|
||||
completions: function () {
|
||||
completion.song = function song(context, args) {
|
||||
// TODO: useful descriptions?
|
||||
function map(list) list.map(function (i) [i, ""]);
|
||||
@@ -424,314 +592,124 @@ function Player() { //{{{
|
||||
context.keys = { text: "contentTitle", description: "contentUrl" };
|
||||
context.completions = player.getMediaPages();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
return {
|
||||
|
||||
// TODO: check bounds and round, 0 - 1 or 0 - 100?
|
||||
/**
|
||||
* @property {string} The player volume as a percentage.
|
||||
*/
|
||||
get volume() gMM.volumeControl.volume,
|
||||
set volume(value) {
|
||||
gMM.volumeControl.volume = value;
|
||||
},
|
||||
mappings: function () {
|
||||
mappings.add([modes.PLAYER],
|
||||
["x"], "Play track",
|
||||
function () { player.play(); });
|
||||
|
||||
// FIXME: can't be called from non-media tabs since 840e78
|
||||
play: function play() {
|
||||
// Check if there is any selection in place, else play first item of the visible view.
|
||||
if (_SBGetCurrentView().selection.count != 0) {
|
||||
// Play the selection.
|
||||
gMM.sequencer.playView(_SBGetCurrentView(), _SBGetCurrentView().getIndexForItem(_SBGetCurrentView().selection.currentMediaItem));
|
||||
focusTrack(gMM.sequencer.currentItem);
|
||||
}
|
||||
else {
|
||||
gMM.sequencer.playView(SBGetBrowser().currentMediaListView, 0);
|
||||
focusTrack(gMM.sequencer.currentItem);
|
||||
}
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["z"], "Previous track",
|
||||
function () { player.previous(); });
|
||||
|
||||
stop: function stop() {
|
||||
gMM.sequencer.stop();
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["c"], "Pause/unpause track",
|
||||
function () { player.togglePlayPause(); });
|
||||
|
||||
next: function next() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_next");
|
||||
gSongbirdWindowController.doCommand("cmd_find_current_track");
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["b"], "Next track",
|
||||
function () { player.next(); });
|
||||
|
||||
previous: function previous() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_previous");
|
||||
gSongbirdWindowController.doCommand("cmd_find_current_track");
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["v"], "Stop track",
|
||||
function () { player.stop(); });
|
||||
|
||||
togglePlayPause: function togglePlayPause() {
|
||||
gSongbirdWindowController.doCommand("cmd_control_playpause");
|
||||
focusTrack(gMM.sequencer.currentItem);
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["Q"], "Queue tracks by artist/album/track",
|
||||
function () { commandline.open(":", "queue ", modes.EX); });
|
||||
|
||||
toggleShuffle: function toggleShuffle() {
|
||||
if (gMM.sequencer.mode != gMM.sequencer.MODE_SHUFFLE)
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_SHUFFLE;
|
||||
else
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_FORWARD;
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["f"], "Loads current view filtered by the keywords",
|
||||
function () { commandline.open(":", "filter ", modes.EX); });
|
||||
|
||||
// FIXME: not really toggling - good enough for now.
|
||||
toggleRepeat: function toggleRepeat() {
|
||||
switch (gMM.sequencer.repeatMode) {
|
||||
case gMM.sequencer.MODE_REPEAT_NONE:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ONE;
|
||||
break;
|
||||
case gMM.sequencer.MODE_REPEAT_ONE:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ALL;
|
||||
break;
|
||||
case gMM.sequencer.MODE_REPEAT_ALL:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_NONE;
|
||||
break;
|
||||
default:
|
||||
gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_NONE;
|
||||
break;
|
||||
}
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["i"], "Select current track",
|
||||
function () { gSongbirdWindowController.doCommand("cmd_find_current_track"); });
|
||||
|
||||
/**
|
||||
* Seek forward <b>interval</b> milliseconds in the currently playing
|
||||
* track.
|
||||
*
|
||||
* @param {number} interval The time interval (ms) to advance the
|
||||
* current track.
|
||||
*/
|
||||
seekForward: function seekForward(interval) {
|
||||
seek(interval, true);
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["s"], "Toggle shuffle",
|
||||
function () { player.toggleShuffle(); });
|
||||
|
||||
/**
|
||||
* Seek backwards <b>interval</b> milliseconds in the currently
|
||||
* playing track.
|
||||
*
|
||||
* @param {number} interval The time interval (ms) to rewind the
|
||||
* current track.
|
||||
*/
|
||||
seekBackward: function seekBackward(interval) {
|
||||
seek(interval, false);
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["r"], "Toggle repeat",
|
||||
function () { player.toggleRepeat(); });
|
||||
|
||||
/**
|
||||
* Seek to a specific position in the currently playing track.
|
||||
*
|
||||
* @param {number} The new position (ms) in the track.
|
||||
*/
|
||||
seekTo: function seekTo(position) {
|
||||
// FIXME: if not playing
|
||||
if (!gMM.playbackControl)
|
||||
this.play();
|
||||
mappings.add([modes.PLAYER],
|
||||
["h", "<Left>"], "Seek -10s",
|
||||
function (count) { player.seekBackward(Math.max(1, count) * 10000); },
|
||||
{ count: true });
|
||||
|
||||
let min = 0;
|
||||
let max = gMM.playbackControl.duration - 5000; // TODO: 5s buffer like cmus desirable?
|
||||
mappings.add([modes.PLAYER],
|
||||
["l", "<Right>"], "Seek +10s",
|
||||
function (count) { player.seekForward(Math.max(1, count) * 10000); },
|
||||
{ count: true });
|
||||
|
||||
gMM.playbackControl.position = util.Math.constrain(position, min, max);
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["H", "<S-Left>"], "Seek -1m",
|
||||
function (count) { player.seekBackward(Math.max(1, count) * 60000); },
|
||||
{ count: true });
|
||||
|
||||
// FIXME: 10% ?
|
||||
// I think just general increments of say 0.05 might be better --djk
|
||||
increaseVolume: function increaseVolume() {
|
||||
gMM.volumeControl.volume = gMM.volumeControl.volume * 1.1;
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["L", "<S-Right>"], "Seek +1m",
|
||||
function (count) { player.seekForward(Math.max(1, count) * 60000); },
|
||||
{ count: true });
|
||||
|
||||
decreaseVolume: function decreaseVolume() {
|
||||
if (gMM.volumeControl.volume == 0)
|
||||
gMM.volumeControl.volume = 0.1;
|
||||
else
|
||||
gMM.volumeControl.volume = gMM.volumeControl.volume * 0.9;
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["=", "+"], "Increase volume by 10%",
|
||||
function () { player.increaseVolume(); });
|
||||
|
||||
focusPlayingTrack :function focusPlayingTrack() {
|
||||
focusTrack(gMM.sequencer.currentItem);
|
||||
},
|
||||
mappings.add([modes.PLAYER],
|
||||
["-"], "Decrease volume by 10%",
|
||||
function () { player.decreaseVolume(); });
|
||||
|
||||
listTracks: function listTracks(view) {
|
||||
//let myView = LibraryUtils.createStandardMediaListView(LibraryUtils.mainLibrary, args);
|
||||
let length = view.length;
|
||||
let tracksList = [];
|
||||
mappings.add([modes.PLAYER],
|
||||
["/"], "Search forward for a track",
|
||||
function (args) { commandline.open("/", "", modes.SEARCH_VIEW_FORWARD); });
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
let mediaItem = view.getItemByIndex(i);
|
||||
let trackName = mediaItem.getProperty(SBProperties.trackName);
|
||||
let albumName = mediaItem.getProperty(SBProperties.albumName);
|
||||
let artistName = mediaItem.getProperty(SBProperties.artistName);
|
||||
mappings.add([modes.PLAYER],
|
||||
["n"], "Find the next track",
|
||||
function () { player.searchViewAgain(false);});
|
||||
|
||||
tracksList[i] = [trackName, "Album : " + albumName + " Artist : " + artistName];
|
||||
}
|
||||
mappings.add([modes.PLAYER],
|
||||
["N"], "Find the previous track",
|
||||
function () { player.searchViewAgain(true);});
|
||||
|
||||
return tracksList;
|
||||
},
|
||||
|
||||
searchView: function searchView(args) {
|
||||
let currentView = _SBGetCurrentView();
|
||||
let mediaItemList = currentView.mediaList;
|
||||
let search = _getSearchString(currentView);
|
||||
let searchString = "";
|
||||
|
||||
if (search != "")
|
||||
searchString = args + " " + search;
|
||||
else
|
||||
searchString = args;
|
||||
|
||||
lastSearchString = searchString;
|
||||
|
||||
let mySearchView = LibraryUtils.createStandardMediaListView(mediaItemList, searchString);
|
||||
|
||||
if (mySearchView.length) {
|
||||
lastSearchView = mySearchView;
|
||||
lastSearchIndex = 0;
|
||||
focusTrack(mySearchView.getItemByIndex(lastSearchIndex));
|
||||
}
|
||||
else
|
||||
liberator.echoerr("E486 Pattern not found: " + searchString, commandline.FORCE_SINGLELINE);
|
||||
},
|
||||
|
||||
searchViewAgain: function searchViewAgain(reverse) {
|
||||
function echo(str) {
|
||||
setTimeout(function () {
|
||||
commandline.echo(str, commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES | commandline.FORCE_SINGLELINE);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
if (lastSearchIndex == 0) {
|
||||
lastSearchIndex = lastSearchView.length - 1;
|
||||
echo("Search hit TOP, continuing at BOTTOM");
|
||||
}
|
||||
else
|
||||
lastSearchIndex = lastSearchIndex - 1;
|
||||
}
|
||||
else {
|
||||
if (lastSearchIndex == (lastSearchView.length - 1)) {
|
||||
lastSearchIndex = 0;
|
||||
echo("Search hit BOTTOM, continuing at TOP");
|
||||
}
|
||||
else
|
||||
lastSearchIndex = lastSearchIndex + 1;
|
||||
}
|
||||
|
||||
// FIXME: Implement for "?" --ken
|
||||
commandline.echo("/" + lastSearchString, null, commandline.FORCE_SINGLELINE);
|
||||
focusTrack(lastSearchView.getItemByIndex(lastSearchIndex));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog keypress callback.
|
||||
*
|
||||
* @param {string} str The contents of the search dialog.
|
||||
*/
|
||||
onSearchKeyPress: function (str) {
|
||||
if (options["incsearch"])
|
||||
this.searchView(str);
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog submit callback.
|
||||
*
|
||||
* @param {string} str The contents of the search dialog.
|
||||
*/
|
||||
onSearchSubmit: function (str) {
|
||||
this.searchView(str);
|
||||
},
|
||||
|
||||
/**
|
||||
* The search dialog cancel callback.
|
||||
*/
|
||||
onSearchCancel: function () {
|
||||
// TODO: restore the view state if altered by an 'incsearch' search
|
||||
},
|
||||
|
||||
getPlaylists: function getPlaylists() {
|
||||
let mainLibrary = LibraryUtils.mainLibrary;
|
||||
let playlists = [mainLibrary];
|
||||
let listener = {
|
||||
onEnumerationBegin: function () { },
|
||||
onEnumerationEnd: function () { },
|
||||
onEnumeratedItem: function (list, item) {
|
||||
// FIXME: why are there null items and duplicates?
|
||||
if (!playlists.some(function (list) list.name == item.name) && item.name != null)
|
||||
playlists.push(item);
|
||||
return Ci.sbIMediaListEnumerationListener.CONTINUE;
|
||||
}
|
||||
for (let i in util.range(0, 6)) {
|
||||
let (rating = i) {
|
||||
mappings.add([modes.PLAYER],
|
||||
["<C-" + rating + ">"], "Rate the current media item " + rating,
|
||||
function () { player.rateMediaItem(rating); });
|
||||
};
|
||||
|
||||
mainLibrary.enumerateItemsByProperty("http://songbirdnest.com/data/1.0#isList", "1", listener);
|
||||
|
||||
return playlists;
|
||||
},
|
||||
|
||||
// Play track at 'row' in 'playlist'
|
||||
playPlaylist: function playPlaylist(playlist, row) {
|
||||
gMM.sequencer.playView(playlist.createView(), row);
|
||||
},
|
||||
|
||||
getMediaPages: function getMediaPages() {
|
||||
let list = gBrowser.currentMediaPage.mediaListView.mediaList;
|
||||
let pages = services.get("mediaPageManager").getAvailablePages(list);
|
||||
return ArrayConverter.JSArray(pages).map(function (page) page.QueryInterface(Ci.sbIMediaPageInfo));
|
||||
},
|
||||
|
||||
loadMediaPage: function loadMediaList(page, list, view) {
|
||||
services.get("mediaPageManager").setPage(list, page);
|
||||
gBrowser.loadMediaList(list, null, null, view, null);
|
||||
},
|
||||
|
||||
rateMediaItem: function rateMediaItem(rating) {
|
||||
if (gMM.sequencer.currentItem)
|
||||
gMM.sequencer.currentItem.setProperty(SBProperties.rating, rating);
|
||||
},
|
||||
|
||||
getUserViewable: function getUserViewable() {
|
||||
let propManager = services.get("propertyManager");
|
||||
let propEnumerator = propManager.propertyIDs;
|
||||
let properties = [];
|
||||
|
||||
while (propEnumerator.hasMore()) {
|
||||
let propertyId = propEnumerator.getNext();
|
||||
|
||||
if (propManager.getPropertyInfo(propertyId).userViewable) {
|
||||
//liberator.dump("propertyId - " + propManager.getPropertyInfo(propertyId).id);
|
||||
properties.push(propManager.getPropertyInfo(propertyId).displayName);
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
},
|
||||
options: function () {
|
||||
options.add(["repeat"],
|
||||
"Set the playback repeat mode",
|
||||
"number", 0,
|
||||
{
|
||||
setter: function (value) gMM.sequencer.repeatMode = value,
|
||||
getter: function () gMM.sequencer.repeatMode,
|
||||
completer: function (context) [
|
||||
["0", "Repeat none"],
|
||||
["1", "Repeat one"],
|
||||
["2", "Repeat all"]
|
||||
],
|
||||
validator: Option.validateCompleter
|
||||
});
|
||||
|
||||
sortBy: function sortBy(property, order) {
|
||||
let pa = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"].createInstance(Ci.sbIMutablePropertyArray);
|
||||
liberator.dump("Property: " + property);
|
||||
|
||||
switch (property.string) {
|
||||
case "#":
|
||||
case "Title":
|
||||
pa.appendProperty(SBProperties.trackName, "a");
|
||||
break;
|
||||
case "Rating":
|
||||
pa.appendProperty(SBProperties.rating, 1);
|
||||
break;
|
||||
case "Album":
|
||||
pa.appendProperty(SBProperties.albumName, "a");
|
||||
break;
|
||||
default:
|
||||
pa.appendProperty(SBProperties.trackName, "a");
|
||||
break;
|
||||
}
|
||||
|
||||
_SBGetCurrentView().setSort(pa);
|
||||
}
|
||||
|
||||
};
|
||||
//}}}
|
||||
} //}}}
|
||||
options.add(["shuffle"],
|
||||
"Play tracks in shuffled order",
|
||||
"boolean", false,
|
||||
{
|
||||
setter: function (value) value ? gMM.sequencer.mode = gMM.sequencer.MODE_SHUFFLE :
|
||||
gMM.sequencer.mode = gMM.sequencer.MODE_FORWARD,
|
||||
getter: function () gMM.sequencer.mode == gMM.sequencer.MODE_SHUFFLE
|
||||
});
|
||||
},
|
||||
services: function () {
|
||||
services.add("mediaPageManager", "@songbirdnest.com/Songbird/MediaPageManager;1", Ci.sbIMediaPageManager);
|
||||
services.add("propertyManager","@songbirdnest.com/Songbird/Properties/PropertyManager;1", Ci.sbIPropertyManager);
|
||||
},
|
||||
});
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
Reference in New Issue
Block a user