Example #1
0
/**
  Retrieves the firmware from the device
  */
void deviceWidget::downloadFirmware()
{
    if (!m_dfu->devices[deviceID].Readable) {
        myDevice->statusLabel->setText(QString("Device not readable!"));
        return;
    }

    myDevice->retrieveButton->setEnabled(false);
    filename = setSaveFileName();

    if (filename.isEmpty()) {
        status("Empty filename", STATUSICON_FAIL);
        return;
    }

    status("Downloading firmware from device", STATUSICON_RUNNING);
    connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
    connect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
    downloadedFirmware.clear(); // Empty the byte array
    bool ret = m_dfu->DownloadFirmware(&downloadedFirmware,deviceID);
    if(!ret) {
        status("Could not start download!", STATUSICON_FAIL);
        return;
    }
    status("Download started, please wait", STATUSICON_RUNNING);
}
void plugDownloader::startNextDownload()
{
    if (m_download_queue.isEmpty()) {
        emit downloadFinished(itemList);
        this->deleteLater();
        return;
    }
    currentItem =  m_download_queue.dequeue();

    currentOutput.setFileName(outPath+currentItem.filename);
    if (!currentOutput.open(QIODevice::WriteOnly)) {
        qDebug() << "Unable to open file";
        startNextDownload();
        return;                 // skip this download
    }
    QNetworkRequest request(currentItem.url);
    currentDownload = manager.get(request);
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
            SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()),
            SLOT(downloadFinished()));
    connect(currentDownload, SIGNAL(readyRead()),
            SLOT(downloadReadyRead()));

    // prepare the output
    downloadTime.start();
}
Example #3
0
void video::handleDownloads()
{
    switch (this->_step)
    {
        case 1:
        {
            handler->downloads.at(0)->tempFile->close();
            handler->downloads.at(0)->tempFile->open();
            QByteArray data = handler->downloads.at(0)->tempFile->readAll();
            handler->downloads.at(0)->tempFile->close();
            QString html = QString::fromUtf8(data, data.size());
            handler->clearDownloads();
            parseVideo(html);
            break;
        }

        case 3:
        {
            if (handler->downloads.size() == 1)
            {
                this->downloadFile = handler->downloads.at(0)->tempFile;
                emit downloadFinished();
            }
            else
            {
                this->_step = 4;
                converter_ffmpeg* ffmpeg = new converter_ffmpeg;

                QList<QFile*> files;
                for (int i=0; i < handler->downloads.size(); i++)
                {
                    files << handler->downloads.at(i)->tempFile;
                }
                this->_progressBar->setMinimum(0);
                this->_progressBar->setMaximum(0);
                for (int i = 0; i <= 3; i++)
                {
                   this->_treeItem->setToolTip(i, "<strong>" + tr("Converting ...") + "</strong>");
                }
                this->downloadFile = new QTemporaryFile(QDir::tempPath() + "/clipgrab-concat--XXXXXX");
                this->downloadFile->open(QIODevice::ReadOnly);
                this->downloadFile->close();
                qDebug() << this->downloadFile;
                connect(ffmpeg, SIGNAL(conversionFinished()), this, SLOT(handleDownloads()));

                ffmpeg->concatenate(files, this->downloadFile);
            }
            break;
        }

        case 4:
        {
            emit downloadFinished();
			break;
        }
    }
}
Example #4
0
/**
  Callback for the firmware download result
  */
