Changeset 712
- Timestamp:
- 07/09/08 10:27:39 (5 months ago)
- Files:
-
- oss/jlib/designer/ui/subscriptiondialog.ui (added)
- oss/jlib/examples/basic/client.py (modified) (1 diff)
- oss/jlib/jlib/core/contact.py (modified) (10 diffs)
- oss/jlib/jlib/gui/contact.py (modified) (4 diffs)
- oss/jlib/jlib/gui/subscriptiondialog.py (added)
- oss/jlib/jlib/gui/subscriptiondialogui.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oss/jlib/examples/basic/client.py
r710 r712 56 56 chatUi = jlibChatWidget(str(contact.jid), parent=widget) 57 57 self.connection.emit(QtCore.SIGNAL("registerLinkages(PyQt_PyObject)"), chatUi.qobj) 58 self.tabWidget.addTab(widget, QtCore.QString(str(contact.jid))) 58 tab = self.tabWidget.addTab(widget, QtCore.QString(str(contact.jid))) 59 self.tabWidget.setCurrentIndex(tab) 59 60 60 61 oss/jlib/jlib/core/contact.py
r711 r712 26 26 QtCore.QObject.connect(self, QtCore.SIGNAL("removeContact(PyQt_PyObject)"), 27 27 self.removeContact) 28 QtCore.QObject.connect(self, QtCore.SIGNAL("addContact(PyQt_PyObject)"), 29 self.addContact) 30 QtCore.QObject.connect(self, QtCore.SIGNAL("addContact(PyQt_PyObject, PyQt_PyObject)"), 31 self.addContactWithGroups) 28 32 29 33 def setComponent(self, component): … … 32 36 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'pushed') 33 37 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'remove') 38 self.emit(QtCore.SIGNAL("setupOneMapping(PyQt_PyObject)"), 'add') 34 39 35 40 def getLinkages(self): … … 45 50 self._deliver(contact_jid, 'remove') 46 51 52 def addContact(self, contact_jid): 53 self._deliver((contact_jid, []), 'add') 54 55 def addContactWithGroups(self, contact_jid, groups): 56 self._deliver((contact_jid, groups), 'add') 57 47 58 class jlibContactComponent(component): 48 59 Inboxes = {"inbox" : "headstock.api.contact.Roster instance", … … 50 61 "pushed" : "roster stanzas pushed by the server", 51 62 "remove" : "", 63 "add" : "", 52 64 "jid" : "headstock.api.jid.JID instance received from the server", 53 65 "ask-activity" : "request activity status to the server for each roster contact"} … … 93 105 for nodeid in roster.items: 94 106 contact = roster.items[nodeid] 95 if contact.subscription == 'remove':107 if contact.subscription in ['remove', 'none']: 96 108 self.qobj.emit(QtCore.SIGNAL("removedContact(PyQt_PyObject)"), contact) 97 elif contact.subscription == 'from':109 elif contact.subscription in ['both', 'from']: 98 110 self.qobj.emit(QtCore.SIGNAL("addedContact(PyQt_PyObject)"), contact) 99 111 self.send(Roster(from_jid=self.from_jid, to_jid=nodeid, 100 112 type=u'result', stanza_id=generate_unique()), 'result') 113 114 if contact.subscription == 'none': 115 r = Roster(from_jid=self.from_jid, to_jid=nodeid, 116 type=u'set', stanza_id=generate_unique()) 117 i = Item(nodeid) 118 i.subscription = u'remove' 119 r.items[nodeid] = i 120 self.send(r, 'result') 101 121 102 122 if self.dataReady('remove'): … … 110 130 self.send(r, 'result') 111 131 132 if self.dataReady('add'): 133 contact_jid, groups = self.recv('add') 134 contact_jid = str(contact_jid) 135 r = Roster(from_jid=self.from_jid, to_jid=contact_jid, 136 type=u'set', stanza_id=generate_unique()) 137 i = Item(contact_jid) 138 i.groups = groups[:] 139 r.items[contact_jid] = i 140 self.send(r, 'result') 141 112 142 if self.dataReady("inbox"): 113 143 roster = self.recv("inbox") … … 138 168 QtGui.QStandardItemModel.__init__(self, parent) 139 169 self.roster = None 170 self.groups = {} 140 171 141 172 def setRoster(self, roster): … … 143 174 for nodeid in roster.items: 144 175 contact = roster.items[nodeid] 145 print contact.groups 146 self.addContact(contact) 176 self.setContact(contact) 147 177 148 178 def getContact(self, index): 149 179 return self.roster.items.values()[index.row()] 150 180 151 def getIndex(self, contact): 152 for nodeid in self.roster.items: 153 if str(contact.jid) == nodeid: 154 return self.index(self.roster.items.keys().index(nodeid), 0) 181 def updateContact(self, contact): 182 for contact in self.roster.items: 183 if unicode(contact.jid) == unicode(contact_jid): 184 self.roster.items 185 186 def getContactByJID(self, contact_jid): 187 return self.roster.items.get(str(contact_jid), None) 188 189 def hasContact(self, contact_jid): 190 return str(contact_jid) in self.roster.items 191 192 def getContactIndex(self, contact): 193 if self.hasContact(contact.jid): 194 row = self.roster.items.keys().index(str(contact.jid)) 195 return self.index(row, 0) 155 196 156 197 return QtCore.QModelIndex() 198 199 def getGroupIndex(self, group): 200 if group in self.groups: 201 return self.groups[group] 157 202 158 203 def deleteContact(self, contact): … … 167 212 self.removeRow(index.row(), index.parent()) 168 213 169 def addContact(self, contact): 170 item = QtGui.QStandardItem() 171 self.appendRow(item) 214 def setContact(self, contact): 215 item = self.itemFromIndex(self.getContactIndex(contact)) 216 if not item: 217 item = QtGui.QStandardItem() 218 if contact.groups: 219 for group in contact.groups: 220 groupItem = self.setGroup(group) 221 groupItem.appendRow(item) 222 else: 223 self.appendRow(item) 172 224 nodejid = str(contact.jid) 173 225 self.setData(self.index(item.row(), 0), 174 226 QtCore.QVariant(QtCore.QString(nodejid))) 175 if nodejid not in self.roster.items: 176 self.roster.items[nodejid] = contact 227 self.roster.items[nodejid] = contact 228 return item 229 230 def setGroup(self, group): 231 index = self.getGroupIndex(group) 232 item = self.itemFromIndex(index) 233 if not item: 234 item = QtGui.QStandardItem(QtCore.QString(group)) 235 self.appendRow(item) 236 self.groups[group] = index 237 return item 177 238 178 239 class jlibPresence(QAxonObject): … … 184 245 self.rejectSubscription) 185 246 QtCore.QObject.connect(self, QtCore.SIGNAL("requestSubscription(PyQt_PyObject)"), 186 self.requestSubscription) 247 self.requestSubscription) 187 248 QtCore.QObject.connect(self, QtCore.SIGNAL("requestUnsubscription(PyQt_PyObject)"), 188 249 self.requestUnsubscription) oss/jlib/jlib/gui/contact.py
r711 r712 5 5 from jlib.core.contact import jlibContact, jlibContactComponent, \ 6 6 jlibContactModel, jlibPresence, jlibPresenceComponent 7 from jlib.gui.subscriptiondialog import jlibSubscriptionDialog 7 8 8 9 __all__ = ['jlibContactWidget'] … … 55 56 def addedContact(self, contact): 56 57 model = self.contacts.model() 57 model. addContact(contact)58 model.setContact(contact) 58 59 59 60 def clicked(self, index): … … 83 84 self.contact.emit(QtCore.SIGNAL("removeContact(PyQt_PyObject)"), contact.jid) 84 85 86 def subscribeToContact(self): 87 ui = jlibSubscriptionDialog() 88 ui.show() 89 if ui.exec_() == QtGui.QDialog.Accepted: 90 contact_jid = unicode(ui.contactJid.text()) 91 group = [] 92 if not ui.group.text().isEmpty(): 93 group.append(unicode(ui.group.text())) 94 self.contact.emit(QtCore.SIGNAL("addContact(PyQt_PyObject, PyQt_PyObject)"), 95 contact_jid, group) 96 self.presence.emit(QtCore.SIGNAL("requestSubscription(PyQt_PyObject)"), contact_jid) 97 85 98 def contextMenuEvent(self, event): 86 99 menu = QtGui.QMenu(self.parent()) … … 88 101 QtCore.QObject.connect(actionUnsub, QtCore.SIGNAL("triggered()"), self.unsubscribeFromContact) 89 102 menu.addAction(actionUnsub) 103 actionSub = QtGui.QAction(QtCore.QString("Subscribe to contact..."), self.parent()) 104 QtCore.QObject.connect(actionSub, QtCore.SIGNAL("triggered()"), self.subscribeToContact) 105 menu.addAction(actionSub) 90 106 menu.exec_(event.globalPos()) 91 107
