from qt import *
import DependentProjectsDlg as DPDlg
try:
    from qtlistview import *
except:
    pass

import coral

TM=coral.getTransactionManager()

class PropertyListItem(QCheckListItem):
    def __init__(self, parent, prj):
        QCheckListItem.__init__(self,parent,unicode(prj.getFilename()),QCheckListItem.CheckBox)
        self.prj=prj
        
class DependentProjectsDialog(DPDlg.DependentProjectsDlg):
    def __init__(self, prjs=[], parent=None):
        DPDlg.DependentProjectsDlg.__init__(self,parent)
        self.projectToSave = {}
        self.projects = prjs
        if not self.projects[0]:
            return
        item = QListViewItem(self.dtable, unicode(self.projects[0].getFilename()))
        for p in self.projects[1:]:
            item = PropertyListItem(self.dtable, p)
            item.setOn(True)
            self.projectToSave[item] = item.prj
        
        
    def valueChanged(self, item):
        if not item:
            return
        if not isinstance(item,PropertyListItem):
            return
        
        if item.isOn() and not self.projectToSave.has_key(item):
            self.projectToSave[item] = item.prj

        elif not item.isOn() and self.projectToSave.has_key(item):
            self.projectToSave.pop(item, None)

    def getSelected(self):
        return self.projectToSave.values()
         
