1
# Copyright (C) 2007 by Robert Collins
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Notification area icon and notification for Bazaar."""
19
from gi.repository import Gtk
24
return (getattr(bzrlib.plugins, "dbus", None) is not None)
28
return (getattr(bzrlib.plugins, "avahi", None) is not None)
31
class NotifyPopupMenu(Gtk.Menu):
36
super(NotifyPopupMenu, self).__init__()
39
def create_items(self):
40
from bzrlib import errors
41
item = Gtk.CheckMenuItem.new_with_mnemonic('_Gateway to LAN')
42
item.connect('toggled', self.toggle_lan_gateway)
44
self.append(Gtk.SeparatorMenuItem())
46
from bzrlib.plugins.dbus.activity import LanGateway
47
self.langateway = LanGateway()
49
item.set_sensitive(False)
50
except errors.BzrError:
51
# FIXME: Should only catch errors that indicate a lan-notify
52
# process is already running.
53
item.set_sensitive(False)
55
item = Gtk.CheckMenuItem.new_with_mnemonic(
56
'Announce _branches on LAN')
57
item.connect('toggled', self.toggle_announce_branches)
59
self.append(Gtk.SeparatorMenuItem())
61
from bzrlib.plugins.avahi.share import ZeroConfServer
62
from bzrlib import urlutils
63
self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
65
item.set_sensitive(False)
67
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_PREFERENCES, None)
68
item.connect('activate', self.show_preferences)
70
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT, None)
71
item.connect('activate', self.show_about)
73
self.append(Gtk.SeparatorMenuItem())
74
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, None)
75
item.connect('activate', Gtk.main_quit)
80
def display(self, icon, event_button, event_time):
81
self.popup(None, None, Gtk.status_icon_position_menu,
82
event_button, event_time, icon)
84
def toggle_lan_gateway(self, item):
86
self.langateway.start()
88
self.langateway.stop()
90
def toggle_announce_branches(self, item):
92
self.zeroconfserver.start()
94
self.zeroconfserver.close()
96
def show_about(self, item):
97
from bzrlib.plugins.gtk.about import AboutDialog
98
dialog = AboutDialog()
101
def show_preferences(self, item):
102
from bzrlib.plugins.gtk.preferences import PreferencesWindow
103
prefs = PreferencesWindow()