25 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
29 const Cc = Components.classes;
30 const Ci = Components.interfaces;
36 .getService(
Ci.fuelIApplication);
89 function checkWithConstraint(aPossibleConstraint, aFlag) {
91 if (
aMask &
self.ORIGIN_PROPERTY) {
92 let prop = aMediaList.getProperty(SBProperties.columnSpec +
94 cols =
self._getColumnMap(prop,
self.ORIGIN_PROPERTY | aFlag);
95 if (cols && cols.columnMap.length) {
102 if (
aMask &
self.ORIGIN_PREFERENCES) {
104 let
pref =
aPlaylist.getAttribute(
"useColumnSpecPreference");
106 self.ORIGIN_PREFERENCES);
107 if (cols && cols.columnMap.length) {
113 if (
aMask &
self.ORIGIN_MEDIALISTDEFAULT) {
114 let prop = aMediaList.getProperty(SBProperties.defaultColumnSpec +
115 aPossibleConstraint);
116 cols =
self._getColumnMap(prop,
self.ORIGIN_MEDIALISTDEFAULT | aFlag);
117 if (cols && cols.columnMap.length) {
122 if (
aMask &
self.ORIGIN_LIBRARY) {
123 let prop = aMediaList.library
124 .getProperty(SBProperties.columnSpec +
126 cols =
self._getColumnMap(prop,
self.ORIGIN_LIBRARY | aFlag);
127 if (cols && cols.columnMap.length) {
132 if (
aMask &
self.ORIGIN_LIBRARYDEFAULT) {
133 let prop = aMediaList.library
134 .getProperty(SBProperties.defaultColumnSpec +
135 aPossibleConstraint);
136 cols =
self._getColumnMap(prop,
self.ORIGIN_LIBRARYDEFAULT | aFlag);
137 if (cols && cols.columnMap.length) {
145 cols = checkWithConstraint(
"+(" +
aConstraint +
")",
146 self.ORIGIN_ONLY_CONSTRAINT);
147 if (cols && cols.columnMap.length) {
152 cols = checkWithConstraint(
"", 0);
153 if (cols && cols.columnMap.length) {
157 if (
aMask &
self.ORIGIN_ATTRIBUTE) {
159 cols =
self._getColumnMap(
aPlaylist.getAttribute(
"columnSpec"),
160 self.ORIGIN_ATTRIBUTE);
162 if (cols && cols.columnMap.length) {
170 return self._getColumnMap([SBProperties.trackName, 229,
"a",
171 SBProperties.duration, 45,
172 SBProperties.genre, 101,
173 SBProperties.year, 45,
174 SBProperties.rating, 90,
175 SBProperties.comment, 291,
177 self.ORIGIN_DEFAULT);
180 return self._getColumnMap([SBProperties.trackName, 229,
181 SBProperties.duration, 45,
182 SBProperties.artistName, 137,
"a",
183 SBProperties.albumName, 210,
184 SBProperties.genre, 90,
185 SBProperties.rating, 90,
186 SBProperties.trackType, 78,
188 self.ORIGIN_DEFAULT);
194 if (!columns || !columns.columnMap.length) {
195 throw new Error(
"Couldn't get columnMap!");
201 ColumnSpecParser.prototype = {
204 _columnSpecOrigin:
null,
206 ORIGIN_PROPERTY: 1 << 0,
207 ORIGIN_PREFERENCES: 1 << 1,
208 ORIGIN_MEDIALISTDEFAULT: 1 << 2,
209 ORIGIN_LIBRARYDEFAULT: 1 << 3,
210 ORIGIN_LIBRARY: 1 << 4,
211 ORIGIN_ATTRIBUTE: 1 << 5,
212 ORIGIN_DEFAULT: 1 << 6,
216 ORIGIN_ONLY_CONSTRAINT: 1 << 31,
223 return this._columnSpecOrigin;
230 get sortIsAscending() {
231 return this.
_columns.sortIsAscending;
234 _getColumnMap:
function(columnSpec, columnSpecOrigin) {
238 sortIsAscending:
null
243 columns = ColumnSpecParser.parseColumnSpec(columnSpec);
244 this._columnSpecOrigin = columnSpecOrigin;
247 Components.utils.reportError(e);
256 ColumnSpecParser.parseColumnSpec =
function(spec) {
262 var strippedSpec = spec.match(/^\s*(.*?)\s*$/);
263 if (!strippedSpec.length > 0)
264 throw new Error(
"RegEx failed to match string");
267 var tokens = strippedSpec[1].split(/\s+/);
270 var columnIndex = -1;
271 var seenSort =
false;
273 for (var index = 0; index < tokens.length; index++) {
274 var token = tokens[index];
276 throw new Error(
"Zero-length token");
278 if (isNaN(parseInt(token))) {
279 if (token.length == 1 && (token ==
"a" || token ==
"d")) {
281 if (columnIndex < 0) {
282 throw new Error(
"You passed in a bunk string!");
286 var column = columns[columnIndex];
287 column.sort = token ==
"a" ?
"ascending" :
"descending";
289 sortID = column.property;
290 sortIsAscending = token ==
"a";
295 columns[++columnIndex] = {
property: token, sort:
null };
300 if (columnIndex < 0) {
301 throw new Error(
"You passed in a bunk string!");
303 var column = columns[columnIndex];
304 column.width = token;
311 sortIsAscending: sortIsAscending
324 ColumnSpecParser.reduceWidthsProportionally =
function(aColumnsArray,
328 for each (var col
in aColumnsArray) {
329 if (!col.width || col.width < 80)
continue;
330 fullWidth += parseInt(col.width);
332 for each (var col
in aColumnsArray) {
333 if (!col.width || col.width < 80)
continue;
334 var fraction = parseInt(col.width)/fullWidth;
335 var subtract = fraction * aNeededWidth;
338 col.width = Math.floor(parseInt(col.width) - subtract);
__defineGetter__("Application", function(){delete Application;Application=Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);return Application;}) function ColumnSpecParser(aMediaList