void QDropboxAccount::_init() { if(!isValid()) { valid = false; return; } if(!hasKey("referral_link") || !hasKey("display_name") || !hasKey("uid") || !hasKey("country") || !hasKey("quota_info") || !hasKey("email")) { #ifdef QTDROPBOX_DEBUG qDebug() << "json invalid 1" << endl; #endif valid = false; return; } QDropboxJson* quota = getJson("quota_info"); if(!quota->hasKey("shared") || !quota->hasKey("quota") || !quota->hasKey("normal")) { #ifdef QTDROPBOX_DEBUG qDebug() << "json invalid 2" << endl; #endif valid = false; return; } _referralLink.setUrl(getString("referral_link"), QUrl::StrictMode); _displayName = getString("display_name"); _uid = getInt("uid"); _country = getString("country"); _email = getString("email"); _quotaShared = quota->getUInt("shared", true); _quota = quota->getUInt("quota", true); _quotaNormal = quota->getUInt("normal", true); valid = true; #ifdef QTDROPBOX_DEBUG qDebug() << "== account data ==" << endl; qDebug() << "reflink: " << _referralLink << endl; qDebug() << "displayname: " << _displayName << endl; qDebug() << "uid: " << _uid << endl; qDebug() << "country: " << _country << endl; qDebug() << "email: " << _email << endl; qDebug() << "quotaShared: " << _quotaShared << endl; qDebug() << "quotaNormal: " << _quotaNormal << endl; qDebug() << "quotaUsed: " << _quota << endl; qDebug() << "== account data end ==" << endl; #endif return; }
int QDropboxJson::parseSubJson(QString strJson, int start, qdropboxjson_entry *jsonEntry) { int openBrackets = 1; QString buffer = ""; QDropboxJson* jsonValue = NULL; int j; for(j=start+1; openBrackets > 0 && j < strJson.size(); ++j) { if(strJson.at(j).toLatin1() == '{') openBrackets++; else if(strJson.at(j).toLatin1() == '}') openBrackets--; } buffer = strJson.mid(start, j-start); #ifdef QTDROPBOX_DEBUG qDebug() << "brackets = " << openBrackets << endl; qDebug() << "json data(" << start << ":" << j-start << ") = " << buffer << endl; #endif jsonValue = new QDropboxJson(); jsonValue->parseString(buffer); // invalid sub json means invalid json if(!jsonValue->isValid()) { #ifdef QTDROPBOX_DEBUG qDebug() << "subjson invalid!" << endl; #endif valid = false; return j; } // insert new jsonEntry->value.json = jsonValue; jsonEntry->type = QDROPBOXJSON_TYPE_JSON; return j; }
void QDropbox::parseAccountInfo(QString response) { #ifdef QTDROPBOX_DEBUG qDebug() << "== account info ==" << response << "== account info end =="; #endif QDropboxJson json; json.parseString(response); _tempJson.parseString(response); if(!json.isValid()) { errorState = QDropbox::APIError; errorText = "Dropbox API did not send correct answer for account information."; #ifdef QTDROPBOX_DEBUG qDebug() << "error: " << errorText << endl; #endif emit errorOccured(errorState); return; } emit accountInfoReceived(response); return; }
void QDropbox::parseDelta(QString response) { #ifdef QTDROPBOX_DEBUG qDebug() << "== metadata ==" << response << "== metadata end =="; #endif QDropboxJson json; json.parseString(response); _tempJson.parseString(response); if(!json.isValid()) { errorState = QDropbox::APIError; errorText = "Dropbox API did not send correct answer for delta."; #ifdef QTDROPBOX_DEBUG qDebug() << "error: " << errorText << endl; #endif emit errorOccured(errorState); stopEventLoop(); return; } emit deltaReceived(response); return; }
QDropboxJson::QDropboxJson(const QDropboxJson &other) : QObject(other.parent()) { _init(); parseString(other.strContent()); }