1 // Copyright (c) 2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
2 // Copyright (c) 2009 by Prathyush Thota <prathyushthota@gmail.com>
3 // Copyright (c) 2009-2011 by Doug Kearns <dougkearns@gmail.com>
4 // Copyright (c) 2009-2011 by Kris Maglione <maglione.k@gmail.com>
6 // This work is licensed for reuse under an MIT license. Details are
7 // given in the LICENSE.txt file included with this file.
10 Components.utils.import("resource://gre/modules/utils.js"); // XXX: PlacesUtils
12 const Config = Module("config", ConfigBase, {
14 appName: "Melodactyl",
19 commandContainer: "mainplayer",
21 Local: function Local(dactyl, modules, window) let ({ config } = modules, { document } = window) {
22 init: function init() {
25 // TODO: mention this to SB devs, they seem keen to provide these
26 // functions to make porting from FF as simple as possible.
27 window.toJavaScriptConsole = function () {
28 toOpenWindowByType("global:console", "chrome://global/content/console.xul");
32 // FIXME: unless I'm seeing double in in the wee small hours gBrowser is
33 // first set from getBrowser which they've deprecated in FF.
34 get browser() window.getBrowser(),
35 get tabbrowser() window.getBrowser(),
38 about: ["About Songbird",
39 function () { window.openDialog("chrome://songbird/content/xul/about.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
40 addons: ["Manage Add-ons",
41 function () { window.SBOpenPreferences("paneAddons"); }],
42 checkupdates: ["Check for updates",
43 function () { window.checkForUpdates(); }],
44 cookies: ["List your cookies",
45 function () { window.toOpenWindowByType("Browser:Cookies", "chrome://browser/content/preferences/cookies.xul", "chrome,dialog=no,resizable"); }],
46 console: ["JavaScript console",
47 function () { window.toJavaScriptConsole(); }],
48 dominspector: ["DOM Inspector",
49 function () { window.inspectDOMDocument(window.content.document); },
50 function () "inspectDOMDocument" in window],
51 downloads: ["Manage Downloads",
52 function () { window.toOpenWindowByType("Download:Manager", "chrome://mozapps/content/downloads/downloads.xul", "chrome,dialog=no,resizable"); }],
53 newsmartplaylist: ["Open the file selector dialog",
54 function () { window.SBNewSmartPlaylist(); }],
55 openfile: ["Open the file selector dialog",
56 function () { window.SBFileOpen(); }],
57 pagesource: ["View page source",
58 function () { window.BrowserViewSourceOfDocument(window.content.document); }],
59 preferences: ["Show Songbird preferences dialog",
60 function () { window.openPreferences(); }],
61 printsetup: ["Setup the page size and orientation before printing",
62 function () { window.PrintUtils.showPageSetup(); }],
63 print: ["Show print dialog",
64 function () { window.PrintUtils.print(); }],
65 saveframe: ["Save frame to disk",
66 function () { window.saveFrameDocument(); }],
67 savepage: ["Save page to disk",
68 function () { window.saveDocument(window.content.document); }],
69 searchengines: ["Manage installed search engines",
70 function () { window.openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
71 selectionsource: ["View selection source",
72 function () { modules.buffer.viewSelectionSource(); }],
73 subscribe: ["Add a new subscription",
74 function () { window.SBSubscribe(); }]
77 // TODO: clean this up
78 focusChange: function (win) {
79 const { modes } = modules;
81 // Switch to -- PLAYER -- mode for Songbird Media Player.
82 if (this.isPlayerWindow)
83 modes.set(modes.PLAYER);
85 if (modes.main == modes.PLAYER)
89 get isPlayerWindow() window.SBGetBrowser().mCurrentTab == window.SBGetBrowser().mediaTab,
92 * Shows or hides the main service pane.
94 * @param {boolean} value Show the service pane if true, hide it if false.
96 showServicePane: function (value) {
97 const key = "splitter.servicepane_splitter.was_collapsed";
98 window.gServicePane.open = value;
99 window.SBDataSetBoolValue(key, window.gServicePane.open);
103 * Opens the display panel with the specified *id*.
105 * @param {string} id The ID of the display pane.
107 openDisplayPane: function (id) {
108 if (id == "servicepane")
109 this.showServicePane(true);
111 let pane = document.getElementById(id);
112 let manager = services.displayPaneManager;
113 let paneinfo = manager.getPaneInfo(pane._lastURL.stringValue);
116 paneinfo = manager.defaultPaneInfo;
118 pane.loadContent(paneinfo);
123 * Closes the display panel with the specified *id*
125 * @param {string} id The ID of the display pane.
127 closeDisplayPane: function (id) {
128 if (id == "servicepane")
129 this.showServicePane(false);
131 document.getElementById(id).hide();
135 /*** optional options, there are checked for existence and a fallback provided ***/
136 features: Set(["bookmarks", "hints", "marks", "history", "quickmarks", "session", "tabs", "player"]),
139 guioptions: "bCmprs",
141 get titlestring() config.name
145 m: ["Menubar", ["main-menubar"]],
146 T: ["Toolbar", ["nav-bar"]],
147 p: ["Player controls", ["player_wrapper"]]
150 overlayChrome: ["chrome://purplerain/content/xul/mainplayer.xul"],
152 styleableChrome: ["chrome://purplerain/content/xul/mainplayer.xul"],
155 BookmarkAdd: "Triggered after a page is bookmarked",
156 ColorScheme: "Triggered after a color scheme has been loaded",
157 DOMLoad: "Triggered when a page's DOM content has fully loaded",
158 DownloadPost: "Triggered when a download has completed",
159 Fullscreen: "Triggered when the browser's fullscreen state changes",
160 LocationChange: "Triggered when changing tabs or when navigation to a new location",
161 PageLoadPre: "Triggered after a page load is initiated",
162 PageLoad: "Triggered when a page gets (re)loaded/opened",
163 ShellCmdPost: "Triggered after executing a shell command with :!cmd",
164 TrackChangePre: "Triggered before a playing track is changed",
165 TrackChange: "Triggered after a playing track has changed",
166 ViewChangePre: "Triggered before a sequencer view is changed",
167 ViewChange: "Triggered after a sequencer view is changed",
168 StreamStart: "Triggered after a stream has started",
169 StreamPause: "Triggered after a stream has paused",
170 StreamEnd: "Triggered after a stream has ended",
171 StreamStop: "Triggered after a stream has stopped",
172 Enter: "Triggered after Songbird starts",
173 LeavePre: "Triggered before exiting Songbird, just before destroying each module",
174 Leave: "Triggered before exiting Songbird"
177 completers: Class.memoize(function () update({
178 displaypane: "displayPane",
179 playlist: "playlist",
180 mediaview: "mediaView",
181 mediasort: "mediaListSort",
183 }, this.__proto__.completers)),
185 removeTab: function (tab) {
186 if (config.tabbrowser.mTabs.length > 1)
187 config.tabbrowser.removeTab(tab);
189 if (buffer.URL != "about:blank" || window.getWebNavigation().sessionHistory.count > 0) {
190 dactyl.open("about:blank", dactyl.NEW_BACKGROUND_TAB);
191 config.tabbrowser.removeTab(tab);
209 viewAddons: ["Add-ons", "A", "chrome://mozapps/content/extensions/extensions.xul"],
210 viewConsole: ["Console", "C", "chrome://global/content/console.xul"],
211 viewDownloads: ["Downloads", "D", "chrome://mozapps/content/downloads/downloads.xul"],
212 viewPreferences: ["Preferences", "P", "about:config"]
215 // FIXME: tab arg and media tab exception?
216 stop: function (tab) {
217 window.SBGetBrowser().mCurrentBrowser.stop();
221 * @property {object} A map of display pane command argument strings to
225 "leftservice" : "servicepane",
226 "bottomcontent": "displaypane_contentpane_bottom",
227 "bottomservice": "displaypane_servicepane_bottom",
228 "rightsidebar" : "displaypane_right_sidebar"
231 commands: function initCommands(dactyl, modules, window) {
232 const { commands, completion, options } = modules;
234 commands.add(["dpcl[ose]"],
235 "Close a display pane",
237 let arg = args.literalArg;
238 dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg));
239 config.closeDisplayPane(Config.displayPanes[arg]);
243 completer: function (context) completion.displayPane(context),
247 // TODO: this should accept a second arg to specify content
248 commands.add(["displayp[ane]", "dp[ane]", "dpope[n]"],
249 "Open a display pane",
251 let arg = args.literalArg;
252 dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg));
253 // TODO: focus when we have better key handling of these extended modes
254 config.openDisplayPane(Config.displayPanes[arg]);
258 completer: function (context) completion.displayPane(context),
262 commands.add(["pref[erences]", "prefs"],
263 "Show " + config.host + " preferences",
265 if (args.bang) { // open Songbird settings GUI dialog
266 dactyl.open("about:config",
267 (options["newtab"] && options.get("newtab").has("all", "prefs"))
268 ? dactyl.NEW_TAB : dactyl.CURRENT_TAB);
271 window.openPreferences();
278 completion: function initCompletion(dactyl, modules, window) {
279 const completion = require("completion");
281 completion.displayPane = function (context) {
282 context.title = ["Display Pane"];
283 context.completions = Config.displayPanes; // FIXME: useful description etc
286 modes: function initModes(dactyl, modules, window) {
287 const { modes } = modules;
290 "<Return>": modes.NORMAL | modes.INSERT,
291 "<Space>": modes.NORMAL | modes.INSERT,
292 "<Up>": modes.NORMAL | modes.INSERT,
293 "<Down>": modes.NORMAL | modes.INSERT
296 modes.addMode("PLAYER", {
300 options: function initOptions(dactyl, modules, window) {
301 const { options } = modules;
303 // TODO: SB doesn't explicitly support an offline mode. Should we? --djk
304 options.add(["online"],
305 "Set the 'work offline' option",
308 setter: function (value) {
309 const ioService = services.io;
310 ioService.offline = !value;
311 prefs.set("browser.offline", ioService.offline);
314 getter: function () !services.io.offline
317 services: function initServices(dactyl, modules, window) {
318 services.add("displayPaneManager", "@songbirdnest.com/Songbird/DisplayPane/Manager;1", Ci.sbIDisplayPaneManager);
319 services.add("mediaPageManager", "@songbirdnest.com/Songbird/MediaPageManager;1", Ci.sbIMediaPageManager);
320 services.add("propertyManager", "@songbirdnest.com/Songbird/Properties/PropertyManager;1", Ci.sbIPropertyManager);
322 services.addClass("mutablePropertyArray", "@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1",
323 Ci.sbIMutablePropertyArray);
327 // vim: set fdm=marker sw=4 sts=4 ts=8 et: