unread messages count
This commit is contained in:
parent
e75190f767
commit
5fd5a9bd85
4 changed files with 52 additions and 6 deletions
|
@ -22,7 +22,7 @@ class Friend(contact.Contact):
|
||||||
self._message_getter = message_getter
|
self._message_getter = message_getter
|
||||||
self._corr = []
|
self._corr = []
|
||||||
self._unsaved_messages = 0
|
self._unsaved_messages = 0
|
||||||
self._history_loaded = False
|
self._history_loaded = self._new_actions = False
|
||||||
self._receipts = 0
|
self._receipts = 0
|
||||||
self._curr_text = ''
|
self._curr_text = ''
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class Friend(contact.Contact):
|
||||||
def get_receipts(self):
|
def get_receipts(self):
|
||||||
return self._receipts
|
return self._receipts
|
||||||
|
|
||||||
receipts = property(get_receipts)
|
receipts = property(get_receipts) # read receipts
|
||||||
|
|
||||||
def inc_receipts(self):
|
def inc_receipts(self):
|
||||||
self._receipts += 1
|
self._receipts += 1
|
||||||
|
@ -184,15 +184,28 @@ class Friend(contact.Contact):
|
||||||
# Unread messages from friend
|
# Unread messages from friend
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def get_actions(self):
|
||||||
|
return self._new_actions
|
||||||
|
|
||||||
|
def set_actions(self, value):
|
||||||
|
self._new_actions = value
|
||||||
|
self._widget.connection_status.update(self.status, value)
|
||||||
|
|
||||||
|
actions = property(get_actions, set_actions) # unread messages, incoming files, av calls
|
||||||
|
|
||||||
def get_messages(self):
|
def get_messages(self):
|
||||||
return self._new_messages
|
return self._new_messages
|
||||||
|
|
||||||
def inc_messages(self):
|
def inc_messages(self):
|
||||||
self._new_messages += 1
|
self._new_messages += 1
|
||||||
|
self._new_actions = True
|
||||||
self._widget.connection_status.update(self.status, True)
|
self._widget.connection_status.update(self.status, True)
|
||||||
|
self._widget.messages.update(self._new_messages)
|
||||||
|
|
||||||
def reset_messages(self):
|
def reset_messages(self):
|
||||||
|
self._new_actions = False
|
||||||
self._new_messages = 0
|
self._new_messages = 0
|
||||||
|
self._widget.messages.update(self._new_messages)
|
||||||
self._widget.connection_status.update(self.status, False)
|
self._widget.connection_status.update(self.status, False)
|
||||||
|
|
||||||
messages = property(get_messages)
|
messages = property(get_messages)
|
||||||
|
|
|
@ -169,6 +169,8 @@ class ContactItem(QtGui.QWidget):
|
||||||
self.status_message.setFont(font)
|
self.status_message.setFont(font)
|
||||||
self.connection_status = StatusCircle(self)
|
self.connection_status = StatusCircle(self)
|
||||||
self.connection_status.setGeometry(QtCore.QRect(243, 5, 32, 32))
|
self.connection_status.setGeometry(QtCore.QRect(243, 5, 32, 32))
|
||||||
|
self.messages = UnreadMessagesCount(self)
|
||||||
|
self.messages.setGeometry(QtCore.QRect(52, 50, 30, 20))
|
||||||
|
|
||||||
|
|
||||||
class StatusCircle(QtGui.QWidget):
|
class StatusCircle(QtGui.QWidget):
|
||||||
|
@ -201,6 +203,30 @@ class StatusCircle(QtGui.QWidget):
|
||||||
self.label.setPixmap(pixmap)
|
self.label.setPixmap(pixmap)
|
||||||
|
|
||||||
|
|
||||||
|
class UnreadMessagesCount(QtGui.QWidget):
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(UnreadMessagesCount, self).__init__(parent)
|
||||||
|
self.resize(30, 20)
|
||||||
|
self.label = QtGui.QLabel(self)
|
||||||
|
self.label.setGeometry(QtCore.QRect(0, 0, 30, 20))
|
||||||
|
self.label.setVisible(False)
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setFamily("Times New Roman")
|
||||||
|
font.setPointSize(12)
|
||||||
|
font.setBold(True)
|
||||||
|
self.label.setFont(font)
|
||||||
|
self.label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter)
|
||||||
|
self.label.setStyleSheet('QLabel { color: white; background-color: red; border-radius: 10; }')
|
||||||
|
|
||||||
|
def update(self, messages_count):
|
||||||
|
if messages_count:
|
||||||
|
self.label.setVisible(True)
|
||||||
|
self.label.setText(str(messages_count))
|
||||||
|
else:
|
||||||
|
self.label.setVisible(False)
|
||||||
|
|
||||||
|
|
||||||
class FileTransferItem(QtGui.QListWidget):
|
class FileTransferItem(QtGui.QListWidget):
|
||||||
|
|
||||||
def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):
|
def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):
|
||||||
|
@ -356,6 +382,9 @@ class FileTransferItem(QtGui.QListWidget):
|
||||||
self.setStyleSheet('QListWidget { border: 1px solid green; }')
|
self.setStyleSheet('QListWidget { border: 1px solid green; }')
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
|
def mark_as_sent(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class UnsentFileItem(FileTransferItem):
|
class UnsentFileItem(FileTransferItem):
|
||||||
|
|
||||||
|
@ -391,6 +420,9 @@ class InlineImageItem(QtGui.QWidget):
|
||||||
self._image_label.setPixmap(pixmap)
|
self._image_label.setPixmap(pixmap)
|
||||||
self.resize(QtCore.QSize(max_size, pixmap.height()))
|
self.resize(QtCore.QSize(max_size, pixmap.height()))
|
||||||
|
|
||||||
|
def mark_as_sent(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.avatar_label.setGeometry(QtCore.QRect(5, 30, 64, 64))
|
self.avatar_label.setGeometry(QtCore.QRect(5, 30, 64, 64))
|
||||||
self.avatar_label.setScaledContents(True)
|
self.avatar_label.setScaledContents(True)
|
||||||
self.name = Form.name = DataLabel(Form)
|
self.name = Form.name = DataLabel(Form)
|
||||||
Form.name.setGeometry(QtCore.QRect(80, 40, 150, 25))
|
Form.name.setGeometry(QtCore.QRect(75, 40, 150, 25))
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
font.setPointSize(14)
|
font.setPointSize(14)
|
||||||
|
@ -175,7 +175,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
Form.name.setFont(font)
|
Form.name.setFont(font)
|
||||||
Form.name.setObjectName("name")
|
Form.name.setObjectName("name")
|
||||||
self.status_message = Form.status_message = DataLabel(Form)
|
self.status_message = Form.status_message = DataLabel(Form)
|
||||||
Form.status_message.setGeometry(QtCore.QRect(80, 60, 170, 25))
|
Form.status_message.setGeometry(QtCore.QRect(75, 60, 170, 25))
|
||||||
font.setPointSize(12)
|
font.setPointSize(12)
|
||||||
font.setBold(False)
|
font.setBold(False)
|
||||||
Form.status_message.setFont(font)
|
Form.status_message.setFont(font)
|
||||||
|
|
|
@ -236,6 +236,7 @@ class Profile(contact.Contact, Singleton):
|
||||||
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8)
|
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8)
|
||||||
message = message.format(tmp, name)
|
message = message.format(tmp, name)
|
||||||
friend.append_message(InfoMessage(message, time.time()))
|
friend.append_message(InfoMessage(message, time.time()))
|
||||||
|
friend.actions = True
|
||||||
if friend.number == self.get_active_number():
|
if friend.number == self.get_active_number():
|
||||||
self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
|
@ -801,7 +802,7 @@ class Profile(contact.Contact, Singleton):
|
||||||
self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update)
|
self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update)
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
else:
|
else:
|
||||||
friend.inc_messages()
|
friend.actions = True
|
||||||
|
|
||||||
friend.append_message(tm)
|
friend.append_message(tm)
|
||||||
|
|
||||||
|
@ -1070,7 +1071,7 @@ class Profile(contact.Contact, Singleton):
|
||||||
self.create_message_item(text, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
self.create_message_item(text, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
else:
|
else:
|
||||||
friend.inc_messages()
|
friend.actions = True
|
||||||
self._call_widget = avwidgets.IncomingCallWidget(friend_number, text, friend.name)
|
self._call_widget = avwidgets.IncomingCallWidget(friend_number, text, friend.name)
|
||||||
self._call_widget.set_pixmap(friend.get_pixmap())
|
self._call_widget.set_pixmap(friend.get_pixmap())
|
||||||
self._call_widget.show()
|
self._call_widget.show()
|
||||||
|
|
Loading…
Reference in a new issue