--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/activityfw/testapplications/activitytestanimal/animalwidget.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,146 @@
+/*
+* 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 "animalwidget.h"
+
+#include <QGridLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QCoreApplication>
+#include <QSignalMapper>
+#include <QVariant>
+#include <QApplication>
+#include <qservicemanager.h>
+
+QTM_USE_NAMESPACE
+
+AnimalWidget::AnimalWidget(QWidget *parent) : QWidget(parent), mActivityClient(NULL)
+{
+ QServiceManager serviceManager;
+ mActivityClient = serviceManager.loadInterface("com.nokia.qt.activities.ActivityClient");
+ if (!mActivityClient) {
+ qFatal("Cannot initialize critical com.nokia.qt.activities.ActivityClient service.");
+ }
+ connect(mActivityClient, SIGNAL(activityRequested(QString)), this, SLOT(loadActivity(QString)));
+
+
+ bool retok = false;
+ bool ok = QMetaObject::invokeMethod(mActivityClient, "waitActivity", Q_RETURN_ARG(bool, retok));
+ if (!ok || !retok) {
+ // qFatal("Subscribe failed");
+ }
+
+
+ mAnimalLabel = new QLabel();
+ mFileNameLabel = new QLabel("No image loaded");
+ QPushButton *africanElephantButton = new QPushButton("African elephant");
+ QPushButton *africanTigerButton = new QPushButton("African tiger");
+ QPushButton *indiaElephantButton = new QPushButton("India elephant");
+ QPushButton *siberianTigerButton = new QPushButton("Siberian tiger");
+ QPushButton *saveActivityButton = new QPushButton("Save activity");
+ QPushButton *quitButton = new QPushButton("Quit");
+
+ QGridLayout *layout = new QGridLayout();
+
+ layout->addWidget(mAnimalLabel, 0, 0, 1, 2);
+ layout->addWidget(mFileNameLabel, 1, 0, 1, 2);
+ layout->addWidget(africanElephantButton, 2, 0);
+ layout->addWidget(africanTigerButton, 2, 1);
+ layout->addWidget(indiaElephantButton, 3, 0);
+ layout->addWidget(siberianTigerButton, 3, 1);
+ layout->addWidget(saveActivityButton, 4, 0);
+ layout->addWidget(quitButton, 4, 1);
+
+ connect(saveActivityButton, SIGNAL(clicked()), this, SLOT(saveActivity()));
+ connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
+
+ QSignalMapper *mapper = new QSignalMapper(this);
+ mapper->setMapping(africanElephantButton, ":/images/africaelephant.jpg");
+ mapper->setMapping(africanTigerButton, ":/images/africatiger.jpg");
+ mapper->setMapping(indiaElephantButton, ":/images/indiaelephant.jpg");
+ mapper->setMapping(siberianTigerButton, ":/images/syberiantiger.jpg");
+ connect(africanElephantButton, SIGNAL(clicked()), mapper, SLOT(map()));
+ connect(africanTigerButton, SIGNAL(clicked()), mapper, SLOT(map()));
+ connect(indiaElephantButton, SIGNAL(clicked()), mapper, SLOT(map()));
+ connect(siberianTigerButton, SIGNAL(clicked()), mapper, SLOT(map()));
+
+ connect(mapper, SIGNAL(mapped(QString)), this, SLOT(changeAnimalImage(QString)));
+
+ setLayout(layout);
+
+ //startup case
+ QStringList arglist = qApp->arguments();
+ QVariantHash actdata;
+ ok = QMetaObject::invokeMethod(mActivityClient, "parseCommandLine", Q_RETURN_ARG(QVariantHash, actdata), Q_ARG(QStringList, arglist));
+ if (!ok) {
+ // qFatal("Startup failed");
+ }
+ QString actid = actdata.value("activityname").toString();
+ if ( !actid.isNull() )
+ {
+ QVariant data;
+ ok = QMetaObject::invokeMethod(mActivityClient, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, actid));
+ if (!ok) {
+ qFatal("Get data failed");
+ }
+ changeAnimalImage(data.toString());
+ }
+ //startup case end
+}
+
+AnimalWidget::~AnimalWidget()
+{
+ delete mActivityClient;
+}
+
+void AnimalWidget::changeAnimalImage(const QString &image)
+{
+ mAnimalLabel->setPixmap(QPixmap(image).scaled(QSize( 200, 300), Qt::KeepAspectRatio));
+ mFileNameLabel->setText(image);
+ mCurrentImage = image;
+}
+
+void AnimalWidget::saveActivity()
+{
+ QVariantHash metadata;
+ metadata.insert("screenshot", *mAnimalLabel->pixmap());
+ bool retok;
+ bool ok = QMetaObject::invokeMethod(mActivityClient, "removeActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, "Activities - pure Qt"));
+ if (!ok) {
+ qFatal("Remove failed");
+ }
+ ok = QMetaObject::invokeMethod(mActivityClient, "addActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, "Activities - pure Qt"), Q_ARG(QVariant, QVariant(mCurrentImage)), Q_ARG(QVariantHash, metadata));
+ if (!ok || !retok) {
+ qFatal("Add failed");
+ }
+}
+
+void AnimalWidget::loadActivity(const QString &name)
+{
+ bool retok;
+ bool ok = QMetaObject::invokeMethod(mActivityClient, "waitActivity", Q_RETURN_ARG(bool, retok));
+ if (!ok || !retok) {
+ // qFatal("Resubscribe failed");
+ }
+
+ QVariant data;
+ ok = QMetaObject::invokeMethod(mActivityClient, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, name));
+ if (!ok) {
+ qFatal("Get data failed");
+ }
+ changeAnimalImage(data.toString());
+}