예제 #1
0
	def _on_row_activated(self, index):
		with qui_utils.notify_error(self._errorLog):
			timeIndex = index.parent()
			if not timeIndex.isValid():
				return
			timeRow = timeIndex.row()
			row = index.row()
			detailsItem = self._categoryManager.get_item(timeRow, row, self.DETAILS_IDX)
			fromItem = self._categoryManager.get_item(timeRow, row, self.FROM_IDX)
			contactDetails = detailsItem.data()

			title = unicode(fromItem.text())
			number = str(contactDetails["number"])
			contactId = number # ids don't seem too unique so using numbers

			descriptionRows = []
			for t in xrange(self._itemStore.rowCount()):
				randomTimeItem = self._itemStore.item(t, 0)
				for i in xrange(randomTimeItem.rowCount()):
					iItem = randomTimeItem.child(i, 0)
					iContactDetails = iItem.data()
					iNumber = str(iContactDetails["number"])
					if number != iNumber:
						continue
					relTime = misc_utils.abbrev_relative_date(iContactDetails["relTime"])
					action = str(iContactDetails["action"])
					number = str(iContactDetails["number"])
					prettyNumber = misc_utils.make_pretty(number)
					rowItems = relTime, action, prettyNumber
					descriptionRows.append("<tr><td>%s</td></tr>" % "</td><td>".join(rowItems))
			description = "<table>%s</table>" % "".join(descriptionRows)
			numbersWithDescriptions = [(str(contactDetails["number"]), "")]
			self._session.draft.add_contact(contactId, None, title, description, numbersWithDescriptions)
예제 #2
0
	def _populate_items(self):
		self._categoryManager.prepare_for_update(self._session.get_when_messages_updated())

		rawMessages = self._session.get_messages()
		rawMessages.sort(key=lambda item: item["time"], reverse=True)
		for item in rawMessages:
			isUnarchived = not item["isArchived"]
			isUnread = not item["isRead"]
			visibleStatus = {
				self.UNREAD_STATUS: isUnarchived and isUnread,
				self.UNARCHIVED_STATUS: isUnarchived,
				self.ALL_STATUS: True,
			}[self._selectedStatusFilter]
			visibleType = self._selectedTypeFilter in [item["type"], self.ALL_TYPES]
			if not (visibleType and visibleStatus):
				continue

			relTime = misc_utils.abbrev_relative_date(item["relTime"])
			number = item["number"]
			prettyNumber = misc_utils.make_pretty(number)
			name = item["name"]
			if not name or name == number:
				name = item["location"]
			if not name:
				name = "Unknown"

			messageParts = list(item["messageParts"])
			if len(messageParts) == 0:
				messages = ("No Transcription", )
			elif len(messageParts) == 1:
				if messageParts[0][1]:
					messages = (messageParts[0][1], )
				else:
					messages = ("No Transcription", )
			else:
				messages = [
					"<b>%s</b>: %s" % (messagePart[0], messagePart[1])
					for messagePart in messageParts
				]

			firstMessage = "<b>%s<br/>%s</b> <i>(%s)</i>" % (name, prettyNumber, relTime)

			expandedMessages = [firstMessage]
			expandedMessages.extend(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):])
			else:
				collapsedMessages = expandedMessages

			item = dict(item.iteritems())
			item["collapsedMessages"] = "<br/>\n".join(collapsedMessages)
			item["expandedMessages"] = "<br/>\n".join(expandedMessages)

			messageItem = QtGui.QStandardItem(item["collapsedMessages"])
			messageItem.setData(item)
			messageItem.setEditable(False)
			messageItem.setCheckable(False)
			row = (messageItem, )
			self._categoryManager.add_row(item["time"], row)
		self._itemView.expandAll()