Rearrange all groups (including default) + bug fixes

This commit is contained in:
Kiooeht 2011-04-25 22:45:29 -07:00
parent 846d7b6dbb
commit 973235a95d

View file

@ -276,12 +276,12 @@ class userConfig(object):
self.groups = json.load(fp) self.groups = json.load(fp)
fp.close() fp.close()
except IOError: except IOError:
chumdict = {} self.groups = {}
fp = open("%s/groups.js" % (self.logpath), 'w') fp = open("%s/groups.js" % (self.logpath), 'w')
json.dump(self.groups, fp) json.dump(self.groups, fp)
fp.close() fp.close()
except ValueError: except ValueError:
chumdict = {} self.groups = {}
fp = open("%s/groups.js" % (self.logpath), 'w') fp = open("%s/groups.js" % (self.logpath), 'w')
json.dump(self.groups, fp) json.dump(self.groups, fp)
fp.close() fp.close()
@ -314,13 +314,13 @@ class userConfig(object):
def sortMethod(self): def sortMethod(self):
return self.config.get('sortMethod', 0) return self.config.get('sortMethod', 0)
def useGroups(self): def useGroups(self):
if not self.config.has_key('useGroups'):
self.set("useGroups", False)
return self.config.get('useGroups', False) return self.config.get('useGroups', False)
def openDefaultGroup(self): def openDefaultGroup(self):
if not self.config.has_key('openDefaultGroup'): groups = self.getGroups()
self.set("openDefaultGroup", True) for g in groups:
return self.config.get('openDefaultGroup', True) if g[0] == "Chums":
return g[1]
return True
def showEmptyGroups(self): def showEmptyGroups(self):
if not self.config.has_key('emptyGroups'): if not self.config.has_key('emptyGroups'):
self.set("emptyGroups", False) self.set("emptyGroups", False)
@ -358,9 +358,18 @@ class userConfig(object):
self.set('block', l) self.set('block', l)
def getGroups(self): def getGroups(self):
if not self.groups.has_key('groups'): if not self.groups.has_key('groups'):
self.saveGroups([]) self.saveGroups([["Chums", True]])
return self.groups.get('groups', []) groups = self.groups.get('groups', [["Chums", True]])
def addGroup(self, group, open=False): 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):
l = self.getGroups() l = self.getGroups()
if group not in l: if group not in l:
l.append([group,open]) l.append([group,open])
@ -616,7 +625,7 @@ class chumArea(RightClickTree):
if text.rfind(" ") != -1: if text.rfind(" ") != -1:
text = text[0:text.rfind(" ")] text = text[0:text.rfind(" ")]
if text == "Chums": if text == "Chums":
return self.groupMenu return None
elif text in self.groups: elif text in self.groups:
return self.groupMenu return self.groupMenu
else: else:
@ -647,9 +656,8 @@ class chumArea(RightClickTree):
text = str(self.topLevelItem(i).text(0)) text = str(self.topLevelItem(i).text(0))
if text.rfind(" ") != -1: if text.rfind(" ") != -1:
text = text[0:text.rfind(" ")] text = text[0:text.rfind(" ")]
if text != "Chums": gTemp.append([unicode(text), self.topLevelItem(i).isExpanded()])
gTemp.append([unicode(text), self.topLevelItem(i).isExpanded()]) self.mainwindow.config.saveGroups(gTemp)
self.mainwindow.config.setGroups(gTemp)
else: else:
item = self.itemAt(event.pos()) item = self.itemAt(event.pos())
if item: if item:
@ -731,11 +739,6 @@ class chumArea(RightClickTree):
if text.rfind(" ") != -1: if text.rfind(" ") != -1:
text = text[0:text.rfind(" ")] text = text[0:text.rfind(" ")]
curgroups.append(text) curgroups.append(text)
if "Chums" not in curgroups:
child_1 = QtGui.QTreeWidgetItem(["Chums"])
self.addTopLevelItem(child_1)
if self.mainwindow.config.openDefaultGroup():
child_1.setExpanded(True)
for i,g in enumerate(self.groups): for i,g in enumerate(self.groups):
if g not in curgroups: if g not in curgroups:
child_1 = QtGui.QTreeWidgetItem(["%s" % (g)]) child_1 = QtGui.QTreeWidgetItem(["%s" % (g)])
@ -868,7 +871,9 @@ class chumArea(RightClickTree):
c.setMood(mood) c.setMood(mood)
if self.mainwindow.config.sortMethod() == 1: if self.mainwindow.config.sortMethod() == 1:
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
saveCurrent = self.currentItem()
self.moodSort(i) self.moodSort(i)
self.setCurrentItem(saveCurrent)
if self.mainwindow.config.showOnlineNumbers(): if self.mainwindow.config.showOnlineNumbers():
self.showOnlineNumbers() self.showOnlineNumbers()
return oldmood return oldmood