From 453b5e25befd91391f4558fe93eb0997a7ffff33 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 4 Jun 2016 15:19:15 +0300 Subject: [PATCH] notes about user and bug fixes --- src/callbacks.py | 6 ++++-- src/file_transfers.py | 2 +- src/mainscreen.py | 17 ++++++++++++++++- src/menu.py | 12 +++++++++--- src/profile.py | 12 ++++++++---- src/settings.py | 3 ++- src/widgets.py | 24 ++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index e08d127..92e5ddb 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -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, @@ -196,7 +198,7 @@ def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, us position, None) 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): diff --git a/src/file_transfers.py b/src/file_transfers.py index 6ced355..66d1f26 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -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): diff --git a/src/mainscreen.py b/src/mainscreen.py index a8b05bd..4608e71 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -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) diff --git a/src/menu.py b/src/menu.py index 7342289..a6d0b0f 100644 --- a/src/menu.py +++ b/src/menu.py @@ -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() + '/' diff --git a/src/profile.py b/src/profile.py index 2387680..7adce11 100644 --- a/src/profile.py +++ b/src/profile.py @@ -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'] diff --git a/src/settings.py b/src/settings.py index 050f061..514dde8 100644 --- a/src/settings.py +++ b/src/settings.py @@ -80,7 +80,8 @@ class Settings(Singleton, dict): 'typing_notifications': False, 'calls_sound': True, 'blocked': [], - 'plugins': [] + 'plugins': [], + 'notes': {} } @staticmethod diff --git a/src/widgets.py b/src/widgets.py index 1499e88..51121fc 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -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() +