As mention in previous post, the QtWatermark application uses harmattan’s ShareUI Framework for sharing the watermarked photo to social networks, cloud storage or email. Thanks to Maciej Matyjas on github with the sharebear project, I was able to use the ShareUI interface using QML in my application. Here’s how it works with a little modification on the sharebear project.

 


void ShareImage::share(const QString &filename)
{
 QString targetName;
 if (filename.at(0) == QChar('f'))
 {
 targetName = filename;
 targetName.replace(0,7,"");
 }
 else
 targetName = filename;

QFileInfo shareFileInfo(targetName);
 QString shareFileURL = shareFileInfo.canonicalFilePath();

if (shareFileURL.isEmpty())
 qDebug() << "Empty sharing file URL...";

QStringList items;
 items << shareFileURL;

ShareUiInterface shareIf("com.nokia.ShareUi");

if (shareIf.isValid())
 {
 shareIf.share(items);
 }
 else
 qDebug() << "Invalid ShareUi";
}

The share function takes the filename as arguments, convert the “file:///home/user/….” filename to “/home/user/….” and get the cannonical file path. Next, the filename of the item we wish to share is appended to a QStringList. The ShareUiInterface is initialize by passing the “com.nokiaShareUi” parameter as dbus service and the item is shared by calling the ShareUiInterface’s share function with the QStringList as the parameter.

The prerequisite of using the ShareUi is you need to add the following line to the Qt project file.


CONFIG += shareuiinterface-maemo-meegotouch share-ui-plugin share-ui-common

In order to fulfill the dependency for building the package, add the libshare-ui-dev to the debian/control file under Build-depends: line

in order for the qml to use the share function, the following line is added to the main.cpp file:


ShareImage si;
viewer.rootContext()->setContextProperty("shareImage", &si);

and in the qml file


shareImage.share(watermarkPreviewPage.imgUrl);

Here it is, with a few lines added, now you can share image, video, url or text using the build-in ShareUi Framework without lot’s of coding for getting OAuth from facebook or twitter. To view the complete source code, please visit the QtWatermark gitorious site. Thank you.