searching in history is in. not yet 100% functionality

This commit is contained in:
Nikos Kouremenos 2005-11-29 14:41:01 +00:00
parent dfb9d92619
commit e542fff69f
3 changed files with 306 additions and 3 deletions

View File

@ -321,6 +321,30 @@ class Logger:
results = cur.fetchall() results = cur.fetchall()
return results return results
def get_search_results_for_query(self, jid, query):
'''returns contact_name, time, kind, show, message
for each row in a list of tupples,
returns list with empty tupple if we found nothing to meet our demands'''
jid = jid.lower()
jid_id = self.get_jid_id(jid)
if False: #query.startswith('SELECT '): # it's SQL query
try:
cur.execute(query)
except sqlite.OperationalError, e:
results = [('', '', '', '', str(e))]
return results
else: # user just typed something, we search in message column
like_sql = '%' + query + '%'
cur.execute('''
SELECT contact_name, time, kind, show, message FROM logs
WHERE jid_id = ? AND message LIKE ?
ORDER BY time
''', (jid_id,like_sql))
results = cur.fetchall()
return results
def date_has_logs(self, jid, year, month, day): 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 for given day, else False'''
jid = jid.lower() jid = jid.lower()

View File

@ -9070,11 +9070,218 @@ Custom</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkExpander" id="search_expander">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="expanded">False</property>
<property name="spacing">0</property>
<signal name="activate" handler="on_search_expander_activate" last_modification_time="Tue, 29 Nov 2005 13:43:41 GMT"/>
<child>
<widget class="GtkVBox" id="expander_vbox">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<widget class="GtkHBox" id="query_hbox">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<widget class="GtkEntry" id="query_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="search_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_search_button_clicked" last_modification_time="Tue, 29 Nov 2005 11:40:15 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment97">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox3002">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1325">
<property name="visible">True</property>
<property name="stock">gtk-find</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label369">
<property name="visible">True</property>
<property name="label">Search</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="query_builder_button">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Build custom query</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Query Builder...</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_query_builder_button_clicked" last_modification_time="Tue, 29 Nov 2005 11:40:18 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="results_scrolledwindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="results_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">True</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label368">
<property name="visible">True</property>
<property name="label" translatable="yes">_Search</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child> <child>
<widget class="GtkHButtonBox" id="hbuttonbox"> <widget class="GtkHButtonBox" id="hbuttonbox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property> <property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">0</property> <property name="spacing">6</property>
<child> <child>
<widget class="GtkButton" id="close_button"> <widget class="GtkButton" id="close_button">
@ -9092,7 +9299,7 @@ Custom</property>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View File

@ -41,6 +41,15 @@ gtk.glade.textdomain(APP)
GTKGUI_GLADE = 'gtkgui.glade' GTKGUI_GLADE = 'gtkgui.glade'
# contact_name, time, kind, show, message
(
C_CONTACT_NAME,
C_TIME,
C_KIND,
C_SHOW,
C_MESSAGE
) = range(5)
class HistoryWindow: class HistoryWindow:
'''Class for browsing logs of conversations with contacts''' '''Class for browsing logs of conversations with contacts'''
@ -51,6 +60,42 @@ class HistoryWindow:
xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP) xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP)
self.window = xml.get_widget('history_window') self.window = xml.get_widget('history_window')
self.query_entry = xml.get_widget('query_entry')
self.expander_vbox = xml.get_widget('expander_vbox')
self.results_treeview = xml.get_widget('results_treeview')
# contact_name, time, kind, show, message
model = gtk.ListStore(str, str, str, str, str)
self.results_treeview.set_model(model)
col = gtk.TreeViewColumn(_('Name'))
self.results_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = C_CONTACT_NAME)
col = gtk.TreeViewColumn(_('Date'))
self.results_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = C_TIME)
col = gtk.TreeViewColumn(_('Kind'))
self.results_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = C_KIND)
col = gtk.TreeViewColumn(_('Status'))
self.results_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = C_SHOW)
col = gtk.TreeViewColumn(_('Message'))
self.results_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = C_MESSAGE)
if account and gajim.contacts[account].has_key(jid): if account and gajim.contacts[account].has_key(jid):
contact = gajim.get_first_contact_instance_from_jid(account, jid) contact = gajim.get_first_contact_instance_from_jid(account, jid)
@ -212,3 +257,30 @@ class HistoryWindow:
buf.insert_with_tags_by_name(end_iter, message, tag_msg) buf.insert_with_tags_by_name(end_iter, message, tag_msg)
else: else:
buf.insert(end_iter, message) buf.insert(end_iter, message)
def set_unset_expand_on_expander(self, widget):
'''expander has to have expand to TRUE so scrolledwindow resizes properly
and does not have a static size. when expander is not expanded we set
expand property (note the Box one) to FALSE
to do this, we first get the box and then apply to expander widget
the True/False thingy depending if it's expanded or not
this function is called in a timeout just after expanded state changes'''
parent = widget.get_parent() # vbox
parent.child_set_property(widget, 'expand', widget.get_expanded())
def on_search_expander_activate(self, widget):
if widget.get_expanded(): # it's the OPPOSITE!, it's not expanded
gobject.timeout_add(200, self.set_unset_expand_on_expander, widget)
else:
gobject.timeout_add(200, self.set_unset_expand_on_expander, widget)
def on_search_button_clicked(self, widget):
text = self.query_entry.get_text()
# contact_name, time, kind, show, message
results = gajim.logger.get_search_results_for_query(self.jid, text)
model = self.results_treeview.get_model()
model.clear()
for row in results:
iter = model.append((row[0], row[1], row[2], row[3], row[4]))