diff --git a/src/main.py b/src/main.py index 270e73e..fc2dbc3 100644 --- a/src/main.py +++ b/src/main.py @@ -85,8 +85,9 @@ class Toxygen(object): :return: tox instance """ self.mainloop.stop = True + self.init.stop = True self.mainloop.wait() - self.init.terminate() + self.init.wait() data = self.tox.get_savedata() ProfileHelper.save_profile(data) del self.tox @@ -110,6 +111,7 @@ class Toxygen(object): def __init__(self, tox, ms, tray): QtCore.QThread.__init__(self) self.tox, self.ms, self.tray = tox, ms, tray + self.stop = False def run(self): # initializing callbacks @@ -118,7 +120,7 @@ class Toxygen(object): for data in node_generator(): self.tox.bootstrap(*data) self.msleep(10000) - while not self.tox.self_get_connection_status(): + while not self.tox.self_get_connection_status() and not self.stop: for data in node_generator(): self.tox.bootstrap(*data) self.msleep(5000) diff --git a/src/profile.py b/src/profile.py index 36b2417..67fdd42 100644 --- a/src/profile.py +++ b/src/profile.py @@ -431,7 +431,7 @@ class Profile(Contact, Singleton): return self._friends[self._active_friend].number if self._active_friend + 1 else -1 def get_active_name(self): - return self._friends[self._active_friend].name if self._active_friend + 1 else '' + return self._friends[self._active_friend].name if self._active_friend + 1 else '' def is_active_online(self): return self._active_friend + 1 and self._friends[self._active_friend].status is not None @@ -608,8 +608,10 @@ class Profile(Contact, Singleton): result = self.tox.friend_add(tox_id, message.encode('utf-8')) tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] item = self.create_friend_item() - friend = Friend(result, tox_id, '', item, tox_id) - self.history.add_friend_to_db(tox_id) # add friend to db + if not self.history.friend_exists_in_db(tox_id): + self.history.add_friend_to_db(tox_id) + message_getter = self.history.messages_getter(tox_id) + friend = Friend(message_getter, result, tox_id, '', item, tox_id) self._friends.append(friend) return True except Exception as ex: # wrong data @@ -628,8 +630,12 @@ class Profile(Contact, Singleton): if reply == QtGui.QMessageBox.Yes: # accepted num = self.tox.friend_add_norequest(tox_id) # num - friend number item = self.create_friend_item() - friend = Friend(num, tox_id, '', item, tox_id) - self.history.add_friend_to_db(tox_id) # add friend to db + if not self.history.friend_exists_in_db(tox_id): + self.history.add_friend_to_db(tox_id) + if not self.history.friend_exists_in_db(tox_id): + self.history.add_friend_to_db(tox_id) + message_getter = self.history.messages_getter(tox_id) + friend = Friend(message_getter, num, tox_id, '', item, tox_id) self._friends.append(friend) except Exception as ex: # something is wrong log('Accept friend request failed! ' + str(ex))