OSDN Git Service

Add jumping to the res.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 29 Aug 2006 15:07:22 +0000 (00:07 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 29 Aug 2006 15:07:22 +0000 (00:07 +0900)
src/Hage1/thread_window.py

index 99d3322..94e2b2b 100644 (file)
@@ -24,6 +24,8 @@ import codecs
 import re
 import pango
 import urllib2
+import urlparse
+import gnome
 
 import misc
 import datfile
@@ -31,6 +33,7 @@ import barehtmlparser
 import idxfile
 import session
 import board_window
+import uri_opener
 from http_sub import HTTPRedirectHandler302
 from BbsType import bbs_type_judge_uri
 from BbsType import bbs_type_exception
@@ -53,10 +56,12 @@ def open_thread(uri):
     if winwrap:
         # already opened
         winwrap.window.present()
-        pass
     else:
-        win_wrap = WinWrap(bbs_type.uri)  # pass original uri
-        session.window_created(uri, win_wrap)
+        winwrap = WinWrap(bbs_type.uri)  # pass original uri
+        session.window_created(uri, winwrap)
+
+    # jump to the res if necessary.
+    winwrap.jump_to_res(bbs_type.uri)
 
 
 class WinWrap:
@@ -139,14 +144,16 @@ class WinWrap:
         return False
 
     def on_link_clicked(self, widget, href):
-        if href.startswith("http://"):
-            from BbsType import bbs_type_exception
-            import uri_opener
-            try:
-                uri_opener.open_uri(href)
-            except bbs_type_exception.BbsTypeError:
-                import gnome
-                gnome.url_show(href)
+
+        if not href.startswith("http://"):
+            # maybe a relative uri.
+            href = urlparse.urljoin(self.bbs_type.get_uri_base(), href)
+
+        try:
+            uri_opener.open_uri(href)
+        except bbs_type_exception.BbsTypeError:
+            # not supported, show with the web browser.
+            gnome.url_show(href)
 
     def on_motion_notify_event(self, widget, event):
         x, y = widget.window_to_buffer_coords(
@@ -304,9 +311,15 @@ class WinWrap:
         if self.title:
             self.window.set_title(self.title)
 
+        self.textbuffer.create_mark("1", self.enditer, True)
+
         datfile.load_dat(self.bbs, self.board, self.thread,
                          self.append_rawres_to_buffer)
-        self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)
+        if self.num > 0:
+            # jump to the last res.
+            mark = self.textbuffer.get_mark(str(self.num+1))
+            if mark:
+                self.textview.scroll_to_mark(mark, 0)
 
 
     def append_rawres_to_buffer(self, line):
@@ -317,7 +330,10 @@ class WinWrap:
             self.num, name, mail, date, msg)
 
         datfile.split_line_to_elems(line.decode("cp932", "replace"), h)
-        
+
+        # for next res
+        self.textbuffer.create_mark(str(self.num+1), self.enditer, True)
+
     def reselems_to_buffer(self, num, name, mail, date, msg):
         p = barehtmlparser.BareHTMLParser(self.untiedata_to_buffer)
         # number
@@ -377,3 +393,14 @@ class WinWrap:
             else:
                 self.textbuffer.insert_with_tags(
                     self.enditer, data, self.leftmargintag)
+
+    def jump_to_res(self, uri):
+        strict_uri = self.bbs_type.get_thread_uri()
+        if uri != strict_uri and uri.startswith(strict_uri):
+            resnum = uri[len(strict_uri):]
+            match = re.match("\d+", resnum)
+            if match:
+                resnum = match.group()
+                mark = self.textbuffer.get_mark(resnum)
+                if mark:
+                    self.textview.scroll_to_mark(mark, 0, True, 0, 0)