/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
625.6.1 by Michael Vogt
notify.py: try import pygtk first to make latest pygtk not die with "need pygtk before importing gtk"
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
24
211 by Jelmer Vernooij
Move notification area code into separate file.
25
import gtk
619.1.1 by Vincent Ladeuil
Fix bug #290618 by using the right facilities.
26
import bzrlib
27
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
28
29
def has_dbus():
30
    return (getattr(bzrlib.plugins, "dbus", None) is not None)
31
619.1.1 by Vincent Ladeuil
Fix bug #290618 by using the right facilities.
32
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
33
def has_avahi():
34
    return (getattr(bzrlib.plugins, "avahi", None) is not None)
211 by Jelmer Vernooij
Move notification area code into separate file.
35
619.1.1 by Vincent Ladeuil
Fix bug #290618 by using the right facilities.
36
211 by Jelmer Vernooij
Move notification area code into separate file.
37
class NotifyPopupMenu(gtk.Menu):
38
    def __init__(self):
39
        super(NotifyPopupMenu, self).__init__()
40
        self.create_items()
41
42
    def create_items(self):
683.1.2 by Jelmer Vernooij
Don't crash when there is already a lan-notify instance running.
43
        from bzrlib import errors
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
44
        item = gtk.CheckMenuItem('_Gateway to LAN')
45
        item.connect('toggled', self.toggle_lan_gateway)
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.dbus.activity import LanGateway
50
            self.langateway = LanGateway()
51
        except ImportError:
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
52
            item.set_sensitive(False)
683.1.2 by Jelmer Vernooij
Don't crash when there is already a lan-notify instance running.
53
        except errors.BzrError:
54
            # FIXME: Should only catch errors that indicate a lan-notify 
55
            # process is already running.
56
            item.set_sensitive(False)
211 by Jelmer Vernooij
Move notification area code into separate file.
57
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
58
        item = gtk.CheckMenuItem('Announce _branches on LAN')
59
        item.connect('toggled', self.toggle_announce_branches)
60
        self.append(item)
61
        self.append(gtk.SeparatorMenuItem())
211 by Jelmer Vernooij
Move notification area code into separate file.
62
        try:
63
            from bzrlib.plugins.avahi.share import ZeroConfServer
64
            from bzrlib import urlutils
65
            self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
66
        except ImportError:
619 by Jelmer Vernooij
Add notifications tab in preferences dialog.
67
            item.set_sensitive(False)
211 by Jelmer Vernooij
Move notification area code into separate file.
68
69
        item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES, None)
70
        item.connect('activate', self.show_preferences)
71
        self.append(item)
221 by Jelmer Vernooij
Add simple about dialog.
72
        item = gtk.ImageMenuItem(gtk.STOCK_ABOUT, None)
73
        item.connect('activate', self.show_about)
74
        self.append(item)
211 by Jelmer Vernooij
Move notification area code into separate file.
75
        self.append(gtk.SeparatorMenuItem())
223 by Jelmer Vernooij
Add icon for Bazaar preferences.
76
        item = gtk.ImageMenuItem(gtk.STOCK_QUIT, None)
211 by Jelmer Vernooij
Move notification area code into separate file.
77
        item.connect('activate', gtk.main_quit)
78
        self.append(item)
79
        self.show_all()
80
81
    def display(self, icon, event_button, event_time):
82
        self.popup(None, None, gtk.status_icon_position_menu, 
83
               event_button, event_time, icon)
84
85
    def toggle_lan_gateway(self, item):
86
        if item.get_active():
87
            self.langateway.start()
88
        else:
89
            self.langateway.stop()
90
91
    def toggle_announce_branches(self, item):
92
        if item.get_active():
93
            self.zeroconfserver.start()
94
        else:
95
            self.zeroconfserver.close()
96
221 by Jelmer Vernooij
Add simple about dialog.
97
    def show_about(self, item):
553.1.3 by Jelmer Vernooij
Use absolute imports.
98
        from bzrlib.plugins.gtk.about import AboutDialog
221 by Jelmer Vernooij
Add simple about dialog.
99
        dialog = AboutDialog()
100
        dialog.run()
101
211 by Jelmer Vernooij
Move notification area code into separate file.
102
    def show_preferences(self, item):
553.1.3 by Jelmer Vernooij
Use absolute imports.
103
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
104
        prefs = PreferencesWindow()
105
        prefs.run()
211 by Jelmer Vernooij
Move notification area code into separate file.
106