Browse Source

Add grid and iterator in the selected message, so it's easier to track

those messages back; delete action uses the grid and iterator to remove
the message from the grid when the operation completes successfully;
the network layer will take care of the favorite status, which will be
returned after the call (in case of error, an exception should be
raised.)
master
Julio Biason 15 years ago
parent
commit
6b5701f10a
  1. 17
      mitterlib/network/__init__.py
  2. 30
      mitterlib/ui/helpers/gtk_messagegrid.py
  3. 31
      mitterlib/ui/ui_pygtk.py

17
mitterlib/network/__init__.py

@ -264,18 +264,23 @@ class Networks(object):
return return
def favouite(self, message): def favouite(self, message):
"""Change the favorite status of the message.""" """Change the favorite status of the message. Returns the new
favorite status."""
assert(isinstance(message, NetworkData)) assert(isinstance(message, NetworkData))
self._proxy() self._proxy()
self.networks[message.network].favorite(message) self.networks[message.network].favorite(message)
self._operations += 1 self._operations += 1
self._save() self._save()
return
# since the operation completed without a problem, we can toggle the
# message as favorited already.
message.favorite = not message.favorite
return message.favorite
def delete_message(self, message, network=None): def delete_message(self, message, network=None):
"""Delete an update. Message can be a NetworkData object, in which """Delete an update. Message can be a :class:`NetworkData` object,
case network is not necessary; otherwise a network must be in which case network is not necessary; otherwise a network must be
provided.""" provided. Always return the same message object"""
if isinstance(message, NetworkData): if isinstance(message, NetworkData):
network = message.network network = message.network
@ -283,7 +288,7 @@ class Networks(object):
self.networks[network].delete_message(message) self.networks[network].delete_message(message)
self._operations += 1 self._operations += 1
self._save() self._save()
return return message
def message(self, message_id, network): def message(self, message_id, network):
"""Return a single NetworkData object for a specified message.""" """Return a single NetworkData object for a specified message."""

30
mitterlib/ui/helpers/gtk_messagegrid.py

@ -95,6 +95,11 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject):
return None return None
data = model.get_value(iter, 0) data = model.get_value(iter, 0)
# just so we can track this message again
data.grid = self
data.iter = iter
return data return data
def __init__(self, avatar_cache): def __init__(self, avatar_cache):
@ -340,6 +345,20 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject):
iter = model.iter_next(iter) iter = model.iter_next(iter)
return return
#-----------------------------------------------------------------------
# Class methods
#-----------------------------------------------------------------------
@staticmethod
def delete(self, message):
"""Removes a message from the grid."""
if not hasattr(message, 'grid'):
_log.debug('No grid information in the message')
return
grid = message.grid
grid.remove(message)
return
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# Public functions # Public functions
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
@ -384,3 +403,14 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject):
"""Make the grid to be redraw when possible.""" """Make the grid to be redraw when possible."""
# we need this 'cause _grid is not exposed. # we need this 'cause _grid is not exposed.
self._grid.queue_draw() self._grid.queue_draw()
return
def remove(self, message):
"""Remove a message from the list"""
if not hasattr(message, 'iter'):
_log.debug('No iterator information in the message')
return
iter = message.iter
self._grid.get_model().remove(iter)
return

31
mitterlib/ui/ui_pygtk.py

@ -494,7 +494,6 @@ class Interface(object):
def _clear_text(self, widget): def _clear_text(self, widget):
"""Clear the text field.""" """Clear the text field."""
self._delete_info = None
self._clear_reply() self._clear_reply()
self._update_field.hide() self._update_field.hide()
@ -537,9 +536,10 @@ class Interface(object):
def _delete_message(self, widget, user_data=None): def _delete_message(self, widget, user_data=None):
"""Delete a message.""" """Delete a message."""
(grid, counter) = self._grids[self._main_tabs.get_current_page()] page = self._main_tabs.get_current_page()
(model, iter) = grid.get_selection().get_selected() message = self._main_tabs.get_nth_page(page).selected
message = model.get_value(iter, 0) if not message:
return
confirm = gtk.MessageDialog(parent=self._main_window, confirm = gtk.MessageDialog(parent=self._main_window,
type=gtk.MESSAGE_QUESTION, type=gtk.MESSAGE_QUESTION,
@ -554,7 +554,6 @@ class Interface(object):
return False return False
self._update_statusbar(_('Deleting message...')) self._update_statusbar(_('Deleting message...'))
self._delete_info = (grid, iter)
_log.debug('Deleting messing %d', message.id) _log.debug('Deleting messing %d', message.id)
self._threads.add_work(self._post_delete_message, self._threads.add_work(self._post_delete_message,
self._exception_delete_message, self._exception_delete_message,
@ -857,13 +856,11 @@ class Interface(object):
return return
### Results for the delete message call ### Results for the delete message call
def _post_delete_message(self, widget, data): def _post_delete_message(self, widget, message):
"""Called when the message is deleted successfully.""" """Called when the message is deleted successfully."""
_log.debug('Message deleted.') _log.debug('Message deleted.')
if self._delete_info: # any grid can take care of deleting the message
(grid, iter) = self._delete_info MessageGrid.delete(message)
grid.get_model().remove(iter)
self._delete_info = None
self._update_statusbar(_('Message deleted.')) self._update_statusbar(_('Message deleted.'))
return return
@ -895,18 +892,14 @@ class Interface(object):
return return
### Results from the favorite call ### Results from the favorite call
def _post_favorite_message(self, widget, data): def _post_favorite_message(self, widget, status):
"""Called when the message was favorited successfully.""" """Called when the message was favorited successfully."""
_log.debug('Favorite status changed.') _log.debug('Favorite status changed.')
(grid, iter) = self._favorite_info if status:
message = grid.get_model().get_value(iter, 0)
if message.favorite:
display = _('Message unfavorited.')
else:
display = _('Message favorited.') display = _('Message favorited.')
else:
display = _('Message unfavorited.')
self._update_statusbar(display) self._update_statusbar(display)
message.favorite = not message.favorite
self._favorite_info = None
return return
def _exception_favorite_message(self, widget, exception): def _exception_favorite_message(self, widget, exception):
@ -957,9 +950,7 @@ class Interface(object):
# This is the ugly bit for speeding up things and making # This is the ugly bit for speeding up things and making
# interthread communication. # interthread communication.
self._delete_info = None
self._reply_message_id = None self._reply_message_id = None
self._favorite_info = None
return return

Loading…
Cancel
Save