void deviceWidget::downloadFinished()
{
    disconnect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
    disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
    status("Download successful", STATUSICON_OK);
    // Now save the result (use the utility function from OP_DFU)
    m_dfu->SaveByteArrayToFile(filename, downloadedFirmware);
    myDevice->retrieveButton->setEnabled(true);
}
Example #5
0
void WebView::unsupportedContent(QNetworkReply* pReply)
{
   bool closeAfterDownload = false;
   if (this->page()->history()->count() == 0)
   {
      /* This is for the case where a new browser window was launched just
         to show a PDF or save a file. Otherwise we would have an empty
         browser window with no history hanging around. */
      window()->hide();
      closeAfterDownload = true;
   }

   DownloadHelper* pDownloadHelper = NULL;

   QString contentType =
         pReply->header(QNetworkRequest::ContentTypeHeader).toString();
   if (contentType.contains(QRegExp(QString::fromAscii("^\\s*application/pdf($|;)"),
                                    Qt::CaseInsensitive)))
   {
      core::FilePath dir(options().scratchTempDir());

      QTemporaryFile pdfFile(QString::fromUtf8(
            dir.childPath("rstudio-XXXXXX.pdf").absolutePath().c_str()));
      pdfFile.open();
      pdfFile.close();
      // DownloadHelper frees itself when downloading is done
      pDownloadHelper = new DownloadHelper(pReply, pdfFile.fileName());
      connect(pDownloadHelper, SIGNAL(downloadFinished(QString)),
              this, SLOT(openFile(QString)));
   }
   else
   {
      QString fileName = promptForFilename(pReply->request(), pReply);
      if (fileName.isEmpty())
      {
         pReply->abort();
         if (closeAfterDownload)
            window()->close();
      }
      else
      {
         // DownloadHelper frees itself when downloading is done
         pDownloadHelper = new DownloadHelper(pReply, fileName);
      }
   }

   if (closeAfterDownload && pDownloadHelper)
   {
      connect(pDownloadHelper, SIGNAL(downloadFinished(QString)),
              window(), SLOT(close()));
   }
}
Example #6
0
void DownloadItem::finished()
{
    if (reply->attribute(QNetworkRequest::RedirectionTargetAttribute).isValid()) {
        QUrl url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        url = reply->url().resolved(url);
        qDebug() << reply->url() << "redirected to " << url;
        if (redirects.contains(url)) {
            qDebug() << "redirect loop detected";
        } else if (redirects.count() > 10) {
            qDebug() << "too many redirects";
        } else {
            //follow redirect
            if (outputFile && outputFile->isOpen()) {
                if (!outputFile->seek(0) || !outputFile->resize(0)) {
                    outputFile->close();
                    outputFile->remove();
                }
            }
            reply->deleteLater();
            reply = nam.get(QNetworkRequest(url));
            reply->setParent(this);
            connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
            connect(reply, SIGNAL(finished()), this, SLOT(finished()));
            redirects.append(url);
            return;
        }
    }
    if (outputFile && outputFile->isOpen()) {
        outputFile->write(reply->readAll());
        outputFile->close();
    }
    emit downloadFinished(this);
}
Example #7
0
void Download::setBytesDownloaded(qint64 bytes)
{    
    m_bytesDownloaded = bytes;

    if(isDownloadFinished())
        emit downloadFinished();
}
Example #8
0
/*!
 * \qmlsignal MangoDownloader::startNextDownload()
 * Used if you want to download multiple files
 */
