make tooltip work for the new api too
This commit is contained in:
parent
ca5a75863f
commit
4fda072f0f
|
@ -28,8 +28,10 @@ from encodings.punycode import punycode_encode
|
||||||
|
|
||||||
import gajim
|
import gajim
|
||||||
from i18n import Q_
|
from i18n import Q_
|
||||||
|
from i18n import ngettext
|
||||||
from xmpp_stringprep import nodeprep, resourceprep, nameprep
|
from xmpp_stringprep import nodeprep, resourceprep, nameprep
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import winsound # windows-only built-in module for playing wav
|
import winsound # windows-only built-in module for playing wav
|
||||||
import win32api
|
import win32api
|
||||||
|
@ -814,3 +816,84 @@ def get_chat_control(account, contact):
|
||||||
highest_contact.resource:
|
highest_contact.resource:
|
||||||
return None
|
return None
|
||||||
return gajim.interface.msg_win_mgr.get_control(contact.jid, account)
|
return gajim.interface.msg_win_mgr.get_control(contact.jid, account)
|
||||||
|
|
||||||
|
def get_notification_icon_tooltip_text():
|
||||||
|
text = None
|
||||||
|
unread_chat = gajim.events.get_nb_events(types = ['printed_chat',
|
||||||
|
'chat'])
|
||||||
|
unread_single_chat = gajim.events.get_nb_events(types = ['normal'])
|
||||||
|
unread_gc = gajim.events.get_nb_events(types = ['printed_gc_msg',
|
||||||
|
'gc_msg'])
|
||||||
|
unread_pm = gajim.events.get_nb_events(types = ['printed_pm', 'pm'])
|
||||||
|
|
||||||
|
accounts = get_accounts_info()
|
||||||
|
|
||||||
|
if unread_chat or unread_single_chat or unread_gc or unread_pm:
|
||||||
|
text = 'Gajim '
|
||||||
|
awaiting_events = unread_chat + unread_single_chat + unread_gc + unread_pm
|
||||||
|
if awaiting_events == unread_chat or awaiting_events == unread_single_chat \
|
||||||
|
or awaiting_events == unread_gc or awaiting_events == unread_pm:
|
||||||
|
# This condition is like previous if but with xor...
|
||||||
|
# Print in one line
|
||||||
|
text += '-'
|
||||||
|
else:
|
||||||
|
# Print in multiple lines
|
||||||
|
text += '\n '
|
||||||
|
if unread_chat:
|
||||||
|
text += ngettext(
|
||||||
|
' %d unread message',
|
||||||
|
' %d unread messages',
|
||||||
|
unread_chat, unread_chat, unread_chat)
|
||||||
|
text += '\n '
|
||||||
|
if unread_single_chat:
|
||||||
|
text += ngettext(
|
||||||
|
' %d unread single message',
|
||||||
|
' %d unread single messages',
|
||||||
|
unread_single_chat, unread_single_chat, unread_single_chat)
|
||||||
|
text += '\n '
|
||||||
|
if unread_gc:
|
||||||
|
text += ngettext(
|
||||||
|
' %d unread group chat message',
|
||||||
|
' %d unread group chat messages',
|
||||||
|
unread_gc, unread_gc, unread_gc)
|
||||||
|
text += '\n '
|
||||||
|
if unread_pm:
|
||||||
|
text += ngettext(
|
||||||
|
' %d unread private message',
|
||||||
|
' %d unread private messages',
|
||||||
|
unread_pm, unread_pm, unread_pm)
|
||||||
|
text += '\n '
|
||||||
|
text = text[:-4] # remove latest '\n '
|
||||||
|
elif len(accounts) > 1:
|
||||||
|
text = _('Gajim')
|
||||||
|
elif len(accounts) == 1:
|
||||||
|
message = accounts[0]['status_line']
|
||||||
|
message = gtkgui_helpers.reduce_chars_newlines(message, 100, 1)
|
||||||
|
message = gtkgui_helpers.escape_for_pango_markup(message)
|
||||||
|
text = _('Gajim - %s') % message
|
||||||
|
else:
|
||||||
|
text = _('Gajim - %s') % get_uf_show('offline')
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
def get_accounts_info():
|
||||||
|
'''helper for notification icon tooltip'''
|
||||||
|
accounts = []
|
||||||
|
accounts_list = gajim.contacts.get_accounts()
|
||||||
|
accounts_list.sort()
|
||||||
|
for account in accounts_list:
|
||||||
|
status_idx = gajim.connections[account].connected
|
||||||
|
# uncomment the following to hide offline accounts
|
||||||
|
# if status_idx == 0: continue
|
||||||
|
status = gajim.SHOW_LIST[status_idx]
|
||||||
|
message = gajim.connections[account].status
|
||||||
|
single_line = get_uf_show(status)
|
||||||
|
if message is None:
|
||||||
|
message = ''
|
||||||
|
else:
|
||||||
|
message = message.strip()
|
||||||
|
if message != '':
|
||||||
|
single_line += ': ' + message
|
||||||
|
accounts.append({'name': account, 'status_line': single_line,
|
||||||
|
'show': status, 'message': message})
|
||||||
|
return accounts
|
||||||
|
|
|
@ -38,7 +38,7 @@ class BaseTooltip:
|
||||||
tooltip.hide_tooltip()
|
tooltip.hide_tooltip()
|
||||||
|
|
||||||
* data - the text to be displayed (extenders override this argument and
|
* data - the text to be displayed (extenders override this argument and
|
||||||
dislpay more complex contents)
|
display more complex contents)
|
||||||
* widget_height - the height of the widget on which we want to show tooltip
|
* widget_height - the height of the widget on which we want to show tooltip
|
||||||
* widget_y_position - the vertical position of the widget on the screen
|
* widget_y_position - the vertical position of the widget on the screen
|
||||||
|
|
||||||
|
@ -222,27 +222,6 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
|
||||||
BaseTooltip.__init__(self)
|
BaseTooltip.__init__(self)
|
||||||
StatusTable.__init__(self)
|
StatusTable.__init__(self)
|
||||||
|
|
||||||
def get_accounts_info(self):
|
|
||||||
accounts = []
|
|
||||||
accounts_list = gajim.contacts.get_accounts()
|
|
||||||
accounts_list.sort()
|
|
||||||
for account in accounts_list:
|
|
||||||
status_idx = gajim.connections[account].connected
|
|
||||||
# uncomment the following to hide offline accounts
|
|
||||||
# if status_idx == 0: continue
|
|
||||||
status = gajim.SHOW_LIST[status_idx]
|
|
||||||
message = gajim.connections[account].status
|
|
||||||
single_line = helpers.get_uf_show(status)
|
|
||||||
if message is None:
|
|
||||||
message = ''
|
|
||||||
else:
|
|
||||||
message = message.strip()
|
|
||||||
if message != '':
|
|
||||||
single_line += ': ' + message
|
|
||||||
accounts.append({'name': account, 'status_line': single_line,
|
|
||||||
'show': status, 'message': message})
|
|
||||||
return accounts
|
|
||||||
|
|
||||||
def fill_table_with_accounts(self, accounts):
|
def fill_table_with_accounts(self, accounts):
|
||||||
iconset = gajim.config.get('iconset')
|
iconset = gajim.config.get('iconset')
|
||||||
if not iconset:
|
if not iconset:
|
||||||
|
@ -273,67 +252,15 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
|
||||||
def populate(self, data):
|
def populate(self, data):
|
||||||
self.create_window()
|
self.create_window()
|
||||||
self.create_table()
|
self.create_table()
|
||||||
self.hbox = gtk.HBox()
|
accounts = helpers.get_accounts_info()
|
||||||
self.table.set_property('column-spacing', 1)
|
if len(accounts) > 1:
|
||||||
text, single_line = '', ''
|
|
||||||
|
|
||||||
unread_chat = gajim.events.get_nb_events(types = ['printed_chat', 'chat'])
|
|
||||||
unread_single_chat = gajim.events.get_nb_events(types = ['normal'])
|
|
||||||
unread_gc = gajim.events.get_nb_events(types = ['printed_gc_msg',
|
|
||||||
'gc_msg'])
|
|
||||||
unread_pm = gajim.events.get_nb_events(types = ['printed_pm', 'pm'])
|
|
||||||
|
|
||||||
accounts = self.get_accounts_info()
|
|
||||||
|
|
||||||
if unread_chat or unread_single_chat or unread_gc or unread_pm:
|
|
||||||
text = 'Gajim '
|
|
||||||
awaiting_events = unread_chat + unread_single_chat + unread_gc + unread_pm
|
|
||||||
if awaiting_events == unread_chat or awaiting_events == unread_single_chat \
|
|
||||||
or awaiting_events == unread_gc or awaiting_events == unread_pm:
|
|
||||||
# This condition is like previous if but with xor...
|
|
||||||
# Print in one line
|
|
||||||
text += '-'
|
|
||||||
else:
|
|
||||||
# Print in multiple lines
|
|
||||||
text += '\n '
|
|
||||||
if unread_chat:
|
|
||||||
text += i18n.ngettext(
|
|
||||||
' %d unread message',
|
|
||||||
' %d unread messages',
|
|
||||||
unread_chat, unread_chat, unread_chat)
|
|
||||||
text += '\n '
|
|
||||||
if unread_single_chat:
|
|
||||||
text += i18n.ngettext(
|
|
||||||
' %d unread single message',
|
|
||||||
' %d unread single messages',
|
|
||||||
unread_single_chat, unread_single_chat, unread_single_chat)
|
|
||||||
text += '\n '
|
|
||||||
if unread_gc:
|
|
||||||
text += i18n.ngettext(
|
|
||||||
' %d unread group chat message',
|
|
||||||
' %d unread group chat messages',
|
|
||||||
unread_gc, unread_gc, unread_gc)
|
|
||||||
text += '\n '
|
|
||||||
if unread_pm:
|
|
||||||
text += i18n.ngettext(
|
|
||||||
' %d unread private message',
|
|
||||||
' %d unread private messages',
|
|
||||||
unread_pm, unread_pm, unread_pm)
|
|
||||||
text += '\n '
|
|
||||||
text = text[:-4] # remove latest '\n '
|
|
||||||
elif len(accounts) > 1:
|
|
||||||
text = _('Gajim')
|
|
||||||
self.current_current_row = 1
|
|
||||||
self.table.resize(2, 1)
|
self.table.resize(2, 1)
|
||||||
self.fill_table_with_accounts(accounts)
|
self.fill_table_with_accounts(accounts)
|
||||||
|
self.hbox = gtk.HBox()
|
||||||
|
self.table.set_property('column-spacing', 1)
|
||||||
|
|
||||||
|
text = helpers.get_notification_icon_tooltip_text()
|
||||||
|
|
||||||
elif len(accounts) == 1:
|
|
||||||
message = accounts[0]['status_line']
|
|
||||||
message = gtkgui_helpers.reduce_chars_newlines(message, 100, 1)
|
|
||||||
message = gtkgui_helpers.escape_for_pango_markup(message)
|
|
||||||
text = _('Gajim - %s') % message
|
|
||||||
else:
|
|
||||||
text = _('Gajim - %s') % helpers.get_uf_show('offline')
|
|
||||||
self.add_text_row(text)
|
self.add_text_row(text)
|
||||||
self.hbox.add(self.table)
|
self.hbox.add(self.table)
|
||||||
self.win.add(self.hbox)
|
self.win.add(self.hbox)
|
||||||
|
@ -449,8 +376,7 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
self.create_table()
|
self.create_table()
|
||||||
if not contacts or len(contacts) == 0:
|
if not contacts or len(contacts) == 0:
|
||||||
# Tooltip for merged accounts row
|
# Tooltip for merged accounts row
|
||||||
accounts = self.get_accounts_info()
|
accounts = helpers.get_accounts_info()
|
||||||
self.current_current_row = 0
|
|
||||||
self.table.resize(2, 1)
|
self.table.resize(2, 1)
|
||||||
self.spacer_label = ''
|
self.spacer_label = ''
|
||||||
self.fill_table_with_accounts(accounts)
|
self.fill_table_with_accounts(accounts)
|
||||||
|
|
Loading…
Reference in New Issue