select last day we have logs for in history browser

This commit is contained in:
Nikos Kouremenos 2005-11-30 21:56:42 +00:00
parent f9543aed35
commit e162e5daed
2 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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()