notes about user and bug fixes

This commit is contained in:
ingvar1995 2016-06-04 15:19:15 +03:00
parent 8fb263dadc
commit 453b5e25be
7 changed files with 64 additions and 12 deletions

View file

@ -85,7 +85,8 @@ def friend_connection_status(tox, friend_num, new_status, user_data):
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS']) sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
elif friend.status is None: elif friend.status is None:
invoke_in_main_thread(profile.send_avatar, friend_num) invoke_in_main_thread(profile.send_avatar, friend_num)
PluginLoader.get_instance().friend_online(friend_num) profile.friend_online(friend_num)
invoke_in_main_thread(PluginLoader.get_instance().friend_online, friend_num)
def friend_name(tox, friend_num, name, size, user_data): def friend_name(tox, friend_num, name, size, user_data):
@ -176,6 +177,7 @@ def tox_file_recv(window, tray):
invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window) invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window)
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER']) sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
else: # AVATAR else: # AVATAR
print 'Avatar' print 'Avatar'
invoke_in_main_thread(profile.incoming_avatar, invoke_in_main_thread(profile.incoming_avatar,
@ -196,7 +198,7 @@ def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, us
position, position,
None) None)
else: else:
Profile.get_instance().incoming_chunk(friend_number, file_number, position,chunk[:length]) Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk[:length])
def file_chunk_request(tox, friend_number, file_number, position, size, user_data): def file_chunk_request(tox, friend_number, file_number, position, size, user_data):

View file

@ -198,7 +198,7 @@ class ReceiveTransfer(FileTransfer):
if position + l > self._file_size: if position + l > self._file_size:
self._file_size = position + l self._file_size = position + l
self._done += l self._done += l
self._state_changed.signal.emit(self.state, self._done / self._size) self.signal()
class ReceiveToBuffer(FileTransfer): class ReceiveToBuffer(FileTransfer):

View file

@ -3,7 +3,7 @@
from menu import * from menu import *
from profile import * from profile import *
from list_items import * from list_items import *
from widgets import QRightClickButton, RubberBand, create_menu from widgets import QRightClickButton, RubberBand, create_menu, MultilineEdit
import plugin_support import plugin_support
@ -470,6 +470,8 @@ class MainWindow(QtGui.QMainWindow):
copy_key_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Copy public key', None, QtGui.QApplication.UnicodeUTF8)) copy_key_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Copy public key', None, QtGui.QApplication.UnicodeUTF8))
auto_accept_item = self.listMenu.addAction(auto) auto_accept_item = self.listMenu.addAction(auto)
remove_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Remove friend', None, QtGui.QApplication.UnicodeUTF8)) remove_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Remove friend', None, QtGui.QApplication.UnicodeUTF8))
notes_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Notes', None, QtGui.QApplication.UnicodeUTF8))
submenu = plugin_support.PluginLoader.get_instance().get_menu(self.listMenu, num) submenu = plugin_support.PluginLoader.get_instance().get_menu(self.listMenu, num)
if len(submenu): if len(submenu):
plug = self.listMenu.addMenu(QtGui.QApplication.translate("MainWindow", 'Plugins', None, QtGui.QApplication.UnicodeUTF8)) plug = self.listMenu.addMenu(QtGui.QApplication.translate("MainWindow", 'Plugins', None, QtGui.QApplication.UnicodeUTF8))
@ -479,10 +481,23 @@ class MainWindow(QtGui.QMainWindow):
self.connect(copy_key_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_friend_key(num)) self.connect(copy_key_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_friend_key(num))
self.connect(clear_history_item, QtCore.SIGNAL("triggered()"), lambda: self.clear_history(num)) self.connect(clear_history_item, QtCore.SIGNAL("triggered()"), lambda: self.clear_history(num))
self.connect(auto_accept_item, QtCore.SIGNAL("triggered()"), lambda: self.auto_accept(num, not allowed)) self.connect(auto_accept_item, QtCore.SIGNAL("triggered()"), lambda: self.auto_accept(num, not allowed))
self.connect(notes_item, QtCore.SIGNAL("triggered()"), lambda: self.show_note(friend))
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0)) parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
self.listMenu.move(parent_position + pos) self.listMenu.move(parent_position + pos)
self.listMenu.show() self.listMenu.show()
def show_note(self, friend):
s = Settings.get_instance()
note = s['notes'][friend.tox_id] if friend.tox_id in s['notes'] else ''
user = QtGui.QApplication.translate("MainWindow", 'Notes about user', None, QtGui.QApplication.UnicodeUTF8)
user = u'{} {}'.format(user, friend.name)
def save_note(text):
s['notes'][friend.tox_id] = text
s.save()
self.note = MultilineEdit(user, note, save_note)
self.note.show()
def set_alias(self, num): def set_alias(self, num):
self.profile.set_alias(num) self.profile.set_alias(num)

