Bug fixes: Lots o' corner cases

This commit is contained in:
Kiooeht 2011-05-05 23:25:51 -07:00
parent 36917ab74d
commit 35d0273d68

View file

@ -376,19 +376,15 @@ class userConfig(object):
def getGroups(self): def getGroups(self):
if not self.groups.has_key('groups'): if not self.groups.has_key('groups'):
self.saveGroups([["Chums", True]]) self.saveGroups([["Chums", True]])
groups = self.groups.get('groups', [["Chums", True]]) return self.groups.get('groups', [["Chums", True]])
default = False
for g in groups:
if g[0] == "Chums":
default = True
break
if not default:
groups.insert(0, ["Chums", True])
self.saveGroups(groups)
return groups
def addGroup(self, group, open=True): def addGroup(self, group, open=True):
l = self.getGroups() l = self.getGroups()
if group not in l: exists = False
for g in l:
if g[0] == group:
exists = True
break
if not exists:
l.append([group,open]) l.append([group,open])
l.sort() l.sort()
self.saveGroups(l) self.saveGroups(l)
@ -401,6 +397,13 @@ class userConfig(object):
l.pop(i) l.pop(i)
l.sort() l.sort()
self.saveGroups(l) self.saveGroups(l)
def expandGroup(self, group, open=True):
l = self.getGroups()
for g in l:
if g[0] == group:
g[1] = open
break
self.saveGroups(l)
def saveGroups(self, groups): def saveGroups(self, groups):
self.groups['groups'] = groups self.groups['groups'] = groups
try: try:
@ -705,7 +708,10 @@ class chumArea(RightClickTree):
def moveGroupMenu(self): def moveGroupMenu(self):
currentGroup = self.currentItem() currentGroup = self.currentItem()
if currentGroup: if currentGroup:
text = str(currentGroup.parent().text(0)) if currentGroup.parent():
text = str(currentGroup.parent().text(0))
else:
text = str(currentGroup.text(0))
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0:text.rfind(" (")] text = text[0:text.rfind(" (")]
currentGroup = text currentGroup = text
@ -813,49 +819,34 @@ class chumArea(RightClickTree):
def expandGroup(self): def expandGroup(self):
item = self.currentItem() item = self.currentItem()
text = str(item.text(0)) text = str(item.text(0))
if text.find(" ") != -1: if text.rfind(" (") != -1:
text = text[0:text.rfind(" (")] text = text[0:text.rfind(" (")]
if text in self.groups: if text in self.groups:
self.mainwindow.config.delGroup(text)
expand = item.isExpanded() expand = item.isExpanded()
self.mainwindow.config.addGroup(text, not expand) self.mainwindow.config.expandGroup(text, not expand)
elif text == "Chums":
self.mainwindow.config.set("openDefaultGroup", not item.isExpanded())
def addItem(self, chumLabel): def addItem(self, chumLabel):
if hasattr(self, 'groups'): if hasattr(self, 'groups'):
if chumLabel.chum.group not in self.groups: if chumLabel.chum.group not in self.groups:
if self.topLevelItemCount() == 0: chumLabel.chum.group = "Chums"
child_1 = QtGui.QTreeWidgetItem(["Chums"]) if "Chums" not in self.groups:
self.mainwindow.config.addGroup("Chums")
if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive):
if not self.findItems(chumLabel.chum.group, QtCore.Qt.MatchContains):
child_1 = QtGui.QTreeWidgetItem(["%s" % (chumLabel.chum.group)])
self.addTopLevelItem(child_1) self.addTopLevelItem(child_1)
if self.mainwindow.config.openDefaultGroup(): if self.openGroups[self.groups.index("%s" % (chumLabel.chum.group))]:
child_1.setExpanded(True) child_1.setExpanded(True)
else: for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(0).text(0)) text = str(self.topLevelItem(i).text(0))
if text.find(" ") != -1: if text.rfind(" (") != -1:
text = text[0:text.rfind(" (")] text = text[0:text.rfind(" (")]
if text != "Chums": if text == chumLabel.chum.group:
child_1 = QtGui.QTreeWidgetItem(["Chums"]) break
self.insertTopLevelItems(0, [child_1]) self.topLevelItem(i).addChild(chumLabel)
if self.mainwindow.config.openDefaultGroup():
child_1.setExpanded(True)
self.topLevelItem(0).addChild(chumLabel)
self.sort() self.sort()
else: if self.mainwindow.config.showOnlineNumbers():
if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive): self.showOnlineNumbers()
if not self.findItems(chumLabel.chum.group, QtCore.Qt.MatchContains):
child_1 = QtGui.QTreeWidgetItem(["%s" % (chumLabel.chum.group)])
self.addTopLevelItem(child_1)
if self.openGroups[self.groups.index("%s" % (chumLabel.chum.group))]:
child_1.setExpanded(True)
for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0))
if text.rfind(" (") != -1:
text = text[0:text.rfind(" (")]
if text == chumLabel.chum.group:
break
self.topLevelItem(i).addChild(chumLabel)
self.sort()
else: # usually means this is now the trollslum else: # usually means this is now the trollslum
if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive): if not self.findItems(chumLabel.handle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive):
self.topLevelItem(0).addChild(chumLabel) self.topLevelItem(0).addChild(chumLabel)
@ -885,7 +876,7 @@ class chumArea(RightClickTree):
elif mood.name() == "offline" and \ elif mood.name() == "offline" and \
len(chums) > 0: len(chums) > 0:
for c in chums: for c in chums:
self.takeItem(self.row(c)) self.takeItem(c)
chums = [] chums = []
for c in chums: for c in chums:
if (hasattr(c, 'mood')): if (hasattr(c, 'mood')):
@ -1822,7 +1813,7 @@ class PesterWindow(MovingWindow):
curChum = self.chumList.currentItem() curChum = self.chumList.currentItem()
if curChum: if curChum:
text = str(curChum.text(0)) text = str(curChum.text(0))
if text.find(" ") != -1: if text.rfind(" (") != -1:
text = text[0:text.rfind(" (")] text = text[0:text.rfind(" (")]
if text not in self.chumList.groups and \ if text not in self.chumList.groups and \
text != "Chums": text != "Chums":
@ -2187,7 +2178,7 @@ class PesterWindow(MovingWindow):
(gname, ok) = QtGui.QInputDialog.getText(self, "Add Group", "Enter a name for the new group:") (gname, ok) = QtGui.QInputDialog.getText(self, "Add Group", "Enter a name for the new group:")
if ok: if ok:
gname = unicode(gname) gname = unicode(gname)
if re.search("[^A-Za-z0-9\s]", gname) is not None: if re.search("[^A-Za-z0-9_\s]", gname) is not None:
msgbox = QtGui.QMessageBox() msgbox = QtGui.QMessageBox()
msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME") msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME")
msgbox.setStandardButtons(QtGui.QMessageBox.Ok) msgbox.setStandardButtons(QtGui.QMessageBox.Ok)