/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to notify.py

Commit messages never contain config options

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
try:
20
 
    import pygtk
21
 
    pygtk.require("2.0")
22
 
except:
23
 
    pass
24
 
 
25
 
import gtk
26
 
import bzrlib
27
 
 
28
 
 
29
 
def has_dbus():
30
 
    return (getattr(bzrlib.plugins, "dbus", None) is not None)
31
 
 
32
 
 
33
 
def has_avahi():
34
 
    return (getattr(bzrlib.plugins, "avahi", None) is not None)
35
 
 
36
 
 
37
 
class NotifyPopupMenu(gtk.Menu):
38
 
 
39
 
    def __init__(self):
40
 
        super(NotifyPopupMenu, self).__init__()
41
 
        self.create_items()
42
 
 
43
 
    def create_items(self):
44
 
        from bzrlib import errors
45
 
        item = gtk.CheckMenuItem('_Gateway to LAN')
46
 
        item.connect('toggled', self.toggle_lan_gateway)
47
 
        self.append(item)
48
 
        self.append(gtk.SeparatorMenuItem())
49
 
        try:
50
 
            from bzrlib.plugins.dbus.activity import LanGateway
51
 
            self.langateway = LanGateway()
52
 
        except ImportError:
53
 
            item.set_sensitive(False)
54
 
        except errors.BzrError:
55
 
            # FIXME: Should only catch errors that indicate a lan-notify 
56
 
            # process is already running.
57
 
            item.set_sensitive(False)
58
 
 
59
 
        item = gtk.CheckMenuItem('Announce _branches on LAN')
60
 
        item.connect('toggled', self.toggle_announce_branches)
61
 
        self.append(item)
62
 
        self.append(gtk.SeparatorMenuItem())
63
 
        try:
64
 
            from bzrlib.plugins.avahi.share import ZeroConfServer
65
 
            from bzrlib import urlutils
66
 
            self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
67
 
        except ImportError:
68
 
            item.set_sensitive(False)
69
 
 
70
 
        item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES, None)
71
 
        item.connect('activate', self.show_preferences)
72
 
        self.append(item)
73
 
        item = gtk.ImageMenuItem(gtk.STOCK_ABOUT, None)
74
 
        item.connect('activate', self.show_about)
75
 
        self.append(item)
76
 
        self.append(gtk.SeparatorMenuItem())
77
 
        item = gtk.ImageMenuItem(gtk.STOCK_QUIT, None)
78
 
        item.connect('activate', gtk.main_quit)
79
 
        self.append(item)
80
 
        self.show_all()
81
 
 
82
 
    def display(self, icon, event_button, event_time):
83
 
        self.popup(None, None, gtk.status_icon_position_menu, 
84
 
               event_button, event_time, icon)
85
 
 
86
 
    def toggle_lan_gateway(self, item):
87
 
        if item.get_active():
88
 
            self.langateway.start()
89
 
        else:
90
 
            self.langateway.stop()
91
 
 
92
 
    def toggle_announce_branches(self, item):
93
 
        if item.get_active():
94
 
            self.zeroconfserver.start()
95
 
        else:
96
 
            self.zeroconfserver.close()
97
 
 
98
 
    def show_about(self, item):
99
 
        from bzrlib.plugins.gtk.about import AboutDialog
100
 
        dialog = AboutDialog()
101
 
        dialog.run()
102
 
 
103
 
    def show_preferences(self, item):
104
 
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
105
 
        prefs = PreferencesWindow()
106
 
        prefs.run()
107