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

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


"""
Module implementing a dialog for loading a script.
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from KdeQt import KQFileDialog

from E4Gui.E4Completers import E4FileCompleter

from Ui_LoadScriptDialog import Ui_LoadScriptDialog

import Utilities

class LoadScriptDialog(QDialog, Ui_LoadScriptDialog):
    """
    Class implementing a dialog for loading a script.
    """
    def __init__(self, parent = None):
        """
        Constructor
        
        @param parent parent of this dialog (QWidget)
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        
        self.scriptFileCompleter = E4FileCompleter(self.scriptFileEdit)

    @pyqtSignature("")
    def on_fileSelectButton_clicked(self):
        """
        Private slot to handle the script file selection.
        """
        file = KQFileDialog.getOpenFileName(\
            self,
            self.trUtf8("Select script file"),
            self.scriptFileEdit.text(),
            self.trUtf8("Script Files (*.py *.epy)"))
        
        if not file.isNull():
            self.scriptFileEdit.setText(Utilities.toNativeSeparators(file))
        
    def getData(self):
        """
        Public method to retrieve the data entered into the dialog.
        
        @return tuple with the collected data (script name, script file,
            execute flag, delete flag) (string, string, boolean, boolean)
        """
        return (unicode(self.scriptNameEdit.text()), 
            unicode(self.scriptFileEdit.text()),
            self.executeCheckBox.isChecked(),
            self.deleteCheckBox.isChecked())
