OSDN Git Service

Add thread log delete.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Thu, 14 Sep 2006 07:35:22 +0000 (16:35 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 15 Sep 2006 00:22:50 +0000 (09:22 +0900)
src/FukuiNoNamari/board_window.py
src/FukuiNoNamari/thread_window.py
src/data/board_window.glade
src/data/thread_window.glade

index 1dbd770..962d074 100644 (file)
@@ -123,6 +123,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
                   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_popup_menu_open_activate": self.on_open_thread}
         self.widget_tree.signal_autoconnect(sigdic)
 
@@ -280,6 +281,32 @@ 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_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)
index c4ce1b3..65fcfe3 100644 (file)
@@ -30,6 +30,7 @@ import gobject
 import threading
 import gconf
 import traceback
+import os
 
 import misc
 from misc import FileWrap, ThreadInvoker
@@ -101,11 +102,8 @@ class WinWrap(winwrapbase.WinWrapBase):
         self.statusbar = self.widget_tree.get_widget("appbar")
         self.textview = self.widget_tree.get_widget("textview")
         self.textview.drag_dest_unset()
-        self.textbuffer = self.textview.get_buffer()
-        self.enditer = self.textbuffer.get_end_iter()
-        self.boldtag = self.textbuffer.create_tag(weight=pango.WEIGHT_BOLD)
-        self.leftmargintag = self.textbuffer.create_tag()
-        self.leftmargintag.set_property("left-margin", 20)
+
+        self.initialize_buffer()
 
         sigdic = {"on_refresh_activate": self.update,
                   "on_compose_activate": self.on_compose_clicked,
@@ -115,6 +113,7 @@ class WinWrap(winwrapbase.WinWrapBase):
                   "on_close_activate": self.on_close_activate,
                   "on_quit_activate": self.on_quit_activate,
                   "on_show_board_activate": self.on_show_board_activate,
+                  "on_delete_activate": self.on_delete_activate,
                   "on_thread_window_delete_event":
                   self.on_thread_window_delete_event,
                   "on_thread_window_destroy": self.on_thread_window_destroy}
@@ -130,6 +129,14 @@ class WinWrap(winwrapbase.WinWrapBase):
 
         self.created()
 
+    def initialize_buffer(self):
+        self.textbuffer = gtk.TextBuffer()
+        self.textview.set_buffer(self.textbuffer)
+        self.enditer = self.textbuffer.get_end_iter()
+        self.boldtag = self.textbuffer.create_tag(weight=pango.WEIGHT_BOLD)
+        self.leftmargintag = self.textbuffer.create_tag()
+        self.leftmargintag.set_property("left-margin", 20)
+
     def destroy(self):
         self.save()
         self.window.destroy()
@@ -243,6 +250,23 @@ class WinWrap(winwrapbase.WinWrapBase):
     def on_show_board_activate(self, widget):
         board_window.open_board(self.bbs_type.get_uri_base())
 
+    def on_delete_activate(self, widget):
+        try:
+            dat_path = misc.get_thread_dat_path(self.bbs_type)
+            os.remove(dat_path)
+        except OSError:
+            traceback.print_exc()
+        try:
+            idx_path = misc.get_thread_idx_path(self.bbs_type)
+            os.remove(idx_path)
+        except OSError:
+            traceback.print_exc()
+        try:
+            states_path = misc.get_thread_states_path(self.bbs_type)
+            os.remove(states_path)
+        except OSError:
+            traceback.print_exc()
+
     def http_get_dat(self, on_get_res):
         datfile_url = self.bbs_type.get_dat_uri()
 
@@ -310,6 +334,12 @@ class WinWrap(winwrapbase.WinWrapBase):
                 gobject.idle_add(create_mark)
 
             line_count = datfile.get_dat_line_count(self.bbs_type)
+            if line_count < self.num:
+                self.num = 0
+                self.size = 0
+
+                gobject.idle_add(self.initialize_buffer)
+
             if line_count > self.num:
                 datfile.load_dat_partly(
                     self.bbs_type, self.append_rawres_to_buffer, self.num+1)
index 38bb871..4fa5f9d 100644 (file)
                          <accelerator key="F" modifiers="GDK_CONTROL_MASK" signal="activate"/>
                        </widget>
                      </child>
+
+                     <child>
+                       <widget class="GtkSeparatorMenuItem" id="separator4">
+                         <property name="visible">True</property>
+                       </widget>
+                     </child>
+
+                     <child>
+                       <widget class="GtkImageMenuItem" id="delete">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">_Delete Thread Log</property>
+                         <property name="use_underline">True</property>
+                         <signal name="activate" handler="on_delete_activate" last_modification_time="Thu, 14 Sep 2006 07:21:17 GMT"/>
+
+                         <child internal-child="image">
+                           <widget class="GtkImage" id="image20">
+                             <property name="visible">True</property>
+                             <property name="stock">gtk-delete</property>
+                             <property name="icon_size">1</property>
+                             <property name="xalign">0.5</property>
+                             <property name="yalign">0.5</property>
+                             <property name="xpad">0</property>
+                             <property name="ypad">0</property>
+                           </widget>
+                         </child>
+                       </widget>
+                     </child>
                    </widget>
                  </child>
                </widget>
                          <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image17">
