From 9b02089bff2be9b6dade00196c979a1f666b7ae0 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 24 Apr 2016 23:24:48 +0300 Subject: [PATCH] inlines fix, menu fix, settings upgrade --- src/menu.py | 6 +++--- src/profile.py | 28 ++++++++++++++++++++-------- src/settings.py | 13 +++++++++++-- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/menu.py b/src/menu.py index de02723..29e4d78 100644 --- a/src/menu.py +++ b/src/menu.py @@ -339,11 +339,11 @@ class NotificationsSettings(CenteredWidget): self.setMinimumSize(QtCore.QSize(350, 200)) self.setMaximumSize(QtCore.QSize(350, 200)) self.enableNotifications = QtGui.QCheckBox(self) - self.enableNotifications.setGeometry(QtCore.QRect(10, 20, 270, 20)) + self.enableNotifications.setGeometry(QtCore.QRect(10, 20, 340, 18)) self.callsSound = QtGui.QCheckBox(self) - self.callsSound.setGeometry(QtCore.QRect(10, 120, 270, 20)) + self.callsSound.setGeometry(QtCore.QRect(10, 120, 340, 18)) self.soundNotifications = QtGui.QCheckBox(self) - self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 270, 20)) + self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18)) s = Settings.get_instance() self.enableNotifications.setChecked(s['notifications']) self.soundNotifications.setChecked(s['sound_notifications']) diff --git a/src/profile.py b/src/profile.py index 20306cd..7bc5d98 100644 --- a/src/profile.py +++ b/src/profile.py @@ -219,6 +219,7 @@ class Friend(Contact): if inline: # inline was loaded i = self._corr.index(tr) self._corr.insert(i, inline) + return i - len(self._corr) except Exception as ex: log('Update transfer data failed: ' + str(ex)) @@ -787,6 +788,7 @@ class Profile(Contact, Singleton): file_name, friend_number, file_number) + elif auto: path = settings['auto_accept_path'] or curr_directory() new_file_name, i = file_name, 1 @@ -797,7 +799,7 @@ class Profile(Contact, Singleton): d = len(file_name) new_file_name = file_name[:d] + ' ({})'.format(i) + file_name[d:] i += 1 - self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number) + self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number, size) tm = TransferMessage(MESSAGE_OWNER['FRIEND'], time.time(), FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED'], @@ -814,10 +816,13 @@ class Profile(Contact, Singleton): friend_number, file_number) if friend_number == self.get_active_number(): - self.create_file_transfer_item(tm) + item = self.create_file_transfer_item(tm) + if (inline and size < 1024 * 1024) or auto: + self._file_transfers[(friend_number, file_number)].set_state_changed_handler(item.update) self._messages.scrollToBottom() else: friend.set_messages(True) + friend.append_message(tm) def cancel_transfer(self, friend_number, file_number, already_cancelled=False): @@ -841,7 +846,7 @@ class Profile(Contact, Singleton): def accept_transfer(self, item, path, friend_number, file_number, size, inline=False): """ - :param item: transfer item. None if auto accept + :param item: transfer item. :param path: path for saving :param friend_number: friend number :param file_number: file number @@ -909,12 +914,19 @@ class Profile(Contact, Singleton): self.set_active(None) elif type(transfer) is ReceiveToBuffer: inline = InlineImage(transfer.get_data()) - self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], - inline) - self.set_active(self._active_friend) + i = self.get_friend_by_number(friend_number).update_transfer_data(file_number, + FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], + inline) + if friend_number == self.get_active_number(): + count = self._messages.count() + item = InlineImageItem(transfer.get_data()) + elem = QtGui.QListWidgetItem() + elem.setSizeHint(QtCore.QSize(600, item.height())) + self._messages.insertItem(count + i + 1, elem) + self._messages.setItemWidget(elem, item) else: - self.get_friend_by_number(friend_number).update_transfer_data(file_number, FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) + self.get_friend_by_number(friend_number).update_transfer_data(file_number, + FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) del self._file_transfers[(friend_number, file_number)] def outgoing_chunk(self, friend_number, file_number, position, size): diff --git a/src/settings.py b/src/settings.py index 8cdbb7b..f6bbc40 100644 --- a/src/settings.py +++ b/src/settings.py @@ -15,6 +15,7 @@ class Settings(Singleton, dict): with open(self.path) as fl: data = fl.read() super(self.__class__, self).__init__(json.loads(data)) + self.upgrade() else: super(self.__class__, self).__init__(Settings.get_default_settings()) self.save() @@ -37,7 +38,7 @@ class Settings(Singleton, dict): p = Settings.get_default_path() + 'toxygen.json' data = json.dumps({'path': unicode(path.decode(locale.getpreferredencoding())), 'name': unicode(name)}) with open(p, 'w') as fl: - fl.write(data) + fl.write(data) @staticmethod def get_default_settings(): @@ -62,7 +63,8 @@ class Settings(Singleton, dict): 'auto_accept_from_friends': [], 'friends_aliases': [], 'typing_notifications': True, - 'calls_sound': True + 'calls_sound': True, + 'blocked': [] } @staticmethod @@ -73,6 +75,13 @@ class Settings(Singleton, dict): ('French', 'fr_FR') ] + def upgrade(self): + default = Settings.get_default_settings() + for key in default: + if key not in self: + self[key] = default[key] + self.save() + def save(self): text = json.dumps(self) with open(self.path, 'w') as fl: