DownloadHandler::DownloadHandler( QWidget *parent ) : QWidget( parent ) , mDownloading( false ) , mHttpGetId( 0 ) , mpNetworkAccessManager( new QNetworkAccessManager( this ) ) , mpURL( new ScrollLine( this ) ) , mpFileName( new ScrollLine( this ) ) , mpEnqueue( new QCheckBox( tr("Enqueue In Partyman"), this ) ) , mpProgressBar( new QProgressBar( this ) ) , mpTimer( new QTimer( this ) ) , mpMagicQueue( new MagicQueue( this ) ) , mpTheMagic( 0 ) , mCookieJar() { QBoxLayout *layout = new QVBoxLayout( this ); QGroupBox *groupBox = new QGroupBox( tr("Now Processing:"), this ); QBoxLayout *groupLayout = new QVBoxLayout(); if( Settings::value( Settings::CommonUseSatellite ) ) { mpMagicQueue->setSelectionMode( QAbstractItemView::MultiSelection ); mpEnqueue->setEnabled( false ); } else { mpMagicQueue->setSelectionMode( QAbstractItemView::NoSelection ); mpEnqueue->setHidden( true ); } layout->setContentsMargins( 0, 0, 0, 0 ); layout->setSpacing( 1 ); groupLayout->setContentsMargins( 5, 5, 5, 5 ); groupLayout->setSpacing( 1 ); groupLayout->addWidget( mpURL ); groupLayout->addWidget( mpFileName ); groupLayout->addWidget( mpEnqueue ); groupLayout->addWidget( mpProgressBar ); groupBox->setLayout( groupLayout ); layout->addWidget( groupBox ); layout->addWidget( mpMagicQueue ); setLayout( layout ); connect( mpNetworkAccessManager, SIGNAL(requestFinished(int,bool)), this, SLOT(httpRequestFinished(int,bool)) ); connect( mpNetworkAccessManager, SIGNAL(dataReadProgress(int,int)), this, SLOT(updateDataReadProgress(int,int)) ); connect( mpNetworkAccessManager, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(readResponseHeader(QHttpResponseHeader)) ); connect( mpTimer, SIGNAL(timeout()), this, SLOT(startDownload()) ); mpTimer->start( 1000 ); }
void HttpClient::onReadyRead() { switch( httpState ) { case Sending: #ifdef HTTP_CLIENT_DEBUG qDebug() << this << "onReadyRead(), Sending"; #endif httpState = ReadingResponseHeader; case ReadingResponseHeader: #ifdef HTTP_CLIENT_DEBUG qDebug() << this << "onReadyRead(), ReadingResponseHeader"; #endif // если не дочитан if( !readResponseHeader() ) break; if( responseHeader.statusCode() == 100 ) { // Continue // это нам говорят продолжай слать пост, игнорируем, // опять будем читать хидер break; } else if ( responseHeader.statusCode() == 302 ) { // Moved temporary if ( responseHeader.hasKey( "Location" ) ) { QString location = responseHeader.value( "Location" ); if ( location.at( 0 ) == '/' ) url.setPath( location ); else url.setUrl( location ); method = GET; } break; } httpState = ReadingResponseBody; case ReadingResponseBody: #ifdef HTTP_CLIENT_DEBUG qDebug() << this << "onReadyRead(), ReadingResponseBody"; #endif // если не дочитан if( !readResponseBody() ) break; emitDone(); break; default: qCritical() << this << "onReadyRead(): unknown httpState"; qFatal( "programming error" ); } }
QT_BEGIN_NAMESPACE #ifndef QT_NO_HTTP #define QCH_FILENAME 92943 #define QCH_NAMESPACE 92944 #define QCH_CHECKSUM 92945 InstallDialog::InstallDialog(QHelpEngineCore *helpEngine, QWidget *parent, const QString &host, int port) : QDialog(parent), m_helpEngine(helpEngine), m_host(host), m_port(port) { TRACE_OBJ m_ui.setupUi(this); m_ui.installButton->setEnabled(false); m_ui.cancelButton->setEnabled(false); m_ui.pathLineEdit->setText(QFileInfo(m_helpEngine->collectionFile()).absolutePath()); m_ui.progressBar->hide(); m_windowTitle = tr("Install Documentation"); m_http = new QHttp(this); connect(m_http, SIGNAL(requestFinished(int,bool)), this, SLOT(httpRequestFinished(int,bool))); connect(m_http, SIGNAL(dataReadProgress(int,int)), this, SLOT(updateDataReadProgress(int,int))); connect(m_http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(readResponseHeader(QHttpResponseHeader))); connect(m_ui.installButton, SIGNAL(clicked()), this, SLOT(install())); connect(m_ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelDownload())); connect(m_ui.browseButton, SIGNAL(clicked()), this, SLOT(browseDirectories())); connect(m_ui.listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(updateInstallButton())); QTimer::singleShot(0, this, SLOT(init())); }
void HttpFetcher::run() { QString fetchFile; // if no file set, assume fetching package list fetchFile = file.isEmpty() ? AbstractPackageController::PACKAGE_SUMMARY_FILE : file; if(url.path().endsWith("/")) url.setPath(url.path() + fetchFile); else url.setPath(url.path() + "/" + fetchFile); if ( http == 0 ) http = new QHttp(); connect( this, SIGNAL(httpAbort()), http, SLOT(abort()) ); QString query; HttpFileReceiver *hr; Md5File *md5File = 0; QDir packagePathDir( Qtopia::packagePath() ); if ( file.isEmpty() ) // getting package list { if ( packageData == 0 ) packageData = new QBuffer(); hr = new HttpInfoReceiver; connect( packageData, SIGNAL(bytesWritten(qint64)), hr, SLOT(packageDataWritten(qint64))); } else // getting a file { md5File = new Md5File( InstallControl::downloadedPkgPath() ); if ( md5File->exists() ) md5File->remove(); packageData = md5File; hr = new HttpFileReceiver; hr->fileSize = fileSize; } hr->fetcher = this; connect( http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), hr, SLOT(readResponseHeader(QHttpResponseHeader))); connect( http, SIGNAL(dataReadProgress(int,int)), hr, SLOT(updateDataReadProgress(int,int))); connect( http, SIGNAL(requestFinished(int,bool)), hr, SLOT(httpRequestFinished(int,bool))); http->setHost( url.host() , url.port(80)); packageData->open( QIODevice::WriteOnly ); httpGetId = http->get( url.path() + query, packageData ); // show some progress now that we've set everything up curProgValue = initProgress; emit progressValue( initProgress ); // run threads event loop exec(); packageData->close(); if( md5File ) md5Sum = md5File->md5Sum(); delete packageData; packageData = 0; delete http; http = 0; delete hr; }