Changeset 710
- Timestamp:
- 07/07/08 05:52:38 (5 months ago)
- Files:
-
- oss/jlib/examples/basic/client.py (modified) (2 diffs)
- oss/jlib/jlib/core/contact.py (modified) (5 diffs)
- oss/jlib/jlib/gui/chat.py (modified) (1 diff)
- oss/jlib/jlib/gui/contact.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oss/jlib/examples/basic/client.py
r709 r710 27 27 28 28 def start(self): 29 self.connection.emit(QtCore.SIGNAL("registerLinkages(PyQt_PyObject)"), self.contactUi.qobj) 29 self.connection.emit(QtCore.SIGNAL("registerLinkages(PyQt_PyObject)"), self.contactUi.contact) 30 self.connection.emit(QtCore.SIGNAL("registerLinkages(PyQt_PyObject)"), self.contactUi.presence) 30 31 self.connection.emit(QtCore.SIGNAL("start()")) 31 32 … … 40 41 def showConnectionSettings(self): 41 42 self.dialog = jlibConnectionDialog() 43 44 # Just because I can't be bothered to type them over and over again 42 45 self.dialog.connection.domain.setText('localhost') 43 46 self.dialog.connection.resource.setText('Home') 44 47 self.dialog.connection.host.setText('localhost') 48 45 49 if self.dialog.exec_() == QtGui.QDialog.Accepted: 46 50 self.connection = self.dialog.connection oss/jlib/jlib/core/contact.py
r709 r710 5 5 6 6 from headstock.protocol.core.roster import RosterDispatcher 7 from headstock.protocol.core.presence import PresenceDispatcher 7 8 from headstock.api.jid import JID 8 9 from headstock.api import Entity 10 from headstock.api.contact import Presence, Roster, Item 9 11 from headstock.lib.utils import generate_unique 10 12 11 13 from bridge import Element as E 12 from bridge.common import XMPP_ ROSTER_NS14 from bridge.common import XMPP_CLIENT_NS, XMPP_ROSTER_NS 13 15 14 16 from PyQt4 import QtCore, QtGui … … 16 18 from jlib.core.qaxon import QAxonObject 17 19 18 __all__ = ['jlibContact', 'jlibContactComponent', 'jlibContactModel'] 20 __all__ = ['jlibContact', 'jlibContactComponent', 'jlibContactModel', 21 'jlibPresence', 'jlibPresenceComponent'] 19 22 20 23 class jlibContact(QAxonObject): … … 25 28 QAxonObject.setComponent(self, component) 26 29 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'inbox') 30 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'pushed') 27 31 28 32 def getLinkages(self): … … 81 85 roster = self.recv('pushed') 82 86 for nodeid in roster.items: 87 contact = roster.items[nodeid] 88 if contact.subscription == 'remove': 89 self.qobj.emit(QtCore.SIGNAL("removedContact(PyQt_PyObject)"), contact) 90 elif contact.subscription == 'from': 91 self.qobj.emit(QtCore.SIGNAL("addedContact(PyQt_PyObject)"), contact) 83 92 self.send(Roster(from_jid=self.from_jid, to_jid=nodeid, 84 93 type=u'result', stanza_id=generate_unique()), 'result') … … 117 126 for nodeid in roster.items: 118 127 contact = roster.items[nodeid] 119 item = QtGui.QStandardItem() 120 self.appendRow(item) 121 self.setData(self.index(item.row(), 0), 122 QtCore.QVariant(QtCore.QString(nodeid))) 128 self.addContact(contact) 123 129 124 130 def getContact(self, index): 125 131 return self.roster.items.values()[index.row()] 132 133 def getIndex(self, contact): 134 for nodeid in self.roster.items: 135 if str(contact.jid) == nodeid: 136 return self.index(self.roster.items.keys().index(nodeid), 0) 137 138 return QtCore.QModelIndex() 139 140 def deleteContact(self, contact): 141 index = None 142 for nodeid in self.roster.items: 143 if str(contact.jid) == nodeid: 144 index = self.index(self.roster.items.keys().index(nodeid), 0) 145 del self.roster.items[nodeid] 146 break 147 148 if index: 149 self.removeRow(index.row(), index.parent()) 150 151 def addContact(self, contact): 152 item = QtGui.QStandardItem() 153 self.appendRow(item) 154 nodejid = str(contact.jid) 155 self.setData(self.index(item.row(), 0), 156 QtCore.QVariant(QtCore.QString(nodejid))) 157 if nodejid not in self.roster.items: 158 self.roster.items[nodejid] = contact 159 160 class jlibPresence(QAxonObject): 161 def __init__(self, parent=None): 162 QAxonObject.__init__(self, parent) 163 QtCore.QObject.connect(self, QtCore.SIGNAL("acceptSubscription(PyQt_PyObject)"), 164 self.acceptSubscription) 165 QtCore.QObject.connect(self, QtCore.SIGNAL("rejectSubscription(PyQt_PyObject)"), 166 self.rejectSubscription) 167 QtCore.QObject.connect(self, QtCore.SIGNAL("requestSubscription(PyQt_PyObject)"), 168 self.requestSubscription) 169 QtCore.QObject.connect(self, QtCore.SIGNAL("requestUnsubscription(PyQt_PyObject)"), 170 self.requestUnsubscription) 171 172 def setComponent(self, component): 173 QAxonObject.setComponent(self, component) 174 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'inbox') 175 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'acceptsub') 176 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'rejectsub') 177 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'requestsub') 178 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'requestunsub') 179 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'requestedsub') 180 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'requestedunsub') 181 182 def getLinkages(self): 183 linkages = {("xmpp", "%s.presence" % XMPP_CLIENT_NS): ("presencedisp", "inbox"), 184 ("presencedisp", "log"): ('logger', "inbox"), 185 ("presencedisp", "xmpp.subscribe"): ("presencehandler", "requestedsub"), 186 ("presencedisp", "xmpp.unsubscribe"): ("presencehandler", "requestedunsub"), 187 ("presencehandler", "outbox"): ("presencedisp", "forward"), 188 ("presencehandler", "roster"): ("rosterdisp", "forward"), 189 ("presencedisp", "outbox"): ("xmpp", "forward")} 190 return dict(presencedisp=PresenceDispatcher(), presencehandler=self.component), linkages 191 192 def acceptSubscription(self, contact_jid): 193 self._deliver(contact_jid, 'acceptsub') 194 195 def rejectSubscription(self, contact_jid): 196 self._deliver(contact_jid, 'rejectsub') 197 198 def requestSubscription(self, contact_jid): 199 self._deliver(contact_jid, 'requestsub') 200 201 def requestUnsubscription(self, contact_jid): 202 self._deliver(contact_jid, 'requestunsub') 203 204 class jlibPresenceComponent(component): 205 Inboxes = {"inbox" : "headstock.api.contact.Presence instance", 206 "control" : "Shutdown the client stream", 207 "jid" : "headstock.api.jid.JID instance received from the server", 208 "requestedsub" : "Received subscription from a peer", 209 "requestedunsub" : "Received unsubscription from a peer", 210 "acceptsub" : "Accepted subscription", 211 "rejectsub" : "Rejected subscription", 212 "requestsub" : "Request subscription to a peer", 213 "requestunsub" : "Request unsubscription to a peer"} 214 215 Outboxes = {"outbox" : "headstock.api.contact.Presence instance to return to the server", 216 "signal" : "Shutdown signal", 217 "roster" : "", 218 "log" : "log",} 219 220 def __init__(self): 221 super(jlibPresenceComponent, self).__init__() 222 223 def setQObject(self, qobj): 224 self.qobj = qobj 225 226 def initComponents(self): 227 sub = SubscribeTo("JID") 228 self.link((sub, 'outbox'), (self, 'jid')) 229 self.addChildren(sub) 230 sub.activate() 231 232 return 1 233 234 def main(self): 235 yield self.initComponents() 236 237 while 1: 238 if self.dataReady("control"): 239 mes = self.recv("control") 240 241 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 242 self.send(producerFinished(), "signal") 243 break 244 245 if self.dataReady("jid"): 246 self.from_jid = self.recv('jid') 247 248 if self.dataReady("requestedsub"): 249 p = self.recv("requestedsub") 250 p.swap_jids() 251 252 self.qobj.emit(QtCore.SIGNAL("requestedSubscription(PyQt_PyObject)"), p) 253 254 if self.dataReady("requestedunsub"): 255 p = self.recv("requestedunsub") 256 p.swap_jids() 257 258 self.qobj.emit(QtCore.SIGNAL("requestedUnsubscription(PyQt_PyObject)"), p) 259 260 if self.dataReady("acceptsub"): 261 to_jid = self.recv("acceptsub") 262 p = Presence(from_jid=self.from_jid, to_jid=unicode(to_jid), 263 type=u'subscribed') 264 self.send(p, "outbox") 265 266 if self.dataReady("rejectsub"): 267 to_jid = self.recv("rejectsub") 268 p = Presence(from_jid=self.from_jid, to_jid=unicode(to_jid), 269 type=u'unsubscribed') 270 self.send(p, "outbox") 271 272 if self.dataReady("requestsub"): 273 to_jid = self.recv("requestsub") 274 p = Presence(from_jid=self.from_jid, to_jid=unicode(to_jid), 275 type=u'subscribe') 276 self.send(p, "outbox") 277 278 if self.dataReady("requestunsub"): 279 to_jid = self.recv("requestunsub") 280 p = Presence(from_jid=self.from_jid, to_jid=unicode(to_jid), 281 type=u'unsubscribe') 282 self.send(p, "outbox") 283 284 285 if not self.anyReady(): 286 self.pause() 287 288 yield 1 289 oss/jlib/jlib/gui/chat.py
r709 r710 27 27 message) 28 28 history = self.chat.toPlainText() 29 self.chat.setText(history + QtCore.QString("%s: %s\n" % (str(self. qobj.jid), str(message))))29 self.chat.setText(history + QtCore.QString("%s: %s\n" % (str(self.contact_jid), str(message)))) 30 30 self.message.clear() 31 31 oss/jlib/jlib/gui/contact.py
r709 r710 3 3 4 4 from jlib.gui.contactui import Ui_jlibContacts 5 from jlib.core.contact import jlibContact, jlibContactComponent, jlibContactModel 5 from jlib.core.contact import jlibContact, jlibContactComponent, \ 6 jlibContactModel, jlibPresence, jlibPresenceComponent 6 7 7 8 __all__ = ['jlibContactWidget'] … … 15 16 Ui_jlibContacts.setupUi(self, parent) 16 17 17 self.qobj = jlibContact(parent=self) 18 self.qobj.setComponent(jlibContactComponent()) 19 QtCore.QObject.connect(self.qobj, QtCore.SIGNAL("receivedRoster(PyQt_PyObject)"), 18 self.contacts.contextMenuEvent = self.contextMenuEvent 19 20 self.contact = jlibContact(parent=self) 21 self.contact.setComponent(jlibContactComponent()) 22 23 self.presence = jlibPresence(parent=self) 24 self.presence.setComponent(jlibPresenceComponent()) 25 26 QtCore.QObject.connect(self.contact, QtCore.SIGNAL("receivedRoster(PyQt_PyObject)"), 20 27 self.receivedRoster) 28 QtCore.QObject.connect(self.contact, QtCore.SIGNAL("removedContact(PyQt_PyObject)"), 29 self.removedContact) 30 QtCore.QObject.connect(self.contact, QtCore.SIGNAL("addedContact(PyQt_PyObject)"), 31 self.addedContact) 32 33 QtCore.QObject.connect(self.presence, QtCore.SIGNAL("requestedSubscription(PyQt_PyObject)"), 34 self.requestedSubscription) 35 21 36 22 37 model = jlibContactModel(parent=self.contacts) … … 28 43 model = self.contacts.model() 29 44 model.setRoster(roster) 45 46 def removedContact(self, contact): 47 model = self.contacts.model() 48 model.deleteContact(contact) 49 50 def addedContact(self, contact): 51 model = self.contacts.model() 52 model.addContact(contact) 30 53 31 54 def clicked(self, index): … … 33 56 self.emit(QtCore.SIGNAL("contactClicked(PyQt_PyObject)"), contact) 34 57 58 def requestedSubscription(self, presence): 59 reply = QtGui.QMessageBox.question(self, 'Subscription requested', 60 "%s wants to connect to you. Do you agree?" % str(presence.to_jid), 61 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) 62 if reply == QtGui.QMessageBox.Yes: 63 self.presence.emit(QtCore.SIGNAL("acceptSubscription(PyQt_PyObject)"), presence.to_jid) 64 self.presence.emit(QtCore.SIGNAL("requestSubscription(PyQt_PyObject)"), presence.to_jid) 65 else: 66 self.presence.emit(QtCore.SIGNAL("rejectSubscription(PyQt_PyObject)"), presence.to_jid) 67 68 def unsubscribeFromContact(self): 69 index = self.contacts.currentIndex() 70 if index.isValid(): 71 contact = index.model().getContact(index) 72 reply = QtGui.QMessageBox.question(self, 'Unsubscribe from contact', 73 "Do you really want to unsubscribe from %s?" % str(contact.jid), 74 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) 75 if reply == QtGui.QMessageBox.Yes: 76 self.presence.emit(QtCore.SIGNAL("rejectSubscription(PyQt_PyObject)"), contact.jid) 77 self.presence.emit(QtCore.SIGNAL("requestUnsubscription(PyQt_PyObject)"), contact.jid) 78 79 def contextMenuEvent(self, event): 80 menu = QtGui.QMenu(self.parent()) 81 actionUnsub = QtGui.QAction(QtCore.QString("Unsubscribe"), self.parent()) 82 QtCore.QObject.connect(actionUnsub, QtCore.SIGNAL("triggered()"), self.unsubscribeFromContact) 83 menu.addAction(actionUnsub) 84 menu.exec_(event.globalPos()) 85