void MangoDownloader::startNextDownload()
{
    if (downloadQueue.isEmpty()) {
        qDebug() << downloadedCount << " " << totalCount << "files downloaded successfully\n";
        emit started(false);
        emit finished();
        return;
    }

    QUrl url = downloadQueue.dequeue();

    QString filename = saveFileName(mPath);
    output.setFileName(mPath + filename);
    if (!output.open(QIODevice::WriteOnly)) {
        qDebug() <<  "Problem opening save file for download";
        startNextDownload();
        return;
    }

    QNetworkRequest request(url);
    currentDownload = manager.get(request);
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
            SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()),
            SLOT(downloadFinished()));
    connect(currentDownload, SIGNAL(readyRead()),
            SLOT(downloadReadyRead()));

    // prepare the output
    qDebug () << "Downloading " <<  url.toEncoded().constData() << "........";
    downloadTime.start();
}
void TabDeckStorage::actDownload()
{
    QString filePath;
    QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
    if (!curLeft.isValid())
        filePath = localDirModel->rootPath();
    else {
        while (!localDirModel->isDir(curLeft))
            curLeft = curLeft.parent();
        filePath = localDirModel->filePath(curLeft);
    }

    RemoteDeckList_TreeModel::FileNode *curRight = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
    if (!curRight)
        return;
    filePath += QString("/deck_%1.cod").arg(curRight->getId());
    
    Command_DeckDownload cmd;
    cmd.set_deck_id(curRight->getId());
    
    PendingCommand *pend = client->prepareSessionCommand(cmd);
    pend->setExtraData(filePath);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(downloadFinished(Response, CommandContainer, QVariant)));
    client->sendCommand(pend);
}
Example #10
0
void AppDownloader::packageFetched()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    reply->deleteLater();

    QString file = reply->property("file").toString();

    QFile f(m_storagePath + file);
    if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
        qWarning() << "Error opening file for writing";
        return;
    }
    f.write(reply->readAll());
    f.flush();
    f.close();

    QString appid = file.split("/").first();

    if (!ZipHelper::unpackArchive(m_storagePath+file, m_storagePath + appid)) {
        qWarning() << "Error unpacking App zip file";
        return;
    }

    emit downloadFinished(appid);
}
void AddNewTorrentDialog::show(QString source, QWidget *parent)
{
    if (source.startsWith("bc://bt/", Qt::CaseInsensitive)) {
        qDebug("Converting bc link to magnet link");
        source = Utils::Misc::bcLinkToMagnet(source);
    }

    AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent);

    if (Utils::Misc::isUrl(source)) {
        // Launch downloader
        Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
        connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString)));
        connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString)));
        connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString)));
    }
    else {
        bool ok = false;
        if (source.startsWith("magnet:", Qt::CaseInsensitive))
            ok = dlg->loadMagnet(source);
        else
            ok = dlg->loadTorrent(source);

        if (ok)
            dlg->open();
        else
            delete dlg;
    }
}
Example #12
0
frmProgress::frmProgress(QWidget * parent, Qt::WFlags f) : QWidget(parent, f)
{
	qRegisterMetaType<QNapiSubtitleInfoList>("QNapiSubtitleInfoList");

	ui.setupUi(this);

#ifdef Q_WS_MAC
	setAttribute(Qt::WA_MacBrushedMetal, GlobalConfig().useBrushedMetal());
#endif
	setAttribute(Qt::WA_DeleteOnClose, false);
	setAttribute(Qt::WA_QuitOnClose, false);

	setBatchMode(false);

	connect(&getThread, SIGNAL(fileNameChange(const QString &)),
			ui.lbFileName, SLOT(setText(const QString &)));
	connect(&getThread, SIGNAL(actionChange(const QString &)),
			ui.lbAction, SLOT(setText(const QString &)));
	connect(&getThread, SIGNAL(progressChange(int, int, float)),
			this, SLOT(updateProgress(int, int, float)));
	connect(&getThread, SIGNAL(selectSubtitles(QString, QNapiSubtitleInfoList)),
			this, SLOT(selectSubtitles(QString, QNapiSubtitleInfoList)));
	connect(this, SIGNAL(subtitlesSelected(int)),
			&getThread, SLOT(subtitlesSelected(int)));
	connect(&getThread, SIGNAL(finished()),
			this, SLOT(downloadFinished()));
}
Example #13
0
void SerialServer::processData(QByteArray& data)
{
    QDataStream dataStream(&data, QIODevice::ReadOnly);
    
    QString fileName;
    QByteArray fileData;
    
    dataStream >> fileName;
    dataStream >> fileData;
    
    if(fileName.isEmpty())
        return;
    
    QFileInfo fileInfo(fileName);
    
    QString projectPath = createProject(fileInfo.baseName());
    writeFile(projectPath + "/" + fileName, fileData);
    
    QString mainFilePath = projectPath + "/" + fileName;
    
    while(dataStream.status() == QDataStream::Ok) {
        fileName.clear();
        fileData.clear();
        
        dataStream >> fileName;
        dataStream >> fileData;
        
        if(!fileName.isEmpty()) {
            writeFile(projectPath + "/" + fileName, fileData);
        }
    }
    emit downloadFinished(mainFilePath);
}
Example #14
0
void DownloadItem::stop(bool askForDeleteFile)
{
    if (downloadStopped_)
        return;

    downloadStopped_ = true;
    QString host = downloadUrl_.host();

    openAfterFinish_ = false;
    updateInfoTimer_.stop();
    reply_->abort();
    reply_->deleteLater();

    outputFile_.close();
    QString outputfile = QFileInfo(outputFile_).absoluteFilePath();
    downloadInfo_->setText(tr("Cancelled - %1").arg(host));
    progressFrame_->hide();
    item_->setSizeHint(sizeHint());

    downloading_ = false;

    emit downloadFinished(false);

    if (askForDeleteFile) {
        QMessageBox::StandardButton button =
            QMessageBox::question(item_->listWidget()->parentWidget(),
                                  tr("Delete file"),
                                  tr("Do you want to also delete downloaded file?"),
                                  QMessageBox::Yes | QMessageBox::No);
        if (button == QMessageBox::Yes) {
            QFile::remove(outputfile);
        }
    }
}
Example #15
0
void DownloadItem::finished()
{
    updateInfoTimer_.stop();

    QString host = downloadUrl_.host();
    QString fileSize = fileSizeToString(total_);

    if (fileSize == tr("Unknown size")) {
        fileSize = fileSizeToString(received_);
    }
    downloadInfo_->setText(QString("%1 - %2 - %3").arg(fileSize, host, QDateTime::currentDateTime().time().toString()));

    progressFrame_->hide();
    item_->setSizeHint(sizeHint());
    outputFile_.close();

    reply_->deleteLater();

    downloading_ = false;

    if (openAfterFinish_) {
        openFile();
    }

    emit downloadFinished(true);
}
void DownloadManagerImpl::slotDownloadFinished(int contactId, int downloadId, const QString &filePath, int type)
{
    emit downloadFinished(contactId, downloadId, filePath, type);
    removeAndUpdateDownload(downloadId, DownloadManager::Finished);
    qDebug() << __PRETTY_FUNCTION__ << " Emitted downloadFinished signal, contactId = "
             << contactId << ", downloadId = " << downloadId;
}
Example #17
0
void DownloadManager::startNextDownload()
{
    if (downloadQueue.isEmpty()) {
        printf("%d/%d files downloaded successfully\n", downloadedCount, totalCount);
        emit finished();
        return;
    }

    QUrl url = downloadQueue.dequeue();

    QString filename = saveFileName(url);
    output.setFileName(filename);
    if (!output.open(QIODevice::WriteOnly)) {
        fprintf(stderr, "Problem opening save file '%s' for download '%s': %s\n",
                qPrintable(filename), url.toEncoded().constData(),
                qPrintable(output.errorString()));

        startNextDownload();
        return;                 // skip this download
    }

    QNetworkRequest request(url);
    currentDownload = manager.get(request);
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
            SLOT(downloadProgress(qint64,qint64)));
    connect(currentDownload, SIGNAL(finished()),
            SLOT(downloadFinished()));
    connect(currentDownload, SIGNAL(readyRead()),
            SLOT(downloadReadyRead()));

    // prepare the output
    printf("Downloading %s...\n", url.toEncoded().constData());
    downloadTime.start();
}
Example #18
0
void TabReplays::actDownload()
{
    QString filePath;
    QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
    if (!curLeft.isValid())
        filePath = localDirModel->rootPath();
    else {
        while (!localDirModel->isDir(curLeft))
            curLeft = curLeft.parent();
        filePath = localDirModel->filePath(curLeft);
    }

    ServerInfo_Replay const *curRight = serverDirView->getCurrentReplay();
    if (!curRight)
        return;
    filePath += QString("/replay_%1.cor").arg(curRight->replay_id());
    
    Command_ReplayDownload cmd;
    cmd.set_replay_id(curRight->replay_id());
    
    PendingCommand *pend = client->prepareSessionCommand(cmd);
    pend->setExtraData(filePath);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(downloadFinished(Response, CommandContainer, QVariant)));
    client->sendCommand(pend);
}
Example #19
0
/**
 * @brief SetsWidget::SetsWidget
 * @param parent
 */
