Permalink
Browse files

added share command in cpp

  • Loading branch information...
1 parent 7ff5e9c commit 2daba0106e8379c0fd3b91dad75a1d9beccbc05b @mborho committed Nov 18, 2012
Showing with 81 additions and 3 deletions.
  1. +6 −2 klippr.pro
  2. +5 −1 main.cpp
  3. +49 −0 sharehelper.cpp
  4. +21 −0 sharehelper.h
View
@@ -26,14 +26,17 @@ QML_IMPORT_PATH =
# MOBILITY +=
# Speed up launching on MeeGo/Harmattan when using applauncherd daemon
+QT += dbus
CONFIG += qdeclarative-boostable
+CONFIG += shareuiinterface-maemo-meegotouch share-ui-plugin share-ui-common mdatauri
# Add dependency to Symbian components
# CONFIG += qt-components
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
- kipptconnector.cpp
+ kipptconnector.cpp \
+ sharehelper.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
@@ -49,4 +52,5 @@ OTHER_FILES += \
qtc_packaging/debian_harmattan/changelog
HEADERS += \
- kipptconnector.h
+ kipptconnector.h \
+ sharehelper.h
View
@@ -2,16 +2,20 @@
#include "qmlapplicationviewer.h"
#include <QDeclarativeContext>
#include "kipptconnector.h"
+#include "sharehelper.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;
QDeclarativeContext *ctxt = viewer.rootContext();
+
KipptConnector *connector = new KipptConnector();
- ctxt->setContextProperty("KipptConnector", connector);
+ ctxt->setContextProperty("KipptConnector", connector);
+ ShareHelper sh;
+ ctxt->setContextProperty("Share", &sh);
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/klippr/main.qml"));
View
@@ -0,0 +1,49 @@
+#include "sharehelper.h"
+
+#include <QString>
+#include <QDebug>
+#ifndef QT_SIMULATOR
+#include <maemo-meegotouch-interfaces/shareuiinterface.h>
+#include <MDataUri>
+#endif
+
+ShareHelper::ShareHelper(QObject *parent) : QObject(parent) { }
+
+void ShareHelper::shareLink (const QString &link, const QString &title) {
+
+// qDebug() << "Make data URI from"
+// << link << title;
+
+#ifndef QT_SIMULATOR
+ MDataUri duri;
+
+ duri.setMimeType ("text/x-url");
+ duri.setTextData (link);
+ duri.setAttribute ("title", title);
+
+ if (duri.isValid() == false) {
+ qCritical() << "Invalid URI";
+ return;
+ }
+
+ QStringList items;
+ items << duri.toString();
+ // qDebug() << "URI:" << items.join (" ");
+
+ // Create a interface object
+ ShareUiInterface shareIf("com.nokia.ShareUi");
+
+ // Check if interface is valid
+ if (shareIf.isValid()) {
+ // Start ShareUI application with selected files.
+ // qDebug() << "Signalling share-ui daemon...";
+ shareIf.share (items);
+ } else {
+ qCritical() << "Invalid interface";
+ return;
+ }
+#else
+ Q_UNUSED(title)
+ Q_UNUSED(url)
+#endif
+}
View
@@ -0,0 +1,21 @@
+#ifndef SHAREHELPER_H
+#define SHAREHELPER_H
+
+#include <QObject>
+
+class ShareHelper: public QObject
+{
+ Q_OBJECT
+public:
+ explicit ShareHelper(QObject *parent = 0);
+
+signals:
+
+public slots:
+
+ void shareLink(const QString &link, const QString &title = QString());
+};
+
+
+
+#endif // SHAREHELPER_H

0 comments on commit 2daba01

Please sign in to comment.