# -*- coding: utf-8 -*-

# Copyright (c) 2002, 2003 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter options used to start a project in the VCS.
"""

import os

from qt import *

from OptionsForm import vcsOptionsForm
from Config import ConfigVcsSystems

class vcsOptionsDialog(vcsOptionsForm):
    """
    Class implementing a dialog to enter options used to start a project in the VCS.
    """
    def __init__(self, project, archiveName, archiveEditable=0, parent=None):
        """
        Constructor
        
        Arguments
        
            project -- reference to the project object
            
            archiveName -- name of the archive (string or QString)
            
            archiveEditable -- flag indicating that the archives name may be changed
                (boolean)
                
            parent -- parent widget (QWidget)
        """
        vcsOptionsForm.__init__(self, parent, None, 1)
        
        self.project = project
        
        vcsSystems = QStringList()
        for vcssys in ConfigVcsSystems:
            vcsSystems.append(vcssys)
        self.vcsComboBox.insertStringList(vcsSystems)
        
        hd = QDir.convertSeparators(QDir.homeDirPath())
        hd = os.path.join(str(hd), ConfigVcsSystems[0].lower() + 'root')
        self.vcsDirectoryEdit.setText(hd)
        
        self.vcsArchiveEdit.setText(archiveName)
        self.vcsArchiveEdit.setReadOnly(not archiveEditable)
        
        self.vcsVendorEdit.setText(archiveName)
        
    def handleDirectory(self):
        """
        Private slot to display a directory selection dialog.
        """
        directory = QFileDialog.getExistingDirectory(self.vcsDirectoryEdit.text(),
            self, None, self.trUtf8("Select VCS-Directory"), 1)
            
        if not directory.isNull():
            self.vcsDirectoryEdit.setText(QDir.convertSeparators(directory))
            
    def handleComboBox(self, vcsSystem):
        """
        Private slot to set the vcs root directory entry.
        
        Arguments
        
            vcsSystem -- name of the VCS system
        """
        hd = QDir.homeDirPath()
        hd.append('/').append(vcsSystem.lower()).append('root')
        self.vcsDirectoryEdit.setText(hd)
        
    def getData(self):
        """
        Public slot to retrieve the data entered into the dialog.
        
        
        Returns 
        
            a tuple of 6 strings and one boolean (vcs system, vcs directory,
            archive name, vendor label, log message, release label,
            command options).
        """
        return (str(self.vcsComboBox.currentText()),
            str(self.vcsDirectoryEdit.text()),
            str(self.vcsArchiveEdit.text()),
            str(self.vcsVendorEdit.text()),
            str(self.vcsLogEdit.text()),
            str(self.vcsReleaseEdit.text()),
            self.optionsCheckBox.isChecked()
        )
