Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/tooltips.py')
-rw-r--r--src/tooltips.py202
1 files changed, 117 insertions, 85 deletions
diff --git a/src/tooltips.py b/src/tooltips.py
index fa96cbd8c..aeaf06b1c 100644
--- a/src/tooltips.py
+++ b/src/tooltips.py
@@ -41,7 +41,9 @@ from common import helpers
from common.pep import MOODS, ACTIVITIES
class BaseTooltip:
- ''' Base Tooltip class;
+ """
+ Base Tooltip class
+
Usage:
tooltip = BaseTooltip()
....
@@ -57,22 +59,28 @@ class BaseTooltip:
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
+ self.check_last_time = None
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
- '''
+ """
+ This method must be overriden by all extenders. This is the most simple
+ implementation: show data as value of a label
+ """
self.create_window()
self.win.add(gtk.Label(data))
def create_window(self):
- ''' create a popup window each time tooltip is requested '''
+ """
+ Create a popup window each time tooltip is requested
+ """
self.win = gtk.Window(gtk.WINDOW_POPUP)
self.win.set_border_width(3)
self.win.set_resizable(False)
@@ -86,10 +94,12 @@ class BaseTooltip:
self.screen = self.win.get_screen()
def _get_icon_name_for_tooltip(self, contact):
- ''' helper function used for tooltip contacts/acounts
+ """
+ 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', ''):
@@ -107,9 +117,8 @@ class BaseTooltip:
self.screen.get_width() + half_width:
self.preferred_position[0] = self.screen.get_width() - \
requisition.width
- else:
+ elif not self.check_last_time:
self.preferred_position[0] -= half_width
- self.screen.get_height()
if self.preferred_position[1] + requisition.height > \
self.screen.get_height():
# flip tooltip up
@@ -133,11 +142,14 @@ class BaseTooltip:
return True
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
- '''
+ """
+ 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.
+ """
+ self.cur_data = data
# set tooltip contents
self.populate(data)
@@ -161,10 +173,15 @@ class BaseTooltip:
self.win.destroy()
self.win = None
self.id = None
+ self.cur_data = None
+ self.check_last_time = None
class StatusTable:
- ''' Contains methods for creating status table. This
- is used in Roster and NotificationArea tooltips '''
+ """
+ Contains methods for creating status table. This is used in Roster and
+ NotificationArea tooltips
+ """
+
def __init__(self):
self.current_row = 1
self.table = None
@@ -201,8 +218,10 @@ class StatusTable:
return str_status
def add_status_row(self, file_path, show, str_status, status_time=None,
- show_lock=False, indent=True):
- ''' appends a new row with status icon to the table '''
+ show_lock=False, indent=True):
+ """
+ Append a new row with status icon to the table
+ """
self.current_row += 1
state_file = show.replace(' ', '_')
files = []
@@ -235,7 +254,10 @@ class StatusTable:
self.current_row + 1, 0, 0, 0, 0)
class NotificationAreaTooltip(BaseTooltip, StatusTable):
- ''' Tooltip that is shown in the notification area '''
+ """
+ Tooltip that is shown in the notification area
+ """
+
def __init__(self):
BaseTooltip.__init__(self)
StatusTable.__init__(self)
@@ -269,7 +291,7 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
for line in acct['event_lines']:
self.add_text_row(' ' + line, 1)
- def populate(self, data):
+ def populate(self, data=''):
self.create_window()
self.create_table()
@@ -280,10 +302,13 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
self.table.set_property('column-spacing', 1)
self.hbox.add(self.table)
- self.win.add(self.hbox)
+ self.hbox.show_all()
class GCTooltip(BaseTooltip):
- ''' Tooltip that is shown in the GC treeview '''
+ """
+ Tooltip that is shown in the GC treeview
+ """
+
def __init__(self):
self.account = None
self.text_label = gtk.Label()
@@ -378,7 +403,10 @@ class GCTooltip(BaseTooltip):
self.win.add(vcard_table)
class RosterTooltip(NotificationAreaTooltip):
- ''' Tooltip that is shown in the roster treeview '''
+ """
+ Tooltip that is shown in the roster treeview
+ """
+
def __init__(self):
self.account = None
self.image = gtk.Image()
@@ -474,6 +502,20 @@ class RosterTooltip(NotificationAreaTooltip):
else: # only one resource
if contact.show:
show = helpers.get_uf_show(contact.show)
+ if not self.check_last_time and self.account:
+ if contact.show == 'offline':
+ if not contact.last_status_time:
+ gajim.connections[self.account].request_last_status_time(
+ contact.jid, '')
+ else:
+ self.check_last_time = contact.last_status_time
+ elif contact.resource:
+ gajim.connections[self.account].request_last_status_time(
+ contact.jid, contact.resource)
+ if contact.last_activity_time:
+ self.check_last_time = contact.last_activity_time
+ else:
+ self.check_last_time = None
if contact.last_status_time:
vcard_current_row += 1
if contact.show == 'offline':
@@ -541,6 +583,23 @@ class RosterTooltip(NotificationAreaTooltip):
properties.append((_('OpenPGP: '),
gobject.markup_escape_text(keyID)))
+ if contact.last_activity_time:
+ text = _(' since %s')
+
+ if time.strftime('%j', time.localtime())== \
+ time.strftime('%j', contact.last_activity_time):
+ # it's today, show only the locale hour representation
+ local_time = time.strftime('%I:%M %p',
+ contact.last_activity_time)
+ else:
+ # time.strftime returns locale encoded string
+ local_time = time.strftime('%c',
+ contact.last_activity_time)
+ local_time = local_time.decode(
+ locale.getpreferredencoding())
+ text = text % local_time
+ properties.append(('Idle' + text,None))
+
while properties:
property_ = properties.pop(0)
vcard_current_row += 1
@@ -561,7 +620,7 @@ class RosterTooltip(NotificationAreaTooltip):
vcard_current_row + 1, gtk.EXPAND | gtk.FILL,
vertical_fill, 0, 0)
else:
- if isinstance(property_[0], (unicode, str)): #FIXME: rm unicode?
+ if isinstance(property_[0], (unicode, str)): # FIXME: rm unicode?
label.set_markup(property_[0])
label.set_line_wrap(True)
else:
@@ -574,75 +633,46 @@ class RosterTooltip(NotificationAreaTooltip):
vcard_current_row + 1, gtk.FILL, gtk.FILL | gtk.EXPAND, 3, 3)
self.win.add(vcard_table)
+ def update_last_time(self, last_time):
+ if not self.check_last_time or time.strftime('%x %I:%M %p', last_time) !=\
+ time.strftime('%x %I:%M %p', self.check_last_time):
+ self.win.destroy()
+ self.win = None
+ self.populate(self.cur_data)
+ self.win.ensure_style()
+ self.win.show_all()
+
def _append_pep_info(self, contact, properties):
- '''
- Append Tune, Mood, Activity information of the specified contact
+ """
+ Append Tune, Mood, Activity, Location information of the specified contact
to the given property list.
- '''
- if 'mood' in contact.mood:
- mood = contact.mood['mood'].strip()
- mood = MOODS.get(mood, mood)
- mood = gobject.markup_escape_text(mood)
- mood_string = _('Mood:') + ' <b>%s</b>' % mood
- if 'text' in contact.mood \
- and contact.mood['text'] != '':
- mood_text = contact.mood['text'].strip()
- mood_text = \
- gobject.markup_escape_text(mood_text)
- mood_string += ' (%s)' % mood_text
+ """
+ if 'mood' in contact.pep:
+ mood = contact.pep['mood'].asMarkupText()
+ mood_string = _('Mood:') + ' %s' % mood
properties.append((mood_string, None))
- if 'activity' in contact.activity:
- activity = act_plain = \
- contact.activity['activity'].strip()
- activity = gobject.markup_escape_text(activity)
- if act_plain in ACTIVITIES:
- activity = ACTIVITIES[activity]['category']
- activity_string = _('Activity:') + ' <b>%s' % activity
- if 'subactivity' in contact.activity:
- activity_sub = \
- contact.activity['subactivity'].strip()
- if act_plain in ACTIVITIES and activity_sub in \
- ACTIVITIES[act_plain]:
- activity_sub = ACTIVITIES[act_plain][activity_sub]
- activity_sub = \
- gobject.markup_escape_text(activity_sub)
- activity_string += ': %s</b>' % activity_sub
- else:
- activity_string += '</b>'
- if 'text' in contact.activity:
- activity_text = contact.activity['text'].strip()
- activity_text = gobject.markup_escape_text(
- activity_text)
- activity_string += ' (%s)' % activity_text
+ if 'activity' in contact.pep:
+ activity = contact.pep['activity'].asMarkupText()
+ activity_string = _('Activity:') + ' %s' % activity
properties.append((activity_string, None))
- if 'artist' in contact.tune \
- or 'title' in contact.tune:
- if 'artist' in contact.tune:
- artist = contact.tune['artist'].strip()
- artist = gobject.markup_escape_text(artist)
- else:
- artist = _('Unknown Artist')
- if 'title' in contact.tune:
- title = contact.tune['title'].strip()
- title = gobject.markup_escape_text(title)
- else:
- title = _('Unknown Title')
- if 'source' in contact.tune:
- source = contact.tune['source'].strip()
- source = gobject.markup_escape_text(source)
- else:
- source = _('Unknown Source')
- tune_string = _('Tune:') + ' ' + \
- _('<b>"%(title)s"</b> by <i>%(artist)s</i>\n'
- 'from <i>%(source)s</i>') % {'title': title,
- 'artist': artist, 'source': source}
+ if 'tune' in contact.pep:
+ tune = contact.pep['tune'].asMarkupText()
+ tune_string = _('Tune:') + ' %s' % tune
properties.append((tune_string, None))
+ if 'location' in contact.pep:
+ location = contact.pep['location'].asMarkupText()
+ location_string = _('Location:') + ' %s' % location
+ properties.append((location_string, None))
+
class FileTransfersTooltip(BaseTooltip):
- ''' Tooltip that is shown in the notification area '''
+ """
+ Tooltip that is shown in the notification area
+ """
+
def __init__(self):
BaseTooltip.__init__(self)
@@ -726,7 +756,9 @@ class FileTransfersTooltip(BaseTooltip):
class ServiceDiscoveryTooltip(BaseTooltip):
- ''' Tooltip that is shown when hovering over a service discovery row '''
+ """
+ Tooltip that is shown when hovering over a service discovery row
+ """
def populate(self, status):
self.create_window()
label = gtk.Label()