import ProjectFilenameDlg as PFDlg
import qt
import string

class ProjectFilenameDialog(PFDlg.ProjectFilenameDlg):
    def __init__(self, parent=None):
        PFDlg.ProjectFilenameDlg.__init__(self,parent)
    
    def selectedFile(self):
        path=unicode(self.pathEdit.text())
        if path == "(empty)":
            path=""
            
        if path and path[-1] != u"/":
            path.append(u"/")
        return path+unicode(self.fileNameEdit.text())

    def setFilename(self, name):
        splitted=name.split('/')
        filename=splitted[-1]
        path=string.join(splitted[:-1],'/')
        self.fileNameEdit.setText(filename)
        if path:
            self.pathEdit.setText(path)
        else:
            self.pathEdit.setText("(empty)")
        
    def browseDirectory(self):
        folder=qt.QFileDialog.getExistingDirectory()
        if folder:
            self.pathEdit.setText(folder)

    def clearPath(self):
        self.pathEdit.setText("(empty)")
