def openAddFriendDialog(self, friend, *args, **kwargs): if not hasattr(self, "_addFriendDialog"): self._addFriendDialog = AddFriendDialog() self._addFriendDialog.setContextProperty("controlManager", controlManager) self._addFriendDialog.setFriendInstance(friend) self._addFriendDialog.showIt()
class ControlManager(QPropertyObject()): def __init__(self): super(ControlManager, self).__init__() self.chatWindowManager = dict() self.notifyModel = NotifyModel(self) dbSignals.post_save.connect(self.on_received_message, sender=ReceivedMessage) cSignals.show_message.connect(self.onNitfiyMessageClicked) cSignals.open_add_friend_dialog.connect(self.openAddFriendDialog) def openAddFriendDialog(self, friend, *args, **kwargs): if not hasattr(self, "_addFriendDialog"): self._addFriendDialog = AddFriendDialog() self._addFriendDialog.setContextProperty("controlManager", controlManager) self._addFriendDialog.setFriendInstance(friend) self._addFriendDialog.showIt() def onNitfiyMessageClicked(self, jid, loaded, *args, **kwargs): self.showChatWindow(jid, loadMessages=loaded) def showChatWindow(self, jid, loadMessages=False): if jid not in self.chatWindowManager: w = ChatWindow(model=self.createModel(jid, loadMessages), jid=jid) w.requestClose.connect(self.onChatWindowClose) w.setContextProperty("commonManager", commonManager) self.chatWindowManager[jid] = w w.showCenter() else: self.chatWindowManager[jid].raise_() @QtCore.pyqtSlot(str) def openChat(self, jid): self.showChatWindow(jid) def createModel(self, jid, loadMessages): return MessageModel(toJid=jid, loadMessages=loadMessages) @postGui() def on_received_message(self, sender, instance, created, update_fields, *args, **kwargs): if created: jid = instance.friend.jid if jid in self.chatWindowManager: w = self.chatWindowManager[jid] w.model.appendMessage(instance, received=True) else: self.notifyModel.appendMessage(instance) @QtCore.pyqtSlot(result="QVariant") def getNotifyModel(self): return self.notifyModel @QtCore.pyqtSlot(str, str) def requestAddFriend(self, jid, message): xmppClient.request_add_friend(jid, message) self._addFriendDialog.hide() def onChatWindowClose(self): w = self.sender() jid = w.jid self.chatWindowManager.pop(jid) w.requestClose.disconnect(self.onChatWindowClose) w.hide() w.close() w.deleteLater()