1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 from bookmark_core import Bookmark
29 from bookmark_editwindow import BookmarkEditWindow
30 from BbsType import bbs_type_exception
37 GLADE_FILENAME = "bookmark_window.glade"
40 winwrap = session.get_window(WinWrap.uri)
43 winwrap.window.present()
48 class WinWrap(winwrapbase.WinWrapBase):
50 uri = "namari://bookmarks-manager"
53 self.bookmarklist = bookmark_list.bookmark_list
54 self.bookmarklist.set_view(self)
56 glade_path = os.path.join(config.glade_dir, GLADE_FILENAME)
57 self.widget_tree = gtk.glade.XML(glade_path)
58 self.window = self.widget_tree.get_widget("window_bookmark")
59 self.window.connect("destroy", self.on_destroy)
60 self.treeview_categories = self.widget_tree.get_widget(
61 "treeview_categories")
62 self.treeview_categories.connect(
63 "cursor-changed", self.on_treeview_categories_cursor_changed)
64 self.treeview_bookmarks = self.widget_tree.get_widget(
66 self.treeview_bookmarks.connect(
67 "row-activated", self.on_treeview_bookmarks_row_activated)
68 self.treeview_bookmarks.connect(
69 "cursor-changed", self.on_treeview_bookmarks_cursor_changed)
70 self.treeview_bookmarks.connect(
72 self.on_treeview_bookmarks_button_press_event)
73 self.statusbar = self.widget_tree.get_widget("statusbar")
75 self.statusbar.get_context_id("bookmarks"), "Ready.")
76 self.menu_bookmark = self.widget_tree.get_widget("menu_bookmark")
78 self.widget_tree.signal_autoconnect(self)
80 renderer = gtk.CellRendererText()
82 treeviewcolumn = gtk.TreeViewColumn("category", renderer, text=0)
83 treeviewcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
84 self.treeview_categories.append_column(treeviewcolumn)
86 treeviewcolumn = gtk.TreeViewColumn("bookmark", renderer, text=0)
87 treeviewcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
88 self.treeview_bookmarks.append_column(treeviewcolumn)
90 self.treeview_categories.set_fixed_height_mode(True)
91 self.treeview_bookmarks.set_fixed_height_mode(True)
93 self.treeview_categories.set_model(gtk.ListStore(str, int))
94 self.treeview_bookmarks.set_model(gtk.ListStore(str, object))
96 self.current_category = ""
97 self.current_category_type = 0
99 self.update_categories()
103 def on_destroy(self, widget):
110 self.bookmarklist.set_view(None)
111 winwrapbase.WinWrapBase.destroyed(self)
114 self.window.destroy()
116 def on_treeview_categories_cursor_changed(self, widget):
117 selection = self.treeview_categories.get_selection()
118 model, iter = selection.get_selected()
120 category = model.get_value(iter, 0)
121 category_type = model.get_value(iter, 1)
122 if category and category != self.current_category:
123 self.update_bookmarks(category, category_type)
125 def _get_selected_bookmark(self):
126 selection = self.treeview_bookmarks.get_selection()
127 model, iter = selection.get_selected()
129 return model.get_value(iter, 1)
131 def on_treeview_bookmarks_cursor_changed(self, widget):
132 bookmark = self._get_selected_bookmark()
134 self.statusbar.pop(self.statusbar.get_context_id("bookmarks"))
136 self.statusbar.get_context_id("bookmarks"), bookmark.uri)
138 def on_treeview_bookmarks_row_activated(self, widget, path, column):
139 model = self.treeview_bookmarks.get_model()
141 iter = model.get_iter(path)
143 self._open_bookmark(model.get_value(iter, 1))
145 def on_treeview_bookmarks_button_press_event(self, widget, event):
146 if event.button == 3:
150 pthinfo = widget.get_path_at_pos(x, y)
151 if pthinfo is not None:
152 path, col, cellx, celly = pthinfo
154 widget.set_cursor(path, col, 0)
155 self.menu_bookmark.popup(None, None, None, event.button, time)
158 def on_update_bbsmenu(self, widget):
159 self.bookmarklist.update_bbsmenu()
160 self.update_categories()
162 def _open_bookmark(self, bookmark):
164 uri_opener.open_uri(bookmark.uri)
165 except bbs_type_exception.BbsTypeError:
166 self._open_bookmark_with_web_browser(bookmark)
168 def _open_bookmark_with_web_browser(self, bookmark):
169 gnome.url_show(bookmark.uri)
171 def update_bookmarks(self, category, category_type):
172 if category_type == 0:
173 bookmarks = self.bookmarklist.get_bookmark_list_in_category(
176 bookmarks = self.bookmarklist.get_non_category_bookmark()
178 model = self.treeview_bookmarks.get_model()
181 for bookmark in bookmarks:
182 model.append([bookmark.name, bookmark])
183 self.treeview_bookmarks.set_model(model)
185 self.current_category = category
186 self.current_category_type = category_type
188 category_model = self.treeview_categories.get_model()
190 for row in category_model:
191 text = row.model.get_value(row.iter, 0)
192 cat_type = row.model.get_value(row.iter, 1)
193 if text == category and cat_type == category_type:
194 selection = self.treeview_categories.get_selection()
195 selection.select_iter(row.iter)
196 self.treeview_categories.scroll_to_cell(row.path)
199 self.statusbar.pop(self.statusbar.get_context_id("bookmarks"))
201 def update_categories(self):
202 model = self.treeview_categories.get_model()
204 categories = self.bookmarklist.get_category_list()
205 model.append(["Non Category", 1])
206 for category in categories:
207 model.append([category, 0])
208 self.treeview_categories.set_model(model)
210 if self.current_category:
211 self.update_bookmarks(self.current_category,
212 self.current_category_type)
214 self.update_bookmarks("", 0)
216 def on_editbookmark_complete(self, old_bookmark, new_bookmark):
218 changed = changed or old_bookmark.name != new_bookmark.name
219 changed = changed or old_bookmark.uri != new_bookmark.uri
220 changed = changed or \
221 len(old_bookmark.categories) != len(new_bookmark.categories)
223 for cat, kat in itertools.izip(old_bookmark.categories,
224 new_bookmark.categories):
225 if cat not in new_bookmark.categories:
228 if kat not in old_bookmark.categories:
232 old_bookmark.name = new_bookmark.name
233 old_bookmark.uri = new_bookmark.uri
234 old_bookmark.categories = new_bookmark.categories
235 self.update_categories()
236 self.bookmarklist.save()
240 def on_newbookmark_complete(self, bookmark):
241 self.bookmarklist.add_new_bookmark(bookmark)
242 self.update_categories()
246 def on_new_activate(self, widget):
247 BookmarkEditWindow(self.on_newbookmark_complete)
249 def on_open_activate(self, widget):
250 bookmark = self._get_selected_bookmark()
252 self._open_bookmark(bookmark)
254 def on_open_web_activate(self, widget):
255 bookmark = self._get_selected_bookmark()
257 self._open_bookmark_with_web_browser(bookmark)
259 def on_properties_activate(self, widget):
260 bookmark = self._get_selected_bookmark()
263 lambda new_bookmark: \
264 self.on_editbookmark_complete(bookmark, new_bookmark),
267 def on_save_activate(self, widget):
268 self.bookmarklist.save()
270 def on_close_activate(self, widget):
273 def on_quit_activate(self, widget):
276 def on_delete_activate(self, widget):
277 bookmark = self._get_selected_bookmark()
279 self.bookmarklist.delete_bookmark(bookmark)
280 self.update_categories()
282 def on_refresh_bbsmenu_activate(self, widget):
283 self.bookmarklist.update_bbsmenu()
284 self.update_categories()