Ejemplo n.º 1
0
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)

        self.urlLineEdit = QtGui.QLineEdit(
            "http://www.ietf.org/iesg/1rfc_index.txt")

        self.urlLabel = QtGui.QLabel(self.tr("&URL:"))
        self.urlLabel.setBuddy(self.urlLineEdit)
        self.statusLabel = QtGui.QLabel(
            self.tr("Please enter the URL of a file "
                    "you want to download."))

        self.quitButton = QtGui.QPushButton(self.tr("Quit"))
        self.downloadButton = QtGui.QPushButton(self.tr("Download"))
        self.downloadButton.setDefault(True)

        self.progressDialog = QtGui.QProgressDialog(self)

        self.http = QtNetwork.QHttp(self)
        self.outFile = None
        self.httpGetId = 0
        self.httpRequestAborted = False

        self.connect(self.urlLineEdit, QtCore.SIGNAL("textChanged(QString &)"),
                     self.enableDownloadButton)
        self.connect(self.http, QtCore.SIGNAL("requestFinished(int, bool)"),
                     self.httpRequestFinished)
        self.connect(self.http, QtCore.SIGNAL("dataReadProgress(int, int)"),
                     self.updateDataReadProgress)
        self.connect(
            self.http,
            QtCore.SIGNAL("responseHeaderReceived(QHttpResponseHeader &)"),
            self.readResponseHeader)
        self.connect(self.progressDialog, QtCore.SIGNAL("canceled()"),
                     self.cancelDownload)
        self.connect(self.downloadButton, QtCore.SIGNAL("clicked()"),
                     self.downloadFile)
        self.connect(self.quitButton, QtCore.SIGNAL("clicked()"), self,
                     QtCore.SLOT("close()"))

        topLayout = QtGui.QHBoxLayout()
        topLayout.addWidget(self.urlLabel)
        topLayout.addWidget(self.urlLineEdit)

        buttonLayout = QtGui.QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(self.downloadButton)
        buttonLayout.addWidget(self.quitButton)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addLayout(topLayout)
        mainLayout.addWidget(self.statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle(self.tr("HTTP"))
        self.urlLineEdit.setFocus()
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        super(HttpWindow, self).__init__(parent)

        self.outFile = None
        self.httpGetId = 0
        self.httpRequestAborted = False

        self.urlLineEdit = QtGui.QLineEdit('https://')

        urlLabel = QtGui.QLabel("&URL:")
        urlLabel.setBuddy(self.urlLineEdit)
        self.statusLabel = QtGui.QLabel("Please enter the URL of a file you "
                                        "want to download.")

        self.downloadButton = QtGui.QPushButton("Download")
        self.downloadButton.setDefault(True)
        self.quitButton = QtGui.QPushButton("Quit")
        self.quitButton.setAutoDefault(False)

        buttonBox = QtGui.QDialogButtonBox()
        buttonBox.addButton(self.downloadButton,
                            QtGui.QDialogButtonBox.ActionRole)
        buttonBox.addButton(self.quitButton, QtGui.QDialogButtonBox.RejectRole)

        self.progressDialog = QtGui.QProgressDialog(self)

        self.http = QtNetwork.QHttp(self)

        self.urlLineEdit.textChanged.connect(self.enableDownloadButton)
        self.http.requestFinished.connect(self.httpRequestFinished)
        self.http.dataReadProgress.connect(self.updateDataReadProgress)
        self.http.responseHeaderReceived.connect(self.readResponseHeader)
        self.http.authenticationRequired.connect(
            self.slotAuthenticationRequired)
        self.http.sslErrors.connect(self.sslErrors)
        self.progressDialog.canceled.connect(self.cancelDownload)
        self.downloadButton.clicked.connect(self.downloadFile)
        self.quitButton.clicked.connect(self.close)

        topLayout = QtGui.QHBoxLayout()
        topLayout.addWidget(urlLabel)
        topLayout.addWidget(self.urlLineEdit)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addLayout(topLayout)
        mainLayout.addWidget(self.statusLabel)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

        self.setWindowTitle("HTTP")
        self.urlLineEdit.setFocus()