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

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

"""
Compatibility module to use the KDE Progress Dialog instead of the Qt Progress Dialog.
"""

import os

import Preferences

try:
    raise ImportError
except (ImportError, RuntimeError):
    os.environ["e4nokde"] = "1"

from PyQt4.QtGui import QProgressDialog
class __qtKQProgressDialog(QProgressDialog):
    """
    Compatibility class to use the Qt Progress Dialog.
    """
    pass

################################################################################

from PyQt4.QtCore import Qt

def KQProgressDialog(labelText, cancelButtonText, minimum, maximum, 
                     parent = None, f = Qt.WindowFlags(Qt.Widget)):
    """
    Public function to instantiate a progress dialog object.
    
    @param labelText text to show in the progress dialog (QString)
    @param cancelButtonText text to show for the cancel button or
        None to disallow cancellation and to hide the cancel button (QString)
    @param minimum minimum value for the progress indicator (integer)
    @param maximum maximum value for the progress indicator (integer)
    @param parent reference to the parent widget (QWidget)
    @param f window flags for the dialog (Qt.WindowFlags)
    @return reference to the progress dialog object
    """
    if Preferences.getUI("UseKDEDialogs") and not os.getenv("e4nokde"):
        return __kdeKQProgressDialog(labelText, cancelButtonText, 
                                     minimum, maximum, parent, f)
    else:
        return __qtKQProgressDialog(labelText, cancelButtonText, 
                                    minimum, maximum, parent, f)
