Esempio n. 1
0
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 );
}
bool QHttp::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0: stateChanged((int)static_QUType_int.get(_o+1)); break;
    case 1: responseHeaderReceived((const QHttpResponseHeader&)*((const QHttpResponseHeader*)static_QUType_ptr.get(_o+1))); break;
    case 2: readyRead((const QHttpResponseHeader&)*((const QHttpResponseHeader*)static_QUType_ptr.get(_o+1))); break;
    case 3: dataSendProgress((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break;
    case 4: dataReadProgress((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break;
    case 5: requestStarted((int)static_QUType_int.get(_o+1)); break;
    case 6: requestFinished((int)static_QUType_int.get(_o+1),(bool)static_QUType_bool.get(_o+2)); break;
    case 7: done((bool)static_QUType_bool.get(_o+1)); break;
    default:
	return QNetworkProtocol::qt_emit(_id,_o);
    }
    return TRUE;
}
Esempio n. 3
0
QNetworkReply* ownCloudInfo::mkdirRequest( const QString& dir )
{
    qDebug() << "OCInfo Making dir " << dir;

    MirallConfigFile cfgFile( _configHandle );
    QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir );
    QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp;
    if (url.scheme() == "https")
        conMode = QHttp::ConnectionModeHttps;

    QHttp* qhttp = new QHttp(QString(url.encodedHost()), conMode, 0, this);

    connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
    connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
    connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader)));
    //connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*)));

    QHttpRequestHeader header("MKCOL", QString(url.encodedPath()), 1,1);   /* header */
    header.setValue("Host", QString(url.encodedHost()));
    header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() );
    header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
    header.setValue("Connection", "keep-alive");
    header.setContentType("application/x-www-form-urlencoded"); //important
    header.setContentLength(0);

    QString con = _configHandle;
    if( con.isEmpty() ) con = DEFAULT_CONNECTION;
    if( _credentials.contains(con)) {
        oCICredentials creds = _credentials.value(con);
        QString concatenated = creds.user + QLatin1Char(':') + creds.passwd;
        const QString b(QLatin1String("Basic "));
        QByteArray data = b.toLocal8Bit() + concatenated.toLocal8Bit().toBase64();
        header.setValue("Authorization", data);

        qhttp->setUser( creds.user, creds.passwd );
    }

    int david = qhttp->request(header,0,0);
    //////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
    /////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool)));
    //connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
    ///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &)));

    return NULL;
}
bool Harcelement::callAdd()
{
    QByteArray content(this->buildRequest().toUtf8());

    QHttpRequestHeader header("POST", this->url_api.path());
    header.setValue("Host", this->url_api.host());
    header.setContentType("application/x-www-form-urlencoded");
    header.setContentLength(content.length());

    QHttp *http = new QHttp(this->getHost());

    http->request(header, content);

    QObject::connect(http, SIGNAL(done(bool)), this->main_window, SLOT(state(bool)));
    QObject::connect(http, SIGNAL(requestFinished(int,bool)), this->main_window, SLOT(httpFinished(int)));
    QObject::connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this->main_window, SLOT(readHeader(QHttpResponseHeader)));

    return true;
}
bool Harcelement::callDelete()
{
    if (this->hash.isEmpty()) {
        return false;
    }

    QByteArray content("");

    QHttpRequestHeader header("DELETE", this->url_api.path() + QString("?%1").arg(QString(QUrl::toPercentEncoding(this->hash))).toUtf8());
    header.setValue("Host", this->url_api.host());
    header.setContentType("application/x-www-form-urlencoded");
    header.setContentLength(content.length());

    QHttp *http = new QHttp(this->getHost());

    http->request(header, content);

    QObject::connect(http, SIGNAL(done(bool)), this->main_window, SLOT(state(bool)));
    QObject::connect(http, SIGNAL(requestFinished(int,bool)), this->main_window, SLOT(httpFinished(int)));
    QObject::connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this->main_window, SLOT(readHeader(QHttpResponseHeader)));

    return true;
}
Esempio n. 6
0
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()));
}
Esempio n. 7
0
void ownCloudInfo::mkdirRequest( const QString& dir )
{
    qDebug() << "OCInfo Making dir " << dir;

    MirallConfigFile cfgFile( _configHandle );
    QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir );
    QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp;
    if (url.scheme() == "https")
        conMode = QHttp::ConnectionModeHttps;

    QHttp* qhttp = new QHttp(url.host(), conMode, 0, this);
    qhttp->setUser( cfgFile.ownCloudUser( _connection ), cfgFile.ownCloudPasswd( _connection ));

    connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
    connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
    connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader)));
    //connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*)));

    QHttpRequestHeader header("MKCOL", url.path(), 1,1);   /* header */
    header.setValue("Host", url.host() );
    header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() );
    header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
    header.setValue("Connection", "keep-alive");
    header.setContentType("application/x-www-form-urlencoded"); //important
    header.setContentLength(0);
    header.setValue("Authorization", cfgFile.basicAuthHeader());

    int david = qhttp->request(header,0,0);
    //////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
    /////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool)));
    //connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
    ///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &)));


}
Esempio n. 8
0
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;
}