32 const Cc = Components.classes;
33 const Ci = Components.interfaces;
34 const Cu = Components.utils;
36 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
37 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
38 Cu.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
39 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
40 Cu.import(
"resource://app/jsmodules/sbSmartMediaListColumnSpecUpdater.jsm");
45 className:
"Songbird Device Event Monitor Service",
46 cid: Components.ID(
"{57b32ce8-a373-4d8d-babb-9d23afeeb409}"),
47 contractID:
"@songbirdnest.com/device/event-monitor-service;1",
49 ifList: [
Ci.sbIDeviceEventListener,
50 Ci.nsISupportsWeakReference,
56 category:
'app-startup',
57 entry:
'service-device-event-monitor',
58 value:
'service,@songbirdnest.com/device/event-monitor-service;1'
64 var obsSvc =
Cc[
'@mozilla.org/observer-service;1']
65 .getService(
Ci.nsIObserverService);
68 obsSvc.addObserver(
this,
'profile-after-change',
true);
69 obsSvc.addObserver(
this,
'quit-application',
true);
75 classID: deviceEventMonitorConfig.cid,
76 contractID: deviceEventMonitorConfig.contractID,
82 _init:
function deviceEventMonitor__init() {
83 var deviceManagerSvc =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
84 .getService(
Ci.sbIDeviceManager2);
85 deviceManagerSvc.addEventListener(
this);
91 _shutdown:
function deviceEventMonitor__shutdown() {
92 var deviceManagerSvc =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
93 .getService(
Ci.sbIDeviceManager2);
94 deviceManagerSvc.removeEventListener(
this);
102 _deviceSupportsVideo:
103 function deviceEventMonitor__deviceSupportsVideo(aDevice) {
104 var capabilities = aDevice.capabilities;
105 var sbIDC =
Ci.sbIDeviceCapabilities;
107 if (capabilities.supportsContent(sbIDC.FUNCTION_VIDEO_PLAYBACK,
108 sbIDC.CONTENT_VIDEO)) {
113 Cu.reportError(
"Unable to determine if device supports video:" + err);
124 _checkForVideoPlaylist:
125 function deviceEventMonitor__checkForVideoPlaylist(aDevice) {
128 if (!this._deviceSupportsVideo(aDevice))
134 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
135 .createInstance(
Ci.sbIMutablePropertyArray);
136 listProperties.appendProperty(SBProperties.isList,
"1");
137 listProperties.appendProperty(SBProperties.hidden,
"0");
138 listProperties.appendProperty(SBProperties.customType,
141 var playlistFound =
false;
142 var searchListener = {
143 onEnumerationBegin:
function(aMediaList) {
144 return Ci.sbIMediaListEnumerationListener.CONTINUE;
146 onEnumeratedItem:
function(aMediaList, aMediaItem) {
148 playlistFound =
true;
149 return Ci.sbIMediaListEnumerationListener.CANCEL;
151 onEnumerationEnd:
function(aMediaList, aStatusCode) {
155 mainLibrary.enumerateItemsByProperties(listProperties,
157 Ci.sbIMediaList.ENUMERATIONTYPE_SNAPSHOT);
159 if (!playlistFound) {
160 var propertyManager =
161 Cc[
"@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
162 .getService(
Ci.sbIPropertyManager);
163 var typePI = propertyManager.getPropertyInfo(SBProperties.contentType);
164 const sbILDSML = Components.interfaces.sbILocalDatabaseSmartMediaList;
166 var videoSmartPlaylist = [
168 name:
"&device.sync.video-togo.playlist",
171 property : SBProperties.contentType,
172 operator : typePI.getOperator(typePI.OPERATOR_EQUALS),
178 matchType : sbILDSML.MATCH_TYPE_ALL,
179 limitType : sbILDSML.LIMIT_TYPE_NONE,
181 selectDirection :
false,
182 randomSelection :
true,
187 var list = mainLibrary.createMediaList(
"smart");
188 for each (var item
in videoSmartPlaylist) {
189 for (var prop in item) {
190 if (prop ==
"conditions") {
191 for each (var condition
in item.conditions) {
192 list.appendCondition(condition.property,
195 condition.rightValue,
196 condition.displayUnit);
199 list[prop] = item[prop];
204 list.setProperty(SBProperties.hidden,
"0");
205 SmartMediaListColumnSpecUpdater.update(list);
211 onDeviceEvent:
function deviceEventMonitor_onDeviceEvent(aDeviceEvent) {
212 switch(aDeviceEvent.type) {
213 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
214 var device = aDeviceEvent.data.QueryInterface(
Ci.sbIDevice);
216 this._checkForVideoPlaylist(device);
223 var obsSvc =
Cc[
'@mozilla.org/observer-service;1']
224 .getService(
Ci.nsIObserverService);
227 case 'quit-application':
228 obsSvc.removeObserver(
this,
'quit-application');
231 case 'profile-after-change':
232 obsSvc.removeObserver(
this,
'profile-after-change');
239 QueryInterface: XPCOMUtils.generateQI(deviceEventMonitorConfig.ifList)
sbLibraryImporterManagerCfg categoryList
function deviceEventMonitor()
sbOSDControlService prototype className
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
var deviceEventMonitorConfig
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const VIDEO_TOGO_PLAYLIST_NAME
sbDeviceFirmwareAutoCheckForUpdate prototype classID
Javascript wrappers for common library tasks.
sbWindowsAutoPlayServiceCfg _xpcom_categories
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype observe