bool FbTalker::addPhoto(const QString& imgPath, const QString& albumID, const QString& caption) { kDebug() << "Adding photo " << imgPath << " to album with id " << albumID << " using caption '" << caption << "'"; if (m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); QMap<QString, QString> args; args["access_token"] = m_accessToken; args["name"] = KUrl(imgPath).fileName(); if (!albumID.isEmpty()) args["aid"] = albumID; if (!caption.isEmpty()) args["caption"] = caption; MPForm form; for (QMap<QString, QString>::const_iterator it = args.constBegin(); it != args.constEnd(); ++it) { form.addPair(it.key(), it.value()); } if (!form.addFile(args["name"], imgPath)) { emit signalBusy(false); return false; } form.finish(); kDebug() << "FORM: " << endl << form.formData(); KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"photos.upload"), form.formData(), KIO::HideProgressInfo); job->addMetaData("UserAgent", m_userAgent); job->addMetaData("content-type", form.contentType()); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_state = FB_ADDPHOTO; m_job = job; m_buffer.resize(0); return true; }
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; }
bool SmugTalker::addPhoto(const QString& imgPath, int albumID, const QString& caption) { if (m_job) { m_job->kill(); m_job = 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(); KMD5 imgMD5(imgData); MPForm form; form.addPair("ByteCount", QString::number(imgSize)); form.addPair("MD5Sum", QString(imgMD5.hexDigest())); form.addPair("AlbumID", QString::number(albumID)); form.addPair("ResponseType", "REST"); if (!caption.isEmpty()) form.addPair("Caption", caption); if (!form.addFile(imgName, imgPath)) return false; form.finish(); QString customHdr; KUrl url("http://upload.smugmug.com/photos/xmladd.mg"); KIO::TransferJob *job = KIO::http_post(url, form.formData(), KIO::HideProgressInfo); job->addMetaData("content-type", form.contentType()); job->addMetaData("UserAgent", m_userAgent); customHdr += "X-Smug-SessionID: " + m_sessionID + "\r\n"; customHdr += "X-Smug-Version: " + m_apiVersion + "\r\n"; job->addMetaData("customHTTPHeader", customHdr); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_state = SMUG_ADDPHOTO; m_job = job; m_buffer.resize(0); return true; }
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); }
bool ImgurTalker::imageUpload(const KUrl& filePath) { kDebug() << "Upload image" << filePath; m_currentUrl = filePath; MPForm form; KUrl exportUrl = KUrl("http://api.imgur.com/2/upload.json"); exportUrl.addQueryItem("key", m_apiKey); exportUrl.addQueryItem("name", filePath.fileName()); exportUrl.addQueryItem("title", filePath.fileName()); // this should be replaced with something the user submits // exportUrl.addQueryItem("caption", ""); // this should be replaced with something the user submits exportUrl.addQueryItem("type", "file"); form.addFile("image", filePath.path()); form.finish(); KIO::TransferJob* job = KIO::http_post(exportUrl, form.formData(), KIO::HideProgressInfo); job->addMetaData("content-type", form.contentType()); job->addMetaData("content-length", QString("Content-Length: %1").arg(form.formData().length())); job->addMetaData("UserAgent", m_userAgent); connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(slotData(KIO::Job*, const QByteArray&))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_state = IE_ADDPHOTO; emit signalUploadStart(filePath); emit signalBusy(true); return true; }
bool DsTalker::addScreenshot(const QString& imgPath, const QString& packageName, const QString& packageVersion, const QString& description) { kDebug() << "Adding screenshot " << imgPath << " to package " << packageName << " " << packageVersion<< " using description '" << description << "'"; if (m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); MPForm form; form.addPair("packagename", packageName); form.addPair("version", packageVersion); form.addPair("description", description); form.addFile(imgPath, imgPath, "file"); form.finish(); kDebug() << "FORM: " << endl << form.formData(); KIO::TransferJob* job = KIO::http_post(m_uploadUrl, form.formData(), KIO::HideProgressInfo); job->addMetaData("UserAgent", m_userAgent); job->addMetaData("content-type", form.contentType()); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_job = job; m_buffer.resize(0); return true; }
bool ImgurTalker::imageRemove(const QString& delete_hash) { // @TODO : make sure it works MPForm form; KUrl removeUrl = KUrl("http://api.imgur.com/2/delete/"); removeUrl.addPath(delete_hash + ".json"); form.finish(); KIO::TransferJob* job = KIO::http_post(removeUrl, form.formData(), KIO::HideProgressInfo); job->addMetaData("content-type", form.contentType()); job->addMetaData("UserAgent", m_userAgent); m_state = IE_REMOVEPHOTO; emit signalBusy(true); return 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; }
void ImageshackTalker::uploadItem(QString path, QMap<QString, QString> opts) { if (m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); QMap<QString, QString> args; args["key"] = m_appKey; args["fileupload"] = KUrl(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(KUrl(path).fileName(), path)) { emit signalBusy(false); return; } form.finish(); kDebug() << "FORM" << form.formData() << "--------------------"; // Check where to upload QString mime = mimeType(path); if (mime.startsWith("video/")) { // video file, check supported types QString form = mime.split("/").at(1); } else { // image file } KIO::Job *job = KIO::http_post(KUrl(m_photoApiUrl), form.formData(), KIO::HideProgressInfo); job->addMetaData("UserAgent", m_userAgent); job->addMetaData("content-type", form.contentType()); connect(job, SIGNAL(data(KIO::Job*, QByteArray)), this, SLOT(data(KIO::Job*, QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_job = job; m_state = IMGHCK_ADDPHOTO; m_buffer.resize(0); }
bool FlickrTalker::addPhoto(const QString& photoPath, const FPhotoInfo& info, bool sendOriginal, bool rescale, int maxDim, int imageQuality) { if (m_job) { m_job->kill(); m_job = 0; } KUrl url(m_uploadUrl); // We dont' want to modify url as such, we just used the KURL object for storing the query items. KUrl url2(""); QString path = photoPath; MPForm form; form.addPair("auth_token", m_token, "text/plain"); url2.addQueryItem("auth_token", m_token); form.addPair("api_key", m_apikey, "text/plain"); url2.addQueryItem("api_key", m_apikey); QString ispublic = (info.is_public == 1) ? "1" : "0"; form.addPair("is_public", ispublic, "text/plain"); url2.addQueryItem("is_public", ispublic); QString isfamily = (info.is_family == 1) ? "1" : "0"; form.addPair("is_family", isfamily, "text/plain"); url2.addQueryItem("is_family", isfamily); QString isfriend = (info.is_friend == 1) ? "1" : "0"; form.addPair("is_friend", isfriend, "text/plain"); url2.addQueryItem("is_friend", isfriend); QString safetyLevel = QString::number(static_cast<int>(info.safety_level)); form.addPair("safety_level", safetyLevel, "text/plain"); url2.addQueryItem("safety_level", safetyLevel); QString contentType = QString::number(static_cast<int>(info.content_type)); form.addPair("content_type", contentType, "text/plain"); url2.addQueryItem("content_type", contentType); QString tags = "\"" + info.tags.join("\" \"") + "\""; if (tags.length() > 0) { form.addPair("tags", tags, "text/plain"); url2.addQueryItem("tags", tags); } if (!info.title.isEmpty()) { form.addPair("title", info.title, "text/plain"); url2.addQueryItem("title", info.title); } if (!info.description.isEmpty()) { form.addPair("description", info.description, "text/plain"); url2.addQueryItem("description", info.description); } QString md5 = getApiSig(m_secret, url2); form.addPair("api_sig", md5, "text/plain"); QImage image; // Check if RAW file. if (KPMetadata::isRawFile(photoPath)) { KDcrawIface::KDcraw::loadDcrawPreview(image, photoPath); } else { image.load(photoPath); } if (!image.isNull()) { path = KStandardDirs::locateLocal("tmp", QFileInfo(photoPath).baseName().trimmed() + ".jpg"); if (sendOriginal) { QFile imgFile(photoPath); imgFile.copy(path); } else { if (rescale && (image.width() > maxDim || image.height() > maxDim)) image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); image.save(path, "JPEG", imageQuality); } // Restore all metadata. KPMetadata meta; if (meta.load(photoPath)) { meta.setImageDimensions(image.size()); // NOTE: see B.K.O #153207: Flickr use IPTC keywords to create Tags in web interface // As IPTC do not support UTF-8, we need to remove it. meta.removeIptcTag("Iptc.Application2.Keywords", false); meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); meta.save(path); } else { kWarning() << "(flickrExport::Image doesn't have metadata)"; } kDebug() << "Resizing and saving to temp file: " << path; } if (!form.addFile("photo", path)) { return false; } form.finish(); KIO::TransferJob* job = KIO::http_post(url, form.formData(), KIO::HideProgressInfo); job->addMetaData("content-type", form.contentType()); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_state = FE_ADDPHOTO; m_job = job; m_buffer.resize(0); emit signalBusy(true); return true; }
bool DBTalker::addPhoto(const QString& imgPath, const QString& uploadFolder, bool rescale, int maxDim, int imageQuality) { if(m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); MPForm form; QString path = imgPath; QImage image; if(KPMetadata::isRawFile(imgPath)) { KDcrawIface::KDcraw::loadRawPreview(image,imgPath); } else { image.load(imgPath); } if(image.isNull()) { return false; } path = KStandardDirs::locateLocal("tmp",QFileInfo(imgPath).baseName().trimmed()+".jpg"); if(rescale && (image.width() > maxDim || image.height() > maxDim)) { image = image.scaled(maxDim,maxDim,Qt::KeepAspectRatio,Qt::SmoothTransformation); } image.save(path,"JPEG",imageQuality); KPMetadata meta; if(meta.load(imgPath)) { meta.setImageDimensions(image.size()); meta.setImageProgramId("Kipi-plugins",kipiplugins_version); meta.save(path); } if(!form.addFile(path)) { emit signalBusy(false); return false; } QString uploadPath = uploadFolder + KUrl(imgPath).fileName(); QString m_url = QString("https://api-content.dropbox.com/1/files_put/dropbox/") + "/" +uploadPath; KUrl url(m_url); url.addQueryItem("oauth_consumer_key",m_oauth_consumer_key); url.addQueryItem("oauth_nonce", nonce); url.addQueryItem("oauth_signature",m_access_oauth_signature); url.addQueryItem("oauth_signature_method",m_oauth_signature_method); url.addQueryItem("oauth_timestamp", QString::number(timestamp)); url.addQueryItem("oauth_version",m_oauth_version); url.addQueryItem("oauth_token",m_oauthToken); url.addQueryItem("overwrite","false"); KIO::TransferJob* const job = KIO::http_post(url,form.formData(),KIO::HideProgressInfo); job->addMetaData("content-type","Content-Type : application/x-www-form-urlencoded"); connect(job,SIGNAL(data(KIO::Job*,QByteArray)), this,SLOT(data(KIO::Job*,QByteArray))); connect(job,SIGNAL(result(KJob*)), this,SLOT(slotResult(KJob*))); m_state = DB_ADDPHOTO; m_job = job; m_buffer.resize(0); emit signalBusy(true); return true; }
void ImageshackTalker::uploadItemToGallery(QString path, const QString &/*gallery*/, QMap<QString, QString> opts) { if (m_job) { m_job->kill(); m_job = 0; } emit signalBusy(true); QMap<QString, QString> args; args["key"] = m_appKey; args["fileupload"] = KUrl(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(KUrl(path).fileName(), path)) { emit signalBusy(false); return; } form.finish(); // Check where to upload QString mime = mimeType(path); // TODO support for video uploads KUrl uploadUrl; if (mime.startsWith(QLatin1String("video/"))) { uploadUrl = KUrl(m_videoApiUrl); m_state = IMGHCK_ADDVIDEO; } else { // image file uploadUrl = KUrl(m_photoApiUrl); m_state = IMGHCK_ADDPHOTO; } KIO::Job* const job = KIO::http_post(uploadUrl, form.formData(), KIO::HideProgressInfo); job->addMetaData("UserAgent", m_userAgent); job->addMetaData("content-type", form.contentType()); m_job = job; // if (gallery.isEmpty()) // { // m_state = IMGHCK_ADDPHOTO; // } // else // { // kDebug() << "upload to gallery " << gallery; // m_state = IMGHCK_ADDPHOTOGALLERY; // job->setProperty("k_galleryName", gallery); // m_job->setProperty("k_step", STEP_UPLOADITEM); // } // TODO implement upload to galleries m_buffer.resize(0); connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(data(KIO::Job*,QByteArray))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); }