OSDN Git Service

Add bookmark.
[fukui-no-namari/fukui-no-namari.git] / src / FukuiNoNamari / board_window.py
index 1647a9a..42097be 100644 (file)
@@ -34,6 +34,8 @@ import config
 import session
 import winwrapbase
 from misc import ThreadInvoker
+import bookmark_list
+import bookmark_window
 
 GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
@@ -60,17 +62,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())
@@ -125,6 +123,12 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
                   "on_filter_activate": self.on_filter_activate,
                   "on_toolbutton_filterbar_close_clicked":
                   self.on_toolbutton_filterbar_close_clicked,
+                  "on_button_filterbar_clear_clicked":
+                  self.on_button_filterbar_clear_clicked,
+                  "on_delete_activate": self.on_delete_activate,
+                  "on_manage_bookmarks_activate": \
+                  self.on_manage_bookmarks_activate,
+                  "on_add_bookmark_activate": self.on_add_bookmark_activate,
                   "on_popup_menu_open_activate": self.on_open_thread}
         self.widget_tree.signal_autoconnect(sigdic)
 
@@ -181,6 +185,13 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
     def on_toolbutton_filterbar_close_clicked(self, widget):
         self.filterbar.hide()
 
+    def on_button_filterbar_clear_clicked(self, widget):
+        self.entry_filterbar.set_text("")
+        model = self.treeview.get_model()
+        if model:
+            model.set_filter_func(None)
+            model.refilter()
+
     def updated_thread_highlight(self, column, cell, model, iter):
 
         def is_updated_thread():
@@ -275,6 +286,39 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
         bbs_type_for_thread = self.bbs_type.clone_with_thread(thread)
         uri_opener.open_uri(bbs_type_for_thread.get_thread_uri(), update)
 
+    def on_add_bookmark_activate(self, widget):
+        bookmark_list.bookmark_list.add_bookmark_with_edit(
+            uri=self.bbs_type.uri)
+
+    def on_manage_bookmarks_activate(self, widget):
+        bookmark_window.open()
+
+    def on_delete_activate(self, widget):
+        selection = self.treeview.get_selection()
+        model, iter = selection.get_selected()
+        if not iter:
+            return
+        thread = model.get_value(
+            iter, ThreadListModel.column_names.index("id"))
+        
+        bbs_type_for_thread = self.bbs_type.clone_with_thread(thread)
+
+        dat_path = misc.get_thread_dat_path(bbs_type_for_thread)
+        try:
+            os.remove(dat_path)
+        except OSError:
+            traceback.print_exc()
+        idx_path = misc.get_thread_idx_path(bbs_type_for_thread)
+        try:
+            os.remove(idx_path)
+        except OSError:
+            traceback.print_exc()
+        states_path = misc.get_thread_states_path(bbs_type_for_thread)
+        try:
+            os.remove(states_path)
+        except OSError:
+            traceback.print_exc()
+
     def on_treeview_button_press_event(self, widget, event):
         if event.button == 3:
             x = int(event.x)
@@ -321,8 +365,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
@@ -350,8 +394,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
             self.merge_remote_subjecttxt(datalist)
             gobject.idle_add(self.update_datastore, datalist)
 
-        sbj_path = misc.get_board_subjecttxt_path(
-            self.bbs_type.bbs_type, self.bbs_type.board)
+        sbj_path = misc.get_board_subjecttxt_path(self.bbs_type)
         sbj_exists = os.path.exists(sbj_path)
 
         if update or not sbj_exists:
@@ -363,8 +406,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
 
     def save(self):
         try:
-            states_path = misc.get_board_states_path(
-                self.bbs_type.bbs_type, self.bbs_type.board)
+            states_path = misc.get_board_states_path(self.bbs_type)
             dirname = os.path.dirname(states_path)
 
             # save only if board dir exists.
@@ -431,8 +473,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
             except:
                 traceback.print_exc()
 
-            states_path = misc.get_board_states_path(
-                self.bbs_type.bbs_type, self.bbs_type.board)
+            states_path = misc.get_board_states_path(self.bbs_type)
             if os.path.exists(states_path):
                 sort_column_name = "num"
                 sort_reverse = False
@@ -498,10 +539,13 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
             self.window.set_default_size(window_width, window_height)
 
             if not toolbar_visible:
-                gobject.idle_add(self.toolbar.parent.hide)
+                gobject.idle_add(self.toolbar.parent.hide,
+                                 priority=gobject.PRIORITY_HIGH)
             if not statusbar_visible:
-                gobject.idle_add(self.statusbar.hide)
+                gobject.idle_add(self.statusbar.hide,
+                                 priority=gobject.PRIORITY_HIGH)
             if not filterbar_visible:
-                gobject.idle_add(self.filterbar.hide)
+                gobject.idle_add(self.filterbar.hide,
+                                 priority=gobject.PRIORITY_HIGH)
         except:
             traceback.print_exc()