menuBarXBLTEMP.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 // This is a temporary file to house methods that need to roll into
26 // our new Menubar XBL object that we'll be building for 0.3
27 function doMenu( command, event ) {
28  switch ( command )
29  {
30  case "menuitem_file_new":
31  var enumerator = null;
32  if (event && event.shiftKey) {
33  if (gBrowser &&
34  gBrowser.selectedTab &&
35  gBrowser.selectedTab.mediaListView)
36  {
37  enumerator = gBrowser.selectedTab
38  .mediaListView
39  .selection
40  .selectedMediaItems;
41  }
42  }
43  if(gServicePane.open) {
44  SBNewPlaylist(enumerator, false);
45  }
46  break;
47  case "menuitem_file_smart":
48  SBNewSmartPlaylist();
49  break;
50  case "menuitem_file_remote":
51  SBSubscribe(null, null);
52  break;
53  case "menuitem_file_podcast":
54  SBNewPodcast();
55  break;
56  case "menuitem_file_file":
57  SBFileOpen();
58  break;
59  case "menuitem_file_url":
60  SBUrlOpen();
61  break;
62  case "menuitem_file_playlist":
63  SBPlaylistOpen();
64  break;
65  case "menuitem_file_library":
66  SBLibraryOpen(null, false);
67  break;
68  case "menuitem_file_newtab":
69  gBrowser.loadOneTab("about:blank", null, null, null, false, null);
70  // |setTimeout| here to ensure we set the location bar focus after
71  // gBrowser.loadOneTab brought the new tab to the front
72  window.setTimeout(function _locationbarFocus() {
73  var locationbar = document.getElementById("location_bar");
74  locationbar.value = "";
75  locationbar.focus();
76  }, 0);
77  break;
78  case "menuitem_file_closetab":
79  gBrowser.removeTab(gBrowser.selectedTab);
80  break;
81  case "menuitem_file_scan":
82  SBScanMedia();
83  break;
84  case "aboutName": // This has to be hardcoded this way for the stinky mac.
85  About();
86  break;
87  case "menu_FileQuitItem": // Stinky mac again. See nsMenuBarX::AquifyMenuBar
88  quitApp();
89  break;
90  case "menuitem_control_play":
91  var sbIMediacoreStatus = Components.interfaces.sbIMediacoreStatus;
92  var state = gMM.status.state;
93  if ( state == sbIMediacoreStatus.STATUS_PLAYING ||
94  state == sbIMediacoreStatus.STATUS_BUFFERING) {
95  gMM.playbackControl.pause();
96  }
97  else if(state == sbIMediacoreStatus.STATUS_PAUSED) {
98  gMM.playbackControl.play();
99  // Otherwise dispatch a play event. Someone should catch this
100  // and intelligently initiate playback. If not, just have
101  // the playback service play the default.
102  }
103  else {
104  var event = document.createEvent("Events");
105  event.initEvent("Play", true, true);
106  window.dispatchEvent(event);
107  }
108  break;
109  case "menuitem_control_next":
110  gMM.sequencer.next();
111  break;
112  case "menuitem_control_prev":
113  gMM.sequencer.previous();
114  break;
115  case "menuitem_control_shuf": {
116  let sequencer = gMM.sequencer;
117  let sequencerMode = sequencer.mode;
118  sequencer.mode =
119  (sequencerMode != sequencer.MODE_SHUFFLE) ?
120  sequencer.MODE_SHUFFLE : sequencer.MODE_FORWARD;
121  }
122  break;
123  case "menuitem_control_repa":
124  gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ALL;
125  break;
126  case "menuitem_control_rep1":
127  gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_ONE;
128  break;
129  case "menuitem_control_repx":
130  gMM.sequencer.repeatMode = gMM.sequencer.MODE_REPEAT_NONE;
131  break;
132  case "menuitem_control_stop":
133  gMM.playbackControl.stop();
134  break;
135  case "menu_extensions":
136  SBOpenPreferences("paneAddons");
137  break;
138  case "menu_preferences":
139  SBOpenPreferences();
140  break;
141  case "menu_downloadmgr":
142  SBOpenDownloadManager();
143  break;
144  case "menuitem_tools_clearprivatedata":
145  Sanitizer.showUI();
146  break;
147  // Renamed to match FireFox
148  case "javascriptConsole":
149  javascriptConsole();
150  break;
151  case "checkForUpdates": {
152  var um =
153  Components.classes["@mozilla.org/updates/update-manager;1"].
154  getService(Components.interfaces.nsIUpdateManager);
155  var prompter =
156  Components.classes["@mozilla.org/updates/update-prompt;1"].
157  createInstance(Components.interfaces.nsIUpdatePrompt);
158 
159  // If there's an update ready to be applied, show the "Update Downloaded"
160  // UI instead and let the user know they have to restart the browser for
161  // the changes to be applied.
162  if (um.activeUpdate && um.activeUpdate.state == "pending")
163  prompter.showUpdateDownloaded(um.activeUpdate);
164  else
165  prompter.checkForUpdates();
166  }
167  break;
168  case "services.browse":
169  var addonsURL = Application.prefs.get("songbird.url.addons").value;
170  gBrowser.loadURI(addonsURL);
171  break;
172 
173  default:
174  return false;
175  }
176  return true;
177 }
178 
179 // Menubar handling
180 function onMenu(target) {
181  // See if this is a special case.
182  if (doMenu(target.getAttribute("id"))) {
183  return;
184  }
185 
186  // The value property may contain a pref key that specifies a url to load.
187  if (target.value) {
188  var pref = Application.prefs.get(target.value);
189  if (pref && pref.value) {
190  if (typeof gBrowser != 'undefined') {
191  gBrowser.loadURI(pref.value);
192  } else {
193  SBBrowserOpenURLInNewWindow(pref.value);
194  }
195  }
196  }
197 }
var gMM
Definition: windowUtils.js:62
var Application
Definition: sbAboutDRM.js:37
var pref
Definition: openLocation.js:44
var event
sidebarFactory createInstance
Definition: nsSidebar.js:351
getService(Ci.sbIFaceplateManager)
let window
return null
Definition: FeedWriter.js:1143
function Sanitizer()
Definition: sanitize.js:42
var gServicePane
Definition: mainWinInit.js:39