2017-03-23 18:04:56 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-09-23 12:37:04 +02:00
|
|
|
"""
|
|
|
|
src/plugins/indicator_libmessaging.py
|
|
|
|
=====================================
|
|
|
|
"""
|
2017-03-23 18:04:56 +01:00
|
|
|
|
|
|
|
import gi
|
2017-10-17 00:30:01 +02:00
|
|
|
gi.require_version('MessagingMenu', '1.0') # noqa:E402
|
2017-03-23 18:04:56 +01:00
|
|
|
from gi.repository import MessagingMenu
|
|
|
|
|
|
|
|
from pybitmessage.bitmessageqt.utils import str_broadcast_subscribers
|
|
|
|
from pybitmessage.tr import _translate
|
|
|
|
|
|
|
|
|
|
|
|
class IndicatorLibmessaging(object):
|
2019-09-23 12:37:04 +02:00
|
|
|
"""Plugin for libmessage indicator"""
|
2017-03-23 18:04:56 +01:00
|
|
|
def __init__(self, form):
|
|
|
|
try:
|
|
|
|
self.app = MessagingMenu.App(desktop_id='pybitmessage.desktop')
|
|
|
|
self.app.register()
|
|
|
|
self.app.connect('activate-source', self.activate)
|
|
|
|
except:
|
|
|
|
self.app = None
|
|
|
|
return
|
|
|
|
|
|
|
|
self._menu = {
|
2017-10-17 00:30:01 +02:00
|
|
|
'send': unicode(_translate('MainWindow', 'Send')),
|
|
|
|
'messages': unicode(_translate('MainWindow', 'Messages')),
|
|
|
|
'subscriptions': unicode(_translate('MainWindow', 'Subscriptions'))
|
2017-03-23 18:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.new_message_item = self.new_broadcast_item = None
|
|
|
|
self.form = form
|
|
|
|
self.show_unread()
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
if self.app:
|
|
|
|
self.app.unregister()
|
|
|
|
|
2019-09-23 12:37:04 +02:00
|
|
|
def activate(self, app, source): # pylint: disable=unused-argument
|
|
|
|
"""Activate the libmessaging indicator plugin"""
|
2017-03-23 18:04:56 +01:00
|
|
|
self.form.appIndicatorInbox(
|
|
|
|
self.new_message_item if source == 'messages'
|
|
|
|
else self.new_broadcast_item
|
|
|
|
)
|
|
|
|
|
|
|
|
def show_unread(self, draw_attention=False):
|
2019-09-23 12:37:04 +02:00
|
|
|
"""
|
|
|
|
show the number of unread messages and subscriptions
|
|
|
|
on the messaging menu
|
|
|
|
"""
|
2017-03-23 18:04:56 +01:00
|
|
|
for source, count in zip(
|
|
|
|
('messages', 'subscriptions'),
|
|
|
|
self.form.getUnread()
|
|
|
|
):
|
|
|
|
if count > 0:
|
|
|
|
if self.app.has_source(source):
|
|
|
|
self.app.set_source_count(source, count)
|
|
|
|
else:
|
|
|
|
self.app.append_source_with_count(
|
|
|
|
source, None, self._menu[source], count)
|
|
|
|
if draw_attention:
|
|
|
|
self.app.draw_attention(source)
|
|
|
|
|
|
|
|
# update the Ubuntu messaging menu
|
|
|
|
def __call__(self, draw_attention, item=None, to_label=None):
|
|
|
|
if not self.app:
|
|
|
|
return
|
|
|
|
# remember this item to that the activate() can find it
|
|
|
|
if item:
|
|
|
|
if to_label == str_broadcast_subscribers:
|
|
|
|
self.new_broadcast_item = item
|
|
|
|
else:
|
|
|
|
self.new_message_item = item
|
|
|
|
|
|
|
|
self.show_unread(draw_attention)
|
|
|
|
|
|
|
|
|
|
|
|
connect_plugin = IndicatorLibmessaging
|