1 # Copyright (C) 2009 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
22 from BbsType import bbs_type_judge_uri
23 from BbsType import bbs_type_exception
26 def on_icon_popup_menu(icon, button, time):
27 menu = StatusIconMenu()
29 menu.popup(None, None, gtk.status_icon_position_menu,button, time, icon)
32 class StatusIconMenu(gtk.Menu):
35 gtk.Menu.__init__(self)
39 self._build_bbs_dict()
40 self._build_menu_items()
42 item = gtk.MenuItem("show all")
43 item.connect("activate", self.on_menu_item_show_all_activate)
46 def _build_menu_items(self):
47 for bbsname, boards in self._bbs_dict.iteritems():
49 label = 'show "' + bbsname + '" "' + board + '" only'
50 item = gtk.MenuItem(label)
51 item.connect("activate", self.on_menu_item_activate,
56 def _build_bbs_dict(self):
57 uris = session.get_windows_uris()
59 bbs_dict = {} ## key: bbs_type value: list of board
63 bbs_type = bbs_type_judge_uri.get_type(uri)
64 if bbs_type.bbs_type not in bbs_dict:
65 bbs_dict[bbs_type.bbs_type] = [bbs_type.board]
66 elif bbs_type.board not in bbs_dict[bbs_type.bbs_type]:
67 bbs_dict[bbs_type.bbs_type].append(bbs_type.board)
68 except bbs_type_exception.BbsTypeError:
71 self._bbs_dict = bbs_dict
73 def on_menu_item_activate(self, widget, bbsname, board):
74 uris = session.get_windows_uris()
78 bbs_type = bbs_type_judge_uri.get_type(uri)
79 if bbs_type.bbs_type == bbsname and bbs_type.board == board:
80 session.show_window(uri)
82 session.hide_window(uri)
83 except bbs_type_exception.BbsTypeError:
86 def on_menu_item_show_all_activate(self, widget):
87 uris = session.get_windows_uris()
89 session.show_window(uri)