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()
with open(path, 'rb') as fin: try:
data = fin.read() with open(path, 'rb') as fin:
if decr.is_data_encrypted(data): data = fin.read()
data = decr.pass_decrypt(data) if decr.is_data_encrypted(data):
with open(path, 'wb') as fout: data = decr.pass_decrypt(data)
fout.write(data) with open(path, 'wb') as fout:
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,13 +654,18 @@ class PluginsSettings(CenteredWidget):
def show_data(self): def show_data(self):
ind = self.comboBox.currentIndex() ind = self.comboBox.currentIndex()
plugin = self.data[ind] if len(self.data):
descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8) plugin = self.data[ind]
self.label.setText(descr) descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8)
if plugin[1]: self.label.setText(descr)
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8)) if plugin[1]:
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8))
else:
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Enable plugin", None, QtGui.QApplication.UnicodeUTF8))
else: else:
self.button.setText(QtGui.QApplication.translate("PluginsForm", "Enable plugin", None, QtGui.QApplication.UnicodeUTF8)) 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()
if inst.is_data_encrypted(data):
data = inst.pass_decrypt(data)
try: try:
if inst.is_data_encrypted(data):
data = inst.pass_decrypt(data)
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()