we can now export from history manager to txt

This commit is contained in:
Nikos Kouremenos 2006-02-10 16:01:47 +00:00
parent 2c7999af67
commit 04c5d6bfae
3 changed files with 213 additions and 33 deletions

View File

@ -54,6 +54,7 @@
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
<signal name="key_press_event" handler="on_jids_listview_key_press_event" last_modification_time="Sat, 04 Feb 2006 22:27:05 GMT"/>
<signal name="button_press_event" handler="on_jids_listview_button_press_event" last_modification_time="Fri, 10 Feb 2006 15:11:21 GMT"/>
</widget>
</child>
</widget>
@ -287,4 +288,103 @@ You can select logs from the left and/or search database from below.
</child>
</widget>
<widget class="GtkMenu" id="context_menu">
<child>
<widget class="GtkMenuItem" id="export_menuitem">
<property name="visible">True</property>
<property name="label" translatable="yes">Export</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_export_menuitem_activate" last_modification_time="Fri, 10 Feb 2006 15:15:30 GMT"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="delete_menuitem">
<property name="visible">True</property>
<property name="label" translatable="yes">Delete</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_delete_menuitem_activate" last_modification_time="Fri, 10 Feb 2006 15:20:26 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
</widget>
<widget class="GtkFileChooserDialog" id="filechooserdialog">
<property name="action">GTK_FILE_CHOOSER_ACTION_SAVE</property>
<property name="local_only">True</property>
<property name="select_multiple">False</property>
<property name="show_hidden">False</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">24</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancel_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="save_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="label">gtk-save</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -335,50 +335,130 @@ class HistoryManager:
self.con.commit()
self.AT_LEAST_ONE_DELETION_DONE = True
def on_jids_listview_button_press_event(self, widget, event):
if event.button == 3: # right click
xml = gtk.glade.XML('history_manager.glade', 'context_menu', i18n.APP)
liststore, list_of_paths = self.jids_listview.get_selection()\
.get_selected_rows()
xml.signal_autoconnect(self)
xml.get_widget('context_menu').popup(None, None, None,
event.button, event.time)
def on_export_menuitem_activate(self, widget):
xml = gtk.glade.XML('history_manager.glade', 'filechooserdialog', i18n.APP)
xml.signal_autoconnect(self)
dlg = xml.get_widget('filechooserdialog')
response = dlg.run()
if response == gtk.RESPONSE_OK: # user want us to export ;)
liststore, list_of_paths = self.jids_listview.get_selection()\
.get_selected_rows()
path_to_file = dlg.get_filename()
self._export_jids_logs_to_file(liststore, list_of_paths, path_to_file)
dlg.destroy()
def on_delete_menuitem_activate(self, widget):
liststore, list_of_paths = self.jids_listview.get_selection()\
.get_selected_rows()
self._delete_jid_logs(liststore, list_of_paths)
def on_jids_listview_key_press_event(self, widget, event):
liststore, list_of_paths = self.jids_listview.get_selection()\
.get_selected_rows()
if event.keyval == gtk.keysyms.Delete:
self._delete_jid_logs(liststore, list_of_paths)
def _export_jids_logs_to_file(self, liststore, list_of_paths, path_to_file):
paths_len = len(list_of_paths)
if paths_len == 0: # nothing is selected
return
if event.keyval == gtk.keysyms.Delete:
pri_text = i18n.ngettext(
'Do you really want to delete logs of the selected contact?',
'Do you really want to delete logs of the selected contacts?',
paths_len)
dialog = dialogs.ConfirmationDialog(pri_text,
_('This is an irreversible operation.'))
if dialog.get_response() != gtk.RESPONSE_OK:
return
# NOTE: it's impossible to have more than one selected and right click
# on a row and still have all those selected. Thank GTK God for that ;)
list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed)
list_of_rowrefs.append(gtk.TreeRowReference(liststore, path))
for rowref in list_of_rowrefs:
path = rowref.get_path()
if path is None:
continue
jid_id = liststore[path][1]
self.cur.execute('''
SELECT time, kind, message FROM logs
WHERE jid_id = ?
ORDER BY time
''', (jid_id,))
results = self.cur.fetchall()
file_ = open(path_to_file, 'w')
for row in results:
# FIXME: check kind and say You or JID
# in store: time, kind, message FROM logs
# in text: JID or You, time, message
time_ = row[0]
kind = row[1]
if kind in (constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV):
who = self._get_jid_from_jid_id(jid_id)
elif kind in (constants.KIND_SINGLE_MSG_SENT,
constants.KIND_CHAT_MSG_SENT):
who = _('You')
else:
continue
# delete all rows from db that match jid_id
list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed)
list_of_rowrefs.append(gtk.TreeRowReference(liststore, path))
for rowref in list_of_rowrefs:
path = rowref.get_path()
if path is None:
continue
jid_id = liststore[path][1]
del liststore[path] # remove from UI
# remove from db
self.cur.execute('''
DELETE FROM logs
message = row[2]
try:
time_ = time.strftime('%x', time.localtime(float(time_)))
except ValueError:
pass
file_.write(_('%(who)s on %(time)s said: %(message)s\n' % {'who': who,
'time': time_, 'message': message}))
def _delete_jid_logs(self, liststore, list_of_paths):
paths_len = len(list_of_paths)
if paths_len == 0: # nothing is selected
return
pri_text = i18n.ngettext(
'Do you really want to delete logs of the selected contact?',
'Do you really want to delete logs of the selected contacts?',
paths_len)
dialog = dialogs.ConfirmationDialog(pri_text,
_('This is an irreversible operation.'))
if dialog.get_response() != gtk.RESPONSE_OK:
return
# delete all rows from db that match jid_id
list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed)
list_of_rowrefs.append(gtk.TreeRowReference(liststore, path))
for rowref in list_of_rowrefs:
path = rowref.get_path()
if path is None:
continue
jid_id = liststore[path][1]
del liststore[path] # remove from UI
# remove from db
self.cur.execute('''
DELETE FROM logs
WHERE jid_id = ?
''', (jid_id,))
# now delete "jid, jid_id" row from jids table
self.cur.execute('''
DELETE FROM jids
WHERE jid_id = ?
''', (jid_id,))
# now delete "jid, jid_id" row from jids table
self.cur.execute('''
DELETE FROM jids
WHERE jid_id = ?
''', (jid_id,))
self.con.commit()
self.con.commit()
self.AT_LEAST_ONE_DELETION_DONE = True
self.AT_LEAST_ONE_DELETION_DONE = True
def on_search_db_button_clicked(self, widget):
text = self.search_entry.get_text()

View File

@ -163,7 +163,7 @@ class MessageWindow:
self.show_title()
def on_tab_eventbox_button_press_event(self, widget, event, child):
if event.button == 3:
if event.button == 3: # right click
n = self.notebook.page_num(child)
self.notebook.set_current_page(n)
self.popup_menu(event)