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

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

"""
Module implementing the Start Program dialog.
"""

from qt import *

from StartForm import StartForm

class StartDialog(StartForm):
    """
    Class implementing the Start Program dialog.
    
    It implements a dialog that is used to start an
    application for debugging. It asks the user to enter
    the commandline parameters, the working directory and
    whether exception reporting should be disabled.
    """
    def __init__(self, caption, argvList, wdList, exceptions, parent=None,
        type=0):
        """
        Constructor
        
        Arguments
        
            caption -- the caption to be displayed (QString)
            
            argvList -- history list of commandline arguments (QStringList)
            
            wdList -- history list of working directories (QStringList)
            
            exceptions -- exception reporting flag (boolean)
            
            parent -- parent widget of this dialog (QWidget)
            
            type -- type of the start dialog
                (0 = start debug dialog
                 1 = start run dialog
                 2 = start coverage dialog
                 3 = start profile dialog)
        """
        StartForm.__init__(self, parent, None, 1)
        
        self.setCaption(caption)
        self.cmdlineCombo.clear()
        self.cmdlineCombo.insertStringList(argvList)
        if argvList.count() > 0:
            self.cmdlineCombo.setCurrentItem(0)
        self.workdirCombo.clear()
        self.workdirCombo.insertStringList(wdList)
        if wdList.count() > 0:
            self.workdirCombo.setCurrentItem(0)
        self.exceptionCheckBox.setChecked(exceptions)
        
        if type in [2, 3]:   # start coverage or profile dialog
            if type == 3:
                self.eraseCheckBox.setText(self.trUtf8('Erase timing data'))
                self.eraseCheckBox.setChecked(1)
            self.eraseCheckBox.setEnabled(1)
        
    def handleDir(self):
        """
        Private method used to open a directory selection dialog.
        """
        cwd = self.workdirCombo.currentText()
        d = QFileDialog.getExistingDirectory(cwd,
            self, None, self.trUtf8('Working directory'))
            
        if not d.isNull() and not d.isEmpty():
            self.workdirCombo.setCurrentText(QDir.convertSeparators(d))
        
    def getData(self):
        """
        Public method to retrieve the data entered into this dialog.
        
        Returns
        
            a tuple of argv, workdir, exceptions
        """
        return (self.cmdlineCombo.currentText(),
                self.workdirCombo.currentText(),
                self.exceptionCheckBox.isChecked())
        
    def getCoverageData(self):
        """
        Public method to retrieve the coverage related data entered into this dialog.
        
        Returns
        
            flag indicating erasure of coverage info (boolean)
        """
        return self.eraseCheckBox.isChecked()
