File: libnotify.py

package info (click to toggle)
liferea 1.15.8-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,652 kB
  • sloc: ansic: 27,425; javascript: 1,646; python: 1,123; makefile: 657; sh: 115; xml: 13
file content (66 lines) | stat: -rw-r--r-- 2,351 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
libnotify Popup Notifications Plugin

Copyright (C) 2013-2015 Lars Windolf <lars.windolf@gmx.de>
Copyright (C) 2020 Tasos Sahanidis <tasos@tasossah.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""

import gettext
import gi
gi.require_version('Notify', '0.7')
from gi.repository import GObject, Liferea, Notify

_ = lambda x: x
try:
    t = gettext.translation("liferea")
except FileNotFoundError:
    pass
else:
    _ = t.gettext


class LibnotifyPlugin(GObject.Object, Liferea.ShellActivatable):
    __gtype_name__ = 'LibnotifyPlugin'

    object = GObject.property (type=GObject.Object)
    shell = GObject.property (type=Liferea.Shell)
    notification = None
    notification_title = _("Feed Updates")
    notification_body = ""
    notification_icon = "net.sourceforge.liferea"
    _handler_id = None

    def do_activate(self):
        Notify.init('Liferea')
        self._handler_id = self.shell.props.feed_list.connect("node-updated", self.on_node_updated)
        self.notification = Notify.Notification.new(self.notification_title, self.notification_body, self.notification_icon)
        self.notification.connect("closed", self.on_closed)

    def do_deactivate(self):
        Notify.uninit()
        self.shell.props.feed_list.disconnect(self._handler_id)

    def on_node_updated(self, widget, node_title):
        # Update the existing notification if it hasn't been closed yet
        if self.notification_body:
            self.notification_body += "\n" + node_title
        else:
            self.notification_body = node_title
        self.notification.update(self.notification_title, self.notification_body, self.notification_icon)
        self.notification.show()

    def on_closed(self, data):
        self.notification_body = ""