int DownloadManager::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: downloadComplete(); break; case 1: progress((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: downloadStatus((*reinterpret_cast< float(*)>(_a[1]))); break; case 3: downloadStarted(); break; case 4: cancel(); break; case 5: download((*reinterpret_cast< QUrl(*)>(_a[1]))); break; case 6: pause(); break; case 7: resume(); break; case 8: download((*reinterpret_cast< QNetworkRequest(*)>(_a[1]))); break; case 9: finished(); break; case 10: downloadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break; case 11: error((*reinterpret_cast< QNetworkReply::NetworkError(*)>(_a[1]))); break; default: ; } _id -= 12; } return _id; }
void BTInstallMgr::preStatus(long totalBytes, long completedBytes, const char* /*message*/) { qWarning("pre Status: %i / %i", (int)totalBytes, (int)completedBytes); emit downloadStarted( "unknown filename" ); m_completedBytes = completedBytes; m_totalBytes = (totalBytes > 0) ? totalBytes : 1; //avoid division by zero }
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); }
void BtInstallThread::run() { qDebug() << "BtInstallThread::run, mod:" << m_module << "src:" << m_source << "dest:" << m_destination; emit preparingInstall(m_module, m_source); //make sure target/mods.d and target/modules exist QDir dir(m_destination); if (!dir.exists()) { dir.mkdir(m_destination); qDebug() << "made directory" << m_destination; } if (!dir.exists("modules")) { dir.mkdir("modules"); qDebug() << "made directory" << m_destination << "/modules"; } if (!dir.exists("mods.d")) { dir.mkdir("mods.d"); qDebug() << "made directory" << m_destination << "/mods.d"; } QObject::connect(&m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int))); QObject::connect(&m_iMgr, SIGNAL(downloadStarted()), this, SLOT(slotDownloadStarted())); //check whether it's an update. If yes, remove existing module first //TODO: silently removing without undo if the user cancels the update is WRONG!!! removeModule(); // manager for the destination path sword::SWMgr lMgr( m_destination.toLatin1() ); if (instbackend::isRemote(m_installSource)) { qDebug() << "calling install"; int status = m_iMgr.installModule(&lMgr, 0, m_module.toLatin1(), &m_installSource); if (status != 0) { qWarning() << "Error with install: " << status << "module:" << m_module; } else { done = true; emit installCompleted(m_module, m_source, status); } } else { //local source emit statusUpdated(m_module, 0); int status = m_iMgr.installModule(&lMgr, m_installSource.directory.c_str(), m_module.toLatin1()); if (status > 0) { qWarning() << "Error with install: " << status << "module:" << m_module; } else if (status == -1) { // it was terminated, do nothing } else { emit statusUpdated(m_module, 100); done = true; emit installCompleted(m_module, m_source, status); } } }
void ArchiveList::fillPartialArchiveItem(PartialArchive *a, QTreeWidgetItem *item) { QTreeWidgetItem *subItem = new QTreeWidgetItem(item); QPushButton *pauseButton = new QPushButton(); pauseButton->setText(a->isDownloading() ? tr("Pause") : tr("Continue")); connect(pauseButton, SIGNAL(clicked()), a, SLOT(togglePauseDownload())); downloadPausedMapper->setMapping(a, pauseButton); downloadStartedMapper->setMapping(a, pauseButton); connect(a, SIGNAL(downloadStarted()), downloadStartedMapper, SLOT(map())); connect(a, SIGNAL(downloadPaused()), downloadPausedMapper, SLOT(map())); int pbarColumn; if (compactLayout) { pbarColumn = 1; subItem->setSizeHint(1, pauseButton->sizeHint()); setItemWidget(subItem, 1, pauseButton); QPushButton *detailsButton = new QPushButton(tr("Details")); showDetailsMapper->setMapping(detailsButton, a); connect(detailsButton, SIGNAL(clicked()), showDetailsMapper, SLOT(map())); subItem->setSizeHint(0, detailsButton->sizeHint()); setItemWidget(subItem, 0, detailsButton); } else { pbarColumn = 2; item->setSizeHint(3, pauseButton->sizeHint()); setItemWidget(item, 3, pauseButton); item->setText(1, a->getSizeMB()); QLabel *peerInfo = new QLabel(); subItem->setSizeHint(1, peerInfo->sizeHint()); setItemWidget(subItem, 1, peerInfo); connect(a, SIGNAL(peerInfoUpdated(QString)), peerInfo, SLOT(setText(QString))); QLabel *speedText = new QLabel(); subItem->setSizeHint(2, speedText->sizeHint()); setItemWidget(subItem, 2, speedText); connect(a, SIGNAL(speedTextUpdated(QString)), speedText, SLOT(setText(QString))); QLabel *statusText = new QLabel(); subItem->setSizeHint(3, statusText->sizeHint()); setItemWidget(subItem, 3, statusText); connect(a, SIGNAL(statusTextUpdated(QString)), statusText, SLOT(setText(QString))); } QProgressBar *pbar = new QProgressBar(); pbar->setMinimum(0); pbar->setMaximum(100); item->setSizeHint(pbarColumn, pbar->sizeHint()); setItemWidget(item, pbarColumn, pbar); connect(a, SIGNAL(progressUpdated(int)), pbar, SLOT(setValue(int))); a->emitStatusEvents(); }
void DownloadManager::download( QNetworkRequest& request ) { //qDebug() << "download( QNetworkRequest& request )"; mCurrentReply = mManager->get(request); connect(mCurrentReply,SIGNAL(finished()),this,SLOT(finished())); connect(mCurrentReply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); connect(mCurrentReply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError))); emit downloadStarted(); }
/* * Download CSV using wget */ bool parseCSV::download(){ if(!QFile(csvPath).exists()){ emit downloadStarted(cObj.getName(), false, false); if(!startProcess("wget "+csv)){ emit error(6); return false; } emit downloadFinished(cObj.getName(), false, false); } return true; }
void PartialArchive::updateState(TorrentClient::State s) { emit statusTextUpdated(getStateText(s)); if (s == TorrentClient::Paused) emit downloadPaused(); else emit downloadStarted(); if (s == TorrentClient::Seeding) changeToLocalArchive(); }
void Downloader::synchronizeMetadata() { downloadInfo->url = metadataGrabber->url; downloadInfo->partialContentSupport = metadataGrabber->partialContentSupport; downloadInfo->fileSize = metadataGrabber->fileSize; downloadInfo->contentType = metadataGrabber->contentType; downloadInfo->fileName = metadataGrabber->fileName; downloadInfo->iconPath ="/usr/share/icons/Humanity/mimes/48/" + Globals::mimeDatabase.mimeTypeForName(downloadInfo->contentType).iconName() + ".svg"; //###################DELETE METADATA GRABBER####################### segmentManager = new SegmentManager(downloadInfo); emit downloadStarted(this); }
void FSettingsDialog::on_btn_Artwork_DownloadAll_clicked() { if(QMessageBox::warning(this, tr("Please confirm!"), tr("If artwork is found, existing artwork will be overwritten!"),QMessageBox::Ok, QMessageBox::Cancel) ==QMessageBox::Cancel) return; runningDownloads = 0; totalDownloads = 0; gameList = db->getGameList(); for(int i=0;i<gameList.length();++i) { FArtManager *artmanager = new FArtManager(); connect(artmanager, SIGNAL(startedDownload()), this, SLOT(downloadStarted())); connect(artmanager, SIGNAL(finishedDownload()), this, SLOT(downloadFinished())); artmanager->getGameData(gameList[i], "PC"); } }
DeclarativeWebContainer::DeclarativeWebContainer(QQuickItem *parent) : QQuickItem(parent) , m_webPage(0) , m_model(0) , m_webPageComponent(0) , m_settingManager(SettingManager::instance()) , m_foreground(true) , m_allowHiding(true) , m_popupActive(false) , m_portrait(true) , m_fullScreenMode(false) , m_fullScreenHeight(0.0) , m_inputPanelVisible(false) , m_inputPanelHeight(0.0) , m_inputPanelOpenHeight(0.0) , m_toolbarHeight(0.0) , m_tabId(0) , m_loading(false) , m_loadProgress(0) , m_canGoForward(false) , m_canGoBack(false) , m_realNavigation(false) , m_completed(false) , m_initialized(false) { m_webPages.reset(new WebPages(this)); setFlag(QQuickItem::ItemHasContents, true); connect(DownloadManager::instance(), SIGNAL(downloadStarted()), this, SLOT(onDownloadStarted())); connect(QMozContext::GetInstance(), SIGNAL(onInitialized()), this, SLOT(initialize())); connect(this, SIGNAL(portraitChanged()), this, SLOT(resetHeight())); connect(this, SIGNAL(enabledChanged()), this, SLOT(handleEnabledChanged())); QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); QDir dir(cacheLocation); if(!dir.exists() && !dir.mkpath(cacheLocation)) { qWarning() << "Can't create directory "+ cacheLocation; return; } connect(this, SIGNAL(heightChanged()), this, SLOT(sendVkbOpenCompositionMetrics())); connect(this, SIGNAL(widthChanged()), this, SLOT(sendVkbOpenCompositionMetrics())); qApp->installEventFilter(this); }
void Downloader::doHttpRequest(QString url){ QNetworkRequest request; request.setUrl(QUrl(url)); request.setRawHeader( "User-Agent" , "Mozilla Firefox" ); // :) Probabilly is not really need! qInfo() << endl << "Starting http request to" << url; reply.reset( httpClient.get(request)); if(reply->error() != QNetworkReply::NoError){ throw std::runtime_error(reply->errorString().toStdString()); } connect(reply.data(), SIGNAL(finished()), this, SIGNAL(downloadFinished())); connect(reply.data(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgressed(qint64,qint64))); connect(reply.data(), SIGNAL(readyRead()), this, SLOT(bytesAvailable())); connect(reply.data(), SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); emit downloadStarted(); }
void DownloadManager::download(QUrl url, QString fileName, QString localDirPath) { qDebug() << "download: URL = " <<url.toString(); if (_pReply != NULL) { abort(); } _URL = url; _fileName = fileName; { if (!localDirPath.isNull() && !localDirPath.isEmpty()) { _path = localDirPath; } else { _path = Utils().getDefaultCacheDirPath(); } QString extension = "mp3";//vk only allows mp3 QFileInfo fileInfo(_path.append("/").append(fileName).append(".").append(extension)); _qsFileAbsPath = fileInfo.absoluteFilePath(); qDebug() << "download: local path =" << _qsFileAbsPath; } _nDownloadSize = 0; _nDownloadSizeAtPause = 0; // _pManager = new QNetworkAccessManager(this); _request = QNetworkRequest(url); _pReply = _pManager->head(_request); emit downloadStarted(); setDownloading(true); _Timer.setInterval(5000); _Timer.setSingleShot(true); connect(&_Timer, SIGNAL(timeout()), this, SLOT(timeout())); _Timer.start(); connect(_pReply, SIGNAL(finished()), this, SLOT(finishedHead())); connect(_pReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); }
/** Retrieves the firmware from the device */ void DeviceWidget::downloadFirmware() { // clear progress bar now // this avoids displaying an error message and the progress at 100% at the same time setProgress(0); updateButtons(false); if (!m_dfu->devices[deviceID].Readable) { myDevice->statusLabel->setText(QString("Device not readable!")); status("Device not readable!", STATUSICON_FAIL); updateButtons(true); return; } filename = setSaveFileName(); if (filename.isEmpty()) { status("Empty filename", STATUSICON_FAIL); updateButtons(true); return; } status("Starting firmware download", STATUSICON_RUNNING); emit downloadStarted(); 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) { emit downloadEnded(false); status("Could not start download!", STATUSICON_FAIL); updateButtons(true); return; } status("Downloading, please wait...", STATUSICON_RUNNING); return; }
void Player::Download() { QEventLoop loop; jSong song = songs->at(curr_track_num); QNetworkRequest req; req.setUrl(QUrl(song.url())); emit downloadStarted(); QNetworkAccessManager *nam = new QNetworkAccessManager(); QNetworkReply *reply = nam->get(req); // emit progress of downloading connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(emitDownloadProgress(qint64,qint64))); QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); emit downloadFinished(); // save file to folder 'music' if(!QDir("music").exists()) QDir().mkdir("music"); QString song_name = QDir().currentPath(); song_name.append("/music/"); song_name.append(song.artist()); song_name.append(" - "); song_name.append(song.title()); song_name.append(".mp3"); QFile out(song_name); out.open(QIODevice::WriteOnly); out.write(reply->readAll()); out.close(); }
bool WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to, QList<BodyMeasure> &data) { response = ""; QString strNokiaToken = ""; QString strNokiaRefreshToken = ""; QString access_token = ""; strNokiaToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_TOKEN).toString(); strNokiaRefreshToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString(); if(strNokiaRefreshToken.isEmpty() || strNokiaRefreshToken == "" || strNokiaRefreshToken == "0" ) { #ifdef Q_OS_MACX #define GC_PREF tr("Golden Cheetah->Preferences") #else #define GC_PREF tr("Tools->Options") #endif QString advise = QString(tr("Error fetching OAuth credentials. Please make sure to complete the Withings authorization procedure found under %1.")).arg(GC_PREF); QMessageBox oautherr(QMessageBox::Critical, tr("OAuth Error"), advise); oautherr.exec(); return false; } if(!strNokiaRefreshToken.isEmpty()) { printd("OAuth 2.0 API\n"); #if QT_VERSION > 0x050000 QUrlQuery postData; #else QUrl postData; #endif QString refresh_token = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString(); postData.addQueryItem("grant_type", "refresh_token"); postData.addQueryItem("client_id", GC_NOKIA_CLIENT_ID ); postData.addQueryItem("client_secret", GC_NOKIA_CLIENT_SECRET ); postData.addQueryItem("refresh_token", refresh_token ); QUrl url = QUrl( "https://account.withings.com/oauth2/token" ); emit downloadStarted(100); QNetworkRequest request(url); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); nam->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); printd("url %s %s\n", url.toString().toStdString().c_str(), postData.toString().toStdString().c_str()); // blocking request loop.exec(); // we go on after receiving the data in SLOT(onRequestReady(QByteArray)) printd("response: %s\n", response.toStdString().c_str()); if (response.contains("\"access_token\"", Qt::CaseInsensitive)) { QJsonParseError parseResult; QJsonDocument migrateJson = QJsonDocument::fromJson(response.toUtf8(), &parseResult); access_token = migrateJson.object()["access_token"].toString(); QString refresh_token = migrateJson.object()["refresh_token"].toString(); QString userid = QString("%1").arg(migrateJson.object()["userid"].toInt()); if (access_token != "") appsettings->setCValue(context->athlete->cyclist, GC_NOKIA_TOKEN, access_token); if (refresh_token != "") appsettings->setCValue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, refresh_token); if (userid != "") appsettings->setCValue(context->athlete->cyclist, GC_WIUSER, userid); #if QT_VERSION > 0x050000 QUrlQuery params; #else QUrl params; #endif emit downloadStarted(100); params.addQueryItem("action", "getmeas"); //params.addQueryItem("userid", userid); params.addQueryItem("access_token", access_token); params.addQueryItem("startdate", QString::number(from.toMSecsSinceEpoch()/1000)); params.addQueryItem("enddate", QString::number(to.toMSecsSinceEpoch()/1000)); QUrl url = QUrl( "https://wbsapi.withings.net/measure?" + params.toString() ); printd("URL: %s\n", url.url().toStdString().c_str()); QNetworkRequest request(url); //request.setRawHeader("Authorization", QString("Bearer %1").arg(access_token).toLatin1()); nam->get(request); emit downloadProgress(50); // blocking request loop.exec(); // we go on after receiving the data in SLOT(onRequestReady(QByteArray)) emit downloadEnded(100); } } printd("response: %s\n", response.toStdString().c_str()); QJsonParseError parseResult; if (response.contains("\"status\":0", Qt::CaseInsensitive)) { parseResult = parse(response, data); } else { QMessageBox oautherr(QMessageBox::Critical, tr("Error"), tr("There was an error during fetching. Please check the error description.")); oautherr.setDetailedText(response); // probably blank oautherr.exec(); return false; } if (QJsonParseError::NoError != parseResult.error) { QMessageBox oautherr(QMessageBox::Critical, tr("Error"), tr("Error parsing Withings API response. Please check the error description.")); QString errorStr = parseResult.errorString() + " at offset " + QString::number(parseResult.offset); error = errorStr.simplified(); oautherr.setDetailedText(error); oautherr.exec(); return false; }; return true; }
void BtInstallThread::slotDownloadStarted() { qDebug("BtInstallThread::slotDownloadStarted"); emit downloadStarted(m_module); }
void Utils::start() { if(quee.isEmpty()) { //qDebug() << "quee.isEmpty"; return; } RequestData data = quee.takeFirst(); QUrl url(data.url); QNetworkRequest req(url); //qDebug() << "Authorization: " << data.auth; //qDebug() << "Url: " << url.toEncoded(); req.setRawHeader("Authorization", data.auth.toAscii()); if(data.isDownload) { QNetworkReply* reply = _nam->get(req); connect(reply,SIGNAL(finished()),this,SLOT(downloadFinished())); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError))); cur_reply = reply; cur_folder = data.folder; cur_filename = data.filename; cur_size = data.size; isFinished = false; emit downloadStarted(data.filename); //qDebug() << "startDownload, filename: " << cur_filename; } else { QString filepath = data.folder + "/" + data.filename; //qDebug() << "filapath: " << filepath; cur_file = new QFile(filepath); if(cur_file->open(QIODevice::ReadOnly)) { QNetworkReply* reply = _nam->put(req,cur_file); connect(reply,SIGNAL(finished()),this,SLOT(uploadFinished())); connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(uploadProgress(qint64,qint64))); connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError))); cur_reply = reply; cur_folder = data.folder; cur_filename = data.filename; cur_size = cur_file->size(); isFinished = false; emit uploadStarted(data.filename); //qDebug() << "size:" << cur_file->size(); } else { qDebug() << "error: file not open!"; } } }