[Bbs2ch-cvs 206] [188] b2rAboneManager 対応

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 8月 5日 (日) 21:53:12 JST


Revision: 188
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=188
Author:   flyson
Date:     2007-08-05 21:53:11 +0900 (Sun, 05 Aug 2007)

Log Message:
-----------
 b2rAboneManager 対応

Modified Paths:
--------------
    trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js
    trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.js
    trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js	2007-08-05 12:45:27 UTC (rev 187)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js	2007-08-05 12:53:11 UTC (rev 188)
@@ -106,6 +106,9 @@
 
 		this._bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
 					.getService(Components.interfaces.nsIBbs2chService);
+		this._aboneManager = Components.classes["@mozilla.org/b2r-abone-manager;1"]
+					.getService(Components.interfaces.b2rIAboneManager);
+
 		this._ioService = Components.classes["@mozilla.org/network/io-service;1"]
 					.getService(Components.interfaces.nsIIOService);
 
@@ -334,7 +337,7 @@
 			}
 		}
 
-		if(this._bbs2chService.shouldAbone(resName, resMail, resID, resMes)){
+		if(this._aboneManager.shouldAbone(resName, resMail, resID, resMes)){
 			resName = resMail = resDate = resMes = "ABONE";
 			if(aNumber>1 && this._bbs2chService.pref.getBoolPref("extensions.bbs2chreader.thread_hide_abone")){
 				return "";
@@ -619,7 +622,7 @@
 			resID = resArray[6];
 		}
 
-		if(this._bbs2chService.shouldAbone(resName, resMail, resID, resMes)){
+		if(this._aboneManager.shouldAbone(resName, resMail, resID, resMes)){
 			resName = resMail = resDate = resMes = "ABONE";
 			if(aNumber>1 && this._bbs2chService.pref.getBoolPref("extensions.bbs2chreader.thread_hide_abone")){
 				return "";

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.js	2007-08-05 12:45:27 UTC (rev 187)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.js	2007-08-05 12:53:11 UTC (rev 188)
@@ -35,228 +35,138 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
+const b2rIAboneManager = Components.interfaces.b2rIAboneManager;
 
 var gBbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
 			.getService(Components.interfaces.nsIBbs2chService);
 
-var lstNgNames;
-var lstNgAddrs;
-var lstNgId;
-var lstNgWords;
-var abone;
+var gAboneManager = Components.classes["@mozilla.org/b2r-abone-manager;1"]
+					.getService(b2rIAboneManager);
 
 
+var gAboneObserver = {
+	observe: function(aSubject, aTopic, aData){
+		var aboneType;
+		switch(aTopic){
+			case "b2r-abone-data-add":
+			case "b2r-abone-data-remove":
+				aboneType = aSubject.QueryInterface(Components.interfaces.nsISupportsPRInt32).data;
+				break;
+			default:
+				return;
+		}
+
+		var aboneListBox;
+		switch(aboneType){
+			case b2rIAboneManager.ABONE_TYPE_NAME:
+				aboneListBox = document.getElementById("aboneNameListBox");
+				break;
+			case b2rIAboneManager.ABONE_TYPE_MAIL:
+				aboneListBox = document.getElementById("aboneMailListBox");
+				break;
+			case b2rIAboneManager.ABONE_TYPE_ID:
+				aboneListBox = document.getElementById("aboneIDListBox");
+				break;
+			case b2rIAboneManager.ABONE_TYPE_WORD:
+				aboneListBox = document.getElementById("aboneWordListBox");
+				break;
+		}
+		var aboneData = gAboneManager.getAboneData(aboneType);
+		initList(aboneData, aboneListBox);
+	}
+};
+
+
 function startup(){
-	lstNgNames = document.getElementById("lstNgNames");
-	lstNgAddrs = document.getElementById("lstNgAddrs");
-	lstNgId = document.getElementById("lstNgId");
-	lstNgWords = document.getElementById("lstNgWords");
+	var aboneNameListBox = document.getElementById("aboneNameListBox");
+	var aboneMailListBox = document.getElementById("aboneMailListBox");
+	var aboneIDListBox = document.getElementById("aboneIDListBox");
+	var aboneWordListBox = document.getElementById("aboneWordListBox");
 
-	abone = new b2rAbone();
 
-	initList(abone.ngNames, lstNgNames);
-	initList(abone.ngAddrs, lstNgAddrs);
-	initList(abone.ngId, lstNgId);
-	initList(abone.ngWords, lstNgWords);
+	initList(gAboneManager.getAboneData(b2rIAboneManager.ABONE_TYPE_NAME), aboneNameListBox);
+	initList(gAboneManager.getAboneData(b2rIAboneManager.ABONE_TYPE_MAIL), aboneMailListBox);
+	initList(gAboneManager.getAboneData(b2rIAboneManager.ABONE_TYPE_ID), aboneIDListBox);
+	initList(gAboneManager.getAboneData(b2rIAboneManager.ABONE_TYPE_WORD), aboneWordListBox);
+
+	var os = Components.classes["@mozilla.org/observer-service;1"]
+				.getService(Components.interfaces.nsIObserverService);
+	os.addObserver(gAboneObserver, "b2r-abone-data-add", false);
+	os.addObserver(gAboneObserver, "b2r-abone-data-remove", false);
 }
 
 
+function shutdown(){
+	var os = Components.classes["@mozilla.org/observer-service;1"]
+				.getService(Components.interfaces.nsIObserverService);
+	os.removeObserver(gAboneObserver, "b2r-abone-data-add", false);
+	os.removeObserver(gAboneObserver, "b2r-abone-data-remove", false);
+
+}
+
+
 function accept(){
-	abone.save();
-	gBbs2chService.refreshAboneData();
 }
 
 
-function initList(aNgArray, aListBox){
-	for(var i=0; i<aNgArray.length; i++){
-		var ngWord = aNgArray[i];
-		if(!ngWord) continue;
-		aListBox.appendItem(ngWord, ngWord);
+function initList(aAboneData, aListBox){
+	while(aListBox.getRowCount() > 0){
+		aListBox.removeItemAt(0);
 	}
+
+	for(let [i, value] in aAboneData){
+		if(!value) continue;
+		aListBox.appendItem(value, value);
+	}
 }
 
-function appendNgWord(aNgType){
-	var ngWord;
-	var ngListBox;
 
-	switch(aNgType){
-		case "names":
-			ngWord = document.getElementById("txtNgNames").value;
-			ngListBox = lstNgNames;
+function addAbone(aType){
+	var aboneWord;
+	var aboneListBox;
+
+	switch(aType){
+		case b2rIAboneManager.ABONE_TYPE_NAME:
+			aboneWord = document.getElementById("aboneNameTextBox").value;
+			aboneListBox = document.getElementById("aboneNameListBox");
 			break;
-		case "addrs":
-			ngWord = document.getElementById("txtNgAddrs").value;
-			ngListBox = lstNgAddrs;
+		case b2rIAboneManager.ABONE_TYPE_MAIL:
+			aboneWord = document.getElementById("aboneMailTextBox").value;
+			aboneListBox = document.getElementById("aboneMailListBox");
 			break;
-		case "id":
-			ngWord = document.getElementById("txtNgId").value;
-			ngListBox = lstNgId;
+		case b2rIAboneManager.ABONE_TYPE_ID:
+			aboneWord = document.getElementById("aboneIDTextBox").value;
+			aboneListBox = document.getElementById("aboneIDListBox");
 			break;
-		case "words":
-			ngWord = document.getElementById("txtNgWords").value;
-			ngListBox = lstNgWords;
+		case b2rIAboneManager.ABONE_TYPE_WORD:
+			aboneWord = document.getElementById("aboneWordTextBox").value;
+			aboneListBox = document.getElementById("aboneWordListBox");
 			break;
 	}
-	if(!ngWord) return;
+	if(!aboneWord) return;
 
-	abone.appendNgWord(aNgType, ngWord);
-	ngListBox.appendItem(ngWord, ngWord);
+	gAboneManager.addAbone(aboneWord, aType);
 }
 
-function removeNgWord(aNgType){
-	var ngWord;
-	var ngListBox;
 
-	switch(aNgType){
-		case "names":
-			ngListBox = lstNgNames;
+function removeAbone(aType){
+	var aboneListBox;
+	switch(aType){
+		case b2rIAboneManager.ABONE_TYPE_NAME:
+			aboneListBox = document.getElementById("aboneNameListBox");
 			break;
-		case "addrs":
-			ngListBox = lstNgAddrs;
+		case b2rIAboneManager.ABONE_TYPE_MAIL:
+			aboneListBox = document.getElementById("aboneMailListBox");
 			break;
-		case "id":
-			ngListBox = lstNgId;
+		case b2rIAboneManager.ABONE_TYPE_ID:
+			aboneListBox = document.getElementById("aboneIDListBox");
 			break;
-		case "words":
-			ngListBox = lstNgWords;
+		case b2rIAboneManager.ABONE_TYPE_WORD:
+			aboneListBox = document.getElementById("aboneWordListBox");
 			break;
 	}
+	if(aboneListBox.selectedIndex == -1) return;
+	var aboneWord = aboneListBox.selectedItem.value;
 
-	if(ngListBox.selectedIndex == -1) return;
-
-	ngWord = ngListBox.selectedItem.value;
-	ngListBox.removeItemAt(ngListBox.selectedIndex);
-	abone.removeNgWord(aNgType, ngWord);
+	gAboneManager.removeAbone(aboneWord, aType);
 }
-
-
-function b2rAbone(){
-	this.init();
-	this.refresh();
-}
-
-
-b2rAbone.prototype = {
-
-	get ngNames(){
-		return this._ngNames;
-	},
-	get ngAddrs(){
-		return this._ngAddrs;
-	},
-	get ngId(){
-		return this._ngId;
-	},
-	get ngWords(){
-		return this._ngWords;
-	},
-
-
-	/**
-	 *	初期化処理
-	 */
-	init: function(){
-		this._bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
-					.getService(Components.interfaces.nsIBbs2chService);
-
-		this._ngNamesFile = this._bbs2chService.getDataDir();
-		this._ngNamesFile.appendRelativePath("NGnames.txt");
-
-		this._ngAddrsFile = this._bbs2chService.getDataDir();
-		this._ngAddrsFile.appendRelativePath("NGaddrs.txt");
-
-		this._ngIdFile = this._bbs2chService.getDataDir();
-		this._ngIdFile.appendRelativePath("NGid.txt");
-
-		this._ngWordsFile = this._bbs2chService.getDataDir();
-		this._ngWordsFile.appendRelativePath("NGwords.txt");
-
-		this._ngNames = new Array();
-		this._ngAddrs = new Array();
-		this._ngId	  = new Array();
-		this._ngWords = new Array();
-
-		this._enabled = false;
-	},
-
-
-	/**
-	 *	NGワードファイルを読み込む
-	 */
-	refresh: function(){
-		function loadNgFile(aLocalFile, aBbs2chService){
-			if(!aLocalFile.exists()) return new Array();
-			var contentLine = aBbs2chService.fromSJIS(
-					aBbs2chService.readFile(aLocalFile.path)).split("\n");
-			var resultArray = new Array();
-				// 空白行は読み込まない
-			for(var i=0; i<contentLine.length; i++){
-				if(contentLine[i]) resultArray.push(contentLine[i]);
-			}
-			return resultArray;
-		}
-		this._ngNames = loadNgFile(this._ngNamesFile, this._bbs2chService);
-		this._ngAddrs = loadNgFile(this._ngAddrsFile, this._bbs2chService);
-		this._ngId	  = loadNgFile(this._ngIdFile, this._bbs2chService);
-		this._ngWords = loadNgFile(this._ngWordsFile, this._bbs2chService);
-
-		this._enabled = ((this.ngNames.length + this.ngAddrs.length +
-								this.ngId.length + this.ngWords.length) != 0)
-	},
-
-
-	/**
-	 *	NGワードファイルに保存
-	 */
-	save: function(){
-		function saveNgFile(aNgArray, aLocalFile, aBbs2chService){
-			var content = aBbs2chService.toSJIS(aNgArray.join("\n"));
-			aBbs2chService.writeFile(aLocalFile.path, content, false);
-		}
-		saveNgFile(this._ngNames, this._ngNamesFile, this._bbs2chService);
-		saveNgFile(this._ngAddrs, this._ngAddrsFile, this._bbs2chService);
-		saveNgFile(this._ngId, this._ngIdFile, this._bbs2chService);
-		saveNgFile(this._ngWords, this._ngWordsFile, this._bbs2chService);
-	},
-
-
-	/**
-	 * NGワード配列に NGワードを登録
-	 * @param aNgType string NG ワード配列のタイプ "names" "addrs" "id" "words"
-	 * @param aWord 登録する NGワード
-	 */
-	appendNgWord: function(aNgType, aWord){
-		var aNgArray;
-		switch(aNgType){
-			case "names": aNgArray = this._ngNames; break;
-			case "addrs": aNgArray = this._ngAddrs; break;
-			case "id":	  aNgArray = this._ngId;	break;
-			case "words": aNgArray = this._ngWords; break;
-		}
-			// 二重登録の禁止
-		for(var i=0; i<aNgArray.length; i++){
-			if(aNgArray[i] == aWord) return;
-		}
-		aNgArray.push(aWord);
-	},
-
-
-	/**
-	 * NGワード配列から NGワードを削除
-	 * @param aNgType string NG ワード配列のタイプ "names" "addrs" "id" "words"
-	 * @param aWord 削除する NGワード
-	 */
-	removeNgWord: function(aNgType, aWord){
-		var aNgArray;
-		switch(aNgType){
-			case "names": aNgArray = this._ngNames; break;
-			case "addrs": aNgArray = this._ngAddrs; break;
-			case "id":	  aNgArray = this._ngId;	break;
-			case "words": aNgArray = this._ngWords; break;
-		}
-		for(var i=0; i<aNgArray.length; i++){
-			if(aNgArray[i] == aWord) aNgArray.splice(i, 1);
-		}
-	}
-
-};
\ No newline at end of file

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul	2007-08-05 12:45:27 UTC (rev 187)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul	2007-08-05 12:53:11 UTC (rev 188)
@@ -4,58 +4,59 @@
 
 
 
-<prefwindow id="winMain" onload="startup()" ondialogaccept="return accept()"
-	title="あぼーん マネージャ" width="550" height="450"
+<prefwindow id="winMain" title="あぼーん マネージャ" width="550" height="450"
+	onload="startup()" onunload="shutdown()" ondialogaccept="return accept()"
 	persist="screenX screenY width height"
 	xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-<prefpane id="pane1" label="名前">
+<prefpane id="aboneNamePane" label="名前">
 	<preferences/>
 	<vbox>
 			<hbox>
-				<textbox id="txtNgNames" flex="1"/>
-				<button label="追加" onclick="appendNgWord('names')"/>
-				<button label="削除" onclick="removeNgWord('names')"/>
+				<textbox id="aboneNameTextBox" flex="1"/>
+				<button label="追加" onclick="addAbone(b2rIAboneManager.ABONE_TYPE_NAME)"/>
+				<button label="削除" onclick="removeAbone(b2rIAboneManager.ABONE_TYPE_NAME)"/>
 			</hbox>
-			<listbox id="lstNgNames" flex="1"/>
+			<listbox id="aboneNameListBox" flex="1"/>
 	</vbox>
 </prefpane>
-<prefpane id="pane2" label="メール">
+<prefpane id="aboneMailPane" label="メール">
 	<preferences/>
 	<vbox>
 			<hbox>
-				<textbox id="txtNgAddrs" flex="1"/>
-				<button label="追加" onclick="appendNgWord('addrs')"/>
-				<button label="削除" onclick="removeNgWord('addrs')"/>
+				<textbox id="aboneMailTextBox" flex="1"/>
+				<button label="追加" onclick="addAbone(b2rIAboneManager.ABONE_TYPE_MAIL)"/>
+				<button label="削除" onclick="removeAbone(b2rIAboneManager.ABONE_TYPE_MAIL)"/>
 			</hbox>
-			<listbox id="lstNgAddrs" flex="1"/>
+			<listbox id="aboneMailListBox" flex="1"/>
 	</vbox>
 </prefpane>
 
-<prefpane id="pane3" label="ID">
+<prefpane id="aboneIDPane" label="ID">
 	<preferences/>
 	<vbox>
 			<hbox>
-				<textbox id="txtNgId" flex="1"/>
-				<button label="追加" onclick="appendNgWord('id')"/>
-				<button label="削除" onclick="removeNgWord('id')"/>
+				<textbox id="aboneIDTextBox" flex="1"/>
+				<button label="追加" onclick="addAbone(b2rIAboneManager.ABONE_TYPE_ID)"/>
+				<button label="削除" onclick="removeAbone(b2rIAboneManager.ABONE_TYPE_ID)"/>
 			</hbox>
-			<listbox id="lstNgId" flex="1"/>
+			<listbox id="aboneIDListBox" flex="1"/>
 	</vbox>
 </prefpane>
 
-<prefpane id="pane4" label="ワード">
+<prefpane id="aboneWordPane" label="ワード">
 	<preferences/>
 	<vbox>
 			<hbox>
-				<textbox id="txtNgWords" flex="1"/>
-				<button label="追加" onclick="appendNgWord('words')"/>
-				<button label="削除" onclick="removeNgWord('words')"/>
+				<textbox id="aboneWordTextBox" flex="1"/>
+				<button label="追加" onclick="addAbone(b2rIAboneManager.ABONE_TYPE_WORD)"/>
+				<button label="削除" onclick="removeAbone(b2rIAboneManager.ABONE_TYPE_WORD)"/>
 			</hbox>
-			<listbox id="lstNgWords" flex="1"/>
+			<listbox id="aboneWordListBox" flex="1"/>
 	</vbox>
 </prefpane>
 
-<script type="application/x-javascript" src="chrome://bbs2chreader/content/settings/abone-manager.js"/>
+<script type="application/javascript; version=1.7"
+			src="chrome://bbs2chreader/content/settings/abone-manager.js"/>
 
 </prefwindow>
\ No newline at end of file




bbs2ch-cvs メーリングリストの案内
Back to archive index