DownloadHelper::DownloadHelper(QNetworkReply* pReply, QString fileName) : QObject(pReply), fileName_(fileName) { connect(pReply, SIGNAL(finished()), this, SLOT(onDownloadFinished())); }
void DownloadManager::doDownload(const QUrl &url) { QString filename = saveFileName(url); if(QFile::exists(filename)) { emit onDownloadFinished(url, filename); return; } doDownloadToPath(url, filename); }
void Downloader::startDownload (const QUrl& url) { /* Reset UI */ m_ui->progressBar->setValue (0); m_ui->stopButton->setText (tr ("Stop")); m_ui->downloadLabel->setText (tr ("Downloading updates")); m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown")); /* Start download */ m_startTime = QDateTime::currentDateTime().toTime_t(); m_reply = m_manager->get (QNetworkRequest (url)); /* Update UI when download progress changes or download finishes */ connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)), this, SLOT (updateProgress (qint64, qint64))); connect (m_reply, SIGNAL (finished()), this, SLOT (onDownloadFinished())); showNormal(); }
bool DownloadJob::checkForResumedFile() { tLog() << Q_FUNC_INFO; if ( !m_tryResuming ) return false; QUrl localFile = prepareFilename(); QFileInfo fi( localFile.toString() ); tLog() << Q_FUNC_INFO << m_fileSize << fi.size(); if ( fi.size() > 0 && fi.exists() && fi.size() == m_fileSize ) { tLog() << Q_FUNC_INFO << "Detected previously finished download."; m_rcvdSize = fi.size(); m_finished = true; onDownloadFinished(); return true; } return false; }
MovieController::MovieController(Movie *parent) : QObject(parent) { m_movie = parent; m_infoLoaded = false; m_infoFromNfoLoaded = false; m_downloadManager = new DownloadManager(this); m_downloadsInProgress = false; m_downloadsSize = 0; connect(m_downloadManager, SIGNAL(downloadFinished(DownloadManagerElement)), this, SLOT(onDownloadFinished(DownloadManagerElement))); connect(m_downloadManager, SIGNAL(allDownloadsFinished(Movie*)), this, SLOT(onAllDownloadsFinished()), Qt::UniqueConnection); }
TvShowWidgetSeason::TvShowWidgetSeason(QWidget *parent) : QWidget(parent), ui(new Ui::TvShowWidgetSeason) { ui->setupUi(this); m_show = 0; m_season = -1; ui->title->clear(); QFont font = ui->title->font(); font.setPointSize(font.pointSize()+4); ui->title->setFont(font); ui->poster->setDefaultPixmap(QPixmap(":/img/film_reel.png")); ui->backdrop->setDefaultPixmap(QPixmap(":/img/pictures_alt.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation)); ui->banner->setDefaultPixmap(QPixmap()); m_downloadManager = new DownloadManager(this); m_loadingMovie = new QMovie(":/img/spinner.gif"); m_loadingMovie->start(); m_savingWidget = new QLabel(this); m_savingWidget->setMovie(m_loadingMovie); m_savingWidget->hide(); onSetEnabled(false); onClear(); QPainter p; QPixmap revert(":/img/arrow_circle_left.png"); p.begin(&revert); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(revert.rect(), QColor(0, 0, 0, 200)); p.end(); ui->buttonRevert->setIcon(QIcon(revert)); ui->buttonRevert->setVisible(false); connect(ui->poster, SIGNAL(clicked()), this, SLOT(onChoosePoster())); connect(ui->backdrop, SIGNAL(clicked()), this, SLOT(onChooseBackdrop())); connect(ui->banner, SIGNAL(clicked()), this, SLOT(onChooseBanner())); connect(ui->poster, SIGNAL(sigClose()), this, SLOT(onDeletePoster())); connect(ui->backdrop, SIGNAL(sigClose()), this, SLOT(onDeleteBackdrop())); connect(ui->banner, SIGNAL(sigClose()), this, SLOT(onDeleteBanner())); connect(ui->buttonRevert, SIGNAL(clicked()), this, SLOT(onRevertChanges())); connect(m_downloadManager, SIGNAL(downloadFinished(DownloadManagerElement)), this, SLOT(onDownloadFinished(DownloadManagerElement))); }
TvShowWidgetSeason::TvShowWidgetSeason(QWidget *parent) : QWidget(parent), ui(new Ui::TvShowWidgetSeason) { ui->setupUi(this); m_show = 0; m_season = -1; ui->title->clear(); ui->posterResolution->clear(); ui->backdropResolution->clear(); ui->bannerResolution->clear(); QFont font = ui->title->font(); font.setPointSize(font.pointSize()+4); ui->title->setFont(font); ui->buttonPreviewBackdrop->setEnabled(false); ui->buttonPreviewPoster->setEnabled(false); ui->buttonPreviewBanner->setEnabled(false); font = ui->posterResolution->font(); #ifdef Q_OS_WIN32 font.setPointSize(font.pointSize()-1); #else font.setPointSize(font.pointSize()-2); #endif ui->posterResolution->setFont(font); ui->backdropResolution->setFont(font); ui->bannerResolution->setFont(font); m_downloadManager = new DownloadManager(this); m_loadingMovie = new QMovie(":/img/spinner.gif"); m_loadingMovie->start(); m_savingWidget = new QLabel(this); m_savingWidget->setMovie(m_loadingMovie); m_savingWidget->hide(); onSetEnabled(false); onClear(); QPixmap zoomIn(":/img/zoom_in.png"); QPainter p; p.begin(&zoomIn); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(zoomIn.rect(), QColor(0, 0, 0, 150)); p.end(); ui->buttonPreviewBackdrop->setIcon(QIcon(zoomIn)); ui->buttonPreviewPoster->setIcon(QIcon(zoomIn)); ui->buttonPreviewBanner->setIcon(QIcon(zoomIn)); QPixmap revert(":/img/reload.png"); p.begin(&revert); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(revert.rect(), QColor(0, 0, 0, 200)); p.end(); ui->buttonRevert->setIcon(QIcon(revert)); ui->buttonRevert->setVisible(false); connect(ui->poster, SIGNAL(clicked()), this, SLOT(onChoosePoster())); connect(ui->backdrop, SIGNAL(clicked()), this, SLOT(onChooseBackdrop())); connect(ui->banner, SIGNAL(clicked()), this, SLOT(onChooseBanner())); connect(ui->buttonPreviewPoster, SIGNAL(clicked()), this, SLOT(onPreviewPoster())); connect(ui->buttonPreviewBackdrop, SIGNAL(clicked()), this, SLOT(onPreviewBackdrop())); connect(ui->buttonPreviewBanner, SIGNAL(clicked()), this, SLOT(onPreviewBanner())); connect(ui->buttonRevert, SIGNAL(clicked()), this, SLOT(onRevertChanges())); connect(m_downloadManager, SIGNAL(downloadFinished(DownloadManagerElement)), this, SLOT(onDownloadFinished(DownloadManagerElement))); }
/** * @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(); }
void DownloadJob::onDownloadProgress( qint64 rcvd, qint64 total ) { if ( m_reply == 0 ) return; if ( rcvd >= m_fileSize && m_fileSize > 0 ) { m_finished = true; } if ( state() == Paused ) return; m_rcvdSize = rcvd; m_fileSize = total; qint64 now = QDateTime::currentDateTime().toMSecsSinceEpoch(); if ( ( now - 50 > m_rcvdStamp ) || ( rcvd == total ) ) { m_rcvdStamp = now; if ( ( m_rcvdSize - 16384 > m_rcvdEmit ) || ( rcvd == total ) ) { m_rcvdEmit = m_rcvdSize; emit progress( progressPercentage() ); } } if ( !m_file ) return; if ( !m_file->isOpen() ) { if ( m_tryResuming && checkForResumedFile() ) return; if ( !m_file->open( QIODevice::WriteOnly ) ) { tLog() << Q_FUNC_INFO << "Failed opening file:" << m_file->fileName(); setState( Failed ); return; } } QByteArray data = m_reply->readAll(); if ( data.isEmpty() ) return; if ( m_file->write( data ) < 0 ) { tLog() << Q_FUNC_INFO << "Failed writing to file:" << data.length(); onDownloadError( QNetworkReply::UnknownContentError ); return; } if ( m_rcvdSize >= m_fileSize && m_fileSize > 0 ) { onDownloadFinished(); } else if ( m_reply->isFinished() && m_reply->bytesAvailable() == 0 ) { if ( ( m_fileSize > 0 && m_rcvdSize < m_fileSize ) || m_rcvdSize == 0 ) { onDownloadError( QNetworkReply::UnknownContentError ); return; } } }
/** * @brief CLI::CLI * @param parent * @param arguments Command line arguments */ CLI::CLI(QObject *parent, QStringList arguments) : QObject(parent) { m_useFolderName = false; m_arguments = arguments; m_downloadManager = new DownloadManager(this); m_infosToLoad << MovieScraperInfos::Title << MovieScraperInfos::Tagline << MovieScraperInfos::Rating << MovieScraperInfos::Released << MovieScraperInfos::Runtime << MovieScraperInfos::Certification << MovieScraperInfos::Trailer << MovieScraperInfos::Overview << MovieScraperInfos::Poster << MovieScraperInfos::Backdrop << MovieScraperInfos::Actors << MovieScraperInfos::Genres << MovieScraperInfos::Studios << MovieScraperInfos::Countries; connect(m_downloadManager, SIGNAL(allDownloadsFinished()), this, SLOT(onDownloadsFinished())); connect(m_downloadManager, SIGNAL(downloadFinished(DownloadManagerElement)), this, SLOT(onDownloadFinished(DownloadManagerElement))); Manager::instance(); }
void DialogBare::onLinkClicked(const QUrl &url) { QString firmwareFile = QFileInfo(url.toString()).fileName(); QString filename; // If a IO firmware file, open save as DialogBare if (firmwareFile.endsWith(".bin") && firmwareFile.contains("px4io")) { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QString path = QString(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); #else QString path = QString(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); #endif qDebug() << path; filename = QFileDialog::getExistingDirectory(this, tr("Select folder (microSD Card)"), path); filename.append("/" + firmwareFile); } else { // Make sure the user doesn't screw up flashing //QMessageBox msgBox; //msgBox.setText("Please unplug your PX4 board now"); //msgBox.exec(); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) filename = QString(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); #else filename = QString(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); #endif if (filename.isEmpty()) { qDebug() << "Falling back to temp dir"; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QString filename = QString(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); #else QString filename = QString(QDesktopServices::storageLocation(QDesktopServices::TempLocation)); #endif // If still empty, bail out if (filename.isEmpty()) ui->upgradeLog->appendHtml(tr("FAILED storing firmware to downloads or temp directory. Harddisk not writable.")); return; } filename += "/" + firmwareFile; } if (filename == "") { return; } // Else, flash the firmware lastFilename = filename; ui->upgradeLog->appendHtml(tr("Downloading firmware file <a href=\"%1\">%1</a>").arg(url.toString())); QNetworkRequest newRequest(url); newRequest.setUrl(url); newRequest.setAttribute(QNetworkRequest::User, filename); // XXX rework QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); //ui->webView->page()->networkAccessManager(); QNetworkReply *reply = networkManager->get(newRequest); connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(onDownloadProgress(qint64, qint64))); connect(reply, SIGNAL(finished()), this, SLOT(onDownloadFinished())); }