taskswitcher/testapplications/parentembedded/parent/lunchwidget.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include "lunchwidget.h"
       
    18 #include <QRect>
       
    19 #include <QPainter>
       
    20 #include <QUrl>
       
    21 #include <qservicemanager.h>
       
    22 #include <xqaiwrequest.h>
       
    23 #include <xqappmgr.h>
       
    24 #include <xqconversions.h>
       
    25 #include <hbapplication>
       
    26 QTM_USE_NAMESPACE
       
    27 
       
    28 #define hbApp qobject_cast<HbApplication*>(qApp)
       
    29 
       
    30 lunchwidget::lunchwidget(QGraphicsItem *parent)
       
    31     : HbWidget(parent)
       
    32 {
       
    33 
       
    34 	mTitle = "trompka";
       
    35     mLunchButton = new HbPushButton("Lunch embedded app");
       
    36     mResultLabel = new HbLabel;
       
    37     
       
    38     mGridLayout = new QGraphicsGridLayout();
       
    39     mGridLayout->addItem(mResultLabel, 0, 0, 1, 1);
       
    40     mGridLayout->addItem(mLunchButton, 1, 0, 1, 1);
       
    41     setLayout(mGridLayout);
       
    42 
       
    43 
       
    44     connect(mLunchButton, SIGNAL(released()), this, SLOT(lunchApp()));
       
    45     
       
    46     QStringList list = hbApp->arguments();
       
    47     int count = list.count();
       
    48 
       
    49     mTimer = new QTimer;
       
    50     if( count >= 2 ) {
       
    51         mTitle = list.at(1);
       
    52         connect( mTimer, SIGNAL(timeout()), this, SLOT(timeout()) );
       
    53         mTimer->start(1);
       
    54         }
       
    55 }
       
    56 
       
    57 lunchwidget::~lunchwidget()
       
    58 {
       
    59 	delete mTimer;
       
    60 }
       
    61 
       
    62 void lunchwidget::lunchApp()
       
    63 {
       
    64     QList<QVariant> args;
       
    65     QString serviceName("com.nokia.services.embeddedservices");
       
    66     QString operation("requestSetTitle(QString)");
       
    67     XQAiwRequest* request;
       
    68     XQApplicationManager appManager;
       
    69     request = appManager.create(serviceName, "requestSetTitle", operation, true); //embedded
       
    70     if ( request == NULL )
       
    71     {
       
    72         mResultLabel->setPlainText( "request failed" );
       
    73         return;    
       
    74     }
       
    75 
       
    76     // Result handlers
       
    77     connect (request, SIGNAL(requestOk(const QVariant&)), 
       
    78         this, SLOT(setTitleCompleted(const QVariant&)));
       
    79     connect (request, SIGNAL(requestError(int,const QString&)), 
       
    80         this, SLOT(serviceRequestError(int,const QString&)));
       
    81 
       
    82     args << mTitle; 
       
    83 
       
    84 
       
    85     request->setArguments(args);
       
    86     if(!request->send()) {
       
    87 		mResultLabel->setPlainText( "sending request failed" );
       
    88     }
       
    89     delete request;
       
    90 }
       
    91 
       
    92 void lunchwidget::setTitleCompleted(const QVariant& data)
       
    93 {
       
    94     QString title = data.toString();
       
    95     mResultLabel->setPlainText( title );
       
    96 }
       
    97     
       
    98 void lunchwidget::serviceRequestError(int err,const QString& msg)
       
    99 {
       
   100     QString errmsg = tr("Error: %1, ").arg(err);
       
   101     errmsg += msg;
       
   102     mResultLabel->setPlainText( errmsg );
       
   103 }    
       
   104 
       
   105 void lunchwidget::timeout()
       
   106 	{
       
   107 	mTimer->stop();
       
   108 	lunchApp();
       
   109 	}