Beispiel #1
0
void ProfileController::checkReplyFeedback() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);

                QString directory = QDir::homePath() + QLatin1String("/HFRBlackData");
                QFile file(directory + "/cache.txt");
                if (file.open(QIODevice::WriteOnly)) {
                    file.write(buffer);
                    file.close();
                }

                parseFeedback(response);
            }
        } else {
            connectionTimedOut();
        }

        reply->deleteLater();
    }
}
void GoogleConnectController::checkReply() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);

                parse(response);
            }
        } else {
            qDebug() << "reply... " << reply->errorString();
            if(reply->errorString() == "Host  not found") {
                emit failedConnection();
            } else
                emit failedRenew();


        }

        reply->deleteLater();
    }

}
Beispiel #3
0
void LoginController::checkReply() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);

				// save cookies on disk
				CookieJar::get()->saveToDisk();
				saveUserName();
				emit complete();
			}
		} else {
			connectionTimedOut();
		}

	    reply->deleteLater();
	}

	if (response.trimmed().isEmpty()) {
		errorMessage();
    }
}
/**
 * Response: create GameMode
 */
void RatingsProcessor::responseCreateGameMode() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);

				requestGameModes();
			}
		} else {
			if (reply->error() < 100) {
				showError("Please check your internet connection");
				return;
			}
			response =
					tr("ResponseCreateGameMode. Error: %1 status: %2").arg(reply->errorString(),
							reply->attribute(
									QNetworkRequest::HttpStatusCodeAttribute).toString());
			if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()
					== "422") {
			}
		}
		reply->deleteLater();
	}
}
void SmileyPickerController::checkReply() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);
				m_Page = response;
				m_IndexSubpagesInFile.clear();
				m_IndexSubpagesInFile.append(0);
				m_lastId = 0;
				m_Mutex.lockForWrite();
				m_Pushing = true;
				m_Mutex.unlock();
				parse(response);
			}
		} else {
			response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
			qDebug() << response;
		}

		reply->deleteLater();
	}
}
//! [1]
void TwitterRequest::onTimelineReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    bool success = false;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer = reply->readAll();
                response = QString::fromUtf8(buffer);
                success = true;
            }
        } else {
            response =  tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
        }

        reply->deleteLater();
    }

    if (response.trimmed().isEmpty()) {
        response = tr("Twitter request failed. Check internet connection");
    }

    emit complete(response, success);
}
void WebResourceManager::checkReply() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				QImage qImage;
				qImage.loadFromData(reply->readAll());

				if (qImage.isNull()) {
					return;
				}

				QString diskPath = QDir::homePath() + "/Cache/"
								+ QString::number(qHash(reply->url().host())) + "_"
								+ QString::number(qHash(reply->url().path())) + ".PNG";

				if (qImage.save(diskPath)) {
						emit onImageReady(reply->url().toString(), diskPath);
				}

				// remove item from download queue
				m_EditQueue->lockForWrite();
				for(int i = 0 ; i < m_DownloadQueue->length() ; ++i)
					if(m_DownloadQueue->at(i).compare(reply->url().toString()) == 0) {
						m_DownloadQueue->removeAt(i);
						m_EditQueue->unlock();
						break;
					}
				m_EditQueue->unlock();
			}
		}
	}
}
/*
 * ForumRequest::onLoginReply()
 *
 * Callback handler for QNetworkReply finished() signal fired when requesting the currently logged in user.
 */
void Authenticator::onCurrentUserReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer = reply->readAll();
                response = QString::fromUtf8(buffer);
            }
        }

        reply->deleteLater();
    }

    if (response.contains("status=\"success\"", Qt::CaseInsensitive))
    {
    	int valStart = response.indexOf("<id type=\"int\">") + 15;
    	int valEnd = response.indexOf("</id>");
    	mUserId = "id/" + response.mid(valStart, (valEnd - valStart));
    }
    else
    {
    	mUserId = "";
    }
}
/**
 * Response: score average
 */
