[Bbs2ch-cvs 315] [297] b2rAboneManager を b2rGlobalService . abone に移動

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 12月 30日 (日) 20:30:08 JST


Revision: 297
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=297
Author:   flyson
Date:     2007-12-30 20:30:07 +0900 (Sun, 30 Dec 2007)

Log Message:
-----------
b2rAboneManager を b2rGlobalService.abone に移動

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
    trunk/bbs2chreader/components/b2rGlobalService.js
    trunk/bbs2chreader/components/b2rIGlobalService.xpt
    trunk/bbs2chreader/components/idl/b2rIGlobalService.idl

Added Paths:
-----------
    trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rAboneManager.js

Removed Paths:
-------------
    trunk/bbs2chreader/components/b2rAboneManager.js
    trunk/bbs2chreader/components/idl/b2rIAboneManager.idl


-------------- next part --------------
Added: trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rAboneManager.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rAboneManager.js	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rAboneManager.js	2007-12-30 11:30:07 UTC (rev 297)
@@ -0,0 +1,222 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is bbs2chreader.
+ *
+ * The Initial Developer of the Original Code is
+ * flyson.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *    flyson <flyso****@users*****>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+
+function b2rAboneManager(){
+	this._init();
+}
+
+b2rAboneManager.prototype = {
+
+	get ABONE_TYPE_NAME(){ return Ci.b2rIAboneManager.ABONE_TYPE_NAME },
+	get ABONE_TYPE_MAIL(){ return Ci.b2rIAboneManager.ABONE_TYPE_MAIL },
+	get ABONE_TYPE_ID  (){ return Ci.b2rIAboneManager.ABONE_TYPE_ID   },
+	get ABONE_TYPE_WORD(){ return Ci.b2rIAboneManager.ABONE_TYPE_WORD },
+
+	_init: function(){
+		this._loadAboneData();
+	},
+
+	_loadAboneData: function(){
+		this._aboneData = new Array();
+		this._aboneData["name"] = this._loadNgFile("NGnames.txt");
+		this._aboneData["mail"] = this._loadNgFile("NGaddrs.txt");
+		this._aboneData["id"] = this._loadNgFile("NGid.txt");
+		this._aboneData["word"] = this._loadNgFile("NGwords.txt");
+	},
+	_loadNgFile: function(aNgFileName){
+		var ngFile = gGlobalService.io.getDataDir();
+		ngFile.appendRelativePath(aNgFileName);
+		if(!ngFile.exists()) return new Array();
+
+		var resultArray = new Array();
+		var fileInputStream = XPC.createInstance("@mozilla.org/network/file-input-stream;1",
+			"nsIFileInputStream");
+		fileInputStream.init(ngFile, 0x01, 0666, 0);
+		fileInputStream.QueryInterface(Ci.nsILineInputStream);
+		let(more, line = {}){
+			do{
+				more = fileInputStream.readLine(line);
+				if(line.value) resultArray.push(line.value);
+			}while(more);
+		}
+		fileInputStream.close();
+		return resultArray;
+	},
+
+
+	_saveAboneData: function(){
+		this._saveNgFile("NGnames.txt", this._aboneData["name"]);
+		this._saveNgFile("NGaddrs.txt", this._aboneData["mail"]);
+		this._saveNgFile("NGid.txt", this._aboneData["id"]);
+		this._saveNgFile("NGwords.txt", this._aboneData["word"]);
+	},
+	_saveNgFile: function(aNgFileName, aboneDataArray){
+		var ngFile = gGlobalService.io.getDataDir();
+		ngFile.appendRelativePath(aNgFileName);
+			// nsILocalFile.create は親フォルダをふくめて作成する
+		if(!ngFile.exists()) ngFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0666);
+
+		var content = aboneDataArray.join("\n");
+
+		var fileOutputStream = XPC.createInstance("@mozilla.org/network/file-output-stream;1",
+				"nsIFileOutputStream");
+			// 0x02=PR_WRONLY; 0x08=PR_CREATE_FILE;
+			// 0x10=PR_APPEND; 0x20=PR_TRUNCATE;
+		fileOutputStream.init(ngFile, 0x02|0x08|0x20, 0666, 0);
+		fileOutputStream.write(content, content.length);
+		fileOutputStream.flush();
+		fileOutputStream.close();
+	},
+
+
+	shouldAbone: function(aName, aMail, aID, aMsg){
+		function checkFunc(aElement, aIndex, aArray){
+			return this.indexOf(aElement) != -1;
+		}
+		if(this._aboneData["name"].some(checkFunc, aName)) return true;
+		if(this._aboneData["mail"].some(checkFunc, aMail)) return true;
+		if(this._aboneData["id"].some(checkFunc, aID)) return true;
+		if(this._aboneData["word"].some(checkFunc, aMsg)) return true;
+
+		return false;
+	},
+
+
+	getAboneData: function(aType){
+		var ngArray;
+		switch(aType){
+			case this.ABONE_TYPE_NAME:
+				ngArray = this._aboneData["name"];
+				break;
+			case this.ABONE_TYPE_MAIL:
+				ngArray = this._aboneData["mail"];
+				break;
+			case this.ABONE_TYPE_ID:
+				ngArray = this._aboneData["id"];
+				break;
+			case this.ABONE_TYPE_WORD:
+				ngArray = this._aboneData["word"];
+				break;
+			default:
+				return null;
+		}
+
+		var unicodeConverter = XPC.createInstance("@mozilla.org/intl/scriptableunicodeconverter",
+				"nsIScriptableUnicodeConverter");
+		unicodeConverter.charset = "Shift_JIS";
+
+		var resultArray = ngArray.map(function testFunc(aElement, aIndex, aArray){
+				return unicodeConverter.ConvertToUnicode(aElement);
+		});
+		return resultArray;
+	},
+
+
+	addAbone: function(aWord, aType){
+		var unicodeConverter = XPC.createInstance("@mozilla.org/intl/scriptableunicodeconverter",
+				"nsIScriptableUnicodeConverter");
+		unicodeConverter.charset = "Shift_JIS";
+
+		var sjisWord = unicodeConverter.ConvertFromUnicode(aWord);
+
+		var ngArray;
+		switch(aType){
+			case this.ABONE_TYPE_NAME:
+				ngArray = this._aboneData["name"];
+				break;
+			case this.ABONE_TYPE_MAIL:
+				ngArray = this._aboneData["mail"];
+				break;
+			case this.ABONE_TYPE_ID:
+				ngArray = this._aboneData["id"];
+				break;
+			case this.ABONE_TYPE_WORD:
+				ngArray = this._aboneData["word"];
+				break;
+			default:
+				return;
+		}
+
+			// 二重登録の禁止
+		if(ngArray.indexOf(sjisWord) != -1) return;
+
+		ngArray.push(sjisWord);
+
+		var os = XPC.getService("@mozilla.org/observer-service;1", "nsIObserverService");
+		var type = XPC.createInstance("@mozilla.org/supports-PRInt32;1", "nsISupportsPRInt32");
+		type.data = aType;
+
+		os.notifyObservers(type, "b2r-abone-data-add", aWord);
+	},
+
+
+	removeAbone: function(aWord, aType){
+		var unicodeConverter = XPC.createInstance("@mozilla.org/intl/scriptableunicodeconverter",
+				"nsIScriptableUnicodeConverter");
+		unicodeConverter.charset = "Shift_JIS";
+
+		var sjisWord = unicodeConverter.ConvertFromUnicode(aWord);
+
+		var ngArray;
+		switch(aType){
+			case this.ABONE_TYPE_NAME:
+				ngArray = this._aboneData["name"];
+				break;
+			case this.ABONE_TYPE_MAIL:
+				ngArray = this._aboneData["mail"];
+				break;
+			case this.ABONE_TYPE_ID:
+				ngArray = this._aboneData["id"];
+				break;
+			case this.ABONE_TYPE_WORD:
+				ngArray = this._aboneData["word"];
+				break;
+			default:
+				return;
+		}
+
+		var wordIndex = ngArray.indexOf(sjisWord);
+		if(wordIndex != -1) ngArray.splice(wordIndex, 1);
+
+		var os = XPC.getService("@mozilla.org/observer-service;1", "nsIObserverService");
+		var type = XPC.createInstance("@mozilla.org/supports-PRInt32;1", "nsISupportsPRInt32");
+		type.data = aType;
+		os.notifyObservers(type, "b2r-abone-data-remove", aWord);
+	}
+
+};
\ No newline at end of file

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js	2007-12-30 11:30:07 UTC (rev 297)
@@ -108,8 +108,6 @@
 					.getService(Components.interfaces.b2rIGlobalService);
 		this._pref = Components.classes["@mozilla.org/preferences-service;1"]
 					.getService(Components.interfaces.nsIPrefBranch);
