/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

  • Committer: Jelmer Vernooij
  • Date: 2011-12-11 17:14:12 UTC
  • Revision ID: jelmer@samba.org-20111211171412-cgcn0yas3zlcahzg
StartĀ onĀ 0.104.0.

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