Cleaned the code for the 'Idle since' tooltip item

This commit is contained in:
Alexander Cherniuk 2010-03-30 15:27:59 +03:00
parent 666c089bcc
commit cc7eb2ae96

View file

@ -33,6 +33,7 @@ import gobject
import os import os
import time import time
import locale import locale
from datetime import datetime
import gtkgui_helpers import gtkgui_helpers
@ -584,21 +585,17 @@ class RosterTooltip(NotificationAreaTooltip):
gobject.markup_escape_text(keyID))) gobject.markup_escape_text(keyID)))
if contact.last_activity_time: if contact.last_activity_time:
text = _(' since %s') text = _("Idle since: %s")
if time.strftime('%j', time.localtime())== \ last_active = datetime(*contact.last_activity_time[:6])
time.strftime('%j', contact.last_activity_time): current = datetime.now()
# it's today, show only the locale hour representation
local_time = time.strftime('%I:%M %p', if last_active.date() == current.date():
contact.last_activity_time) formatted = last_active.strftime("%X")
else: else:
# time.strftime returns locale encoded string formatted = last_active.strftime("%c")
local_time = time.strftime('%c',
contact.last_activity_time) properties.append((text % formatted, None))
local_time = local_time.decode(
locale.getpreferredencoding())
text = text % local_time
properties.append(('Idle' + text, None))
while properties: while properties:
property_ = properties.pop(0) property_ = properties.pop(0)