From fb07453d57d3326bb5727dc86a40367cb42547d5 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Thu, 24 Nov 2005 01:39:47 +0000 Subject: [PATCH] initial stuff at mark day that has logs. atm it is slow and has some bugs I will fix soon. I commit this nonetheless --- src/common/logger.py | 41 ++++++++++++++++++++++++++++++++++++----- src/gtkgui.glade | 1 + src/gtkgui_helpers.py | 3 +++ src/history_window.py | 14 ++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index fabb77f3c..662cff120 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -206,7 +206,16 @@ class Logger: results = cur.fetchall() results.reverse() return results - + + def get_unix_time_from_date(self, year, month, day): + # year (fe 2005), month (fe 11), day (fe 25) + # returns time in seconds for the second that starts that date since epoch + # gimme unixtime from year month day: + d = datetime.date(year, month, day) + local_time = d.timetuple() # time tupple (compat with time.localtime()) + start_of_day = int(time.mktime(local_time)) # we have time since epoch baby :) + return start_of_day + def get_conversation_for_date(self, jid, year, month, day): '''returns contact_name, time, kind, show, message for each row in a list of tupples, @@ -214,10 +223,7 @@ class Logger: jid = jid.lower() jid_id = self.get_jid_id(jid) - # gimme unixtime from year month day: - d = datetime.date(year, month, day) - local_time = d.timetuple() # time tupple (compat with time.localtime()) - start_of_day = int(time.mktime(local_time)) # we have time since epoch baby :) + start_of_day = self.get_unix_time_from_date(year, month, day) now = int(time.time()) @@ -232,3 +238,28 @@ class Logger: 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''' + jid = jid.lower() + jid_id = self.get_jid_id(jid) + + start_of_day = self.get_unix_time_from_date(year, month, day) + seconds_in_a_day = 86400 # 60 * 60 * 24 + last_second_of_day = start_of_day + seconds_in_a_day - 1 + + con = sqlite.connect(LOG_DB_PATH) + cur = con.cursor() + # just ask one row to see if we have sth for this date + cur.execute(''' + SELECT log_line_id FROM logs + WHERE jid_id = %d + AND time BETWEEN %d AND %d + ORDER BY time LIMIT 1 + ''' % (jid_id, start_of_day, last_second_of_day)) + + results = cur.fetchone() + if results: + return True + else: + return False diff --git a/src/gtkgui.glade b/src/gtkgui.glade index aeb08f879..ef7830d01 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -9007,6 +9007,7 @@ Custom True GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES + True diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 0f03f3715..e456f987b 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -442,3 +442,6 @@ def make_gtk_month_python_month(month): but python's time start from 1, so align to python month MUST be integer''' return month + 1 + +def make_python_month_gtk_month(month): + return month - 1 diff --git a/src/history_window.py b/src/history_window.py index e629dba94..6556b4160 100644 --- a/src/history_window.py +++ b/src/history_window.py @@ -20,6 +20,7 @@ import gtk import gtk.glade import time +import calendar import os import gtkgui_helpers @@ -81,6 +82,19 @@ class HistoryWindow: year, month, day = widget.get_date() # integers month = gtkgui_helpers.make_gtk_month_python_month(month) self.add_lines_for_date(year, month, day) + + def on_calendar_month_changed(self, widget): + year, month, day = widget.get_date() # integers + month = gtkgui_helpers.make_gtk_month_python_month(month) + weekday, days_in_this_month = calendar.monthrange(year, month) + for day in xrange(1, days_in_this_month + 1): # count from 1, so add 1 more + #FIXME: optimize (ask db once per month and store days that have logs) + # return those here in tupple + #print 'ask', year, month, day + if gajim.logger.date_has_logs(self.jid, year, month, day): + widget.mark_day(day) + else: + widget.unmark_day(day) def add_lines_for_date(self, year, month, day): '''adds all the lines for given date in textbuffer'''