Skip to content

Commit

Permalink
group related bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dae-eklen committed May 10, 2012
1 parent c782b39 commit befe072
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
10 changes: 3 additions & 7 deletions AbstractContactList.py
Expand Up @@ -30,14 +30,10 @@ def addGroup(self, group):
self.tree[group] = {}
self.addTopLevelItem(self.groups[group])

def removeGroup(self, group, ind = None):
for (index, d) in enumerate(self.groups):
if d == group:
ind = index

def removeGroup(self, group):
if group:
self.takeTopLevelItem(ind)
del self.groups[group]
self.takeTopLevelItem(self.indexOfTopLevelItem(self.groups[group]))
del self.groups[group]

def presence(self, data):
jid, show = data
Expand Down
24 changes: 20 additions & 4 deletions AbstractDialog.py
Expand Up @@ -81,24 +81,40 @@ def updateDialog(self):
if len(self.jidTo) is 1:
if self.initialJidTo != self.jidTo: # if person is new
initialJid = self.setCheckboxes()
self.chb_members.setChecked(False)
self.showMembersBuddies(False)
self.close()

self.buddyList.newDialog(self.jidTo[0])

# restore initial jidTo
self.jidTo[0] = initialJid[0]
self.jidTo[0] = unicode(initialJid[0])
else:
if self.initialJidTo != self.jidTo: # if selected people are new
if not self.oldMUC(): # if selected people are new
initialJid = self.setCheckboxes()
self.close()

self.buddyList.newMUCItem(self.jidTo)
self.buddyList.newMUCDialog(self.jidTo)

# restore initial jidTo
self.jidTo = []
for el in initialJid:
self.jidTo.append(el)
self.jidTo.append(unicode(el))
self.chb_members.setChecked(False)
self.showMembersBuddies(False)
self.close()

def oldMUC(self):
# True - elements in self.initialJidTo match ones in self.jidTo,
# False - otherwise
match = 0
for initJid in self.initialJidTo:
for jid in self.jidTo:
if initJid == jid:
match = match + 1
if len(self.jidTo) == len(self.initialJidTo) == match:
return True
return False

def setCheckboxes(self):
initialJid = []
Expand Down
39 changes: 20 additions & 19 deletions BuddyList.py
Expand Up @@ -2,6 +2,7 @@
from PyQt4.QtCore import Qt, SIGNAL, QSettings
import time, re

from constants import MUC_GROUP_TITLE
from BuddyItem import BuddyItem
from AbstractContactList import AbstractContactList
from MUCItem import MUCItem
Expand Down Expand Up @@ -54,17 +55,19 @@ def remove(self):
match = match + 1
if len(self.currentItem.jid) == match ==len(keyList):
# make elements unicode
for n in range(len(keyList)): keyList[n] = unicode(keyList[n])
for n in range(len(keyList)): keyList[n] = unicode(keyList[n])

group = "Multi-User Chats"
self.groups[group].removeChild(self.muc[str(keyList)])
del self.muc[str(keyList)]
del self.tree[group][str(keyList)]

if len(self.tree[group].keys()) is 0:
self.removeGroup(group)
del self.tree[MUC_GROUP_TITLE][str(keyList)]
self.groups[MUC_GROUP_TITLE].removeChild(self.muc[str(keyList)])
#self.emit(SIGNAL("closeMUC"))

if len(self.tree[MUC_GROUP_TITLE].keys()) is 0:
self.removeGroup(MUC_GROUP_TITLE)
del self.tree[MUC_GROUP_TITLE]

del self.muc[str(keyList)]
self.updateSettingsMUC()
self.hideGroups()

def constructMUC(self):
# get MUC from settings
Expand All @@ -73,9 +76,8 @@ def constructMUC(self):
mucs = self.settings.value("MUC", "")
self.settings.endGroup()

if mucs is not None:
group = "Multi-User Chats"
self.addGroup(group)
if mucs is not None:
self.addGroup(MUC_GROUP_TITLE)

# muc from settings to list
emailPattern = """[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}"""
Expand All @@ -86,13 +88,13 @@ def constructMUC(self):
for n in range(len(jidsFromOneMUC)): jidsFromOneMUC[n] = unicode(jidsFromOneMUC[n])

# add MUC item to list
self.muc[str(jidsFromOneMUC)] = MUCItem(self, self.groups[group], jidsFromOneMUC, "-", self.connection)
self.muc[str(jidsFromOneMUC)] = MUCItem(self, self.groups[MUC_GROUP_TITLE], jidsFromOneMUC, "-", self.connection)

titleMUC = "Group chat (" + str(len(jidsFromOneMUC)) + ")"
self.muc[str(jidsFromOneMUC)].setName(titleMUC)

self.groups[group].addChild(self.muc[str(jidsFromOneMUC)])
self.tree[group][str(jidsFromOneMUC)] = self.muc[str(jidsFromOneMUC)]
self.groups[MUC_GROUP_TITLE].addChild(self.muc[str(jidsFromOneMUC)])
self.tree[MUC_GROUP_TITLE][str(jidsFromOneMUC)] = self.muc[str(jidsFromOneMUC)]

def sendMessage(self, item, col):
if item and item.type() == QTreeWidgetItem.UserType + 1:
Expand All @@ -104,20 +106,19 @@ def newDialog(self, jid):
child.createMsgDialog()

def newMUCItem(self, jid):
group = "Multi-User Chats"
if not self.MUCExists(jid):
self.addGroup(group)
self.addGroup(MUC_GROUP_TITLE)

# make elements unicode
for n in range(len(jid)): jid[n] = unicode(jid[n])

self.muc[str(jid)] = MUCItem(self, self.groups[group], jid, "-", self.connection)
self.muc[str(jid)] = MUCItem(self, self.groups[MUC_GROUP_TITLE], jid, "-", self.connection)

titleMUC = "Group chat (" + str(len(jid)) + ")"
self.muc[str(jid)].setName(titleMUC)

self.groups[group].addChild(self.muc[str(jid)])
self.tree[group][str(jid)] = self.muc[str(jid)]
self.groups[MUC_GROUP_TITLE].addChild(self.muc[str(jid)])
self.tree[MUC_GROUP_TITLE][str(jid)] = self.muc[str(jid)]

self.updateSettingsMUC()

Expand Down
2 changes: 2 additions & 0 deletions constants.py
Expand Up @@ -3,6 +3,8 @@

SHOW = ('available', 'chat', 'away', 'xa', 'dnd', 'offline')

MUC_GROUP_TITLE = "Multi-User Chats"


PATH_UI_MAIN = os.path.join('.', 'interface', 'ui_mainwindow.ui')
PATH_UI_CONNECTION = os.path.join('.', 'interface', 'ui_connection.ui')
Expand Down
2 changes: 1 addition & 1 deletion main.py
Expand Up @@ -168,7 +168,7 @@ def showOfflineBuddies(self):

if __name__ == "__main__":
# Setup logging
logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
#logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')

app = QApplication(sys.argv)
window = MainWindow()
Expand Down

0 comments on commit befe072

Please sign in to comment.