SetsWidget::SetsWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SetsWidget)
{
    ui->setupUi(this);

    ui->sets->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    ui->movies->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    ui->movies->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->buttonPreviewBackdrop->setEnabled(false);
    ui->buttonPreviewPoster->setEnabled(false);

#ifdef Q_OS_MAC
    QFont setsFont = ui->sets->font();
    setsFont.setPointSize(setsFont.pointSize()-2);
    ui->sets->setFont(setsFont);
#endif

#ifndef Q_OS_MAC
    QFont nameFont = ui->setName->font();
    nameFont.setPointSize(nameFont.pointSize()-4);
    ui->setName->setFont(nameFont);
#endif

    Helper::instance()->applyStyle(ui->movies);
    Helper::instance()->applyStyle(ui->label_13);
    Helper::instance()->applyStyle(ui->label_14);
    Helper::instance()->applyStyle(ui->posterResolution);
    Helper::instance()->applyStyle(ui->backdropResolution);
    Helper::instance()->applyStyle(ui->groupBox_3);
    Helper::instance()->applyEffect(ui->groupBox_3);

    m_loadingMovie = new QMovie(":/img/spinner.gif");
    m_loadingMovie->start();
    m_downloadManager = new DownloadManager(this);

    connect(ui->sets, SIGNAL(itemSelectionChanged()), this, SLOT(onSetSelected()));
    connect(ui->sets, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onSetNameChanged(QTableWidgetItem*)));
    connect(ui->movies, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onSortTitleChanged(QTableWidgetItem*)));
    connect(ui->movies, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(onJumpToMovie(QTableWidgetItem*)));
    connect(ui->buttonAddMovie, SIGNAL(clicked()), this, SLOT(onAddMovie()));
    connect(ui->buttonRemoveMovie, SIGNAL(clicked()), this, SLOT(onRemoveMovie()));
    connect(ui->poster, SIGNAL(clicked()), this, SLOT(chooseSetPoster()));
    connect(ui->backdrop, SIGNAL(clicked()), this, SLOT(chooseSetBackdrop()));
    connect(ui->buttonPreviewPoster, SIGNAL(clicked()), this, SLOT(onPreviewPoster()));
    connect(ui->buttonPreviewBackdrop, SIGNAL(clicked()), this, SLOT(onPreviewBackdrop()));
    connect(m_downloadManager, SIGNAL(downloadFinished(DownloadManagerElement)), this, SLOT(onDownloadFinished(DownloadManagerElement)));

    ui->sets->setContextMenuPolicy(Qt::CustomContextMenu);
    m_tableContextMenu = new QMenu(ui->sets);
    QAction *actionAddSet = new QAction(tr("Add Movie Set"), this);
    QAction *actionDeleteSet = new QAction(tr("Delete Movie Set"), this);
    m_tableContextMenu->addAction(actionAddSet);
    m_tableContextMenu->addAction(actionDeleteSet);
    connect(actionAddSet, SIGNAL(triggered()), this, SLOT(onAddMovieSet()));
    connect(actionDeleteSet, SIGNAL(triggered()), this, SLOT(onRemoveMovieSet()));
    connect(ui->sets, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showSetsContextMenu(QPoint)));

    clear();
}
Example #20
0
StatusBar::StatusBar()
{
    mDownloadButton = new QToolButton( this );
    mDownloadButton->setGeometry( 0, 0, 20, 20 );
    mDownloadButton->setIcon( QIcon(":/icons/menus/download.png"));
    
    mDownloadManager = new DownloadManager( window() );

    connect( mDownloadButton, SIGNAL( clicked(bool) ), 
             this, SLOT( toggleDownloadManager()) );
    
    connect( mDownloadManager, SIGNAL( downloadFinished() ),
             this, SLOT( popupDownloadManager() ) );
    
    setFixedHeight( 21 );
        
    mLabel = new QLabel( this );
    QFont font;
    font.setPixelSize( 12 );
    
    mLabel->setFont( font );
    mLabel->setMaximumHeight( 20 );
    
    addPermanentWidget( mDownloadButton );
    addPermanentWidget( mLabel );
    mLabel->setText( "" );
}
Example #21
0
void FtpThread::isDone()
{
    if(doneBytes>=this->size)
    {
        downloadFinished(false);
    }
}
    void DownloadManager::stopDownloadImpl( QString const & url, bool pause )
    {
        QNetworkReply *reply = m_urlHash[url];

        if( reply ) {
            QObject::disconnect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( downloadProgress( qint64, qint64 )));
            QObject::disconnect( reply, SIGNAL( finished() ), this, SLOT( downloadFinished() ));
            QObject::disconnect( reply, SIGNAL( readyRead() ), this, SLOT( downloadReadyRead() ) );
            QObject::disconnect( reply, SIGNAL( error( QNetworkReply::NetworkError )), this, SLOT( downloadError( QNetworkReply::NetworkError )));

            Downloads item = m_downloadHash[ reply ];
            reply->abort();
            if( !item.m_file) return;

            item.m_file->write( reply->readAll() );
            item.m_file->close();

            if ( !pause ) {
                QFile::remove( item.m_tempFile );
            }

            m_downloadHash.remove( reply );
            m_urlHash.remove( url );
            startNextDownload();

            reply->deleteLater();
        }
    }
