From e162e5daed829243c44f43c55d1b1a2c2c9cb092 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Wed, 30 Nov 2005 21:56:42 +0000 Subject: [PATCH] select last day we have logs for in history browser --- src/common/logger.py | 23 +++++++++++++++++++---- src/history_window.py | 10 +++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 3342a3c6e..8e360cc33 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -339,13 +339,14 @@ class Logger: SELECT contact_name, time, kind, show, message, subject FROM logs WHERE jid_id = ? AND message LIKE ? ORDER BY time - ''', (jid_id,like_sql)) + ''', (jid_id, like_sql)) results = cur.fetchall() return results def date_has_logs(self, jid, year, month, day): - '''returns True if we have logs for given day, else False''' + '''returns True if we have logs (excluding statuses) for given date, + else False''' jid = jid.lower() jid_id = self.get_jid_id(jid) @@ -362,8 +363,22 @@ class Logger: LIMIT 1 ''' % (jid_id, start_of_day, last_second_of_day, constants.KIND_STATUS, constants.KIND_GCSTATUS)) - results = cur.fetchone() - if results: + result = cur.fetchone() + if result: return True else: return False + + def get_last_date_that_has_logs(self, jid): + '''returns last time (in seconds since EPOCH) for which + we had logs (excluding statuses)''' + jid = jid.lower() + jid_id = self.get_jid_id(jid) + cur.execute(''' + SELECT time FROM logs + WHERE jid_id = ? + AND kind NOT IN (?, ?) + ORDER BY time DESC LIMIT 1 + ''', (jid_id, constants.KIND_STATUS, constants.KIND_GCSTATUS)) + result = cur.fetchone() + return result diff --git a/src/history_window.py b/src/history_window.py index f646eb43b..f2f33ba44 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -117,8 +117,16 @@ class HistoryWindow: tag.set_property('foreground', 'grey') tag.set_property('justification', gtk.JUSTIFY_CENTER) - date = time.localtime() + # select and show logs for last date we have logs with contact + # and if we don't have logs at all, default to today + result = gajim.logger.get_last_date_that_has_logs(self.jid) + tim = result[0] + if tim != '': + date = time.localtime(tim) + else: + date = time.localtime() y, m, d = date[0], date[1], date[2] + self.calendar.select_day(d) self.add_lines_for_date(y, m, d) self.window.show_all()