+                           <widget class="GtkImage" id="image21">
                              <property name="visible">True</property>
                              <property name="stock">gtk-refresh</property>
                              <property name="icon_size">1</property>
                  <property name="homogeneous">True</property>
                </packing>
              </child>
+
+             <child>
+               <widget class="GtkToolButton" id="toolbutton_delete">
+                 <property name="visible">True</property>
+                 <property name="stock_id">gtk-delete</property>
+                 <property name="visible_horizontal">True</property>
+                 <property name="visible_vertical">True</property>
+                 <property name="is_important">False</property>
+                 <signal name="clicked" handler="on_delete_activate" last_modification_time="Thu, 14 Sep 2006 07:02:05 GMT"/>
+               </widget>
+               <packing>
+                 <property name="expand">False</property>
+                 <property name="homogeneous">True</property>
+               </packing>
+             </child>
            </widget>
          </child>
        </widget>
       <signal name="activate" handler="on_popup_menu_open_activate" last_modification_time="Wed, 09 Aug 2006 23:44:38 GMT"/>
     </widget>
   </child>
+
+  <child>
+    <widget class="GtkSeparatorMenuItem" id="separator3">
+      <property name="visible">True</property>
+    </widget>
+  </child>
+
+  <child>
+    <widget class="GtkImageMenuItem" id="delete">
+      <property name="visible">True</property>
+      <property name="label" translatable="yes">_Delete</property>
+      <property name="use_underline">True</property>
+      <signal name="activate" handler="on_delete_activate" last_modification_time="Thu, 14 Sep 2006 06:54:58 GMT"/>
+
+      <child internal-child="image">
+       <widget class="GtkImage" id="image18">
+         <property name="visible">True</property>
+         <property name="stock">gtk-delete</property>
+         <property name="icon_size">1</property>
+         <property name="xalign">0.5</property>
+         <property name="yalign">0.5</property>
+         <property name="xpad">0</property>
+         <property name="ypad">0</property>
+       </widget>
+      </child>
+    </widget>
+  </child>
 </widget>
 
 </glade-interface>
index ed8a48f..96a7154 100644 (file)
@@ -52,7 +52,7 @@
                          <signal name="activate" handler="on_show_board_activate" last_modification_time="Mon, 21 Aug 2006 03:30:53 GMT"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image5">
+                           <widget class="GtkImage" id="image10">
                              <property name="visible">True</property>
                              <property name="stock">gtk-go-up</property>
                              <property name="icon_size">1</property>
@@ -74,7 +74,7 @@
                          <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image6">
+                           <widget class="GtkImage" id="image11">
                              <property name="visible">True</property>
                              <property name="stock">gnome-stock-mail-new</property>
                              <property name="icon_size">1</property>
                      </child>
 
                      <child>
+                       <widget class="GtkImageMenuItem" id="delete">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">_Delete Log</property>
+                         <property name="use_underline">True</property>
+                         <signal name="activate" handler="on_delete_activate" last_modification_time="Thu, 14 Sep 2006 04:44:02 GMT"/>
+
+                         <child internal-child="image">
+                           <widget class="GtkImage" id="image12">
+                             <property name="visible">True</property>
+                             <property name="stock">gtk-delete</property>
+                             <property name="icon_size">1</property>
+                             <property name="xalign">0.5</property>
+                             <property name="yalign">0.5</property>
+                             <property name="xpad">0</property>
+                             <property name="ypad">0</property>
+                           </widget>
+                         </child>
+                       </widget>
+                     </child>
+
+                     <child>
                        <widget class="GtkSeparatorMenuItem" id="separator2">
                          <property name="visible">True</property>
                        </widget>
                          <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image7">
+                           <widget class="GtkImage" id="image13">
                              <property name="visible">True</property>
                              <property name="stock">gtk-refresh</property>
                              <property name="icon_size">1</property>
                  <property name="homogeneous">True</property>
                </packing>
              </child>
+
+             <child>
+               <widget class="GtkToolButton" id="toolbutton_delete">
+                 <property name="visible">True</property>
+                 <property name="stock_id">gtk-delete</property>
+                 <property name="visible_horizontal">True</property>
+                 <property name="visible_vertical">True</property>
+                 <property name="is_important">False</property>
+                 <signal name="clicked" handler="on_delete_activate" last_modification_time="Thu, 14 Sep 2006 04:42:06 GMT"/>
+               </widget>
+               <packing>
+                 <property name="expand">False</property>
+                 <property name="homogeneous">True</property>
+               </packing>
+             </child>
            </widget>
          </child>
        </widget>