Example #23
0
void CacheDownload::start()
{
    if (!m_entry->stale)
    {
        emit succeeded(index_within_job);
        return;
    }
    m_output_file.setFileName(m_target_path);
    // if there already is a file and md5 checking is in effect and it can be opened
    if (!ensureFilePathExists(m_target_path))
    {
        emit failed(index_within_job);
        return;
    }
    QLOG_INFO() << "Downloading " << m_url.toString();
    QNetworkRequest request(m_url);
    if (m_entry->remote_changed_timestamp.size())
        request.setRawHeader(QString("If-Modified-Since").toLatin1(),
                             m_entry->remote_changed_timestamp.toLatin1());
    if (m_entry->etag.size())
        request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());

    request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");

    auto worker = MMC->qnam();
    QNetworkReply *rep = worker->get(request);

    m_reply = std::shared_ptr<QNetworkReply>(rep);
    connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
            SLOT(downloadProgress(qint64, qint64)));
    connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
    connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
            SLOT(downloadError(QNetworkReply::NetworkError)));
    connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
}
void AddNewTorrentDialog::show(QString source, QWidget *parent)
{
    AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent);

    if (Utils::Misc::isUrl(source)) {
        // Launch downloader
        Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
        connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString)));
        connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString)));
        connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString)));
    }
    else {
        bool ok = false;
        BitTorrent::MagnetUri magnetUri(source);
        if (magnetUri.isValid())
            ok = dlg->loadMagnet(magnetUri);
        else
            ok = dlg->loadTorrent(source);

        if (ok)
            dlg->open();
        else
            delete dlg;
    }
}
void CDownload::startDownload(QNetworkAccessManager* netManager)
{
    if (mState == EDownloadNotStarted)
    {
        mState = EDownloadFailed;
        if (netManager)
        {
            QNetworkAccessManager::NetworkAccessibility access = netManager->networkAccessible();
            if (access != QNetworkAccessManager::NotAccessible)
            {
                mNetReply = netManager->get(QNetworkRequest(QUrl(mUrlName)));
                if (mNetReply)
                {
                    connect(
                        mNetReply, SIGNAL(finished()),
                        this, SLOT(downloadFinished()));

                    connect(
                        mNetReply, SIGNAL(error(QNetworkReply::NetworkError)),
                        this, SLOT(downloadError(QNetworkReply::NetworkError)));
                    //connect(
                    //    mNetReply, SIGNAL(downloadProgress(qint64, qint64)),
                    //    this, SLOT(downloadProgress(qint64, qint64)));
                    mState = EDownloadStarted;
                }
            }
        }
    }
}
void HttpUpdater::downloadInstaller(const QUrl& url)
{
    //download the file from net into local place
    QString filename = saveFileName(url);
    binFile.setFileName(filename);
    if (!binFile.open(QIODevice::WriteOnly))
    {

        QMessageBox::warning(0, "HEXplorer::update", "Problem opening file " +
                           filename + " for download at " + url.toEncoded().constData() +
                           " : " + url.toEncoded().constData() + "\n",
                              QMessageBox::Ok, QMessageBox::Cancel);

        return;

        return;
    }

    QNetworkRequest request(url);
    requestInstaller = manager.get(request);

    connect(requestInstaller, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64)));
    connect(requestInstaller, SIGNAL(finished()), SLOT(downloadFinished()));
    connect(requestInstaller, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));

    downloadTime.start();
}
Example #27
0
void OnlineDevice::copySongTo(const Song &s, const QString &musicPath, bool overwrite, bool copyCover)
{
    Q_UNUSED(copyCover)

    jobAbortRequested=false;
    QString baseDir=MPDConnection::self()->getDetails().dir;
    QString dest(baseDir+musicPath);
    if (!overwrite && (QFile::exists(dest) || MpdLibraryModel::self()->songExists(s))) {
        emit actionStatus(SongExists);
        return;
    }

    overWrite=overwrite;
    lastProg=-1;
    currentDestFile=baseDir+musicPath;
    currentSong=s;

    QDir dir(Utils::getDir(dest));
    if (!dir.exists() && !Utils::createWorldReadableDir(dir.absolutePath(), baseDir)) {
        emit actionStatus(DirCreationFaild);
        return;
    }

    job=NetworkAccessManager::self()->get(QUrl(s.file));
    connect(job, SIGNAL(finished()), SLOT(downloadFinished()));
    connect(job, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64)));
}
Example #28
0
void DownloadItem::finished()
{
#ifdef DOWNMANAGER_DEBUG
    qDebug() << __FUNCTION__ << m_reply;
#endif
    m_timer.stop();

    QString host = m_reply->url().host();
    ui->downloadInfo->setText(tr("Done - %1 (%2)").arg(host, QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate)));
    ui->progressBar->hide();
    ui->button->hide();
    ui->frame->hide();
    m_outputFile.close();

    if (m_reply) {
        m_reply->deleteLater();
    }
    else {
#if QTWEBENGINE_DISABLED
        m_ftpDownloader->deleteLater();
#endif
    }

    m_item->setSizeHint(sizeHint());
    m_downloading = false;

    if (m_openAfterFinish) {
        openFile();
    }

    emit downloadFinished(true);
}
void DownloadManager::downloadRequested(const QNetworkRequest& request) {
    std::cout << "DownloadManager::DownloadRequested()\n";
    QString src = request.url().toString();
    QString dest = request.attribute(QNetworkRequest::User, "~").toString();

    QFile* fileDestination = new QFile(dest);
    fileDestination->open(QIODevice::ReadWrite);
    QNetworkReply* reply = mNetworkAccess.get(request);
    reply->setReadBufferSize(0);
    mActiveDownloads.insert(reply, fileDestination);

    connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
    connect(reply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));

    DownloadData* data = new DownloadData();
    data->mRemotePath = src;
    data->mLocalPath = dest;

    connect(reply, SIGNAL(finished()), data, SLOT(finished()));

    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), data, SLOT(catchProgress(qint64, qint64)));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), data, SIGNAL(error(QNetworkReply::NetworkError)));
    connect(data, SIGNAL(stopMe()), this, SLOT(stopDownload()));
    connect(data, SIGNAL(removeMe()), this, SLOT(removeDownload()));
    //connect(data, SIGNAL(reloadMe()), this, SLOT(reloadDownload()));

    emit downloadStarted(data);
    emit controller_showSystemTrayMessage("", "Download Started: " + data->localName());
    mModel.addDownload(data);
    mDownloads.insert(data, reply);
}
Example #30
0
frmProgress::frmProgress(QWidget * parent, Qt::WindowFlags f)
    : QWidget(parent, f)
{
    qRegisterMetaType<QNapiSubtitleInfoList>("QNapiSubtitleInfoList");

    ui.setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose, false);
    setAttribute(Qt::WA_QuitOnClose, false);

    setBatchMode(false);

    connect(&getThread, SIGNAL(fileNameChange(const QString &)),
            ui.lbFileName, SLOT(setText(const QString &)));
    connect(&getThread, SIGNAL(actionChange(const QString &)),
            ui.lbAction, SLOT(setText(const QString &)));
    connect(&getThread, SIGNAL(progressChange(int, int, float)),
            this, SLOT(updateProgress(int, int, float)));
    connect(&getThread, SIGNAL(selectSubtitles(QString, QNapiSubtitleInfoList)),
            this, SLOT(selectSubtitles(QString, QNapiSubtitleInfoList)));
    connect(this, SIGNAL(subtitlesSelected(int)),
            &getThread, SLOT(subtitlesSelected(int)));
    connect(&getThread, SIGNAL(finished()),
            this, SLOT(downloadFinished()));

    QRect position = frameGeometry();
    position.moveCenter(QDesktopWidget().availableGeometry().center());
    move(position.topLeft());
}