profile.py updates - avatars and file transfers
This commit is contained in:
parent
e61f600d59
commit
1a996522f1
@ -152,7 +152,8 @@ def tox_file_recv(window, tray):
|
||||
print 'Avatar'
|
||||
invoke_in_main_thread(profile.incoming_avatar,
|
||||
friend_number,
|
||||
file_number)
|
||||
file_number,
|
||||
size)
|
||||
return wrapped
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -102,6 +102,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
self.sendMessageButton.setGeometry(QtCore.QRect(550, 10, 60, 110))
|
||||
self.sendMessageButton.setObjectName("sendMessageButton")
|
||||
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.fileTransferButton.setText(QtGui.QApplication.translate("Form", "File", 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()
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Messages
|
||||
# Messages and file transfers
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def send_message(self):
|
||||
text = self.messageEdit.toPlainText()
|
||||
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
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -165,7 +165,7 @@ class ProfileSettings(CenteredWidget):
|
||||
Profile.get_instance().reset_avatar()
|
||||
|
||||
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
|
||||
if name[0]:
|
||||
with open(name[0], 'rb') as f:
|
||||
|
@ -56,7 +56,7 @@ class ProfileHelper(object):
|
||||
|
||||
@staticmethod
|
||||
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:
|
||||
data = fin.read()
|
||||
with open(new_path, 'wb') as fout:
|
||||
@ -167,6 +167,14 @@ class Contact(object):
|
||||
f.write(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):
|
||||
"""
|
||||
@ -304,7 +312,7 @@ class Profile(Contact, Singleton):
|
||||
self._screen = screen
|
||||
self._messages = screen.messages
|
||||
self._tox = tox
|
||||
self._file_transfers = [] # list of file transfers
|
||||
self._file_transfers = [] # list of file transfers
|
||||
settings = Settings.get_instance()
|
||||
self._show_online = settings['show_online_friends']
|
||||
screen.online_contacts.setChecked(self._show_online)
|
||||
@ -696,7 +704,23 @@ class Profile(Contact, Singleton):
|
||||
def incoming_file_transfer(self, friend_number, file_number, size, file_name):
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user