activityfw/testapplications/appactluncher/lunchwidget.cpp
author Jaakko Haukipuro (Nokia-MS/Oulu) <Jaakko.Haukipuro@nokia.com>
Thu, 16 Sep 2010 12:11:40 +0100
changeset 117 c63ee96dbe5f
permissions -rw-r--r--
Missing activityfw and taskswitcher components - fix for Bug 3670

/*
* 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 <afactivities_global.h>
#include <hbcheckbox.h>
#include <hbcombobox.h>
#include <afactivitylauncher.h>
#include <XQConversions>

QTM_USE_NAMESPACE

const QString KAppUid = "Efe0aa02";
const QString KActUid = "Eba3ddd2";

lunchwidget::lunchwidget(QGraphicsItem *parent)
    : HbWidget(parent)
{

    QServiceManager serviceManager;
    mActivityManager = serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager");
    if (!mActivityManager) {
        qFatal("Cannot initialize critical com.nokia.qt.activities.ActivityManager service.");
    }
    mBackgroundCheckBox = new HbCheckBox("background");
    mBackgroundCheckBox->setCheckState(Qt::Unchecked);
    mLunchButton = new HbPushButton("Lunch App");
    mLunchButton1 = new HbPushButton("Lunch Act");
    mResultLabel = new HbLabel;
    mPlatformCombo = new HbComboBox();
    mPlatformCombo->addItem("Qt");
    mPlatformCombo->addItem("Symbian");
    
    mGridLayout = new QGraphicsGridLayout();
    mGridLayout->addItem(mResultLabel, 0, 0, 1, 1);
    mGridLayout->addItem(mLunchButton, 1, 0, 1, 1);
    mGridLayout->addItem(mLunchButton1, 2, 0, 1, 1);
    mGridLayout->addItem(mBackgroundCheckBox, 3, 0, 1, 1);
    mGridLayout->addItem(mPlatformCombo, 4, 0, 1, 1);
    setLayout(mGridLayout);


    connect(mLunchButton, SIGNAL(released()), this, SLOT(lunchApp()));
    connect(mLunchButton1, SIGNAL(released()), this, SLOT(lunchAct()));
    
    User::LeaveIfError(mApaLsSession.Connect());
    User::LeaveIfError(mWsSession.Connect());
    mSymbianAL = CAfActivityLauncher::NewL(mApaLsSession, mWsSession) ;

}

lunchwidget::~lunchwidget()
{
    mApaLsSession.Close();
    mWsSession.Close();
    delete mSymbianAL;
}

void lunchwidget::lunchApp()
{
    QUrl url;
    url.setScheme(Af::KActivityScheme);
    url.setHost(KAppUid);
    url.addQueryItem(Af::KActivityUriNameKey, "nonexist");
    if (mBackgroundCheckBox->checkState() == Qt::Checked) {
        url.addQueryItem(Af::KActivityUriBackgroundKey, "back");
    }
    url.addQueryItem("param1", "trompka");
    QString debugString = url.toString(); 
    lunch(url);
}

void lunchwidget::lunchAct()
{
    QUrl url;
    url.setScheme(Af::KActivityScheme);
    url.setHost(KActUid);
    url.addQueryItem(Af::KActivityUriNameKey, "bold");
    if (mBackgroundCheckBox->checkState() == Qt::Checked) {
        url.addQueryItem(Af::KActivityUriBackgroundKey, "back");
    }
    url.addQueryItem("param1", "trompka");
    QString debugString = url.toString(); 
    
    lunch(url);
}

void lunchwidget::lunch(const QUrl& url)
{
    bool ok = true;
    if(mPlatformCombo->currentText() == "Qt") {
        ok = QMetaObject::invokeMethod(mActivityManager, "launchActivity", Q_ARG(QUrl, url) );
    }
    else {
        HBufC *uriDescriptor = XQConversions::qStringToS60Desc(QString(url.toEncoded()));
        TRAPD(err, mSymbianAL->launchActivityL(*uriDescriptor));
        bool errbool = static_cast<bool>(err);
        ok = !errbool;
        delete uriDescriptor;
    }
    
    if ( ok ) {
        mResultLabel->setPlainText( "ok" );
        }
    else {        
         mResultLabel->setPlainText( "fail" );
        }
}