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;
}
Esempio n. 2
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);
}
Esempio n. 3
0
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
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);
}
Esempio n. 7
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;
}
Esempio n. 8
0
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*)));

}