void RatingsProcessor::responseScoreAverage() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);

				bb::data::JsonDataAccess jda;
				QVariant vlist = jda.loadFromBuffer(response);

				QVariantMap list = vlist.toMap();

				float temp = list["value"].toFloat();

				m_ratValue = temp;

			}
		} else {
			m_ratValue = 0;
			if (reply->error() < 100) {
				showError("Please check your internet connection");
				return;
			}
			response =
					tr("Error: %1 status: %2").arg(reply->errorString(),
							reply->attribute(
									QNetworkRequest::HttpStatusCodeAttribute).toString());
			//another error
			showError("ResponseScoreAverage. QBlox Server Error = " + response);
			return;
		}
		reply->deleteLater();
	}

	emit ratValueChanged();

	emit imageChanged();

	m_label.clear();
	emit labelChanged();

	emit idRatChanged();

	m_loading = false;
	emit loadingChanged();

	m_urlImage = m_imageUrl;
	emit urlImageChanged();

	m_showing = true;
	emit showingChanged();

	emit ratValueChanged();

	return;
}
qint64 QNetworkReplyProto::bytesAvailable() const
{
  QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
  if (item)
    return item->bytesAvailable();
  return 0;
}
void PAAlternativeLauncher::manifestReadyRead()
{
	QNetworkReply *reply = dynamic_cast<QNetworkReply *>(sender());
	if(reply)
	{
		if(reply->error() == QNetworkReply::NoError)
		{
			qint64 bytes_available = reply->bytesAvailable();
			QByteArray input = reply->read(bytes_available);
			Q_ASSERT(input.size() == bytes_available);
			mZstream.next_in = (Bytef *)input.constData();
			mZstream.avail_in = bytes_available;

			uInt old_avail_out = mZstream.avail_out;
			int res = inflate(&mZstream, Z_SYNC_FLUSH);
			if(res != Z_OK && res != Z_STREAM_END)
			{
				reply->abort();
				info.warning("ZLib", mZstream.msg, false);
				return;
			}

			mManifestJson.write((const char *)mBuffer, old_avail_out - mZstream.avail_out);
			mZstream.avail_out = mBufferSize;
			mZstream.next_out = mBuffer;
			Q_ASSERT(mZstream.avail_in == 0);
		}
		else
		{
			reply->abort();
			info.critical(tr("Manifest"), tr("Error while getting manifest (1).\n%1").arg(reply->errorString()));
		}
	}
}
Beispiel #12
0
/**
 * PostHttp::onGetReply()
 *
 * SLOT
 * Read and return the http response from our http post request
 */
void PostHttp::onGetReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
            }
        } else {
            response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
            qDebug() << response;
        }

        reply->deleteLater();
    }

    if (response.trimmed().isEmpty()) {
        response = tr("Unable to retrieve post response");
    }

    emit complete(response);
}
Beispiel #13
0
	void ImageLoader::onReplyFinished() {
		QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

		QString response;
		if (reply) {
			if (reply->error() == QNetworkReply::NoError) {
				const int available = reply->bytesAvailable();
				if (available > 0) {
					const QByteArray data(reply->readAll());
					QImage image;
					image.loadFromData(data);
					image = image.scaled(120, 120, Qt::KeepAspectRatioByExpanding);
					const QImage swappedImage = image.rgbSwapped();
					const bb::ImageData imageData = bb::ImageData::fromPixels(swappedImage.bits(), bb::PixelFormat::RGBA_Premultiplied, swappedImage.width(), swappedImage.height(), swappedImage.bytesPerLine());

					_image = bb::cascades::Image(imageData);
					emit imageChanged();

					_loading = false;
					emit loadingChanged();

					reply->deleteLater();
					return;
				}
			}
			reply->deleteLater();
		}

		// TODO: handle error: set default icon
	}
/*
 * TwitterRequest::onTimelineReply()
 *
 * Callback handler for QNetworkReply finished() signal
 */
void TwitterRequest::onTimelineReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    QString response;
    bool success = false;
    if (reply)
    {
        if (reply->error() == QNetworkReply::NoError)
        {
            int available = reply->bytesAvailable();
            if (available > 0)
            {
                int bufSize = sizeof(char) * available + sizeof(char);
                QByteArray buffer(bufSize, 0);
                int read = reply->read(buffer.data(), available);
                response = QString::fromUtf8(buffer);
                success = true;
            }
        }
        else
        {
            response =  QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
            qDebug() << response;
        }
        reply->deleteLater();
    }
    if (response.trimmed().isEmpty())
    {
        response = "Twitter request failed. Check internet connection";
        qDebug() << response;
    }
    emit complete(response, success);
}
void QBNetwork::onRequestUsers() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
	if (reply) {
		const int available = reply->bytesAvailable();
		if (available > 0) {
			const QByteArray buffer(reply->readAll());
			QString response = QString::fromUtf8(buffer);

			JsonDataAccess jda;
			QVariant qtData = jda.loadFromBuffer(response);
			if (jda.hasError()) {
				const DataAccessError err = jda.error();
				emit error(
						tr("Error converting JSON data: %1").arg(
								err.errorMessage()));
			} else {
				emit usersReceived(response);
			}
		} else {
			emit error("Wrong reply for request users request");
		}
		reply->deleteLater();
	} else {
		emit error("Wrong reply for request users request");
	}

	disconnectFromAll();
}
/**
 * RatingsProcessor::onReplyFinished()
 *
 * Handler for the signal indicating the response for the previous network request.
 *
 * If the result was a success, it will start the thread of constructing the QImage object.
 */
