Chum groups updates: Save groups in own database, allow custom group ordering/drag-drop groups
This commit is contained in:
parent
3732539cc6
commit
d4e58ccc9a
2 changed files with 89 additions and 34 deletions
10
irc.py
10
irc.py
|
@ -53,7 +53,7 @@ class PesterIRC(QtCore.QThread):
|
||||||
if not res:
|
if not res:
|
||||||
logging.debug("false Yield: %s, returning" % res)
|
logging.debug("false Yield: %s, returning" % res)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setConnected(self):
|
def setConnected(self):
|
||||||
self.registeredIRC = True
|
self.registeredIRC = True
|
||||||
self.connected.emit()
|
self.connected.emit()
|
||||||
|
@ -87,7 +87,7 @@ class PesterIRC(QtCore.QThread):
|
||||||
self.cli.command_handler.getMood(*chums)
|
self.cli.command_handler.getMood(*chums)
|
||||||
@QtCore.pyqtSlot(PesterList)
|
@QtCore.pyqtSlot(PesterList)
|
||||||
def getMoods(self, chums):
|
def getMoods(self, chums):
|
||||||
self.cli.command_handler.getMood(*chums)
|
self.cli.command_handler.getMood(*chums)
|
||||||
@QtCore.pyqtSlot(QtCore.QString, QtCore.QString)
|
@QtCore.pyqtSlot(QtCore.QString, QtCore.QString)
|
||||||
def sendMessage(self, text, handle):
|
def sendMessage(self, text, handle):
|
||||||
h = unicode(handle)
|
h = unicode(handle)
|
||||||
|
@ -251,7 +251,7 @@ class PesterHandler(DefaultCommandHandler):
|
||||||
mychumhandle = self.mainwindow.profile().handle
|
mychumhandle = self.mainwindow.profile().handle
|
||||||
mymood = self.mainwindow.profile().mood.value()
|
mymood = self.mainwindow.profile().mood.value()
|
||||||
if msg.find(mychumhandle, 8) != -1:
|
if msg.find(mychumhandle, 8) != -1:
|
||||||
helpers.msg(self.client, "#pesterchum",
|
helpers.msg(self.client, "#pesterchum",
|
||||||
"MOOD >%d" % (mymood))
|
"MOOD >%d" % (mymood))
|
||||||
elif chan[0] == '#':
|
elif chan[0] == '#':
|
||||||
if msg[0:16] == "PESTERCHUM:TIME>":
|
if msg[0:16] == "PESTERCHUM:TIME>":
|
||||||
|
@ -347,7 +347,7 @@ class PesterHandler(DefaultCommandHandler):
|
||||||
logging.info("---> recv \"CHANNELS END\"")
|
logging.info("---> recv \"CHANNELS END\"")
|
||||||
self.parent.channelListReceived.emit(pl)
|
self.parent.channelListReceived.emit(pl)
|
||||||
self.channel_list = []
|
self.channel_list = []
|
||||||
|
|
||||||
def getMood(self, *chums):
|
def getMood(self, *chums):
|
||||||
chumglub = "GETMOOD "
|
chumglub = "GETMOOD "
|
||||||
for c in chums:
|
for c in chums:
|
||||||
|
@ -364,4 +364,4 @@ class PesterHandler(DefaultCommandHandler):
|
||||||
helpers.msg(self.client, "#pesterchum", chumglub)
|
helpers.msg(self.client, "#pesterchum", chumglub)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
self.parent.setConnectionBroken()
|
self.parent.setConnectionBroken()
|
||||||
|
|
||||||
|
|
113
pesterchum.py
113
pesterchum.py
|
@ -120,6 +120,8 @@ class PesterProfileDB(dict):
|
||||||
else:
|
else:
|
||||||
self.logpath = _datadir+"logs"
|
self.logpath = _datadir+"logs"
|
||||||
|
|
||||||
|
if not os.path.exists(self.logpath):
|
||||||
|
os.makedirs(self.logpath)
|
||||||
try:
|
try:
|
||||||
fp = open("%s/chums.js" % (self.logpath), 'r')
|
fp = open("%s/chums.js" % (self.logpath), 'r')
|
||||||
chumdict = json.load(fp)
|
chumdict = json.load(fp)
|
||||||
|
@ -261,6 +263,29 @@ class userConfig(object):
|
||||||
self.userprofile = userProfile(self.config["defaultprofile"])
|
self.userprofile = userProfile(self.config["defaultprofile"])
|
||||||
else:
|
else:
|
||||||
self.userprofile = None
|
self.userprofile = None
|
||||||
|
|
||||||
|
if sys.platform != "darwin":
|
||||||
|
self.logpath = "logs"
|
||||||
|
else:
|
||||||
|
self.logpath = _datadir+"logs"
|
||||||
|
|
||||||
|
if not os.path.exists(self.logpath):
|
||||||
|
os.makedirs(self.logpath)
|
||||||
|
try:
|
||||||
|
fp = open("%s/groups.js" % (self.logpath), 'r')
|
||||||
|
self.groups = json.load(fp)
|
||||||
|
fp.close()
|
||||||
|
except IOError:
|
||||||
|
chumdict = {}
|
||||||
|
fp = open("%s/groups.js" % (self.logpath), 'w')
|
||||||
|
json.dump(self.groups, fp)
|
||||||
|
fp.close()
|
||||||
|
except ValueError:
|
||||||
|
chumdict = {}
|
||||||
|
fp = open("%s/groups.js" % (self.logpath), 'w')
|
||||||
|
json.dump(self.groups, fp)
|
||||||
|
fp.close()
|
||||||
|
|
||||||
def chums(self):
|
def chums(self):
|
||||||
if not self.config.has_key('chums'):
|
if not self.config.has_key('chums'):
|
||||||
self.set("chums", [])
|
self.set("chums", [])
|
||||||
|
@ -332,15 +357,15 @@ class userConfig(object):
|
||||||
l.pop(l.index(handle))
|
l.pop(l.index(handle))
|
||||||
self.set('block', l)
|
self.set('block', l)
|
||||||
def getGroups(self):
|
def getGroups(self):
|
||||||
if not self.config.has_key('groups'):
|
if not self.groups.has_key('groups'):
|
||||||
self.set('groups', [])
|
self.saveGroups([])
|
||||||
return self.config.get('groups', [])
|
return self.groups.get('groups', [])
|
||||||
def addGroup(self, group, open=False):
|
def addGroup(self, group, open=False):
|
||||||
l = self.getGroups()
|
l = self.getGroups()
|
||||||
if group not in l:
|
if group not in l:
|
||||||
l.append([group,open])
|
l.append([group,open])
|
||||||
l.sort()
|
l.sort()
|
||||||
self.set('groups', l)
|
self.saveGroups(l)
|
||||||
def delGroup(self, group):
|
def delGroup(self, group):
|
||||||
l = self.getGroups()
|
l = self.getGroups()
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -349,7 +374,17 @@ class userConfig(object):
|
||||||
i = i+1
|
i = i+1
|
||||||
l.pop(i)
|
l.pop(i)
|
||||||
l.sort()
|
l.sort()
|
||||||
self.set('groups', l)
|
self.saveGroups(l)
|
||||||
|
def saveGroups(self, groups):
|
||||||
|
self.groups['groups'] = groups
|
||||||
|
try:
|
||||||
|
jsonoutput = json.dumps(self.groups)
|
||||||
|
except ValueError, e:
|
||||||
|
raise e
|
||||||
|
fp = open("%s/groups.js" % (self.logpath), 'w')
|
||||||
|
fp.write(jsonoutput)
|
||||||
|
fp.close()
|
||||||
|
|
||||||
def server(self):
|
def server(self):
|
||||||
return self.config.get('server', 'irc.mindfang.org')
|
return self.config.get('server', 'irc.mindfang.org')
|
||||||
def port(self):
|
def port(self):
|
||||||
|
@ -508,10 +543,6 @@ class chumArea(RightClickTree):
|
||||||
gTemp = self.mainwindow.config.getGroups()
|
gTemp = self.mainwindow.config.getGroups()
|
||||||
self.groups = [g[0] for g in gTemp]
|
self.groups = [g[0] for g in gTemp]
|
||||||
self.openGroups = [g[1] for g in gTemp]
|
self.openGroups = [g[1] for g in gTemp]
|
||||||
# quick hack to sort saved groups
|
|
||||||
self.mainwindow.config.addGroup("f3rskv9dssag[%3ffvsla09iv34G#$v")
|
|
||||||
self.mainwindow.config.delGroup("f3rskv9dssag[%3ffvsla09iv34G#$v")
|
|
||||||
# end quick hack
|
|
||||||
self.showAllGroups()
|
self.showAllGroups()
|
||||||
if not self.mainwindow.config.hideOfflineChums():
|
if not self.mainwindow.config.hideOfflineChums():
|
||||||
self.showAllChums()
|
self.showAllChums()
|
||||||
|
@ -596,25 +627,49 @@ class chumArea(RightClickTree):
|
||||||
return self.optionsMenu
|
return self.optionsMenu
|
||||||
|
|
||||||
def dropEvent(self, event):
|
def dropEvent(self, event):
|
||||||
item = self.itemAt(event.pos())
|
thisitem = str(event.source().currentItem().text(0))
|
||||||
if item:
|
if thisitem.rfind(" ") != -1:
|
||||||
text = str(item.text(0))
|
thisitem = thisitem[0:thisitem.rfind(" ")]
|
||||||
if text.rfind(" ") != -1:
|
if thisitem == "Chums" or thisitem in self.groups:
|
||||||
text = text[0:text.rfind(" ")]
|
droppos = str(self.itemAt(event.pos()).text(0))
|
||||||
if text == "Chums" or text in self.groups:
|
if droppos.rfind(" ") != -1:
|
||||||
group = text
|
droppos = droppos[0:droppos.rfind(" ")]
|
||||||
else:
|
if droppos == "Chums" or droppos in self.groups:
|
||||||
ptext = str(item.parent().text(0))
|
saveOpen = self.openGroups[self.groups.index(thisitem)]
|
||||||
if ptext.rfind(" ") != -1:
|
saveDrop = self.itemAt(event.pos())
|
||||||
ptext = ptext[0:ptext.rfind(" ")]
|
saveItem = self.takeTopLevelItem(self.indexOfTopLevelItem(event.source().currentItem()))
|
||||||
group = ptext
|
self.insertTopLevelItems(self.indexOfTopLevelItem(saveDrop)+1, [saveItem])
|
||||||
chumLabel = event.source().currentItem()
|
if saveOpen:
|
||||||
chumLabel.chum.group = group
|
saveItem.setExpanded(True)
|
||||||
self.mainwindow.chumdb.setGroup(chumLabel.chum.handle, group)
|
|
||||||
self.takeItem(chumLabel)
|
gTemp = []
|
||||||
self.addItem(chumLabel)
|
for i in range(self.topLevelItemCount()):
|
||||||
if self.mainwindow.config.showOnlineNumbers():
|
text = str(self.topLevelItem(i).text(0))
|
||||||
self.showOnlineNumbers()
|
if text.rfind(" ") != -1:
|
||||||
|
text = text[0:text.rfind(" ")]
|
||||||
|
if text != "Chums":
|
||||||
|
gTemp.append([unicode(text), self.topLevelItem(i).isExpanded()])
|
||||||
|
self.mainwindow.config.setGroups(gTemp)
|
||||||
|
else:
|
||||||
|
item = self.itemAt(event.pos())
|
||||||
|
if item:
|
||||||
|
text = str(item.text(0))
|
||||||
|
if text.rfind(" ") != -1:
|
||||||
|
text = text[0:text.rfind(" ")]
|
||||||
|
if text == "Chums" or text in self.groups:
|
||||||
|
group = text
|
||||||
|
else:
|
||||||
|
ptext = str(item.parent().text(0))
|
||||||
|
if ptext.rfind(" ") != -1:
|
||||||
|
ptext = ptext[0:ptext.rfind(" ")]
|
||||||
|
group = ptext
|
||||||
|
chumLabel = event.source().currentItem()
|
||||||
|
chumLabel.chum.group = group
|
||||||
|
self.mainwindow.chumdb.setGroup(chumLabel.chum.handle, group)
|
||||||
|
self.takeItem(chumLabel)
|
||||||
|
self.addItem(chumLabel)
|
||||||
|
if self.mainwindow.config.showOnlineNumbers():
|
||||||
|
self.showOnlineNumbers()
|
||||||
|
|
||||||
def moveGroupMenu(self):
|
def moveGroupMenu(self):
|
||||||
currentGroup = self.currentItem()
|
currentGroup = self.currentItem()
|
||||||
|
@ -657,7 +712,7 @@ class chumArea(RightClickTree):
|
||||||
if not len(self.findItems(chandle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive)):
|
if not len(self.findItems(chandle, QtCore.Qt.MatchContains | QtCore.Qt.MatchRecursive)):
|
||||||
chumLabel = chumListing(c, self.mainwindow)
|
chumLabel = chumListing(c, self.mainwindow)
|
||||||
self.addItem(chumLabel)
|
self.addItem(chumLabel)
|
||||||
#self.sortItems()
|
self.sort()
|
||||||
def hideOfflineChums(self):
|
def hideOfflineChums(self):
|
||||||
for j in range(self.topLevelItemCount()):
|
for j in range(self.topLevelItemCount()):
|
||||||
i = 0
|
i = 0
|
||||||
|
|
Loading…
Reference in a new issue