OSDN Git Service

Make bbs type little massive.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 8 Sep 2006 03:49:17 +0000 (12:49 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 8 Sep 2006 03:49:17 +0000 (12:49 +0900)
src/FukuiNoNamari/BbsType/bbs_type_2ch.py
src/FukuiNoNamari/BbsType/bbs_type_base.py
src/FukuiNoNamari/board_window.py
src/FukuiNoNamari/submit_window.py
src/FukuiNoNamari/thread_window.py

index b4c6a22..d9916a0 100644 (file)
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 import re
-import copy
+import codecs
 
 from bbs_type_exception import BbsTypeError
 from bbs_type_base import BaseType
 
+# default name for morningcoffee
+moco_name = u'\u540d\u7121\u3057\u52df\u96c6\u4e2d\u3002\u3002\u3002'
 
 _base_reg_expr = re.compile("http://(?P<host>[^./]+\.2ch\.net)/(?P<board>[^/]+)/$")
 _cgi_reg_expr = re.compile("http://(?P<host>[^./]+\.2ch\.net)/test/read.cgi/(?P<board>[^/]+)/(?P<thread>[^/]+)/.*")
@@ -31,6 +33,19 @@ class Type2ch(BaseType):
     _base_reg = _base_reg_expr
     _cgi_reg = _cgi_reg_expr
 
+    def is_same_board(self, another):
+        return self.bbs_type == another.bbs_type \
+               and self.board == another.board
+
+    def set_extra_post(self, post_dict):
+        post_dict["hana"] = "mogera"
+
+        if self.board == "morningcoffee":
+            if "FROM" not in post_dict or not post_dict["FROM"]:
+                post_dict["FROM"] = moco_name.encode("cp932", "replace")
+
+        return post_dict
+
     def get_board_dir_path(self):
         """Returns board dir path from logs dir downward, not full path"""
 
index e0c5c6f..36fe32f 100644 (file)
@@ -59,6 +59,11 @@ class BaseType:
     def is_thread(self):
         return self.thread
 
+    def is_same_board(self, another):
+        return self.bbs_type == another.bbs_type \
+               and self.host == another.host \
+               and self.board == another.board
+
     def clone_with_thread(self, thread):
         if not thread:
             raise ValueError, "parameter must not be empty"
@@ -84,6 +89,9 @@ class BaseType:
         return "http://" + self.host + "/test/read.cgi/" + \
                   self.board + "/" + self.thread + "/"
 
+    def set_extra_post(self, post_dict):
+        return post_dict
+
     def get_board_dir_path(self):
         """Returns board dir path from logs dir downward, not full path"""
 
index f8154e5..c6ca793 100644 (file)
@@ -60,17 +60,13 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
 
         self.bbs_type = bbs_type_judge_uri.get_type(uri)
         board_data.BoardData.__init__(self, self.bbs_type)
-        self.bbs = self.bbs_type.bbs_type
-        self.host = self.bbs_type.host
-        self.board = self.bbs_type.board
-        self.uri = self.bbs_type.uri
         
         glade_path = os.path.join(GLADE_DIR, GLADE_FILENAME)
         self.widget_tree = gtk.glade.XML(glade_path)
 
         self.window = self.widget_tree.get_widget("board_window")
 
-        self.window.set_title(self.uri)
+        self.window.set_title(self.bbs_type.uri)
 
         self.treeview = self.widget_tree.get_widget("treeview")
         self.treeview.set_model(ThreadListModel())
@@ -321,8 +317,8 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
 
         # nothing to do if thread_uri does not belong to this board.
         bbs_type = bbs_type_judge_uri.get_type(thread_uri)
-        if bbs_type.bbs_type != self.bbs \
-           or bbs_type.board != self.board or not bbs_type.is_thread():
+        if not bbs_type.is_thread() \
+               or not bbs_type.is_same_board(self.bbs_type):
             return
 
         thread = bbs_type.thread
index e46a4c5..f64426f 100644 (file)
@@ -113,7 +113,6 @@ class WinWrap:
         self.post_dict["bbs"] = self.bbs_type.board
         self.post_dict["key"] = self.bbs_type.thread
         self.post_dict["time"] = str(int(time.time()))
-        self.post_dict["hana"] = "mogera"
         self.post_dict["submit"] = u"\u66f8\u304d\u8fbc\u3080".encode(
             "cp932", "replace")
 
@@ -131,10 +130,6 @@ class WinWrap:
 
     def on_submit_activate(self, widget):
         name = self.entry_name.get_text()
-        if self.bbs_type.bbs_type == "2ch" \
-               and self.bbs_type.board == "morningcoffee" \
-               and not name:
-            name = u'\u540d\u7121\u3057\u52df\u96c6\u4e2d\u3002\u3002\u3002'
         mail = self.entry_mail.get_text()
         msg = self.textbuffer.get_text(
             self.textbuffer.get_start_iter(), self.textbuffer.get_end_iter())
@@ -143,6 +138,8 @@ class WinWrap:
         self.post_dict["mail"] = mail.encode("cp932", "replace")
         self.post_dict["MESSAGE"] = msg.encode("cp932", "replace")
 
+        self.post_dict = self.bbs_type.set_extra_post(self.post_dict)
+
         self.do_submit()
 
     def do_submit(self):
index b32f7bc..a5e2797 100644 (file)
@@ -86,11 +86,6 @@ class WinWrap(winwrapbase.WinWrapBase):
         if not self.bbs_type.is_thread():
             raise bbs_type_exception.BbsTypeError, \
                   "the uri does not represent thread: " + uri
-        self.bbs = self.bbs_type.bbs_type
-        self.board = self.bbs_type.board
-        self.thread = self.bbs_type.thread
-        self.host = self.bbs_type.host
-        self.uri = self.bbs_type.uri
         self.size = 0
         self.num = 0
         self.title = ""