Active Topics

 



Notices


Reply
Thread Tools
Posts: 38 | Thanked: 55 times | Joined on Jan 2013
#1
A new version of Logo Quiz is almost ready for release!
I just need help in the following stuff:

Takeing a Screenshot and use teh Share Api to share it! what i have done so far is:

Code:
#include "sharehelper.h"
//#include <QImage>

// sharehelper.cpp is based on the PhotoMosaic App
// See: http://www.developer.nokia.com/Community/Wiki/Photomosaic_App_with_Qt

// PhotoMosaic in turn is based on the butaca project
// See: http://projects.developer.nokia.com/butaca/

// The article "How to Use the Harmattan?s ShareUI Framework in Qml" on linux4us.org was also helpful
// See: http://blog.linux4us.org/2012/06/14/how-to-use-the-harmattans-shareui-framework-qml/

#include <QDeclarativeContext>

#ifndef QT_SIMULATOR
#include <maemo-meegotouch-interfaces/shareuiinterface.h>
#include <MDataUri>
#endif
/*
ShareHelper::ShareHelper(QObject *parent) :
    QObject(parent)
{
}
*/
ShareHelper::ShareHelper(QmlApplicationViewer *currentView){
    this->currentView = currentView;
}

// shares a URL with the share-ui interface
void ShareHelper::shareURL(QString title, QString description, QString url)
{
#ifndef QT_SIMULATOR
    MDataUri dataUri;

    dataUri.setMimeType("text/x-url");
    dataUri.setTextData(url);

    dataUri.setAttribute("title", title);
    dataUri.setAttribute("description", description);

    // qDebug() << dataUri.toString();

    QStringList items;
    items << dataUri.toString();
    ShareUiInterface shareIf("com.nokia.ShareUi");
    if (shareIf.isValid()) {
        shareIf.share(items);
    } else {
        qCritical() << "Invalid interface";
    }
#else
    Q_UNUSED(title)
    Q_UNUSED(url)
#endif
}


// shares an image with the share-ui interface
void ShareHelper::shareImage(QString title, QString description, QString url)
{
#ifndef QT_SIMULATOR
    MDataUri dataUri;
    QByteArray body;
    QBuffer buffer(&body);
    buffer.open(QIODevice::WriteOnly);
    if(url != "") {
        QImage image;
        image.load(url);
        image.save(&buffer, "JPG");
    } else {
        QPixmap::grabWidget(currentView).save(&buffer,"JPG");
    }

    dataUri.setMimeType("image/jpeg");
    dataUri.setBinaryData(body);

    dataUri.setAttribute("title", title);
    dataUri.setAttribute("description", description);

    qDebug() << dataUri.toString();

    QStringList items;
    items << dataUri.toString();
    ShareUiInterface shareIf("com.nokia.ShareUi");
    if (shareIf.isValid()) {
        shareIf.share(items);
    } else {
        qCritical() << "Invalid interface";
    }
#else
    Q_UNUSED(title)
    Q_UNUSED(url)
#endif
}

void ShareHelper::shareScreen(QString title, QString description, QString url){

#ifndef QT_SIMULATOR
    MDataUri dataUri;
    QByteArray body;
    QBuffer buffer(&body);
    buffer.open(QIODevice::WriteOnly);
    if(url != "") {
        QImage image;
        image.load(url);
        image.save(&buffer, "JPG");
    } else {
        //QPixmap::grabWidget(currentView).save(&buffer,"JPG",-1);
        QPixmap::grabWidget(currentView).save(QDir::currentPath() + "/screen.jpg", "JPG",-1);
        QImage image;
        image.load(QDir::currentPath() + "/screen.jpg");
        image.save(&buffer, "JPG");

    }

    dataUri.setMimeType("image/jpeg");
    dataUri.setBinaryData(body);

    dataUri.setAttribute("title", title);
    dataUri.setAttribute("description", description);

    qDebug() << dataUri.toString();

    QStringList items;
    items << dataUri.toString();
    ShareUiInterface shareIf("com.nokia.ShareUi");
    if (shareIf.isValid()) {
        shareIf.share(items);
    } else {
        qCritical() << "Invalid interface";
    }
#else
    QPixmap::grabWidget(currentView).save(QDir::currentPath() + "/screen.jpg", "JPG",-1);
    Q_UNUSED(title)
    Q_UNUSED(url)
#endif
}
Code:
#ifndef SHAREHELPER_H
#define SHAREHELPER_H

#include <QObject>
#include <QPixmap>
#include <qmlapplicationviewer.h>
#include <QDir>

// sharehelper.h is based on the PhotoMosaic App
// See: http://www.developer.nokia.com/Community/Wiki/Photomosaic_App_with_Qt

// PhotoMosaic in turn based on the butaca project
// See: http://projects.developer.nokia.com/butaca/

// The article "How to Use the Harmattan?s ShareUI Framework in Qml" on linux4us.org was also helpful
// See: http://blog.linux4us.org/2012/06/14/how-to-use-the-harmattans-shareui-framework-qml/

class ShareHelper : public QObject
{
public:
    ShareHelper(QmlApplicationViewer* currentView);

    Q_OBJECT public: Q_INVOKABLE void shareScreen(QString title, QString description, QString url);
    //explicit ShareHelper(QObject *parent = 0);

signals:

public slots:
    //! Shares a URL with the share-ui interface
    //! \param title The title of the content to be shared
    //! \param description The description of the content to be shared
    //! \param url The URL to be shared
    void shareURL(QString title, QString description, QString url);

    //! Shares an Image with the share-ui interface
    //! \param title The title of the content to be shared
    //! \param description The description of the content to be shared
    //! \param url The URL of the image to be shared
    void shareImage(QString title, QString description, QString url);
private:
    QmlApplicationViewer* currentView;
};

#endif // SHAREHELPER_H
it does take a screenshot on simulator but on the device it does not? (makes a gray image) and opens the share page but does not display the image? some help would be apricated
Attached Images
    
 

The Following 5 Users Say Thank You to momoelz For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 02:36.