Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pippy_app.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/pippy_app.py b/pippy_app.py
index d44a396..3be11c6 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -21,6 +21,7 @@ import pango
import logging
import re
import simplejson
+import time
from datetime import datetime
from activity import ViewSourceActivity
@@ -32,6 +33,7 @@ from sugar.graphics.roundbox import CanvasRoundBox
from sugar.graphics.xocolor import XoColor
from sugar.graphics.palette import Palette, CanvasInvoker
from sugar.graphics.menuitem import MenuItem
+from sugar.util import timestamp_to_elapsed_string
from telepathy.client import Connection, Channel
from telepathy.interfaces import (
@@ -393,8 +395,15 @@ class Chat(ViewSourceActivity):
def add_separator(self, timestamp):
"""Add whitespace and timestamp between chat sessions."""
box = hippo.CanvasBox(padding=2)
+ time_with_current_year = (time.localtime(time.time())[0],) +\
+ time.strptime(timestamp, "%b %d %H:%M:%S")[1:]
+ timestamp_seconds = time.mktime(time_with_current_year)
+ if timestamp_seconds > time.time():
+ time_with_previous_year = (time.localtime(time.time())[0]-1,) +\
+ time.strptime(timestamp, "%b %d %H:%M:%S")[1:]
+ timestamp_seconds = time.mktime(time_with_previous_year)
message = hippo.CanvasText(
- text=timestamp,
+ text=timestamp_to_elapsed_string(timestamp_seconds),
color=COLOR_BUTTON_GREY.get_int(),
font_desc=FONT_NORMAL.get_pango_desc(),
xalign=hippo.ALIGNMENT_CENTER)
@@ -460,15 +469,19 @@ class Chat(ViewSourceActivity):
"""
logger.debug('read_file: reading %s' % file_path)
log = open(file_path).readlines()
+ last_line_was_timestamp = False
for line in log:
if line.endswith('\t\t\n'):
- timestamp = line.strip().split('\t')[0]
- self.add_separator(timestamp)
+ if last_line_was_timestamp is False:
+ timestamp = line.strip().split('\t')[0]
+ self.add_separator(timestamp)
+ last_line_was_timestamp = True
else:
timestamp, nick, color, status, text = line.strip().split('\t')
status_message = bool(int(status))
self.add_text({'nick': nick, 'color': color},
text, status_message)
+ last_line_was_timestamp = False
def _show_via_journal(self, url):
"""Ask the journal to display a URL"""