OSDN Git Service

Add an update option to uri_opener.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 29 Aug 2006 16:32:32 +0000 (01:32 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 29 Aug 2006 16:32:32 +0000 (01:32 +0900)
src/Hage1/board_window.py
src/Hage1/dbus_object.py
src/Hage1/thread_window.py
src/Hage1/uri_opener.py

index adbdb02..b681771 100644 (file)
@@ -24,7 +24,7 @@ import time
 import gobject
 
 import board_data
-import thread_window
+import uri_opener
 import misc
 from threadlistmodel import ThreadListModel
 from BbsType import bbs_type_judge_uri
@@ -35,7 +35,7 @@ GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
 GLADE_FILENAME = "board_window.glade"
 
-def open_board(uri):
+def open_board(uri, update=False):
     if not uri:
         raise ValueError, "parameter must not be empty"
 
@@ -43,10 +43,12 @@ def open_board(uri):
     if winwrap:
         # already opened
         winwrap.window.present()
-        pass
+        if update:
+            winwrap.load(update)
     else:
-        win_wrap = WinWrap(uri)
-        session.window_created(uri, win_wrap)
+        winwrap = WinWrap(uri)
+        session.window_created(uri, winwrap)
+        winwrap.load(update)
 
 
 class WinWrap:
@@ -103,9 +105,6 @@ class WinWrap:
                   "on_popup_menu_open_activate": self.on_open_thread}
         self.widget_tree.signal_autoconnect(sigdic)
 
-        t = board_data.LoadLocal(self.bbs, self.board, self.update_datastore)
-        t.start()
-
     def updated_thread_highlight(self, column, cell, model, iter):
 
         def is_updated_thread():
@@ -193,8 +192,14 @@ class WinWrap:
             iter, ThreadListModel.column_names.index("title"))
         print thread + ':"' + title + '"', "activated"
 
+        res = model.get_value(iter, ThreadListModel.column_names.index("res"))
+        lineCount = model.get_value(
+            iter, ThreadListModel.column_names.index("lineCount"))
+
+        update = res > lineCount
+
         bbs_type_for_thread = self.bbs_type.clone_with_thread(thread)
-        thread_window.open_thread(bbs_type_for_thread.get_thread_uri())
+        uri_opener.open_uri(bbs_type_for_thread.get_thread_uri(), update)
 
     def on_treeview_button_press_event(self, widget, event):
         if event.button == 3:
@@ -279,3 +284,18 @@ class WinWrap:
             except ValueError:
                 idx_dic["lastModified"] = 0
             model.modify_row(idx_dic)
+
+    def load(self, update=False):
+        sbj_path = misc.get_board_subjecttxt_path(
+            self.bbs_type.bbs_type, self.bbs_type.board)
+        sbj_exists = os.path.exists(sbj_path)
+
+        if update or not sbj_exists:
+            t = board_data.GetRemote(
+                self.bbs, self.board, self.bbs_type.get_subject_txt_uri(),
+                self.update_datastore)
+            t.start()
+        else:
+            t = board_data.LoadLocal(
+                self.bbs, self.board, self.update_datastore)
+            t.start()
index b6038e9..c0a4533 100644 (file)
@@ -30,5 +30,5 @@ class DBusHage1Object(dbus.service.Object):
         dbus.service.Object.__init__(self, bus_name, object_path)
 
     @dbus.service.method(dbus_interface_name)
-    def open_uri(self, uri):
-        uri_opener.open_uri(uri)
+    def open_uri(self, uri, update=False):
+        uri_opener.open_uri(uri, update)
index 94e2b2b..b251af7 100644 (file)
@@ -42,7 +42,7 @@ GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
 GLADE_FILENAME = "thread_window.glade"
 
-def open_thread(uri):
+def open_thread(uri, update=False):
     if not uri:
         raise ValueError, "parameter must not be empty"
 
@@ -56,9 +56,12 @@ def open_thread(uri):
     if winwrap:
         # already opened
         winwrap.window.present()
+        if update:
+            winwrap.load(update)
     else:
         winwrap = WinWrap(bbs_type.uri)  # pass original uri
         session.window_created(uri, winwrap)
+        winwrap.load(update)
 
     # jump to the res if necessary.
     winwrap.jump_to_res(bbs_type.uri)
@@ -111,8 +114,6 @@ class WinWrap:
         self.textview.connect("visibility-notify-event",
                               self.on_visibility_notify_event)
 
-        self.load_dat()
-
     def on_compose_clicked(self, widget):
         import submit_window
         submit_window.open(self.bbs_type.get_thread_uri())
@@ -404,3 +405,12 @@ class WinWrap:
                 mark = self.textbuffer.get_mark(resnum)
                 if mark:
                     self.textview.scroll_to_mark(mark, 0, True, 0, 0)
+
+    def load(self, update=False):
+        dat_path = misc.get_thread_dat_path(
+            self.bbs_type.bbs_type, self.bbs_type.board, self.bbs_type.thread)
+        dat_exists = os.path.exists(dat_path)
+        if update or not dat_exists:
+            self.update()
+        else:
+            self.load_dat()
index 41b81d5..a279bc8 100644 (file)
@@ -19,11 +19,11 @@ import board_window
 import thread_window
 from BbsType import bbs_type_judge_uri
 
-def open_uri(uri):
+def open_uri(uri, update=False):
     bbs_type = bbs_type_judge_uri.get_type(uri)
     if bbs_type.is_board():
-        board_window.open_board(uri)
+        board_window.open_board(uri, update)
     elif bbs_type.is_thread():
-        thread_window.open_thread(uri)
+        thread_window.open_thread(uri, update)
     else:
         print "the uri represents neither board nor thread: ", uri