+# Copyright (C) 2009 by Aiwota Programmer
+# aiwotaprog@tetteke.tk
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+import gtk
+import traceback
+
+from BbsType import bbs_type_judge_uri
+from BbsType import bbs_type_exception
+import session
+
+def on_icon_popup_menu(icon, button, time):
+ menu = StatusIconMenu()
+ menu.show_all()
+ menu.popup(None, None, gtk.status_icon_position_menu,button, time, icon)
+
+
+class StatusIconMenu(gtk.Menu):
+
+ def __init__(self):
+ gtk.Menu.__init__(self)
+
+ self._bbs_dict = {}
+
+ self._build_bbs_dict()
+ self._build_menu_items()
+
+ item = gtk.MenuItem("show all")
+ item.connect("activate", self.on_menu_item_show_all_activate)
+ self.append(item)
+
+ def _build_menu_items(self):
+ for bbsname, boards in self._bbs_dict.iteritems():
+ for board in boards:
+ label = 'show "' + bbsname + '" "' + board + '" only'
+ item = gtk.MenuItem(label)
+ item.connect("activate", self.on_menu_item_activate,
+ bbsname, board)
+ self.append(item)
+
+
+ def _build_bbs_dict(self):
+ uris = session.get_windows_uris()
+
+ bbs_dict = {} ## key: bbs_type value: list of board
+
+ for uri in uris:
+ try:
+ bbs_type = bbs_type_judge_uri.get_type(uri)
+ if bbs_type.bbs_type not in bbs_dict:
+ bbs_dict[bbs_type.bbs_type] = [bbs_type.board]
+ elif bbs_type.board not in bbs_dict[bbs_type.bbs_type]:
+ bbs_dict[bbs_type.bbs_type].append(bbs_type.board)
+ except bbs_type_exception.BbsTypeError:
+ pass
+
+ self._bbs_dict = bbs_dict
+
+ def on_menu_item_activate(self, widget, bbsname, board):
+ uris = session.get_windows_uris()
+
+ for uri in uris:
+ try:
+ bbs_type = bbs_type_judge_uri.get_type(uri)
+ if bbs_type.bbs_type == bbsname and bbs_type.board == board:
+ session.show_window(uri)
+ else:
+ session.hide_window(uri)
+ except bbs_type_exception.BbsTypeError:
+ pass
+
+ def on_menu_item_show_all_activate(self, widget):
+ uris = session.get_windows_uris()
+ for uri in uris:
+ session.show_window(uri)