void DownloadUpdateDialog::startDownload(QString version)
{
#ifdef Q_OS_WIN
    tmpFile = new QFile(QDir::tempPath() + "/" + "ScreenCloud-" + version + "-" + QString(ARCH) + ".msi", this);
    if(tmpFile->exists())
    {
        INFO(tr("Removing existing installer ") + tmpFile->fileName());
        tmpFile->remove();
    }
    INFO(tr("Saving installer to ") + tmpFile->fileName());
    QNetworkRequest downloadRequest("https://screencloud.net/files/windows/ScreenCloud-" + version + "-" + QString(ARCH) + ".msi");
    QNetworkReply* r = netManager->get(downloadRequest);
    connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64)));
    INFO(tr("Downloading ") + downloadRequest.url().toString());
#endif
#ifdef Q_OS_MACX
    tmpFile = new QFile(QDir::tempPath() + "/" + "ScreenCloud-" + version + ".dmg", this);
    if(tmpFile->exists())
    {
        INFO(tr("Removing existing dmg ") + tmpFile->fileName());
        tmpFile->remove();
    }
    INFO(tr("Saving dmg to ") + tmpFile->fileName());
    QNetworkRequest downloadRequest("https://screencloud.net/files/mac/ScreenCloud-" + version + ".dmg");
    QNetworkReply* r = netManager->get(downloadRequest);
    connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64,qint64)));
    INFO(tr("Downloading ") + downloadRequest.url().toString());
#endif
}
Exemplo n.º 2
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->ftpServerLineEdit->setText("192.168.12.128");
    ui->userNameLineEdit->setText("dev");
    ui->passWordLineEdit->setText("123");
    ui->passWordLineEdit->setEchoMode(QLineEdit::Password);
    initiateUI();
//    ui->label->clear();
    
    ftp = new QFtp(this);
    connect(ui->fileListTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
            this, SLOT(processItem(QTreeWidgetItem*,int)));
    connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int)));
    connect(ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)), 
            this, SLOT(updateDataTransferProgress(qint64,qint64)));
//    ftp->connectToHost("192.168.12.128");
//    ftp->login("dev", "123");
//    ftp->cd("Documents");
//    ftp->get("test");
//    ftp->close();
}
Exemplo n.º 3
0
//![0]
void FtpWindow::connectOrDisconnect()
{
    if (ftp) {
        ftp->abort();
        ftp->deleteLater();
        ftp = 0;
//![0]
        fileList->setEnabled(false);
        cdToParentButton->setEnabled(false);
        downloadButton->setEnabled(false);
        connectButton->setEnabled(true);
        connectButton->setText(tr("Connect"));
#ifndef QT_NO_CURSOR
        setCursor(Qt::ArrowCursor);
#endif
        statusLabel->setText(tr("Please enter the name of an FTP server."));
        return;
    }

#ifndef QT_NO_CURSOR
    setCursor(Qt::WaitCursor);
#endif

//![1]
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandFinished(int,bool)),
            this, SLOT(ftpCommandFinished(int,bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)),
            this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
            this, SLOT(updateDataTransferProgress(qint64,qint64)));

    fileList->clear();
    currentPath.clear();
    isDirectory.clear();
//![1]

//![2]
    QUrl url(ftpServerLineEdit->text());
    if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
        ftp->connectToHost(ftpServerLineEdit->text(), 21);
        ftp->login();
    } else {
        ftp->connectToHost(url.host(), url.port(21));

        if (!url.userName().isEmpty())
            ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
        else
            ftp->login();
        if (!url.path().isEmpty())
            ftp->cd(url.path());
    }