void RatingsProcessor::onReplyFinished() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {

				const QByteArray data(reply->readAll());

				// Setup the image processing thread
				ImageProcessor *imageProcessor = new ImageProcessor(data);

				/*
				 * Invoke our onProcessingFinished slot after the processing has finished.
				 * Since imageProcessor and 'this' are located in different threads we use 'QueuedConnection' to
				 * allow a cross-thread boundary invocation. In this case the QImage parameter is copied in a thread-safe way
				 * from the worker thread to the main thread.
				 */
				connect(imageProcessor, SIGNAL(finished(QImage)), this,
						SLOT(onImageProcessingFinished(QImage)),
						Qt::QueuedConnection);

				imageProcessor->start();
			}
		} else {
			if (reply->error() < 100) {
				m_loading = false;
				emit loadingChanged();
				showError("Please check your internet connection");
				return;
			}
			m_label =
					tr("Error: %1 status: %2").arg(reply->errorString(),
							reply->attribute(
									QNetworkRequest::HttpStatusCodeAttribute).toString());

			emit labelChanged();

			m_loading = false;
			emit loadingChanged();

			emit ratValueChanged();
		}

		reply->deleteLater();
	} else {
		m_label = tr("Download failed.");

		emit labelChanged();

		m_loading = false;
		emit loadingChanged();

		emit ratValueChanged();
	}
}
void QBNetwork::onRequestSessionRegister() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		const int available = reply->bytesAvailable();
		if (available > 0) {
			const QByteArray buffer(reply->readAll());
			response = QString::fromUtf8(buffer);

			JsonDataAccess jda;
			QVariant qtData = jda.loadFromBuffer(response);
			if (jda.hasError()) {
				const DataAccessError err = jda.error();
				emit error(
						tr("Error converting JSON data: %1").arg(
								err.errorMessage()));
			} else {
				const QVariantMap object = qtData.value<QVariantMap>();
				QMapIterator<QString, QVariant> it(object);
				while (it.hasNext()) {
					it.next();
					if (it.key() == "session") {
						QVariantMap sessObject = it.value().toMap();
						QMapIterator<QString, QVariant> sit(sessObject);
						while (sit.hasNext()) {
							sit.next();
							if (sit.key() == "user_id") {
								m_userId = sit.value().toString();
							}
							if (sit.key() == "token") {
								m_token = sit.value().toString();
							}
						}
					}
				}

				if (m_token != NULL) {
					//register after we have session
					emit sessionEstablished();
					registerNewUser();
				} else {
					emit error("Wrong reply for register session request");
				}
			}
		} else {
			emit error("Wrong reply for register session request");
		}
		reply->deleteLater();
	} else {
		emit error("Wrong reply for register session request");
	}

	disconnectFromAll();
}
Beispiel #18
0
void ImageLoader::onReplyFinished()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray data(reply->readAll());

                // Setup the image processing thread
                ImageProcessor *imageProcessor = new ImageProcessor(data);
                m_thread = new QThread(this);

                // Move the image processor to the worker thread
                imageProcessor->moveToThread(m_thread);

                // Invoke ImageProcessor's start() slot as soon as the worker thread has started
                connect(m_thread, SIGNAL(started()), imageProcessor, SLOT(start()));

                // Delete the worker thread automatically after it has finished
                connect(m_thread, SIGNAL(finished()), m_thread, SLOT(deleteLater()));

                /*
                 * Invoke our onProcessingFinished slot after the processing has finished.
                 * Since imageProcessor and 'this' are located in different threads we use 'QueuedConnection' to
                 * allow a cross-thread boundary invocation. In this case the QImage parameter is copied in a thread-safe way
                 * from the worker thread to the main thread.
                 */
                connect(imageProcessor, SIGNAL(finished(QImage)), this, SLOT(onImageProcessingFinished(QImage)), Qt::QueuedConnection);

                // Terminate the thread after the processing has finished
                connect(imageProcessor, SIGNAL(finished(QImage)), m_thread, SLOT(quit()));

                m_thread->start();
            }
        } else {
            m_label = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
            emit labelChanged();

            m_loading = false;
            emit loadingChanged();
        }

        reply->deleteLater();
    } else {
        m_label = tr("Download failed. Check internet connection");
        emit labelChanged();

        m_loading = false;
        emit loadingChanged();
    }
}
Beispiel #19
0
void QWebdav::replyReadyRead()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
    if (reply->bytesAvailable() < 256000)
        return;

    QIODevice* dataIO = m_inDataDevices.value(reply, 0);
    if(dataIO == 0)
        return;
    dataIO->write(reply->readAll());
}
Beispiel #20
0
void ApplicationUI::onReadReply()
{
    // We got a reply!!!

    qDebug() << "We got a reply!!!";

    // Retrieve the reply
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    // If reply exists
    if (reply) {
        // If the reply ain't an error reply
        if (reply->error() == QNetworkReply::NoError) {
            // If the reply length is more than 0 (if it's not empty)
            const int available = reply->bytesAvailable();
            if (available > 0) {
                // Save the reply to a variable
                const QByteArray buffer(reply->readAll());

                // Print the variable to the console, this is for debugging only
                qDebug() << "Buffer :" << buffer;

                // Retrieve the file name
                QString fileName = reply->url().toString().split("/").last().remove("/");

                // Create the new file and writes it
                QFile thisFile("/accounts/1000/shared/documents/" + (fileName.isEmpty() ? "downloadApp.file" : fileName));

                // Print the file path to the console, this is for debugging only
                qDebug() << "File name :" << thisFile.fileName();

                // Try to open the file
                if (thisFile.open(QIODevice::ReadWrite))
                {
                    qDebug() << "File was opened, writing to file";
                    // Write to the file
                    thisFile.write(buffer);
                    thisFile.flush();
                    thisFile.close();

                    // Warn the user that the file is now in the Documents folder
                    SystemToast* pToast = new SystemToast();
                    pToast->setBody(thisFile.fileName().split("/").last() + " saved to your Documents folder");
                    pToast->setPosition(SystemUiPosition::MiddleCenter);
                    pToast->show();
                }
                // Memory management
                thisFile.deleteLater();
            }
        } // end of : if (reply->error() == QNetworkReply::NoError)
        // Memory management
        reply->deleteLater();
    }  // end of : if (reply)
}
void KVNetworkAccessManager::trackedGETReadyRead()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
	bool ok;
	/*qint64 length = */reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(&ok);

	// Don't report progress for replies without a Content-Length
	if(ok)
	{
		trackedGETProgress += reply->bytesAvailable();
		emit trackedProgressChanged(trackedGETProgress, trackedGETTotalSize);
	}
}
void CommandDownloadFile::readyRead()
{
    Q_D(CommandDownloadFile);

    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    Q_ASSERT(reply);
    if (!reply)
        return;

    qint64 sz = reply->bytesAvailable();
    QByteArray ba = reply->read(sz);

    QIODevice* out = d->out;
    out->write(ba);
}
void QBNetwork::onRequestLogin() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);
				JsonDataAccess jda;
				QVariant qtData = jda.loadFromBuffer(response);
				if (jda.hasError()) {
					const DataAccessError err = jda.error();
					showError(
							tr("Error converting JSON data: %1").arg(
									err.errorMessage()));
				} else {
					const QVariantMap object = qtData.value<QVariantMap>();
					QMapIterator<QString, QVariant> it(object);
					while (it.hasNext()) {
						it.next();
						if (it.key() == "user") {
							QVariantMap sessObject = it.value().toMap();
							QMapIterator<QString, QVariant> sit(sessObject);
							while (sit.hasNext()) {
								sit.next();
								if (sit.key() == "id") {
									break;
								}
							}
						}
					}
				}
			}
		} else {
			if (reply->error() < 100) {
				showError("Please check your internet connection");
				return;
			}
			response =
					tr("Error: %1 status: %2").arg(reply->errorString(),
							reply->attribute(
									QNetworkRequest::HttpStatusCodeAttribute).toString());
		}
		reply->deleteLater();
	}
	requestUsers();
}
Beispiel #24
0
void BugReportController::checkReplyIssues() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
                parseIssues(response);
            }
        }

        reply->deleteLater();
    }
}
Beispiel #25
0
/**
 * Loads Server information.
 *
 * @brief ServerInfoClient::loadServerInfo
 */
