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'])
elif friend.status is None:
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):
@ -176,6 +177,7 @@ def tox_file_recv(window, tray):
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']:
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
else: # AVATAR
print 'Avatar'
invoke_in_main_thread(profile.incoming_avatar,

View File

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

View File

@ -3,7 +3,7 @@
from menu import *
from profile import *
from list_items import *
from widgets import QRightClickButton, RubberBand, create_menu
from widgets import QRightClickButton, RubberBand, create_menu, MultilineEdit
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))
auto_accept_item = self.listMenu.addAction(auto)
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)
if len(submenu):
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(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(notes_item, QtCore.SIGNAL("triggered()"), lambda: self.show_note(friend))
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
self.listMenu.move(parent_position + pos)
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):
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)
name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Image Files (*.png)')
if name[0]:
with open(name[0], 'rb') as f:
data = f.read()
Profile.get_instance().set_avatar(data)
bitmap = QtGui.QPixmap(name[0])
bitmap.scaled(QtCore.QSize(128, 128), aspectMode=QtCore.Qt.KeepAspectRatio,
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):
directory = QtGui.QFileDialog.getExistingDirectory() + '/'

View File

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

View File

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

View File

@ -88,3 +88,27 @@ def create_menu(menu):
continue
action.setText(text)
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()