diff --git a/src/history.py b/src/history.py index abcb58b..9caf2be 100644 --- a/src/history.py +++ b/src/history.py @@ -23,12 +23,15 @@ class History(object): path = settings.ProfileHelper.get_path() + self._name + '.hstr' if os.path.exists(path): decr = LibToxEncryptSave.get_instance() - with open(path, 'rb') as fin: - data = fin.read() - if decr.is_data_encrypted(data): - data = decr.pass_decrypt(data) - with open(path, 'wb') as fout: - fout.write(data) + try: + with open(path, 'rb') as fin: + data = fin.read() + if decr.is_data_encrypted(data): + data = decr.pass_decrypt(data) + with open(path, 'wb') as fout: + fout.write(data) + except: + os.remove(path) db = connect(name + '.hstr') cursor = db.cursor() cursor.execute('CREATE TABLE IF NOT EXISTS friends(' diff --git a/src/menu.py b/src/menu.py index a6d0b0f..689d1d6 100644 --- a/src/menu.py +++ b/src/menu.py @@ -654,13 +654,18 @@ class PluginsSettings(CenteredWidget): def show_data(self): ind = self.comboBox.currentIndex() - plugin = self.data[ind] - descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8) - self.label.setText(descr) - if plugin[1]: - self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8)) + if len(self.data): + plugin = self.data[ind] + descr = plugin[2] or QtGui.QApplication.translate("PluginsForm", "No description available", None, QtGui.QApplication.UnicodeUTF8) + self.label.setText(descr) + 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: - 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): ind = self.comboBox.currentIndex() diff --git a/src/profile.py b/src/profile.py index a809cac..3074f85 100644 --- a/src/profile.py +++ b/src/profile.py @@ -167,7 +167,7 @@ class Friend(Contact): def dec_receipt(self): if self._receipts: self._receipts -= 1 - self.mark_as_sent(False) + self.mark_as_sent() def load_corr(self, first_time=True): """ @@ -212,22 +212,13 @@ class Friend(Contact): else: return '' - def last_message_owner(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): + def unsent_messages(self): messages = filter(lambda x: x.get_owner() == 2, self._corr) return messages - def mark_as_sent(self, mark_all=True): - for message in filter(lambda x: x.get_owner() == 2, self._corr): - message.mark_as_sent() - if not mark_all: - break + def mark_as_sent(self): + message = filter(lambda x: x.get_owner() == 2, self._corr)[0] + message.mark_as_sent() def clear_corr(self): """ @@ -552,14 +543,13 @@ class Profile(Contact, Singleton): """ friend = self.get_friend_by_number(friend_number) friend.load_corr() - messages = friend.not_sent_messages() + messages = friend.unsent_messages() try: for message in messages: self.split_and_send(friend_number, message.get_data()[-1], message.get_data()[0].encode('utf-8')) + friend.mark_as_sent() except: pass - else: - friend.mark_as_sent() def split_and_send(self, number, message_type, message): """ diff --git a/src/settings.py b/src/settings.py index 514dde8..a589d35 100644 --- a/src/settings.py +++ b/src/settings.py @@ -19,9 +19,9 @@ class Settings(Singleton, dict): with open(self.path) as fl: data = fl.read() inst = LibToxEncryptSave.get_instance() - if inst.is_data_encrypted(data): - data = inst.pass_decrypt(data) try: + if inst.is_data_encrypted(data): + data = inst.pass_decrypt(data) info = json.loads(data) except Exception as ex: info = Settings.get_default_settings()