Updating the SMS window on refreshes
authorEd Page <eopage@byu.net>
Fri, 18 Feb 2011 23:34:05 +0000 (17:34 -0600)
committerEd Page <eopage@byu.net>
Fri, 18 Feb 2011 23:34:05 +0000 (17:34 -0600)
src/dialogs.py

index 7481afe..0312ee6 100644 (file)
@@ -514,6 +514,8 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
        def __init__(self, parent, app, session, errorLog):
                qwrappers.WindowWrapper.__init__(self, parent, app)
                self._session = session
+               self._session.messagesUpdated.connect(self._on_refresh_history)
+               self._session.historyUpdated.connect(self._on_refresh_history)
                self._session.draft.recipientsChanged.connect(self._on_recipients_changed)
 
                self._session.draft.sendingMessage.connect(self._on_op_started)
@@ -606,6 +608,8 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        _moduleLogger.exception("Oh well")
 
        def destroy(self):
+               self._session.messagesUpdated.disconnect(self._on_refresh_history)
+               self._session.historyUpdated.disconnect(self._on_refresh_history)
                self._session.draft.recipientsChanged.disconnect(self._on_recipients_changed)
                self._session.draft.sendingMessage.disconnect(self._on_op_started)
                self._session.draft.calling.disconnect(self._on_op_started)
@@ -657,6 +661,21 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                        else:
                                self._smsButton.setEnabled(True)
 
+       def _update_history(self, cid):
+               draftContactsCount = self._session.draft.get_num_contacts()
+               if draftContactsCount != 1:
+                       self._history.setVisible(False)
+               else:
+                       description = self._session.draft.get_description(cid)
+
+                       self._targetList.setVisible(False)
+                       if description:
+                               self._history.setText(description)
+                               self._history.setVisible(True)
+                       else:
+                               self._history.setText("")
+                               self._history.setVisible(False)
+
        def _update_target_fields(self):
                draftContactsCount = self._session.draft.get_num_contacts()
                if draftContactsCount == 0:
@@ -665,16 +684,10 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
                elif draftContactsCount == 1:
                        (cid, ) = self._session.draft.get_contacts()
                        title = self._session.draft.get_title(cid)
-                       description = self._session.draft.get_description(cid)
                        numbers = self._session.draft.get_numbers(cid)
 
                        self._targetList.setVisible(False)
-                       if description:
-                               self._history.setText(description)
-                               self._history.setVisible(True)
-                       else:
-                               self._history.setText("")
-                               self._history.setVisible(False)
+                       self._update_history(cid)
                        self._populate_number_selector(self._singleNumberSelector, cid, 0, numbers)
                        self._cids = [cid]
 
@@ -762,6 +775,16 @@ class SMSEntryWindow(qwrappers.WindowWrapper):
 
        @QtCore.pyqtSlot()
        @misc_utils.log_exception(_moduleLogger)
+       def _on_refresh_history(self):
+               draftContactsCount = self._session.draft.get_num_contacts()
+               if draftContactsCount != 1:
+                       # Changing contact count will automatically refresh it
+                       return
+               (cid, ) = self._session.draft.get_contacts()
+               self._update_history(cid)
+
+       @QtCore.pyqtSlot()
+       @misc_utils.log_exception(_moduleLogger)
        def _on_recipients_changed(self):
                with qui_utils.notify_error(self._app.errorLog):
                        self._update_target_fields()