From 5fd5a9bd854b217818516bad8b7d2dde75714a34 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 16 Jun 2016 15:48:29 +0300 Subject: [PATCH] unread messages count --- src/friend.py | 17 +++++++++++++++-- src/list_items.py | 32 ++++++++++++++++++++++++++++++++ src/mainscreen.py | 4 ++-- src/profile.py | 5 +++-- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/friend.py b/src/friend.py index 52e9ac7..97d85ea 100644 --- a/src/friend.py +++ b/src/friend.py @@ -22,7 +22,7 @@ class Friend(contact.Contact): self._message_getter = message_getter self._corr = [] self._unsaved_messages = 0 - self._history_loaded = False + self._history_loaded = self._new_actions = False self._receipts = 0 self._curr_text = '' @@ -39,7 +39,7 @@ class Friend(contact.Contact): def get_receipts(self): return self._receipts - receipts = property(get_receipts) + receipts = property(get_receipts) # read receipts def inc_receipts(self): self._receipts += 1 @@ -184,15 +184,28 @@ class Friend(contact.Contact): # 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): return self._new_messages def inc_messages(self): self._new_messages += 1 + self._new_actions = True self._widget.connection_status.update(self.status, True) + self._widget.messages.update(self._new_messages) def reset_messages(self): + self._new_actions = False self._new_messages = 0 + self._widget.messages.update(self._new_messages) self._widget.connection_status.update(self.status, False) messages = property(get_messages) diff --git a/src/list_items.py b/src/list_items.py index a58c5f5..2ad18ca 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -169,6 +169,8 @@ class ContactItem(QtGui.QWidget): self.status_message.setFont(font) self.connection_status = StatusCircle(self) 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): @@ -201,6 +203,30 @@ class StatusCircle(QtGui.QWidget): 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): 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.state = state + def mark_as_sent(self): + return False + class UnsentFileItem(FileTransferItem): @@ -391,6 +420,9 @@ class InlineImageItem(QtGui.QWidget): self._image_label.setPixmap(pixmap) self.resize(QtCore.QSize(max_size, pixmap.height())) + def mark_as_sent(self): + return False + diff --git a/src/mainscreen.py b/src/mainscreen.py index 2959275..dc62e8c 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -167,7 +167,7 @@ class MainWindow(QtGui.QMainWindow): self.avatar_label.setGeometry(QtCore.QRect(5, 30, 64, 64)) self.avatar_label.setScaledContents(True) 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.setFamily("Times New Roman") font.setPointSize(14) @@ -175,7 +175,7 @@ class MainWindow(QtGui.QMainWindow): Form.name.setFont(font) Form.name.setObjectName("name") 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.setBold(False) Form.status_message.setFont(font) diff --git a/src/profile.py b/src/profile.py index e7398ee..027f57a 100644 --- a/src/profile.py +++ b/src/profile.py @@ -236,6 +236,7 @@ class Profile(contact.Contact, Singleton): message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8) message = message.format(tmp, name) friend.append_message(InfoMessage(message, time.time())) + friend.actions = True if friend.number == self.get_active_number(): self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE']) 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._messages.scrollToBottom() else: - friend.inc_messages() + friend.actions = True 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._messages.scrollToBottom() else: - friend.inc_messages() + friend.actions = True self._call_widget = avwidgets.IncomingCallWidget(friend_number, text, friend.name) self._call_widget.set_pixmap(friend.get_pixmap()) self._call_widget.show()