2007-04-01 11:02:04 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/tooltips.py
|
2005-08-15 01:52:12 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005 Alex Mauer <hawke AT hawkesnest.net>
|
2008-08-15 19:31:51 +02:00
|
|
|
## Stéphan Kochen <stephan AT kochen.nl>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem AT gmail.com>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Travis Shirk <travis AT pobox.com>
|
|
|
|
## Stefan Bethge <stefan AT lanpartei.de>
|
|
|
|
## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Copyright (C) 2007-2008 Stephan Erb <steve-e AT h3c.de>
|
|
|
|
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
2005-08-15 01:52:12 +02:00
|
|
|
##
|
2007-12-12 09:44:46 +01:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-08-15 01:52:12 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-12-12 09:44:46 +01:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-08-15 01:52:12 +02:00
|
|
|
##
|
2007-12-12 09:44:46 +01:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-08-15 01:52:12 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-08-15 01:52:12 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-12-12 09:44:46 +01:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-12-12 09:44:46 +01:00
|
|
|
##
|
2005-08-15 01:52:12 +02:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
2013-07-28 20:50:30 +02:00
|
|
|
from gi.repository import GLib
|
2017-06-12 22:04:22 +02:00
|
|
|
from gi.repository import Pango
|
2005-08-15 01:52:12 +02:00
|
|
|
import os
|
2006-02-22 15:31:01 +01:00
|
|
|
import time
|
2010-03-30 14:27:59 +02:00
|
|
|
from datetime import datetime
|
2010-03-30 15:39:49 +02:00
|
|
|
from datetime import timedelta
|
2005-08-15 01:52:12 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
2017-09-16 11:49:31 +02:00
|
|
|
from gajim.common.const import AvatarSize
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
|
|
|
from gajim.common.i18n import Q_
|
2005-08-15 01:52:12 +02:00
|
|
|
|
|
|
|
class BaseTooltip:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Base Tooltip class
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
tooltip = BaseTooltip()
|
|
|
|
....
|
|
|
|
tooltip.show_tooltip(data, widget_height, widget_y_position)
|
|
|
|
....
|
|
|
|
if tooltip.timeout != 0:
|
|
|
|
tooltip.hide_tooltip()
|
|
|
|
|
|
|
|
* data - the text to be displayed (extenders override this argument and
|
|
|
|
display more complex contents)
|
|
|
|
* 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
|
|
|
|
|
|
|
|
Tooltip is displayed aligned centered to the mouse poiner and 4px below the widget.
|
|
|
|
In case tooltip goes below the visible area it is shown above the widget.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.timeout = 0
|
|
|
|
self.preferred_position = [0, 0]
|
|
|
|
self.win = None
|
|
|
|
self.id = None
|
|
|
|
self.cur_data = None
|
2014-06-21 10:39:34 +02:00
|
|
|
self.shown = False
|
2015-08-15 22:16:45 +02:00
|
|
|
self.position_computed = False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def populate(self, data):
|
|
|
|
"""
|
|
|
|
This method must be overriden by all extenders. This is the most simple
|
|
|
|
implementation: show data as value of a label
|
|
|
|
"""
|
|
|
|
self.create_window()
|
2012-12-23 16:23:43 +01:00
|
|
|
self.win.add(Gtk.Label(label=data))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def create_window(self):
|
|
|
|
"""
|
|
|
|
Create a popup window each time tooltip is requested
|
|
|
|
"""
|
2015-07-18 17:27:50 +02:00
|
|
|
self.win = Gtk.Window.new(Gtk.WindowType.POPUP)
|
2011-11-10 22:26:11 +01:00
|
|
|
self.win.set_title('tooltip')
|
2010-02-08 15:08:40 +01:00
|
|
|
self.win.set_border_width(3)
|
|
|
|
self.win.set_resizable(False)
|
|
|
|
self.win.set_name('gtk-tooltips')
|
2012-12-23 16:23:43 +01:00
|
|
|
self.win.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
self.win.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
|
2012-12-28 21:59:20 +01:00
|
|
|
self.win.connect('size-allocate', self.on_size_allocate)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.win.connect('motion-notify-event', self.motion_notify_event)
|
|
|
|
self.screen = self.win.get_screen()
|
|
|
|
|
|
|
|
def _get_icon_name_for_tooltip(self, contact):
|
|
|
|
"""
|
|
|
|
Helper function used for tooltip contacts/acounts
|
|
|
|
|
|
|
|
Tooltip on account has fake contact with sub == '', in this case we show
|
|
|
|
real status of the account
|
|
|
|
"""
|
|
|
|
if contact.ask == 'subscribe':
|
|
|
|
return 'requested'
|
|
|
|
elif contact.sub in ('both', 'to', ''):
|
|
|
|
return contact.show
|
|
|
|
return 'not in roster'
|
|
|
|
|
|
|
|
def motion_notify_event(self, widget, event):
|
2015-10-04 20:50:41 +02:00
|
|
|
GLib.idle_add(self.hide_tooltip)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2012-12-28 21:59:20 +01:00
|
|
|
def on_size_allocate(self, widget, rect):
|
2015-08-15 22:16:45 +02:00
|
|
|
if not self.position_computed:
|
|
|
|
half_width = rect.width / 2 + 1
|
|
|
|
if self.preferred_position[1] + rect.height > \
|
|
|
|
self.screen.get_height():
|
|
|
|
# flip tooltip up
|
|
|
|
self.preferred_position[1] -= rect.height + self.widget_height \
|
|
|
|
+ 8
|
|
|
|
if self.preferred_position[1] < 0:
|
|
|
|
self.preferred_position[1] = self.screen.get_height() - \
|
|
|
|
rect.height - 2
|
|
|
|
|
|
|
|
if self.preferred_position[0] + rect.width + 7 < \
|
|
|
|
self.screen.get_width():
|
|
|
|
self.preferred_position[0] = self.preferred_position[0]\
|
|
|
|
+ 7
|
|
|
|
else:
|
|
|
|
self.preferred_position[0] = self.preferred_position[0]\
|
|
|
|
- rect.width - 7
|
|
|
|
self.win.move(self.preferred_position[0],
|
|
|
|
self.preferred_position[1])
|
|
|
|
return
|
|
|
|
if self.preferred_position[0] < half_width:
|
|
|
|
self.preferred_position[0] = 0
|
|
|
|
elif self.preferred_position[0] + rect.width > \
|
|
|
|
self.screen.get_width() + half_width:
|
|
|
|
self.preferred_position[0] = self.screen.get_width() - \
|
|
|
|
rect.width
|
2017-07-26 22:24:19 +02:00
|
|
|
else:
|
2015-08-15 22:16:45 +02:00
|
|
|
self.preferred_position[0] -= half_width
|
|
|
|
self.position_computed = True
|
2010-02-08 15:08:40 +01:00
|
|
|
self.win.move(self.preferred_position[0], self.preferred_position[1])
|
|
|
|
|
|
|
|
def show_tooltip(self, data, widget_height, widget_y_position):
|
|
|
|
"""
|
|
|
|
Show tooltip on widget
|
|
|
|
|
|
|
|
Data contains needed data for tooltip contents.
|
|
|
|
widget_height is the height of the widget on which we show the tooltip.
|
|
|
|
widget_y_position is vertical position of the widget on the screen.
|
|
|
|
"""
|
2014-06-21 10:39:34 +02:00
|
|
|
if self.shown:
|
|
|
|
return
|
2015-08-15 22:16:45 +02:00
|
|
|
self.position_computed = False
|
2010-02-08 15:08:40 +01:00
|
|
|
self.cur_data = data
|
|
|
|
# set tooltip contents
|
|
|
|
self.populate(data)
|
|
|
|
|
|
|
|
# get the X position of mouse pointer on the screen
|
2013-07-29 14:38:09 +02:00
|
|
|
pointer_x = self.screen.get_display().get_device_manager().\
|
|
|
|
get_client_pointer().get_position()[1]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# get the prefered X position of the tooltip on the screen in case this position is >
|
|
|
|
# than the height of the screen, tooltip will be shown above the widget
|
|
|
|
preferred_y = widget_y_position + widget_height + 4
|
|
|
|
|
|
|
|
self.preferred_position = [pointer_x, preferred_y]
|
|
|
|
self.widget_height = widget_height
|
|
|
|
self.win.show_all()
|
2014-06-21 10:39:34 +02:00
|
|
|
self.shown = True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def hide_tooltip(self):
|
|
|
|
if self.timeout > 0:
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.source_remove(self.timeout)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.timeout = 0
|
|
|
|
if self.win:
|
|
|
|
self.win.destroy()
|
|
|
|
self.win = None
|
|
|
|
self.id = None
|
|
|
|
self.cur_data = None
|
2014-06-21 10:39:34 +02:00
|
|
|
self.shown = False
|
2005-08-15 01:52:12 +02:00
|
|
|
|
|
|
|
class StatusTable:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Contains methods for creating status table. This is used in Roster and
|
|
|
|
NotificationArea tooltips
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2016-11-17 03:29:18 +01:00
|
|
|
self.current_row = 0
|
2010-02-08 15:08:40 +01:00
|
|
|
self.table = None
|
|
|
|
self.text_label = None
|
|
|
|
self.spacer_label = ' '
|
|
|
|
|
|
|
|
def create_table(self):
|
2013-07-29 18:22:19 +02:00
|
|
|
self.table = Gtk.Grid()
|
|
|
|
self.table.insert_column(0)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.table.set_property('column-spacing', 2)
|
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
def add_text_row(self, text, col_inc=0):
|
|
|
|
self.table.insert_row(self.current_row)
|
2012-12-23 16:23:43 +01:00
|
|
|
self.text_label = Gtk.Label()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.text_label.set_line_wrap(True)
|
2017-06-12 22:04:22 +02:00
|
|
|
self.text_label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
2016-11-17 03:29:18 +01:00
|
|
|
self.text_label.set_max_width_chars(35)
|
2016-09-25 23:44:38 +02:00
|
|
|
self.text_label.set_halign(Gtk.Align.START)
|
|
|
|
self.text_label.set_valign(Gtk.Align.START)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.text_label.set_selectable(False)
|
|
|
|
self.text_label.set_markup(text)
|
2013-07-29 18:22:19 +02:00
|
|
|
self.table.attach(self.text_label, 1 + col_inc, self.current_row,
|
|
|
|
3 - col_inc, 1)
|
2016-11-17 03:29:18 +01:00
|
|
|
self.current_row += 1
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def get_status_info(self, resource, priority, show, status):
|
2013-01-01 21:06:16 +01:00
|
|
|
str_status = resource + ' (' + str(priority) + ')'
|
2010-02-08 15:08:40 +01:00
|
|
|
if status:
|
|
|
|
status = status.strip()
|
|
|
|
if status != '':
|
|
|
|
# reduce to 100 chars, 1 line
|
|
|
|
status = helpers.reduce_chars_newlines(status, 100, 1)
|
2013-07-28 20:50:30 +02:00
|
|
|
str_status = GLib.markup_escape_text(str_status)
|
|
|
|
status = GLib.markup_escape_text(status)
|
2010-02-08 15:08:40 +01:00
|
|
|
str_status += ' - <i>' + status + '</i>'
|
|
|
|
return str_status
|
|
|
|
|
2017-07-26 22:24:19 +02:00
|
|
|
def add_status_row(self, file_path, show, str_status, show_lock=False,
|
|
|
|
indent=True):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Append a new row with status icon to the table
|
|
|
|
"""
|
2016-11-17 03:29:18 +01:00
|
|
|
self.table.insert_row(self.current_row)
|
2010-02-08 15:08:40 +01:00
|
|
|
state_file = show.replace(' ', '_')
|
|
|
|
files = []
|
|
|
|
files.append(os.path.join(file_path, state_file + '.png'))
|
|
|
|
files.append(os.path.join(file_path, state_file + '.gif'))
|
2012-12-23 16:23:43 +01:00
|
|
|
image = Gtk.Image()
|
2010-02-08 15:08:40 +01:00
|
|
|
image.set_from_pixbuf(None)
|
|
|
|
for f in files:
|
|
|
|
if os.path.exists(f):
|
|
|
|
image.set_from_file(f)
|
|
|
|
break
|
2012-12-23 16:23:43 +01:00
|
|
|
spacer = Gtk.Label(label=self.spacer_label)
|
2016-09-25 23:44:38 +02:00
|
|
|
image.set_halign(Gtk.Align.START)
|
2016-09-25 23:07:46 +02:00
|
|
|
image.set_valign(Gtk.Align.CENTER)
|
2010-02-08 15:08:40 +01:00
|
|
|
if indent:
|
2013-07-29 18:22:19 +02:00
|
|
|
self.table.attach(spacer, 1, self.current_row, 1, 1)
|
|
|
|
self.table.attach(image, 2, self.current_row, 1, 1)
|
2012-12-23 16:23:43 +01:00
|
|
|
status_label = Gtk.Label()
|
2010-02-08 15:08:40 +01:00
|
|
|
status_label.set_markup(str_status)
|
2016-09-25 23:44:38 +02:00
|
|
|
status_label.set_halign(Gtk.Align.START)
|
|
|
|
status_label.set_valign(Gtk.Align.START)
|
2010-02-08 15:08:40 +01:00
|
|
|
status_label.set_line_wrap(True)
|
2013-07-29 18:22:19 +02:00
|
|
|
self.table.attach(status_label, 3, self.current_row, 1, 1)
|
2010-02-08 15:08:40 +01:00
|
|
|
if show_lock:
|
2012-12-23 16:23:43 +01:00
|
|
|
lock_image = Gtk.Image()
|
2017-09-28 00:14:26 +02:00
|
|
|
lock_image.set_from_icon_name("dialog-password",
|
2013-07-29 18:22:19 +02:00
|
|
|
Gtk.IconSize.MENU)
|
|
|
|
self.table.attach(lock_image, 4, self.current_row, 1, 1)
|
2016-11-17 03:29:18 +01:00
|
|
|
self.current_row += 1
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-08-15 01:52:12 +02:00
|
|
|
class NotificationAreaTooltip(BaseTooltip, StatusTable):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Tooltip that is shown in the notification area
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
BaseTooltip.__init__(self)
|
|
|
|
StatusTable.__init__(self)
|
|
|
|
|
|
|
|
def fill_table_with_accounts(self, accounts):
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.get('iconset')
|
2010-02-08 15:08:40 +01:00
|
|
|
if not iconset:
|
|
|
|
iconset = 'dcraven'
|
|
|
|
file_path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
|
|
|
|
for acct in accounts:
|
|
|
|
message = acct['message']
|
|
|
|
message = helpers.reduce_chars_newlines(message, 100, 1)
|
2013-07-28 20:50:30 +02:00
|
|
|
message = GLib.markup_escape_text(message)
|
2017-08-13 13:18:56 +02:00
|
|
|
if acct['name'] in app.con_types and \
|
|
|
|
app.con_types[acct['name']] in ('tls', 'ssl'):
|
2010-02-08 15:08:40 +01:00
|
|
|
show_lock = True
|
|
|
|
else:
|
|
|
|
show_lock = False
|
|
|
|
if message:
|
|
|
|
self.add_status_row(file_path, acct['show'],
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.markup_escape_text(acct['name']) + ' - ' + message,
|
|
|
|
show_lock=show_lock, indent=False)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.add_status_row(file_path, acct['show'],
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.markup_escape_text(acct['name']), show_lock=show_lock,
|
|
|
|
indent=False)
|
2010-02-08 15:08:40 +01:00
|
|
|
for line in acct['event_lines']:
|
|
|
|
self.add_text_row(' ' + line, 1)
|
|
|
|
|
|
|
|
def populate(self, data=''):
|
|
|
|
self.create_window()
|
|
|
|
self.create_table()
|
|
|
|
|
|
|
|
accounts = helpers.get_notification_icon_tooltip_dict()
|
|
|
|
self.fill_table_with_accounts(accounts)
|
2012-12-23 16:23:43 +01:00
|
|
|
self.hbox = Gtk.HBox()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.table.set_property('column-spacing', 1)
|
|
|
|
|
|
|
|
self.hbox.add(self.table)
|
|
|
|
self.hbox.show_all()
|
2005-08-24 19:29:35 +02:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
class GCTooltip(Gtk.Window):
|
|
|
|
# pylint: disable=E1101
|
2017-09-16 11:49:31 +02:00
|
|
|
def __init__(self, account, parent):
|
2016-11-19 17:25:48 +01:00
|
|
|
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP, transient_for=parent)
|
2017-09-16 11:49:31 +02:00
|
|
|
self.account = account
|
2016-11-13 21:06:37 +01:00
|
|
|
self.row = None
|
|
|
|
self.set_title('tooltip')
|
|
|
|
self.set_border_width(3)
|
|
|
|
self.set_resizable(False)
|
|
|
|
self.set_name('gtk-tooltips')
|
|
|
|
self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
|
|
|
|
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('tooltip_gc_contact.ui')
|
|
|
|
for name in ('nick', 'status', 'jid', 'user_show', 'fillelement',
|
|
|
|
'resource', 'affiliation', 'avatar', 'resource_label',
|
|
|
|
'jid_label', 'tooltip_grid'):
|
|
|
|
setattr(self, name, self.xml.get_object(name))
|
|
|
|
|
|
|
|
self.add(self.tooltip_grid)
|
|
|
|
self.tooltip_grid.show()
|
|
|
|
|
|
|
|
def clear_tooltip(self):
|
|
|
|
"""
|
|
|
|
Hide all Elements of the Tooltip Grid
|
|
|
|
"""
|
|
|
|
for child in self.tooltip_grid.get_children():
|
|
|
|
child.hide()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def populate(self, contact):
|
2016-11-13 21:06:37 +01:00
|
|
|
"""
|
|
|
|
Populate the Tooltip Grid with data of from the contact
|
|
|
|
"""
|
|
|
|
self.clear_tooltip()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
self.nick.set_text(contact.get_shown_name())
|
|
|
|
self.nick.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
# Status Message
|
|
|
|
if contact.status:
|
2010-02-08 15:08:40 +01:00
|
|
|
status = contact.status.strip()
|
|
|
|
if status != '':
|
2016-11-13 21:06:37 +01:00
|
|
|
self.status.set_text(status)
|
|
|
|
self.status.show()
|
2010-04-03 20:08:09 +02:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
# Status
|
2010-04-03 20:08:09 +02:00
|
|
|
show = helpers.get_uf_show(contact.show)
|
2016-11-13 21:06:37 +01:00
|
|
|
self.user_show.set_markup(colorize_status(show))
|
|
|
|
self.user_show.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
# JID
|
2010-04-03 20:38:54 +02:00
|
|
|
if contact.jid.strip():
|
2016-11-13 21:06:37 +01:00
|
|
|
self.jid.set_text(contact.jid)
|
|
|
|
self.jid.show()
|
|
|
|
self.jid_label.show()
|
|
|
|
# Resource
|
2010-04-03 20:38:54 +02:00
|
|
|
if hasattr(contact, 'resource') and contact.resource.strip():
|
2016-11-13 21:06:37 +01:00
|
|
|
self.resource.set_text(contact.resource)
|
|
|
|
self.resource.show()
|
|
|
|
self.resource_label.show()
|
2010-04-03 20:38:54 +02:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
# Affiliation
|
2010-02-08 15:08:40 +01:00
|
|
|
if contact.affiliation != 'none':
|
|
|
|
uf_affiliation = helpers.get_uf_affiliation(contact.affiliation)
|
2013-07-29 18:22:19 +02:00
|
|
|
uf_affiliation = \
|
2016-11-13 21:06:37 +01:00
|
|
|
_('%(owner_or_admin_or_member)s of this group chat') \
|
|
|
|
% {'owner_or_admin_or_member': uf_affiliation}
|
2010-04-03 20:38:54 +02:00
|
|
|
uf_affiliation = self.colorize_affiliation(uf_affiliation)
|
2016-11-13 21:06:37 +01:00
|
|
|
self.affiliation.set_markup(uf_affiliation)
|
|
|
|
self.affiliation.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
# Avatar
|
2017-09-16 11:49:31 +02:00
|
|
|
if contact.avatar_sha is not None:
|
|
|
|
app.log('avatar').debug(
|
|
|
|
'Load GCTooltip: %s %s', contact.name, contact.avatar_sha)
|
|
|
|
pixbuf = app.interface.get_avatar(contact.avatar_sha, AvatarSize.TOOLTIP)
|
|
|
|
if pixbuf is not None:
|
|
|
|
self.avatar.set_from_pixbuf(pixbuf)
|
|
|
|
self.avatar.show()
|
|
|
|
self.fillelement.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-13 21:06:37 +01:00
|
|
|
@staticmethod
|
|
|
|
def colorize_affiliation(affiliation):
|
|
|
|
"""
|
|
|
|
Color the affiliation of a MUC participant inside the tooltip by
|
|
|
|
it's semantics. Color palette is the Tango.
|
|
|
|
"""
|
|
|
|
formatted = "<span foreground='%s'>%s</span>"
|
|
|
|
color = None
|
|
|
|
if affiliation.startswith(Q_("?Group Chat Contact Affiliation:None")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_affiliation_none_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif affiliation.startswith(_("Member")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_affiliation_member_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif affiliation.startswith(_("Administrator")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_affiliation_administrator_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif affiliation.startswith(_("Owner")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_affiliation_owner_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
if color:
|
|
|
|
affiliation = formatted % (color, affiliation)
|
|
|
|
return affiliation
|
2005-08-24 14:58:03 +02:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
class RosterTooltip(Gtk.Window, StatusTable):
|
|
|
|
# pylint: disable=E1101
|
|
|
|
def __init__(self, parent):
|
|
|
|
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP, transient_for=parent)
|
|
|
|
StatusTable.__init__(self)
|
|
|
|
self.create_table()
|
|
|
|
self.row = None
|
|
|
|
self.contact_jid = None
|
|
|
|
self.last_widget = None
|
|
|
|
self.num_resources = 0
|
|
|
|
self.set_title('tooltip')
|
|
|
|
self.set_border_width(3)
|
|
|
|
self.set_resizable(False)
|
|
|
|
self.set_name('gtk-tooltips')
|
|
|
|
self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('tooltip_roster_contact.ui')
|
|
|
|
for name in ('name', 'status', 'jid', 'user_show', 'fillelement',
|
|
|
|
'resource', 'avatar', 'resource_label', 'pgp', 'pgp_label',
|
2017-07-26 22:24:19 +02:00
|
|
|
'jid_label', 'tooltip_grid', 'idle_since', 'idle_since_label',
|
|
|
|
'mood', 'tune', 'activity', 'location', 'tune_label',
|
|
|
|
'location_label', 'activity_label', 'mood_label', 'sub_label',
|
|
|
|
'sub', 'status_label'):
|
2016-11-17 03:29:18 +01:00
|
|
|
setattr(self, name, self.xml.get_object(name))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
self.add(self.tooltip_grid)
|
|
|
|
self.tooltip_grid.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
def clear_tooltip(self):
|
|
|
|
"""
|
|
|
|
Hide all Elements of the Tooltip Grid
|
|
|
|
"""
|
|
|
|
for child in self.tooltip_grid.get_children():
|
|
|
|
child.hide()
|
|
|
|
status_table = self.tooltip_grid.get_child_at(0, 3)
|
|
|
|
if status_table:
|
|
|
|
status_table.destroy()
|
|
|
|
self.create_table()
|
|
|
|
|
|
|
|
def fill_table_with_accounts(self, accounts):
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.get('iconset')
|
2016-11-17 03:29:18 +01:00
|
|
|
if not iconset:
|
|
|
|
iconset = 'dcraven'
|
|
|
|
file_path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
|
|
|
|
for acct in accounts:
|
|
|
|
message = acct['message']
|
|
|
|
message = helpers.reduce_chars_newlines(message, 100, 1)
|
|
|
|
message = GLib.markup_escape_text(message)
|
2017-08-13 13:18:56 +02:00
|
|
|
if acct['name'] in app.con_types and \
|
|
|
|
app.con_types[acct['name']] in ('tls', 'ssl'):
|
2016-11-17 03:29:18 +01:00
|
|
|
show_lock = True
|
|
|
|
else:
|
|
|
|
show_lock = False
|
|
|
|
if message:
|
|
|
|
self.add_status_row(file_path, acct['show'],
|
|
|
|
GLib.markup_escape_text(acct['name']) + ' - ' + message,
|
|
|
|
show_lock=show_lock, indent=False)
|
|
|
|
else:
|
|
|
|
self.add_status_row(file_path, acct['show'],
|
|
|
|
GLib.markup_escape_text(acct['name']), show_lock=show_lock,
|
|
|
|
indent=False)
|
|
|
|
for line in acct['event_lines']:
|
|
|
|
self.add_text_row(' ' + line, 1)
|
|
|
|
|
|
|
|
def populate(self, contacts, account, typ):
|
|
|
|
"""
|
|
|
|
Populate the Tooltip Grid with data of from the contact
|
|
|
|
"""
|
|
|
|
self.current_row = 0
|
|
|
|
self.account = account
|
|
|
|
if self.last_widget:
|
|
|
|
self.last_widget.set_vexpand(False)
|
|
|
|
|
|
|
|
self.clear_tooltip()
|
|
|
|
|
|
|
|
if account == 'all':
|
2010-02-08 15:08:40 +01:00
|
|
|
# Tooltip for merged accounts row
|
|
|
|
accounts = helpers.get_notification_icon_tooltip_dict()
|
|
|
|
self.spacer_label = ''
|
|
|
|
self.fill_table_with_accounts(accounts)
|
2016-11-17 03:29:18 +01:00
|
|
|
self.tooltip_grid.attach(self.table, 0, 3, 2, 1)
|
|
|
|
self.table.show_all()
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
if typ == 'account':
|
2017-08-13 13:18:56 +02:00
|
|
|
jid = app.get_jid_from_account(account)
|
2016-11-17 03:29:18 +01:00
|
|
|
contacts = []
|
2017-08-13 13:18:56 +02:00
|
|
|
connection = app.connections[account]
|
2016-11-17 03:29:18 +01:00
|
|
|
# get our current contact info
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
nbr_on, nbr_total = app.\
|
2016-11-17 03:29:18 +01:00
|
|
|
contacts.get_nb_online_total_contacts(
|
|
|
|
accounts=[account])
|
|
|
|
account_name = account
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_connected(account):
|
2016-11-17 03:29:18 +01:00
|
|
|
account_name += ' (%s/%s)' % (repr(nbr_on),
|
|
|
|
repr(nbr_total))
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.create_self_contact(jid=jid,
|
2016-11-17 03:29:18 +01:00
|
|
|
account=account, name=account_name,
|
|
|
|
show=connection.get_status(), status=connection.status,
|
|
|
|
resource=connection.server_resource,
|
|
|
|
priority=connection.priority)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.connections[account].gpg:
|
|
|
|
contact.keyID = app.config.get_per('accounts',
|
2016-11-17 03:29:18 +01:00
|
|
|
connection.name, 'keyid')
|
|
|
|
contacts.append(contact)
|
|
|
|
# if we're online ...
|
|
|
|
if connection.connection:
|
|
|
|
roster = connection.connection.getRoster()
|
|
|
|
# in threadless connection when no roster stanza is sent
|
|
|
|
# 'roster' is None
|
|
|
|
if roster and roster.getItem(jid):
|
|
|
|
resources = roster.getResources(jid)
|
|
|
|
# ...get the contact info for our other online
|
|
|
|
# resources
|
|
|
|
for resource in resources:
|
|
|
|
# Check if we already have this resource
|
|
|
|
found = False
|
|
|
|
for contact_ in contacts:
|
|
|
|
if contact_.resource == resource:
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
if found:
|
|
|
|
continue
|
|
|
|
show = roster.getShow(jid + '/' + resource)
|
|
|
|
if not show:
|
|
|
|
show = 'online'
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.create_self_contact(
|
2016-11-17 03:29:18 +01:00
|
|
|
jid=jid, account=account, show=show,
|
|
|
|
status=roster.getStatus(
|
|
|
|
jid + '/' + resource),
|
|
|
|
priority=roster.getPriority(
|
|
|
|
jid + '/' + resource), resource=resource)
|
|
|
|
contacts.append(contact)
|
|
|
|
|
|
|
|
# Username/Account/Groupchat
|
2017-08-13 13:18:56 +02:00
|
|
|
self.prim_contact = app.contacts.get_highest_prio_contact_from_contacts(
|
2013-07-29 18:22:19 +02:00
|
|
|
contacts)
|
2016-11-17 03:29:18 +01:00
|
|
|
self.contact_jid = self.prim_contact.jid
|
|
|
|
name = GLib.markup_escape_text(self.prim_contact.get_shown_name())
|
|
|
|
name_markup = '<b>{}</b>'.format(name)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('mergeaccounts'):
|
|
|
|
color = app.config.get('tooltip_account_name_color')
|
2016-11-17 03:29:18 +01:00
|
|
|
account_name = GLib.markup_escape_text(self.prim_contact.account.name)
|
|
|
|
name_markup += " <span foreground='{}'>({})</span>".format(
|
|
|
|
color, account_name)
|
2012-03-13 14:32:09 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
if account and helpers.jid_is_blocked(account, self.prim_contact.jid):
|
2010-02-08 15:08:40 +01:00
|
|
|
name_markup += _(' [blocked]')
|
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
try:
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.prim_contact.jid in app.interface.minimized_controls[account]:
|
2016-11-17 03:29:18 +01:00
|
|
|
name_markup += _(' [minimized]')
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.name.set_markup(name_markup)
|
|
|
|
self.name.show()
|
|
|
|
|
|
|
|
self.num_resources = 0
|
2010-02-08 15:08:40 +01:00
|
|
|
# put contacts in dict, where key is priority
|
|
|
|
contacts_dict = {}
|
|
|
|
for contact in contacts:
|
|
|
|
if contact.resource:
|
2016-11-17 03:29:18 +01:00
|
|
|
self.num_resources += 1
|
|
|
|
priority = int(contact.priority)
|
|
|
|
if priority in contacts_dict:
|
|
|
|
contacts_dict[priority].append(contact)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2016-11-17 03:29:18 +01:00
|
|
|
contacts_dict[priority] = [contact]
|
|
|
|
if self.num_resources > 1:
|
|
|
|
self.status_label.show()
|
2017-08-13 13:18:56 +02:00
|
|
|
transport = app.get_transport_name_from_jid(self.prim_contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if transport:
|
|
|
|
file_path = os.path.join(helpers.get_transport_path(transport),
|
2013-07-29 18:22:19 +02:00
|
|
|
'16x16')
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.get('iconset')
|
2010-02-08 15:08:40 +01:00
|
|
|
if not iconset:
|
|
|
|
iconset = 'dcraven'
|
2012-06-16 22:58:46 +02:00
|
|
|
file_path = os.path.join(helpers.get_iconset_path(iconset),
|
|
|
|
'16x16')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
contact_keys = sorted(contacts_dict.keys())
|
|
|
|
contact_keys.reverse()
|
|
|
|
for priority in contact_keys:
|
|
|
|
for acontact in contacts_dict[priority]:
|
|
|
|
icon_name = self._get_icon_name_for_tooltip(acontact)
|
2016-11-17 03:29:18 +01:00
|
|
|
if acontact.status and len(acontact.status) > 25:
|
|
|
|
status = ''
|
|
|
|
add_text = True
|
|
|
|
else:
|
|
|
|
status = acontact.status
|
|
|
|
add_text = False
|
|
|
|
|
|
|
|
status_line = self.get_status_info(acontact.resource,
|
|
|
|
acontact.priority, acontact.show, status)
|
2017-07-26 22:24:19 +02:00
|
|
|
self.add_status_row(file_path, icon_name, status_line)
|
2016-11-17 03:29:18 +01:00
|
|
|
if add_text:
|
|
|
|
self.add_text_row(acontact.status, 2)
|
|
|
|
|
|
|
|
self.tooltip_grid.attach(self.table, 0, 3, 2, 1)
|
|
|
|
self.table.show_all()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
else: # only one resource
|
2017-07-26 22:24:19 +02:00
|
|
|
if contact.show and contact.status:
|
|
|
|
status = contact.status.strip()
|
|
|
|
if status:
|
|
|
|
self.status.set_text(status)
|
|
|
|
self.status.show()
|
|
|
|
self.status_label.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
# PEP Info
|
|
|
|
self._append_pep_info(contact)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
# JID
|
|
|
|
self.jid.set_text(self.prim_contact.jid)
|
|
|
|
self.jid.show()
|
|
|
|
self.jid_label.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# contact has only one ressource
|
2016-11-17 03:29:18 +01:00
|
|
|
if self.num_resources == 1 and contact.resource:
|
|
|
|
res = GLib.markup_escape_text(contact.resource)
|
|
|
|
prio = str(contact.priority)
|
|
|
|
self.resource.set_text("{} ({})".format(res, prio))
|
|
|
|
self.resource.show()
|
|
|
|
self.resource_label.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.prim_contact.jid not in app.gc_connected[account]:
|
2016-11-17 03:29:18 +01:00
|
|
|
if (account and
|
|
|
|
self.prim_contact.sub and
|
|
|
|
self.prim_contact.sub != 'both'):
|
|
|
|
# ('both' is the normal sub so we don't show it)
|
|
|
|
self.sub.set_text(helpers.get_uf_sub(self.prim_contact.sub))
|
|
|
|
self.sub.show()
|
|
|
|
self.sub_label.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
if self.prim_contact.keyID:
|
2010-02-08 15:08:40 +01:00
|
|
|
keyID = None
|
2016-11-17 03:29:18 +01:00
|
|
|
if len(self.prim_contact.keyID) == 8:
|
|
|
|
keyID = self.prim_contact.keyID
|
|
|
|
elif len(self.prim_contact.keyID) == 16:
|
|
|
|
keyID = self.prim_contact.keyID[8:]
|
2010-02-08 15:08:40 +01:00
|
|
|
if keyID:
|
2016-11-17 03:29:18 +01:00
|
|
|
self.pgp.set_text(keyID)
|
|
|
|
self.pgp.show()
|
|
|
|
self.pgp_label.show()
|
|
|
|
|
|
|
|
self._set_idle_time(contact)
|
|
|
|
|
|
|
|
# Avatar
|
2017-09-16 11:49:31 +02:00
|
|
|
pixbuf = app.contacts.get_avatar(
|
|
|
|
account, self.prim_contact.jid, AvatarSize.TOOLTIP)
|
|
|
|
if pixbuf is None:
|
|
|
|
return
|
|
|
|
self.avatar.set_from_pixbuf(pixbuf)
|
|
|
|
self.avatar.show()
|
|
|
|
|
|
|
|
# Sets the Widget that is at the bottom to expand.
|
|
|
|
# This is needed in case the Picture takes more Space then the Labels
|
|
|
|
i = 1
|
|
|
|
while i < 15:
|
|
|
|
if self.tooltip_grid.get_child_at(0, i):
|
|
|
|
if self.tooltip_grid.get_child_at(0, i).get_visible():
|
|
|
|
self.last_widget = self.tooltip_grid.get_child_at(0, i)
|
|
|
|
i += 1
|
|
|
|
self.last_widget.set_vexpand(True)
|
2016-11-17 03:29:18 +01:00
|
|
|
|
|
|
|
def _append_pep_info(self, contact):
|
|
|
|
"""
|
|
|
|
Append Tune, Mood, Activity, Location information of the specified contact
|
|
|
|
to the given property list.
|
|
|
|
"""
|
|
|
|
if 'mood' in contact.pep:
|
|
|
|
mood = contact.pep['mood'].asMarkupText()
|
|
|
|
self.mood.set_markup(mood)
|
|
|
|
self.mood.show()
|
|
|
|
self.mood_label.show()
|
|
|
|
|
|
|
|
if 'activity' in contact.pep:
|
|
|
|
activity = contact.pep['activity'].asMarkupText()
|
|
|
|
self.activity.set_markup(activity)
|
|
|
|
self.activity.show()
|
|
|
|
self.activity_label.show()
|
|
|
|
|
|
|
|
if 'tune' in contact.pep:
|
|
|
|
tune = contact.pep['tune'].asMarkupText()
|
|
|
|
self.tune.set_markup(tune)
|
|
|
|
self.tune.show()
|
|
|
|
self.tune_label.show()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
if 'location' in contact.pep:
|
|
|
|
location = contact.pep['location'].asMarkupText()
|
|
|
|
self.location.set_markup(location)
|
|
|
|
self.location.show()
|
|
|
|
self.location_label.show()
|
|
|
|
|
|
|
|
def _set_idle_time(self, contact):
|
2017-07-26 22:24:19 +02:00
|
|
|
if contact.idle_time:
|
2017-08-13 13:18:56 +02:00
|
|
|
idle_color = app.config.get('tooltip_idle_color')
|
2017-07-26 22:24:19 +02:00
|
|
|
idle_time = contact.idle_time
|
|
|
|
idle_time = time.localtime(contact.idle_time)
|
|
|
|
idle_time = datetime(*(idle_time[:6]))
|
2010-03-30 14:27:59 +02:00
|
|
|
current = datetime.now()
|
2017-07-26 22:24:19 +02:00
|
|
|
if idle_time.date() == current.date():
|
|
|
|
formatted = idle_time.strftime("%X")
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-07-26 22:24:19 +02:00
|
|
|
formatted = idle_time.strftime("%c")
|
|
|
|
idle_markup = "<span foreground='{}'>{}</span>".format(idle_color,
|
|
|
|
formatted)
|
|
|
|
self.idle_since.set_markup(idle_markup)
|
|
|
|
self.idle_since.show()
|
|
|
|
self.idle_since_label.show()
|
2016-11-17 03:29:18 +01:00
|
|
|
|
|
|
|
if contact.show and self.num_resources < 2:
|
|
|
|
show = helpers.get_uf_show(contact.show)
|
|
|
|
# Contact is Groupchat
|
|
|
|
if (self.account and
|
2017-08-13 13:18:56 +02:00
|
|
|
self.prim_contact.jid in app.gc_connected[self.account]):
|
|
|
|
if app.gc_connected[self.account][self.prim_contact.jid]:
|
2016-11-17 03:29:18 +01:00
|
|
|
show = _('Connected')
|
|
|
|
else:
|
|
|
|
show = _('Disconnected')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-11-17 03:29:18 +01:00
|
|
|
self.user_show.set_markup(colorize_status(show))
|
|
|
|
self.user_show.show()
|
|
|
|
|
|
|
|
def _get_icon_name_for_tooltip(self, contact):
|
|
|
|
"""
|
|
|
|
Helper function used for tooltip contacts/acounts
|
|
|
|
|
|
|
|
Tooltip on account has fake contact with sub == '', in this case we show
|
|
|
|
real status of the account
|
|
|
|
"""
|
|
|
|
if contact.ask == 'subscribe':
|
|
|
|
return 'requested'
|
|
|
|
elif contact.sub in ('both', 'to', ''):
|
|
|
|
return contact.show
|
|
|
|
return 'not in roster'
|
|
|
|
|
2008-05-19 23:31:25 +02:00
|
|
|
|
2005-08-15 01:52:12 +02:00
|
|
|
class FileTransfersTooltip(BaseTooltip):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Tooltip that is shown in the notification area
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
BaseTooltip.__init__(self)
|
|
|
|
|
|
|
|
def populate(self, file_props):
|
2012-12-23 16:23:43 +01:00
|
|
|
ft_table = Gtk.Table(2, 1)
|
2010-02-08 15:08:40 +01:00
|
|
|
ft_table.set_property('column-spacing', 2)
|
|
|
|
current_row = 1
|
|
|
|
self.create_window()
|
|
|
|
properties = []
|
2012-06-14 18:27:23 +02:00
|
|
|
name = file_props.name
|
|
|
|
if file_props.type_ == 'r':
|
|
|
|
file_name = os.path.split(file_props.file_name)[1]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2012-06-14 18:27:23 +02:00
|
|
|
file_name = file_props.name
|
2013-07-28 20:50:30 +02:00
|
|
|
properties.append((_('Name: '), GLib.markup_escape_text(file_name)))
|
2012-06-14 18:27:23 +02:00
|
|
|
if file_props.type_ == 'r':
|
2017-08-18 22:05:16 +02:00
|
|
|
type_ = Q_('?Noun:Download')
|
2010-02-08 15:08:40 +01:00
|
|
|
actor = _('Sender: ')
|
2013-01-01 21:06:16 +01:00
|
|
|
sender = file_props.sender.split('/')[0]
|
2017-08-13 13:18:56 +02:00
|
|
|
name = app.contacts.get_first_contact_from_jid(
|
2012-06-14 18:27:23 +02:00
|
|
|
file_props.tt_account, sender).get_shown_name()
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-18 22:05:16 +02:00
|
|
|
type_ = Q_('?Noun:Upload')
|
2010-02-08 15:08:40 +01:00
|
|
|
actor = _('Recipient: ')
|
2012-06-14 18:27:23 +02:00
|
|
|
receiver = file_props.receiver
|
2010-02-08 15:08:40 +01:00
|
|
|
if hasattr(receiver, 'name'):
|
|
|
|
name = receiver.get_shown_name()
|
|
|
|
else:
|
|
|
|
name = receiver.split('/')[0]
|
|
|
|
properties.append((_('Type: '), type_))
|
2013-07-28 20:50:30 +02:00
|
|
|
properties.append((actor, GLib.markup_escape_text(name)))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2012-06-14 18:27:23 +02:00
|
|
|
transfered_len = file_props.received_len
|
|
|
|
if not transfered_len:
|
|
|
|
transfered_len = 0
|
2010-02-08 15:08:40 +01:00
|
|
|
properties.append((_('Transferred: '), helpers.convert_bytes(transfered_len)))
|
|
|
|
status = ''
|
2012-06-14 18:27:23 +02:00
|
|
|
if file_props.started:
|
2010-02-08 15:08:40 +01:00
|
|
|
status = _('Not started')
|
2012-06-14 18:27:23 +02:00
|
|
|
if file_props.stopped == True:
|
|
|
|
status = _('Stopped')
|
|
|
|
elif file_props.completed:
|
|
|
|
status = _('Completed')
|
|
|
|
elif file_props.connected == False:
|
|
|
|
if file_props.completed:
|
2010-02-08 15:08:40 +01:00
|
|
|
status = _('Completed')
|
|
|
|
else:
|
2012-06-14 18:27:23 +02:00
|
|
|
if file_props.paused == True:
|
2017-08-18 22:05:16 +02:00
|
|
|
status = Q_('?transfer status:Paused')
|
2012-06-14 18:27:23 +02:00
|
|
|
elif file_props.stalled == True:
|
2010-02-08 15:08:40 +01:00
|
|
|
#stalled is not paused. it is like 'frozen' it stopped alone
|
|
|
|
status = _('Stalled')
|
|
|
|
else:
|
|
|
|
status = _('Transferring')
|
|
|
|
else:
|
|
|
|
status = _('Not started')
|
|
|
|
properties.append((_('Status: '), status))
|
2014-02-15 21:28:39 +01:00
|
|
|
file_desc = file_props.desc or ''
|
2013-07-28 20:50:30 +02:00
|
|
|
properties.append((_('Description: '), GLib.markup_escape_text(
|
|
|
|
file_desc)))
|
2010-02-08 15:08:40 +01:00
|
|
|
while properties:
|
|
|
|
property_ = properties.pop(0)
|
|
|
|
current_row += 1
|
2012-12-23 16:23:43 +01:00
|
|
|
label = Gtk.Label()
|
2016-09-25 23:44:38 +02:00
|
|
|
label.set_halign(Gtk.Align.START)
|
|
|
|
label.set_valign(Gtk.Align.START)
|
2010-02-08 15:08:40 +01:00
|
|
|
label.set_markup(property_[0])
|
|
|
|
ft_table.attach(label, 1, 2, current_row, current_row + 1,
|
2012-12-23 16:23:43 +01:00
|
|
|
Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)
|
|
|
|
label = Gtk.Label()
|
2016-09-25 23:44:38 +02:00
|
|
|
label.set_halign(Gtk.Align.START)
|
|
|
|
label.set_valign(Gtk.Align.START)
|
2010-02-08 15:08:40 +01:00
|
|
|
label.set_line_wrap(True)
|
|
|
|
label.set_markup(property_[1])
|
|
|
|
ft_table.attach(label, 2, 3, current_row, current_row + 1,
|
2012-12-23 16:23:43 +01:00
|
|
|
Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.win.add(ft_table)
|
2016-11-13 21:06:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def colorize_status(status):
|
|
|
|
"""
|
|
|
|
Colorize the status message inside the tooltip by it's
|
|
|
|
semantics. Color palette is the Tango.
|
|
|
|
"""
|
|
|
|
formatted = "<span foreground='%s'>%s</span>"
|
|
|
|
color = None
|
|
|
|
if status.startswith(Q_("?user status:Available")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_online_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif status.startswith(_("Free for Chat")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_free_for_chat_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif status.startswith(_("Away")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_away_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif status.startswith(_("Busy")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_busy_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif status.startswith(_("Not Available")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_na_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
elif status.startswith(_("Offline")):
|
2017-08-13 13:18:56 +02:00
|
|
|
color = app.config.get('tooltip_status_offline_color')
|
2016-11-13 21:06:37 +01:00
|
|
|
if color:
|
|
|
|
status = formatted % (color, status)
|
2017-02-07 20:56:26 +01:00
|
|
|
return status
|