diff -r f3521a11d878 -r 918767a9c8d3 Wikipedia/Bookmarks.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wikipedia/Bookmarks.js Tue Mar 09 10:34:58 2010 +0000 @@ -0,0 +1,295 @@ +// //////////////////////////////////////////////////////////////////////////// +// Symbian Foundation Example Code +// +// This software is in the public domain. No copyright is claimed, and you +// may use it for any purpose without license from the Symbian Foundation. +// No warranty for any purpose is expressed or implied by the authors or +// the Symbian Foundation. +// //////////////////////////////////////////////////////////////////////////// + +var MILLIS_IN_A_DAY = 24*60*60*1000; + +function BookmarksViewItem(articleTitle, articleContent, articleBase, pos) { + var d = new Date(); + this.articleTitle = articleTitle; + this.articleContent = articleContent; + this.pos = pos; + this.articleBase = articleBase; + this.timestamp = d.getTime(); +} + + +function BookmarksView (){ + try { + ListView.prototype.init.call(this, null, null); + var caption = new NavigationButton(1, "titlebar.png", "Bookmarks", true); + caption.addEventListener("ActionPerformed", function(){wikiHomeView.show();}); + this.addControl(caption); + this.previousView = null; + this.items = new Array(); + this.startindex = 0; + this.endindex = 0; + this.rendered = false; + this.todayControl = null; + this.loadItems(); + }catch(w) {alert(w);} +} + +BookmarksView.prototype = new ListView(null, null); + +BookmarksView.prototype.items = null; + + +BookmarksView.prototype.addItem = function(articleTitle, articleContent, articleBase){ + try { + this.removeItem(articleTitle); + this.rendered = false; + var item = null; + item = new BookmarksViewItem(articleTitle, null /*articleContent*/, articleBase, this.endindex); + this.items[this.endindex - this.startindex] = item; + this.endindex++; + this.saveItem(item); + }catch(w) { alert(w);} +} + + +BookmarksView.prototype.saveItem = function(item){ + if ( window.widget ) { +// alert("BM: Saving item: pos=" + item.pos +", title=" + item.articleTitle +", ts=" + item.timestamp +// + "titlekey:" + getBookmarksTitleKey(item.pos) + ", timekey: " + getBookmarksTimeKey(item.pos) ); + + widget.setPreferenceForKey(item.articleTitle, getBookmarksTitleKey(item.pos)); + //widget.setPreferenceForKey(item.articleContent, getBookmarksContentKey(item.pos)); + widget.setPreferenceForKey(item.articleBase, getBookmarksBaseKey(item.pos)); + widget.setPreferenceForKey(""+item.timestamp, getBookmarksTimeKey(item.pos)); + this.storeIndex(); + } +} + +BookmarksView.prototype.storeIndex = function () { + widget.setPreferenceForKey("" + this.startindex, "boox-start"); + widget.setPreferenceForKey("" + this.endindex, "boox-end"); +// alert("BM: index stored, start:"+this.startindex + ", end:"+this.endindex); +} + + +BookmarksView.prototype.clear = function(){ + this.items = new Array(); + if (window.widget) { + for (var i = this.startindex; i < this.endindex + 1; i++) { + widget.setPreferenceForKey(null, getBookmarksTitleKey(i)); + widget.setPreferenceForKey(null, getBookmarksContentKey(i)); + widget.setPreferenceForKey(null, getBookmarksBaseKey(i)); + widget.setPreferenceForKey(null, getBookmarksTimeKey(i)); + } + this.startindex = 0; + this.endindex = 0; + this.storeIndex(); + this.rendered = false; + this.render(); + } +} + +BookmarksView.prototype.loadItems = function(){ + uiManager.showNotification(-1, "wait", "Loading..."); + var self = this; + setTimeout(function(){self.doLoadItems();},0); +} + + +BookmarksView.prototype.doLoadItems = function(){ + if ( window.widget ) { + var d = new Date(); + var now = d.getTime(); + this.items = new Array(); + var tmpstart = widget.preferenceForKey("boox-start"); + var tmpend = widget.preferenceForKey("boox-end"); + + this.startindex = (( tmpstart != undefined && tmpstart != null ) ? parseInt(tmpstart) : 0); + this.endindex = (( tmpend != undefined && tmpend != null ) ? parseInt(tmpend) : 0); + +// alert("BM: startindex=" + this.startindex +", endindex=" + this.endindex); + + for (var i = this.startindex; i < this.endindex; i++) { + var pos = i - this.startindex; + var title = widget.preferenceForKey(getBookmarksTitleKey(i)); +// alert("BM: Examining item: i=" + i + ", pos=" + pos +", title=" + title ); + if ( !title || title == null || title == "null") continue; + var item = new BookmarksViewItem(title,null,null,i); + item.articleContent = widget.preferenceForKey(getBookmarksContentKey(i)); + item.articleBase = widget.preferenceForKey(getBookmarksBaseKey(i)); + item.timestamp = parseFloat(widget.preferenceForKey(getBookmarksTimeKey(i))); + item.pos = i; + this.items[pos] = item; +// alert("BM: Loaded item: i=" + i + ", pos=" + pos +", title=" + title +", ts=" + item.timestamp); + } + this.rendered = false; + } + uiManager.hideNotification(); +} + +BookmarksView.prototype.render = function(){ + if ( this.rendered ) return; + var d = new Date(); + var now = d.getTime(); + // clear components + this.removeAllControls(); + var caption = new NavigationButton(1, "titlebar.png", "Bookmarks", true); + caption.addEventListener("ActionPerformed", function(){ + wikiHomeView.show(); + }); + this.addControl(caption); + + // add components for bookmarks items, up to today + + var thecontrol = new ContentPanel(null, "All bookmarks", "", true, true); + thecontrol.setContent(this.renderBookmarksContent(0, now)); + this.addControl(thecontrol); + this.rendered = true; +} + +BookmarksView.prototype.renderBookmarksContent = function (from , to) { + var buf = "