//![2]

    fileList->setEnabled(true);
    connectButton->setEnabled(false);
    connectButton->setText(tr("Disconnect"));
    statusLabel->setText(tr("Connecting to FTP server %1...")
                         .arg(ftpServerLineEdit->text()));
}
Exemplo n.º 4
0
void Updater::downloadInstaller(QUrl url)
{   
    QString fName = url.path().split("/").last();
    QString path = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
    installer = new QFile(path + "/" + fName);
    
    if (!installer->open(QIODevice::WriteOnly)){
        QMessageBox::information(this, tr("HTTP"), tr("Unable to save the file %1: %2.")
        .arg(installer->fileName()).arg(installer->errorString()));
        delete installer;
        installer = 0;
        return;
    }
    
    mProgDialog->setLabelText(tr("Downloading %1").arg(fName));
    connect(mProgDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
    mProgDialog->show();
    
    instReply = qnam.get(QNetworkRequest(url));
    connect(instReply, SIGNAL(downloadProgress(qint64,qint64)),
            this, SLOT(updateDataTransferProgress(qint64,qint64)));
    connect(instReply, SIGNAL(finished()), this, SLOT(httpFinishedInstaller()));
    connect(instReply, SIGNAL(readyRead()), this, SLOT(httpReadyReadInstaller()));

}
Exemplo n.º 5
0
void MainWindow::connectFtp(QString ip, QString id, QString pwd)
{
    //write info
    login->writeInfo();

    connect(ftp, SIGNAL(listInfo(QUrlInfo)),
            this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(commandFinished(int,bool)),
            this, SLOT(ftpCommandFinished(int,bool)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
            this, SLOT(updateDataTransferProgress(qint64,qint64)));

    ftp->connectToHost(ip, 21); //FIXME : port editable
    ftp->login(id, pwd);
}
Exemplo n.º 6
0
// 连接按钮
void MainWindow::on_connectButton_clicked()
{
    ui->fileList->clear();
    currentPath.clear();
    isDirectory.clear();
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCommandStarted(int)));
    connect(ftp, SIGNAL(commandFinished(int, bool)),
            this, SLOT(ftpCommandFinished(int, bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
            this, SLOT(updateDataTransferProgress(qint64, qint64)));
    QString ftpServer = ui->ftpServerLineEdit->text();
    QString userName = ui->userNameLineEdit->text();
    QString passWord = ui->passWordLineEdit->text();
    ftp->connectToHost(ftpServer, 21);
    ftp->login(userName, passWord);
}
Exemplo n.º 7
0
void ImageshackUploader::transfert()
{
    // Read the file
    QFile file(m_fileToUpload);
    file.open(QIODevice::ReadOnly);
    QByteArray fileData = file.readAll();
    file.close();

    QString boundary = "---------------------------161761219329510";

    QString suffix( QFileInfo(m_fileToUpload).suffix().toLower() );
    if (suffix == "jpg")
        suffix = "jpeg";

    QByteArray requestBody;
    requestBody += QString("--" + boundary + "\r\n").toAscii();
    requestBody += QString("Content-Disposition: form-data; name=\"public\"\r\n\r\nyes\r\n").toAscii();
    requestBody += QString("--" + boundary + "\r\n").toAscii();
    requestBody += QString("Content-Disposition: form-data; name=\"key\"\r\n\r\n%1\r\n").arg(apiKey).toAscii();
    requestBody += QString("--" + boundary + "\r\n").toAscii();
    requestBody += QString("Content-Disposition: form-data; name=\"fileupload\"; filename=\"%1\"\r\n").arg( QFileInfo(m_fileToUpload).fileName() ).toAscii();
    requestBody += QString("Content-Type: image/%1\r\n\r\n").arg(suffix).toAscii();
    requestBody += fileData;
    requestBody += "\r\n";
    requestBody += QString("--" + boundary + "\r\n").toAscii();

    QNetworkRequest request = QNetworkRequest( QUrl(UploadUrl) );
    request.setUrl( QUrl(UploadUrl) );
    request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary );
    request.setHeader( QNetworkRequest::ContentLengthHeader, QString::number( requestBody.length() ).toAscii() );
    request.setRawHeader("Connection", "Keep-Alive");
    request.setRawHeader("User-Agent", "Fine User-Agent");

    // Start network access
    QNetworkReply * reply = m_manager->post(
        request,
        requestBody);

    connect( reply, SIGNAL( uploadProgress(qint64, qint64) ),
             this, SLOT( updateDataTransferProgress(qint64, qint64) ) );
}
Exemplo n.º 8
0
int Conexionftp::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: conexionfinished(); break;
        case 1: putcorrected(); break;
        case 2: puterror((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 3: conexionestablished(); break;
        case 4: commandfinish((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 5: updateDataTransferProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 6: stateChange((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 7: enableConnectButton(); break;
        default: ;
        }
        _id -= 8;
    }
    return _id;
}
Exemplo n.º 9
0
void FtpWindow::connectToFtp()
{
//![1]
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandFinished(int,bool)),
            this, SLOT(ftpCommandFinished(int,bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)),
            this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
            this, SLOT(updateDataTransferProgress(qint64,qint64)));

    fileList->clear();
    currentPath.clear();
    isDirectory.clear();
//![1]

//![2]
    QUrl url(ftpServerLineEdit->text());
    if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
        ftp->connectToHost(ftpServerLineEdit->text(), 21);
        ftp->login();
    } else {
        ftp->connectToHost(url.host(), url.port(21));

        if (!url.userName().isEmpty())
            ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
        else
            ftp->login();
        if (!url.path().isEmpty())
            ftp->cd(url.path());
    }
//![2]

    fileList->setEnabled(true);
    connectButton->setEnabled(false);
    connectButton->setText(tr("Disconnect"));
    statusLabel->setText(tr("Connecting to FTP server %1...")
                         .arg(ftpServerLineEdit->text()));
}
Exemplo n.º 10
0
int FtpWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: connectOrDisconnect(); break;
        case 1: downloadFile(); break;
        case 2: cancelDownload(); break;
        case 3: ftpCommandFinished((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 4: addToList((*reinterpret_cast< const QUrlInfo(*)>(_a[1]))); break;
        case 5: processItem((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 6: cdToParent(); break;
        case 7: updateDataTransferProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 8: enableDownloadButton(); break;
        default: ;
        }
        _id -= 9;
    }
    return _id;
}