bool ServerInfoClient::loadServerInfo(){
    QString url = baseURL();

    QUrl _url(url);
    QNetworkRequest request( _url );

    prepareRequest(request);
    request.setRawHeader(QByteArray("accept"), QByteArray("application/json"));

    QEventLoop loop;

    QTimer timeoutTimer;
    timeoutTimer.setSingleShot(true);
    connect(&timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));

    //REST request
    QNetworkReply *reply = manager->get( request );
    QObject::connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));

    //Wait 2000 miliseconds
    timeoutTimer.start(2000);

    loop.exec();

    if(reply->bytesAvailable() == 0)
    {        
        return false;
    }

    QByteArray arr = reply->readAll();

    QJsonDocument jsonResponse = QJsonDocument::fromJson(arr);
    QJsonObject jsonObject = jsonResponse.object();

    _initializeDate = jsonObject["initializeDate"].toString().toLongLong();
    _serverBootTime = jsonObject["serverBootTime"].toString().toLongLong();
    _currentServerTime = jsonObject["currentServerTime"].toString().toLongLong();
    _icatEnabled = jsonObject["icatEnabled"].toString();
    _relVersion =  jsonObject["relVersion"].toString();
    _apiVersion =  jsonObject["apiVersion"].toString();
    _rodsZone =  jsonObject["rodsZone"].toString();

    return true;

}
Beispiel #26
0
void Snap2ChatAPISimple::onComplete()
{
	QNetworkReply* reply 	= qobject_cast<QNetworkReply*>(sender());
	int status 				= reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
	QString reason 			= reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();

	QString response;

	if (reply)
	{
		if (reply->error() == QNetworkReply::NoError)
		{
			const int available = reply->bytesAvailable();

			if (available > 0)
			{
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);
			}
		}
		else
		{
			response = "error";
		}

		reply->deleteLater();
	}

	if (response.trimmed().isEmpty())
	{
		response = "error";
	}

	if(QString::number(status) == "200")
	{
		response = ((response.length() > 0 && response != "error") ? response : QString::number(status));
	}
	else
	{
		response = QString::number(status);
	}

	emit complete(response, QString::number(status), reply->property("endpoint").toString());
}
/*
 * ForumRequest::onLoginReply()
 *
 * Callback handler for QNetworkReply finished() signal fired after login.
 */
