ui: info messages and fixes

This commit is contained in:
ingvar1995 2016-06-13 19:28:17 +03:00
parent 9bf072e122
commit f6affc14ef
7 changed files with 89 additions and 26 deletions

View File

@ -94,11 +94,9 @@ def friend_name(tox, friend_num, name, size, user_data):
Friend changed his name
"""
profile = Profile.get_instance()
friend = profile.get_friend_by_number(friend_num)
print 'New name: ', str(friend_num), str(name)
invoke_in_main_thread(friend.set_name, name)
if profile.get_active_number() == friend_num:
invoke_in_main_thread(profile.set_active)
invoke_in_main_thread(profile.new_name, friend_num, name)
def friend_status_message(tox, friend_num, status_message, size, user_data):
@ -279,7 +277,7 @@ def callback_audio(toxav, friend_number, samples, audio_samples_per_channel, aud
"""
New audio chunk
"""
print audio_samples_per_channel, audio_channels_count, rate
# print audio_samples_per_channel, audio_channels_count, rate
Profile.get_instance().call.chunk(
''.join(chr(x) for x in samples[:audio_samples_per_channel * 2 * audio_channels_count]),
audio_channels_count,

View File

@ -4,6 +4,7 @@ import threading
import settings
from toxav_enums import *
# TODO: play sound until outgoing call will be started or cancelled and add timeout
# TODO: add widget for call
CALL_TYPE = {
'NONE': 0,

View File

@ -164,11 +164,15 @@ class Friend(contact.Contact):
def get_messages(self):
return self._new_messages
def set_messages(self, value):
self._widget.connection_status.messages = self._new_messages = value
def inc_messages(self):
self._widget.connection_status.messages = self._new_messages + 1
self._widget.connection_status.repaint()
messages = property(get_messages, set_messages)
def reset_messages(self):
self._widget.connection_status.messages = self._new_messages = 0
self._widget.connection_status.repaint()
messages = property(get_messages)
# -----------------------------------------------------------------------------------------------------------------
# Friend's number (can be used in toxcore)

View File

@ -124,9 +124,12 @@ class MessageItem(QtGui.QWidget):
self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
self.setFixedHeight(self.message.height())
if message_type == TOX_MESSAGE_TYPE['ACTION']:
if message_type != TOX_MESSAGE_TYPE['NORMAL']:
self.name.setStyleSheet("QLabel { color: #4169E1; }")
self.name.setAlignment(QtCore.Qt.AlignCenter)
self.message.setStyleSheet("QTextEdit { color: #4169E1; }")
self.message.setAlignment(QtCore.Qt.AlignCenter)
self.time.setStyleSheet("QLabel { color: #4169E1; }")
class ContactItem(QtGui.QWidget):

View File

@ -230,9 +230,9 @@ class MainWindow(QtGui.QMainWindow):
def setup_left_top(self, Form):
Form.setObjectName("left_top")
Form.setCursor(QtCore.Qt.PointingHandCursor)
Form.setMinimumSize(QtCore.QSize(250, 80))
Form.setMaximumSize(QtCore.QSize(250, 80))
Form.setBaseSize(QtCore.QSize(250, 80))
Form.setMinimumSize(QtCore.QSize(270, 80))
Form.setMaximumSize(QtCore.QSize(270, 80))
Form.setBaseSize(QtCore.QSize(270, 80))
self.avatar_label = Form.avatar_label = QtGui.QLabel(Form)
self.avatar_label.setGeometry(QtCore.QRect(5, 15, 64, 64))
self.avatar_label.setScaledContents(True)
@ -250,7 +250,7 @@ class MainWindow(QtGui.QMainWindow):
font.setBold(False)
Form.status_message.setFont(font)
Form.status_message.setObjectName("status_message")
self.connection_status = Form.connection_status = StatusCircle(self)
self.connection_status = Form.connection_status = StatusCircle(Form)
Form.connection_status.setGeometry(QtCore.QRect(230, 29, 64, 64))
Form.connection_status.setMinimumSize(QtCore.QSize(32, 32))
Form.connection_status.setMaximumSize(QtCore.QSize(32, 32))
@ -579,12 +579,12 @@ class MainWindow(QtGui.QMainWindow):
self.profile.set_active(num)
def mouseReleaseEvent(self, event):
x, y = event.x(), event.y()
pos = self.connection_status.pos()
if (pos.x() < x < pos.x() + 32) and (pos.y() < y < pos.y() + 32):
x, y = pos.x() + self.user_info.pos().x(), pos.y() + self.user_info.pos().y()
if (x < event.x() < x + 32) and (y < event.y() < y + 32):
self.profile.change_status()
else:
super(self.__class__, self).mouseReleaseEvent(event)
super(MainWindow, self).mouseReleaseEvent(event)
def filtering(self):
self.profile.filtration(self.online_contacts.currentIndex() == 1, self.contact_name.text())

View File

@ -4,7 +4,8 @@ MESSAGE_TYPE = {
'TEXT': 0,
'ACTION': 1,
'FILE_TRANSFER': 2,
'INLINE': 3
'INLINE': 3,
'INFO_MESSAGE': 4
}
FILE_TRANSFER_MESSAGE_STATUS = {
@ -90,3 +91,9 @@ class InlineImage(Message):
def get_data(self):
return self._data
class InfoMessage(TextMessage):
def __init__(self, message, time):
super(InfoMessage, self).__init__(message, None, time, MESSAGE_TYPE['INFO_MESSAGE'])

View File

@ -154,7 +154,7 @@ class Profile(contact.Contact, Singleton):
if value is not None:
self._active_friend = value
friend = self._friends[value]
self._friends[value].set_messages(False)
self._friends[value].reset_messages()
self._screen.messageEdit.clear()
self._messages.clear()
friend.load_corr()
@ -166,7 +166,7 @@ class Profile(contact.Contact, Singleton):
convert_time(data[2]),
friend.name if data[1] == MESSAGE_OWNER['FRIEND'] else self._name,
data[3])
elif message.get_type() == 2:
elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']:
item = self.create_file_transfer_item(message)
if message.get_status() >= 2: # active file transfer
try:
@ -175,8 +175,14 @@ class Profile(contact.Contact, Singleton):
ft.signal()
except:
print 'Incoming not started transfer - no info found'
else: # inline
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
self.create_inline_item(message.get_data())
else: # info message
data = message.get_data()
self.create_message_item(data[0],
convert_time(data[2]),
'',
data[3])
self._messages.scrollToBottom()
if value in self._call:
self._screen.active_call()
@ -216,6 +222,20 @@ class Profile(contact.Contact, Singleton):
def is_active_online(self):
return self._active_friend + 1 and self._friends[self._active_friend].status is not None
def new_name(self, number, name):
friend = self.get_friend_by_number(number)
tmp = friend.name
friend.set_name(name)
name = name.decode('utf-8')
if friend.name == name and tmp != name:
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()))
if friend.number == self.get_active_number():
self.create_message_item(message, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
self._messages.scrollToBottom()
self.set_active(None)
def update(self):
if self._active_friend + 1:
self.set_active(self._active_friend)
@ -318,7 +338,7 @@ class Profile(contact.Contact, Singleton):
TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type))
else:
friend = self.get_friend_by_number(friend_num)
friend.set_messages(True)
friend.inc_messages()
friend.append_message(
TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type))
if not friend.visibility:
@ -408,6 +428,14 @@ class Profile(contact.Contact, Singleton):
if message.get_status() >= 2: # active file transfer
ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())]
ft.set_state_changed_handler(item.update)
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
self.create_inline_item(message.get_data())
else: # info message
data = message.get_data()
self.create_message_item(data[0],
convert_time(data[2]),
'',
data[3])
def export_history(self, directory):
self._history.export(directory)
@ -730,7 +758,7 @@ class Profile(contact.Contact, Singleton):
self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update)
self._messages.scrollToBottom()
else:
friend.set_messages(True)
friend.inc_messages()
friend.append_message(tm)
@ -942,6 +970,15 @@ class Profile(contact.Contact, Singleton):
if num not in self._call and self.is_active_online(): # start call
self._call(num, audio, video)
self._screen.active_call()
if video:
text = QtGui.QApplication.translate("incoming_call", "Outgoing video call", None,
QtGui.QApplication.UnicodeUTF8)
else:
text = QtGui.QApplication.translate("incoming_call", "Outgoing audio call", None,
QtGui.QApplication.UnicodeUTF8)
self._friends[self._active_friend].append_message(InfoMessage(text, time.time()))
self.create_message_item(text, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
self._messages.scrollToBottom()
elif num in self._call: # finish or cancel call if you call with active friend
self.stop_call(num, False)
@ -950,15 +987,20 @@ class Profile(contact.Contact, Singleton):
Incoming call from friend. Only audio is supported now
"""
friend = self.get_friend_by_number(friend_number)
if video:
text = QtGui.QApplication.translate("incoming_call", "Incoming video call", None,
QtGui.QApplication.UnicodeUTF8)
else:
text = QtGui.QApplication.translate("incoming_call", "Incoming audio call", None,
QtGui.QApplication.UnicodeUTF8)
friend.append_message(InfoMessage(text, time.time()))
self._incoming_calls.add(friend_number)
if friend_number == self.get_active_number():
self._screen.incoming_call()
self.create_message_item(text, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
self._messages.scrollToBottom()
else:
friend.set_messages(True)
if video:
text = QtGui.QApplication.translate("incoming_call", "Incoming video call", None, QtGui.QApplication.UnicodeUTF8)
else:
text = QtGui.QApplication.translate("incoming_call", "Incoming audio call", None, QtGui.QApplication.UnicodeUTF8)
friend.inc_messages()
self._call_widget = avwidgets.IncomingCallWidget(friend_number, text, friend.name)
self._call_widget.set_pixmap(friend.get_pixmap())
self._call_widget.show()
@ -979,10 +1021,18 @@ class Profile(contact.Contact, Singleton):
"""
if friend_number in self._incoming_calls:
self._incoming_calls.remove(friend_number)
text = QtGui.QApplication.translate("incoming_call", "Call declined", None, QtGui.QApplication.UnicodeUTF8)
else:
text = QtGui.QApplication.translate("incoming_call", "Call finished", None, QtGui.QApplication.UnicodeUTF8)
self._screen.call_finished()
self._call.finish_call(friend_number, by_friend) # finish or decline call
if hasattr(self, '_call_widget'):
del self._call_widget
friend = self.get_friend_by_number(friend_number)
friend.append_message(InfoMessage(text, time.time()))
if friend_number == self.get_active_number():
self.create_message_item(text, curr_time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
self._messages.scrollToBottom()
def tox_factory(data=None, settings=None):