dndDefaultHandler.js
Go to the documentation of this file.
1 // JScript source code
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26  */
27 
33 if (typeof(Ci) == "undefined")
34  var Ci = Components.interfaces;
35 if (typeof(Cc) == "undefined")
36  var Cc = Components.classes;
37 if (typeof(Cr) == "undefined")
38  var Cr = Components.results;
39 
40 if (typeof(ExternalDropHandler) == "undefined")
41  Components.utils.import("resource://app/jsmodules/DropHelper.jsm");
42 
43 
44 // Module specific global for auto-init/deinit support
45 var dndDefaultHandler_module = {};
46 dndDefaultHandler_module.init_once = 0;
47 dndDefaultHandler_module.deinit_once = 0;
48 
49 dndDefaultHandler_module.onDragOver = function(event) { nsDragAndDrop.dragOver( event, SBDropObserver ) }
50 dndDefaultHandler_module.onDragDrop = function(event) { nsDragAndDrop.drop( event, SBDropObserver ) }
51 dndDefaultHandler_module.onLoad = function(event)
52 {
53  if (dndDefaultHandler_module.init_once++) { dump("WARNING: dndDefaultHandler_module double init!!\n"); return; }
54 
55  document.addEventListener( "dragover", dndDefaultHandler_module.onDragOver, false );
56  document.addEventListener( "dragdrop", dndDefaultHandler_module.onDragDrop, false );
57 }
58 
59 dndDefaultHandler_module.onUnload = function()
60 {
61  if (dndDefaultHandler_module.deinit_once++) { dump("WARNING: dndDefaultHandler_module double deinit!!\n"); return; }
62  document.removeEventListener( "dragover", dndDefaultHandler_module.onDragOver, false );
63  document.removeEventListener( "dragdrop", dndDefaultHandler_module.onDragDrop, false );
64  window.removeEventListener("load", dndDefaultHandler_module.onLoad, false);
65  window.removeEventListener("unload", dndDefaultHandler_module.onUnload, false);
66 }
67 // Auto-init/deinit registration
68 window.addEventListener("load", dndDefaultHandler_module.onLoad, false);
69 window.addEventListener("unload", dndDefaultHandler_module.onUnload, false);
70 
72 {
73  canHandleMultipleItems: true,
74 
75  getSupportedFlavours : function ()
76  {
77  var flavours = new FlavourSet();
78  ExternalDropHandler.addFlavours(flavours);
79  return flavours;
80  },
81 
82  onDragOver: function ( evt, flavour, session ) {},
83  onDrop: function ( evt, dropdata, session )
84  {
85  var dropHandlerListener = {
87  onDropComplete: function(aTargetList,
88  aImportedInLibrary,
89  aDuplicates,
90  aInsertedInMediaList,
91  aOtherDropsHandled) {
92  // show the standard report on the status bar
93  return true;
94  },
95  onFirstMediaItem: function(aTargetList, aFirstMediaItem) {
96  this.observer.playFirstDrop(aFirstMediaItem);
97  },
98  };
99  ExternalDropHandler.drop(window, session, dropHandlerListener);
100  },
101 
102  playFirstDrop: function(firstDrop) {
103  var view = LibraryUtils.createStandardMediaListView(LibraryUtils.mainLibrary);
104 
105  var index = view.getIndexForItem(firstDrop);
106 
107  // If we have a browser, try to show the view
108  if (window.gBrowser) {
109  gBrowser.showIndexInView(view, index);
110  }
111 
112  // Play the item
113  gMM.sequencer.playView(view, index);
114  }
115 };
116 
const Cc
var gMM
Definition: windowUtils.js:62
dndDefaultHandler_module onDragOver
var event
var SBDropObserver
let window
oState session
const Cr
const Ci
Javascript wrappers for common library tasks.
let observer