void Authenticator::onLoginReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer = reply->readAll();
                response = QString::fromUtf8(buffer);
            }
        }

        reply->deleteLater();
    }

    if (response.contains("status=\"success\"", Qt::CaseInsensitive))
    {
    	qDebug() << "Auth success!";
    	int valStart = response.indexOf("<value type=\"string\">") + 21;
    	int valEnd = response.indexOf("</value>");
		mSessionKey = response.mid(valStart, (valEnd - valStart));

    	mAuthenticated = true;

    	getUserId();

        bb::system::SystemToast* toast = new bb::system::SystemToast(this);
        toast->setBody(tr("You are now logged into the forum."));
        toast->show();
    }
    else
    {
    	qDebug() << "Auth failed!";
    	mAuthenticated = false;
    	bb::system::SystemToast* toast = new bb::system::SystemToast(this);
		toast->setBody(tr("Failed to log into the forum."));
		toast->show();
    }

    mAuthenticationInProgress = false;
    emit authenticationChanged(mAuthenticated);
}
void PrivateMessageController::checkMessageDeleted() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
                qDebug() << response;
            }
        } else {
            connectionTimedOut();
        }

        reply->deleteLater();
    }
}
void HeadlessApplication::checkReplyFav() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
                if(checkErrorMessage(response))
                    parseFav(response);

            }
        }

        reply->deleteLater();
    }
}
void ExploreCategoryController::checkReply() {
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray buffer(reply->readAll());
				response = QString::fromUtf8(buffer);
				parse(response);
			}
		} else {
			response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
			qDebug() << response;
		}

		reply->deleteLater();
	}
}