Changeset 29

Show
Ignore:
Timestamp:
07/09/08 08:12:37 (2 months ago)
Author:
simon
Message:

This is a big disruptive change and I'm only half way through it, unfortunately, so everything is broken now. Unfortunately I've got to stop now. We're moving from using playlist.songs() to playlist.items(). Currently broken: the main window; moving songs about in the playlist edit window; everything that uses playlist.songs(). Exporting needs testing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • chrome/songbee/edit-pl.xul

    r25 r29  
    8585    var initial_order = new Array; 
    8686 
    87     pl.songs(function (s) { 
     87    pl.items(function (i) { 
    8888        var li = document.createElement("listitem"); 
    8989        li.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 
    90         li.setAttribute("label", s.title()); 
    91         li.songId = s.id(); 
     90        li.setAttribute("label", i.title()); 
     91        li.playitem = i; 
     92                li.piType = i.type(); 
     93                li.piData = i.data(); 
     94                li.piSong = i.song()._id; 
    9295        target.appendChild(li); 
    93         initial_order.push(li.songId); 
     96        initial_order.push(i._id); 
    9497    }); 
    9598 
     
    97100var dragging = 0; 
    98101var dragSetup = 0; 
    99  
    100 function jsdump(str) 
    101 { 
    102   Components.classes['@mozilla.org/consoleservice;1'] 
    103             .getService(Components.interfaces.nsIConsoleService) 
    104             .logStringMessage(str); 
    105 } 
    106102 
    107103function beginToDrag (t) { 
     
    123119 
    124120function doTreeDoubleClick() { 
    125     addToPlaylist("", selectedSong()); 
    126 } 
    127  
    128 function addToPlaylist(item, song) { 
     121    addToPlaylist(selectedSong(), "song", ""); 
     122} 
     123 
     124function addToPlaylist(song, type, data) { 
    129125    // Convert to listitem 
    130     if (!item && !song) { return } 
    131     var s = Song.retrieve(song ? song : item.songId);  
    132     if (!s) { return } 
    133     var li = document.createElement("listitem"); 
     126        var li = document.createElement("listitem"); 
    134127    li.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 
    135     li.setAttribute("label", s.title()); 
    136     li.songId = s.id(); 
    137  
     128        li.piType = type; 
     129        li.piData = data; 
     130        if (type == "song") { 
     131                var s = Song.retrieve(song);  
     132                li.setAttribute("label", s.title()); 
     133                if (!s) { alert("Bug: Couldn't get a song we've clicked on") } 
     134                li.piSong = s.id(); 
     135        } else { 
     136                alert("Bug: Need to represent a non-song item in the playlist"); 
     137        } 
    138138    target.appendChild(li); 
    139139} 
     
    151151    var newElem = document.createElement("listitem"); 
    152152    newElem.setAttribute("label", dragging.label); 
    153     newElem.songId = dragging.songId
     153       for (var a in ["piSong", "piData", "piType"]) newElem[a] = dragging[a]
    154154    newElem.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 
    155155    dragSetup = 0; 
     
    182182    if (children.length != initial_order.length) return 1; 
    183183    for (var i =0; i < children.length; i++) { 
    184         if (children[i].songId != initial_order[i]) return 1; 
     184        if (!children[i].playitem) return 1; 
     185                if (children[i].playitem._id != initial_order[i]) return 1; 
    185186    } 
    186187    return 0; 
     
    204205    pl.tidy_up(); 
    205206    for (var i =0; i < target.childNodes.length; i++) { 
    206         var song = target.childNodes[i].songId; 
    207         pl.add_item(song, i+1); 
    208         window.arguments[1].setup(); 
    209     } 
     207        var node = target.childNodes[i] 
     208        pl.add_item(node.piSong, i+1, node.piType, node.piData); 
     209    } 
     210        window.arguments[1].setup(); // Redraw the main (playlist list) window 
    210211} 
    211212 
  • chrome/songbee/export.js

    r1 r29  
    2727    var stylesheet = getXSLT(); 
    2828 
    29     pl.songs(function (s) { 
    30         var frag = transformDOM(s.xmlDOM(), stylesheet, save); 
    31         var head = save.createElement("h1"); head.innerHTML = s.title(); 
     29    pl.items(function (i) { 
     30        var head = save.createElement("h1"); head.innerHTML = i.title(); 
    3231        song_place.appendChild(head); 
    33         song_place.appendChild(frag); 
     32        song_place.appendChild(i.transformToHTML(stylesheet, save)); 
    3433    }); 
    3534    var serializer = new XMLSerializer(); 
  • chrome/songbee/songbee-sql.js

    r24 r29  
    3535        doSQLStatement("INSERT INTO songbee_system (schema_version) VALUES (2.0)"); 
    3636        doSQLStatement("ALTER TABLE play_item ADD COLUMN type"); 
     37        doSQLStatement("UPDATE play_item SET type='song'"); 
    3738        doSQLStatement("ALTER TABLE play_item ADD COLUMN data"); 
    3839        doSQLStatement("ALTER TABLE playlist ADD COLUMN css"); 
     
    131132 
    132133function doSQLStatement(sql, params) { 
    133     var statement = mDBConn.createStatement(sql) 
     134    var statement; 
     135        try     { statement = mDBConn.createStatement(sql); } catch (e) { alert("SQL setup failed: "+sql); } 
    134136    if (params) { 
    135137        for (var i =0; i < params.length; i++)  
     
    159161} 
    160162 
    161 Playlist.prototype.songs = function (callback) { 
    162     return doSQL("SELECT song.id, song_key, title, first_line, xml FROM song, play_item WHERE play_item.playlist = "+this._id+" AND play_item.song = song.id ORDER BY play_item.position ", Song, callback); 
    163 }; 
    164  
    165 Playlist.prototype.tidy_up = function () { 
    166     doSQLStatement("DELETE FROM play_item WHERE playlist= (?1)", [this._id]); 
    167 }; 
    168  
    169 Playlist.prototype.add_item = function(song, position) { 
    170     doSQLStatement("INSERT INTO play_item (playlist, song, position) VALUES ((?1), (?2), (?3))", [this._id, song, position]); 
    171 }; 
    172  
    173163Song.prototype.xmlDOM = function () { 
    174164    var parsed = (new DOMParser()).parseFromString(this.xml(), "text/xml"); 
    175165    return parsed; 
    176166}; 
     167 
     168Playlist.prototype.items = function (callback) { 
     169    return doSQL("SELECT id, playlist, song, position, type, data FROM play_item WHERE play_item.playlist = "+this._id+" ORDER BY position ", PlayItem, function (pi) { pi.specialize(); if (callback) callback(pi); }); 
     170}; 
     171 
     172Playlist.prototype.tidy_up = function () { 
     173    doSQLStatement("DELETE FROM play_item WHERE playlist= (?1)", [this._id]); 
     174}; 
     175 
     176Playlist.prototype.add_item = function(song, position, type, data) { 
     177        if (!type) type = "song"; 
     178        if (!data) data = ""; 
     179        if (type == "song" and !song) { alert("Bug: No song ID given for song item."); return; } 
     180    doSQLStatement("INSERT INTO play_item (playlist, song, position, type, data) VALUES ((?1), (?2), (?3),(?4),(?5))", [this._id, song, position, type, data]); 
     181}; 
     182 
     183PlayItem.prototype.song = function() { 
     184        if (!this.type == "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); } 
     185        var songlist = doSQL("SELECT song.id, song_key, title, first_line, xml FROM song  WHERE id = "+this._song, Song); 
     186        if (songlist.length < 1 )  { alert("Retrieving song not in database: has it been deleted?"); } 
     187        return songlist[0] 
     188} 
     189 
     190/* PlayItem function dispatchers. We are faking specialization here. */ 
     191 
     192var PlayItemDispatchers = { 
     193        transformToHTML: { 
     194                song: function (stylesheet, doc) { return transformDOM(this.song().xmlDOM(), stylesheet, doc) }, 
     195                fallback: function () { return "<p>[Don't know how to transform object of type "+this.type+"]</p>" } 
     196        }, 
     197        title: { 
     198                song: function () { return this.song().title() }, 
     199                fallback: function() { return "[PlayItem "+this._id+"/"+this.type()+"]" } 
     200        } 
     201}; 
     202 
     203PlayItem.prototype.specialize = function () { 
     204        for (var handle in PlayItemDispatchers) { 
     205                this[handle] = PlayItemDispatchers[handle][this.type()] || PlayItemDispatchers[handle]["fallback"]; 
     206        } 
     207}