Ejemplo n.º 1
0
	/**
	 * \brief parseJSON
	 * \note parses from mSharedData and populate the arrays such as
	 * mNameTable[], mTable[], mDataTime, mColor[]
	 */
	void parseJSON()
	{
		YAJLDom::Value *jsonRoot = YAJLDom::parse((const unsigned char*)mSharesData, strlen(mSharesData));

		if(jsonRoot->getType() == YAJLDom::Value::ARRAY)
		{
			lprintfln("SUCCESS IN PARSING JSON DATA");
			MAUtil::String tmp,t;
			float scale = mScaleBarHeight;
			const int gridX = mGraph->getScene().getGridX();
			const int gridZ	= mGraph->getScene().getGridZ();
			bool bGotDate = false;
			for(int i=0; i<gridX; i++)
			{
				YAJLDom::Value *row = jsonRoot->getValueByIndex(i);

				int j = 0;
				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("l")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@r l=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("l_cur")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ l_cur=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("c")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ c=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("cp")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ cp=%s t=%s", tmp.c_str(),t.c_str());

				if (bGotDate == false)
				{
					tmp = row->getValueForKey("lt")->toString();
					mDateTime = tmp.c_str();
					bGotDate = true;
				}
			}

			glm::vec4 colScheme[gridZ];
			glm::vec4 redScheme[gridZ];

			colScheme[0] = glm::vec4(0.0f, 236.0f/255.0f, 255.0f/255.0f, 1.0f);	// L blue
			colScheme[1] = glm::vec4(0.0f, 177.0f/255.0f, 191.0f/255.0f, 1.0f);	// D blue
			colScheme[2] = glm::vec4(181.0f/255.0f, 255.0f/255.0f, 0.0f, 1.0f);	// L Green
			colScheme[3] = glm::vec4(124.0f/255.0f, 175.0f/255.0f, 0.0f, 1.0f);	// D Green

			redScheme[0] = glm::vec4(255.0f/255.0f, 0.0f, 236.0f/255.0f, 1.0f);	// L blue
			redScheme[1] = glm::vec4(177.0f/255.0f, 0.0f, 191.0f/255.0f, 1.0f);	// D blue
			redScheme[2] = glm::vec4(255.0f/255.0f, 90.0f/255.0f, 0.0f, 1.0f);  // L Red
			redScheme[3] = glm::vec4(175.0f/255.0f, 64.0f/255.0f, 0.0f, 1.0f);  // D Red

			for(int j=0; j<gridZ; j++)
			{
				for(int i=0; i<gridX; i++)
				{
					const int id 	= i+gridX*j;
					mColors[id] 	= mTables[id]>=0.0f? colScheme[j]: redScheme[j];
				}
			}
		}
	}
Ejemplo n.º 2
0
void PhotoLoader::parseResponse(Cloudbase::CBHelperResponseInfo resp) {

	if ( resp.function == "download" ) {
		qDebug() << "received file";
		QString oldName = QString::fromStdString(resp.downloadedFileName);
		QString newName = QString::fromStdString(resp.downloadedFileName+".jpg");
		QFile::rename(oldName, newName);
		qDebug() << QString::fromStdString(resp.downloadedFileName);
		return;
	}

	qDebug() << "error message: " << resp.errorMessage.c_str();
	if ( resp.postSuccess ) {
		if ( resp.parsedMessage->getType() == YAJLDom::Value::ARRAY ) {
			QVariantList photos;
			// loop over the array of objects from the photos collection
			for (int i = 0; i < resp.parsedMessage->getNumChildValues(); i++) {
				YAJLDom::Value* curPhoto = resp.parsedMessage->getValueByIndex(i);

				// get all the basic data for the current object
				QString title = QString::fromStdString(curPhoto->getValueForKey("title")->toString());
				QString username = QString::fromStdString(curPhoto->getValueForKey("username")->toString());
				QString tags = QString::fromStdString(curPhoto->getValueForKey("tags")->toString());
				QString photoTime = QString::fromStdString(curPhoto->getValueForKey("photo_time")->toString());
				QString filePath = "";

				Photo* newPhoto = new Photo(title, username, tags, "");

				// if we have files attached to the document
				if (!curPhoto->getValueForKey("cb_files")->isNull()) {
					YAJLDom::Value* photoFiles = curPhoto->getValueForKey("cb_files");
					// loop over the files - we may have multiple files as we could be creating
					// thumbnails as well as the full size picture. We assume the thumbnail images
					// contain "thumb" in the file name
					for (int y = 0; y < photoFiles->getNumChildValues(); y++) {
						qDebug() << "loop over files";
						YAJLDom::Value* curFile = photoFiles->getValueByIndex(y);

						qDebug() << "starting download";
						const QDir home = QDir::currentPath()+"/data/";
						QString fileIdString = QString::fromStdString(curFile->getValueForKey("file_id")->toString());
						filePath = home.absoluteFilePath(fileIdString);
						newPhoto->setThumbnailFileId(filePath);
						helper->downloadFile(curFile->getValueForKey("file_id")->toString(), this);

						qDebug() << "file path: " << filePath;
					}

					// send the photo back to the application using the SIGNAL
					//emit receivedPhoto(newPhoto);
				} else {
					qDebug() << "no files";
				}

				QVariantMap photoMap;
				qDebug() << "loaded photo: " << title;
				photoMap["title"] = title;
				photoMap["imageSource"] = filePath;
				photoMap["username"] = username;
				photoMap["tags"] = tags;
				photoMap["time"] = photoTime;

				//photos.append(photoMap);
				photos << photoMap;
			}
			qDebug() << "Emitting signal receivedPhotos";
			emit receivedPhotos(photos);
		}
	}

}