profile.py updates - avatars and file transfers

This commit is contained in:
ingvar1995 2016-03-16 22:59:15 +03:00
parent e61f600d59
commit 1a996522f1
4 changed files with 38 additions and 6 deletions

View File

@ -152,7 +152,8 @@ def tox_file_recv(window, tray):
print 'Avatar' print 'Avatar'
invoke_in_main_thread(profile.incoming_avatar, invoke_in_main_thread(profile.incoming_avatar,
friend_number, friend_number,
file_number) file_number,
size)
return wrapped return wrapped
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -102,6 +102,7 @@ class MainWindow(QtGui.QMainWindow):
self.sendMessageButton.setGeometry(QtCore.QRect(550, 10, 60, 110)) self.sendMessageButton.setGeometry(QtCore.QRect(550, 10, 60, 110))
self.sendMessageButton.setObjectName("sendMessageButton") self.sendMessageButton.setObjectName("sendMessageButton")
self.sendMessageButton.clicked.connect(self.send_message) self.sendMessageButton.clicked.connect(self.send_message)
self.fileTransferButton.clicked.connect(self.send_file)
self.screenshotButton.setText(QtGui.QApplication.translate("Form", "Screenshot", None, QtGui.QApplication.UnicodeUTF8)) self.screenshotButton.setText(QtGui.QApplication.translate("Form", "Screenshot", None, QtGui.QApplication.UnicodeUTF8))
self.fileTransferButton.setText(QtGui.QApplication.translate("Form", "File", None, QtGui.QApplication.UnicodeUTF8)) self.fileTransferButton.setText(QtGui.QApplication.translate("Form", "File", None, QtGui.QApplication.UnicodeUTF8))
self.sendMessageButton.setText(QtGui.QApplication.translate("Form", "Send", None, QtGui.QApplication.UnicodeUTF8)) self.sendMessageButton.setText(QtGui.QApplication.translate("Form", "Send", None, QtGui.QApplication.UnicodeUTF8))
@ -268,13 +269,19 @@ class MainWindow(QtGui.QMainWindow):
self.int_s.show() self.int_s.show()
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Messages # Messages and file transfers
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
def send_message(self): def send_message(self):
text = self.messageEdit.toPlainText() text = self.messageEdit.toPlainText()
self.profile.send_message(text) self.profile.send_message(text)
def send_file(self):
if self.profile.is_active_online(): # active friend exists and online
name = QtGui.QFileDialog.getOpenFileName(self, 'Choose file')
if name:
self.profile.send_file(name)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Functions which called when user open context menu in friends list # Functions which called when user open context menu in friends list
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -165,7 +165,7 @@ class ProfileSettings(CenteredWidget):
Profile.get_instance().reset_avatar() Profile.get_instance().reset_avatar()
def set_avatar(self): def set_avatar(self):
name = QtGui.QFileDialog.getOpenFileName(self, 'Open file') name = QtGui.QFileDialog.getOpenFileName(self, 'Open file', None, 'Image Files (*.png *.jpg *.bmp)')
print name print name
if name[0]: if name[0]:
with open(name[0], 'rb') as f: with open(name[0], 'rb') as f:

View File

@ -56,7 +56,7 @@ class ProfileHelper(object):
@staticmethod @staticmethod
def export_profile(new_path): def export_profile(new_path):
new_path += ProfileHelper._path.split('/')[-1] new_path += os.path.basename(ProfileHelper._path)
with open(ProfileHelper._path, 'rb') as fin: with open(ProfileHelper._path, 'rb') as fin:
data = fin.read() data = fin.read()
with open(new_path, 'wb') as fout: with open(new_path, 'wb') as fout:
@ -167,6 +167,14 @@ class Contact(object):
f.write(avatar) f.write(avatar)
self.load_avatar() self.load_avatar()
def get_avatar_hash(self):
avatar_path = (Settings.get_default_path() + 'avatars/{}.png').format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
if not os.path.isfile(avatar_path): # load default image
avatar_path = curr_directory() + '/images/avatar.png'
with open(avatar_path, 'rb') as fl:
data = fl.read()
return Tox.hash(data)
class Friend(Contact): class Friend(Contact):
""" """
@ -696,7 +704,23 @@ class Profile(Contact, Singleton):
def incoming_file_transfer(self, friend_number, file_number, size, file_name): def incoming_file_transfer(self, friend_number, file_number, size, file_name):
pass pass
def incoming_avatar(self, friend_number, file_number): def incoming_avatar(self, friend_number, file_number, size):
friend = self.get_friend_by_number(friend_number)
if not size:
friend.reset_avatar()
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
else:
hash = friend.get_avatar_hash()
new_avatar_hash = self._tox.file_get_file_id(friend_number, file_number)
if hash == new_avatar_hash: # avatar is the same
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) # ignore file
else:
pass
def send_avatar(self, friend_number):
pass
def send_file(self, path):
pass pass