27 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
28 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
29 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
30 Components.utils.import(
"resource://app/jsmodules/sbColumnSpecParser.jsm");
34 const Cc = Components.classes;
35 const Ci = Components.interfaces;
37 var SmartMediaListColumnSpecUpdater = {
39 update:
function(list) {
44 var storageGuid = list.getProperty(SBProperties.storageGUID);
45 var storageList = list.library.getMediaItem(storageGuid);
48 if (list.limitType !=
Ci.sbILocalDatabaseSmartMediaList.LIMIT_TYPE_NONE) {
49 if (list.randomSelection) {
52 sort = SBProperties.ordinal;
55 sort = list.selectPropertyID;
56 sortDirection = list.selectDirection ?
"a" :
"d";
61 if (list.conditionCount == 1) {
62 var condition = list.getConditionAt(0);
63 if (!this._isDummyProperty(condition.propertyID)) {
64 sort = condition.propertyID;
66 sort = SBProperties.artistName;
69 sort = SBProperties.artistName;
76 Cc[
"@songbirdnest.com/Songbird/SmartPlaylistPropertyRegistrar;1"]
77 .getService(
Ci.sbISmartPlaylistPropertyRegistrar);
78 var props = registrar.getPropertiesForContext(
"default");
79 while (props.hasMoreElements()) {
80 var
p = props.getNext();
81 p.QueryInterface(
Ci.sbISmartPlaylistProperty);
82 if (p.propertyID == sort) {
91 if (!registeredProp) {
93 registeredProp.propertyID = sort;
94 registeredProp.defaultColumnWidth = 80;
95 registeredProp.defaultSortDirection = this._getDefaultSortDirection(sort);
100 sortDirection = registeredProp.defaultSortDirection;
102 columnWidth = registeredProp.defaultColumnWidth;
105 var userSpecs = this._getColumnSpec(storageList);
108 var columnMap = this._getColumnSpec(
LibraryUtils.mainLibrary);
110 var currentUserSpec = storageList.getProperty(SBProperties.columnSpec);
111 var currentDefaultSpec = storageList.getProperty(SBProperties.defaultColumnSpec);
115 var userModifiedColumns = currentUserSpec != currentDefaultSpec;
121 property: SBProperties.ordinal,
125 if (!this._getColumn(columnMap, SBProperties.ordinal)) {
126 ColumnSpecParser.reduceWidthsProportionally(columnMap, ordinal.width);
127 columnMap.unshift(ordinal);
129 if (!this._getColumn(userSpecs, SBProperties.ordinal)) {
130 ColumnSpecParser.reduceWidthsProportionally(userSpecs, ordinal.width);
131 userSpecs.unshift(ordinal);
136 var defaultCols = columnMap;
137 var cols = userSpecs;
147 if (!this._getColumn(defaultCols, sort)) {
148 ColumnSpecParser.reduceWidthsProportionally(defaultCols, columnWidth);
149 defaultCols.push(newSort);
152 if (!this._getColumn(cols, sort)) {
153 ColumnSpecParser.reduceWidthsProportionally(cols, columnWidth);
158 function resetObsoleteSorts(aArray) {
159 for (var
i=0;
i<aArray.length;
i++) {
161 if (col.property != sort) {
164 col.sort = sortDirection;
168 resetObsoleteSorts(defaultCols);
169 if (!userModifiedColumns) {
172 resetObsoleteSorts(cols);
176 function makeSpecString(aArray) {
178 for (var
i=0;
i<aArray.length;
i++) {
180 if (spec !=
"") spec +=
" ";
181 spec += col.property;
187 if (col.sort ==
"ascending") {
190 else if (col.sort ==
"descending") {
199 var defaultSpec = makeSpecString(defaultCols);
200 var userSpec = makeSpecString(cols);
203 storageList.setProperty(SBProperties.defaultColumnSpec, defaultSpec);
204 storageList.setProperty(SBProperties.columnSpec, userSpec);
207 _getColumn:
function(aColumnArray, aPropertyID) {
208 for each (var column
in aColumnArray) {
209 if (column.property == aPropertyID)
215 _getColumnSpec:
function(aMediaList) {
216 var parser =
new ColumnSpecParser(aMediaList,
null);
217 return parser.columnMap;
220 _getDefaultSortDirection:
function(prop) {
221 var pm = Components.classes[
"@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
222 .getService(Components.interfaces.sbIPropertyManager);
223 var info = pm.getPropertyInfo(prop);
238 _isDummyProperty:
function(aProperty) {
239 var pm =
Cc[
"@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
240 .getService(Components.interfaces.sbIPropertyManager);
241 var info = pm.getPropertyInfo(aProperty);
242 return (info instanceof
Ci.sbIDummyPropertyInfo);
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i