homescreenapp/hshomescreenclientplugin/src/hshomescreenclient.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 60 30f14686fb04
--- a/homescreenapp/hshomescreenclientplugin/src/hshomescreenclient.cpp	Fri Apr 16 14:54:01 2010 +0300
+++ b/homescreenapp/hshomescreenclientplugin/src/hshomescreenclient.cpp	Mon May 03 12:24:59 2010 +0300
@@ -16,9 +16,24 @@
 */
 #include "hshomescreenclient.h"
 #include <xqservicerequest.h>
+#include <xqrequestinfo.h>
 #include <QEventLoop>
 
 const char INTERFACE_NAME[] = "com.nokia.services.hsapplication.IHomeScreenClient";
+
+
+/*!
+    \class HsHomescreenClient
+    \ingroup group_hshomescreenclient
+    \brief Implements home screen client api, see @page_homescreenclientapi for 
+    usage details.
+    
+*/
+
+
+/*!
+  Constructor
+*/
 HsHomescreenClient::HsHomescreenClient(QObject *parent)
     :QObject(parent),
     mAsyncRequest(0),
@@ -26,11 +41,20 @@
 {   
 }
 
+/*!
+  Destructor
+*/
 HsHomescreenClient::~HsHomescreenClient()
 {
     delete mAsyncRequest;
 }
 
+/*!
+    Adds new widget, with the given \a uri and \a preferences, 
+    to the active home screen page.
+    Note that \a preferences is dependent on the 
+    widget implementation and it can be empty if widget does not have any preferences see @ref sssection_setpreferences. 
+ */
 bool HsHomescreenClient::addWidget(
     const QString &uri, 
     const QVariantHash &preferences)
@@ -43,19 +67,46 @@
    
     return mRequestResult;
 }
+
+/*!
+   Sets wallpaper \a fileName. Filename should include full path to the image file.
+ */
+bool HsHomescreenClient::setWallpaper(const QString &fileName)
+{
+    QEventLoop eventLoop;
+    connect(this, SIGNAL(requestFinished()), &eventLoop, SLOT(quit()));
+    QMetaObject::invokeMethod(
+            this, 
+            "doSetWallpaper", 
+            Qt::QueuedConnection,
+            Q_ARG(QString,fileName));
+    eventLoop.exec();
+   
+    return mRequestResult;
+}
     
+/*!
+   Called when request is completed.
+ */
 void HsHomescreenClient::onRequestCompleted(const QVariant &result)
 {
     mRequestResult = result.toBool();
     emit requestFinished();
 }
     
+/*!
+   Called when request has some errors.
+ */
 void HsHomescreenClient::onRequestError(int error)
 {
     Q_UNUSED(error)
     emit requestFinished();
 }
     
+/*!
+ * Uses Qt Highway to send 'addWidget' request to home screen application.
+ * \a uri and \a preferences as in widget model.
+ */
 void HsHomescreenClient::doAddWidget(
     const QString &uri, 
     const QVariantHash &preferences)
@@ -63,18 +114,49 @@
     delete mAsyncRequest;
     mAsyncRequest = 0;
     mAsyncRequest = new XQServiceRequest(INTERFACE_NAME,
-                       "addWidget(QString,QVariantHash)",false);
+                       "addWidget(QString,QVariantHash)", false);
+    
+    XQRequestInfo requestInfo = mAsyncRequest->info();
+    requestInfo.setBackground(true);
+    mAsyncRequest->setInfo(requestInfo);
+    
     *mAsyncRequest << uri;
     *mAsyncRequest << preferences;
     
     connect(mAsyncRequest, SIGNAL(requestCompleted(QVariant)), 
-           SLOT(onRequestCompleted(QVariant)));
+            SLOT(onRequestCompleted(QVariant)));
     connect(mAsyncRequest, SIGNAL(requestError(int)), 
-              SLOT(onRequestError(int)));
+            SLOT(onRequestError(int)));
        
     mRequestResult = false;
-    bool res=mAsyncRequest->send();
-    if(!res){
+    if (!mAsyncRequest->send()) {
+       emit requestFinished();
+    }
+}
+
+/*!
+ * Uses Qt Highway to send 'setWallpaper' request to home screen application.
+ * \a fileName full path to the image file.
+ */
+void HsHomescreenClient::doSetWallpaper(const QString &fileName)
+{
+    delete mAsyncRequest;
+    mAsyncRequest = 0;
+    mAsyncRequest = new XQServiceRequest(INTERFACE_NAME,
+                        "setWallpaper(QString)", false);
+    XQRequestInfo requestInfo = mAsyncRequest->info();
+    requestInfo.setBackground(true);
+    mAsyncRequest->setInfo(requestInfo);
+    
+    *mAsyncRequest << fileName;
+    
+    connect(mAsyncRequest, SIGNAL(requestCompleted(QVariant)), 
+            SLOT(onRequestCompleted(QVariant)));
+    connect(mAsyncRequest, SIGNAL(requestError(int)),
+            SLOT(onRequestError(int)));
+       
+    mRequestResult = false;
+    if (!mAsyncRequest->send()) {
        emit requestFinished();
     }