/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 bzr-notify

  • Committer: Jelmer Vernooij
  • Date: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
"""Run the bzr tray icon.
4
 
 
5
 
This is a background program which will pop up a notification on the users
6
 
screen when a commit occurs.
7
 
"""
8
 
 
9
 
from bzrlib.plugin import load_plugins
10
 
load_plugins()
11
 
 
12
 
from bzrlib.plugins.gtk.commands import open_display
13
 
 
14
 
from bzrlib.plugins.gtk.notify import NotifyPopupMenu
15
 
Gtk = open_display()
16
 
 
17
 
import cgi
18
 
import dbus
19
 
import dbus.service
20
 
import gobject
21
 
import pynotify
22
 
from bzrlib.bzrdir import BzrDir
23
 
from bzrlib.osutils import format_date
24
 
from bzrlib.transport import get_transport
25
 
 
26
 
menu = NotifyPopupMenu()
27
 
try:
28
 
    import appindicator
29
 
except ImportError:
30
 
    icon = gtk.status_icon_new_from_icon_name("bzr-panel")
31
 
    icon.connect('popup-menu', menu.display)
32
 
    icon.set_visible(False)
33
 
    hide_icon = lambda: icon.set_visible(False)
34
 
    show_icon = lambda: icon.set_visible(True)
35
 
else:
36
 
    indicator = appindicator.Indicator ("bzr-gtk-notify",
37
 
        "bzr-panel", appindicator.CATEGORY_OTHER)
38
 
    indicator.set_status (appindicator.STATUS_PASSIVE)
39
 
    indicator.set_attention_icon("bzr-panel")
40
 
    indicator.set_menu(menu)
41
 
    hide_icon = lambda: indicator.set_status (appindicator.STATUS_PASSIVE)
42
 
    show_icon = lambda: indicator.set_status (appindicator.STATUS_ATTENTION)
43
 
 
44
 
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
45
 
    import dbus.glib
46
 
BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
47
 
bus = dbus.SessionBus()
48
 
 
49
 
def catch_branch(revision_id, urls):
50
 
    # TODO: show all the urls, or perhaps choose the 'best'.
51
 
    url = urls[0]
52
 
    try:
53
 
        if isinstance(revision_id, unicode):
54
 
            revision_id = revision_id.encode('utf8')
55
 
        transport = get_transport(url)
56
 
        a_dir = BzrDir.open_from_transport(transport)
57
 
        branch = a_dir.open_branch()
58
 
        revno = branch.revision_id_to_revno(revision_id)
59
 
        revision = branch.repository.get_revision(revision_id)
60
 
        summary = 'New revision %d in %s' % (revno, url)
61
 
        body = 'Committer: %s\n' % revision.committer
62
 
        body += 'Date: %s\n' % format_date(revision.timestamp,
63
 
            revision.timezone)
64
 
        body += '\n'
65
 
        body += revision.message
66
 
        body = cgi.escape(body)
67
 
        nw = pynotify.Notification(summary, body)
68
 
        def start_viz(notification=None, action=None, data=None):
69
 
            """Start the viz program."""
70
 
            from bzrlib.plugins.gtk.commands import start_viz_window
71
 
            pp = start_viz_window(branch, revision_id)
72
 
            pp.show()
73
 
        def start_branch(notification=None, action=None, data=None):
74
 
            """Start a Branch dialog"""
75
 
            from bzrlib.plugins.gtk.branch import BranchDialog
76
 
            bd = BranchDialog(remote_path=url)
77
 
            bd.run()
78
 
        if "actions" in pynotify.get_server_caps():
79
 
            nw.add_action("inspect", "Inspect", start_viz, None)
80
 
            nw.add_action("branch", "Branch", start_branch, None)
81
 
        show_icon()
82
 
        gobject.timeout_add(5000, hide_icon)
83
 
        nw.set_timeout(5000)
84
 
        nw.show()
85
 
    except Exception, e:
86
 
        print e
87
 
        raise
88
 
bus.add_signal_receiver(catch_branch,
89
 
                        dbus_interface=BROADCAST_INTERFACE,
90
 
                        signal_name="Revision")
91
 
pynotify.init("bzr-notify")
92
 
gtk.main()