-		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);
@@ -343,7 +341,7 @@
 			}
 		}
 
-		if(this._aboneManager.shouldAbone(resName, resMail, resID, resMes)){
+		if(this._b2rService.abone.shouldAbone(resName, resMail, resID, resMes)){
 			this._chainAboneNumbers.push(aNumber);
 			resName = resMail = resDate = resMes = "ABONE";
 			if(aNumber>1 && this._pref.getBoolPref("extensions.bbs2chreader.thread_hide_abone")){
@@ -643,7 +641,7 @@
 			resID = resArray[6];
 		}
 
-		if(this._aboneManager.shouldAbone(resName, resMail, resID, resMes)){
+		if(this._b2rService.abone.shouldAbone(resName, resMail, resID, resMes)){
 			resName = resMail = resDate = resMes = "ABONE";
 			if(aNumber>1 && this._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-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.js	2007-12-30 11:30:07 UTC (rev 297)
@@ -35,15 +35,10 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-const b2rIAboneManager = Components.interfaces.b2rIAboneManager;
+var gAboneManager = Cc["@bbs2ch.sourceforge.jp/b2r-global-service;1"]
+		.getService(Ci.b2rIGlobalService).abone;
 
-var gBbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
-			.getService(Components.interfaces.nsIBbs2chService);
 
-var gAboneManager = Components.classes["@mozilla.org/b2r-abone-manager;1"]
-					.getService(b2rIAboneManager);
-
-
 var gAboneObserver = {
 	observe: function(aSubject, aTopic, aData){
 		var aboneType;
@@ -58,16 +53,16 @@
 
 		var aboneListBox;
 		switch(aboneType){
-			case b2rIAboneManager.ABONE_TYPE_NAME:
+			case Ci.b2rIAboneManager.ABONE_TYPE_NAME:
 				aboneListBox = document.getElementById("aboneNameListBox");
 				break;
-			case b2rIAboneManager.ABONE_TYPE_MAIL:
+			case Ci.b2rIAboneManager.ABONE_TYPE_MAIL:
 				aboneListBox = document.getElementById("aboneMailListBox");
 				break;
-			case b2rIAboneManager.ABONE_TYPE_ID:
+			case Ci.b2rIAboneManager.ABONE_TYPE_ID:
 				aboneListBox = document.getElementById("aboneIDListBox");
 				break;
-			case b2rIAboneManager.ABONE_TYPE_WORD:
+			case Ci.b2rIAboneManager.ABONE_TYPE_WORD:
 				aboneListBox = document.getElementById("aboneWordListBox");
 				break;
 		}
@@ -84,10 +79,10 @@
 	var aboneWordListBox = document.getElementById("aboneWordListBox");
 
 
-	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);
+	initList(gAboneManager.getAboneData(Ci.b2rIAboneManager.ABONE_TYPE_NAME), aboneNameListBox);
+	initList(gAboneManager.getAboneData(Ci.b2rIAboneManager.ABONE_TYPE_MAIL), aboneMailListBox);
+	initList(gAboneManager.getAboneData(Ci.b2rIAboneManager.ABONE_TYPE_ID), aboneIDListBox);
+	initList(gAboneManager.getAboneData(Ci.b2rIAboneManager.ABONE_TYPE_WORD), aboneWordListBox);
 
 	var os = Components.classes["@mozilla.org/observer-service;1"]
 				.getService(Components.interfaces.nsIObserverService);
@@ -126,19 +121,19 @@
 	var aboneListBox;
 
 	switch(aType){
-		case b2rIAboneManager.ABONE_TYPE_NAME:
+		case Ci.b2rIAboneManager.ABONE_TYPE_NAME:
 			aboneWord = document.getElementById("aboneNameTextBox").value;
 			aboneListBox = document.getElementById("aboneNameListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_MAIL:
+		case Ci.b2rIAboneManager.ABONE_TYPE_MAIL:
 			aboneWord = document.getElementById("aboneMailTextBox").value;
 			aboneListBox = document.getElementById("aboneMailListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_ID:
+		case Ci.b2rIAboneManager.ABONE_TYPE_ID:
 			aboneWord = document.getElementById("aboneIDTextBox").value;
 			aboneListBox = document.getElementById("aboneIDListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_WORD:
+		case Ci.b2rIAboneManager.ABONE_TYPE_WORD:
 			aboneWord = document.getElementById("aboneWordTextBox").value;
 			aboneListBox = document.getElementById("aboneWordListBox");
 			break;
@@ -152,16 +147,16 @@
 function removeAbone(aType){
 	var aboneListBox;
 	switch(aType){
-		case b2rIAboneManager.ABONE_TYPE_NAME:
+		case Ci.b2rIAboneManager.ABONE_TYPE_NAME:
 			aboneListBox = document.getElementById("aboneNameListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_MAIL:
+		case Ci.b2rIAboneManager.ABONE_TYPE_MAIL:
 			aboneListBox = document.getElementById("aboneMailListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_ID:
+		case Ci.b2rIAboneManager.ABONE_TYPE_ID:
 			aboneListBox = document.getElementById("aboneIDListBox");
 			break;
-		case b2rIAboneManager.ABONE_TYPE_WORD:
+		case Ci.b2rIAboneManager.ABONE_TYPE_WORD:
 			aboneListBox = document.getElementById("aboneWordListBox");
 			break;
 	}

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/settings/abone-manager.xul	2007-12-30 11:30:07 UTC (rev 297)
@@ -7,8 +7,8 @@
 	persist="screenX screenY width height"
 	xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-<script type="application/javascript; version=1.7"
-			src="chrome://bbs2chreader/content/settings/abone-manager.js"/>
+<script type="application/javascript;version=1.7" src="chrome://bbs2chreader/content/lib/xpc.js"/>
+<script type="application/javascript;version=1.7" src="chrome://bbs2chreader/content/settings/abone-manager.js"/>
 
 <tabbox id="aboneManagerTabBox" flex="1">
 	<tabs>

Deleted: trunk/bbs2chreader/components/b2rAboneManager.js
===================================================================
--- trunk/bbs2chreader/components/b2rAboneManager.js	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/components/b2rAboneManager.js	2007-12-30 11:30:07 UTC (rev 297)
@@ -1,373 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is bbs2chreader.
- *
- * The Initial Developer of the Original Code is
- * flyson.
- * Portions created by the Initial Developer are Copyright (C) 2004
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *    flyson <flyso****@users*****>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
-
-function b2rAboneManager(){
-
-}
-
-b2rAboneManager.prototype = {
-
-	get ABONE_TYPE_NAME(){ return Ci.b2rIAboneManager.ABONE_TYPE_NAME },
-	get ABONE_TYPE_MAIL(){ return Ci.b2rIAboneManager.ABONE_TYPE_MAIL },
-	get ABONE_TYPE_ID  (){ return Ci.b2rIAboneManager.ABONE_TYPE_ID   },
-	get ABONE_TYPE_WORD(){ return Ci.b2rIAboneManager.ABONE_TYPE_WORD },
-
-	_startup: function(){
-		this._loadAboneData();
-		dump("b2rAboneManager.startup\n");
-	},
-
-	_shutdown: function(){
-		this._saveAboneData();
-		dump("b2rAboneManager.shutdown\n");
-	},
-
-	_loadAboneData: function(){
-		this._aboneData = new Array();
-		this._aboneData["name"] = this._loadNgFile("NGnames.txt");
-		this._aboneData["mail"] = this._loadNgFile("NGaddrs.txt");
-		this._aboneData["id"] = this._loadNgFile("NGid.txt");
-		this._aboneData["word"] = this._loadNgFile("NGwords.txt");
-	},
-	_loadNgFile: function(aNgFileName){
-		var bbs2chService = Cc["@mozilla.org/bbs2ch-service;1"]
-						.getService(Ci.nsIBbs2chService);
-
-		var ngFile = bbs2chService.getDataDir();
-		ngFile.appendRelativePath(aNgFileName);
-		if(!ngFile.exists()) return new Array();
-
-		var contentLine = bbs2chService.readFileLine(ngFile.path, {});
-		var resultArray = new Array();
-			// 空白行は読み込まない
-		for(let [i, line] in Iterator(contentLine)){
-			if(line) resultArray.push(line);
-		}
-		return resultArray;
-	},
-
-
-	_saveAboneData: function(){
-		this._saveNgFile("NGnames.txt", this._aboneData["name"]);
-		this._saveNgFile("NGaddrs.txt", this._aboneData["mail"]);
-		this._saveNgFile("NGid.txt", this._aboneData["id"]);
-		this._saveNgFile("NGwords.txt", this._aboneData["word"]);
-	},
-	_saveNgFile: function(aNgFileName, aboneDataArray){
-		var bbs2chService = Cc["@mozilla.org/bbs2ch-service;1"]
-						.getService(Ci.nsIBbs2chService);
-
-		var ngFile = bbs2chService.getDataDir();
-		ngFile.appendRelativePath(aNgFileName);
-		bbs2chService.writeFile(ngFile.path, aboneDataArray.join("\n"), false);
-	},
-
-
-
-	shouldAbone: function(aName, aMail, aID, aMsg){
-		function checkFunc(aElement, aIndex, aArray){
-			return this.indexOf(aElement) != -1;
-		}
-		if(this._aboneData["name"].some(checkFunc, aName)) return true;
-		if(this._aboneData["mail"].some(checkFunc, aMail)) return true;
-		if(this._aboneData["id"].some(checkFunc, aID)) return true;
-		if(this._aboneData["word"].some(checkFunc, aMsg)) return true;
-
-		return false;
-	},
-
-
-	getAboneData: function(aType){
-		var ngArray;
-		switch(aType){
-			case this.ABONE_TYPE_NAME:
-				ngArray = this._aboneData["name"];
-				break;
-			case this.ABONE_TYPE_MAIL:
-				ngArray = this._aboneData["mail"];
-				break;
-			case this.ABONE_TYPE_ID:
-				ngArray = this._aboneData["id"];
-				break;
-			case this.ABONE_TYPE_WORD:
-				ngArray = this._aboneData["word"];
-				break;
-			default:
-				return null;
-		}
-
-		var unicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-					.createInstance(Ci.nsIScriptableUnicodeConverter);
-		unicodeConverter.charset = "Shift_JIS";
-
-		var resultArray = ngArray.map(function testFunc(aElement, aIndex, aArray){
-				return unicodeConverter.ConvertToUnicode(aElement);
-		});
-		return resultArray;
-	},
-
-
-	addAbone: function(aWord, aType){
-		var unicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-					.createInstance(Ci.nsIScriptableUnicodeConverter);
-		unicodeConverter.charset = "Shift_JIS";
-
-		var sjisWord = unicodeConverter.ConvertFromUnicode(aWord);
-
-		var ngArray;
-		switch(aType){
-			case this.ABONE_TYPE_NAME:
-				ngArray = this._aboneData["name"];
-				break;
-			case this.ABONE_TYPE_MAIL:
-				ngArray = this._aboneData["mail"];
-				break;
-			case this.ABONE_TYPE_ID:
-				ngArray = this._aboneData["id"];
-				break;
-			case this.ABONE_TYPE_WORD:
-				ngArray = this._aboneData["word"];
-				break;
-			default:
-				return;
-		}
-
-			// 二重登録の禁止
-		if(ngArray.indexOf(sjisWord) != -1) return;
-
-		ngArray.push(sjisWord);
-
-		var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-		var type = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
-		type.data = aType;
-
-		os.notifyObservers(type, "b2r-abone-data-add", aWord);
-	},
-
-
-	removeAbone: function(aWord, aType){
-		var unicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-					.createInstance(Ci.nsIScriptableUnicodeConverter);
-		unicodeConverter.charset = "Shift_JIS";
-
-		var sjisWord = unicodeConverter.ConvertFromUnicode(aWord);
-
-		var ngArray;
-		switch(aType){
-			case this.ABONE_TYPE_NAME:
-				ngArray = this._aboneData["name"];
-				break;
-			case this.ABONE_TYPE_MAIL:
-				ngArray = this._aboneData["mail"];
-				break;
-			case this.ABONE_TYPE_ID:
-				ngArray = this._aboneData["id"];
-				break;
-			case this.ABONE_TYPE_WORD:
-				ngArray = this._aboneData["word"];
-				break;
-			default:
-				return;
-		}
-
-		var wordIndex = ngArray.indexOf(sjisWord);
-		if(wordIndex != -1) ngArray.splice(wordIndex, 1);
-
-		var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-		var type = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
-		type.data = aType;
-		os.notifyObservers(type, "b2r-abone-data-remove", aWord);
-
-	},
-
-
-
-
-  	// ********** ********* implements nsIObserver ********** **********
-
-	observe: function(aSubject, aTopic, aData){
-		var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-		switch(aTopic){
-			case "app-startup":
-				dump("b2rAboneManager\n");
-				os.addObserver(this, "profile-after-change", false);
-				os.addObserver(this, "quit-application", false);
-				break;
-			case "profile-after-change":
-				this._startup();
-				os.removeObserver(this, "profile-after-change");
-				break;
-			case "quit-application":
-				this._shutdown();
-				os.removeObserver(this, "quit-application");
-				break;
-		}
-	},
-
-
-  	// ********** ********* implements nsIClassInfo ********** **********
-
-	get classDescription() {
-		return "b2rAboneManager js component";
-	},
-	get classID() {
-		return Components.ID("{ff8a31ea-d3c1-47f1-a72b-0a2a0975d69a}");
-	},
-	get implementationLanguage() {
-		return Ci.nsIProgrammingLanguage.JAVASCRIPT;
-	},
-	get flags() {
-		return Ci.nsIClassInfo.SINGLETON;
-	},
-	get contractID() {
-    	return "@mozilla.org/b2r-abone-manager;1";
-	},
-
-	getInterfaces: function(aCount) {
-	    var interfaces = [
-			Ci.b2rIAboneManager,
-			Ci.nsIClassInfo,
-			Ci.nsIObserver,
-			Ci.nsISupports
-		];
-	    aCount.value = interfaces.length;
-    	return interfaces;
-	},
-
- 	getHelperForLanguage: function(aLanguage) {
-    	return null;
-	},
-
-
-  	// ********** ********* implements nsISupports ********** **********
-
-	QueryInterface: function(aIID){
-		if(aIID.equals(Ci.b2rIAboneManager) ||
-				aIID.equals(Ci.nsIClassInfo) ||
-				aIID.equals(Ci.nsIObserver) ||
-				aIID.equals(Ci.nsISupports)){
-			return this;
-		}
-		throw Components.results.NS_ERROR_NO_INTERFACE;
-	}
-
-};
-
-
-
-
-// ********** ********* Component Registration ********** **********
-
-var Factory = {
-
-	createInstance: function (aOuter, aIID){
-		if(aOuter != null)
-			throw Components.results.NS_ERROR_NO_AGGREGATION;
-
-		if(aIID.equals(Ci.b2rIAboneManager))
-			return this.getInstance(aIID);
-		if(aIID.equals(Ci.nsIClassInfo))
-			return this.getInstance(aIID);
-		if(aIID.equals(Ci.nsIObserver))
-			return this.getInstance(aIID);
-		if(aIID.equals(Ci.nsISupports))
-			return this.getInstance(aIID);
-
-		throw Components.results.NS_ERROR_INVALID_ARG;
-	},
-
-	getInstance: function(aIID){
-		if(!this._instance){
-			this._instance = new b2rAboneManager();
-		}
-		return this._instance.QueryInterface(aIID);
-	}
-
-};
-
-var Module = {
-
-	CONTRACTID: "@mozilla.org/b2r-abone-manager;1",
-	CID: Components.ID("{ff8a31ea-d3c1-47f1-a72b-0a2a0975d69a}"),
-	CNAME: "b2rAboneManager js component",
-
-
-	registerSelf: function(aCompMgr, aFileSpec, aLocation, aType){
-		aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
-		aCompMgr.registerFactoryLocation(this.CID, this.CNAME, this.CONTRACTID,
-											aFileSpec, aLocation, aType);
-		var categoryManager = Cc["@mozilla.org/categorymanager;1"]
-					.getService(Ci.nsICategoryManager);
-		categoryManager.addCategoryEntry("app-startup", this.CONTRACTID,
-											this.CONTRACTID, true, true);
-	},
-
-
-	unregisterSelf: function(aCompMgr, aFileSpec, aLocation){
-		aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
-
-		var categoryManager = Cc["@mozilla.org/categorymanager;1"]
-					.getService(Ci.nsICategoryManager);
-		categoryManager.deleteCategoryEntry("app-startup", this.CONTRACTID, true);
-	},
-
-
-	getClassObject: function(aCompMgr, aCID, aIID){
-		if(aCID.equals(this.CID))
-			return Factory;
-
-		if(!aIID.equals(Ci.nsIFactory))
-			throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
-		throw Components.results.NS_ERROR_NO_INTERFACE;
-	},
-
-
-	canUnload: function(aCompMgr){
-		return true;
-	}
-
-};
-
-
-function NSGetModule(aCompMgr, aFileSpec){
-	return Module;
-}
\ No newline at end of file

Modified: trunk/bbs2chreader/components/b2rGlobalService.js
===================================================================
--- trunk/bbs2chreader/components/b2rGlobalService.js	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/components/b2rGlobalService.js	2007-12-30 11:30:07 UTC (rev 297)
@@ -136,8 +136,11 @@
 		if(!this._initialized) throw Components.results.NS_ERROR_NOT_INITIALIZED;
 		return this._viewer;
 	},
+	get abone(){
+		if(!this._initialized) throw Components.results.NS_ERROR_NOT_INITIALIZED;
+		return this._abone;
+	},
 
-
 	getHttpChannel: function(aURL){
 		if(!this._initialized) throw Components.results.NS_ERROR_NOT_INITIALIZED;
 		var httpChannel;
@@ -225,25 +228,29 @@
 		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rGlobalThreadUtils.js", null);
 		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rGlobalHistory.js", null);
 		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rGlobalViewer.js", null);
+		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rAboneManager.js", null);
 
 		this._initialized = true;
 		this._io = new b2rGlobalIO();
 		this._threadUtils = new b2rGlobalThreadUtils();
 		this._history = new b2rGlobalHistory();
 		this._viewer = new b2rGlobalViewer();
+		this._abone = new b2rAboneManager();
+	},
 
-		dump("b2rGlobalService._startup()\n");
+
+	_quitApp: function(){
+		this._abone._saveAboneData();
 	},
 
-
 	_shutdown: function(){
 		this._io = null;
 		this._threadUtils = null;
 		this._history = null;
 		this._viewer = null;
+		this._abone = null;
 
 		this._initialized = false;
-		dump("b2rGlobalService._shutdown()\n");
 	},
 
 
@@ -255,12 +262,17 @@
 		switch(aTopic){
 			case "app-startup":
 				observerService.addObserver(this, "profile-after-change", false);
+				observerService.addObserver(this, "quit-application", false);
 				observerService.addObserver(this, "xpcom-shutdown", false);
 				break;
 			case "profile-after-change":
 				this._startup();
 				observerService.removeObserver(this, "profile-after-change");
 				break;
+			case "quit-application":
+				this._quitApp();
+				observerService.removeObserver(this, "quit-application");
+				break;
 			case "xpcom-shutdown":
 				this._shutdown();
 				observerService.removeObserver(this, "xpcom-shutdown");

Modified: trunk/bbs2chreader/components/b2rIGlobalService.xpt
===================================================================
(Binary files differ)

Deleted: trunk/bbs2chreader/components/idl/b2rIAboneManager.idl
===================================================================
--- trunk/bbs2chreader/components/idl/b2rIAboneManager.idl	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/components/idl/b2rIAboneManager.idl	2007-12-30 11:30:07 UTC (rev 297)
@@ -1,29 +0,0 @@
-#include "nsISupports.idl"
-
-interface nsIVariant;
-
-[scriptable, uuid(cfdf8cd6-c1b2-4d17-a82b-0616d457e647)]
-interface b2rIAboneManager : nsISupports
-{
-
-	const unsigned long ABONE_TYPE_NAME = 0;
-	const unsigned long ABONE_TYPE_MAIL = 1;
-	const unsigned long ABONE_TYPE_ID   = 2;
-	const unsigned long ABONE_TYPE_WORD = 3;
-
-
-	/**
-	 * レスが、NGワードに該当したら真を返す。引数の文字列は SJIS を渡すこと
-	 * @param aName 名前
-	 * @param aMail メールアドレス
-	 * @param aID ID
-	 * @param aMsg レス本文
-	 * @return boolean 該当したら真
-	 */
-	boolean shouldAbone(in AString aName, in AString aMail, in AString aID, in AString aMsg);
-
-	nsIVariant getAboneData(in unsigned long aType);
-
-	boolean addAbone(in AString aWord, in unsigned long aType);
-	boolean removeAbone(in AString aWord, in unsigned long aType);
-};
\ No newline at end of file

Modified: trunk/bbs2chreader/components/idl/b2rIGlobalService.idl
===================================================================
--- trunk/bbs2chreader/components/idl/b2rIGlobalService.idl	2007-12-29 15:44:29 UTC (rev 296)
+++ trunk/bbs2chreader/components/idl/b2rIGlobalService.idl	2007-12-30 11:30:07 UTC (rev 297)
@@ -6,8 +6,8 @@
 interface nsIURL;
 interface nsIHttpChannel;
 interface mozIStorageConnection;
+interface nsIVariant;
 
-
 [scriptable, uuid(fe8fed8e-6449-4b68-8899-026f806be131)]
 interface b2rIGlobalIO : nsISupports
 {
@@ -112,6 +112,33 @@
 };
 
 
+[scriptable, uuid(cfdf8cd6-c1b2-4d17-a82b-0616d457e647)]
+interface b2rIAboneManager : nsISupports
+{
+
+	const unsigned long ABONE_TYPE_NAME = 0;
+	const unsigned long ABONE_TYPE_MAIL = 1;
+	const unsigned long ABONE_TYPE_ID   = 2;
+	const unsigned long ABONE_TYPE_WORD = 3;
+
+
+	/**
+	 * レスが、NGワードに該当したら真を返す。引数の文字列は SJIS を渡すこと
+	 * @param aName 名前
+	 * @param aMail メールアドレス
+	 * @param aID ID
+	 * @param aMsg レス本文
+	 * @return boolean 該当したら真
+	 */
+	boolean shouldAbone(in AString aName, in AString aMail, in AString aID, in AString aMsg);
+
+	nsIVariant getAboneData(in unsigned long aType);
+
+	boolean addAbone(in AString aWord, in unsigned long aType);
+	boolean removeAbone(in AString aWord, in unsigned long aType);
+};
+
+
 [scriptable, uuid(b7823d3f-eb1c-44a2-b178-b3a8f64fa371)]
 interface b2rIGlobalService : nsISupports
 {
@@ -160,6 +187,7 @@
 	readonly attribute b2rIGlobalThreadUtils threadUtils;
 	readonly attribute b2rIGlobalHistory history;
 	readonly attribute b2rIGlobal2chViewer viewer;
+	readonly attribute b2rIAboneManager abone;
 
 	/**
 	 * プロクシや UserAgent などの設定を施した nsIHttpChannel を返す


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