Example #1
0
bool autobots_toutiao::GetCode(const QByteArray& rp_data, QString& hash_code, QString& public_key)
{
  QJsonParseError json_error;
  QJsonDocument parse_doucment = QJsonDocument::fromJson(rp_data, &json_error); 
  if(json_error.error == QJsonParseError::NoError) 
  {  
    if(parse_doucment.isObject())  
    {  
      QJsonObject obj = parse_doucment.object(); 
      if(obj.contains("hash"))  
      {  
        QJsonValue name_value = obj.take("hash");
        if(name_value.isString())
        {
          hash_code = name_value.toString();
        }
      }
      if(obj.contains("key"))  
      {  
        QJsonValue name_value = obj.take("key");
        if(name_value.isString())
        {
          public_key = name_value.toString();
        }
      }
    }
  }

  if (!hash_code.isEmpty() && !public_key.isEmpty())
  {
    return true;
  }

  return false;
}
Example #2
0
QJsonObject YunClient::getRequestData(QString array)
{
    QByteArray byte_array = array.toLocal8Bit();
    QJsonParseError json_error;
    QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_array, &json_error);

    QJsonObject dataJson;
    if(json_error.error == QJsonParseError::NoError)
    {
        if(!parse_doucment.isObject())
            return dataJson;

        QJsonObject json = parse_doucment.object();
        if(json.contains("status")){
            QJsonValue value = json.take("status");
            if(!value.toBool()){
                errView(json);
                return dataJson;
            }
        }

        if(json.contains("data")){
            dataJson = json.take("data").toObject();
        }
    }

    return dataJson;
}
Example #3
0
QJsonArray YunClient::setPagingInfo(QJsonObject json)
{
    QJsonArray listJson;
    if(json.contains("limit")){
        QJsonValue value = json.take("limit");
        lineedit_recordPage->setText(QString::number(value.toInt()));
    }

    QString total, current;
    if(json.contains("totalPages")){
        QJsonValue value = json.take("totalPages");
        total = QString::number(value.toInt());
    }

    if(json.contains("currentPage")){
        QJsonValue value = json.take("currentPage");
        current = QString::number(value.toInt());
    }
    if (total.compare("0") != 0 && current.compare("0") != 0)
        label_page->setText(QString("共: %1/%2").arg(current).arg(total));

    if(json.contains("totalRecords")){
        QJsonValue value = json.take("totalRecords");
        label_totalRecords->setText(QString("共:%1").arg(value.toInt()));
    }

    if (json.contains("list")){
        listJson = json.take("list").toArray();
    }

    return listJson;
}
QVector<Language> LoadSupportLanguage() {
    QFile json(":/support_languages.json");
    qDebug()<<"Open File"<<json.open(QIODevice::ReadOnly);

    QVector<Language> supportLanguagesList;
    QJsonParseError json_error;
    QJsonDocument supportLanguages = QJsonDocument::fromJson(json.readAll(), &json_error);
    json.close();
    if(json_error.error == QJsonParseError::NoError) {
        if (supportLanguages.isArray()) {
            QJsonArray languresArray = supportLanguages.array();
            int size = languresArray.size();
            for (int i = 0; i < size; ++i) {
                Language language;
                QJsonValue languageJson = languresArray.at(i);
                QJsonObject languageObject = languageJson.toObject();
                language.Locale =languageObject.take("Locale").toString();
                language.Description = languageObject.take("Description").toString();
                language.LanguageCode = languageObject.take("LanguageCode").toString();
                language.CountryCode = languageObject.take("CountryCode").toString();
                supportLanguagesList.push_back(language);
            }
        }
    }
    return supportLanguagesList;
}
Example #5
0
void JsonObjectConverter<DiscoveryInformation>::fillFrom(
    QJsonObject jo, DiscoveryInformation& result)
{
    fromJson(jo.take("m.homeserver"_ls), result.homeserver);
    fromJson(jo.take("m.identity_server"_ls), result.identityServer);

    fromJson(jo, result.additionalProperties);
}
SplicePicturesImageItem::SplicePicturesImageItem(QJsonObject &json) {
    row = json.take("row").toInt();
    col = json.take("col").toInt();
    path = json.take("path").toString();
    x = json.take("x").toInt();
    y = json.take("y").toInt();
    rotation = Rational(json.take("rotation").toString());
    zoom = Rational(json.take("zoom").toString());
    loadFromPath(path);
}
void SplicePicturesPanel::loadConfiguration(QJsonDocument configuration) {
    imageList.clear();
    QJsonObject json = configuration.object();
    imageZoom = json.take("zoom").toDouble();
    QJsonArray array = json.take("images").toArray();
    foreach (const QJsonValue & value, array) {
        QJsonObject itemJson = value.toObject();
        SplicePicturesImageItem item(itemJson);
        imageList.push_back(item);
    }
bool feedBackMessage::loadfromJson(QByteArray textJson)
{
    QJsonParseError jsonParseError;
    QJsonDocument jsonDocument = QJsonDocument::fromJson(textJson, &jsonParseError);
    if(jsonParseError.error == QJsonParseError::NoError)
    {
        if(jsonDocument.isObject())
        {

            QJsonObject jsonObject = jsonDocument.object();
            if(jsonObject.contains("username"))
            {
                QJsonValue jsonValue = jsonObject.take("username");
                if(jsonValue.isString())
                {
                    user = jsonValue.toString();
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
            if(jsonObject.contains("status"))
            {
                QJsonValue jsonValue = jsonObject.take("status");
                if(jsonValue.isString())
                {
                    stat = jsonValue.toString();
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
}
void CAlgorithmSettingsModel::saveSettingsEx(int row, QUrl filename) {
    QJsonObject data;
    CQJsonTreeItem* parentItem = mRootItem->getChilds()->value(row);
    CQJsonTreeItem* tempItem;
    int size = parentItem->getChilds()->size();
    for(int i = 0; i < size; i++)
    {
      tempItem= parentItem->getChilds()->value(i);
      QJsonObject o = tempItem->toJson();
      QString key = o.keys().at(0);
      data.insert(key, o.take(key));
    }
    if (filename.isEmpty() == true) {
        filename.setPassword("a" + workflow->getStep(row)->Name());
    }
    if (workflow->getStep(row)->ValidateParameters(&data)) {
        emit saveQJsonEx(data, filename);
        workflow->getStep(row)->getAlgorithm()->setParameters(data);
    }
    else{
        QString pluginM = workflow->getStep(row)->Name();
        pluginM.append(" parameter not Valid!");
        CLogController::instance().frameworkMessage(pluginM);
    }
}
bool CAlgorithmSettingsModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
  if(CQJsonModel::setData(index, value,role))
  {
    CQJsonTreeItem* parentItem = backtrack(index);
    QJsonObject params;
    IPlugin* plugin = workflow->getStep(parentItem->row());

    CQJsonTreeItem* tempItem;
    int size = parentItem->getChilds()->size();
    for(int i = 0; i < size; i++)
    {
      tempItem = parentItem->getChilds()->value(i);
      QJsonObject o = tempItem->toJson();
      QString key = o.keys().at(0);
      params.insert(key, o.take(key));
    }

    if(plugin->ValidateParameters(&params))
    {
      plugin->getAlgorithm()->setParameters(params);
    }else{
        QString pluginM = plugin->Name();
        pluginM.append(" parameter not Valid!");
        CLogController::instance().frameworkMessage(pluginM);
    }
    return true;
  }

  return false;
}
bool CAlgorithmSettingsModel::validateAll(){
   int count = mRootItem->getChilds()->size();
   for(int row = 0; row < count; row++)
   {
       QJsonObject data;
       CQJsonTreeItem* parentItem = mRootItem->getChilds()->value(row);
       CQJsonTreeItem* tempItem;
       int size = parentItem->getChilds()->size();
       int size2 = workflow->getStepCount();
       if(size != size2){
         return false;
       }
       for(int i = 0; i < size; i++)
       {
         tempItem= parentItem->getChilds()->value(i);
         QJsonObject o = tempItem->toJson();
         QString key = o.keys().at(0);
         data.insert(key, o.take(key));
       }
        if (workflow->getStep(row)->ValidateParameters(&data) == false) {
            CLogController::instance().frameworkMessage("Error: " + workflow->getStep(row)->Name() + " Invalid Parameter");
         return false;
        }else{
            workflow->getStep(row)->getAlgorithm()->setParameters(data);
        }
   }
   return true;
}
Example #12
0
bool autobots_toutiao::GetSupportStatus(const QByteArray& byte_arr)
{
	QJsonParseError json_error;
	QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_arr, &json_error);
	if (json_error.error == QJsonParseError::NoError)
	{
		if (parse_doucment.isObject())
		{
			QJsonObject obj = parse_doucment.object();
			if (obj.contains("err_no"))
			{
				QJsonValue name_value = obj.take("err_no");
				if (name_value.isDouble())
				{
					int int_value = name_value.toDouble(); // success
					if (int_value == 0)
					{
						// 点赞成功
						ui.lineEdit_msg->setText("点赞成功");
					}
				}
			}
		}
	}

	return false;
}
Example #13
0
void YunClient::errView(QJsonObject json)
{
    QString errcode, errmsg;
    if(json.contains("errorCode")){
        QJsonValue value = json.take("errorCode");
        errcode = value.toString();
    }
    if (json.contains("errorMsg")){
        QJsonValue value = json.take("errorMsg");
        errmsg = value.toString();
    }
    QMessageBox::critical(this, "HTTP ERROR",
                              QString("request error."
                                      "error code: %1\n"
                                      "error msg : %2").arg(errcode).arg(errmsg),
                              QMessageBox::Yes, QMessageBox::Yes);
}
Example #14
0
QString Picasa::getUsernameById(QString userid){
    QString username;
    if(userid.isEmpty())
        userid = "default";
    QUrl url = QUrl("https://picasaweb.google.com/data/feed/api/user/" + userid
                    + "?kind=photo&alt=json&access_token="+this->access_token);

    QJsonDocument document = getJsonDocument(url);
    QJsonObject feed = document.object().take("feed").toObject();
    username = feed.take("gphoto$nickname").toObject().take("$t").toString();
    if(userid == "default"){
        this->currentUserId = feed.take("gphoto$user").toObject().take("$t").toString();
        this->currentUser = username;
    }

    return username;
}
Example #15
0
bool autobots_toutiao::GetFatieStatus(const QByteArray& byte_arr)
{
	QJsonParseError json_error;
	QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_arr, &json_error);
	if (json_error.error == QJsonParseError::NoError)
	{
		if (parse_doucment.isObject())
		{
			QJsonObject obj = parse_doucment.object();
			if (obj.contains("err_no"))
			{
				QJsonValue name_value = obj.take("err_no");
				if (name_value.isDouble())
				{
					int int_value = name_value.toDouble(); // success
					if (int_value == 0)
					{
						// 发帖成功
						if (obj.contains("comment_id"))
						{
							QString comment_str;
							QString comment_id;
							QJsonValue comment_obj = obj.take("comment_id");

							if (comment_obj.isDouble())
							{
								double id = comment_obj.toDouble();
								comment_id = QString::number(id, 'f', 0);
							}


							if (!comment_id.isEmpty())
							{
								FatieSucceed(comment_str, comment_id);
								return true;
							}
						}
					}
				}
			}
		}
	}

	return false;
}
Example #16
0
bool autobots_toutiao::UpdateDiggCount(const QByteArray& data, int& count_)
{
	bool ret = false;
  QJsonParseError json_error;
  QJsonDocument parse_doucment = QJsonDocument::fromJson(data, &json_error); 
  if(json_error.error == QJsonParseError::NoError) 
  {  
    if(parse_doucment.isObject())  
    { 
      QJsonObject obj = parse_doucment.object(); 
      if(obj.contains("message"))  
      {  
        QJsonValue name_value = obj.take("message");
        if(name_value.isString())
        {
          QString msg = name_value.toString();

          if (msg == "success" )
          {
			ret = true;
          }
        }

      }

	  if (obj.contains("data"))
	  {
		  QJsonValue data_value = obj.take("data");

		  QJsonObject data_ojb = data_value.toObject();

		  double comment_id = 0;
		  if (data_ojb.contains("digg_count"))
		  {
			  QJsonValue count_value = data_ojb.take("digg_count");
			  count_ = count_value.toDouble();	  
		  }
	  }
    }
  }

  return ret;
}
Example #17
0
void WeatherRequest::replyFinished(QNetworkReply *reply)
{
    m_items.clear();
    QByteArray ba = reply->readAll();
    reply->deleteLater();
    if(ba.isEmpty())
        return;

    QJsonObject jobj = QJsonDocument::fromJson(ba).object();
    if(jobj.contains("list"))
    {
        QJsonValue value = jobj.take("list");
        if(value.isArray())
        {
            QJsonArray array = value.toArray();
            QJsonArray::iterator it = array.begin();
            for(;it != array.end(); it++)
            {
                if((*it).isObject())
                {
                    QJsonObject obj = (*it).toObject();
                    QStringList keys = m_maps.keys();
                    QStringList::iterator keyIt = keys.begin();
                    WeatherItem item;
                    for(; keyIt != keys.end(); keyIt++)
                    {
                        m_maps[*keyIt]->readData(item,obj.take(*keyIt));
                    }
                    m_items.append(item);
                }
            }
        }
    }
    if(m_items.count() == 7)
    {
        emit refreshData(m_items);
    }
    if(!m_timer->isActive())
    {
        m_timer->start();
    }
}
Example #18
0
int autobots_toutiao::GetResult(const QByteArray& data)
{
	int res = false;
	QJsonParseError json_error;
	QJsonDocument parse_doucment = QJsonDocument::fromJson(data, &json_error);
	if (json_error.error == QJsonParseError::NoError)
	{
		if (parse_doucment.isObject())
		{
			QJsonObject obj = parse_doucment.object();
			if (obj.contains("error_code"))
			{
				QJsonValue name_value = obj.take("error_code");
				int n = name_value.toDouble();
				if (n == 0)
				{
					res = 0;
					QJsonValue redirect_obj = obj.take("redirect_url");
					QString url_str = redirect_obj.toString();
					ProcessRedirectGet(url_str);
				}
				if (n == 1009)
				{
					res = -2;
				}
				if (n == 1102)
				{
					// 验证码错误
					res = -1;
// 					if (obj.contains("captcha"))
// 					{
// 						QJsonValue captcha_obj = obj.take("captcha");
// 						QString validata_code = captcha_obj.toString();
// 					}

				}
			}
		}
	}
	return res;
}
void Updater::checkVersion()
{
    if(_reply->canReadLine()) {
        QJsonDocument doc = QJsonDocument::fromJson(_reply->readAll());
        _reply->deleteLater();
        QJsonObject obj = doc.object();
        QString version = obj.take("version").toString();
        QMap<QString, QVariant> map;
        if(fullVersion() < strToIntVrs(version)) {
            map.insert("programName", obj.take("programName"));
            map.insert("version", version);
            map.insert("desc", obj.take("desc"));

            _downloadLink = QUrl(obj.take("updateDownload").toString());
            _fileName = obj.take("updateFile").toString();

            emit newVersionIsAvailable(map);
            return;
        }
    }
    emit newVersionIsUnavailable();
}
Example #20
0
QJsonObject festrip_api::user_login(QString username, QString password)
{
    QUrlQuery query = QUrlQuery(QUrl(QString(FESTRIP_URL).append("/api/user/")));
    // Fill in query
    query.addQueryItem("query", "login");
    query.addQueryItem("user", username);
    query.addQueryItem("pass", password);
    // Send query to server
    QJsonObject response = this->send_query(POST, query);
    token = response.take("app_token");
    // Return JSON
    return(response);
}
Example #21
0
QList<Photo> Picasa::getPhotosByAlbum(Album *album){
    QList<Photo> photos;
    if(album->getId().isEmpty() || album->getOwnerId().isEmpty())
        return photos;
    QUrl url = QUrl("https://picasaweb.google.com/data/feed/api/user/" + album->getOwnerId()
                    + "/albumid/" + album->getId() + "?alt=json&access_token="+this->access_token);
    QJsonDocument document = getJsonDocument(url);
    QJsonObject feed = document.object().take("feed").toObject();
    QJsonArray array = feed.take("entry").toArray();

    foreach(QJsonValue photo_, array){
        Photo photo(photo_.toObject());
        photo.setAlbum(album->getTitle());
        photos.append(photo);
    }
Example #22
0
void wsServer::processTextMessage(QString message)
{
   QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
   if (pClient) {
       QJsonDocument jsonDoc = QJsonDocument::fromJson(message.toUtf8());
       QJsonObject json = jsonDoc.object();

       QString command = json.take("command").toString();
       //get table
       if(command == "gt"){
           //send current table to remote

       }
   }
}
Example #23
0
bool autobots_toutiao::ExactComments(const QByteArray& rp_data, bool& has_more)
{
	bool res = false;
	QJsonParseError json_error;
	QJsonDocument parse_doucment = QJsonDocument::fromJson(rp_data, &json_error);
	if (json_error.error == QJsonParseError::NoError)
	{
		if (parse_doucment.isObject())
		{
			QJsonObject obj = parse_doucment.object();

			// 查找data节点
			if (obj.contains("data"))
			{
				QJsonObject data_obj = obj.take("data").toObject();

				// 查找comments节点
				if (data_obj.contains("comments"))
				{
					QJsonArray comments_arry = data_obj.take("comments").toArray();
					for (int i = 1; i < comments_arry.size(); ++i)
					{
						QJsonObject comment_obj = comments_arry.at(i).toObject();
						if (comment_obj.contains("id") && comment_obj.contains("dongtai_id"))
						{
							double d1 = comment_obj.take("id").toDouble();
							QString id = QString::number(d1, 'f', 0);
							QString d_id = QString::number(comment_obj.take("dongtai_id").toDouble(), 'f', 0);
							m_id_dongtaiid.insert(id, d_id);
						}
					}

				}

				if (data_obj.contains("has_more"))
				{
					has_more = data_obj.take("has_more").toBool();
				}				
			}
		}
	}

	return res;
}
Example #24
0
QString Shadow::GetJsonVal(QString key,QJsonObject jsonObj)
{
    if(jsonObj.contains(key))
    {
        QJsonValue value = jsonObj.take(key);
        if(value.isDouble())
        {
            int valueInt = (int)(value.toDouble());
            QString str = QString::number(valueInt);
            return str;
        } else if(value.isString()){
            QString valueString = value.toString();
            return valueString;
        } else {
            return "";
        }
    }
    return "";
}
Example #25
0
QString ParseLrc::getLrcText(QByteArray lrcdataarray){
    QJsonParseError *errlrc;
    QJsonDocument lrcdocd = QJsonDocument::fromJson(lrcdataarray,errlrc);
    if(lrcdocd.isObject()){
        QJsonObject lrcobjl = lrcdocd.object();
        if(lrcobjl.contains("data")){
            QJsonValue lrcvalue = lrcobjl.take("data");
            if(lrcvalue.isObject()){
                QJsonObject lrcobj2 = lrcvalue.toObject();
                if(lrcobj2.contains("lrc")){
                    QJsonValue lrcstringvalue = lrcobj2.take("lrc");
                    if(lrcstringvalue.isString()){
                        QString lrc = lrcstringvalue.toString();
                        return lrc;
                    }
                }
            }
        }else{
            return "Sorry,No Lyric...";
        }
    }
}
Example #26
0
QString WorkThread::ParseToken(const QByteArray & data)
{
    QString ret;
    QJsonParseError json_error;
    QJsonDocument parse_doucment = QJsonDocument::fromJson(data, &json_error);
    if (json_error.error == QJsonParseError::NoError)
    {
        if (parse_doucment.isObject())
        {
            QJsonObject obj = parse_doucment.object();
            if (obj.contains("gentoken"))
            {
                QJsonValue name_value = obj.take("gentoken");
                if (name_value.isString())
                {
                    ret = name_value.toString();
                }
            }
        }
    }

    return ret;
}
Example #27
0
bool autobots_toutiao::GetFatieStatus(const QByteArray& byte_arr)
{
  QJsonParseError json_error;
  QJsonDocument parse_doucment = QJsonDocument::fromJson(byte_arr, &json_error); 
  if(json_error.error == QJsonParseError::NoError) 
  {  
    if(parse_doucment.isObject())  
    {  
      QJsonObject obj = parse_doucment.object(); 
      if(obj.contains("code"))  
      {  
        QJsonValue name_value = obj.take("code");
        if(name_value.isDouble())
        {
          int d = name_value.toDouble();
          return d == 0;
        }
      }
    }
  }

  return false;
}
Example #28
0
bool autobots_toutiao::GetResult(const QByteArray& rp_data)
{
  QJsonParseError json_error;
  QJsonDocument parse_doucment = QJsonDocument::fromJson(rp_data, &json_error); 
  if(json_error.error == QJsonParseError::NoError) 
  {  
    if(parse_doucment.isObject())  
    {  
      QJsonObject obj = parse_doucment.object(); 
      if(obj.contains("status"))  
      {  
        QJsonValue name_value = obj.take("status");
        if(name_value.isBool())
        {
          bool res = name_value.toBool();
          return res;
        }
      }
    }
  }

  return false;
}
void ThemeSelectorWidget::populateThemeList() {
    QDir dir;
    dir.cd("Themes");
    QStringList dirList = dir.entryList(QDir::AllDirs);
    QString themeItem;
    foreach (themeItem, dirList) {
        if(themeItem == "." || themeItem == "..") continue;
        dir.cd(themeItem);
        QFile *file = new QFile(dir.absoluteFilePath("ThemeInfo.json"));
        file->open(QIODevice::ReadOnly);
        QTextStream stream(file);
        QString json = stream.readAll();
        file->close();
        QJsonDocument document = QJsonDocument::fromJson(json.toUtf8());
        QJsonObject object = document.object();
        QString themeName = object.take("Name").toString();
        QString themeIcon = object.take("Icon").toString();
        QString themeAuthor = object.take("Author").toString();
        QString themeDesc = object.take("Desc").toString();
        QString themeVer = object.take("Version").toString();
        QString themeJS = object.take("ThemeScript").toString();
        QString appBG = object.take("AppBackgroundColor").toString();
        QString appTextColorScheme = object.take("AppTextColorScheme").toString();
        QStringList itemData;
        itemData << dir.absoluteFilePath(themeJS);
        itemData << appBG;
        itemData << appTextColorScheme;
        itemDataList.append(itemData);
        QListWidgetItem *item = new QListWidgetItem(QIcon(dir.absoluteFilePath(themeIcon)),themeName);
        item->setToolTip(themeDesc + "\nAuthor: " + themeAuthor + "\nVersion: " +themeVer);
        ui->listWidget->addItem(new QListWidgetItem(QIcon(dir.absoluteFilePath(themeIcon)),themeName));
        dir.cdUp();
    }
    if(ui->listWidget->count() == 0) {
        ui->applyButton->setDisabled(true);
    } else {
        ui->applyButton->setDisabled(false);
    }
}
Example #30
0
void YunClient::setVersionList(QJsonArray json)
{
    rowList.clear();
    for (int i=0; i<json.size(); i++)
    {
        QJsonObject vjson = json.at(i).toObject();
        QStringList rowValue;

        rowValue.append(QString::number(i+1));
        if(vjson.contains("versionId")){
            QJsonValue value = vjson.take("versionId");
            rowValue.append(QString::number(value.toInt()));
        }
        if(vjson.contains("versionName")){
            QJsonValue value = vjson.take("versionName");
            rowValue.append(value.toString());
        }
        if(vjson.contains("versionSize")){
            QJsonValue value = vjson.take("versionSize");
            rowValue.append(QString::number(value.toDouble()));
        }
        if(vjson.contains("versionInfo")){
            QJsonValue value = vjson.take("versionInfo");
            rowValue.append(value.toString());
        }
        if(vjson.contains("releaseTime")){
            QJsonValue value = vjson.take("releaseTime");
            rowValue.append(value.toString());
        }
        if(vjson.contains("isUpdate")){
            QJsonValue value = vjson.take("isUpdate");
            QString status("未更新");
            if (value.toBool())
                status = "已更新";
            rowValue.append(status);
        }

        rowList.append(rowValue);
    }

    update_list->setModelValue(rowList);
}