View file

@ -212,9 +212,15 @@ class ProfileSettings(CenteredWidget):
choose = QtGui.QApplication.translate("ProfileSettingsForm", "Choose avatar", None, QtGui.QApplication.UnicodeUTF8) choose = QtGui.QApplication.translate("ProfileSettingsForm", "Choose avatar", None, QtGui.QApplication.UnicodeUTF8)
name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Image Files (*.png)') name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Image Files (*.png)')
if name[0]: if name[0]:
with open(name[0], 'rb') as f: bitmap = QtGui.QPixmap(name[0])
data = f.read() bitmap.scaled(QtCore.QSize(128, 128), aspectMode=QtCore.Qt.KeepAspectRatio,
Profile.get_instance().set_avatar(data) mode=QtCore.Qt.SmoothTransformation)
byte_array = QtCore.QByteArray()
buffer = QtCore.QBuffer(byte_array)
buffer.open(QtCore.QIODevice.WriteOnly)
bitmap.save(buffer, 'PNG')
Profile.get_instance().set_avatar(str(byte_array.data()))
def export_profile(self): def export_profile(self):
directory = QtGui.QFileDialog.getExistingDirectory() + '/' directory = QtGui.QFileDialog.getExistingDirectory() + '/'

View file

@ -483,18 +483,20 @@ class Profile(Contact, Singleton):
if self._active_friend + 1: if self._active_friend + 1:
self.set_active(self._active_friend) self.set_active(self._active_friend)
def friend_online(self, friend_number):
for key in filter(lambda x: x[0] == friend_number, self._file_transfers.keys()):
self.resume_transfer(key[0], key[1], True)
def friend_exit(self, friend_number): def friend_exit(self, friend_number):
""" """
Friend with specified number quit Friend with specified number quit
""" """
# TODO: pause transfers
self.get_friend_by_number(friend_number).status = None self.get_friend_by_number(friend_number).status = None
self.friend_typing(friend_number, False) self.friend_typing(friend_number, False)
if friend_number in self._call: if friend_number in self._call:
self._call.finish_call(friend_number, True) self._call.finish_call(friend_number, True)
for key in filter(lambda x: x[0] == friend_number, self._file_transfers.keys()): for key in filter(lambda x: x[0] == friend_number, self._file_transfers.keys()):
self._file_transfers[key].cancelled() self._file_transfers[key].pause(False)
del self._file_transfers[key]
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Typing notifications # Typing notifications
@ -718,7 +720,9 @@ class Profile(Contact, Singleton):
text, ok = QtGui.QInputDialog.getText(None, text, ok = QtGui.QInputDialog.getText(None,
title, title,
dialog) dialog,
QtGui.QLineEdit.Normal,
name.decode('utf-8'))
if ok: if ok:
settings = Settings.get_instance() settings = Settings.get_instance()
aliases = settings['friends_aliases'] aliases = settings['friends_aliases']

View file

@ -80,7 +80,8 @@ class Settings(Singleton, dict):
'typing_notifications': False, 'typing_notifications': False,
'calls_sound': True, 'calls_sound': True,
'blocked': [], 'blocked': [],
'plugins': [] 'plugins': [],
'notes': {}
} }
@staticmethod @staticmethod

View file

@ -88,3 +88,27 @@ def create_menu(menu):
continue continue
action.setText(text) action.setText(text)
return menu return menu
class MultilineEdit(CenteredWidget):
def __init__(self, title, text, save):
super(MultilineEdit, self).__init__()
self.resize(350, 200)
self.setMinimumSize(QtCore.QSize(350, 200))
self.setMaximumSize(QtCore.QSize(350, 200))
self.setWindowTitle(title)
self.edit = QtGui.QTextEdit(self)
self.edit.setGeometry(QtCore.QRect(0, 0, 350, 150))
self.edit.setText(text)
self.button = QtGui.QPushButton(self)
self.button.setGeometry(QtCore.QRect(0, 150, 350, 50))
self.button.setText(QtGui.QApplication.translate("MainWindow", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.button.clicked.connect(self.button_click)
self.center()
self.save = save
def button_click(self):
self.save(self.edit.toPlainText())
self.close()