コード例 #1
0
void QBNetwork::login(QString userName, QString userPassword) {
	qDebug() << "login userName " << userName << " userPassword " << userPassword;
	setLoadAction(true);
	QBLOX_LOGIN = userName;
	QBLOX_PASSWORD = userPassword;

	const QUrl url(QBLOX_API_SERVER + "session.json");

	QString timestamp = QString::number(QBUtils::getTimestampUTCMs());

	QString postParam = "application_id=";
	postParam += QBLOX_APP_ID;
	postParam += "&auth_key=";
	postParam += QBLOX_AUTH_KEY;
	postParam += "&nonce=";
	postParam += timestamp;
	postParam += "&timestamp=";
	postParam += timestamp;
	postParam += "&user[login]=";
	postParam += QBLOX_LOGIN;
	postParam += "&user[password]=";
	postParam += QBLOX_PASSWORD;

	QString signature = hmac_sha1(postParam, QBLOX_AUTH_SECRET);

	QVariantMap qUser;
	qUser["login"] = QBLOX_LOGIN;
	qUser["password"] = QBLOX_PASSWORD;

	QVariantMap qSettings;
	qSettings["application_id"] = QBLOX_APP_ID;
	qSettings["auth_key"] = QBLOX_AUTH_KEY;
	qSettings["nonce"] = timestamp;
	qSettings["timestamp"] = timestamp;
	qSettings["signature"] = signature;
	qSettings["user"] = qUser;

	QVariant setData = QVariant(qSettings);
	QString outRequest = "";
	JsonDataAccess jda;
	jda.saveToBuffer(setData, &outRequest);

	QNetworkRequest request(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
	request.setRawHeader("QuickBlox-REST-API-Version", "0.1.0");

	QNetworkReply* reply = m_networkAccessManager->post(request,
			outRequest.toAscii());
	connect(reply, SIGNAL(finished()), this, SLOT(onRequestSessionWithLogin()));
	connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
			SLOT(onNetworkError(QNetworkReply::NetworkError)));
}
コード例 #2
0
ファイル: app.cpp プロジェクト: 13natty/Cascades-Samples
//! [2]
void App::convertQtToJson()
{
    const QString result = tr("Converting ... ");
    setResult(result);
    setRhsTitleAndText(mRhsDefaultTitle, "");

    QString jsonBuffer;
    JsonDataAccess jda;
    jda.saveToBuffer(mQtData, &jsonBuffer);
    if (jda.hasError()) {
        const DataAccessError err = jda.error();
        const QString errorMsg = tr("Error converting Qt data to JSON: %1").arg(err.errorMessage());
        setResultAndState(errorMsg, QtDisplayed);
    } else {
        setRhsTitleAndText(tr("JSON Data from Qt"), jsonBuffer);
        setResultAndState(result + tr("Success"), ReadyToWrite);
    }
}
コード例 #3
0
/**
 * Registration the new user
 */
