initial stuff at mark day that has logs. atm it is slow and has some bugs I will fix soon. I commit this nonetheless

This commit is contained in:
Nikos Kouremenos 2005-11-24 01:39:47 +00:00
parent 117f7e9999
commit fb07453d57
4 changed files with 54 additions and 5 deletions

View File

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

View File

@ -9007,6 +9007,7 @@ Custom</property>
<property name="can_focus">True</property>
<property name="display_options">GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES</property>
<signal name="day_selected" handler="on_calendar_day_selected" last_modification_time="Sun, 20 Nov 2005 19:26:58 GMT"/>
<signal name="month_changed" handler="on_calendar_month_changed" last_modification_time="Thu, 24 Nov 2005 00:49:22 GMT"/>
</widget>
<packing>
<property name="shrink">True</property>

View File

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

View File

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