/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
211 by Jelmer Vernooij
Move notification area code into separate file.
1
# Copyright (C) 2007 by Robert Collins
2
#                       Jelmer Vernooij
3
#
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.
8
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.
13
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."""
18
19
import gtk
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
20
import bzrlib.plugins.dbus
21
22
def has_dbus():
23
    return (getattr(bzrlib.plugins, "dbus", None) is not None)
24
25
def has_avahi():
26
    return (getattr(bzrlib.plugins, "avahi", None) is not None)
211 by Jelmer Vernooij
Move notification area code into separate file.
27
28
class NotifyPopupMenu(gtk.Menu):
29
    def __init__(self):
30
        super(NotifyPopupMenu, self).__init__()
31
        self.create_items()
32
33
    def create_items(self):
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
34
        item = gtk.CheckMenuItem('_Gateway to LAN')
35
        item.connect('toggled', self.toggle_lan_gateway)
36
        self.append(item)
37
        self.append(gtk.SeparatorMenuItem())
211 by Jelmer Vernooij
Move notification area code into separate file.
38
        try:
39
            from bzrlib.plugins.dbus.activity import LanGateway
40
            self.langateway = LanGateway()
41
        except ImportError:
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
42
            item.set_sensitive(False)
211 by Jelmer Vernooij
Move notification area code into separate file.
43
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
44
        item = gtk.CheckMenuItem('Announce _branches on LAN')
45
        item.connect('toggled', self.toggle_announce_branches)
46
        self.append(item)
47
        self.append(gtk.SeparatorMenuItem())
211 by Jelmer Vernooij
Move notification area code into separate file.
48
        try:
49
            from bzrlib.plugins.avahi.share import ZeroConfServer
50
            from bzrlib import urlutils
51
            self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
52
        except ImportError:
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
53
            item.set_sensitive(False)
211 by Jelmer Vernooij
Move notification area code into separate file.
54
55
        item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES, None)
56
        item.connect('activate', self.show_preferences)
57
        self.append(item)
221 by Jelmer Vernooij
Add simple about dialog.
58
        item = gtk.ImageMenuItem(gtk.STOCK_ABOUT, None)
59
        item.connect('activate', self.show_about)
60
        self.append(item)
211 by Jelmer Vernooij
Move notification area code into separate file.
61
        self.append(gtk.SeparatorMenuItem())
223 by Jelmer Vernooij
Add icon for Bazaar preferences.
62
        item = gtk.ImageMenuItem(gtk.STOCK_QUIT, None)
211 by Jelmer Vernooij
Move notification area code into separate file.
63
        item.connect('activate', gtk.main_quit)
64
        self.append(item)
65
        self.show_all()
66
67
    def display(self, icon, event_button, event_time):
68
        self.popup(None, None, gtk.status_icon_position_menu, 
69
               event_button, event_time, icon)
70
71
    def toggle_lan_gateway(self, item):
72
        if item.get_active():
73
            self.langateway.start()
74
        else:
75
            self.langateway.stop()
76
77
    def toggle_announce_branches(self, item):
78
        if item.get_active():
79
            self.zeroconfserver.start()
80
        else:
81
            self.zeroconfserver.close()
82
221 by Jelmer Vernooij
Add simple about dialog.
83
    def show_about(self, item):
553.1.3 by Jelmer Vernooij
Use absolute imports.
84
        from bzrlib.plugins.gtk.about import AboutDialog
221 by Jelmer Vernooij
Add simple about dialog.
85
        dialog = AboutDialog()
86
        dialog.run()
87
211 by Jelmer Vernooij
Move notification area code into separate file.
88
    def show_preferences(self, item):
553.1.3 by Jelmer Vernooij
Use absolute imports.
89
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
90
        prefs = PreferencesWindow()
91
        prefs.run()
211 by Jelmer Vernooij
Move notification area code into separate file.
92