Changeset 713
- Timestamp:
- 07/09/08 15:29:54 (5 months ago)
- Files:
-
- oss/jlib/jlib/core/contact.py (modified) (1 diff)
- oss/jlib/jlib/gui/contact.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oss/jlib/jlib/core/contact.py
r712 r713 158 158 159 159 class jlibContactItem(QtGui.QStandardItem): 160 def __init__(self, parent=None): 161 QtGui.QStandardItem.__init__(self, parent) 160 def __init__(self, contact): 161 QtGui.QStandardItem.__init__(self) 162 self.contact = contact 162 163 163 164 def type(self): 164 165 return QtGui.QStandardItem.UserType + 101 166 167 class jlibContactGroupItem(QtGui.QStandardItem): 168 def __init__(self, group): 169 QtGui.QStandardItem.__init__(self) 170 self.group = group 171 172 def type(self): 173 return QtGui.QStandardItem.UserType + 102 165 174 166 175 class jlibContactModel(QtGui.QStandardItemModel): 167 176 def __init__(self, parent=None): 168 177 QtGui.QStandardItemModel.__init__(self, parent) 169 self. roster = None170 self.group s = {}178 self.contact_items = {} 179 self.group_items = {} 171 180 172 181 def setRoster(self, roster): 173 self.roster = roster174 182 for nodeid in roster.items: 175 183 contact = roster.items[nodeid] 184 for group in contact.groups: 185 self.setGroup(group) 176 186 self.setContact(contact) 177 187 188 def isAContactItem(self, index): 189 return self.itemFromIndex(index).type() == QtGui.QStandardItem.UserType + 101 190 178 191 def getContact(self, index): 179 return self.roster.items.values()[index.row()] 180 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 192 return self.itemFromIndex(index).contact 193 189 194 def hasContact(self, contact_jid): 190 return str(contact_jid) in self. roster.items191 195 return str(contact_jid) in self.contact_items 196 192 197 def getContactIndex(self, contact): 193 198 if self.hasContact(contact.jid): 194 row = self.roster.items.keys().index(str(contact.jid)) 195 return self.index(row, 0) 199 return self.contact_items[str(contact.jid)].index() 196 200 197 201 return QtCore.QModelIndex() 198 202 199 203 def getGroupIndex(self, group): 200 if group in self.groups: 201 return self.groups[group] 204 if group in self.group_items: 205 return self.group_items[group].index() 206 207 return QtCore.QModelIndex() 208 209 def getGroup(self, group): 210 if group in self.group_items: 211 return self.group_items[group] 202 212 203 213 def deleteContact(self, contact): 204 index = None 205 for nodeid in self.roster.items: 206 if str(contact.jid) == nodeid: 207 index = self.index(self.roster.items.keys().index(nodeid), 0) 208 del self.roster.items[nodeid] 209 break 210 211 if index: 214 index = self.getContactIndex(contact) 215 216 if index.isValid(): 217 del self.contact_items[str(contact.jid)] 212 218 self.removeRow(index.row(), index.parent()) 213 219 214 220 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) 221 rootItem = self.invisibleRootItem() 222 223 index = self.getContactIndex(contact) 224 if index.isValid(): 225 item = self.contact_items[str(contact.jid)] 226 else: 227 item = jlibContactItem(contact) 228 229 if contact.groups: 230 for group in contact.groups: 231 groupItem = self.getGroup(group) 232 groupItem.appendRow(item) 233 else: 234 rootItem.appendRow(item) 235 224 236 nodejid = str(contact.jid) 225 self.setData(self.index(item.row(), 0), 226 QtCore.QVariant(QtCore.QString(nodejid))) 227 self.roster.items[nodejid] = contact 237 item.setData(QtCore.QVariant(QtCore.QString(nodejid)), 238 QtCore.Qt.DisplayRole) 239 240 self.contact_items[nodejid] = item 241 228 242 return item 229 243 230 244 def setGroup(self, group): 231 245 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 246 if index.isValid(): 247 item = self.group_items[group] 248 else: 249 item = jlibContactGroupItem(group) 250 rootItem = self.invisibleRootItem() 251 rootItem.appendRow(item) 252 item.setData(QtCore.QVariant(QtCore.QString(str(group))), 253 QtCore.Qt.DisplayRole) 254 self.group_items[group] = item 237 255 return item 238 256 oss/jlib/jlib/gui/contact.py
r712 r713 59 59 60 60 def clicked(self, index): 61 contact = index.model().getContact(index) 62 self.emit(QtCore.SIGNAL("contactClicked(PyQt_PyObject)"), contact) 61 if index.model().isAContactItem(index): 62 contact = index.model().getContact(index) 63 self.emit(QtCore.SIGNAL("contactClicked(PyQt_PyObject)"), contact) 63 64 64 65 def requestedSubscription(self, presence): … … 98 99 def contextMenuEvent(self, event): 99 100 menu = QtGui.QMenu(self.parent()) 101 100 102 actionUnsub = QtGui.QAction(QtCore.QString("Unsubscribe"), self.parent()) 101 103 QtCore.QObject.connect(actionUnsub, QtCore.SIGNAL("triggered()"), self.unsubscribeFromContact) 102 104 menu.addAction(actionUnsub) 105 103 106 actionSub = QtGui.QAction(QtCore.QString("Subscribe to contact..."), self.parent()) 104 107 QtCore.QObject.connect(actionSub, QtCore.SIGNAL("triggered()"), self.subscribeToContact) 105 108 menu.addAction(actionSub) 109 106 110 menu.exec_(event.globalPos()) 107 111
