Exposing to the user the ability to do partial refreshes
[gc-dialer] / src / gv_views.py
index e6b243b..08de9b7 100644 (file)
@@ -342,8 +342,9 @@ class History(object):
                self._itemView.clear()
 
        def refresh(self, force=True):
+               self._itemView.setFocus(QtCore.Qt.OtherFocusReason)
                self._session.update_history(force)
-               if self._app.notifyOnMissed:
+               if self._app.notifyOnMissed and self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_BACKGROUND:
                        self._app.ledHandler.off()
 
        def _populate_items(self):
@@ -405,7 +406,8 @@ class History(object):
        def _on_row_activated(self, index):
                with qui_utils.notify_error(self._errorLog):
                        timeIndex = index.parent()
-                       assert timeIndex.isValid(), "Invalid row"
+                       if not timeIndex.isValid():
+                               return
                        timeRow = timeIndex.row()
                        row = index.row()
                        detailsItem = self._categoryManager.get_item(timeRow, row, self.DETAILS_IDX)
@@ -449,7 +451,7 @@ class Messages(object):
        ALL_STATUS = "Any"
        MESSAGE_STATUSES = [UNREAD_STATUS, UNARCHIVED_STATUS, ALL_STATUS]
 
-       _MIN_MESSAGES_SHOWN = 4
+       _MIN_MESSAGES_SHOWN = 1
 
        def __init__(self, app, session, errorLog):
                self._selectedTypeFilter = self.ALL_TYPES
@@ -505,6 +507,7 @@ class Messages(object):
                self._itemView.setItemsExpandable(False)
                self._itemView.setItemDelegate(self._htmlDelegate)
                self._itemView.activated.connect(self._on_row_activated)
+               self._itemView.header().sectionResized.connect(self._on_column_resized)
 
                self._layout = QtGui.QVBoxLayout()
                self._layout.addLayout(self._selectionLayout)
@@ -549,8 +552,20 @@ class Messages(object):
                self._itemView.clear()
 
        def refresh(self, force=True):
-               self._session.update_messages(force)
-               if self._app.notifyOnSms or self._app.notifyOnVoicemail:
+               self._itemView.setFocus(QtCore.Qt.OtherFocusReason)
+
+               if self._selectedTypeFilter == self.NO_MESSAGES:
+                       pass
+               elif self._selectedTypeFilter == self.TEXT_MESSAGES:
+                       self._session.update_messages(self._session.MESSAGE_TEXTS, force)
+               elif self._selectedTypeFilter == self.VOICEMAIL_MESSAGES:
+                       self._session.update_messages(self._session.MESSAGE_VOICEMAILS, force)
+               elif self._selectedTypeFilter == self.ALL_TYPES:
+                       self._session.update_messages(self._session.MESSAGE_ALL, force)
+               else:
+                       assert False, "How did we get here?"
+
+               if self._app.notifyOnSms or self._app.notifyOnVoicemail and self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_BACKGROUND:
                        self._app.ledHandler.off()
 
        def _populate_items(self):
@@ -593,11 +608,11 @@ class Messages(object):
                                        for messagePart in messageParts
                                ]
 
-                       firstMessage = "<b>%s - %s</b> <i>(%s)</i>" % (name, prettyNumber, relTime)
+                       firstMessage = "<b>%s<br/>%s</b> <i>(%s)</i>" % (name, prettyNumber, relTime)
 
                        expandedMessages = [firstMessage]
                        expandedMessages.extend(messages)
-                       if (self._MIN_MESSAGES_SHOWN + 1) < len(messages):
+                       if self._MIN_MESSAGES_SHOWN < len(messages):
                                secondMessage = "<i>%d Messages Hidden...</i>" % (len(messages) - self._MIN_MESSAGES_SHOWN, )
                                collapsedMessages = [firstMessage, secondMessage]
                                collapsedMessages.extend(messages[-(self._MIN_MESSAGES_SHOWN+0):])
@@ -647,7 +662,8 @@ class Messages(object):
        def _on_row_activated(self, index):
                with qui_utils.notify_error(self._errorLog):
                        timeIndex = index.parent()
-                       assert timeIndex.isValid(), "Invalid row"
+                       if not timeIndex.isValid():
+                               return
                        timeRow = timeIndex.row()
                        row = index.row()
                        item = self._categoryManager.get_item(timeRow, row, 0)
@@ -666,6 +682,11 @@ class Messages(object):
                        numbersWithDescriptions = [(number, "")]
                        self._session.draft.add_contact(contactId, title, description, numbersWithDescriptions)
 
+       @QtCore.pyqtSlot(QtCore.QModelIndex)
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_column_resized(self, index, oldSize, newSize):
+               self._htmlDelegate.setWidth(newSize, self._itemStore)
+
 
 class Contacts(object):
 
@@ -674,7 +695,7 @@ class Contacts(object):
        def __init__(self, app, session, errorLog):
                self._app = app
                self._session = session
-               self._session.contactsUpdated.connect(self._on_contacts_updated)
+               self._session.accountUpdated.connect(self._on_contacts_updated)
                self._errorLog = errorLog
                self._addressBookFactories = [
                        null_backend.NullAddressBookFactory(),
@@ -754,7 +775,8 @@ class Contacts(object):
                self._itemView.clear()
 
        def refresh(self, force=True):
-               self._backend.update_contacts(force)
+               self._itemView.setFocus(QtCore.Qt.OtherFocusReason)
+               self._backend.update_account(force)
 
        @property
        def _backend(self):
@@ -863,7 +885,8 @@ class Contacts(object):
        def _on_row_activated(self, index):
                with qui_utils.notify_error(self._errorLog):
                        letterIndex = index.parent()
-                       assert letterIndex.isValid(), "Invalid row"
+                       if not letterIndex.isValid():
+                               return
                        letterRow = letterIndex.row()
                        letter = list(self._prefixes())[letterRow]
                        letterItem = self._alphaItem[letter]