Beispiel #1
0
	def _on_sms_clicked(self, checked = False):
		with qui_utils.notify_error(self._errorLog):
			number = misc_utils.make_ugly(str(self._entry.text()))
			self._entry.clear()

			contactId = number
			title = misc_utils.make_pretty(number)
			description = misc_utils.make_pretty(number)
			numbersWithDescriptions = [(number, "")]
			self._session.draft.add_contact(contactId, None, title, description, numbersWithDescriptions)
Beispiel #2
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)
Beispiel #3
0
	def set_callbacks(self, choices, default):
		self._callbackSelector.clear()

		self._callbackSelector.addItem("Not Set", "")

		uglyDefault = misc_utils.make_ugly(default)
		if not uglyDefault:
			uglyDefault = default
		for number, description in choices.iteritems():
			prettyNumber = misc_utils.make_pretty(number)
			uglyNumber = misc_utils.make_ugly(number)
			if not uglyNumber:
				prettyNumber = number
				uglyNumber = number

			self._callbackSelector.addItem("%s - %s" % (prettyNumber, description), uglyNumber)
			if uglyNumber == uglyDefault:
				self._callbackSelector.setCurrentIndex(self._callbackSelector.count() - 1)
Beispiel #4
0
	def _populate_number_selector(self, selector, cid, cidIndex, numbers):
		selector.clear()

		selectedNumber = self._session.draft.get_selected_number(cid)
		if len(numbers) == 1:
			# If no alt numbers available, check the address book
			numbers, defaultIndex = _get_contact_numbers(self._session, cid, selectedNumber, numbers[0][1])
		else:
			defaultIndex = _index_number(numbers, selectedNumber)

		for number, description in numbers:
			prettyNumber = misc_utils.make_pretty(number)
			if description:
				label = "%s - %s" % (prettyNumber, description)
			else:
				label = prettyNumber
			selector.addItem(label)
		selector.setVisible(True)
		if 1 < len(numbers):
			selector.setEnabled(True)
			selector.setCurrentIndex(defaultIndex)
		else:
			selector.setEnabled(False)
Beispiel #5
0
	def _populate_items(self):
		self._categoryManager.prepare_for_update(self._session.get_when_history_updated())

		history = self._session.get_history()
		history.sort(key=lambda item: item["time"], reverse=True)
		for event in history:
			if self._selectedFilter not in [self.HISTORY_ITEM_TYPES[-1], event["action"]]:
				continue

			relTime = event["relTime"]
			action = event["action"]
			number = event["number"]
			prettyNumber = misc_utils.make_pretty(number)
			if prettyNumber.startswith("+1 "):
				prettyNumber = prettyNumber[len("+1 "):]
			name = event["name"]
			if not name or name == number:
				name = event["location"]
			if not name:
				name = "Unknown"

			detailsItem = QtGui.QStandardItem(self._actionIcon[action], "%s\n%s" % (prettyNumber, relTime))
			detailsFont = detailsItem.font()
			detailsFont.setPointSize(max(detailsFont.pointSize() - 6, 5))
			detailsItem.setFont(detailsFont)
			nameItem = QtGui.QStandardItem(name)
			nameFont = nameItem.font()
			nameFont.setPointSize(nameFont.pointSize() + 4)
			nameItem.setFont(nameFont)
			row = detailsItem, nameItem
			for item in row:
				item.setEditable(False)
				item.setCheckable(False)
			row[self.DETAILS_IDX].setData(event)
			self._categoryManager.add_row(event["time"], row)
		self._itemView.expandAll()
Beispiel #6
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()