/** * Creates folder inside any folder(of which id is passed) */ void GDTalker::createFolder(const QString& title, const QString& id) { if (m_reply) { m_reply->abort(); m_reply = 0; } QUrl url(QString::fromLatin1("https://www.googleapis.com/drive/v2/files")); QByteArray data; data += "{\"title\":\""; data += title.toLatin1(); data += "\",\r\n"; data += "\"parents\":"; data += "[{"; data += "\"id\":\""; data += id.toLatin1(); data += "\"}],\r\n"; data += "\"mimeType\":"; data += "\"application/vnd.google-apps.folder\""; data += "}\r\n"; qCDebug(KIPIPLUGINS_LOG) << "data:" << data; QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); netRequest.setRawHeader("Authorization", m_bearer_access_token.toLatin1()); m_reply = m_netMngr->post(netRequest, data); m_state = GD_CREATEFOLDER; m_buffer.resize(0); emit signalBusy(true); }
void SmugTalker::listAlbumTmpl() { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QUrl url(m_apiURL); QUrlQuery q; q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.albumtemplates.get")); q.addQueryItem(QString::fromLatin1("SessionID"), m_sessionID); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->get(netRequest); m_state = SMUG_LISTALBUMTEMPLATES; m_buffer.resize(0); }
void SmugTalker::listSubCategories(qint64 categoryID) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QUrl url(m_apiURL); QUrlQuery q; q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.subcategories.get")); q.addQueryItem(QString::fromLatin1("SessionID"), m_sessionID); q.addQueryItem(QString::fromLatin1("CategoryID"), QString::number(categoryID)); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->get(netRequest); m_state = SMUG_LISTSUBCATEGORIES; m_buffer.resize(0); }
/** * Gets access token from googledrive after authentication by user */ void Authorize::getAccessToken() { QUrl url(QString::fromLatin1("https://accounts.google.com/o/oauth2/token?")); QUrlQuery urlQuery; urlQuery.addQueryItem(QString::fromLatin1("scope"), m_scope); urlQuery.addQueryItem(QString::fromLatin1("response_type"), m_response_type); urlQuery.addQueryItem(QString::fromLatin1("token_uri"), m_token_uri); url.setQuery(urlQuery); QByteArray postData; postData = "code="; postData += m_code.toLatin1(); postData += "&client_id="; postData += m_client_id.toLatin1(); postData += "&client_secret="; postData += m_client_secret.toLatin1(); postData += "&redirect_uri="; postData += m_redirect_uri.toLatin1(); postData += "&grant_type=authorization_code"; QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->post(netRequest, postData); m_Authstate = GD_ACCESSTOKEN; m_buffer.resize(0); emit signalBusy(true); }
void QGeoTileFetcherNokia::fetchCopyrightsData() { QString copyrightUrl = "http://"; copyrightUrl += m_uriProvider->getCurrentHost(); copyrightUrl += "/maptiler/v2/copyright/newest?output=json"; if (!token().isEmpty()) { copyrightUrl += "&token="; copyrightUrl += token(); } if (!applicationId().isEmpty()) { copyrightUrl += "&app_id="; copyrightUrl += applicationId(); } QNetworkRequest netRequest((QUrl(copyrightUrl))); m_copyrightsReply = m_networkManager->get(netRequest); if (m_copyrightsReply->error() != QNetworkReply::NoError) { qWarning() << __FUNCTION__ << m_copyrightsReply->errorString(); m_copyrightsReply->deleteLater(); return; } if (m_copyrightsReply->isFinished()) { copyrightsFetched(); } else { connect(m_copyrightsReply, SIGNAL(finished()), this, SLOT(copyrightsFetched())); } }
void YggdrasilTask::executeTask() { setStatus(getStateMessage(STATE_SENDING_REQUEST)); // Get the content of the request we're going to send to the server. QJsonDocument doc(getRequestContent()); auto worker = MMC->qnam(); QUrl reqUrl("https://" + URLConstants::AUTH_BASE + getEndpoint()); QNetworkRequest netRequest(reqUrl); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QByteArray requestData = doc.toJson(); m_netReply = worker->post(netRequest, requestData); connect(m_netReply, &QNetworkReply::finished, this, &YggdrasilTask::processReply); connect(m_netReply, &QNetworkReply::uploadProgress, this, &YggdrasilTask::refreshTimers); connect(m_netReply, &QNetworkReply::downloadProgress, this, &YggdrasilTask::refreshTimers); connect(m_netReply, &QNetworkReply::sslErrors, this, &YggdrasilTask::sslErrors); timeout_keeper.setSingleShot(true); timeout_keeper.start(timeout_max); counter.setSingleShot(false); counter.start(time_step); progress(0, timeout_max); connect(&timeout_keeper, &QTimer::timeout, this, &YggdrasilTask::abort); connect(&counter, &QTimer::timeout, this, &YggdrasilTask::heartbeat); }
/** Creates folder at specified path */ void DBTalker::createFolder(const QString& path) { //path also has name of new folder so send path parameter accordingly qCDebug(KIPIPLUGINS_LOG) << "in cre fol " << path; QUrl url(QString::fromLatin1("https://api.dropbox.com/1/fileops/create_folder")); QUrlQuery q(url); q.addQueryItem(QString::fromLatin1("root"),m_root); q.addQueryItem(QString::fromLatin1("path"),path); q.addQueryItem(QString::fromLatin1("oauth_consumer_key"), m_oauth_consumer_key); q.addQueryItem(QString::fromLatin1("oauth_nonce"), m_nonce); q.addQueryItem(QString::fromLatin1("oauth_signature"), m_access_oauth_signature); q.addQueryItem(QString::fromLatin1("oauth_signature_method"), m_oauth_signature_method); q.addQueryItem(QString::fromLatin1("oauth_timestamp"), QString::number(m_timestamp)); q.addQueryItem(QString::fromLatin1("oauth_version"), m_oauth_version); q.addQueryItem(QString::fromLatin1("oauth_token"), m_oauthToken); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->post(netRequest, QByteArray()); m_state = DB_CREATEFOLDER; m_buffer.resize(0); emit signalBusy(true); }
void ImageshackTalker::authenticate() { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); emit signalJobInProgress(1, 4, i18n("Authenticating the user")); QUrl url(QString::fromLatin1("https://api.imageshack.com/v2/user/login")); QUrlQuery q(url); q.addQueryItem(QString::fromLatin1("user"), m_imageshack->email()); q.addQueryItem(QString::fromLatin1("password"), m_imageshack->password()); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->post(netRequest, QByteArray()); m_state = IMGHCK_AUTHENTICATING; m_buffer.resize(0); }
bool SmugTalker::addPhoto(const QString& imgPath, qint64 albumID, const QString& albumKey, const QString& caption) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QString imgName = QFileInfo(imgPath).fileName(); // load temporary image to buffer QFile imgFile(imgPath); if (!imgFile.open(QIODevice::ReadOnly)) { emit signalBusy(false); return false; } long long imgSize = imgFile.size(); QByteArray imgData = imgFile.readAll(); imgFile.close(); MPForm form; form.addPair(QString::fromLatin1("ByteCount"), QString::number(imgSize)); form.addPair(QString::fromLatin1("MD5Sum"), QString::fromLatin1( QCryptographicHash::hash(imgData, QCryptographicHash::Md5).toHex())); form.addPair(QString::fromLatin1("AlbumID"), QString::number(albumID)); form.addPair(QString::fromLatin1("AlbumKey"), albumKey); form.addPair(QString::fromLatin1("ResponseType"), QString::fromLatin1("REST")); if (!caption.isEmpty()) form.addPair(QString::fromLatin1("Caption"), caption); if (!form.addFile(imgName, imgPath)) return false; form.finish(); QString customHdr; QUrl url(QString::fromLatin1("http://upload.smugmug.com/photos/xmladd.mg")); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, form.contentType()); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); netRequest.setRawHeader("X-Smug-SessionID", m_sessionID.toLatin1()); netRequest.setRawHeader("X-Smug-Version", m_apiVersion.toLatin1()); m_reply = m_netMngr->post(netRequest, form.formData()); m_state = SMUG_ADDPHOTO; m_buffer.resize(0); return true; }
void SmugTalker::createAlbum(const SmugAlbum& album) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QUrl url(m_apiURL); QUrlQuery q; q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.albums.create")); q.addQueryItem(QString::fromLatin1("SessionID"), m_sessionID); q.addQueryItem(QString::fromLatin1("Title"), album.title); q.addQueryItem(QString::fromLatin1("CategoryID"), QString::number(album.categoryID)); if (album.subCategoryID > 0) q.addQueryItem(QString::fromLatin1("SubCategoryID"), QString::number(album.subCategoryID)); if (!album.description.isEmpty()) q.addQueryItem(QString::fromLatin1("Description"), album.description); if (album.tmplID > 0) { // template will also define privacy settings q.addQueryItem(QString::fromLatin1("AlbumTemplateID"), QString::number(album.tmplID)); } else { if (!album.password.isEmpty()) q.addQueryItem(QString::fromLatin1("Password"), album.password); if (!album.passwordHint.isEmpty()) q.addQueryItem(QString::fromLatin1("PasswordHint"), album.passwordHint); if (album.isPublic) q.addQueryItem(QString::fromLatin1("Public"), QString::fromLatin1("1")); else q.addQueryItem(QString::fromLatin1("Public"), QString::fromLatin1("0")); } url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->get(netRequest); m_state = SMUG_CREATEALBUM; m_buffer.resize(0); }
void ImageshackTalker::uploadItemToGallery(const QString& path, const QString& /*gallery*/, const QMap<QString, QString>& opts) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QMap<QString, QString> args; args[QString::fromLatin1("key")] = m_appKey; args[QString::fromLatin1("fileupload")] = QUrl(path).fileName(); MPForm form; for (QMap<QString, QString>::const_iterator it = opts.constBegin(); it != opts.constEnd(); ++it) { form.addPair(it.key(), it.value()); } for (QMap<QString, QString>::const_iterator it = args.constBegin(); it != args.constEnd(); ++it) { form.addPair(it.key(), it.value()); } if (!form.addFile(QUrl(path).fileName(), path)) { emit signalBusy(false); return; } form.finish(); // Check where to upload QString mime = mimeType(path); QUrl uploadUrl; uploadUrl = QUrl(m_photoApiUrl); m_state = IMGHCK_ADDPHOTO; QNetworkRequest netRequest(uploadUrl); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, form.contentType()); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->post(netRequest, form.formData()); m_buffer.resize(0); }
/** * Gets list of folder of user in json format */ void GDTalker::listFolders() { QUrl url(QString::fromLatin1("https://www.googleapis.com/drive/v2/files?q=mimeType = 'application/vnd.google-apps.folder'")); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); netRequest.setRawHeader("Authorization", m_bearer_access_token.toLatin1()); m_reply = m_netMngr->get(netRequest); m_state = GD_LISTFOLDERS; m_buffer.resize(0); emit signalBusy(true); }
QGeoTiledMapReply *QGeoTileFetcherNokia::getTileImage(const QGeoTileSpec &spec) { // TODO add error detection for if request.connectivityMode() != QGraphicsGeoMap::OnlineMode QString rawRequest = getRequestString(spec); QNetworkRequest netRequest((QUrl(rawRequest))); // The extra pair of parens disambiguates this from a function declaration netRequest.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); QNetworkReply *netReply = m_networkManager->get(netRequest); QGeoTiledMapReply *mapReply = new QGeoMapReplyNokia(netReply, spec); return mapReply; }
void LoginTask::executeTask() { setStatus("Logging in..."); auto worker = MMC->qnam(); connect(worker, SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*))); QUrl loginURL("https://login.minecraft.net/"); QNetworkRequest netRequest(loginURL); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrlQuery params; params.addQueryItem("user", uInfo.username); params.addQueryItem("password", uInfo.password); params.addQueryItem("version", "13"); netReply = worker->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8()); }
void SmugTalker::getPhoto(const QString& imgPath) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QNetworkRequest netRequest(QUrl::fromLocalFile(imgPath)); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); netRequest.setRawHeader("X-Smug-SessionID", m_sessionID.toLatin1()); netRequest.setRawHeader("X-Smug-Version", m_apiVersion.toLatin1()); m_reply = m_netMngr->get(netRequest); m_state = SMUG_GETPHOTO; m_buffer.resize(0); }
void SmugTalker::login(const QString& email, const QString& password) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); emit signalLoginProgress(1, 4, i18n("Logging in to SmugMug service...")); QUrl url(m_apiURL); QUrlQuery q; if (email.isEmpty()) { q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.login.anonymously")); q.addQueryItem(QString::fromLatin1("APIKey"), m_apiKey); } else { q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.login.withPassword")); q.addQueryItem(QString::fromLatin1("APIKey"), m_apiKey); q.addQueryItem(QString::fromLatin1("EmailAddress"), email); q.addQueryItem(QString::fromLatin1("Password"), password); } url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->get(netRequest); m_state = SMUG_LOGIN; m_buffer.resize(0); m_user.email = email; }
/** Get username of dropbox user */ void DBTalker::getUserName() { QUrl url(QString::fromLatin1("https://api.dropbox.com/1/account/info")); QUrlQuery q(url); q.addQueryItem(QString::fromLatin1("oauth_consumer_key"), m_oauth_consumer_key); q.addQueryItem(QString::fromLatin1("oauth_nonce"), m_nonce); q.addQueryItem(QString::fromLatin1("oauth_signature"), m_access_oauth_signature); q.addQueryItem(QString::fromLatin1("oauth_signature_method"), m_oauth_signature_method); q.addQueryItem(QString::fromLatin1("oauth_timestamp"), QString::number(m_timestamp)); q.addQueryItem(QString::fromLatin1("oauth_version"), m_oauth_version); q.addQueryItem(QString::fromLatin1("oauth_token"), m_oauthToken); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->post(netRequest, QByteArray()); m_state = DB_USERNAME; m_buffer.resize(0); emit signalBusy(true); }
/** Gets access token from refresh token for handling login of user across digikam sessions */ void Authorize::getAccessTokenFromRefreshToken(const QString& msg) { QUrl url(QString::fromLatin1("https://accounts.google.com/o/oauth2/token")); QByteArray postData; postData = "&client_id="; postData += m_client_id.toLatin1(); postData += "&client_secret="; postData += m_client_secret.toLatin1(); postData += "&refresh_token="; postData += msg.toLatin1(); postData += "&grant_type=refresh_token"; QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->post(netRequest, postData); m_Authstate = GD_REFRESHTOKEN; m_buffer.resize(0); emit signalBusy(true); }
void SmugTalker::listPhotos(const qint64 albumID, const QString& albumKey, const QString& albumPassword, const QString& sitePassword) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); QUrl url(m_apiURL); QUrlQuery q; q.addQueryItem(QString::fromLatin1("method"), QString::fromLatin1("smugmug.images.get")); q.addQueryItem(QString::fromLatin1("SessionID"), m_sessionID); q.addQueryItem(QString::fromLatin1("AlbumID"), QString::number(albumID)); q.addQueryItem(QString::fromLatin1("AlbumKey"), albumKey); q.addQueryItem(QString::fromLatin1("Heavy"), QString::fromLatin1("1")); if (!albumPassword.isEmpty()) q.addQueryItem(QString::fromLatin1("Password"), albumPassword); if (!sitePassword.isEmpty()) q.addQueryItem(QString::fromLatin1("SitePassword"), sitePassword); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); netRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); m_reply = m_netMngr->get(netRequest); m_state = SMUG_LISTPHOTOS; m_buffer.resize(0); }
/** Get list of folders by parsing json sent by dropbox */ void DBTalker::listFolders(const QString& path) { QString make_url = QString::fromLatin1("https://api.dropbox.com/1/metadata/dropbox/") + path; QUrl url(make_url); QUrlQuery q(url); q.addQueryItem(QString::fromLatin1("oauth_consumer_key"), m_oauth_consumer_key); q.addQueryItem(QString::fromLatin1("oauth_nonce"), m_nonce); q.addQueryItem(QString::fromLatin1("oauth_signature"), m_access_oauth_signature); q.addQueryItem(QString::fromLatin1("oauth_signature_method"), m_oauth_signature_method); q.addQueryItem(QString::fromLatin1("oauth_timestamp"), QString::number(m_timestamp)); q.addQueryItem(QString::fromLatin1("oauth_version"), m_oauth_version); q.addQueryItem(QString::fromLatin1("oauth_token"), m_oauthToken); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/x-www-form-urlencoded")); m_reply = m_netMngr->get(netRequest); m_state = DB_LISTFOLDERS; m_buffer.resize(0); emit signalBusy(true); }
bool DBTalker::addPhoto(const QString& imgPath, const QString& uploadFolder, bool rescale, int maxDim, int imageQuality) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); MPForm form; QImage image; if (m_iface) { image = m_iface->preview(QUrl::fromLocalFile(imgPath)); } if (image.isNull()) { return false; } QString path = makeTemporaryDir("dropbox").filePath(QFileInfo(imgPath) .baseName().trimmed() + QLatin1String(".jpg")); if (rescale && (image.width() > maxDim || image.height() > maxDim)) { image = image.scaled(maxDim,maxDim,Qt::KeepAspectRatio,Qt::SmoothTransformation); } image.save(path,"JPEG",imageQuality); if (m_meta->load(QUrl::fromLocalFile(imgPath))) { m_meta->setImageDimensions(image.size()); m_meta->setImageProgramId(QString::fromLatin1("Kipi-plugins"), kipipluginsVersion()); m_meta->save(QUrl::fromLocalFile(path)); } if (!form.addFile(path)) { emit signalBusy(false); return false; } QString uploadPath = uploadFolder + QUrl(imgPath).fileName(); QString m_url = QString::fromLatin1("https://api-content.dropbox.com/1/files_put/dropbox/") + QString::fromLatin1("/") + uploadPath; QUrl url(m_url); QUrlQuery q(url); q.addQueryItem(QString::fromLatin1("oauth_consumer_key"), m_oauth_consumer_key); q.addQueryItem(QString::fromLatin1("oauth_nonce"), m_nonce); q.addQueryItem(QString::fromLatin1("oauth_signature"), m_access_oauth_signature); q.addQueryItem(QString::fromLatin1("oauth_signature_method"), m_oauth_signature_method); q.addQueryItem(QString::fromLatin1("oauth_timestamp"), QString::number(m_timestamp)); q.addQueryItem(QString::fromLatin1("oauth_version"), m_oauth_version); q.addQueryItem(QString::fromLatin1("oauth_token"), m_oauthToken); q.addQueryItem(QString::fromLatin1("overwrite"), QString::fromLatin1("false")); url.setQuery(q); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("multipart/mixed")); m_reply = m_netMngr->post(netRequest, form.formData()); m_state = DB_ADDPHOTO; m_buffer.resize(0); emit signalBusy(true); return true; }
bool weatherStation::update() { QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkRequest netRequest(*apiLink); QNetworkReply *netReply; QTimer timer; timer.setSingleShot(true); QEventLoop loop; netReply = manager->get(netRequest); connect(netReply, SIGNAL(finished()), &loop, SLOT(quit())); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); timer.start(10000); loop.exec(); QString data; QFile weatherTempData("weatherTempData.txt"); weatherTempData.open(QFile::ReadWrite); if(timer.isActive()) { timer.stop(); if(netReply->error() > 0) { qDebug() << "network error"; data = weatherTempData.readAll(); qDebug() << "read from file"; } else { int v = netReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (v >= 200 && v < 300) { // Success data = netReply->readAll(); weatherTempData.seek(0); QTextStream out(&weatherTempData); out << data; weatherTempData.seek(0); //qDebug() << weatherTempData.readAll(); } } } else { // timeout disconnect(netReply, SIGNAL(finished()), &loop, SLOT(quit())); netReply->abort(); data = weatherTempData.readAll(); qDebug() << "read from file"; } weatherTempData.close(); QXmlStreamReader *xmlReader = new QXmlStreamReader(data); int weatherRecordCounter = 0; //Parse the XML until we reach end of it while(!xmlReader->atEnd() && !xmlReader->hasError()) { // Read next element QXmlStreamReader::TokenType token = xmlReader->readNext(); //If token is just StartDocument - go to next if(token == QXmlStreamReader::StartDocument) { continue; } //qDebug() << xmlReader->name(); if(token == QXmlStreamReader::EndElement) if(xmlReader->name() == "time") { weatherRecordCounter++; //qDebug() << "is end element"; continue; } // //If token is StartElement - read it if(token == QXmlStreamReader::StartElement) { if(xmlReader->name() == "sun") { QXmlStreamAttributes att = xmlReader->attributes(); sunrise = sunrise.fromString(att.value("rise").toString(),"yyyy-MM-ddTHH:mm:ss"); sunrise.setTimeSpec(Qt::UTC); sunrise = sunrise.toLocalTime(); sunset = sunset.fromString(att.value("set").toString(),"yyyy-MM-ddTHH:mm:ss"); sunset.setTimeSpec(Qt::UTC); sunset = sunset.toLocalTime(); //qDebug() << sunrise.toString("yyyy-MM-ddTHH:mm:ss"); //qDebug() << sunset.toString("yyyy-MM-ddTHH:mm:ss"); continue; } if(xmlReader->name() == "time") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecord *record = new weatherRecord(); record->day = record->day.fromString(att.value("day").toString(),"yyyy-MM-dd"); /*record->from = record->from.fromString(att.value("from").toString(),"yyyy-MM-ddTHH:mm:ss"); record->to = record->to.fromString(att.value("to").toString(),"yyyy-MM-ddTHH:mm:ss"); qDebug() << record->from.toString("yyyy-MM-ddTHH:mm:ss"); qDebug() << record->to.toString("yyyy-MM-ddTHH:mm:ss");*/ weatherRecords.append(record); continue; } if(xmlReader->name() == "precipitation") { if(xmlReader->isEndElement()) { weatherRecords.at(weatherRecordCounter)->precipitationType = "no"; continue; } else { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->precipitationType=att.value("type").toString(); weatherRecords.at(weatherRecordCounter)->precipitationValue=att.value("value").toFloat(); weatherRecords.at(weatherRecordCounter)->precipitationUnit=att.value("unit").toString(); continue; } } if(xmlReader->name() == "windDirection") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->windDirection=att.value("deg").toFloat(); continue; } if(xmlReader->name() == "windSpeed") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->windSpeed=att.value("mps").toFloat(); weatherRecords.at(weatherRecordCounter)->windType=att.value("name").toString(); continue; } if(xmlReader->name() == "temperature") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->currentTemp=att.value("day").toFloat(); weatherRecords.at(weatherRecordCounter)->minTemp=att.value("min").toFloat(); weatherRecords.at(weatherRecordCounter)->maxTemp=att.value("max").toFloat(); continue; } if(xmlReader->name() == "pressure") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->pressure=att.value("value").toFloat(); continue; } if(xmlReader->name() == "humidity") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->humidity=att.value("value").toFloat(); continue; } if(xmlReader->name() == "clouds") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->cloudsPercent=att.value("all").toInt(); weatherRecords.at(weatherRecordCounter)->cloudsName=att.value("value").toString(); continue; } if(xmlReader->name() == "symbol") { QXmlStreamAttributes att = xmlReader->attributes(); weatherRecords.at(weatherRecordCounter)->icon=att.value("var").toString(); continue; } } } if(xmlReader->hasError()) return false; return true; }
bool GDTalker::addPhoto(const QString& imgPath, const GSPhoto& info, const QString& id, bool rescale, int maxDim, int imageQuality) { if (m_reply) { m_reply->abort(); m_reply = 0; } emit signalBusy(true); MPForm_GDrive form; form.addPair(QUrl::fromLocalFile(imgPath).fileName(),info.description,imgPath,id); QString path = imgPath; QMimeDatabase mimeDB; if (!mimeDB.mimeTypeForFile(path).name().startsWith(QLatin1String("video/"))) { QImage image; if (m_iface) { image = m_iface->preview(QUrl::fromLocalFile(imgPath)); } if (image.isNull()) { image.load(imgPath); } if (image.isNull()) { return false; } path = makeTemporaryDir("gs").filePath(QFileInfo(imgPath) .baseName().trimmed() + QLatin1String(".jpg")); int imgQualityToApply = 100; if (rescale) { if (image.width() > maxDim || image.height() > maxDim) image = image.scaled(maxDim,maxDim,Qt::KeepAspectRatio,Qt::SmoothTransformation); imgQualityToApply = imageQuality; } image.save(path,"JPEG",imgQualityToApply); if (m_iface) { QPointer<MetadataProcessor> meta = m_iface->createMetadataProcessor(); if (meta && meta->load(QUrl::fromLocalFile(imgPath))) { meta->setImageDimensions(image.size()); meta->setImageProgramId(QString::fromLatin1("Kipi-plugins"), kipipluginsVersion()); meta->save(QUrl::fromLocalFile(path), true); } } } if (!form.addFile(path)) { emit signalBusy(false); return false; } form.finish(); QUrl url(QString::fromLatin1("https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart")); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, form.contentType()); netRequest.setRawHeader("Authorization", m_bearer_access_token.toLatin1()); netRequest.setRawHeader("Host", "www.googleapis.com"); m_reply = m_netMngr->post(netRequest, form.formData()); qCDebug(KIPIPLUGINS_LOG) << "In add photo"; m_state = GD_ADDPHOTO; m_buffer.resize(0); emit signalBusy(true); return true; }
void LFNetConfigLoader::retrieveConfig() { this->notifyStatus("Loading OpenSSL stuff ..."); OpenSSL_add_all_algorithms(); ERR_load_BIO_strings(); ERR_load_crypto_strings(); this->notifyStatus("Generating private key ..."); BIGNUM* e = BN_new(); BN_set_word(e, RSA_F4); RSA* key = RSA_new(); RSA_generate_key_ex(key, 4096, e, NULL); this->notifyStatus("Saving private key ..."); BIO* privateKey = BIO_new_file((_configLocation + "/private.key").toLocal8Bit().data(), "w"); PEM_write_bio_RSAPrivateKey(privateKey, key, NULL, NULL, 0, NULL, NULL); BIO_free(privateKey); this->notifyStatus("Generating csr ..."); EVP_PKEY* pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, key); X509_NAME* name = X509_NAME_new(); X509_NAME_add_entry_by_txt(name, "O", MBSTRING_UTF8, (unsigned char*)"LF-Net", -1, -1, 0); X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8, (unsigned char*)"VPN", -1, -1, 0); X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (unsigned char*)(_username.toUpper() + "_" + _computerName.toUpper()).toUtf8().data(), -1, -1, 0); X509_REQ* req = X509_REQ_new(); X509_REQ_set_pubkey(req, pkey); X509_REQ_set_subject_name(req, name); X509_REQ_set_version(req, 1); X509_REQ_sign(req, pkey, EVP_sha512()); BIO* request = BIO_new(BIO_s_mem()); PEM_write_bio_X509_REQ(request, req); BUF_MEM* requestData; BIO_get_mem_ptr(request, &requestData); this->notifyStatus("Request certificate using generated csr ..."); QNetworkAccessManager *mgr = new QNetworkAccessManager(this); connect(mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(certificateRequestFinished(QNetworkReply*))); connect(mgr, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); QNetworkRequest netRequest(QUrl("https://mokoscha.lf-net.org/request_certificate")); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain"); mgr->post(netRequest, QByteArray(requestData->data, requestData->length)); this->notifyStatus("Cleaning up temporary data ..."); BIO_free(request); X509_REQ_free(req); X509_NAME_free(name); EVP_PKEY_free(pkey); BN_free(e); this->notifyStatus("Waiting for certificate ..."); }