void QBNetwork::registrationNewUser() {
	if (m_token == "") {
		return;
	}
	const QUrl url(QBLOX_API_SERVER + "users.json");

	QString timestamp = getTimestampUTC();

	QString postParam = "&user[login]=";
	postParam += QBLOX_LOGIN;
	postParam += "&user[password]=";
	postParam += QBLOX_PASSWORD;
	postParam += "&user[tag_list]=";
	postParam += "man,UsersBB10";
	postParam += "&token=";
	postParam += m_token;

	QString signature = hmac_sha1(postParam, QBLOX_AUTH_SECRET);

	QVariantMap qUser;
	qUser["login"] = QBLOX_LOGIN;
	qUser["password"] = QBLOX_PASSWORD;
	qUser["tag_list"] = "UsersBB10";

	QVariantMap qSettings;
	qSettings["user"] = qUser;
	qSettings["token"] = m_token;

	QVariant setData = QVariant(qSettings);
	QString outRequest = "";
	JsonDataAccess jda;
	jda.saveToBuffer(setData, &outRequest);

	QNetworkRequest request(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
	request.setRawHeader("QuickBlox-REST-API-Version", "0.1.0");

	QNetworkReply* reply = m_networkAccessManager->post(request,
			outRequest.toAscii());
	connect(reply, SIGNAL(finished()), this, SLOT(onRegistrationNewUser()));
}
コード例 #4
0
/**
 * Request session for registration
 */
void QBNetwork::requestSessionRegister() {
	const QUrl url(QBLOX_API_SERVER + "session.json");

	QString timestamp = getTimestampUTC();

	QString postParam = "application_id=";
	postParam += QBLOX_APP_ID;
	postParam += "&auth_key=";
	postParam += QBLOX_AUTH_KEY;
	postParam += "&nonce=";
	postParam += timestamp;
	postParam += "&timestamp=";
	postParam += timestamp;

	QString signature = hmac_sha1(postParam, QBLOX_AUTH_SECRET);

	QVariantMap qUser;
	qUser["login"] = QBLOX_LOGIN;
	qUser["password"] = QBLOX_PASSWORD;

	QVariantMap qSettings;
	qSettings["application_id"] = QBLOX_APP_ID;
	qSettings["auth_key"] = QBLOX_AUTH_KEY;
	qSettings["nonce"] = timestamp;
	qSettings["timestamp"] = timestamp;
	qSettings["signature"] = signature;

	QVariant setData = QVariant(qSettings);
	QString outRequest = "";
	JsonDataAccess jda;
	jda.saveToBuffer(setData, &outRequest);

	QNetworkRequest request(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
	request.setRawHeader("QuickBlox-REST-API-Version", "0.1.0");

	QNetworkReply* reply = m_networkAccessManager->post(request,
			outRequest.toAscii());
	connect(reply, SIGNAL(finished()), this, SLOT(onRequestSessionRegister()));
}
コード例 #5
0
/**
 * Request: create GameMode
 */
void RatingsProcessor::requestCreateGameMode(QString title) {
	const QUrl url(QBLOX_API_SERVER + "gamemodes.json");

	QVariantMap param;
	param["title"] = title;

	QVariantMap qSettings;
	qSettings["gamemode"] = param;

	QVariant setData = QVariant(qSettings);
	QString outRequest = "";
	JsonDataAccess jda;
	jda.saveToBuffer(setData, &outRequest);

	QNetworkRequest request(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
	request.setRawHeader("QuickBlox-REST-API-Version", "0.1.0");
	request.setRawHeader("QB-Token", QBAuth::m_token.toUtf8());
	QNetworkReply* reply = m_networkAccessManager->post(request,
			outRequest.toAscii());
	connect(reply, SIGNAL(finished()), this, SLOT(responseCreateGameMode()));
}
コード例 #6
0
ファイル: applicationui.cpp プロジェクト: Jendorski/HFRBlack
void ApplicationUI::onInvoked(const bb::system::InvokeRequest& request) {
    qDebug() << "invoke!" << request.action();

    if(request.action().compare("bb.action.VIEW") == 0 || request.action().compare("bb.action.OPEN") == 0) {
//         qDebug() << "HubIntegration: onInvoked: view item: " << request.data();

         JsonDataAccess jda;

         QVariantMap objectMap = (jda.loadFromBuffer(request.data())).toMap();
         QVariantMap itemMap = objectMap["attributes"].toMap();


         QVariantList items = m_Settings.value("hub/items").toList();

         QString urlToOpen;
         for(int index = 0; index < items.size(); index++) {
             QVariantMap item = items.at(index).toMap();
             QString sourceId = item["messageid"].toString();

              if (item["sourceId"].toString() == itemMap["messageid"].toString() ||
                  item["sourceId"].toString() == itemMap["sourceId"].toString()) {

                  qDebug() << "FOUD!";
                  urlToOpen = item["url"].toString();

                  break;
              }
         }

         qDebug() << "URL TO OPEN: " << urlToOpen;

         QmlDocument *qml = QmlDocument::create("asset:///StartupCardThread.qml")
                                                          .parent(this);

         m_root = qml->createRootObject<NavigationPane>();
         qml->setContextProperty("_app", this);
         m_app->setScene(m_root);

         QObject *thread = m_root->findChild<QObject*>("pageThread");
         if(thread != NULL) {
             thread->setProperty("urlPage", urlToOpen);

             bb::device::DisplayInfo display;
             QDeclarativePropertyMap* displayDimensions = new QDeclarativePropertyMap;
             displayDimensions->insert( "width", QVariant( display.pixelSize().width() ) );
             displayDimensions->insert( "height", QVariant( display.pixelSize().height() ) );
             qml->setContextProperty( "DisplayInfo", displayDimensions );
         } else
             qDebug() << "pageThread variable is not found in the qml document :(";


         InvokeRequest request;
         request.setTarget("com.amonchakai.HFR10Service");
         request.setAction("bb.action.MARKREAD");
         request.setMimeType("hub/item");
         request.setUri(QUrl("pim:"));

         QByteArray bytes;
         jda.saveToBuffer(objectMap, &bytes);
         request.setData(bytes);

         m_InvokeManager->invoke(request);

    }

    if(request.action().compare("bb.action.COMPOSE") == 0) {
        QmlDocument *qml = QmlDocument::create("asset:///StartupCardCompose.qml")
                                                                  .parent(this);

        m_root = qml->createRootObject<NavigationPane>();
        qml->setContextProperty("_app", this);

        m_app->setScene(m_root);

        QString directory = QDir::homePath() + QLatin1String("/HFRBlackData");
        if (!QFile::exists(directory)) {
            return;
        }

        QFile file(directory + "/UserID.txt");

        QString userName;
        if (file.open(QIODevice::ReadOnly)) {
            QDataStream stream(&file);
            stream >> userName;

            file.close();
        }
コード例 #7
0
void Card::on_invoked(const bb::system::InvokeRequest& request)
{
    qDebug() << "==== Card::onInvoked() START ====";

    emit load_configuration();

    QVariantMap metadata    = request.metadata();
    QString source          = request.source().installId() + " - " + request.source().groupId();
    QString listId          = QString::number(request.listId());
    QString action          = request.action();
    QString target          = request.target();
    QString uri             = request.uri().toString();
    QString data            = QString::fromUtf8(request.data());

    qDebug() << "==== Card::onInvoked(): action: " << action << data << ", uri: " << uri;

    if(action == "bb.action.VIEW")
    {
        JsonDataAccess jda;
        QVariantMap objectMap   = (jda.loadFromBuffer(data)).toMap();
        QVariantMap itemMap     = objectMap["attributes"].toMap();
        QString messageID1      = itemMap["messageid"].toString();
        QString sourceID1       = itemMap["sourceId"].toString();

        QString itemsFromJSON   = Utilities::get_string_from_file("data/hub_items.json");

        QVariantList itemsFromJSONList = jda.loadFromBuffer(itemsFromJSON).toList();

        qDebug() << "**** Card::onInvoked: itemsFromJSONList: " << itemsFromJSONList.size() << ", sourceId1: " << sourceID1 << ", messageID1: " << messageID1;

        for(int index = 0; index < itemsFromJSONList.size(); index++)
        {
            QVariantMap attributes    = itemsFromJSONList.at(index).toMap();
            QString pageName          = attributes["thePage"].toString();
            QString theData           = attributes["theData"].toString();
            QString sourceID2         = attributes["sourceId"].toString();

            qDebug() << "**** Card::onInvoked: thePage" << pageName << ", theData: " << theData << ", sourceId2: " << sourceID2;

            if (sourceID2 == messageID1 || sourceID2 == sourceID1)
            {
                InvokeRequest request2;
                request2.setTarget("com.nemory.Insta10HeadlessService");
                request2.setAction("bb.action.MARKREAD");
                request2.setMimeType("hub/item");
                request2.setUri(QUrl("pim:"));

                QByteArray bytes;
                jda.saveToBuffer(objectMap, &bytes);
                request2.setData(bytes);

                InvokeTargetReply *reply = _invoke_manager->invoke(request2);

                if (!reply)
                {
                    qDebug() << "**** FAILED Card::onInvoked: " << reply->errorCode();
                    reply->deleteLater();
                }

                QmlDocument *pageDocument  = QmlDocument::create("asset:///pages/" + pageName).parent(this);
                _page = pageDocument->createRootObject<Page>();
                _page->setProperty("is_card", true);
                //_page->setActionBarVisibility((getSetting("backButton", "false") == "false") ? ChromeVisibility::Hidden : ChromeVisibility::Default);
                _navigation_pane->push(_page);
                Application::instance()->setScene(_navigation_pane);

                emit initialize_card();

                emit opened_item(attributes, theData);

                break;
            }
        }

        jda.deleteLater();
    }
    else if(action == "bb.action.COMPOSE")
    {

    }
    else if(action == "bb.action.SHARE")
    {

        startHeadless();
    }
    else
    {
        startHeadless();
    }
}