taskswitcher/testapplications/parentembedded/parent/lunchwidget.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/taskswitcher/testapplications/parentembedded/parent/lunchwidget.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,109 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+#include "lunchwidget.h"
+#include <QRect>
+#include <QPainter>
+#include <QUrl>
+#include <qservicemanager.h>
+#include <xqaiwrequest.h>
+#include <xqappmgr.h>
+#include <xqconversions.h>
+#include <hbapplication>
+QTM_USE_NAMESPACE
+
+#define hbApp qobject_cast<HbApplication*>(qApp)
+
+lunchwidget::lunchwidget(QGraphicsItem *parent)
+    : HbWidget(parent)
+{
+
+	mTitle = "trompka";
+    mLunchButton = new HbPushButton("Lunch embedded app");
+    mResultLabel = new HbLabel;
+    
+    mGridLayout = new QGraphicsGridLayout();
+    mGridLayout->addItem(mResultLabel, 0, 0, 1, 1);
+    mGridLayout->addItem(mLunchButton, 1, 0, 1, 1);
+    setLayout(mGridLayout);
+
+
+    connect(mLunchButton, SIGNAL(released()), this, SLOT(lunchApp()));
+    
+    QStringList list = hbApp->arguments();
+    int count = list.count();
+
+    mTimer = new QTimer;
+    if( count >= 2 ) {
+        mTitle = list.at(1);
+        connect( mTimer, SIGNAL(timeout()), this, SLOT(timeout()) );
+        mTimer->start(1);
+        }
+}
+
+lunchwidget::~lunchwidget()
+{
+	delete mTimer;
+}
+
+void lunchwidget::lunchApp()
+{
+    QList<QVariant> args;
+    QString serviceName("com.nokia.services.embeddedservices");
+    QString operation("requestSetTitle(QString)");
+    XQAiwRequest* request;
+    XQApplicationManager appManager;
+    request = appManager.create(serviceName, "requestSetTitle", operation, true); //embedded
+    if ( request == NULL )
+    {
+        mResultLabel->setPlainText( "request failed" );
+        return;    
+    }
+
+    // Result handlers
+    connect (request, SIGNAL(requestOk(const QVariant&)), 
+        this, SLOT(setTitleCompleted(const QVariant&)));
+    connect (request, SIGNAL(requestError(int,const QString&)), 
+        this, SLOT(serviceRequestError(int,const QString&)));
+
+    args << mTitle; 
+
+
+    request->setArguments(args);
+    if(!request->send()) {
+		mResultLabel->setPlainText( "sending request failed" );
+    }
+    delete request;
+}
+
+void lunchwidget::setTitleCompleted(const QVariant& data)
+{
+    QString title = data.toString();
+    mResultLabel->setPlainText( title );
+}
+    
+void lunchwidget::serviceRequestError(int err,const QString& msg)
+{
+    QString errmsg = tr("Error: %1, ").arg(err);
+    errmsg += msg;
+    mResultLabel->setPlainText( errmsg );
+}    
+
+void lunchwidget::timeout()
+	{
+	mTimer->stop();
+	lunchApp();
+	}