improvements and bug fixes

This commit is contained in:
ingvar1995 2016-06-05 14:59:36 +03:00
parent d02ee92508
commit 672dafc701
4 changed files with 29 additions and 31 deletions

View File

@ -23,12 +23,15 @@ class History(object):
path = settings.ProfileHelper.get_path() + self._name + '.hstr' path = settings.ProfileHelper.get_path() + self._name + '.hstr'
if os.path.exists(path): if os.path.exists(path):
decr = LibToxEncryptSave.get_instance() decr = LibToxEncryptSave.get_instance()
try:
with open(path, 'rb') as fin: with open(path, 'rb') as fin:
data = fin.read() data = fin.read()
if decr.is_data_encrypted(data): if decr.is_data_encrypted(data):
data = decr.pass_decrypt(data) data = decr.pass_decrypt(data)
with open(path, 'wb') as fout: with open(path, 'wb') as fout:
fout.write(data) fout.write(data)
except:
os.remove(path)
db = connect(name + '.hstr') db = connect(name + '.hstr')
cursor = db.cursor() cursor = db.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS friends(' cursor.execute('CREATE TABLE IF NOT EXISTS friends('

View File

@ -654,6 +654,7 @@ class PluginsSettings(CenteredWidget):
def show_data(self): def show_data(self):
ind = self.comboBox.currentIndex() ind = self.comboBox.currentIndex()
if len(self.data):
plugin = self.data[ind] plugin = self.data[ind]
descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8) descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8)
self.label.setText(descr) self.label.setText(descr)
@ -661,6 +662,10 @@ class PluginsSettings(CenteredWidget):
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8)) self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8))
else: else:
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Enable plugin", None, QtGui.QApplication.UnicodeUTF8)) self.button.setText(QtGui.QApplication.translate("PluginsForm", "Enable plugin", None, QtGui.QApplication.UnicodeUTF8))
else:
self.open.setVisible(False)
self.button.setVisible(False)
self.label.setText(QtGui.QApplication.translate("PluginsForm", "No plugins found", None, QtGui.QApplication.UnicodeUTF8))
def button_click(self): def button_click(self):
ind = self.comboBox.currentIndex() ind = self.comboBox.currentIndex()

View File

@ -167,7 +167,7 @@ class Friend(Contact):
def dec_receipt(self): def dec_receipt(self):
if self._receipts: if self._receipts:
self._receipts -= 1 self._receipts -= 1
self.mark_as_sent(False) self.mark_as_sent()
def load_corr(self, first_time=True): def load_corr(self, first_time=True):
""" """
@ -212,22 +212,13 @@ class Friend(Contact):
else: else:
return '' return ''
def last_message_owner(self): def unsent_messages(self):
messages = filter(lambda x: x.get_type() <= 1, self._corr)
if messages:
return messages[-1].get_owner()
else:
return -1
def not_sent_messages(self):
messages = filter(lambda x: x.get_owner() == 2, self._corr) messages = filter(lambda x: x.get_owner() == 2, self._corr)
return messages return messages
def mark_as_sent(self, mark_all=True): def mark_as_sent(self):
for message in filter(lambda x: x.get_owner() == 2, self._corr): message = filter(lambda x: x.get_owner() == 2, self._corr)[0]
message.mark_as_sent() message.mark_as_sent()
if not mark_all:
break
def clear_corr(self): def clear_corr(self):
""" """
@ -552,14 +543,13 @@ class Profile(Contact, Singleton):
""" """
friend = self.get_friend_by_number(friend_number) friend = self.get_friend_by_number(friend_number)
friend.load_corr() friend.load_corr()
messages = friend.not_sent_messages() messages = friend.unsent_messages()
try: try:
for message in messages: for message in messages:
self.split_and_send(friend_number, message.get_data()[-1], message.get_data()[0].encode('utf-8')) self.split_and_send(friend_number, message.get_data()[-1], message.get_data()[0].encode('utf-8'))
friend.mark_as_sent()
except: except:
pass pass
else:
friend.mark_as_sent()
def split_and_send(self, number, message_type, message): def split_and_send(self, number, message_type, message):
""" """

View File

@ -19,9 +19,9 @@ class Settings(Singleton, dict):
with open(self.path) as fl: with open(self.path) as fl:
data = fl.read() data = fl.read()
inst = LibToxEncryptSave.get_instance() inst = LibToxEncryptSave.get_instance()
try:
if inst.is_data_encrypted(data): if inst.is_data_encrypted(data):
data = inst.pass_decrypt(data) data = inst.pass_decrypt(data)
try:
info = json.loads(data) info = json.loads(data)
except Exception as ex: except Exception as ex:
info = Settings.get_default_settings() info = Settings.get_default_settings()