svnno****@sourc*****
svnno****@sourc*****
2007年 11月 3日 (土) 22:30:11 JST
Revision: 247 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=247 Author: flyson Date: 2007-11-03 22:30:11 +0900 (Sat, 03 Nov 2007) Log Message: ----------- 履歴関連メソッドを nsBbs2chService から b2rGlobalService に移動 Modified Paths: -------------- trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js trunk/bbs2chreader/components/b2rGlobalService.js trunk/bbs2chreader/components/nsBbs2chService.js -------------- next part -------------- Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js 2007-11-03 12:53:58 UTC (rev 246) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js 2007-11-03 13:30:11 UTC (rev 247) @@ -1,6 +1,9 @@ var gBbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"] .getService(Components.interfaces.nsIBbs2chService); +var gB2rService = Components.classes["@bbs2ch.sourceforge.jp/b2r-global-service;1"] + .getService(Components.interfaces.b2rIGlobalService); + var gBbsmenuUpdater var gTreeBbsMenu; var gTreeBbsMenuView; @@ -134,10 +137,10 @@ if(boardMax > 15) boardMax = 15; var sql = "SELECT url, title FROM history WHERE type=0 ORDER BY last_visited DESC LIMIT ?1"; - var statement = gBbs2chService.historyDB.createStatement(sql); + var statement = gB2rService.history.database.createStatement(sql); statement.bindInt32Parameter(0, boardMax); - gBbs2chService.historyDB.beginTransaction(); + gB2rService.history.database.beginTransaction(); try{ while(statement.executeStep()){ var url = "bbs2ch:board:" + statement.getString(0); @@ -150,7 +153,7 @@ } statement.reset(); }finally{ - gBbs2chService.historyDB.commitTransaction(); + gB2rService.history.database.commitTransaction(); } if(popHistory.hasChildNodes()){ @@ -161,10 +164,10 @@ var threadMax = gBbs2chService.pref.getIntPref("extensions.bbs2chreader.bbsmenu_historymenu_thread_max"); if(threadMax > 15) threadMax = 15; sql = sql = "SELECT url, title FROM history WHERE type=1 ORDER BY last_visited DESC LIMIT ?1"; - statement = gBbs2chService.historyDB.createStatement(sql); + statement = gB2rService.history.database.createStatement(sql); statement.bindInt32Parameter(0, threadMax); - gBbs2chService.historyDB.beginTransaction(); + gB2rService.history.database.beginTransaction(); try{ while(statement.executeStep()){ var url = statement.getString(0); @@ -188,7 +191,7 @@ } statement.reset(); }finally{ - gBbs2chService.historyDB.commitTransaction(); + gB2rService.history.database.commitTransaction(); } if(popHistory.hasChildNodes()){ Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js 2007-11-03 12:53:58 UTC (rev 246) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js 2007-11-03 13:30:11 UTC (rev 247) @@ -37,6 +37,8 @@ var gBbs2chService = Cc["@mozilla.org/bbs2ch-service;1"].getService(Ci.nsIBbs2chService); +var gB2rService = Cc["@bbs2ch.sourceforge.jp/b2r-global-service;1"].getService(Ci.b2rIGlobalService); + var gTreeSubject; var gBoardItems; var gSubjectDownloader; @@ -180,7 +182,7 @@ document.getElementById("lblTitle").setAttribute("value", gBoardItems.title); if(gFirstInitTreeSubject){ - gBbs2chService.visitPage(gBoardItems.url, gBoardItems.title, 0); + gB2rService.history.visitPage(gBoardItems.url, gBoardItems.title, 0); gFirstInitTreeSubject = false; } Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js 2007-11-03 12:53:58 UTC (rev 246) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js 2007-11-03 13:30:11 UTC (rev 247) @@ -261,7 +261,9 @@ close: function(){ if(this._headerResponded && this.dat){ var title = this._bbs2chService.fromSJIS(this.dat.title); - this._bbs2chService.visitPage(this.dat.threadPlainURL, title, 1); + var gB2rService = Components.classes["@bbs2ch.sourceforge.jp/b2r-global-service;1"] + .getService(Components.interfaces.b2rIGlobalService); + gB2rService.history.visitPage(this.dat.threadPlainURL, title, 1); } this._opend = false; this._httpChannel = null; Modified: trunk/bbs2chreader/components/b2rGlobalService.js =================================================================== --- trunk/bbs2chreader/components/b2rGlobalService.js 2007-11-03 12:53:58 UTC (rev 246) +++ trunk/bbs2chreader/components/b2rGlobalService.js 2007-11-03 13:30:11 UTC (rev 247) @@ -94,7 +94,7 @@ var dataDir = this._dataDir.clone().QueryInterface(Ci.nsILocalFile); if(!dataDir.exists()){ - dataDir.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0666); + dataDir.create(Ci.nsILocalFile.DIRECTORY_TYPE, 0666); } return dataDir; }, @@ -251,21 +251,93 @@ b2rGlobalHistory.prototype = { - get historyDB(){ - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + get database(){ + return this._database; }, _init: function(aGlobalService){ + var storageService = XPC.getService("@mozilla.org/storage/service;1", "mozIStorageService"); + var pref = XPC.getService("@mozilla.org/preferences-service;1", "nsIPrefBranch"); + + var dbFile = aGlobalService.io.getDataDir(); + dbFile.appendRelativePath("history.sqlite"); + this._database = storageService.openDatabase(dbFile); + + this._database.beginTransaction(); + try{ + if(!this._database.tableExists("history")){ + var sql = <> + CREATE TABLE history( + id INTEGER PRIMARY KEY, + url TEXT NOT NULL, + title NOT NULL, + last_visited INTEGER NOT NULL DEFAULT 0, + visit_count INTEGER NOT NULL DEFAULT 1, + type INTEGER NOT NULL DEFAULT 0 + ); + </>.toString(); + this._database.executeSimpleSQL(sql); + } + + var historyExpireDays = pref.getIntPref("extensions.bbs2chreader.history_expire_days"); + if(historyExpireDays > 365) historyExpireDays = 365; + var sql = "DELETE FROM history WHERE last_visited < strftime('%s', 'now', '-" + historyExpireDays + " day')"; + this._database.executeSimpleSQL(sql); + + }finally{ + this._database.commitTransaction(); + } }, visitPage: function(aBoardURL, aTitle, aType){ + var pageID = null; + + this._database.beginTransaction(); + try{ + var sql = "SELECT id FROM history WHERE url=?1"; + var statement = this._database.createStatement(sql); + statement.bindStringParameter(0, aBoardURL.spec); + if(statement.executeStep()){ + pageID = statement.getInt32(0); + } + statement.reset(); + + if(pageID){ + sql = "UPDATE history SET title=?1, visit_count=visit_count+1, last_visited=?2 WHERE id=?3;"; + statement = this._database.createStatement(sql); + statement.bindStringParameter(0, aTitle); + statement.bindInt32Parameter(1, Date.now() / 1000); + statement.bindInt32Parameter(2, pageID); + statement.execute(); + }else{ + sql = "INSERT INTO history(url, title, type, last_visited) VALUES(?1, ?2, ?3, ?4);"; + statement = this._database.createStatement(sql); + statement.bindStringParameter(0, aURL.spec); + statement.bindStringParameter(1, aTitle); + statement.bindInt32Parameter(2, aType); + statement.bindInt32Parameter(3, Date.now() / 1000); + statement.execute(); + } + }finally{ + this._database.commitTransaction(); + } + return true; }, clearAll: function(){ - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + this._database.beginTransaction(); + try{ + this._database.executeSimpleSQL("DELETE FROM history;"); + }finally{ + this._database.commitTransaction(); + } + + try{ + this._database.executeSimpleSQL("VACUUM"); + }catch(ex){} } }; @@ -470,12 +542,12 @@ _startup: function(){ + this._initialized = true; this._io = new b2rGlobalIO(); this._threadUtils = new b2rGlobalThreadUtils(); this._history = new b2rGlobalHistory(this); this._viewer = new b2rGlobalViewer(this); - this._initialized = true; dump("b2rGlobalService._startup()\n"); }, Modified: trunk/bbs2chreader/components/nsBbs2chService.js =================================================================== --- trunk/bbs2chreader/components/nsBbs2chService.js 2007-11-03 12:53:58 UTC (rev 246) +++ trunk/bbs2chreader/components/nsBbs2chService.js 2007-11-03 13:30:11 UTC (rev 247) @@ -39,106 +39,8 @@ const Cc = Components.classes; -function b2rGlobalHistory(aBbs2chService){ - this._init(aBbs2chService); -} -b2rGlobalHistory.prototype = { - get historyDB(){ - return this._historyDB; - }, - - _init: function(aBbs2chService){ - var storageService = Cc["@mozilla.org/storage/service;1"] - .getService(Ci.mozIStorageService); - var dbFile = aBbs2chService.getDataDir(); - dbFile.appendRelativePath("history.sqlite"); - // 初回起動でデータディレクトリが存在しない場合にそなえて先に作成 - if(!dbFile.exists()){ - dbFile.create(dbFile.NORMAL_FILE_TYPE, 0666); - } - - this._historyDB = storageService.openDatabase(dbFile); - - this._historyDB.beginTransaction(); - try{ - if(!this._historyDB.tableExists("history")){ - var sql = <><![CDATA[ - CREATE TABLE history( - id INTEGER PRIMARY KEY, - url TEXT NOT NULL, - title NOT NULL, - last_visited INTEGER NOT NULL DEFAULT 0, - visit_count INTEGER NOT NULL DEFAULT 1, - type INTEGER NOT NULL DEFAULT 0 - ); - ]]></>.toString(); - this._historyDB.executeSimpleSQL(sql); - } - - var historyExpireDays = aBbs2chService.pref.getIntPref("extensions.bbs2chreader.history_expire_days"); - if(historyExpireDays > 365) historyExpireDays = 365; - var sql = "DELETE FROM history WHERE last_visited < strftime('%s', 'now', '-" + historyExpireDays + " day')"; - this._historyDB.executeSimpleSQL(sql); - - }finally{ - this.historyDB.commitTransaction(); - } - }, - - visitPage: function(aURL, aTitle, aType){ - var pageID = null; - - this.historyDB.beginTransaction(); - try{ - var sql = "SELECT id FROM history WHERE url=?1"; - var statement = this.historyDB.createStatement(sql); - statement.bindStringParameter(0, aURL.spec); - if(statement.executeStep()){ - pageID = statement.getInt32(0); - } - statement.reset(); - - if(pageID){ - sql = "UPDATE history SET title=?1, visit_count=visit_count+1, last_visited=?2 WHERE id=?3;"; - statement = this.historyDB.createStatement(sql); - statement.bindStringParameter(0, aTitle); - statement.bindInt32Parameter(1, Date.now() / 1000); - statement.bindInt32Parameter(2, pageID); - statement.execute(); - }else{ - sql = "INSERT INTO history(url, title, type, last_visited) VALUES(?1, ?2, ?3, ?4);"; - statement = this.historyDB.createStatement(sql); - statement.bindStringParameter(0, aURL.spec); - statement.bindStringParameter(1, aTitle); - statement.bindInt32Parameter(2, aType); - statement.bindInt32Parameter(3, Date.now() / 1000); - statement.execute(); - } - }finally{ - this.historyDB.commitTransaction(); - } - return true; - }, - - clearHistory: function(){ - this._historyDB.beginTransaction(); - try{ - this._historyDB.executeSimpleSQL("DELETE FROM history;"); - }finally{ - this.historyDB.commitTransaction(); - } - - try{ - this._historyDB.executeSimpleSQL("VACUUM"); - }catch(ex){} - } -}; - - - - function nsBbs2chService(){ // getBoardType で利用する例外的な URL のリスト( 2ch だけど板じゃない URL) this._exURLs = new Array( @@ -152,7 +54,6 @@ this.__unicodeConverter = null; this.__ioService = null; - this._globalHistory = null; this._pref = null; this._prefDefault = null; this._userAgent = null; @@ -256,18 +157,16 @@ }, get historyDB(){ - return this._globalHistory.historyDB; + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, _delayInit: function(){ - this._globalHistory = new b2rGlobalHistory(this); this._maruAutoAuth(); }, _shutdown: function(){ this.__unicodeConverter = null; this.__ioService = null; - this._globalHistory = null; this._pref = null; this._prefDefault = null; this._userAgent = null; @@ -729,12 +628,12 @@ visitPage: function(aURL, aTitle, aType){ - return this._globalHistory.visitPage(aURL, aTitle, aType); + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, clearHistory :function(){ - this._globalHistory.clearHistory(); + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },