bool CWizDocumentStatusCheckThread::checkDocumentEditStatus(const QString& strKbGUID, const QString& strGUID) { QString strRequestUrl = WizFormatString4(_T("%1/get?obj_id=%2/%3&t=%4"), WizKMGetDocumentEditStatusURL(), strKbGUID, strGUID, ::WizIntToStr(GetTickCount())); downloadData(strRequestUrl); return true; }
std::unique_ptr<HeightData> downloadHeightmapTile(const std::string& url, const Tile& tile, float extrusionScale) { std::stringstream out; if (downloadData(out, url)) { unsigned char* pixels; int width, height, comp; // Decode texture PNG const unsigned char* pngData = reinterpret_cast<const unsigned char*>(out.str().c_str()); pixels = stbi_load_from_memory(pngData, out.str().length(), &width, &height, &comp, STBI_rgb_alpha); // printf("Texture data %d width, %d height, %d comp\n", width, height, comp); if (comp != STBI_rgb_alpha) { printf("Failed to decompress PNG file\n"); return nullptr; } std::unique_ptr<HeightData> data = std::unique_ptr<HeightData>(new HeightData()); data->elevation.resize(height); for (int i = 0; i < height; ++i) { data->elevation[i].resize(width); } data->width = width; data->height = height; unsigned char* pixel = pixels; for (size_t i = 0; i < width * height; i++, pixel += 4) { float red = *(pixel+0); float green = *(pixel+1); float blue = *(pixel+2); // Decode the elevation packed data from color component float elevation = (red * 256 + green + blue / 256) - 32768; int y = i / height; int x = i % width; assert(x >= 0 && x <= width && y >= 0 && y <= height); data->elevation[x][y] = elevation * extrusionScale; } return data; } return nullptr; }
std::unique_ptr<TileData> downloadTile(const std::string& url, const Tile& tile) { std::stringstream out; if (downloadData(out, url)) { // parse written data into a JSON object rapidjson::Document doc; doc.Parse(out.str().c_str()); if (doc.HasParseError()) { printf("Error parsing tile\n"); return nullptr; } std::unique_ptr<TileData> data = std::unique_ptr<TileData>(new TileData()); for (auto layer = doc.MemberBegin(); layer != doc.MemberEnd(); ++layer) { data->layers.emplace_back(std::string(layer->name.GetString())); GeoJson::extractLayer(layer->value, data->layers.back(), tile); } return data; } return nullptr; }
AddRecording::AddRecording(int id,QString *filter,QWidget *parent) : QDialog(parent,"",true,Qt::WStyle_Customize|Qt::WStyle_DialogBorder) { setCaption(""); // // Fix the Window Size // setMinimumWidth(sizeHint().width()); setMaximumWidth(sizeHint().width()); setMinimumHeight(sizeHint().height()); setMaximumHeight(sizeHint().height()); // // Generate Fonts // QFont button_font=QFont("Helvetica",12,QFont::Bold); button_font.setPixelSize(12); QFont label_font=QFont("Helvetica",12,QFont::Bold); label_font.setPixelSize(12); QFont day_font=QFont("Helvetica",12,QFont::Normal); day_font.setPixelSize(12); add_id=id; add_filter=filter; // // Title Label // QLabel *label=new QLabel(tr("Schedule a:"),this,"title_label"); label->setGeometry(0,0,sizeHint().width(),30); label->setFont(label_font); label->setAlignment(AlignCenter); // // Recording Button // QPushButton *button=new QPushButton(this,"recording_button"); button->setGeometry(10,30,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Recording")); button->setDisabled(true); QString sql=QString("select CHANNEL from DECKS \ where (CARD_NUMBER>=0)&&(CHANNEL>0)&&(CHANNEL<=9)"); RDSqlQuery *q=new RDSqlQuery(sql); if(q->first()) { button->setEnabled(true); } delete q; connect(button,SIGNAL(clicked()),this,SLOT(recordingData())); // // Playout Button // button=new QPushButton(this,"playout_button"); button->setGeometry(10,80,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Playout")); button->setDisabled(true); sql=QString("select CHANNEL from DECKS where (CARD_NUMBER>=0)&&")+ "(PORT_NUMBER>=0)&&(CHANNEL>128)&&(CHANNEL<=137)"; q=new RDSqlQuery(sql); if(q->first()) { button->setEnabled(true); } delete q; connect(button,SIGNAL(clicked()),this,SLOT(playoutData())); // // Download Event Button // button=new QPushButton(this,"download_button"); button->setGeometry(10,130,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Download")); connect(button,SIGNAL(clicked()),this,SLOT(downloadData())); // // Upload Event Button // button=new QPushButton(this,"upload_button"); button->setGeometry(10,180,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Upload")); connect(button,SIGNAL(clicked()),this,SLOT(uploadData())); // // Macro Event Cart Button // button=new QPushButton(this,"macro_button"); button->setGeometry(10,230,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Macro Cart")); connect(button,SIGNAL(clicked()),this,SLOT(macroData())); // // Switch Event Cart Button // button=new QPushButton(this,"switch_button"); button->setGeometry(10,280,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Switch Event")); connect(button,SIGNAL(clicked()),this,SLOT(switchData())); // // Cancel Button // button=new QPushButton(this,"cancel_button"); button->setGeometry(10,350,sizeHint().width()-20,50); button->setFont(button_font); button->setText(tr("&Cancel")); button->setDefault(true); connect(button,SIGNAL(clicked()),this,SLOT(cancelData())); }
void QNetworkAccessHttpBackend::postRequest() { QThread *thread = 0; if (isSynchronous()) { // A synchronous HTTP request uses its own thread thread = new QThread(); QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); } else if (!manager->httpThread) { // We use the manager-global thread. // At some point we could switch to having multiple threads if it makes sense. manager->httpThread = new QThread(); QObject::connect(manager->httpThread, SIGNAL(finished()), manager->httpThread, SLOT(deleteLater())); manager->httpThread->start(); #ifndef QT_NO_NETWORKPROXY qRegisterMetaType<QNetworkProxy>("QNetworkProxy"); #endif #ifndef QT_NO_OPENSSL qRegisterMetaType<QList<QSslError> >("QList<QSslError>"); qRegisterMetaType<QSslConfiguration>("QSslConfiguration"); #endif qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >("QList<QPair<QByteArray,QByteArray> >"); qRegisterMetaType<QHttpNetworkRequest>("QHttpNetworkRequest"); qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); qRegisterMetaType<QSharedPointer<char> >("QSharedPointer<char>"); thread = manager->httpThread; } else { // Asynchronous request, thread already exists thread = manager->httpThread; } QUrl url = request().url(); httpRequest.setUrl(url); bool ssl = url.scheme().toLower() == QLatin1String("https"); setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, ssl); httpRequest.setSsl(ssl); #ifndef QT_NO_NETWORKPROXY QNetworkProxy transparentProxy, cacheProxy; foreach (const QNetworkProxy &p, proxyList()) { // use the first proxy that works // for non-encrypted connections, any transparent or HTTP proxy // for encrypted, only transparent proxies if (!ssl && (p.capabilities() & QNetworkProxy::CachingCapability) && (p.type() == QNetworkProxy::HttpProxy || p.type() == QNetworkProxy::HttpCachingProxy)) { cacheProxy = p; transparentProxy = QNetworkProxy::NoProxy; break; } if (p.isTransparentProxy()) { transparentProxy = p; cacheProxy = QNetworkProxy::NoProxy; break; } } // check if at least one of the proxies if (transparentProxy.type() == QNetworkProxy::DefaultProxy && cacheProxy.type() == QNetworkProxy::DefaultProxy) { // unsuitable proxies QMetaObject::invokeMethod(this, "error", isSynchronous() ? Qt::DirectConnection : Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProxyNotFoundError), Q_ARG(QString, tr("No suitable proxy found"))); QMetaObject::invokeMethod(this, "finished", isSynchronous() ? Qt::DirectConnection : Qt::QueuedConnection); return; } #endif bool loadedFromCache = false; httpRequest.setPriority(convert(request().priority())); switch (operation()) { case QNetworkAccessManager::GetOperation: httpRequest.setOperation(QHttpNetworkRequest::Get); loadedFromCache = loadFromCacheIfAllowed(httpRequest); break; case QNetworkAccessManager::HeadOperation: httpRequest.setOperation(QHttpNetworkRequest::Head); loadedFromCache = loadFromCacheIfAllowed(httpRequest); break; case QNetworkAccessManager::PostOperation: invalidateCache(); httpRequest.setOperation(QHttpNetworkRequest::Post); createUploadByteDevice(); break; case QNetworkAccessManager::PutOperation: invalidateCache(); httpRequest.setOperation(QHttpNetworkRequest::Put); createUploadByteDevice(); break; case QNetworkAccessManager::DeleteOperation: invalidateCache(); httpRequest.setOperation(QHttpNetworkRequest::Delete); break; case QNetworkAccessManager::CustomOperation: invalidateCache(); // for safety reasons, we don't know what the operation does httpRequest.setOperation(QHttpNetworkRequest::Custom); createUploadByteDevice(); httpRequest.setCustomVerb(request().attribute( QNetworkRequest::CustomVerbAttribute).toByteArray()); break; default: break; // can't happen } if (loadedFromCache) { // commented this out since it will be called later anyway // by copyFinished() //QNetworkAccessBackend::finished(); return; // no need to send the request! :) } QList<QByteArray> headers = request().rawHeaderList(); if (resumeOffset != 0) { if (headers.contains("Range")) { // Need to adjust resume offset for user specified range headers.removeOne("Range"); // We've already verified that requestRange starts with "bytes=", see canResume. QByteArray requestRange = request().rawHeader("Range").mid(6); int index = requestRange.indexOf('-'); quint64 requestStartOffset = requestRange.left(index).toULongLong(); quint64 requestEndOffset = requestRange.mid(index + 1).toULongLong(); requestRange = "bytes=" + QByteArray::number(resumeOffset + requestStartOffset) + '-' + QByteArray::number(requestEndOffset); httpRequest.setHeaderField("Range", requestRange); } else { httpRequest.setHeaderField("Range", "bytes=" + QByteArray::number(resumeOffset) + '-'); } } foreach (const QByteArray &header, headers) httpRequest.setHeaderField(header, request().rawHeader(header)); if (request().attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool() == true) httpRequest.setPipeliningAllowed(true); if (static_cast<QNetworkRequest::LoadControl> (request().attribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Manual) httpRequest.setWithCredentials(false); // Create the HTTP thread delegate QHttpThreadDelegate *delegate = new QHttpThreadDelegate; #ifndef QT_NO_BEARERMANAGEMENT QVariant v(property("_q_networksession")); if (v.isValid()) delegate->networkSession = qvariant_cast<QSharedPointer<QNetworkSession> >(v); #endif // For the synchronous HTTP, this is the normal way the delegate gets deleted // For the asynchronous HTTP this is a safety measure, the delegate deletes itself when HTTP is finished connect(thread, SIGNAL(finished()), delegate, SLOT(deleteLater())); // Set the properties it needs delegate->httpRequest = httpRequest; #ifndef QT_NO_NETWORKPROXY delegate->cacheProxy = cacheProxy; delegate->transparentProxy = transparentProxy; #endif delegate->ssl = ssl; #ifndef QT_NO_OPENSSL if (ssl) delegate->incomingSslConfiguration = request().sslConfiguration(); #endif // Do we use synchronous HTTP? delegate->synchronous = isSynchronous(); // The authentication manager is used to avoid the BlockingQueuedConnection communication // from HTTP thread to user thread in some cases. delegate->authenticationManager = manager->authenticationManager; if (!isSynchronous()) { // Tell our zerocopy policy to the delegate delegate->downloadBufferMaximumSize = request().attribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute).toLongLong(); // These atomic integers are used for signal compression delegate->pendingDownloadData = pendingDownloadDataEmissions; delegate->pendingDownloadProgress = pendingDownloadProgressEmissions; // Connect the signals of the delegate to us connect(delegate, SIGNAL(downloadData(QByteArray)), this, SLOT(replyDownloadData(QByteArray)), Qt::QueuedConnection); connect(delegate, SIGNAL(downloadFinished()), this, SLOT(replyFinished()), Qt::QueuedConnection); connect(delegate, SIGNAL(downloadMetaData(QList<QPair<QByteArray,QByteArray> >,int,QString,bool,QSharedPointer<char>,qint64)), this, SLOT(replyDownloadMetaData(QList<QPair<QByteArray,QByteArray> >,int,QString,bool,QSharedPointer<char>,qint64)), Qt::QueuedConnection); connect(delegate, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(replyDownloadProgressSlot(qint64,qint64)), Qt::QueuedConnection); connect(delegate, SIGNAL(error(QNetworkReply::NetworkError,QString)), this, SLOT(httpError(QNetworkReply::NetworkError, const QString)), Qt::QueuedConnection); #ifndef QT_NO_OPENSSL connect(delegate, SIGNAL(sslConfigurationChanged(QSslConfiguration)), this, SLOT(replySslConfigurationChanged(QSslConfiguration)), Qt::QueuedConnection); #endif // Those need to report back, therefire BlockingQueuedConnection connect(delegate, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), this, SLOT(httpAuthenticationRequired(QHttpNetworkRequest,QAuthenticator*)), Qt::BlockingQueuedConnection); #ifndef QT_NO_NETWORKPROXY connect (delegate, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), Qt::BlockingQueuedConnection); #endif #ifndef QT_NO_OPENSSL connect(delegate, SIGNAL(sslErrors(QList<QSslError>,bool*,QList<QSslError>*)), this, SLOT(replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *)), Qt::BlockingQueuedConnection); #endif // This signal we will use to start the request. connect(this, SIGNAL(startHttpRequest()), delegate, SLOT(startRequest())); connect(this, SIGNAL(abortHttpRequest()), delegate, SLOT(abortRequest())); // To throttle the connection. QObject::connect(this, SIGNAL(readBufferSizeChanged(qint64)), delegate, SLOT(readBufferSizeChanged(qint64))); QObject::connect(this, SIGNAL(readBufferFreed(qint64)), delegate, SLOT(readBufferFreed(qint64))); if (uploadByteDevice) { QNonContiguousByteDeviceThreadForwardImpl *forwardUploadDevice = new QNonContiguousByteDeviceThreadForwardImpl(uploadByteDevice->atEnd(), uploadByteDevice->size()); if (uploadByteDevice->isResetDisabled()) forwardUploadDevice->disableReset(); forwardUploadDevice->setParent(delegate); // needed to make sure it is moved on moveToThread() delegate->httpRequest.setUploadByteDevice(forwardUploadDevice); // From main thread to user thread: QObject::connect(this, SIGNAL(haveUploadData(QByteArray, bool, qint64)), forwardUploadDevice, SLOT(haveDataSlot(QByteArray, bool, qint64)), Qt::QueuedConnection); QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), forwardUploadDevice, SIGNAL(readyRead()), Qt::QueuedConnection); // From http thread to user thread: QObject::connect(forwardUploadDevice, SIGNAL(wantData(qint64)), this, SLOT(wantUploadDataSlot(qint64))); QObject::connect(forwardUploadDevice, SIGNAL(processedData(qint64)), this, SLOT(sentUploadDataSlot(qint64))); connect(forwardUploadDevice, SIGNAL(resetData(bool*)), this, SLOT(resetUploadDataSlot(bool*)), Qt::BlockingQueuedConnection); // this is the only one with BlockingQueued! } } else if (isSynchronous()) {