inlines fix, menu fix, settings upgrade

This commit is contained in:
ingvar1995 2016-04-24 23:24:48 +03:00
parent ee15359c19
commit 9b02089bff
3 changed files with 34 additions and 13 deletions

View file

@ -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'])

View file

@ -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,
i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'],
inline)
self.set_active(self._active_friend)
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):

View file

@ -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()
@ -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: