def performAction(self):
        d  = self.displayName
        h  = self.host
        p  = self.port
        pa = self.path
        u  = self.username
        ps = self.password
        s  = self.useSSL
        v  = self.view
        m  = self.morsecode
        parent = self.GetParent()

        if self.sharingInstance == None:
            if self.morsecode:
                self.sharingInstance = MorsecodeTester(h, p, pa, u, ps, s, v)
            else:
                self.sharingInstance = WebDAVTester(h, p, pa, u, ps, s, v)

        reconnect = lambda: SharingTestDialog(parent, d, h, p, pa, u, ps, s, v, m)

        self.sharingInstance.testAccountSettings(self.OnActionComplete,
                                                reconnect)
    def performAction(self):
        d = self.displayName
        h = self.host
        p = self.port
        pa = self.path
        u = self.username
        ps = self.password
        s = self.useSSL
        v = self.view
        m = self.morsecode
        parent = self.GetParent()

        if self.sharingInstance == None:
            if self.morsecode:
                self.sharingInstance = MorsecodeTester(h, p, pa, u, ps, s, v)
            else:
                self.sharingInstance = WebDAVTester(h, p, pa, u, ps, s, v)

        reconnect = lambda: SharingTestDialog(parent, d, h, p, pa, u, ps, s, v,
                                              m)

        self.sharingInstance.testAccountSettings(self.OnActionComplete,
                                                 reconnect)
class SharingTestDialog(ProgressDialog):
    TIMEOUT = 60

    def __init__(self, parent, displayName=None, host=None, port=None,
                 path=None, username=None, password=None,
                 useSSL=False, view=None, morsecode=False):

        self.displayName = displayName
        self.host = host
        self.port = port
        self.path = path
        self.username = username
        self.password = password
        self.useSSL = useSSL
        self.view = view
        self.morsecode = morsecode

        self.sharingInstance = None

        super(SharingTestDialog, self).__init__(parent)
        self.initDialog()

    def performAction(self):
        d  = self.displayName
        h  = self.host
        p  = self.port
        pa = self.path
        u  = self.username
        ps = self.password
        s  = self.useSSL
        v  = self.view
        m  = self.morsecode
        parent = self.GetParent()

        if self.sharingInstance == None:
            if self.morsecode:
                self.sharingInstance = MorsecodeTester(h, p, pa, u, ps, s, v)
            else:
                self.sharingInstance = WebDAVTester(h, p, pa, u, ps, s, v)

        reconnect = lambda: SharingTestDialog(parent, d, h, p, pa, u, ps, s, v, m)

        self.sharingInstance.testAccountSettings(self.OnActionComplete,
                                                reconnect)

    def cancelAction(self):
        self.sharingInstance.cancelLastRequest()

    def getTimeoutText(self):
        return "timeout error"

    def getTitleText(self):
        return _(u"Testing '%(accountName)s'") % \
                  {'accountName': self.displayName}

    def getStartText(self):
        return _(u"Connecting to server '%(hostName)s'") % \
                 {'hostName': self.host}

    def getSuccessText(self, statusValue):
        davCode = statusValue[0]

        msg = constants.MAIL_PROTOCOL_SUCCESS % {'hostName': self.host}
        msg += u"\n\n\t\t"

        if davCode == WebDAV.READ_ONLY:
            msg += READ_ONLY

        else:
            msg += READ_WRITE

        return msg

    def getErrorText(self, statusValue):

        try:
            davCode, errText = statusValue

            if davCode == WebDAV.CANT_CONNECT:
                txt = errText

            elif davCode == WebDAV.NO_ACCESS:
                txt = NO_ACCESS

            else:
                txt = UNKNOWN

        except ValueError:
            # If the dialog raised a timeout error then
            # the statusValue will be a unicode string and
            # not a tuple containing the dav code as well.
            txt = statusValue

        return constants.MAIL_PROTOCOL_ERROR % \
                        {'hostName': self.host, 'errText': txt}
class SharingTestDialog(ProgressDialog):
    TIMEOUT = 60

    def __init__(self,
                 parent,
                 displayName=None,
                 host=None,
                 port=None,
                 path=None,
                 username=None,
                 password=None,
                 useSSL=False,
                 view=None,
                 morsecode=False):

        self.displayName = displayName
        self.host = host
        self.port = port
        self.path = path
        self.username = username
        self.password = password
        self.useSSL = useSSL
        self.view = view
        self.morsecode = morsecode

        self.sharingInstance = None

        super(SharingTestDialog, self).__init__(parent)
        self.initDialog()

    def performAction(self):
        d = self.displayName
        h = self.host
        p = self.port
        pa = self.path
        u = self.username
        ps = self.password
        s = self.useSSL
        v = self.view
        m = self.morsecode
        parent = self.GetParent()

        if self.sharingInstance == None:
            if self.morsecode:
                self.sharingInstance = MorsecodeTester(h, p, pa, u, ps, s, v)
            else:
                self.sharingInstance = WebDAVTester(h, p, pa, u, ps, s, v)

        reconnect = lambda: SharingTestDialog(parent, d, h, p, pa, u, ps, s, v,
                                              m)

        self.sharingInstance.testAccountSettings(self.OnActionComplete,
                                                 reconnect)

    def cancelAction(self):
        self.sharingInstance.cancelLastRequest()

    def getTimeoutText(self):
        return "timeout error"

    def getTitleText(self):
        return _(u"Testing '%(accountName)s'") % \
                  {'accountName': self.displayName}

    def getStartText(self):
        return _(u"Connecting to server '%(hostName)s'") % \
                 {'hostName': self.host}

    def getSuccessText(self, statusValue):
        davCode = statusValue[0]

        msg = constants.MAIL_PROTOCOL_SUCCESS % {'hostName': self.host}
        msg += u"\n\n\t\t"

        if davCode == WebDAV.READ_ONLY:
            msg += READ_ONLY

        else:
            msg += READ_WRITE

        return msg

    def getErrorText(self, statusValue):

        try:
            davCode, errText = statusValue

            if davCode == WebDAV.CANT_CONNECT:
                txt = errText

            elif davCode == WebDAV.NO_ACCESS:
                txt = NO_ACCESS

            else:
                txt = UNKNOWN

        except ValueError:
            # If the dialog raised a timeout error then
            # the statusValue will be a unicode string and
            # not a tuple containing the dav code as well.
            txt = statusValue

        return constants.MAIL_PROTOCOL_ERROR % \
                        {'hostName': self.host, 'errText': txt}